Moved logwindow dispay out of BorgendTray, and made notification_center

Sun, 21 Jan 2018 22:38:01 +0000

author
Tuomo Valkonen <tuomov@iki.fi>
date
Sun, 21 Jan 2018 22:38:01 +0000
changeset 42
00accd11978b
parent 41
e2641cb9ca6d
child 43
8f3ac19f11b6

Moved logwindow dispay out of BorgendTray, and made notification_center
display it (if it would work)

ui.py file | annotate | diff | comparison | revisions
--- 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