Let customize menu's quit handler
This commit is contained in:
parent
410e35c6ec
commit
068451c2ed
|
@ -63,6 +63,13 @@ class LadiStatusIcon (LadiMenu, LadiApp):
|
|||
def on_about(self, *args):
|
||||
LadiMenu.on_about(self, version=get_version_string())
|
||||
|
||||
def quit(self, *args, **kwargs):
|
||||
# Some default config might need to be injected in the config file,
|
||||
# we handle all that before we quit.
|
||||
self.global_config.set_config_section (self.appname, self.config_dict)
|
||||
self.global_config.save ()
|
||||
Gtk.main_quit()
|
||||
|
||||
def set_tooltip_text(self, text): pass
|
||||
|
||||
def __init__ (self, config_filename = None):
|
||||
|
@ -79,7 +86,9 @@ class LadiStatusIcon (LadiMenu, LadiApp):
|
|||
self.config_dict = self.global_config.get_config_section (self.appname)
|
||||
autostart = bool(eval(self.config_dict['autostart']))
|
||||
# Build the UI
|
||||
LadiMenu.__init__(self, autostart)
|
||||
LadiMenu.__init__(self,
|
||||
autostart,
|
||||
quit = self.quit)
|
||||
|
||||
def menu_activate(self, status_icon, button, activate_time, user_data=None):
|
||||
menu = self.create_menu()
|
||||
|
@ -102,11 +111,6 @@ class LadiStatusIcon (LadiMenu, LadiApp):
|
|||
|
||||
def run(self):
|
||||
Gtk.main ()
|
||||
# Some default config might need to be injected in the config file,
|
||||
# we handle all that before we quit.
|
||||
self.global_config.set_config_section (self.appname, self.config_dict)
|
||||
self.global_config.save ()
|
||||
return 0
|
||||
|
||||
class LadiStatusTray(Gtk.StatusIcon, LadiStatusIcon):
|
||||
|
||||
|
@ -214,7 +218,7 @@ class LadiStatusIndicator(LadiStatusIcon):
|
|||
menu_items.append((Gtk.SeparatorMenuItem.new(),))
|
||||
if hasattr(self, 'on_about'):
|
||||
menu_items.append((Gtk.ImageMenuItem(_("About")), self.on_about, None))
|
||||
menu_items.append((Gtk.ImageMenuItem(_("Quit")), self.on_menu_command, Gtk.main_quit))
|
||||
menu_items.append((Gtk.ImageMenuItem(_("Quit")), self.on_menu_command, self.quit))
|
||||
|
||||
menu = Gtk.Menu()
|
||||
for menu_tuple in menu_items:
|
||||
|
@ -251,9 +255,10 @@ if __name__ == "__main__":
|
|||
'monitor JACK, as well as start some JACK related applications'),
|
||||
epilog=_('This program is part of the LADITools suite.'))
|
||||
parser.add_argument('--version', action='version', version="%(prog)s " + get_version_string())
|
||||
|
||||
parser.parse_args()
|
||||
|
||||
Gtk.init(None)
|
||||
|
||||
if AppIndicator3:
|
||||
LadiStatusIndicator().run()
|
||||
else:
|
||||
|
|
|
@ -27,9 +27,15 @@ from .. import _gettext_domain
|
|||
from .manager import LadiManagerGtk
|
||||
|
||||
class LadiMenu(LadiManagerGtk):
|
||||
def __init__(self, jack_autostart):
|
||||
|
||||
def __init__(self, jack_autostart, **kwargs):
|
||||
|
||||
LadiManagerGtk.__init__(self, jack_autostart)
|
||||
|
||||
self.handler = { 'quit' : Gtk.main_quit, }
|
||||
if 'quit_handler' in kwargs:
|
||||
self.handler['quit'] = kwargs['quit']
|
||||
|
||||
def on_menu_show_diagnose(self, widget, data=None):
|
||||
dlg = Gtk.MessageDialog(None,
|
||||
Gtk.DialogFlags.MODAL,
|
||||
|
@ -174,7 +180,7 @@ class LadiMenu(LadiManagerGtk):
|
|||
menu_items.append((Gtk.SeparatorMenuItem.new(), None, None))
|
||||
if hasattr(self, 'on_about'):
|
||||
menu_items.append((Gtk.ImageMenuItem(_("About")), self.on_about, None))
|
||||
menu_items.append((Gtk.ImageMenuItem(_("Quit")), self.on_menu_command, Gtk.main_quit))
|
||||
menu_items.append((Gtk.ImageMenuItem(_("Quit")), self.on_menu_command, self.handler['quit']))
|
||||
|
||||
for menu_tuple in menu_items:
|
||||
item = menu_tuple[0]
|
||||
|
|
Loading…
Reference in New Issue