always try to initialize systray icon and notifications
This commit is contained in:
parent
feedbcf581
commit
9c621d5816
|
|
@ -23,10 +23,6 @@ def _require(module, os_package):
|
||||||
def _parse_arguments():
|
def _parse_arguments():
|
||||||
import argparse
|
import argparse
|
||||||
arg_parser = argparse.ArgumentParser(prog=NAME.lower())
|
arg_parser = argparse.ArgumentParser(prog=NAME.lower())
|
||||||
arg_parser.add_argument('-S', '--no-systray', action='store_false', dest='systray',
|
|
||||||
help='do not place an icon in the desktop\'s systray')
|
|
||||||
arg_parser.add_argument('-N', '--no-notifications', action='store_false', dest='notifications',
|
|
||||||
help='disable desktop notifications (shown only when in systray)')
|
|
||||||
arg_parser.add_argument('-d', '--debug', action='count', default=0,
|
arg_parser.add_argument('-d', '--debug', action='count', default=0,
|
||||||
help='print logging messages, for debugging purposes (may be repeated for extra verbosity)')
|
help='print logging messages, for debugging purposes (may be repeated for extra verbosity)')
|
||||||
arg_parser.add_argument('-V', '--version', action='version', version='%(prog)s ' + __version__)
|
arg_parser.add_argument('-V', '--version', action='version', version='%(prog)s ' + __version__)
|
||||||
|
|
@ -47,25 +43,15 @@ def _parse_arguments():
|
||||||
def _run(args):
|
def _run(args):
|
||||||
import solaar.ui as ui
|
import solaar.ui as ui
|
||||||
|
|
||||||
# even if --no-notifications is given on the command line, still have to
|
ui.notify.init()
|
||||||
# check they are available, and decide whether to put the option in the
|
|
||||||
# systray icon
|
|
||||||
args.notifications &= args.systray
|
|
||||||
if args.systray and ui.notify.init(NAME):
|
|
||||||
ui.action.toggle_notifications.set_active(args.notifications)
|
|
||||||
if not args.notifications:
|
|
||||||
ui.notify.uninit()
|
|
||||||
else:
|
|
||||||
ui.action.toggle_notifications = None
|
|
||||||
|
|
||||||
from solaar.listener import DUMMY, ReceiverListener
|
from solaar.listener import DUMMY, ReceiverListener
|
||||||
window = ui.main_window.create(NAME, DUMMY.name, DUMMY.max_devices, args.systray)
|
window = ui.main_window.create(NAME, DUMMY.name, 6, True)
|
||||||
if args.systray:
|
assert window
|
||||||
menu_actions = (ui.action.toggle_notifications,
|
menu_actions = (ui.action.toggle_notifications,
|
||||||
ui.action.about)
|
ui.action.about)
|
||||||
icon = ui.status_icon.create(window, menu_actions)
|
icon = ui.status_icon.create(window, menu_actions)
|
||||||
else:
|
assert icon
|
||||||
icon = None
|
|
||||||
|
|
||||||
listener = [None]
|
listener = [None]
|
||||||
|
|
||||||
|
|
@ -114,10 +100,13 @@ def _run(args):
|
||||||
|
|
||||||
if listener[0]:
|
if listener[0]:
|
||||||
listener[0].stop()
|
listener[0].stop()
|
||||||
listener[0].join()
|
|
||||||
|
|
||||||
ui.notify.uninit()
|
ui.notify.uninit()
|
||||||
|
|
||||||
|
if listener[0]:
|
||||||
|
listener[0].join()
|
||||||
|
listener[0] = None
|
||||||
|
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
_require('pyudev', 'python-pyudev')
|
_require('pyudev', 'python-pyudev')
|
||||||
|
|
|
||||||
|
|
@ -13,6 +13,7 @@ try:
|
||||||
from . import icons as _icons
|
from . import icons as _icons
|
||||||
|
|
||||||
|
|
||||||
|
_NAMESPACE = 'Solaar'
|
||||||
# assumed to be working since the import succeeded
|
# assumed to be working since the import succeeded
|
||||||
available = True
|
available = True
|
||||||
|
|
||||||
|
|
@ -20,14 +21,14 @@ try:
|
||||||
# while its notification is still visible we don't create another one
|
# while its notification is still visible we don't create another one
|
||||||
_notifications = {}
|
_notifications = {}
|
||||||
|
|
||||||
def init(app_title):
|
def init():
|
||||||
"""Init the notifications system."""
|
"""Init the notifications system."""
|
||||||
global available
|
global available
|
||||||
if available:
|
if available:
|
||||||
if not Notify.is_initted():
|
if not Notify.is_initted():
|
||||||
logging.info("starting desktop notifications")
|
logging.info("starting desktop notifications")
|
||||||
try:
|
try:
|
||||||
return Notify.init(app_title)
|
return Notify.init(_NAMESPACE)
|
||||||
except:
|
except:
|
||||||
logging.exception("initializing desktop notifications")
|
logging.exception("initializing desktop notifications")
|
||||||
available = False
|
available = False
|
||||||
|
|
@ -41,6 +42,15 @@ try:
|
||||||
Notify.uninit()
|
Notify.uninit()
|
||||||
|
|
||||||
|
|
||||||
|
def toggle(action):
|
||||||
|
if action.get_active():
|
||||||
|
init()
|
||||||
|
else:
|
||||||
|
uninit()
|
||||||
|
action.set_sensitive(available)
|
||||||
|
return action.get_active()
|
||||||
|
|
||||||
|
|
||||||
def show(dev, reason=None):
|
def show(dev, reason=None):
|
||||||
"""Show a notification with title and text."""
|
"""Show a notification with title and text."""
|
||||||
if available and Notify.is_initted():
|
if available and Notify.is_initted():
|
||||||
|
|
@ -68,6 +78,7 @@ try:
|
||||||
|
|
||||||
except ImportError:
|
except ImportError:
|
||||||
available = False
|
available = False
|
||||||
init = lambda app_title: False
|
init = lambda: False
|
||||||
uninit = lambda: None
|
uninit = lambda: None
|
||||||
show = lambda dev, reason: None
|
toggle = lambda action: False
|
||||||
|
show = lambda dev, reason=None: None
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue