ui: add option to show the main window or run solaar without tray

This commit is contained in:
Peter F. Patel-Schneider 2020-02-05 15:34:54 -05:00 committed by Filipe Laíns
parent 5afa094175
commit 4afe8c893b
4 changed files with 24 additions and 20 deletions

View File

@ -48,7 +48,7 @@ def _parse_arguments():
help='unifying receiver to use; the first detected receiver if unspecified. Example: /dev/hidraw2')
arg_parser.add_argument('--restart-on-wake-up', action='store_true',
help='restart Solaar on sleep wake-up (experimental)')
arg_parser.add_argument('-t', '--tray', action='store_true', help='start GUI with only tray icon')
arg_parser.add_argument('-w', '--window', choices=('hide','show','only'), help='start with window hidden / showing / only (no tray icon)')
arg_parser.add_argument('-V', '--version', action='version', version='%(prog)s ' + __version__)
arg_parser.add_argument('--help-actions', action='store_true',
help='print help for the optional actions')
@ -61,6 +61,9 @@ def _parse_arguments():
_cli.print_help()
return
if args.window is None:
args.window = 'hide'
import logging
if args.debug > 0:
log_level = logging.WARNING - 10 * args.debug
@ -106,7 +109,7 @@ def main():
_upower.watch(listener.ping_all)
# main UI event loop
ui.run_loop(listener.start_all, listener.stop_all, args.tray)
ui.run_loop(listener.start_all, listener.stop_all, args.window!='only', args.window!='hide')
except Exception as e:
import sys
sys.exit('%s: error: %s' % (NAME.lower(), e))

View File

@ -86,7 +86,7 @@ def ui_async(function, *args, **kwargs):
from . import notify, tray, window
def _startup(app, startup_hook, tray_only):
def _startup(app, startup_hook, use_tray, show_window):
if _log.isEnabledFor(_DEBUG):
_log.debug("startup registered=%s, remote=%s", app.get_is_registered(), app.get_is_remote())
@ -96,8 +96,9 @@ def _startup(app, startup_hook, tray_only):
_task_runner.start()
notify.init()
tray.init(lambda _ignore: window.destroy())
window.init(tray_only)
if use_tray:
tray.init(lambda _ignore: window.destroy())
window.init(show_window, use_tray)
startup_hook()
@ -133,12 +134,13 @@ def _shutdown(app, shutdown_hook):
notify.uninit()
def run_loop(startup_hook, shutdown_hook, tray_only, args=None):
def run_loop(startup_hook, shutdown_hook, use_tray, show_window, args=None):
assert use_tray or show_window, 'need either tray or visible window'
# from gi.repository.Gio import ApplicationFlags as _ApplicationFlags
APP_ID = 'io.github.pwr.solaar'
application = Gtk.Application.new(APP_ID, 0) # _ApplicationFlags.HANDLES_COMMAND_LINE)
application.connect('startup', lambda app, startup_hook:_startup(app,startup_hook,tray_only), startup_hook)
application.connect('startup', lambda app, startup_hook:_startup(app,startup_hook,use_tray,show_window), startup_hook)
application.connect('command-line', _command_line)
application.connect('activate', _activate)
application.connect('shutdown', _shutdown, shutdown_hook)

View File

@ -458,10 +458,10 @@ def init(_quit_handler):
def destroy():
global _icon, _menu, _devices_info
assert _icon is not None
i, _icon = _icon, None
_destroy(i)
i = None
if _icon is not None:
i, _icon = _icon, None
_destroy(i)
i = None
_icon = None
_menu = None

View File

@ -304,11 +304,10 @@ def _create_window_layout():
panel.pack_start(_info, True, True, 0)
panel.pack_start(_empty, True, True, 0)
about_button = _new_button(_("About") + ' ' + NAME, 'help-about',
icon_size=_SMALL_BUTTON_ICON_SIZE, clicked=_show_about_window)
bottom_buttons_box = Gtk.ButtonBox(Gtk.Orientation.HORIZONTAL)
bottom_buttons_box.set_layout(Gtk.ButtonBoxStyle.START)
about_button = _new_button(_("About") + ' ' + NAME, 'help-about',
icon_size=_SMALL_BUTTON_ICON_SIZE, clicked=_show_about_window)
bottom_buttons_box.add(about_button)
# solaar_version = Gtk.Label()
@ -327,7 +326,7 @@ def _create_window_layout():
return vbox
def _create():
def _create(delete_action):
window = Gtk.Window()
window.set_title(NAME)
window.set_role('status-window')
@ -335,7 +334,7 @@ def _create():
# window.set_type_hint(Gdk.WindowTypeHint.UTILITY)
# window.set_skip_taskbar_hint(True)
# window.set_skip_pager_hint(True)
window.connect('delete-event', _hide)
window.connect('delete-event', delete_action)
vbox = _create_window_layout()
window.add(vbox)
@ -731,7 +730,7 @@ _empty = None
_window = None
def init(tray_only):
def init(show_window,hide_on_close):
Gtk.Window.set_default_icon_name(NAME.lower())
Gtk.Window.set_default_icon_from_file(_icons.icon_file(NAME.lower()))
@ -741,12 +740,12 @@ def init(tray_only):
_details = _create_details_panel()
_info = _create_info_panel()
_empty = _create_empty_panel()
_window = _create()
if (not tray_only) :
_window = _create(_hide if hide_on_close else destroy)
if show_window:
_window.present()
def destroy():
def destroy(_ignore1=None, _ignore2=None):
global _model, _tree, _details, _info, _empty, _window
w, _window = _window, None
w.destroy()