GTK+ Forums Forum Index GTK+ Forums
Discussion forum for GTK+ and Programming. Ask questions, troubleshoot problems, view and post example code, or express your opinions.
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Gnocl now gets support for glade files

 
Post new topic   Reply to topic    GTK+ Forums Forum Index -> Project Showcase
Author Message
wjgiddings
GTK+ Geek


Joined: 06 Feb 2009
Posts: 71
Location: The Midlands, England

PostPosted: Mon Nov 30, 2009 8:38 pm    Post subject: Gnocl now gets support for glade files Reply with quote

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.

Code: (Plaintext)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
#---------------
# gladeXMLTest1.tcl
#---------------
# William J Giddings
# 30-Nov-2009
#---------------

#!/bin/sh
# 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 button1.glade
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!"]

gnocl::mainLoop


And here are the results.

Before....



And after...

Back to top
Display posts from previous:   
Post new topic   Reply to topic    GTK+ Forums Forum Index -> Project Showcase All times are GMT
Page 1 of 1

 


Powered by phpBB © 2001, 2005 phpBB Group
CodeBB 1.0 Beta 2
Protected by Anti-Spam ACP