Programming Forums
User Name Password Register
 

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

 
 
Thread Tools Display Modes
Prev Previous Post in Thread   Next Post in Thread Next
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: 5 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
 

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 10:32 PM.

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