Merge pull request #142 from TastyPi/master
Add a setting for enabling/disabling the tray icon
This commit is contained in:
commit
70feb71b09
3 changed files with 53 additions and 15 deletions
|
|
@ -82,8 +82,7 @@ class Discover:
|
|||
self.text_overlay = TextOverlayWindow(self)
|
||||
self.menu = self.make_menu()
|
||||
self.make_sys_tray_icon(self.menu)
|
||||
self.settings = MainSettingsWindow(
|
||||
self.text_overlay, self.voice_overlay)
|
||||
self.settings = MainSettingsWindow(self)
|
||||
|
||||
def make_sys_tray_icon(self, menu):
|
||||
"""
|
||||
|
|
@ -98,7 +97,8 @@ class Discover:
|
|||
"discover_overlay",
|
||||
"discover-overlay-tray",
|
||||
AppIndicator3.IndicatorCategory.APPLICATION_STATUS)
|
||||
self.ind.set_status(AppIndicator3.IndicatorStatus.ACTIVE)
|
||||
# Hide for now since we don't know if it should be shown yet
|
||||
self.ind.set_status(AppIndicator3.IndicatorStatus.PASSIVE)
|
||||
self.ind.set_menu(menu)
|
||||
except (ImportError, ValueError) as exception:
|
||||
# Create System Tray
|
||||
|
|
@ -106,6 +106,8 @@ class Discover:
|
|||
self.tray = Gtk.StatusIcon.new_from_icon_name(
|
||||
"discover-overlay-tray")
|
||||
self.tray.connect('popup-menu', self.show_menu)
|
||||
# Hide for now since we don't know if it should be shown yet
|
||||
self.tray.set_visible(False)
|
||||
|
||||
def make_menu(self):
|
||||
"""
|
||||
|
|
@ -143,6 +145,25 @@ class Discover:
|
|||
"""
|
||||
Gtk.main_quit()
|
||||
|
||||
def set_force_xshape(self, force):
|
||||
"""
|
||||
Set if XShape should be forced
|
||||
"""
|
||||
self.voice_overlay.set_force_xshape(force)
|
||||
self.text_overlay.set_force_xshape(force)
|
||||
|
||||
def set_sys_tray_icon_visible(self, visible):
|
||||
"""
|
||||
Sets whether the tray icon is visible
|
||||
"""
|
||||
if self.ind is not None:
|
||||
# pylint: disable=import-outside-toplevel
|
||||
from gi.repository import AppIndicator3
|
||||
self.ind.set_status(
|
||||
AppIndicator3.IndicatorStatus.ACTIVE if visible else AppIndicator3.IndicatorStatus.PASSIVE)
|
||||
elif self.tray is not None:
|
||||
self.tray.set_visible(visible)
|
||||
|
||||
|
||||
def entrypoint():
|
||||
"""
|
||||
|
|
|
|||
|
|
@ -23,11 +23,11 @@ from gi.repository import Gtk
|
|||
class GeneralSettingsWindow(SettingsWindow):
|
||||
"""Core Settings Tab"""
|
||||
|
||||
def __init__(self, overlay, overlay2):
|
||||
def __init__(self, discover):
|
||||
SettingsWindow.__init__(self)
|
||||
self.overlay = overlay
|
||||
self.overlay2 = overlay2
|
||||
self.discover = discover
|
||||
self.xshape = None
|
||||
self.show_sys_tray_icon = None
|
||||
self.set_size_request(400, 200)
|
||||
self.connect("destroy", self.close_window)
|
||||
self.connect("delete-event", self.close_window)
|
||||
|
|
@ -44,10 +44,11 @@ class GeneralSettingsWindow(SettingsWindow):
|
|||
config = ConfigParser(interpolation=None)
|
||||
config.read(self.config_file)
|
||||
self.xshape = config.getboolean("general", "xshape", fallback=False)
|
||||
self.show_sys_tray_icon = config.getboolean("general", "showsystray", fallback=True)
|
||||
|
||||
# Pass all of our config over to the overlay
|
||||
self.overlay.set_force_xshape(self.xshape)
|
||||
self.overlay2.set_force_xshape(self.xshape)
|
||||
self.discover.set_force_xshape(self.xshape)
|
||||
self.discover.set_sys_tray_icon_visible(self.show_sys_tray_icon)
|
||||
|
||||
def save_config(self):
|
||||
"""
|
||||
|
|
@ -59,6 +60,7 @@ class GeneralSettingsWindow(SettingsWindow):
|
|||
config.add_section("general")
|
||||
|
||||
config.set("general", "xshape", "%d" % (int(self.xshape)))
|
||||
config.set("general", "showsystray", "yes" if self.show_sys_tray_icon else "no")
|
||||
|
||||
with open(self.config_file, 'w') as file:
|
||||
config.write(file)
|
||||
|
|
@ -81,10 +83,18 @@ class GeneralSettingsWindow(SettingsWindow):
|
|||
xshape.set_active(self.xshape)
|
||||
xshape.connect("toggled", self.change_xshape)
|
||||
|
||||
# Show sys tray
|
||||
show_sys_tray_icon_label = Gtk.Label.new("Show tray icon")
|
||||
show_sys_tray_icon = Gtk.CheckButton.new()
|
||||
show_sys_tray_icon.set_active(self.show_sys_tray_icon)
|
||||
show_sys_tray_icon.connect("toggled", self.change_show_sys_tray_icon)
|
||||
|
||||
box.attach(autostart_label, 0, 0, 1, 1)
|
||||
box.attach(autostart, 1, 0, 1, 1)
|
||||
box.attach(xshape_label, 0, 1, 1, 1)
|
||||
box.attach(xshape, 1, 1, 1, 1)
|
||||
box.attach(show_sys_tray_icon_label, 0, 2, 1, 1)
|
||||
box.attach(show_sys_tray_icon, 1, 2, 1, 1)
|
||||
|
||||
self.add(box)
|
||||
|
||||
|
|
@ -99,7 +109,14 @@ class GeneralSettingsWindow(SettingsWindow):
|
|||
"""
|
||||
XShape setting changed
|
||||
"""
|
||||
self.overlay.set_force_xshape(button.get_active())
|
||||
self.overlay2.set_force_xshape(button.get_active())
|
||||
self.discover.set_force_xshape(button.get_active())
|
||||
self.xshape = button.get_active()
|
||||
self.save_config()
|
||||
|
||||
def change_show_sys_tray_icon(self, button):
|
||||
"""
|
||||
Show tray icon setting changed
|
||||
"""
|
||||
self.discover.set_sys_tray_icon_visible(button.get_active())
|
||||
self.show_sys_tray_icon = button.get_active()
|
||||
self.save_config()
|
||||
|
|
|
|||
|
|
@ -23,14 +23,15 @@ from gi.repository import Gtk
|
|||
class MainSettingsWindow(Gtk.Window):
|
||||
"""Settings window holding all settings tab"""
|
||||
|
||||
def __init__(self, text_overlay, voice_overlay):
|
||||
def __init__(self, discover):
|
||||
Gtk.Window.__init__(self)
|
||||
|
||||
self.connect("destroy", self.close_window)
|
||||
self.connect("delete-event", self.close_window)
|
||||
|
||||
self.text_overlay = text_overlay
|
||||
self.voice_overlay = voice_overlay
|
||||
self.discover = discover
|
||||
self.text_overlay = discover.text_overlay
|
||||
self.voice_overlay = discover.voice_overlay
|
||||
self.set_title("Discover Overlay Configuration")
|
||||
self.set_icon_name("discover-overlay")
|
||||
self.set_default_size(280, 180)
|
||||
|
|
@ -45,8 +46,7 @@ class MainSettingsWindow(Gtk.Window):
|
|||
self.text_settings = TextSettingsWindow(self.text_overlay)
|
||||
notebook.append_page(self.text_settings)
|
||||
notebook.set_tab_label_text(self.text_settings, "Text")
|
||||
self.core_settings = GeneralSettingsWindow(
|
||||
self.text_overlay, self.voice_overlay)
|
||||
self.core_settings = GeneralSettingsWindow(self.discover)
|
||||
notebook.append_page(self.core_settings)
|
||||
notebook.set_tab_label_text(self.core_settings, "Core")
|
||||
self.add(notebook)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue