GTK+ Forums

Discussion forum for GTK+ and Programming. Ask questions, troubleshoot problems, view and post example code, or express your opinions.
It is currently Fri Feb 12, 2016 11:50 am

All times are UTC

Post new topic Reply to topic  [ 1 post ] 
Author Message
 Post subject: Gnocl now gets support for glade files
PostPosted: Mon Nov 30, 2009 8:38 pm 
Although I prefer hard coding my GTK+ UIs using the scripting capabilities of Gnocl -after all it is extremely easy- none the less, determined Glade users are perhaps more interested in getting rapid results on the coding side of things. The following test script demonstrates how, using the gnocl::glade commmand currently under development for Gnocl, a UI made in Glade can be loaded into a Tcl/Gnocl script and the resultant widgets manipulated as easily as their pure Gnocl counterparts. Here a simple layout of three buttons is accessed, the widgets modified, signal handlers set up, and new objects added to the main container.

# gladeXMLTest1.tcl
# William J Giddings
# 30-Nov-2009

# the next line restarts using tclsh \
exec tclsh "$0" "$@"

package require Gnocl

# load a simple glade file, containing three buttons in a horizontal row
# the variable glade1_widgets contains a list of all widgets created
# by loading this file, they will include the names given in the glade file itself
# along with the names assigned when registering these with Tcl
set glade1
set glade1_widgets [gnocl::glade new $glade1]

# for convenience sake, create a list of aliases for these new widgets
# we can use the glade widget names to do this, to make things manageable

foreach item $glade1_widgets {
foreach {gnocl glade} $item {}
set $glade $gnocl

# in the glade file the toplevel window is named window1
# lets resize, rename and centre it on screen

$window1 configure -title "Glade Test" -width 320 -height 200
$window1 centre ;# or 'center' if you wish

# we can now access the widget attributes as these are registered with gnocl!
$button1 configure -icon "%#New" -onClicked { puts "NEW! from %w" }
$button2 configure -icon "%#Open" -onClicked { puts "Open! from %w" }
$button3 configure -icon "%#Save" -onClicked { puts "Save! from %w" }

# as there needs to be a container for these widgets we can get its name with
set box [$window1 cget -child]

# and, of course, add new widgets too!
$box add [gnocl::toggleButton -text "CLICK ME!"]


And here are the results.



And after...


Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 1 post ] 

All times are UTC

Who is online

Users browsing this forum: No registered users and 1 guest

You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group