Class: GTK::SubmitSongDialog

Inherits:
BaseDialog
  • Object
show all
Defined in:
lib/wiki_lyrics/gui/gui-gtk.rb

Instance Attribute Summary

Attributes inherited from BaseDialog

#accepted, #values

Instance Method Summary collapse

Methods inherited from BaseDialog

#exec

Constructor Details

#initialize(values) ⇒ SubmitSongDialog

Returns a new instance of SubmitSongDialog.



395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
# File 'lib/wiki_lyrics/gui/gui-gtk.rb', line 395

def initialize( values )
	super( values )

	set_border_width( 5 )
	set_resizable( true )
	set_default_size( 600, 400 )
	resize( 600, 400 )

	edit_mode = @values["edit_mode"].to_s() == "true"

	set_title( I18n.get( "gui.submitsong.title." + (edit_mode ? "edit" : "submit"), values["site_name"] ) )

	artist_label = Gtk::Label.new( "<b>#{I18n.get( "gui.common.artist" )}</b>" );
	artist_label.set_xalign( 0.9 )
	artist_label.set_use_markup( true )
	@artist_lineedit = Gtk::Entry.new()
	@artist_lineedit.set_text( values["artist"] )

	title_label = Gtk::Label.new( "<b>#{I18n.get( "gui.common.song" )}</b>" );
	title_label.set_xalign( 0.9 )
	title_label.set_use_markup( true )
	@title_lineedit = Gtk::Entry.new()
	@title_lineedit.set_text( values["title"] )

	credits_label = Gtk::Label.new( "<b>#{I18n.get( "gui.common.credits" )}</b>" );
	credits_label.set_xalign( 0.9 )
	credits_label.set_use_markup( true )
	@credits_lineedit = Gtk::Entry.new()
	@credits_lineedit.set_text( values["credits"] )

	lyricist_label = Gtk::Label.new( "<b>#{I18n.get( "gui.common.lyricist" )}</b>" );
	lyricist_label.set_xalign( 0.9 )
	lyricist_label.set_use_markup( true )
	@lyricist_lineedit = Gtk::Entry.new()
	@lyricist_lineedit.set_text( values["lyricist"] )

	year_label = Gtk::Label.new( "<b>#{I18n.get( "gui.common.year" )}</b>" );
	year_label.set_xalign( 0.9 )
	year_label.set_use_markup( true )
	@year_spinbox = Gtk::SpinButton.new( Gtk::Adjustment.new( values["year"], 1900, Date.today().year, 1, 10, 0 ) )
	@year_spinbox.set_numeric( true )

	album_label = Gtk::Label.new( "<b>#{I18n.get( "gui.common.album" )}</b>" );
	album_label.set_xalign( 0.9 )
	album_label.set_use_markup( true )
	@album_lineedit = Gtk::Entry.new()
	@album_lineedit.set_text( values["album"] )

	@instrumental_checkbox = Gtk::CheckButton.new( I18n.get( "gui.submitsong.instrumental" ) )
	@instrumental_checkbox.set_active( values["instrumental"].to_s == "true" )
	@instrumental_checkbox.signal_connect( "toggled" ) { toggle_instrumental_checked() }

	lyrics_scrolled_window = Gtk::ScrolledWindow.new()
	lyrics_scrolled_window.set_policy( Gtk::POLICY_AUTOMATIC, Gtk::POLICY_AUTOMATIC )
	@lyrics_text_buffer = GTK::TextBuffer.new()
	@lyrics_text_buffer.set_text( values["lyrics"] )
	@lyrics_text = GTK::TextView.new()
	@lyrics_text.set_indent( 2 )
	@lyrics_text.set_buffer( @lyrics_text_buffer )
	lyrics_scrolled_window.add( @lyrics_text )
	@lyrics_text.set_sensitive( ! @instrumental_checkbox.active?() )

	@reviewed_checkbox = Gtk::CheckButton.new( I18n.get( "gui.common.reviewed" ) )
	@reviewed_checkbox.set_active( false )

	buttons = create_action_buttons( "split", I18n.get( "gui.common.submit" ) )

	lyrics_frame = Gtk::Frame.new()
	lyrics_frame.add( lyrics_scrolled_window )
	lyrics_frame.set_shadow_type( Gtk::SHADOW_IN )

	grid = Gtk::Table.new( 9, 4, false )
	grid.set_row_spacings( 3 )
	grid.attach( artist_label, 0, 1, 0, 1, Gtk::SHRINK|Gtk::FILL, 0, 5 )
	grid.attach( @artist_lineedit, 1, 2, 0, 1, Gtk::EXPAND|Gtk::FILL, 0 )
	grid.attach( title_label, 2, 3, 0, 1, Gtk::SHRINK|Gtk::FILL, 0, 5 )
	grid.attach( @title_lineedit, 3, 4, 0, 1, Gtk::EXPAND|Gtk::FILL, 0 )
	grid.attach( credits_label, 0, 1, 1, 2, Gtk::SHRINK|Gtk::FILL, 0, 5 )
	grid.attach( @credits_lineedit, 1, 2, 1, 2, Gtk::EXPAND|Gtk::FILL, 0 )
	grid.attach( lyricist_label, 2, 3, 1, 2, Gtk::SHRINK|Gtk::FILL, 0, 5 )
	grid.attach( @lyricist_lineedit, 3, 4, 1, 2, Gtk::EXPAND|Gtk::FILL, 0 )
	grid.attach( year_label, 0, 1, 2, 3, Gtk::SHRINK|Gtk::FILL, 0, 5 )
	grid.attach( @year_spinbox, 1, 2, 2, 3, Gtk::EXPAND|Gtk::FILL, 0 )
	grid.attach( album_label, 2, 3, 2, 3, Gtk::SHRINK|Gtk::FILL, 0, 5 )
	grid.attach( @album_lineedit, 3, 4, 2, 3, Gtk::EXPAND|Gtk::FILL, 0 )
	grid.attach( @instrumental_checkbox, 0, 4, 3, 4, Gtk::EXPAND|Gtk::FILL, 0 )
	grid.attach( lyrics_frame, 0, 4, 4, 5, Gtk::EXPAND|Gtk::FILL, Gtk::EXPAND|Gtk::FILL )
	grid.attach( @reviewed_checkbox, 0, 4, 5, 6, Gtk::EXPAND|Gtk::FILL, 0 )
	grid.attach( buttons, 0, 4, 6, 7, Gtk::EXPAND|Gtk::FILL, 0 )

	add( grid )

end

Instance Method Details

#acceptObject



493
494
495
496
497
498
499
500
501
502
503
504
505
506
# File 'lib/wiki_lyrics/gui/gui-gtk.rb', line 493

def accept()
	@values = {
		"artist"		=> @artist_lineedit.text(),
		"year"			=> @year_spinbox.value().to_i(),
		"album"			=> @album_lineedit.text(),
		"title"			=> @title_lineedit.text(),
		"lyrics"		=> @lyrics_text_buffer.text(),
		"instrumental"	=> @instrumental_checkbox.active?(),
		"lyricist"		=> @lyricist_lineedit.text(),
		"credits"		=> @credits_lineedit.text(),
		"reviewed"		=> @reviewed_checkbox.active?()
	}
	super()
end

#toggle_instrumental_checkedObject



489
490
491
# File 'lib/wiki_lyrics/gui/gui-gtk.rb', line 489

def toggle_instrumental_checked()
	@lyrics_text.set_sensitive( ! @instrumental_checkbox.active?() )
end