From c8889c0cca519c6e3e52b4ba01fad011632cda58 Mon Sep 17 00:00:00 2001 From: Thomas Leonard Date: Fri, 30 Dec 2011 08:43:21 +0000 Subject: [PATCH] Moved DialogResponse, ButtonClickedBlocker and MixedButton to gtkutils --- zeroinstall/0launch-gui/dialog.py | 44 +++---------------------------------- zeroinstall/gtkui/gtkutils.py | 46 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 49 insertions(+), 41 deletions(-) diff --git a/zeroinstall/0launch-gui/dialog.py b/zeroinstall/0launch-gui/dialog.py index d120a64..862b1e6 100644 --- a/zeroinstall/0launch-gui/dialog.py +++ b/zeroinstall/0launch-gui/dialog.py @@ -3,11 +3,8 @@ import gtk import os -from zeroinstall.support import tasks from zeroinstall.gtkui import gtkutils -n_windows = 0 - last_error = None builderfile = os.path.join(os.path.dirname(__file__), 'zero-install.ui') @@ -30,26 +27,6 @@ class Dialog(gtk.Dialog): button.show_all() return button -class DialogResponse(tasks.Blocker): - response = None - def __init__(self, dialog): - tasks.Blocker.__init__(self, dialog.get_title()) - a = None - def response(d, resp): - self.response = resp - d.disconnect(a) - self.trigger() - a = dialog.connect('response', response) - -class ButtonClickedBlocker(tasks.Blocker): - def __init__(self, button): - tasks.Blocker.__init__(self, "Button click") - a = None - def clicked(b): - b.disconnect(a) - self.trigger() - a = button.connect('clicked', lambda b: self.trigger()) - def alert(parent, message, type = gtk.MESSAGE_ERROR): if type == gtk.MESSAGE_ERROR: global last_error @@ -57,21 +34,6 @@ def alert(parent, message, type = gtk.MESSAGE_ERROR): gtkutils.show_message_box(parent, message, type) -def MixedButton(message, stock, x_align = 0.5, button = None): - if button is None: - button = gtk.Button() - - label = gtk.Label('') - label.set_text_with_mnemonic(message) - label.set_mnemonic_widget(button) - - image = gtk.image_new_from_stock(stock, gtk.ICON_SIZE_BUTTON) - box = gtk.HBox(False, 2) - align = gtk.Alignment(x_align, 0.5, 0.0, 0.0) - - box.pack_start(image, False, False, 0) - box.pack_end(label, False, False, 0) - - button.add(align) - align.add(box) - return button +DialogResponse = gtkutils.DialogResponse +ButtonClickedBlocker = gtkutils.ButtonClickedBlocker +MixedButton = gtkutils.MixedButton diff --git a/zeroinstall/gtkui/gtkutils.py b/zeroinstall/gtkui/gtkutils.py index 35c37fe..97af3ad 100644 --- a/zeroinstall/gtkui/gtkutils.py +++ b/zeroinstall/gtkui/gtkutils.py @@ -4,6 +4,7 @@ # See the README file for details, or visit http://0install.net. import gtk +from zeroinstall.support import tasks class Template: """Wrapper for GtkBuilder widget tree that throws a sensible exception if the widget isn't found.""" @@ -76,3 +77,48 @@ def get_busy_pointer(): #old bug http://bugzilla.gnome.org/show_bug.cgi?id=103616 _busy_pointer = gtk.gdk.Cursor(gtk.gdk.WATCH) return _busy_pointer + +class DialogResponse(tasks.Blocker): + """Triggers when the GtkDialog gets a response. + @since: 1.5""" + response = None + def __init__(self, dialog): + tasks.Blocker.__init__(self, dialog.get_title()) + a = None + def response(d, resp): + self.response = resp + d.disconnect(a) + self.trigger() + a = dialog.connect('response', response) + +class ButtonClickedBlocker(tasks.Blocker): + """Triggers when the GtkButton is activated. + @since: 1.5""" + def __init__(self, button): + tasks.Blocker.__init__(self, "Button click") + a = None + def clicked(b): + b.disconnect(a) + self.trigger() + a = button.connect('clicked', lambda b: self.trigger()) + +def MixedButton(message, stock, x_align = 0.5, button = None): + """A GtkButton with a stock icon. + @since: 1.5""" + if button is None: + button = gtk.Button() + + label = gtk.Label('') + label.set_text_with_mnemonic(message) + label.set_mnemonic_widget(button) + + image = gtk.image_new_from_stock(stock, gtk.ICON_SIZE_BUTTON) + box = gtk.HBox(False, 2) + align = gtk.Alignment(x_align, 0.5, 0.0, 0.0) + + box.pack_start(image, False, False, 0) + box.pack_end(label, False, False, 0) + + button.add(align) + align.add(box) + return button -- 2.11.4.GIT