added eugtk examples
This commit is contained in:
102
eugtk/examples/glade/widgets.ex
Normal file
102
eugtk/examples/glade/widgets.ex
Normal file
@@ -0,0 +1,102 @@
|
||||
|
||||
---------------------------------------------------------------------------
|
||||
--# Demo of many numeric widgets built with Glade
|
||||
-- would take hundreds of lines of code
|
||||
-- if coded 'by hand', but only a few if the interface is designed by Glade.
|
||||
---------------------------------------------------------------------------
|
||||
|
||||
include GtkEngine.e
|
||||
|
||||
-- Use the following if you want to load the Glade code at runtime.
|
||||
-- This will happen even if the program is bound or compiled, which means
|
||||
-- that changes to the .glade file could improve (or break!) your program:
|
||||
|
||||
-- add(builder,"~/demos/examples/glade/widgets.glade")
|
||||
|
||||
-- Use the 2 lines below instead of the one above
|
||||
-- if you prefer to load the glade XML as an include:
|
||||
|
||||
include widgets.xml
|
||||
add(builder,widgets:XML)
|
||||
|
||||
-- If you do this, it will likewise be included each time the program is
|
||||
-- interpreted, and therefore subject to the xml code being edited.
|
||||
|
||||
-- HOWEVER - when your program is bound or compiled, the glade XML will be
|
||||
-- bound into the program, and latter changes to the .xml will no longer
|
||||
-- have any affect on your program.
|
||||
|
||||
connect("window1","destroy","Quit")
|
||||
main()
|
||||
|
||||
-- All functions which respond to the interface MUST be declared global!
|
||||
-- Controls can be referenced by string ID, rather than by handle.
|
||||
-- The string ID is assigned automatically by Glade when object is created,
|
||||
-- but can be changed on the Glade Properties/General tab (ID:) if you
|
||||
-- prefer a more meaningful name.
|
||||
-- DON'T change the Widget name: field under the Properties/Common tab!
|
||||
|
||||
--------------------------------------------------------------------------------------
|
||||
global function on_radiobuttons_toggled(atom self, atom scale)
|
||||
--------------------------------------------------------------------------------------
|
||||
-- Two calls to this function are made each time a radio button is clicked,
|
||||
-- one as the previously-selected button is toggled 'off', and another
|
||||
-- as the newly-clicked button it toggled 'on'.
|
||||
-- We use the 'active' property to decide which one to respond to.
|
||||
|
||||
-- Each button's 'name' field is used to pass the percentage to set.
|
||||
-- There seems to be little use for that field otherwise.
|
||||
|
||||
atom percent = 0
|
||||
|
||||
if get(self,"active") then
|
||||
percent = to_number(get(self,"name"))
|
||||
set(scale,"value",percent)
|
||||
end if
|
||||
|
||||
return 1
|
||||
end function
|
||||
|
||||
--------------------------------------------------------------
|
||||
global function on_switch1_active_notify(atom self, atom spin)
|
||||
--------------------------------------------------------------
|
||||
set("spinner1","active",get(self,"active")) -- toggle it
|
||||
return 1
|
||||
end function
|
||||
|
||||
--------------------------------------------------
|
||||
global function on_scale1_value_changed(atom self)
|
||||
--------------------------------------------------
|
||||
atom val = get(self,"value")
|
||||
set("progressbar1","fraction",val * .01)
|
||||
set("levelbar1","value",val)
|
||||
set("show_text","active",val != 0)
|
||||
return 1
|
||||
end function
|
||||
|
||||
-----------------------------------------------
|
||||
global function on_show_text_toggled(atom self)
|
||||
-----------------------------------------------
|
||||
set("progressbar1","show text",get(self,"active"))
|
||||
return 1
|
||||
end function
|
||||
|
||||
--------------------------------------------
|
||||
global function on_digits_changed(atom self)
|
||||
--------------------------------------------
|
||||
integer decimals = get(self,"active")-1 -- indexes are zero-based
|
||||
set("value","digits",decimals)
|
||||
set("scale1","digits",decimals)
|
||||
return 1
|
||||
end function
|
||||
|
||||
----------------------------------------
|
||||
global function on_help_about_activate()
|
||||
----------------------------------------
|
||||
return Info("window1","About...","Widgets",
|
||||
sprintf("This is a demo of several\nGtk numeric controls\n\n"
|
||||
&"Current value <span color='red'>%g</span>",get("levelbar1","value")),,
|
||||
"~/demos/thumbnails/applications-development.svg")
|
||||
end function
|
||||
|
||||
|
||||
Reference in New Issue
Block a user