From 7f6a1240b1ac19284948f20dcf54b0e9834741b2 Mon Sep 17 00:00:00 2001 From: Thomas Leonard Date: Mon, 28 Jan 2008 22:49:04 +0000 Subject: [PATCH] Run/Download is now a toggle button. If you turn it off then the current downloads are cancelled. --- zeroinstall/0launch-gui/dialog.py | 5 +- zeroinstall/0launch-gui/mainwindow.py | 27 +++-- zeroinstall/0launch-gui/preferences.py | 1 - zeroinstall/0launch-gui/zero-install.glade | 154 +---------------------------- 4 files changed, 25 insertions(+), 162 deletions(-) diff --git a/zeroinstall/0launch-gui/dialog.py b/zeroinstall/0launch-gui/dialog.py index cac1dcf..15f91c2 100644 --- a/zeroinstall/0launch-gui/dialog.py +++ b/zeroinstall/0launch-gui/dialog.py @@ -34,8 +34,9 @@ def alert(parent, message, type = gtk.MESSAGE_ERROR): box.connect('response', resp) box.show() -def MixedButton(message, stock, x_align = 0.5): - button = gtk.Button() +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) diff --git a/zeroinstall/0launch-gui/mainwindow.py b/zeroinstall/0launch-gui/mainwindow.py index e53e1c6..16caa32 100644 --- a/zeroinstall/0launch-gui/mainwindow.py +++ b/zeroinstall/0launch-gui/mainwindow.py @@ -16,6 +16,7 @@ class MainWindow: progress = None browser = None window = None + cancel_download_and_run = None def __init__(self, download_only): widgets = policy.widgets @@ -39,10 +40,14 @@ class MainWindow: prefs = widgets.get_widget('preferences') self.window.action_area.set_child_secondary(prefs, True) + # Glade won't let me add this to the template! if download_only: - unused = widgets.get_widget('run').hide() + run_button = dialog.MixedButton("_Download", gtk.STOCK_EXECUTE, button = gtk.ToggleButton()) else: - unused = widgets.get_widget('download').hide() + run_button = dialog.MixedButton("_Run", gtk.STOCK_EXECUTE, button = gtk.ToggleButton()) + self.window.add_action_widget(run_button, gtk.RESPONSE_OK) + run_button.show_all() + run_button.set_flags(gtk.CAN_DEFAULT) self.window.set_default_response(gtk.RESPONSE_OK) self.window.default_widget.grab_focus() @@ -52,7 +57,11 @@ class MainWindow: self.window.destroy() sys.exit(1) elif resp == gtk.RESPONSE_OK: - task = tasks.Task(self.download_and_run(), "download and run") + if self.cancel_download_and_run: + self.cancel_download_and_run.trigger() + if run_button.get_active(): + self.cancel_download_and_run = tasks.Blocker("cancel downloads") + tasks.Task(self.download_and_run(run_button, self.cancel_download_and_run), "download and run") elif resp == gtk.RESPONSE_HELP: gui_help.display() elif resp == SHOW_PREFERENCES: @@ -72,13 +81,17 @@ class MainWindow: def destroyed(self): policy.abort_all_downloads() - def download_and_run(self): + def download_and_run(self, run_button, cancelled): try: task = tasks.Task(policy.download_impls(), "download implementations") - yield task.finished + blockers = [task.finished, cancelled] + yield blockers + tasks.check(blockers) - tasks.check(task.finished) + if cancelled.happened: + policy.abort_all_downloads() + return if policy.get_uncached_implementations(): dialog.alert('Not all downloads succeeded; cannot run program.') @@ -91,8 +104,10 @@ class MainWindow: self.window.destroy() sys.exit(0) # Success except SafeException, ex: + run_button.set_active(False) policy.handler.report_error(ex) except Exception, ex: + run_button.set_active(False) import traceback traceback.print_exc() policy.handler.report_error(ex) diff --git a/zeroinstall/0launch-gui/preferences.py b/zeroinstall/0launch-gui/preferences.py index 6046615..63439b8 100644 --- a/zeroinstall/0launch-gui/preferences.py +++ b/zeroinstall/0launch-gui/preferences.py @@ -65,7 +65,6 @@ class Preferences: self.window.default_widget.grab_focus() def response(dialog, resp): - import download_box if resp in (gtk.RESPONSE_CLOSE, gtk.RESPONSE_DELETE_EVENT): self.window.destroy() elif resp == gtk.RESPONSE_HELP: diff --git a/zeroinstall/0launch-gui/zero-install.glade b/zeroinstall/0launch-gui/zero-install.glade index 7d78c88..1c661ce 100644 --- a/zeroinstall/0launch-gui/zero-install.glade +++ b/zeroinstall/0launch-gui/zero-install.glade @@ -68,158 +68,6 @@ -6 - - - - True - True - True - True - True - GTK_RELIEF_NORMAL - True - -5 - - - - True - 0.5 - 0.5 - 0 - 0 - 0 - 0 - 0 - 0 - - - - True - False - 2 - - - - True - gtk-network - 4 - 0.5 - 0.5 - 0 - 0 - - - 0 - False - False - - - - - - True - Download - True - False - GTK_JUSTIFY_LEFT - False - False - 0.5 - 0.5 - 0 - 0 - PANGO_ELLIPSIZE_NONE - -1 - False - 0 - - - 0 - False - False - - - - - - - - - - - - True - True - True - GTK_RELIEF_NORMAL - True - -5 - - - - True - 0.5 - 0.5 - 0 - 0 - 0 - 0 - 0 - 0 - - - - True - False - 2 - - - - True - gtk-execute - 4 - 0.5 - 0.5 - 0 - 0 - - - 0 - False - False - - - - - - True - Run - True - False - GTK_JUSTIFY_LEFT - False - False - 0.5 - 0.5 - 0 - 0 - PANGO_ELLIPSIZE_NONE - -1 - False - 0 - - - 0 - False - False - - - - - - - - 0 @@ -313,7 +161,7 @@ True - _Refresh all now + Re_fresh all now True False GTK_JUSTIFY_LEFT -- 2.11.4.GIT