-
Notifications
You must be signed in to change notification settings - Fork 20
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Minimized to Tray #167
base: main
Are you sure you want to change the base?
Minimized to Tray #167
Changes from all commits
97943e4
6824a9e
2b4f091
cdae061
63928ad
ed82e77
fd4fd9b
c72f791
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,6 +14,7 @@ Frédéric Péters <[email protected]> | |
* Frédéric Péters <[email protected]> | ||
* Daniel Sheeler <[email protected]> | ||
* Athanasios Silis <[email protected]> | ||
* Ryno Kotze <[email protected]> | ||
|
||
|
||
# Translation | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -34,7 +34,7 @@ | |
from .serialization import SerializedObject, Serializator | ||
from .styling import load_css_styles | ||
from .version import __version__ | ||
|
||
from .indicator import Indicator | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please keep imports from the '.' package in alphabetical order, unless other reasons prevent it. |
||
|
||
__program__ = "jack_mixer" | ||
# A "locale" directory present within the package take precedence | ||
|
@@ -92,7 +92,8 @@ class JackMixer(SerializedObject): | |
# scales suitable as volume slider scales | ||
slider_scales = [scale.Linear30dB(), scale.Linear70dB()] | ||
|
||
def __init__(self, client_name=__program__): | ||
def __init__(self, client_name=__program__, minimized=False): | ||
self.minimize_on_start = minimized | ||
Comment on lines
+95
to
+96
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please name the init arg the same as the instance attribute, i.e. |
||
self.visible = False | ||
self.nsm_client = None | ||
# name of project file that is currently open | ||
|
@@ -103,6 +104,9 @@ def __init__(self, client_name=__program__): | |
self.last_xml_serialization = None | ||
self.cached_xml_serialization = None | ||
|
||
log.info("Starting %s %s", __program__, __version__) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please change the log level to DEBUG. |
||
self.indicator = Indicator(self) | ||
|
||
if os.environ.get("NSM_URL"): | ||
self.nsm_client = NSMClient( | ||
prettyName=__program__, | ||
|
@@ -719,7 +723,14 @@ def on_save_as_cb(self, *args): | |
dlg.destroy() | ||
|
||
def on_quit_cb(self, *args, on_delete=False): | ||
if not self.nsm_client and self.gui_factory.get_confirm_quit(): | ||
log.info("on_quit_cb") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please remove this log call. |
||
if self.indicator.available and self.gui_factory.get_tray_minimized(): | ||
log.info("on_quit_cb: hiding window") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please remove this log call. |
||
self.window.set_visible(False) | ||
return True | ||
|
||
elif not self.nsm_client and self.gui_factory.get_confirm_quit(): | ||
log.info("on_quit_cb: confirm quit") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please remove this log call. |
||
dlg = Gtk.MessageDialog( | ||
parent=self.window, | ||
message_type=Gtk.MessageType.QUESTION, | ||
|
@@ -741,6 +752,7 @@ def on_quit_cb(self, *args, on_delete=False): | |
if response != Gtk.ResponseType.OK: | ||
return on_delete | ||
|
||
log.info("on_quit_cb: quitting") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please remove this log call. |
||
Gtk.main_quit() | ||
|
||
def on_shrink_channels_cb(self, widget): | ||
|
@@ -1049,7 +1061,7 @@ def save_to_xml(self, file): | |
b.save(file) | ||
|
||
def load_from_xml(self, file, silence_errors=False, from_nsm=False): | ||
log.debug("Loading from XML...") | ||
log.debug("Loading from XML... YES WE ARE!") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please remove this logging message change. |
||
self.unserialized_channels = [] | ||
b = XmlSerialization() | ||
try: | ||
|
@@ -1146,11 +1158,17 @@ def main(self): | |
if not self.mixer: | ||
return | ||
|
||
if self.visible or self.nsm_client is None: | ||
width, height = self.window.get_size() | ||
self.window.show_all() | ||
if hasattr(self, "paned_position"): | ||
self.paned.set_position(self.paned_position / self.width * width) | ||
if not self.minimize_on_start: | ||
log.info("Showing main window") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please change the log level to DEBUG. |
||
if self.visible or self.nsm_client is None: | ||
width, height = self.window.get_size() | ||
self.window.show_all() | ||
if hasattr(self, "paned_position"): | ||
self.paned.set_position(self.paned_position / self.width * width) | ||
else: | ||
if self.indicator.available: | ||
Comment on lines
+1168
to
+1169
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Make this an |
||
log.info("Minimizing main window") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please change the log level to DEBUG. |
||
self.window.hide() | ||
|
||
signal.signal(signal.SIGUSR1, self.sighandler) | ||
signal.signal(signal.SIGTERM, self.sighandler) | ||
|
@@ -1176,7 +1194,16 @@ def error_dialog(parent, msg, *args, **kw): | |
|
||
|
||
def main(): | ||
log.debug("JACK Mixer version %s" % __version__) | ||
sys.stdout.flush() | ||
parser = argparse.ArgumentParser(prog=__program__, description=_(__doc__.splitlines()[0])) | ||
parser.add_argument( | ||
"-m", | ||
"--minimized", | ||
action="store_true", | ||
default=False, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The default for |
||
help=_("start JACK Mixer minimized to system tray (default: %(default)s) If system tray is available."), | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. "start application minimized to system tray if system tray is available (default: no)" ( Please update translation message catalog to include this string. |
||
) | ||
parser.add_argument( | ||
"-c", | ||
"--config", | ||
|
@@ -1204,7 +1231,7 @@ def main(): | |
) | ||
|
||
try: | ||
mixer = JackMixer(args.client_name) | ||
mixer = JackMixer(args.client_name, args.minimized) | ||
except Exception as e: | ||
error_dialog(None, _("Mixer creation failed:\n\n{}"), e, debug=args.debug) | ||
sys.exit(1) | ||
|
@@ -1230,6 +1257,5 @@ def main(): | |
mixer.main() | ||
mixer.cleanup() | ||
|
||
|
||
if __name__ == "__main__": | ||
main() |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
import gi | ||
try: | ||
gi.require_version('Gtk', '3.0') | ||
except Exception as e: | ||
print(e) | ||
print('Repository version required not present') | ||
exit(1) | ||
|
||
try: | ||
from gi.repository import AppIndicator3 as appindicator | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This triggers the following warning. Please insert the appropriate
|
||
except ImportError: | ||
appindicator = None | ||
|
||
import os | ||
import logging as log | ||
from gi.repository import Gtk | ||
from os import environ, path | ||
|
||
prefix = environ.get('MESON_INSTALL_PREFIX', '/usr') | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This won't work. |
||
datadir = path.join(prefix, 'share') | ||
icondir = path.join(datadir, 'icons', 'hicolor', 'scalable', 'apps') | ||
|
||
class Indicator: | ||
def __init__(self, jack_mixer): | ||
self.app = jack_mixer | ||
if appindicator is None: | ||
log.warning('AppIndicator3 not found, indicator will not be available') | ||
self.available = False | ||
return | ||
self.available = True | ||
icon = os.path.join(icondir, 'jack_mixer.svg') | ||
self.indicator = appindicator.Indicator.new("Jack Mixer", | ||
icon, | ||
appindicator.IndicatorCategory.APPLICATION_STATUS) | ||
self.indicator.set_status(appindicator.IndicatorStatus.ACTIVE) | ||
self.indicator.set_menu(self.create_menu()) | ||
|
||
def create_menu(self): | ||
self.menu = Gtk.Menu() | ||
self.menu.set_title('Jack Mixer') | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The title should not be hard-coded here. I suggest you make it an init keyword arg and pass it from There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. For example: def __init__(self, app, name, icon=None):
self.available = bool(appindicator)
if appindicator is None:
log.warning('AppIndicator3 not found, indicator will not be available')
return
self.app = app
self.name = name
self.indicator = appindicator.Indicator.new(
name,
icon or name,
appindicator.IndicatorCategory.APPLICATION_STATUS)
self.indicator.set_status(appindicator.IndicatorStatus.ACTIVE)
self.indicator.set_menu(self.create_menu())
def create_menu(self):
self.menu = Gtk.Menu()
self.menu.set_title(self.name)
.... |
||
|
||
self.hidewindow = Gtk.MenuItem(label = 'Hide / Show Jack Mixer') | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This string should be translatable. |
||
self.hidewindow.connect('activate', self.hideshow) | ||
self.menu.append(self.hidewindow) | ||
|
||
self.separator = Gtk.SeparatorMenuItem() | ||
self.menu.append(self.separator) | ||
|
||
self.exittray = Gtk.MenuItem(label = 'Quit') | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This string should be translatable. |
||
self.exittray.connect('activate', self.quit) | ||
self.menu.append(self.exittray) | ||
|
||
self.menu.show_all() | ||
return self.menu | ||
|
||
def hideshow(self, source): | ||
self.app.window.set_visible(not self.app.window.get_visible()) | ||
|
||
def quit(self, source, on_delete=False): | ||
if not self.app.nsm_client and self.app.gui_factory.get_confirm_quit(): | ||
dlg = Gtk.MessageDialog( | ||
parent=self.app.window, | ||
message_type=Gtk.MessageType.QUESTION, | ||
buttons=Gtk.ButtonsType.NONE, | ||
) | ||
dlg.set_markup(_("<b>Quit application?</b>")) | ||
dlg.format_secondary_markup( | ||
_( | ||
"All jack_mixer ports will be closed and connections lost," | ||
"\nstopping all sound going through jack_mixer.\n\n" | ||
"Are you sure?" | ||
) | ||
) | ||
dlg.add_buttons( | ||
Gtk.STOCK_CANCEL, Gtk.ResponseType.CANCEL, Gtk.STOCK_QUIT, Gtk.ResponseType.OK | ||
) | ||
response = dlg.run() | ||
dlg.destroy() | ||
if response != Gtk.ResponseType.OK: | ||
return on_delete | ||
Comment on lines
+60
to
+80
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please don't duplicate code from |
||
|
||
Gtk.main_quit() |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -53,6 +53,7 @@ python_sources = files([ | |
'serialization_xml.py', | ||
'slider.py', | ||
'styling.py', | ||
'indicator.py', | ||
]) | ||
|
||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -80,6 +80,15 @@ def create_ui(self): | |
self.language_box.pack_start(Gtk.Label(_("Language:")), False, True, 5) | ||
self.language_box.pack_start(self.language_combo, True, True, 0) | ||
|
||
if self.app.indicator.available: | ||
self.tray_minimized_checkbutton = Gtk.CheckButton(_("Minimize to tray")) | ||
self.tray_minimized_checkbutton.set_tooltip_text( | ||
_("Minimize the application to the system tray when the window is closed") | ||
) | ||
Comment on lines
+84
to
+87
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please update the translation message catalog for these new translatable strings. |
||
self.tray_minimized_checkbutton.set_active(self.app.gui_factory.get_tray_minimized()) | ||
self.tray_minimized_checkbutton.connect("toggled", self.on_tray_minimized_toggled) | ||
interface_vbox.pack_start(self.tray_minimized_checkbutton, True, True, 3) | ||
|
||
self.confirm_quit_checkbutton = Gtk.CheckButton(_("Confirm quit")) | ||
self.confirm_quit_checkbutton.set_tooltip_text( | ||
_("Always ask for confirmation before quitting the application") | ||
|
@@ -336,6 +345,9 @@ def on_vumeter_color_change(self, *args): | |
|
||
self.custom_color_box.set_sensitive(self.vumeter_color_checkbutton.get_active()) | ||
|
||
def on_tray_minimized_toggled(self, *args): | ||
self.app.gui_factory.set_tray_minimized(self.tray_minimized_checkbutton.get_active()) | ||
|
||
def on_confirm_quit_toggled(self, *args): | ||
self.app.gui_factory.set_confirm_quit(self.confirm_quit_checkbutton.get_active()) | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
[Unit] | ||
Description=Jack Mixer Service | ||
Requires=pipewire.socket | ||
After=graphical.target pwg.service | ||
|
||
[Service] | ||
Type=simple | ||
ExecStart=/usr/local/bin/jack_mixer --minimized --config /home/lemonxah/.config/jack_mixer/lemonxah.xml | ||
ExecStop=/bin/kill -9 $MAINPID | ||
Restart=always | ||
|
||
[Install] | ||
WantedBy=default.target | ||
Comment on lines
+1
to
+13
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is a different feature. Please make a separate PR for it and remove it from this one. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this you real name? If not, please use a less gross Pseudonym.