PageRenderTime 21ms CodeModel.GetById 12ms app.highlight 3ms RepoModel.GetById 1ms app.codeStats 0ms

/src/wrappers/gtk/examples/dialogs/dialogs_demo.e

http://github.com/tybor/Liberty
Specman e | 139 lines | 116 code | 17 blank | 6 comment | 7 complexity | d3fbb86fe9f0baac5e47ea4b36282a4b MD5 | raw file
  1indexing
  2	description: "GTK+ 2 example demostrating the use of dialogs"
  3	copyright: "(C) 2004 Paolo Redaelli "
  4	license: "LGPL v2 or later"
  5	date: "$Date:$"
  6	revision: "$Revision:$"
  7
  8class DIALOGS_DEMO
  9
 10inherit
 11	GTK --redefine default_rescue end
 12	DIALOG_FLAGS --redefine default_rescue end
 13	MESSAGE_TYPES --redefine default_rescue end
 14	BUTTONS_TYPES --redefine default_rescue end
 15	ANY --redefine default_rescue end
 16
 17insert
 18	GTK_RESPONSE_TYPE
 19	
 20creation make
 21
 22feature -- dialogs
 23	dialog: GTK_DIALOG
 24	label: GTK_LABEL
 25	message: GTK_MESSAGE_DIALOG
 26	file_chooser: GTK_FILE_CHOOSER_DIALOG
 27	--file_selection: GTK_FILE_SELECTION
 28	answer: INTEGER
 29			-- answer code of the last dialog run
 30	
 31feature -- Initialisation
 32	
 33	make is
 34		do
 35			gtk.initialize								
 36			run_some_dialogs
 37			show_file_dialogs
 38			run_files_dialog
 39		end
 40
 41	run_some_dialogs is
 42		do
 43			create dialog.make
 44			-- Add a label
 45			create label.with_label ("What's your favourite programming language?")
 46			label.show
 47			dialog.vbox.pack_start_defaults (label)			
 48			-- Add some buttons 
 49			dialog.add_button("Eiffel", 10)
 50			dialog.add_button("C#", 11)
 51			dialog.add_button("Python", 12)
 52			dialog.add_help_button
 53			dialog.midscreen
 54			-- TODO: 10,11,12 are response_id... Check if it is clear enough.
 55						
 56			answer:=dialog.run
 57			inspect answer
 58			when 10 then print("Eiffel is a wise choice!%N")
 59			when 11 then print("Using C# brings you in the forest of patents. Are you sure you want to go on?")
 60			when 12 then print("Python is nice and easy to program, but sometimes it can be quite slow!%N")
 61			else 
 62			end
 63			dialog.destroy
 64			
 65			create message.make (Void, modal_dialog, info_message, ok_button,
 66									  "[
 67										eGTK are Eiffel wrappers to the
 68										GTK+ libraries made from the scratch
 69										for SmartEiffel.
 70										]")
 71			message.add_button ("Hey, why don't you help Andreas?",22)
 72			message.midscreen
 73			answer := message.run
 74			print("Answer is:") print(answer.out) print("%N")
 75			message.destroy
 76			
 77			create message.with_markup (Void, modal_dialog, question_message, yes_no_buttons,
 78												 "[
 79												  <b><big>eGTK</big> is a work in progress</b>.
 80												  We need volunteers. Would help us?
 81												  ]")
 82			-- message.set_modal message.add_yes_no_buttons
 83														
 84			answer := message.run
 85			print("Answer is:") print(answer.out) print("%N")
 86			message.destroy
 87		end
 88
 89	show_file_dialogs is
 90		local filename: STRING
 91		do
 92			create file_chooser.make_open ("Choose the Eiffelest file you have",Void,
 93													 <<["Sure", {INTEGER 1}],
 94														["Nay",  {INTEGER 2}]>>)
 95			file_chooser.add_ok_cancel_buttons
 96			answer := file_chooser.run
 97			filename := file_chooser.filename
 98			print ("Answer is ") print (answer.out)
 99			if answer/=gtk_response_ok then print (". Sadly no file choosen%N")
100			else  print (". Happily you chose: '") print (filename) print("'%N")
101			end
102		end
103
104	run_files_dialog is
105		local filenames: G_SLIST_STRING; i: ITERATOR[STRING]
106		do
107			create file_chooser.make_open ("Choose some files",Void,Void)
108			file_chooser.add_ok_cancel_buttons
109			file_chooser.allow_multiple_selections
110			
111			answer := file_chooser.run
112			print ("Answer is "+answer.out+".%N")
113
114			filenames := file_chooser.filenames
115			if answer/=gtk_response_ok then 
116				print ("Cancel pressed.%N")
117			else 
118				print (filenames.count.out + " files choosen. ")
119				from i:=filenames.get_new_iterator; i.start; print("Choosen files are: ") 
120				until i.is_off 
121				loop 
122					print ("`") print(i.item) print ("'")
123					i.next
124					if not i.is_off then print (", ") end
125				end 
126				print (" No more%N")
127			end
128		end
129
130	my_rescue is
131		local failing_message: GTK_MESSAGE_DIALOG; an_answer: INTEGER
132		do
133			print_run_time_stack
134			create failing_message.make (Void, modal_dialog, error_message, ok_button,
135												 "We are falling!")
136			failing_message.set_title ("Program error")
137			an_answer := failing_message.run
138		end
139end