From a92d307486cf484b2c7372016263020464af1ba8 Mon Sep 17 00:00:00 2001 From: Uriziel Date: Fri, 21 Sep 2012 12:28:49 +0200 Subject: [PATCH] Proper behaviour on configuration window close --- syncplay/client.py | 11 +++++++---- syncplay/ui/GuiConfiguration.py | 14 +++++++++++++- 2 files changed, 20 insertions(+), 5 deletions(-) diff --git a/syncplay/client.py b/syncplay/client.py index 6584e49..c0b5d40 100644 --- a/syncplay/client.py +++ b/syncplay/client.py @@ -527,9 +527,10 @@ class SyncplayClientManager(object): from syncplay import ui from syncplay.ConfigurationGetter import ConfigurationGetter +from syncplay.ConfigurationGetter import InvalidConfigValue from syncplay.ui.GuiConfiguration import GuiConfiguration - - +import sys + class SyncplayClient(object): def __init__(self): self._prepareArguments() @@ -540,9 +541,11 @@ class SyncplayClient(object): try: self._promptForMissingArguments() self.argsGetter.saveValuesIntoConfigFile() - except: + except InvalidConfigValue: self._checkAndSaveConfiguration() - + except GuiConfiguration.WindowClosed: + sys.exit() + def _prepareArguments(self): self.argsGetter = ConfigurationGetter() self.args = self.argsGetter.getConfiguration() diff --git a/syncplay/ui/GuiConfiguration.py b/syncplay/ui/GuiConfiguration.py index 58d9a68..70c04d1 100644 --- a/syncplay/ui/GuiConfiguration.py +++ b/syncplay/ui/GuiConfiguration.py @@ -8,10 +8,11 @@ import cairo, gio, pango, atk, pangocairo, gobject #@UnusedImport class GuiConfiguration: def __init__(self, args, force = False): self.args = args + self.closedAndNotSaved = False if(args.host == None or args.name == None or force): self.window = gtk.Window(gtk.WINDOW_TOPLEVEL) self.window.set_title("Syncplay Configuration") - self.window.connect("delete_event", lambda w, e: gtk.main_quit()) + self.window.connect("delete_event", lambda w, e: self._windowClosed()) vbox = gtk.VBox(False, 0) self.window.add(vbox) vbox.show() @@ -26,6 +27,11 @@ class GuiConfiguration: button.show() self.window.show() gtk.main() + + def _windowClosed(self): + self.window.destroy() + gtk.main_quit() + self.closedAndNotSaved = True def _addLabeledEntries(self, args, vbox): self.hostEntry = self._addLabeledEntryToVbox('Host: ', args.host, vbox, self._focusNext) @@ -34,6 +40,8 @@ class GuiConfiguration: self.passEntry = self._addLabeledEntryToVbox('Server password (optional): ', args.password, vbox, self._focusNext) def getProcessedConfiguration(self): + if(self.closedAndNotSaved): + raise self.WindowClosed return self.args def _saveDataAndLeave(self): @@ -70,6 +78,10 @@ class GuiConfiguration: hbox.show() return entry + class WindowClosed(Exception): + def __init__(self): + Exception.__init__(self) + class GuiConfigurationForMPC(GuiConfiguration): def __init__(self, args, force = False): force = (args.mpc_path == None) or force