diff options
author | B Stack <bgstack15@gmail.com> | 2020-09-27 17:29:21 -0400 |
---|---|---|
committer | B Stack <bgstack15@gmail.com> | 2020-09-27 17:29:21 -0400 |
commit | fe40ba2086c76c87544a3b9f70ab9f7fb6b05c30 (patch) | |
tree | 92a7ba28dc1025d3dde60b1ec8269d1cb236722f /src/usr | |
parent | handle if user config does not exist (diff) | |
download | myautomount-fe40ba2086c76c87544a3b9f70ab9f7fb6b05c30.tar.gz myautomount-fe40ba2086c76c87544a3b9f70ab9f7fb6b05c30.tar.bz2 myautomount-fe40ba2086c76c87544a3b9f70ab9f7fb6b05c30.zip |
add XApp.StatusIcon support
Diffstat (limited to 'src/usr')
-rwxr-xr-x | src/usr/libexec/myautomount/myautomount-trayicon.py | 45 |
1 files changed, 32 insertions, 13 deletions
diff --git a/src/usr/libexec/myautomount/myautomount-trayicon.py b/src/usr/libexec/myautomount/myautomount-trayicon.py index db20055..276cbfe 100755 --- a/src/usr/libexec/myautomount/myautomount-trayicon.py +++ b/src/usr/libexec/myautomount/myautomount-trayicon.py @@ -16,18 +16,24 @@ # https://stackoverflow.com/questions/28279363/python-way-to-get-mounted-filesystems/28279434#28279434 # timer https://python-gtk-3-tutorial.readthedocs.io/en/latest/spinner.html?highlight=timer#id1 # Improve: -# move out user configs to separate file in ~/.config/myautomount, but using the xdg spec. -# add all headers +# Add notifications, perhaps with xnotify (https://github.com/phillbush/xnotify)? # Dependencies: # dep-devuan: autofs, python3-pyinotify -# dep-fedora: +# dep-fedora: autofs, python3-inotify # dep-pip: inotify # python-inotify, the seb-m one. -# And whatever provides Gtk 3.0 for python3. +# And whatever provides Gtk 3.0 for python3, probably python3-gobject +# If you want WITH_XAPP_SUPPORT=1, +# dep-fedora: python3-xapps-overrides +# dep-devuan: python3-xapp +WITH_XAPP_SUPPORT = 0 import gi, os, fnmatch, sys, pyinotify, time, subprocess gi.require_version("Gtk","3.0") from gi.repository import Gtk, Gdk, GLib +if WITH_XAPP_SUPPORT: + gi.require_version("XApp","1.0") + from gi.repository import XApp import xdg.DesktopEntry as dentry import xdg.Exceptions as exc @@ -185,15 +191,24 @@ def desktopfilelist(params): filelist.append(os.path.join(root, i)) return filelist -class MainIcon(Gtk.StatusIcon): +CLASSTYPE=XApp.StatusIcon if WITH_XAPP_SUPPORT else Gtk.StatusIcon +class MainIcon(CLASSTYPE): def __init__(self): - Gtk.StatusIcon.__init__(self) - self.set_from_icon_name("media-removable") + CLASSTYPE.__init__(self) self.traymenu = Gtk.Menu() - self.connect("button-press-event", self.on_button_press_event) - self.connect("popup-menu", self.context_menu) - if only_update_on_menuitem != 1: - self.connect("query-tooltip", self.mouseover) + if WITH_XAPP_SUPPORT: + # XApp.StatusIcon + self.set_icon_name("media-removable") + self.set_secondary_menu(self.traymenu) + self.set_primary_menu(self.traymenu) + # XApp.StatusIcon has no mechanism for query-tooltip, so a timer will be set in reestablish_menu. + else: + # Gtk.StatusIcon + self.set_from_icon_name("media-removable") + self.connect("popup-menu", self.context_menu) + if only_update_on_menuitem != 1: + self.connect("query-tooltip", self.mouseover) + self.connect("button-press-event", self.on_button_press_event) # need these anyway, for when the icon is hidden. self.wm1 = pyinotify.WatchManager() self.s1 = pyinotify.Stats() @@ -243,8 +258,11 @@ class MainIcon(Gtk.StatusIcon): print(f"hide_when_no_media={hide_when_no_media}") print(f"menuitem_count={self.menuitem_count}") if str(hide_when_no_media) == "1" and self.menuitem_count == 0: - print("hiding self, from reestablishmenu") + print("hiding icon because no entries, because hide_when_no_media=1") self.hide() + elif WITH_XAPP_SUPPORT: + # Xapp.StatusIcon has no mechanism for query-tooltip (mouseover), so must always poll + self.start_timer() def execute(self, widget): x=0 ; y=-1 @@ -334,7 +352,8 @@ class MainIcon(Gtk.StatusIcon): self.reestablish_menu() else: print("No changes...") - self.hide() + #self.hide() + self.start_timer() def on_timeout(self, *args, **kwargs): """ A timeout function """ |