# http://www.bleb.org/
import gtk, gobject
-import gnome.gconf
-import hildon, osso
-import traceback
-import time
import re
import thread
import os.path
_have_osso = True
except ImportError:
_have_osso = False
+
+try:
+ import gnome.gconf
+ _have_gconf = True
+except ImportError:
+ _have_gconf = False
gobject.threads_init()
# -- Main class...
#
-class Wimpworks:
+class WimpWorks:
'''A framework for creating easy-to-use graphical user interfaces using
GTK+, Python, DBus and more.
@param dbus_name Name to register with DBus. If unspecified, no
DBus registration will be performed.'''
- self.gconf = gnome.gconf.client_get_default()
self.name = application
self.dbus_name = dbus_name
self.menu = None
+
+ if _have_gconf:
+ self.gconf = gnome.gconf.client_get_default()
if _have_hildon:
self.app = hildon.Program()
self.main_window = hildon.Window()
+ gtk.set_application_name(application)
else:
self.app = None
self.main_window = gtk.Window()
-
- gtk.set_application_name(application)
- self.window.connect("delete-event", gtk.main_quit)
+
+ self.main_window.set_title(application)
+ self.main_window.connect("delete-event", gtk.main_quit)
if _have_osso and dbus_name:
self.osso_context = osso.Context(dbus_name, version, False)
self.app.add_window(self.main_window)
if _have_hildon:
- self._expose_hid = self.window.connect('expose-event', self._take_screenshot)
+ self._expose_hid = self.main_window.connect('expose-event', self._take_screenshot)
# -----------------------------------------------------------------------
@param window Window to set background of. If unset, will default to the
main application window.'''
- file = "/opt/%s/share/%s" % (self.name, file) # TODO Handle other forms of path
+ # TODO Handle other forms of path
+ file = "/opt/%s/share/%s" % (re.sub('[^a-z0-9_]', '', self.name.lower()), file)
if not window:
window = self.main_window
called.'''
if not window:
- window = self.main_Window
+ window = self.main_window
if not self.menu:
if _have_hildon:
'''Once the application has been initialised, this will show the main window
and run the mainloop.'''
- self.window.show_all()
+ self.main_window.show_all()
gtk.main()
@see http://maemo.org/api_refs/5.0/5.0-final/hildon/hildon-Additions-to-GTK+.html#hildon-gtk-window-take-screenshot'''
- self.window.disconnect(self._expose_hid)
+ self.main_window.disconnect(self._expose_hid)
if not os.path.isfile("/home/user/.cache/launch/%s.pvr" % (self.dbus_name)):
gobject.timeout_add(80, hildon.hildon_gtk_window_take_screenshot, self.main_window, True)
called 'do_method'.'''
method = re.sub('[^a-z0-9_]', '', method.lower())
- self.attr("do_%s" % (method))(event.window)
+ getattr(self, "do_%s" % (method))(event.window)
# -----------------------------------------------------------------------
@param offset The vertical offset for the buttons. If unspecified,
they will be centred. Ranges from 0.0 (top) to 1.0 (bottom).'''
- print self
self._container = container
alignment = gtk.Alignment(xalign=0.5, yalign=0.8, xscale=0.8)
self._box = gtk.HButtonBox()
alignment.add(self._box)
- container.add(alignment)
+ container.main_window.add(alignment)
self._box.set_property('layout-style', gtk.BUTTONBOX_SPREAD)
@param title Value of the button, and used to derive the callback method.
@param subtitle An optional subtitle containing more information.'''
- if _have_hildon:
- button = hildon.Button(gtk.HILDON_SIZE_THUMB_HEIGHT, hildon.BUTTON_ARRANGEMENT_VERTICAL,
- title = title, value = subtitle)
- else:
- button = gtk.Button(title)
+ if _have_hildon:
+ button = hildon.Button(gtk.HILDON_SIZE_THUMB_HEIGHT, hildon.BUTTON_ARRANGEMENT_VERTICAL,
+ title = title, value = subtitle)
+ else:
+ button = gtk.Button(label = title)
+
+ button.set_property('width-request', 250)
+ button.connect('clicked', self._container.callback, title)
+ self._box.add(button)
- button.set_property('width-request', 250)
- button.connect('clicked', self.wimpworks.callback, title)
- self._box.add(button)