diff --git a/deluge/ui/gtkui/gtkui.py b/deluge/ui/gtkui/gtkui.py index b0b8b88b3..e25bbb07d 100644 --- a/deluge/ui/gtkui/gtkui.py +++ b/deluge/ui/gtkui/gtkui.py @@ -146,10 +146,6 @@ class GtkUI: except: pass - # Twisted catches signals to terminate, so just have it call the shutdown - # method. - reactor.addSystemEventTrigger("after", "shutdown", self.shutdown) - if deluge.common.windows_check(): from win32api import SetConsoleCtrlHandler from win32con import CTRL_CLOSE_EVENT @@ -201,16 +197,11 @@ class GtkUI: self.connectionmanager = ConnectionManager() reactor.callWhenRunning(self._on_reactor_start) - # Start the gtk main loop - try: - gtk.gdk.threads_enter() - reactor.run() - gtk.gdk.threads_leave() - except KeyboardInterrupt: - self.shutdown() - else: - self.shutdown() + gtk.gdk.threads_enter() + reactor.run() + self.shutdown() + gtk.gdk.threads_leave() def shutdown(self, *args, **kwargs): log.debug("gtkui shutting down..") @@ -223,6 +214,7 @@ class GtkUI: # Shutdown all components component.shutdown() + if self.started_in_classic: try: client.daemon.shutdown() @@ -232,13 +224,10 @@ class GtkUI: # Make sure the config is saved. self.config.save() - try: - gtk.main_quit() - except RuntimeError: - pass - def _on_reactor_start(self): log.debug("_on_reactor_start") + self.mainwindow.first_show() + if self.config["classic_mode"]: try: client.start_classic_mode() diff --git a/deluge/ui/gtkui/mainwindow.py b/deluge/ui/gtkui/mainwindow.py index a732654be..862e5684a 100644 --- a/deluge/ui/gtkui/mainwindow.py +++ b/deluge/ui/gtkui/mainwindow.py @@ -72,6 +72,7 @@ class MainWindow(component.Component): except: self.window.set_icon(common.get_logo(32)) self.vpaned = self.main_glade.get_widget("vpaned") + self.initial_vpaned_position = self.config["window_pane_position"] # Load the window state self.load_window_state() @@ -93,14 +94,18 @@ class MainWindow(component.Component): self.config.register_set_function("show_rate_in_title", self._on_set_show_rate_in_title, apply_now=False) + client.register_event_handler("NewVersionAvailableEvent", self.on_newversionavailable_event) + client.register_event_handler("TorrentFinishedEvent", self.on_torrentfinished_event) + + def first_show(self): if not(self.config["start_in_tray"] and \ self.config["enable_system_tray"]) and not \ self.window.get_property("visible"): log.debug("Showing window") self.show() - - client.register_event_handler("NewVersionAvailableEvent", self.on_newversionavailable_event) - client.register_event_handler("TorrentFinishedEvent", self.on_torrentfinished_event) + while gtk.events_pending(): + gtk.main_iteration(False) + self.vpaned.set_position(self.initial_vpaned_position) def show(self): try: @@ -112,6 +117,7 @@ class MainWindow(component.Component): self.window.show() + def hide(self): component.pause("TorrentView") component.pause("StatusBar") @@ -162,8 +168,6 @@ class MainWindow(component.Component): self.window.resize(w, h) if self.config["window_maximized"]: self.window.maximize() - self.vpaned.set_position( - self.config["window_height"] - self.config["window_pane_position"]) def on_window_configure_event(self, widget, event): if not self.config["window_maximized"] and self.visible: @@ -204,7 +208,7 @@ class MainWindow(component.Component): return True def on_vpaned_position_event(self, obj, param): - self.config["window_pane_position"] = self.config["window_height"] - self.vpaned.get_position() + self.config["window_pane_position"] = self.vpaned.get_position() def on_drag_data_received_event(self, widget, drag_context, x, y, selection_data, info, timestamp): args = []