Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

Reply
 
Thread Tools Display Modes
Old Nov 5th, 2005, 7:22 AM   #1
Arevos
Programming Guru
 
Arevos's Avatar
 
Join Date: Aug 2005
Location: England
Posts: 1,499
Rep Power: 4 Arevos is on a distinguished road
Glade helper class

I've created a simple helper class for Glade, a widget designer for the crossplatform GTK toolkit:
import pygtk
pygtk.require("2.0")
import gtk
import gtk.glade

class GladeApplication:
   def __init__(self, glade_file):
      class Widgets:
         def __init__(self, glade):
            self._glade = glade
         def __getattr__(self, name):
            return self._glade.get_widget(name)
      
      self._glade = gtk.glade.XML(glade_file)
      self._glade.signal_autoconnect(self)
      self.widget = Widgets(self._glade)
This class puts all the widgets defined by Glade in "self.widgets", and looks for events in the main class.

For instance, to test this I created a simple ROT13 application that consists of a window, a textview widget, and a button widget. In Glade I setup the window's destroy event to point to "on_destroy", and the button clicked event to point to "on_button_clicked". I saved the glade XML file as "rot13.glade".

The python code to use this:
class Rot13(GladeApplication):
   def __init__(self):
      GladeApplication.__init__(self, "rot13.glade")

   def on_destroy(self, window):
      gtk.main_quit()

   def on_button_clicked(self, button):
      text_buffer = self.widget.textview.get_buffer()
      text = text_buffer.get_text(*text_buffer.get_bounds())
      text_buffer.set_text(text.encode('rot13'))

Rot13()
gtk.main()
Arevos is offline   Reply With Quote
Old Nov 6th, 2005, 10:19 AM   #2
Dietrich
Professional Programmer
 
Dietrich's Avatar
 
Join Date: Feb 2005
Posts: 434
Rep Power: 4 Dietrich is on a distinguished road
Smile

Arevos, pygtk and Glade sound interesting. I have tried to play with it before, but got lost in the files to download. Could you please give a list of all the files one needs and where to get them?

I am using Windows XP.

Thank you!
__________________
I looked it up on the Intergnats!
Dietrich is offline   Reply With Quote
Old Nov 6th, 2005, 12:46 PM   #3
Arevos
Programming Guru
 
Arevos's Avatar
 
Join Date: Aug 2005
Location: England
Posts: 1,499
Rep Power: 4 Arevos is on a distinguished road
Well, I'm on linux so installing PyGTK/Glade fairly straightforward (apt-get handles all of the hard stuff).

Under Windows, I believe you can download PyGTK 2.6 from here and the GTK Windows development environment from here, and I suspect you should be set.
Arevos is offline   Reply With Quote
Old Nov 7th, 2005, 8:36 AM   #4
Dietrich
Professional Programmer
 
Dietrich's Avatar
 
Join Date: Feb 2005
Posts: 434
Rep Power: 4 Dietrich is on a distinguished road
Smile

Thank you,
I got pygtk/gtk to work.

Now I need to know a little more about glade/gnome and I will be set.
__________________
I looked it up on the Intergnats!
Dietrich is offline   Reply With Quote
Old Nov 7th, 2005, 9:05 AM   #5
Arevos
Programming Guru
 
Arevos's Avatar
 
Join Date: Aug 2005
Location: England
Posts: 1,499
Rep Power: 4 Arevos is on a distinguished road
Glade is a graphical GUI builder for the GTK toolkit. You can build up an interface, and connect predefined events to custom hooks (for instance, connecting the button-clicked event to "on_button_clicked"). Glade saves the interface as XML, which can then be loaded up by PyGTK.

Gnome is a desktop environment for Linux that uses the GTK toolkit. Glade was developed for the Gnome project, though Gnome is not required for Glade to run; only GTK is needed.
Arevos is offline   Reply With Quote
Old Nov 7th, 2005, 10:52 AM   #6
coldDeath
Expert Programmer
 
coldDeath's Avatar
 
Join Date: Aug 2005
Location: UK
Posts: 862
Rep Power: 3 coldDeath is on a distinguished road
Send a message via AIM to coldDeath Send a message via Yahoo to coldDeath
I need to look into this when i have some spare time, I'm pretty bogged down with coursework etc. But when i can i'll download pyGTK and have a go. I already have Glade though.
__________________
Join us at #programmingforums @ irc.freenode.net!

My software never has bugs. It just develops random features.
coldDeath is offline   Reply With Quote
Old Nov 7th, 2005, 1:34 PM   #7
Dietrich
Professional Programmer
 
Dietrich's Avatar
 
Join Date: Feb 2005
Posts: 434
Rep Power: 4 Dietrich is on a distinguished road
Thank you Arevos,
that explains your Glade helper class.
__________________
I looked it up on the Intergnats!
Dietrich is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 9:18 PM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC