Class: TK::FixPagesDialog

Inherits:
BaseDialog show all
Defined in:
lib/wiki_lyrics/gui/gui-tk.rb

Instance Attribute Summary

Attributes inherited from BaseDialog

#accepted, #values

Instance Method Summary collapse

Methods inherited from BaseDialog

#accept, #destroy, #exec, #get_position, get_screen_size, #get_size, #set_position, #set_size

Constructor Details

#initialize(values) ⇒ FixPagesDialog

Returns a new instance of FixPagesDialog.



957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
# File 'lib/wiki_lyrics/gui/gui-tk.rb', line 957

def initialize( values )
	super( values )

	@fetch_func = eval( @values["fetch_func"] )
	@fix_func = eval( @values["fix_func"] )
	@submit_func = eval( @values["submit_func"] )

	set_size( 600, 400 )

	@shell.title( "#{values["site_name"]} - #{values["title"]}" )

	label = Label.new( @shell, I18n.get( "gui.common.url" ) )
	label.grid( "row"=>1, "column"=>1 )
	@url_lineedit = TextEdit.new( @shell, values["url"] )
	@url_lineedit.grid( "row"=>1, "column"=>2, "columnspan"=>3, "sticky"=>"ew" )

	page_frame = TkFrame.new( @shell )
	page_frame.grid( "row"=>2, "column"=>1, "columnspan"=>4, "sticky"=>"nesw" )
	bar = TkScrollbar.new( page_frame, "orient"=>"ver" )
	bar.pack( "side"=>"right", "fill"=>"y" )
	@page_text = TextArea.new( page_frame ) { yscrollcommand { |first, last| bar.set( first, last ) } }
	@page_text.pack( "side"=>"left", "fill"=>"both", "expand"=>true )
	bar.command( proc { |*args| @page_text.yview( *args ) } )

	buttons_frame = TkFrame.new( @shell )
	@submit_button = Button.new( buttons_frame, I18n.get( "gui.common.submit" ) )
	@submit_button.command( proc { submit_page() } )
	@submit_button.pack( "side"=>"right" )
	@fix_button = Button.new( buttons_frame, I18n.get( "gui.common.fix" ) )
	@fix_button.command( proc { fix_page() }  )
	@fix_button.pack( "side"=>"right" )
	@fetch_button = Button.new( buttons_frame, I18n.get( "gui.common.load" ) )
	@fetch_button.command( proc { fetch_page() } )
	@fetch_button.pack( "side"=>"right" )
	buttons_frame.grid( "row"=>3, "column"=>1, "columnspan"=>4, "sticky"=>"ew" )

	@shell.grid_rowconfigure( 2, "weight"=>1 )
	@shell.grid_columnconfigure( 2, "weight"=>1 )
end

Instance Method Details

#fetch_pageObject



997
998
999
1000
1001
1002
1003
# File 'lib/wiki_lyrics/gui/gui-tk.rb', line 997

def fetch_page()
	if (page_content = @fetch_func.call( @url_lineedit.value() ))
		@original_content = page_content
		@original_url = @url_lineedit.text()
		@page_text.set_text( page_content )
	end
end

#fix_pageObject



1005
1006
1007
# File 'lib/wiki_lyrics/gui/gui-tk.rb', line 1005

def fix_page()
	@page_text.set_text( @fix_func.call( @page_text.text() ) ) if @original_content
end

#submit_pageObject



1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
# File 'lib/wiki_lyrics/gui/gui-tk.rb', line 1009

def submit_page()
	if @original_content != nil && @original_content != (page_content = @page_text.text())
		if @submit_func.call( @original_url, page_content )
			@original_content = page_content
			puts I18n.get( "gui.fixpages.success", @original_url )
		else
			puts I18n.get( "gui.fixpages.error", @original_url )
		end
	end
end