![]() |
|
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
Programming Guru
![]() Join Date: Aug 2005
Location: England
Posts: 1,499
Rep Power: 4
![]() |
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)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() |
|
|
|
|
|
#2 |
|
Professional Programmer
Join Date: Feb 2005
Posts: 434
Rep Power: 4
![]() |
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! |
|
|
|
|
|
#3 |
|
Programming Guru
![]() Join Date: Aug 2005
Location: England
Posts: 1,499
Rep Power: 4
![]() |
|
|
|
|
|
|
#4 |
|
Professional Programmer
Join Date: Feb 2005
Posts: 434
Rep Power: 4
![]() |
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! |
|
|
|
|
|
#5 |
|
Programming Guru
![]() Join Date: Aug 2005
Location: England
Posts: 1,499
Rep Power: 4
![]() |
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. |
|
|
|
|
|
#6 |
|
Expert Programmer
|
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.
|
|
|
|
|
|
#7 |
|
Professional Programmer
Join Date: Feb 2005
Posts: 434
Rep Power: 4
![]() |
Thank you Arevos,
that explains your Glade helper class.
__________________
I looked it up on the Intergnats! |
|
|
|
![]() |
| Bookmarks |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|