ui.py

changeset 42
00accd11978b
parent 40
cfbeeec8cb82
child 45
aa2a95dc6093
--- a/ui.py	Sun Jan 21 22:01:57 2018 +0000
+++ b/ui.py	Sun Jan 21 22:38:01 2018 +0000
@@ -142,7 +142,6 @@
             menu, state=self.__rebuild_menu()
 
             self.refresh_timer=None
-            self.logwindow=None
 
             super().__init__(traynames[state], menu=menu, quit_button=None)
 
@@ -164,7 +163,7 @@
             menu.append(item)
             state=combine_state(state, this_state)
 
-        menu_log=rumps.MenuItem("Show log", callback=self.showlog)
+        menu_log=rumps.MenuItem("Show log", callback=lambda _: showlog())
         menu.append(menu_log)
 
         if not settings['no_quit_menu_entry']:
@@ -217,22 +216,38 @@
             notification_workaround(borgend.appname_stylised,
                                     err.__class__.__name__, str(err))
 
-    @rumps.notifications
-    def notification_center(data):
-        pass
+#
+# Log window
+#
 
-    def showlog(self, _):
-        try:
-            if not self.logwindow:
+logwindow=[None]
+logwindow_lock=Lock()
+
+def showlog():
+    try:
+        w=None
+        with logwindow_lock:
+            if not logwindow[0]:
                 lines=borgend.fifolog.formatAll()
                 msg="\n".join(lines[0:])
-                self.logwindow=rumps.Window(title=borgend.appname_stylised+' log',
-                                            default_text=msg,
-                                            ok='Close',
-                                            dimensions=(640,320))
-                self.logwindow.run()
-                # Does not return until closed
-                self.logwindow=None
-        except Exception as err:
-            utils.log_exception(logger, err)
+                w=rumps.Window(title=borgend.appname_stylised+' log',
+                               default_text=msg,
+                               ok='Close',
+                               dimensions=(640,320))
+                logwindow[0]=w
+        if w:
+            try:
+                w.run()
+            finally:
+                with logwindow_lock:
+                    logwindow[0]=None
+    except Exception as err:
+        utils.log_exception(logger, err)
 
+#
+# Notification click response => show log window
+#
+
+@rumps.notifications
+def notification_center(_):
+    showlog()

mercurial