- Changed 'hidden' from transient to config value
- Commented entrypoint - Cleaned up entrypoint - Reimplemented 'hide'/'show' options for systray
This commit is contained in:
parent
1f6eb658c1
commit
81beb4950a
4 changed files with 126 additions and 28 deletions
|
|
@ -145,19 +145,9 @@ class Discover:
|
|||
if "--steamos" in data or "-s" in data:
|
||||
self.steamos = True
|
||||
if "--hide" in data:
|
||||
if self.voice_overlay:
|
||||
self.voice_overlay.set_hidden(True)
|
||||
if self.text_overlay:
|
||||
self.text_overlay.set_hidden(True)
|
||||
if self.notification_overlay:
|
||||
self.notification_overlay.set_hidden(True)
|
||||
self.config_set("general", "hideoverlay", "True")
|
||||
if "--show" in data:
|
||||
if self.voice_overlay:
|
||||
self.voice_overlay.set_hidden(False)
|
||||
if self.text_overlay:
|
||||
self.text_overlay.set_hidden(False)
|
||||
if self.notification_overlay:
|
||||
self.notification_overlay.set_hidden(False)
|
||||
self.config_set("general", "hideoverlay", "False")
|
||||
if "--mute" in data:
|
||||
if self.connection:
|
||||
self.connection.set_mute(True)
|
||||
|
|
@ -182,6 +172,15 @@ class Discover:
|
|||
if self.connection:
|
||||
self.connection.request_text_rooms_for_guild(match.group(1))
|
||||
|
||||
def config_set(self, context, key, value):
|
||||
config = ConfigParser(interpolation=None)
|
||||
config.read(self.config_file)
|
||||
if not context in config.sections():
|
||||
config.add_section(context)
|
||||
config.set(context, key, value)
|
||||
with open(self.config_file, 'w') as file:
|
||||
config.write(file)
|
||||
|
||||
def rpc_changed(self, _a=None, _b=None, _c=None, _d=None):
|
||||
"""
|
||||
Called when the RPC file has been altered
|
||||
|
|
@ -391,6 +390,11 @@ class Discover:
|
|||
self.set_force_xshape(
|
||||
config.getboolean("general", "xshape", fallback=False))
|
||||
|
||||
hidden = config.getboolean("general", "hideoverlay", fallback=False)
|
||||
self.voice_overlay.set_hidden(hidden)
|
||||
self.text_overlay.set_hidden(hidden)
|
||||
self.notification_overlay.set_hidden(hidden)
|
||||
|
||||
def get_monitor_index(self, name):
|
||||
"""
|
||||
Helper function to find the index number of the monitor
|
||||
|
|
@ -479,23 +483,26 @@ def entrypoint():
|
|||
"""
|
||||
Entry Point.
|
||||
|
||||
Check for PID & RPC.
|
||||
Find all needed file locations and read args
|
||||
|
||||
If an overlay is already running then pass the args along and close
|
||||
if '--rpc' simply pass them over the rpc file
|
||||
|
||||
Otherwise start up the overlay!
|
||||
if '-c' or '--configure' start the config window only
|
||||
|
||||
otherwise start overlay
|
||||
"""
|
||||
|
||||
# Find Config directory
|
||||
config_dir = os.path.join(xdg_config_home, "discover_overlay")
|
||||
os.makedirs(config_dir, exist_ok=True)
|
||||
line = ""
|
||||
for arg in sys.argv[1:]:
|
||||
line = "%s %s" % (line, arg)
|
||||
|
||||
# Find RPC, Channel info, config and debug files
|
||||
rpc_file = os.path.join(config_dir, "discover_overlay.rpc")
|
||||
channel_file = os.path.join(config_dir, "channels.rpc")
|
||||
config_file = os.path.join(config_dir, "config.ini")
|
||||
debug_file = os.path.join(config_dir, "output.txt")
|
||||
|
||||
# Prepare logger
|
||||
logging.getLogger().setLevel(logging.INFO)
|
||||
FORMAT = "%(levelname)s - %(name)s - %(message)s"
|
||||
if "--debug" in sys.argv or "-v" in sys.argv:
|
||||
|
|
@ -506,21 +513,30 @@ def entrypoint():
|
|||
log = logging.getLogger(__name__)
|
||||
log.info("Starting Discover Overlay: %s",
|
||||
pkg_resources.get_distribution('discover_overlay').version)
|
||||
|
||||
# Catch any errors and log them
|
||||
try:
|
||||
if "--rpc" in sys.argv:
|
||||
# Send command to overlay
|
||||
line = ""
|
||||
for arg in sys.argv[1:]:
|
||||
line = "%s %s" % (line, arg)
|
||||
with open(rpc_file, "w") as tfile:
|
||||
tfile.write(line)
|
||||
log.warning("Sent RPC command")
|
||||
else:
|
||||
if "-c" in sys.argv or "--configure" in sys.argv:
|
||||
# Show config window
|
||||
settings = MainSettingsWindow(
|
||||
config_file, rpc_file, channel_file, sys.argv[1:])
|
||||
Gtk.main()
|
||||
sys.exit(0)
|
||||
with open(rpc_file, "w") as tfile:
|
||||
tfile.write("--close")
|
||||
Discover(rpc_file, config_file, channel_file,
|
||||
debug_file, sys.argv[1:])
|
||||
else:
|
||||
# Tell any other running overlay to close
|
||||
with open(rpc_file, "w") as tfile:
|
||||
tfile.write("--close")
|
||||
# Show the overlay
|
||||
Discover(rpc_file, config_file, channel_file,
|
||||
debug_file, sys.argv[1:])
|
||||
return
|
||||
|
||||
except Exception as ex:
|
||||
|
|
|
|||
|
|
@ -2091,7 +2091,7 @@
|
|||
</packing>
|
||||
</child>
|
||||
<child>
|
||||
<!-- n-columns=2 n-rows=4 -->
|
||||
<!-- n-columns=2 n-rows=5 -->
|
||||
<object class="GtkGrid">
|
||||
<property name="visible">True</property>
|
||||
<property name="can-focus">False</property>
|
||||
|
|
@ -2207,6 +2207,31 @@
|
|||
<property name="top-attach">1</property>
|
||||
</packing>
|
||||
</child>
|
||||
<child>
|
||||
<object class="GtkLabel">
|
||||
<property name="visible">True</property>
|
||||
<property name="can-focus">False</property>
|
||||
<property name="label" translatable="yes">Hide overlays</property>
|
||||
<property name="xalign">0</property>
|
||||
</object>
|
||||
<packing>
|
||||
<property name="left-attach">0</property>
|
||||
<property name="top-attach">4</property>
|
||||
</packing>
|
||||
</child>
|
||||
<child>
|
||||
<object class="GtkCheckButton">
|
||||
<property name="name">core_hide_overlay</property>
|
||||
<property name="visible">True</property>
|
||||
<property name="can-focus">True</property>
|
||||
<property name="receives-default">False</property>
|
||||
<property name="draw-indicator">True</property>
|
||||
</object>
|
||||
<packing>
|
||||
<property name="left-attach">1</property>
|
||||
<property name="top-attach">4</property>
|
||||
</packing>
|
||||
</child>
|
||||
</object>
|
||||
<packing>
|
||||
<property name="position">4</property>
|
||||
|
|
|
|||
|
|
@ -642,7 +642,6 @@
|
|||
<property name="can-focus">False</property>
|
||||
<property name="row-spacing">1</property>
|
||||
<property name="column-spacing">5</property>
|
||||
<property name="row-homogeneous">True</property>
|
||||
<property name="column-homogeneous">True</property>
|
||||
<child>
|
||||
<object class="GtkFontButton">
|
||||
|
|
@ -2092,7 +2091,7 @@
|
|||
</packing>
|
||||
</child>
|
||||
<child>
|
||||
<!-- n-columns=2 n-rows=4 -->
|
||||
<!-- n-columns=2 n-rows=5 -->
|
||||
<object class="GtkGrid">
|
||||
<property name="visible">True</property>
|
||||
<property name="can-focus">False</property>
|
||||
|
|
@ -2208,6 +2207,32 @@
|
|||
<property name="top-attach">1</property>
|
||||
</packing>
|
||||
</child>
|
||||
<child>
|
||||
<object class="GtkLabel">
|
||||
<property name="visible">True</property>
|
||||
<property name="can-focus">False</property>
|
||||
<property name="label" translatable="yes">Hide overlays</property>
|
||||
<property name="xalign">0</property>
|
||||
</object>
|
||||
<packing>
|
||||
<property name="left-attach">0</property>
|
||||
<property name="top-attach">4</property>
|
||||
</packing>
|
||||
</child>
|
||||
<child>
|
||||
<object class="GtkCheckButton">
|
||||
<property name="name">core_hide_overlay</property>
|
||||
<property name="visible">True</property>
|
||||
<property name="can-focus">True</property>
|
||||
<property name="receives-default">False</property>
|
||||
<property name="draw-indicator">True</property>
|
||||
<signal name="toggled" handler="core_hide_overlay_changed" swapped="no"/>
|
||||
</object>
|
||||
<packing>
|
||||
<property name="left-attach">1</property>
|
||||
<property name="top-attach">4</property>
|
||||
</packing>
|
||||
</child>
|
||||
</object>
|
||||
<packing>
|
||||
<property name="position">4</property>
|
||||
|
|
|
|||
|
|
@ -51,6 +51,7 @@ class MainSettingsWindow():
|
|||
self.channel_ids = []
|
||||
self.current_guild = "0"
|
||||
self.current_channel = "0"
|
||||
self.hidden_overlay = False
|
||||
|
||||
self.menu = self.make_menu()
|
||||
self.make_sys_tray_icon(self.menu)
|
||||
|
|
@ -125,17 +126,20 @@ class MainSettingsWindow():
|
|||
self.monitor_channel = channel_file.monitor_file(0, None)
|
||||
self.monitor_channel.connect("changed", self.populate_guild_menu)
|
||||
|
||||
self.read_config()
|
||||
self.server_handler = self.widget['text_server'].connect(
|
||||
'changed', self.text_server_changed)
|
||||
self.channel_handler = self.widget['text_channel'].connect(
|
||||
'changed', self.text_channel_changed)
|
||||
self.hidden_overlay_handler = self.widget['core_hide_overlay'].connect(
|
||||
'toggled', self.core_hide_overlay_changed)
|
||||
|
||||
self.read_config()
|
||||
|
||||
self.populate_guild_menu()
|
||||
|
||||
builder.connect_signals(self)
|
||||
print(args)
|
||||
if not ( self.show_sys_tray_icon and '--minimized' in self.args ):
|
||||
if not (self.show_sys_tray_icon and '--minimized' in self.args):
|
||||
window.show()
|
||||
|
||||
def request_channels_from_guild(self, guild_id):
|
||||
|
|
@ -445,6 +449,9 @@ class MainSettingsWindow():
|
|||
"general", "showsystray", fallback=True)
|
||||
self.set_sys_tray_icon_visible(self.show_sys_tray_icon)
|
||||
self.widget['core_show_tray_icon'].set_active(self.show_sys_tray_icon)
|
||||
self.hidden_overlay = self.show_sys_tray_icon = config.getboolean(
|
||||
"general", "hideoverlay", fallback=False)
|
||||
self.update_toggle_overlay()
|
||||
|
||||
def make_colour(self, col):
|
||||
col = json.loads(col)
|
||||
|
|
@ -533,19 +540,41 @@ class MainSettingsWindow():
|
|||
"""
|
||||
menu = Gtk.Menu()
|
||||
settings_opt = Gtk.MenuItem.new_with_label(_("Settings"))
|
||||
self.toggle_opt = Gtk.MenuItem.new_with_label(_("Hide overlay"))
|
||||
close_overlay_opt = Gtk.MenuItem.new_with_label(_("Close Overlay"))
|
||||
close_opt = Gtk.MenuItem.new_with_label(_("Close Settings"))
|
||||
|
||||
menu.append(settings_opt)
|
||||
menu.append(self.toggle_opt)
|
||||
menu.append(close_overlay_opt)
|
||||
menu.append(close_opt)
|
||||
|
||||
settings_opt.connect("activate", self.present_settings)
|
||||
self.toggle_opt.connect("activate", self.toggle_overlay)
|
||||
close_overlay_opt.connect("activate", self.close_overlay)
|
||||
close_opt.connect("activate", self.close_app)
|
||||
menu.show_all()
|
||||
return menu
|
||||
|
||||
def toggle_overlay(self, _a=None, _b=None):
|
||||
self.hidden_overlay = not self.hidden_overlay
|
||||
print("TOGGLE TO %s" % (self.hidden_overlay))
|
||||
self.config_set("general", "hideoverlay", "%s" % (self.hidden_overlay))
|
||||
self.update_toggle_overlay()
|
||||
|
||||
def update_toggle_overlay(self, _a=None, _b=None):
|
||||
self.widget['core_hide_overlay'].handler_block(
|
||||
self.hidden_overlay_handler)
|
||||
|
||||
self.widget['core_hide_overlay'].set_active(self.hidden_overlay)
|
||||
|
||||
self.widget['core_hide_overlay'].handler_unblock(
|
||||
self.hidden_overlay_handler)
|
||||
if self.hidden_overlay:
|
||||
self.toggle_opt.set_label(_("Show overlay"))
|
||||
else:
|
||||
self.toggle_opt.set_label(_("Hide overlay"))
|
||||
|
||||
def close_overlay(self, _a=None, _b=None):
|
||||
with open(self.rpc_file, 'w') as f:
|
||||
f.write('--rpc --close')
|
||||
|
|
@ -955,3 +984,6 @@ class MainSettingsWindow():
|
|||
def core_show_tray_icon_changed(self, button):
|
||||
self.set_sys_tray_icon_visible(button.get_active())
|
||||
self.config_set("general", "showsystray", "%s" % (button.get_active()))
|
||||
|
||||
def core_hide_overlay_changed(self, button):
|
||||
self.toggle_overlay()
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue