From 49500d3c75bc59f1d6b9fc5f585dd3b6f130d3d9 Mon Sep 17 00:00:00 2001 From: Trigg Date: Thu, 14 Jul 2022 16:36:18 +0000 Subject: [PATCH] - warning : broken - Started refactor to separate config gui completely --- discover_overlay/about_settings.py | 83 - discover_overlay/discord_connector.py | 49 +- discover_overlay/discover_overlay.py | 366 ++-- discover_overlay/glade/settings.glade | 2192 ++++++++++++++++++++++++ discover_overlay/glade/settings.glade~ | 2192 ++++++++++++++++++++++++ discover_overlay/overlay.py | 12 +- discover_overlay/settings_window.py | 414 ++++- setup.py | 2 +- 8 files changed, 5023 insertions(+), 287 deletions(-) delete mode 100644 discover_overlay/about_settings.py create mode 100644 discover_overlay/glade/settings.glade create mode 100644 discover_overlay/glade/settings.glade~ diff --git a/discover_overlay/about_settings.py b/discover_overlay/about_settings.py deleted file mode 100644 index 0a899d4..0000000 --- a/discover_overlay/about_settings.py +++ /dev/null @@ -1,83 +0,0 @@ -# This program is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with this program. If not, see . -"""Overview setting tab on settings window""" -import gettext -import json -import logging -import pkg_resources -from configparser import ConfigParser -import gi -import sys -from .settings import SettingsWindow - -log = logging.getLogger(__name__) -t = gettext.translation('default', pkg_resources.resource_filename( - 'discover_overlay', 'locales'), fallback=True) -_ = t.gettext - -gi.require_version("Gtk", "3.0") -# pylint: disable=wrong-import-position,wrong-import-order -from gi.repository import Gtk, Gdk, GLib # nopep8 - - -GUILD_DEFAULT_VALUE = "0" - - -class AboutSettingsWindow(Gtk.Grid): - """Basic overview and a nicer looking landing page for Steam Deck""" - - def __init__(self, discover): - Gtk.Grid.__init__(self) - self.discover = discover - self.create_gui() - - def create_gui(self): - """ - Prepare the gui - """ - spacing_box_1 = Gtk.Box() - spacing_box_1.set_size_request(60, 60) - self.attach(spacing_box_1, 1, 0, 1, 1) - - icon = Gtk.Image.new_from_icon_name("discover-overlay-tray", 256) - icon.set_pixel_size(128) - self.attach(icon, 1, 1, 1, 1) - - spacing_box_2 = Gtk.Box() - spacing_box_2.set_size_request(60, 60) - self.attach(spacing_box_2, 1, 2, 1, 1) - - blurb = Gtk.Label.new(None) - message = "%s (%s)\n\n%s\n\n%s (https://discord.gg/jRKWMuDy5V) %s (https://github.com/trigg/Discover)\n\n\n\n\n\n" % ( - _("Welcome to Discover Overlay"), - pkg_resources.get_distribution('discover_overlay').version, - _("Discover-Overlay is a GTK3 overlay written in Python3. It can be configured to show who is currently talking on discord or it can be set to display text and images from a preconfigured channel. It is fully customisable and can be configured to display anywhere on the screen. We fully support X11 and wlroots based environments. We felt the need to make this project due to the shortcomings in support on Linux by the official discord client."), - _("Please visit our discord"), - _(" for support. Or open an issue on our GitHub ") - ) - blurb.set_markup(message) - blurb.set_line_wrap(True) - self.attach(blurb, 1, 3, 1, 1) - - killapp = Gtk.Button.new_with_label(_("Close overlay")) - killapp.connect("pressed", self.close_app) - self.attach(killapp, 1, 5, 1, 1) - - self.set_column_homogeneous(True) - - def close_app(self, button): - log.info("Quit pressed") - sys.exit(0) - - def present_settings(self): - self.show_all() diff --git a/discover_overlay/discord_connector.py b/discover_overlay/discord_connector.py index a7ed805..5d19027 100644 --- a/discover_overlay/discord_connector.py +++ b/discover_overlay/discord_connector.py @@ -126,6 +126,7 @@ class DiscordConnector: self.current_text = "0" return if channel != self.current_text: + self.current_text = channel self.start_listening_text(channel) if need_req: self.req_channel_details(channel) @@ -305,7 +306,8 @@ class DiscordConnector: self.set_in_room(j["data"]["user_id"], True) elif j["evt"] == "VOICE_CHANNEL_SELECT": if j["data"]["channel_id"]: - self.set_channel(j["data"]["channel_id"], j["data"]["guild_id"]) + self.set_channel(j["data"]["channel_id"], + j["data"]["guild_id"]) else: self.set_channel(None, None) elif j["evt"] == "VOICE_CONNECTION_STATUS": @@ -344,15 +346,18 @@ class DiscordConnector: elif j["cmd"] == "GET_GUILDS": for guild in j["data"]["guilds"]: self.guilds[guild["id"]] = guild - if len(self.discover.settings.voice_settings.guild_ids) == 0 or guild["id"] in self.discover.settings.voice_settings.guild_ids: - self.req_channels(guild["id"]) + # TODO Update settings window with guild/channel list + # self.discover.settings.add_guild(guild["id"]) + # if len(self.discover.settings.voice_settings.guild_ids) == 0 or guild["id"] in self.discover.settings.voice_settings.guild_ids: + # self.req_channels(guild["id"]) return elif j["cmd"] == "GET_GUILD": # We currently only get here because of a "CHANNEL_CREATE" event. Stupidly long winded way around if j["data"]: guild = j["data"] - if len(self.discover.settings.voice_settings.guild_ids) == 0 or guild["id"] in self.discover.settings.voice_settings.guild_ids: - self.req_channels(guild["id"]) + # TODO Check if this is the guild in text settings, if so request an update list + # if len(self.discover.settings.voice_settings.guild_ids) == 0 or guild["id"] in self.discover.settings.voice_settings.guild_ids: + # self.req_channels(guild["id"]) return elif j["cmd"] == "GET_CHANNELS": self.guilds[j['nonce']]["channels"] = j["data"]["channels"] @@ -362,9 +367,10 @@ class DiscordConnector: self.channels[channel["id"]] = channel if channel["type"] == 2: self.req_channel_details(channel["id"]) - if j["nonce"] == self.discover.settings.text_settings.get_guild(): - self.discover.settings.text_settings.set_channels(j["data"]["channels"]) - self.check_guilds() + # TODO At this point change the channel list in settings + # if j["nonce"] == self.discover.settings.text_settings.get_guild(): + # self.discover.settings.text_settings.set_channels( + # j["data"]["channels"]) return elif j["cmd"] == "SUBSCRIBE": # Only log errors @@ -375,10 +381,12 @@ class DiscordConnector: return elif j["cmd"] == "GET_SELECTED_VOICE_CHANNEL": if 'data' in j and j['data'] and 'id' in j['data']: - self.set_channel(j['data']['id'],j['data']['guild_id']) - self.discover.voice_overlay.set_channel_title(j["data"]["name"]) + self.set_channel(j['data']['id'], j['data']['guild_id']) + self.discover.voice_overlay.set_channel_title( + j["data"]["name"]) if self.current_guild in self.guilds and 'icon_url' in self.guilds[self.current_guild]: - self.discover.voice_overlay.set_channel_icon(self.guilds[self.current_guild]['icon_url']) + self.discover.voice_overlay.set_channel_icon( + self.guilds[self.current_guild]['icon_url']) else: self.discover.voice_overlay.set_channel_icon(None) self.list_altered = True @@ -418,14 +426,6 @@ class DiscordConnector: return log.warning(j) - def check_guilds(self): - """ - Check if all of the guilds contain a channel - """ - for guild in self.guilds.values(): - if len(self.discover.settings.voice_settings.guild_ids) > 0 and guild["id"] in self.discover.settings.voice_settings.guild_ids and "channels" not in guild: - return - def on_connected(self): """ Called when connection is finalised @@ -686,9 +686,6 @@ class DiscordConnector: Called at 60Hz approximately but has near zero bearing on rendering """ - if self.discover.show_settings_delay: - self.discover.show_settings_delay = False - self.discover.show_settings() # Ensure connection if not self.websocket: if self.reconnect_delay <= 0: @@ -713,13 +710,9 @@ class DiscordConnector: if self.discover.text_overlay.popup_style: self.text_altered = True if self.text_altered: - self.discover.text_overlay.set_text_list(self.text, self.text_altered) + self.discover.text_overlay.set_text_list( + self.text, self.text_altered) self.text_altered = False - # Update guilds - self.discover.settings.text_settings.set_guilds(self.guilds) - # Check for changed channel - if self.authed: - self.set_text_channel(self.discover.settings.text_settings.get_channel()) if len(self.rate_limited_channels) > 0: guild = self.rate_limited_channels.pop() diff --git a/discover_overlay/discover_overlay.py b/discover_overlay/discover_overlay.py index d84c609..2da55d2 100755 --- a/discover_overlay/discover_overlay.py +++ b/discover_overlay/discover_overlay.py @@ -19,8 +19,11 @@ import re import traceback import logging import pkg_resources +import json import gi import pidfile +from configparser import ConfigParser + from .settings_window import MainSettingsWindow from .voice_overlay import VoiceOverlayWindow from .text_overlay import TextOverlayWindow @@ -29,7 +32,7 @@ from .discord_connector import DiscordConnector gi.require_version("Gtk", "3.0") # pylint: disable=wrong-import-position,wrong-import-order -from gi.repository import Gtk, GLib, Gio # nopep8 +from gi.repository import Gtk, GLib, Gio, Gdk # nopep8 try: from xdg.BaseDirectory import xdg_config_home @@ -45,7 +48,8 @@ _ = t.gettext class Discover: """Main application class""" - def __init__(self, rpc_file, debug_file, args): + def __init__(self, rpc_file, config_file, debug_file, args): + self.mix_settings = False self.ind = None self.tray = None self.steamos = False @@ -61,6 +65,7 @@ class Discover: "GameScope session detected. Enabling steam and gamescope integration") self.steamos = True self.show_settings_delay = True + self.mix_settings = True settings = Gtk.Settings.get_default() if settings: settings.set_property( @@ -68,17 +73,24 @@ class Discover: self.create_gui() - self.connection = DiscordConnector( self ) + self.connection = DiscordConnector(self) - self.settings.text_settings.add_connector(self.connection) self.connection.connect() GLib.timeout_add((1000 / 60), self.connection.do_read) GLib.timeout_add((1000 / 20), self.periodic_run) self.rpc_file = rpc_file + self.config_file = config_file + rpc_file = Gio.File.new_for_path(rpc_file) monitor = rpc_file.monitor_file(0, None) monitor.connect("changed", self.rpc_changed) + config_file = Gio.File.new_for_path(config_file) + monitor_config = config_file.monitor_file(0, None) + monitor_config.connect("changed", self.config_changed) + + self.config_changed() + Gtk.main() def periodic_run(self, data=None): @@ -117,7 +129,7 @@ class Discover: print(" --hide ", _("Hide overlay")) print(" --show ", _("Show overlay")) print(" --rpc ", - _("Send command, not start new instance. Only needed if running in flatpak")) + _("Send command, not start new instance.")) print(" --mute ", _("Set own user to mute")) print(" --unmute ", _("Set unmuted")) print(" --deaf ", _("Set own user to deafened")) @@ -128,11 +140,6 @@ class Discover: print(_("For gamescope compatibility ensure ENV has 'GDK_BACKEND=x11'")) if normal_close: sys.exit(0) - if "--configure" in data or "-c" in data: - if self.settings: - self.show_settings() - else: - self.show_settings_delay = True if "--close" in data or "-x" in data: sys.exit(0) if "--steamos" in data or "-s" in data: @@ -175,7 +182,230 @@ class Discover: with open(self.rpc_file, "r") as tfile: data = tfile.readlines() if len(data) >= 1: - self.do_args(data[0].split(" "), False) + self.do_args(data[0].strip().split(" "), False) + + def config_changed(self, _a=None, _b=None, _c=None, _d=None): + """ + Called when the config file has been altered + """ + # Read new config + config = ConfigParser(interpolation=None) + config.read(self.config_file) + + # Set Voice overlay options + self.voice_overlay.set_align_x(config.getboolean( + "main", "rightalign", fallback=False)) + self.voice_overlay.set_align_y( + config.getint("main", "topalign", fallback=1)) + self.voice_overlay.set_bg(json.loads(config.get( + "main", "bg_col", fallback="[0.0,0.0,0.0,0.5]"))) + self.voice_overlay.set_fg(json.loads(config.get( + "main", "fg_col", fallback="[1.0,1.0,1.0,1.0]"))) + self.voice_overlay.set_fg_hi(json.loads(config.get( + "main", "fg_hi_col", fallback="[1.0,1.0,1.0,1.0]"))) + self.voice_overlay.set_tk(json.loads(config.get( + "main", "tk_col", fallback="[0.0,0.7,0.0,1.0]"))) + self.voice_overlay.set_mt(json.loads(config.get( + "main", "mt_col", fallback="[0.6,0.0,0.0,1.0]"))) + self.voice_overlay.set_mute_bg(json.loads(config.get( + "main", "mt_bg_col", fallback="[0.0,0.0,0.0,0.5]"))) + self.voice_overlay.set_hi(json.loads(config.get( + "main", "hi_col", fallback="[0.0,0.0,0.0,0.5]"))) + self.voice_overlay.set_bo(json.loads(config.get( + "main", "bo_col", fallback="[0.0,0.0,0.0,0.0]"))) + self.voice_overlay.set_avatar_bg_col(json.loads(config.get( + "main", "avatar_bg_col", fallback="[0.0,0.0,0.0,0.0]"))) + self.voice_overlay.set_avatar_size( + config.getint("main", "avatar_size", fallback=48)) + self.voice_overlay.set_icon_spacing( + config.getint("main", "icon_spacing", fallback=8)) + self.voice_overlay.set_text_padding( + config.getint("main", "text_padding", fallback=6)) + self.voice_overlay.set_text_baseline_adj(config.getint( + "main", "text_baseline_adj", fallback=0)) + font = config.get("main", "font", fallback=None) + title_font = config.get("main", "title_font", fallback=None) + self.voice_overlay.set_square_avatar(config.getboolean( + "main", "square_avatar", fallback=True)) + self.voice_overlay.set_only_speaking(config.getboolean( + "main", "only_speaking", fallback=False)) + self.voice_overlay.set_highlight_self(config.getboolean( + "main", "highlight_self", fallback=False)) + self.voice_overlay.set_icon_only(config.getboolean( + "main", "icon_only", fallback=False)) + monitor = config.get("main", "monitor", fallback="None") + self.voice_overlay.set_vert_edge_padding(config.getint( + "main", "vert_edge_padding", fallback=0)) + self.voice_overlay.set_horz_edge_padding(config.getint( + "main", "horz_edge_padding", fallback=0)) + floating = config.getboolean("main", "floating", fallback=False) + floating_x = config.getint("main", "floating_x", fallback=0) + floating_y = config.getint("main", "floating_y", fallback=0) + floating_w = config.getint("main", "floating_w", fallback=400) + floating_h = config.getint("main", "floating_h", fallback=400) + self.voice_overlay.set_order( + config.getint("main", "order", fallback=0)) + self.voice_overlay.set_hide_on_mouseover( + config.getboolean("text", "autohide", fallback=False)) + self.voice_overlay.set_horizontal(config.getboolean( + "main", "horizontal", fallback=False)) + self.voice_overlay.set_guild_ids(self.parse_guild_ids( + config.get("main", "guild_ids", fallback=""))) + self.voice_overlay.set_overflow( + config.getint("main", "overflow", fallback=0)) + self.voice_overlay.set_show_connection(config.getboolean( + "main", "show_connection", fallback=False)) + self.voice_overlay.set_show_title(config.getboolean( + "main", "show_title", fallback=False)) + self.voice_overlay.set_show_disconnected(config.getboolean( + "main", "show_disconnected", fallback=False)) + self.voice_overlay.set_border_width( + config.getint("main", "border_width", fallback=2)) + self.voice_overlay.set_icon_transparency(config.getfloat( + "main", "icon_transparency", fallback=1.0)) + self.voice_overlay.set_fancy_border(config.getboolean("main", + "fancy_border", fallback=True)) + self.voice_overlay.set_show_dummy(config.getboolean("main", + "show_dummy", fallback=False)) + self.voice_overlay.set_dummy_count(config.getint("main", + "dummy_count", fallback=10)) + + self.voice_overlay.set_monitor(self.get_monitor_index( + monitor)) + + self.voice_overlay.set_enabled(True) + + self.voice_overlay.set_floating( + floating, floating_x, floating_y, floating_w, floating_h) + + if font: + self.voice_overlay.set_font(font) + if title_font: + self.voice_overlay.set_title_font(title_font) + + # Set Text overlay options + self.text_overlay.set_enabled(config.getboolean( + "text", "enabled", fallback=False)) + self.text_overlay.set_align_x(config.getboolean( + "text", "rightalign", fallback=True)) + self.text_overlay.set_align_y( + config.getint("text", "topalign", fallback=2)) + monitor = config.get("text", "monitor", fallback="None") + self.floating = config.getboolean("text", "floating", fallback=True) + self.floating_x = config.getint("text", "floating_x", fallback=0) + self.floating_y = config.getint("text", "floating_y", fallback=0) + self.floating_w = config.getint("text", "floating_w", fallback=400) + self.floating_h = config.getint("text", "floating_h", fallback=400) + self.channel = config.get("text", "channel", fallback="0") + self.guild = config.get("text", "guild", fallback="0") + self.font = config.get("text", "font", fallback=None) + self.text_overlay.set_bg(json.loads(config.get( + "text", "bg_col", fallback="[0.0,0.0,0.0,0.5]"))) + self.text_overlay.set_fg(json.loads(config.get( + "text", "fg_col", fallback="[1.0,1.0,1.0,1.0]"))) + self.text_overlay.set_popup_style(config.getboolean( + "text", "popup_style", fallback=False)) + self.text_overlay.set_text_time( + config.getint("text", "text_time", fallback=30)) + self.text_overlay.set_show_attach(config.getboolean( + "text", "show_attach", fallback=True)) + self.text_overlay.set_line_limit( + config.getint("text", "line_limit", fallback=20)) + self.text_overlay.set_hide_on_mouseover( + config.getboolean("text", "autohide", fallback=False)) + + self.text_overlay.set_monitor(self.get_monitor_index( + monitor)) + self.text_overlay.set_floating( + floating, floating_x, floating_y, floating_w, floating_h) + + if self.font: + self.text_overlay.set_font(self.font) + + # Set Notification overlay options + self.notification_overlay.set_enabled(config.getboolean( + "notification", "enabled", fallback=False)) + self.notification_overlay.set_align_x(config.getboolean( + "notification", "rightalign", fallback=True)) + self.notification_overlay.set_align_y( + config.getint("notification", "topalign", fallback=2)) + monitor = config.get("notification", "monitor", fallback="None") + floating = config.getboolean( + "notification", "floating", fallback=False) + floating_x = config.getint( + "notification", "floating_x", fallback=0) + floating_y = config.getint( + "notification", "floating_y", fallback=0) + floating_w = config.getint( + "notification", "floating_w", fallback=400) + floating_h = config.getint( + "notification", "floating_h", fallback=400) + font = config.get("notification", "font", fallback=None) + self.notification_overlay.set_bg(json.loads(config.get( + "notification", "bg_col", fallback="[0.0,0.0,0.0,0.5]"))) + self.notification_overlay.set_fg(json.loads(config.get( + "notification", "fg_col", fallback="[1.0,1.0,1.0,1.0]"))) + self.notification_overlay.set_text_time(config.getint( + "notification", "text_time", fallback=10)) + self.notification_overlay.set_show_icon(config.getboolean( + "notification", "show_icon", fallback=True)) + self.notification_overlay.set_reverse_order(config.getboolean( + "notification", "rev", fallback=False)) + self.notification_overlay.set_limit_width(config.getint( + "notification", "limit_width", fallback=400)) + self.notification_overlay.set_icon_left(config.getboolean( + "notification", "icon_left", fallback=True)) + self.notification_overlay.set_icon_pad(config.getint( + "notification", "icon_padding", fallback=8)) + self.notification_overlay.set_icon_size(config.getint( + "notification", "icon_size", fallback=32)) + self.notification_overlay.set_padding(config.getint( + "notification", "padding", fallback=8)) + self.notification_overlay.set_border_radius(config.getint( + "notification", "border_radius", fallback=8)) + + self.notification_overlay.set_monitor(self.get_monitor_index( + monitor)) + self.notification_overlay.set_floating( + floating, floating_x, floating_y, floating_w, floating_h) + if self.font: + self.notification_overlay.set_font(self.font) + + # Set Core settings + self.set_force_xshape( + config.getboolean("general", "xshape", fallback=False)) + + def get_monitor_index(self, name): + """ + Helper function to find the index number of the monitor + """ + display = Gdk.Display.get_default() + if "get_n_monitors" in dir(display): + for i in range(0, display.get_n_monitors()): + if display.get_monitor(i).get_model() == name: + return i + return 0 + + def get_monitor_obj(self, name): + """ + Helper function to find the monitor object of the monitor + """ + display = Gdk.Display.get_default() + if "get_n_monitors" in dir(display): + for i in range(0, display.get_n_monitors()): + if display.get_monitor(i).get_model() == name: + return display.get_monitor(i) + + return None + + def parse_guild_ids(self, guild_ids_str): + """Parse the guild_ids from a str and return them in a list""" + guild_ids = [] + for guild_id in guild_ids_str.split(","): + guild_id = guild_id.strip() + if guild_id != "": + guild_ids.append(guild_id) + return guild_ids def create_gui(self): """ @@ -190,62 +420,9 @@ class Discover: else: self.text_overlay = TextOverlayWindow(self) self.notification_overlay = NotificationOverlayWindow(self) - self.menu = self.make_menu() - self.make_sys_tray_icon(self.menu) - self.settings = MainSettingsWindow(self) - if self.steamos: - # Larger fonts needed - css = Gtk.CssProvider.new() - css.load_from_data(bytes("* { font-size:20px; }", "utf-8")) - self.settings.get_style_context().add_provider( - css, Gtk.STYLE_PROVIDER_PRIORITY_USER) - - def make_sys_tray_icon(self, menu): - """ - Attempt to create an AppIndicator icon, failing that attempt to make - a systemtray icon - """ - if self.steamos: - return - try: - gi.require_version('AppIndicator3', '0.1') - # pylint: disable=import-outside-toplevel - from gi.repository import AppIndicator3 - self.ind = AppIndicator3.Indicator.new( - "discover_overlay", - "discover-overlay-tray", - AppIndicator3.IndicatorCategory.APPLICATION_STATUS) - # 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 - log.info("Falling back to Systray : %s", exception) - 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): - """ - Create System Menu - """ - menu = Gtk.Menu() - settings_opt = Gtk.MenuItem.new_with_label(_("Settings")) - show_opt = Gtk.MenuItem.new_with_label(_("Toggle Hidden")) - close_opt = Gtk.MenuItem.new_with_label(_("Close")) - - menu.append(settings_opt) - menu.append(show_opt) - menu.append(close_opt) - - settings_opt.connect("activate", self.show_settings) - show_opt.connect("activate", self.toggle_show) - close_opt.connect("activate", self.close) - menu.show_all() - return menu + if self.mix_settings: + MainSettingsWindow(self.config_file) def show_menu(self, obj, button, time): """ @@ -264,18 +441,6 @@ class Discover: if self.notification_overlay: self.notification_overlay.set_hidden(hide) - def show_settings(self, _obj=None, _data=None): - """ - Show settings window - """ - self.settings.present_settings() - - def hide_settings(self, _obj=None, _data=None): - """ - Hide settings window - """ - self.settings.close_window() - def close(self, _a=None, _b=None, _c=None): """ End of the program @@ -300,18 +465,6 @@ class Discover: if self.notification_overlay: self.notification_overlay.set_task(visible) - 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(): """ @@ -332,6 +485,7 @@ def entrypoint(): pid_file = os.path.join(config_dir, "discover_overlay.pid") rpc_file = os.path.join(config_dir, "discover_overlay.rpc") + config_file = os.path.join(config_dir, "config.ini") debug_file = os.path.join(config_dir, "output.txt") logging.getLogger().setLevel(logging.INFO) FORMAT = "%(levelname)s - %(name)s - %(message)s" @@ -343,31 +497,21 @@ def entrypoint(): log = logging.getLogger(__name__) log.info("Starting Discover Overlay: %s", pkg_resources.get_distribution('discover_overlay').version) - # Flatpak compat mode try: - if "container" in os.environ and os.environ["container"] == "flatpak": - if "--rpc" in sys.argv: - with open(rpc_file, "w") as tfile: - tfile.write(line) - log.warning("Sent RPC command") - else: - log.info("Flatpak compat mode started") - with open(rpc_file, "w") as tfile: - tfile.write("--close") - Discover(rpc_file, debug_file, sys.argv[1:]) - return - - # Normal usage - - try: - with pidfile.PIDFile(pid_file): - Discover(rpc_file, debug_file, sys.argv[1:]) - except pidfile.AlreadyRunningError: - log.warning("Discover overlay is currently running") - + if "--rpc" in sys.argv: 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: + settings = MainSettingsWindow(config_file) + Gtk.main() + sys.exit(0) + with open(rpc_file, "w") as tfile: + tfile.write("--close") + Discover(rpc_file, config_file, debug_file, sys.argv[1:]) + return + except Exception as ex: log.error(ex) log.error(traceback.format_exc()) diff --git a/discover_overlay/glade/settings.glade b/discover_overlay/glade/settings.glade new file mode 100644 index 0000000..3313495 --- /dev/null +++ b/discover_overlay/glade/settings.glade @@ -0,0 +1,2192 @@ + + + + + + 0.5 + 1 + 0.5 + 0.01 + 0.10 + + + 8 + 128 + 48 + 1 + 8 + + + 1 + 100 + 1 + 10 + + + 64 + 1 + 1 + + + 128 + 1 + 8 + + + 100 + 8 + 1 + 10 + + + 8 + 128 + 48 + 1 + 8 + + + 100 + 4000 + 400 + 1 + 10 + + + 128 + 1 + 8 + + + 1 + 4000 + 10 + 1 + 10 + + + + + + + + + Alphabetically + + + ID + + + Last Spoken + + + + + + + + + + + Shrink + + + Wrap + + + None + + + + + 1 + 100 + 10 + 1 + 10 + + + 64 + 1 + 1 + + + + + + + + + Left + + + Right + + + + + 10 + 100 + 50 + 1 + 10 + + + 4000 + 1 + 8 + + + -100 + 100 + 1 + 8 + + + 4000 + 1 + 8 + + + False + Discover Overlay Configuration + discover-overlay + + + notebook + True + True + + + + True + False + + + True + False + 10 + discover-overlay + 6 + + + 1 + 0 + + + + + overview_main_text + True + False + 50 + INTRO TEXT + True + + + 0 + 1 + 3 + + + + + Close overlay + overview_close_button + True + True + True + + + + 0 + 3 + 3 + + + + + + + + + + + + + + + + + + + + + + notebook_overview_label + True + False + Overview + + + False + + + + + + True + False + + + + True + False + 40 + + + voice_overlay_location_label + True + False + Overlay Location + + + 0 + 0 + 2 + + + + + Anchor to Edge + voice_anchor_to_edge + True + True + False + True + True + radiobutton1 + + + + 0 + 1 + + + + + Floating + voice_floating + True + True + False + True + True + + + + 1 + 1 + + + + + Place window + voice_place_window_button + True + True + True + + + + 0 + 5 + 2 + + + + + Show Advanced Options + voice_show_advanced_options_button + True + True + True + + + 0 + 6 + 2 + + + + + voice_align_1 + True + False + 0 + + Left + Right + + + + + 0 + 3 + 2 + + + + + voice_align_2 + True + False + 0 + + Top + Middle + Bottom + + + + + 0 + 4 + 2 + + + + + voice_monitor + True + False + + + + 0 + 2 + 2 + + + + + 0 + 0 + + + + + + True + False + 40 + True + True + + + voice_foreground_label + True + False + Foreground + + + 1 + 0 + + + + + voice_background_label + True + False + Background + + + 2 + 0 + + + + + voice_border_label + True + False + Border + + + 3 + 0 + + + + + voice_talking_label + True + False + Talking + + + 0 + 1 + + + + + voice_idle_label + True + False + Idle + + + 0 + 2 + + + + + voice_mute_label + True + False + Mute + + + 0 + 3 + + + + + voice_avatar_label + True + False + Avatar + + + 0 + 4 + + + + + voice_talking_foreground + True + True + True + True + + + + 1 + 1 + + + + + voice_talking_background + True + True + True + True + + + + 2 + 1 + + + + + voice_talking_border + True + True + True + True + + + + 3 + 1 + + + + + voice_idle_foreground + True + True + True + True + + + + 1 + 2 + + + + + voice_idle_background + True + True + True + True + + + + 2 + 2 + + + + + voice_idle_border + True + True + True + True + + + + 3 + 2 + + + + + voice_mute_foreground + True + True + True + True + + + + 1 + 3 + + + + + voice_mute_background + True + True + True + True + + + + 2 + 3 + + + + + voice_avatar_background + True + True + True + True + + + + 2 + 4 + + + + + + + + + + + + + + + + + 1 + 0 + + + + + + True + False + True + True + + + voice_font + True + True + True + Sans 12 + en-us + + + + + 1 + 0 + + + + + voice_title_font + True + True + True + Sans 12 + en-us + + + + + 1 + 1 + + + + + voice_font_label + True + False + Font + 0 + + + 0 + 0 + + + + + voice_title_font_label + True + False + Title Font + 0 + + + 0 + 1 + + + + + voice_icon_spacing + True + True + icon_spacing_adj + + + + 1 + 2 + + + + + voice_icon_spacing_label + True + False + Icon Spacing + 0 + + + 0 + 2 + + + + + voice_text_padding_label + True + False + Text Padding + 0 + + + 0 + 3 + + + + + voice_text_padding + True + True + text_padding_adj + + + + 1 + 3 + + + + + voice_text_vertical_offset_label + True + False + Text Vertical Offset + 0 + + + 0 + 4 + + + + + voce_vertical_padding_label + True + False + Verticle Edge Padding + 0 + + + 0 + 5 + + + + + voice_horizontal_padding_label + True + False + Horizontal Edge Padding + 0 + + + 0 + 6 + + + + + voice_display_horizontally_label + True + False + Display Horizontally + 0 + + + 0 + 7 + + + + + voice_highlight_self_label + True + False + Highlight self + 0 + + + 0 + 8 + + + + + voice_display_speakers_only_label + True + False + Display speakers only + 0 + + + 0 + 9 + + + + + voice_avatar_opacity_label + True + False + Avatar Opacity + 0 + + + 2 + 0 + + + + + voice_avatar_size_label + True + False + Avatar Size + 0 + + + 2 + 1 + + + + + voice_display_icon_only_label + True + False + Display Icon Only + 0 + + + 2 + 2 + + + + + voice_square_avatar_label + True + False + Square Avatar + 0 + + + 2 + 3 + + + + + voice_fancy_avatar_shapes_label + True + False + Fancy Avatar Shapes + 0 + + + 2 + 4 + + + + + voice_order_avatars_by_label + True + False + Order Avatars By + 0 + + + 2 + 5 + + + + + voice_border_width_label + True + False + Border width + 0 + + + 2 + 6 + + + + + voice_overflow_style_label + True + False + Overflow style + 0 + + + 2 + 7 + + + + + voice_show_title_label + True + False + Show title + 0 + + + 2 + 8 + + + + + voice_show_connection_status_label + True + False + Show Connection Status + 0 + + + 2 + 9 + + + + + voice_avatar_opacity + True + True + ava_opacity_adj + 1 + + + + 3 + 0 + + + + + voice_avatar_size + True + True + avatar_size_adj + + + + 3 + 1 + + + + + voice_display_icon_only + True + True + False + True + + + + 3 + 2 + + + + + voice_square_avatar + True + True + False + True + + + + 3 + 3 + + + + + voice_fancy_avatar_shapes + True + True + False + True + + + + 3 + 4 + + + + + voice_show_title + True + True + False + True + + + + 3 + 8 + + + + + voice_show_connection_status + True + True + False + True + + + + 3 + 9 + + + + + voice_show_disconnected_label + True + False + Show while Disconnected + 0 + + + 2 + 10 + + + + + voice_show_disconnected + True + True + False + True + + + + 3 + 10 + + + + + voice_display_speakers_only + True + True + False + True + + + + 1 + 9 + + + + + voice_highlight_self + True + True + False + True + + + + 1 + 8 + + + + + voice_display_horizontally + True + True + False + True + + + + 1 + 7 + + + + + voice_horizontal_padding + True + True + voice_horizontal_padding_adj + + + + 1 + 6 + + + + + voice_vertical_padding + True + True + voice_vertical_padding_adj + + + + 1 + 5 + + + + + voice_text_vertical_offset + True + True + voice_text_offset + + + + 1 + 4 + + + + + voice_show_test_content_label + True + False + Show test content + + + 0 + 11 + + + + + voice_show_test_content + True + True + False + True + + + + 1 + 11 + + + + + voice_dummy_count_label + True + False + Dummy Count + + + 2 + 11 + + + + + voice_dummy_count + True + True + voice_dummy_count_adj + + + + 3 + 11 + + + + + voice_border_width + True + True + border_width_adj + + + + 3 + 6 + + + + + voice_order_avatars_by + True + False + + Alphabetically + ID + Last Spoken + + + + + 3 + 5 + + + + + voice_overflow_style + True + False + + None + Wrap + Shrink + + + + + 3 + 7 + + + + + + + + + + + 0 + 1 + 2 + + + + + 1 + + + + + notebook_voice_label + True + False + Voice + + + 1 + False + + + + + + True + False + + + text_enable_label + True + False + Enable + 0 + + + 0 + 0 + + + + + text_enable + True + True + False + True + + + + 1 + 0 + + + + + text_popup_style_label + True + False + Popup Style + 0 + + + 0 + 1 + + + + + text_popup_style + True + True + False + True + + + + 1 + 1 + + + + + text_server_label + True + False + Server + 0 + + + 0 + 2 + + + + + text_channel_label + True + False + Channel + 0 + + + 0 + 3 + + + + + text_font_label + True + False + Font + 0 + + + 0 + 4 + + + + + text_colour_label + True + False + Text Colour + 0 + + + 0 + 5 + + + + + text_background_colour_label + True + False + Background Colour + 0 + + + 0 + 6 + + + + + text_overlay_location_label + True + False + Overlay Location + 0 + + + 0 + 7 + 2 + + + + + text_show_attachments_label + True + False + Show attachments + 0 + + + 0 + 9 + + + + + text_line_limit_label + True + False + Line limit + 0 + + + 0 + 10 + + + + + Refresh List + text_refresh_server_button + True + True + True + + + + 2 + 2 + + + + + Refresh List + text_refresh_channel_button + True + True + True + + + + 2 + 3 + + + + + text_font + True + True + True + Sans 12 + en-us + + + + + 1 + 4 + + + + + text_colour + True + True + True + + + + 1 + 5 + + + + + text_background_colour + True + True + True + + + + 1 + 6 + + + + + Place Window + text_place_window_button + True + True + True + + + + 1 + 8 + + + + + text_show_attachments + True + True + False + True + + + + 1 + 9 + + + + + text_line_limit + True + True + text_line_limit_adj + + + + 1 + 10 + + + + + text_server + True + False + + + + 1 + 2 + + + + + text_channel + True + False + + + + 1 + 3 + + + + + text_monitor + True + False + + + + 1 + 7 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 2 + + + + + notebook_text_label + True + False + Text + + + 2 + False + + + + + + True + False + + + notification_enable_label + True + False + Enable + 0 + + + 0 + 0 + + + + + notification_reverse_order_label + True + False + Reverse Order + 0 + + + 0 + 1 + + + + + notification_popup_timer_label + True + False + Popup timer + 0 + + + 0 + 2 + + + + + notification_limit_popup_width_label + True + False + Limit popup width + 0 + + + 0 + 3 + + + + + notification_font_label + True + False + Font + 0 + + + 0 + 4 + + + + + notification_text_colour_label + True + False + Text Colour + 0 + + + 0 + 5 + + + + + notification_background_colour_label + True + False + Background Colour + 0 + + + 0 + 6 + + + + + notification_overlay_location_label + True + False + Overlay location + 0 + + + 0 + 7 + 3 + + + + + notification_show_icon_label + True + False + Show Icon + 0 + + + 0 + 10 + + + + + notification_icon_position_label + True + False + Icon position + 0 + + + 0 + 11 + + + + + notification_enable + True + True + False + True + + + + 1 + 0 + + + + + notification_reverse_order + True + True + False + True + + + + 1 + 1 + + + + + notification_popup_timer + True + True + notification_popup_timer_adj + + + + 1 + 2 + + + + + notification_limit_popup_width + True + True + notification_limit_width_adj + + + + 1 + 3 + + + + + notification_font + True + True + True + Sans 12 + en-us + + + + + 1 + 4 + + + + + notification_text_colour + True + True + True + + + + 1 + 5 + + + + + notification_background_colour + True + True + True + + + + 1 + 6 + + + + + notification_show_icon + True + True + False + True + + + + 1 + 10 + + + + + notification_show_test_content + True + True + False + True + + + + 1 + 16 + + + + + notification_show_test_content_label + True + False + Show test content + 0 + + + 0 + 16 + + + + + notification_border_radius_label + True + False + Border radius + 0 + + + 0 + 15 + + + + + notification_padding_between_label + True + False + Padding between notifications + 0 + + + 0 + 14 + + + + + notification_icon_size_label + True + False + Icon Size + 0 + + + 0 + 13 + + + + + notification_icon_padding_label + True + False + Icon Padding + 0 + + + 0 + 12 + + + + + notification_icon_padding + True + True + notification_icon_padding_adj + + + + 1 + 12 + + + + + notification_icon_size + True + True + notification_icon_size_adj + + + + 1 + 13 + + + + + notification_padding_between + True + True + notification_padding_adj + + + + 1 + 14 + + + + + notification_border_radius + True + True + notification_border_radius_adj + + + + 1 + 15 + + + + + notification_monitor + True + False + 0 + + Unknown + + + + + 1 + 7 + + + + + notification_align_1 + True + False + 0 + + Left + Middle + Right + + + + + 1 + 8 + + + + + notification_align_2 + True + False + 0 + + Top + Bottom + + + + + 1 + 9 + + + + + notification_icon_position + True + False + + Left + Right + + + + + 1 + 11 + + + + + 3 + + + + + notebook_notification_label + True + False + Notification + + + 3 + False + + + + + + True + False + + + core_run_on_startup_label + True + False + Run on startup + 0 + + + 0 + 0 + + + + + core_run_on_startup + True + True + False + True + + + + 1 + 0 + + + + + core_force_xshape_label + True + False + Force XShape + 0 + + + 0 + 1 + + + + + core_force_xshape + True + True + False + True + + + + 1 + 1 + + + + + core_show_tray_icon_label + True + False + Show tray icon + + + 0 + 2 + + + + + core_show_tray_icon + True + True + False + True + + + + 1 + 2 + + + + + 4 + + + + + notebook_core_label + True + False + Core + + + 4 + False + + + + + + diff --git a/discover_overlay/glade/settings.glade~ b/discover_overlay/glade/settings.glade~ new file mode 100644 index 0000000..5aeb59c --- /dev/null +++ b/discover_overlay/glade/settings.glade~ @@ -0,0 +1,2192 @@ + + + + + + 0.5 + 1 + 0.5 + 0.01 + 0.10 + + + 8 + 128 + 48 + 1 + 8 + + + 1 + 100 + 1 + 10 + + + 64 + 1 + 1 + + + 128 + 1 + 8 + + + 100 + 8 + 1 + 10 + + + 8 + 128 + 48 + 1 + 8 + + + 100 + 4000 + 400 + 1 + 10 + + + 128 + 1 + 8 + + + 1 + 4000 + 10 + 1 + 10 + + + + + + + + + Alphabetically + + + ID + + + Last Spoken + + + + + + + + + + + Shrink + + + Wrap + + + None + + + + + 1 + 100 + 10 + 1 + 10 + + + 64 + 1 + 1 + + + + + + + + + Left + + + Right + + + + + 10 + 100 + 50 + 1 + 10 + + + 4000 + 1 + 8 + + + -100 + 100 + 1 + 8 + + + 4000 + 1 + 8 + + + False + Discover Overlay Configuration + discover-overlay + + + notebook + True + True + + + + True + False + + + True + False + 10 + discover-overlay + 6 + + + 1 + 0 + + + + + overview_main_text + True + False + 50 + INTRO TEXT + True + + + 0 + 1 + 3 + + + + + Close overlay + overview_close_button + True + True + True + + + + 0 + 3 + 3 + + + + + + + + + + + + + + + + + + + + + + notebook_overview_label + True + False + Overview + + + False + + + + + + True + False + + + + True + False + 40 + + + voice_overlay_location_label + True + False + Overlay Location + + + 0 + 0 + 2 + + + + + Anchor to Edge + voice_anchor_to_edge + True + True + False + True + True + radiobutton1 + + + + 0 + 1 + + + + + Floating + voice_floating + True + True + False + True + True + + + + 1 + 1 + + + + + Place window + voice_place_window_button + True + True + True + + + + 0 + 5 + 2 + + + + + Show Advanced Options + voice_show_advanced_options_button + True + True + True + + + 0 + 6 + 2 + + + + + voice_align_1 + True + False + 0 + + Left + Right + + + + + 0 + 3 + 2 + + + + + voice_align_2 + True + False + 0 + + Top + Middle + Bottom + + + + + 0 + 4 + 2 + + + + + voice_monitor + True + False + + + + 0 + 2 + 2 + + + + + 0 + 0 + + + + + + True + False + 40 + True + True + + + voice_foreground_label + True + False + Foreground + + + 1 + 0 + + + + + voice_background_label + True + False + Background + + + 2 + 0 + + + + + voice_border_label + True + False + Border + + + 3 + 0 + + + + + voice_talking_label + True + False + Talking + + + 0 + 1 + + + + + voice_idle_label + True + False + Idle + + + 0 + 2 + + + + + voice_mute_label + True + False + Mute + + + 0 + 3 + + + + + voice_avatar_label + True + False + Avatar + + + 0 + 4 + + + + + voice_talking_foreground + True + True + True + True + + + + 1 + 1 + + + + + voice_talking_background + True + True + True + True + + + + 2 + 1 + + + + + voice_talking_border + True + True + True + True + + + + 3 + 1 + + + + + voice_idle_foreground + True + True + True + True + + + + 1 + 2 + + + + + voice_idle_background + True + True + True + True + + + + 2 + 2 + + + + + voice_idle_border + True + True + True + True + + + + 3 + 2 + + + + + voice_mute_foreground + True + True + True + True + + + + 1 + 3 + + + + + voice_mute_background + True + True + True + True + + + + 2 + 3 + + + + + voice_avatar_background + True + True + True + True + + + + 2 + 4 + + + + + + + + + + + + + + + + + 1 + 0 + + + + + + True + False + True + True + + + voice_font + True + True + True + Sans 12 + en-us + + + + + 1 + 0 + + + + + voice_title_font + True + True + True + Sans 12 + en-us + + + + + 1 + 1 + + + + + voice_font_label + True + False + Font + 0 + + + 0 + 0 + + + + + voice_title_font_label + True + False + Title Font + 0 + + + 0 + 1 + + + + + voice_icon_spacing + True + True + icon_spacing_adj + + + + 1 + 2 + + + + + voice_icon_spacing_label + True + False + Icon Spacing + 0 + + + 0 + 2 + + + + + voice_text_padding_label + True + False + Text Padding + 0 + + + 0 + 3 + + + + + voice_text_padding + True + True + text_padding_adj + + + + 1 + 3 + + + + + voice_text_vertical_offset_label + True + False + Text Vertical Offset + 0 + + + 0 + 4 + + + + + voce_vertical_padding_label + True + False + Verticle Edge Padding + 0 + + + 0 + 5 + + + + + voice_horizontal_padding_label + True + False + Horizontal Edge Padding + 0 + + + 0 + 6 + + + + + voice_display_horizontally_label + True + False + Display Horizontally + 0 + + + 0 + 7 + + + + + voice_highlight_self_label + True + False + Highlight self + 0 + + + 0 + 8 + + + + + voice_display_speakers_only_label + True + False + Display speakers only + 0 + + + 0 + 9 + + + + + voice_avatar_opacity_label + True + False + Avatar Opacity + 0 + + + 2 + 0 + + + + + voice_avatar_size_label + True + False + Avatar Size + 0 + + + 2 + 1 + + + + + voice_display_icon_only_label + True + False + Display Icon Only + 0 + + + 2 + 2 + + + + + voice_square_avatar_label + True + False + Square Avatar + 0 + + + 2 + 3 + + + + + voice_fancy_avatar_shapes_label + True + False + Fancy Avatar Shapes + 0 + + + 2 + 4 + + + + + voice_order_avatars_by_label + True + False + Order Avatars By + 0 + + + 2 + 5 + + + + + voice_border_width_label + True + False + Border width + 0 + + + 2 + 6 + + + + + voice_overflow_style_label + True + False + Overflow style + 0 + + + 2 + 7 + + + + + voice_show_title_label + True + False + Show title + 0 + + + 2 + 8 + + + + + voice_show_connection_status_label + True + False + Show Connection Status + 0 + + + 2 + 9 + + + + + voice_avatar_opacity + True + True + ava_opacity_adj + 1 + + + + 3 + 0 + + + + + voice_avatar_size + True + True + avatar_size_adj + + + + 3 + 1 + + + + + voice_display_icon_only + True + True + False + True + + + + 3 + 2 + + + + + voice_square_avatar + True + True + False + True + + + + 3 + 3 + + + + + voice_fancy_avatar_shapes + True + True + False + True + + + + 3 + 4 + + + + + voice_show_title + True + True + False + True + + + + 3 + 8 + + + + + voice_show_connection_status + True + True + False + True + + + + 3 + 9 + + + + + voice_show_disconnected_label + True + False + Show while Disconnected + 0 + + + 2 + 10 + + + + + voice_show_disconnected + True + True + False + True + + + + 3 + 10 + + + + + voice_display_speakers_only + True + True + False + True + + + + 1 + 9 + + + + + voice_highlight_self + True + True + False + True + + + + 1 + 8 + + + + + voice_display_horizontally + True + True + False + True + + + + 1 + 7 + + + + + voice_horizontal_padding + True + True + voice_horizontal_padding_adj + + + + 1 + 6 + + + + + voice_vertical_padding + True + True + voice_vertical_padding_adj + + + + 1 + 5 + + + + + voice_text_vertical_offset + True + True + voice_text_offset + + + + 1 + 4 + + + + + voice_show_test_content_label + True + False + Show test content + + + 0 + 11 + + + + + voice_show_test_content + True + True + False + True + + + + 1 + 11 + + + + + voice_dummy_count_label + True + False + Dummy Count + + + 2 + 11 + + + + + voice_dummy_count + True + True + voice_dummy_count_adj + + + + 3 + 11 + + + + + voice_border_width + True + True + border_width_adj + + + + 3 + 6 + + + + + voice_order_avatars_by + True + False + + Alphabetically + ID + Last Spoken + + + + + 3 + 5 + + + + + voice_overflow_style + True + False + + None + Wrap + Shrink + + + + + 3 + 7 + + + + + + + + + + + 0 + 1 + 2 + + + + + 1 + + + + + notebook_voice_label + True + False + Voice + + + 1 + False + + + + + + True + False + + + text_enable_label + True + False + Enable + 0 + + + 0 + 0 + + + + + text_enable + True + True + False + True + + + + 1 + 0 + + + + + text_popup_style_label + True + False + Popup Style + 0 + + + 0 + 1 + + + + + text_popup_style + True + True + False + True + + + + 1 + 1 + + + + + text_server_label + True + False + Server + 0 + + + 0 + 2 + + + + + text_channel_label + True + False + Channel + 0 + + + 0 + 3 + + + + + text_font_label + True + False + Font + 0 + + + 0 + 4 + + + + + text_colour_label + True + False + Text Colour + 0 + + + 0 + 5 + + + + + text_background_colour_label + True + False + Background Colour + 0 + + + 0 + 6 + + + + + text_overlay_location_label + True + False + Overlay Location + 0 + + + 0 + 7 + 2 + + + + + text_show_attachments_label + True + False + Show attachments + 0 + + + 0 + 9 + + + + + text_line_limit_label + True + False + Line limit + 0 + + + 0 + 10 + + + + + Refresh List + text_refresh_server_button + True + True + True + + + + 2 + 2 + + + + + Refresh List + text_refresh_channel_button + True + True + True + + + + 2 + 3 + + + + + text_font + True + True + True + Sans 12 + en-us + + + + + 1 + 4 + + + + + text_colour + True + True + True + + + + 1 + 5 + + + + + text_background_colour + True + True + True + + + + 1 + 6 + + + + + Place Window + text_place_window_button + True + True + True + + + + 1 + 8 + + + + + text_show_attachments + True + True + False + True + + + + 1 + 9 + + + + + text_line_limit + True + True + text_line_limit_adj + + + + 1 + 10 + + + + + text_server + True + False + + + + 1 + 2 + + + + + text_channel + True + False + + + + 1 + 3 + + + + + text_monitor + True + False + + + + 1 + 7 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 2 + + + + + notebook_text_label + True + False + Text + + + 2 + False + + + + + + True + False + + + notification_enable_label + True + False + Enable + 0 + + + 0 + 0 + + + + + notification_reverse_order_label + True + False + Reverse Order + 0 + + + 0 + 1 + + + + + notification_popup_timer_label + True + False + Popup timer + 0 + + + 0 + 2 + + + + + notification_limit_popup_width_label + True + False + Limit popup width + 0 + + + 0 + 3 + + + + + notification_font_label + True + False + Font + 0 + + + 0 + 4 + + + + + notification_text_colour_label + True + False + Text Colour + 0 + + + 0 + 5 + + + + + notification_background_colour_label + True + False + Background Colour + 0 + + + 0 + 6 + + + + + notification_overlay_location_label + True + False + Overlay location + 0 + + + 0 + 7 + 3 + + + + + notification_show_icon_label + True + False + Show Icon + 0 + + + 0 + 10 + + + + + notification_icon_position_label + True + False + Icon position + 0 + + + 0 + 11 + + + + + notification_enable + True + True + False + True + + + + 1 + 0 + + + + + notification_reverse_order + True + True + False + True + + + + 1 + 1 + + + + + notification_popup_timer + True + True + notification_popup_timer_adj + + + + 1 + 2 + + + + + notification_limit_popup_width + True + True + notification_limit_width_adj + + + + 1 + 3 + + + + + notification_font + True + True + True + Sans 12 + en-us + + + + + 1 + 4 + + + + + notification_text_colour + True + True + True + + + + 1 + 5 + + + + + notification_background_colour + True + True + True + + + + 1 + 6 + + + + + notification_show_icon + True + True + False + True + + + + 1 + 10 + + + + + notification_show_test_content + True + True + False + True + + + + 1 + 16 + + + + + notification_show_test_content_label + True + False + Show test content + 0 + + + 0 + 16 + + + + + notification_border_radius_label + True + False + Border radius + 0 + + + 0 + 15 + + + + + notification_padding_between_label + True + False + Padding between notifications + 0 + + + 0 + 14 + + + + + notification_icon_size_label + True + False + Icon Size + 0 + + + 0 + 13 + + + + + notification_icon_padding_label + True + False + Icon Padding + 0 + + + 0 + 12 + + + + + notification_icon_padding + True + True + notification_icon_padding_adj + + + + 1 + 12 + + + + + notification_icon_size + True + True + notification_icon_size_adj + + + + 1 + 13 + + + + + notification_padding_between + True + True + notification_padding_adj + + + + 1 + 14 + + + + + notification_border_radius + True + True + notification_border_radius_adj + + + + 1 + 15 + + + + + notification_monitor + True + False + 0 + + Unknown + + + + + 1 + 7 + + + + + notification_align_1 + True + False + 0 + + Left + Middle + Right + + + + + 1 + 8 + + + + + notification_align_2 + True + False + 0 + + Top + Bottom + + + + + 1 + 9 + + + + + notification_icon_position + True + False + + Left + Right + + + + + 1 + 11 + + + + + 3 + + + + + notebook_notification_label + True + False + Notification + + + 3 + False + + + + + + True + False + + + core_run_on_startup_label + True + False + Run on startup + 0 + + + 0 + 0 + + + + + core_run_on_startup + True + True + False + True + + + + 1 + 0 + + + + + core_force_xshape_label + True + False + Force XShape + 0 + + + 0 + 1 + + + + + core_force_xshape + True + True + False + True + + + + 1 + 1 + + + + + core_show_tray_icon_label + True + False + Show tray icon + + + 0 + 2 + + + + + core_show_tray_icon + True + True + False + True + + + + 1 + 2 + + + + + 4 + + + + + notebook_core_label + True + False + Core + + + 4 + False + + + + + + diff --git a/discover_overlay/overlay.py b/discover_overlay/overlay.py index e43c32b..2e421c1 100644 --- a/discover_overlay/overlay.py +++ b/discover_overlay/overlay.py @@ -266,15 +266,17 @@ class OverlayWindow(Gtk.Window): self.hidden = hidden self.set_enabled(self.enabled) - def set_monitor(self, idx=None, mon=None): + def set_monitor(self, idx=None): """ Set the monitor this overlay should display on. """ self.monitor = idx if self.is_wayland: - if mon: - GtkLayerShell.set_monitor(self, mon) - self.set_untouchable() + display = Gdk.Display.get_default() + if "get_monitor" in dir(display): + monitor = display.get_monitor(self.monitor) + GtkLayerShell.set_monitor(self, monitor) + self.set_untouchable() self.force_location() self.needsredraw = True @@ -338,4 +340,4 @@ class OverlayWindow(Gtk.Window): def check_composite(self): screen = self.get_screen() if not self.compositing == screen.is_composited(): - self.needsredraw = True \ No newline at end of file + self.needsredraw = True diff --git a/discover_overlay/settings_window.py b/discover_overlay/settings_window.py index 3e7b1a8..b71c223 100644 --- a/discover_overlay/settings_window.py +++ b/discover_overlay/settings_window.py @@ -13,92 +13,388 @@ """Settings window holding all settings tab""" import gettext import gi +import logging import pkg_resources -from .voice_settings import VoiceSettingsWindow -from .text_settings import TextSettingsWindow -from .general_settings import GeneralSettingsWindow -from .about_settings import AboutSettingsWindow -from .notification_settings import NotificationSettingsWindow +import sys +import os +import json + +from configparser import ConfigParser gi.require_version("Gtk", "3.0") # pylint: disable=wrong-import-position,wrong-import-order -from gi.repository import Gtk # nopep8 +from gi.repository import Gtk, Gdk # nopep8 +log = logging.getLogger(__name__) t = gettext.translation( 'default', pkg_resources.resource_filename('discover_overlay', 'locales'), fallback=True) _ = t.gettext -class MainSettingsWindow(Gtk.Window): - """Settings window holding all settings tab""" +class MainSettingsWindow(): + """Settings class""" - def __init__(self, discover): - Gtk.Window.__init__(self) + def __init__(self, config_file): - self.connect("destroy", self.close_window) - self.connect("delete-event", self.close_window) + self.config_file = config_file - self.discover = discover - self.text_overlay = discover.text_overlay - self.voice_overlay = discover.voice_overlay - self.notification_overlay = discover.notification_overlay - self.set_title(_("Discover Overlay Configuration")) - self.set_icon_name("discover-overlay") - self.set_default_size(280, 180) + builder = Gtk.Builder.new_from_file(pkg_resources.resource_filename( + 'discover_overlay', 'glade/settings.glade')) + window = builder.get_object("settings_window") + window.connect("destroy", self.close_window) + window.connect("delete-event", self.close_window) - # Create - notebook = Gtk.Notebook() + window.set_default_size(280, 180) - if discover.steamos: - notebook.set_tab_pos(Gtk.PositionType.LEFT) - self.set_default_size(1280, 800) + # Make an array of all named widgets + self.widget = {} + for widget in builder.get_objects(): + if widget.find_property("name"): + name = widget.get_property("name") + self.widget[name] = widget - self.about_settings = AboutSettingsWindow(self.discover) - about_label = Gtk.Label.new(_("Overview")) - notebook.append_page(self.about_settings) - notebook.set_tab_label(self.about_settings, about_label) + # Translate labels and buttons + if name.endswith("_label"): + widget.set_label(_(widget.get_label())) + if name.endswith("_button"): + widget.set_label(_(widget.get_label())) - self.voice_settings = VoiceSettingsWindow(self.voice_overlay, discover) - voice_label = Gtk.Label.new(_("Voice")) - notebook.append_page(self.voice_settings) - notebook.set_tab_label(self.voice_settings, voice_label) + self.widget['overview_main_text'].set_markup("%s (%s)\n\n%s\n\n%s (https://discord.gg/jRKWMuDy5V) %s (https://github.com/trigg/Discover)\n\n\n\n\n\n" % ( + _("Welcome to Discover Overlay"), + pkg_resources.get_distribution('discover_overlay').version, + _("Discover-Overlay is a GTK3 overlay written in Python3. It can be configured to show who is currently talking on discord or it can be set to display text and images from a preconfigured channel. It is fully customisable and can be configured to display anywhere on the screen. We fully support X11 and wlroots based environments. We felt the need to make this project due to the shortcomings in support on Linux by the official discord client."), + _("Please visit our discord"), + _(" for support. Or open an issue on our GitHub ") + )) - self.text_settings = TextSettingsWindow(self.text_overlay, discover) - text_label = Gtk.Label.new(_("Text")) - notebook.append_page(self.text_settings) - notebook.set_tab_label(self.text_settings, text_label) + if "GAMESCOPE_WAYLAND_DISPLAY" in os.environ: + log.info( + "GameScope session detected. Enabling steam and gamescope integration") + self.steamos = True + settings = Gtk.Settings.get_default() + if settings: + settings.set_property( + "gtk-application-prefer-dark-theme", Gtk.true) + self.widget['notebook'].set_tab_pos(Gtk.PositionType.LEFT) + # TODO Not assume the display size. Probably poll it from GDK Display? + window.set_default_size(1280, 800) - self.notification_settings = NotificationSettingsWindow( - self.notification_overlay, discover) - notification_label = Gtk.Label.new(_("Notifications")) - notebook.append_page(self.notification_settings) - notebook.set_tab_label(self.notification_settings, notification_label) + # Larger fonts needed + css = Gtk.CssProvider.new() + css.load_from_data(bytes("* { font-size:20px; }", "utf-8")) + self.window.get_style_context().add_provider( + css, Gtk.STYLE_PROVIDER_PRIORITY_USER) + self.window = window - self.core_settings = GeneralSettingsWindow(self.discover) - core_label = Gtk.Label.new(_("Core")) - notebook.append_page(self.core_settings) - notebook.set_tab_label(self.core_settings, core_label) - self.add(notebook) - self.notebook = notebook + self.read_config() + + window.show() + self.menu = self.make_menu() + self.make_sys_tray_icon(self.menu) + + # builder.connect_signals(self) def close_window(self, widget=None, event=None): """ Hide the settings window for use at a later date """ - self.text_settings.close_window(widget, event) - self.voice_settings.close_window(widget, event) - self.core_settings.close_window(widget, event) - self.hide() + self.window.hide() return True def present_settings(self): """ Show the settings window """ - self.about_settings.present_settings() - self.voice_settings.present_settings() - self.text_settings.present_settings() - self.notification_settings.present_settings() - self.core_settings.present_settings() - self.notebook.show() - self.show() - self.notebook.set_current_page(0) + # self.about_settings.present_settings() + # self.voice_settings.present_settings() + # self.text_settings.present_settings() + # self.notification_settings.present_settings() + # self.core_settings.present_settings() + # self.notebook.show() + # self.show() + self.widget['notebook'].set_current_page(0) + self.window.show() + + def read_config(self): + # Read config and put into gui + config = ConfigParser(interpolation=None) + config.read(self.config_file) + + # Read Voice section + + self.voice_floating_x = config.getint("main", "floating_x", fallback=0) + self.voice_floating_y = config.getint("main", "floating_y", fallback=0) + self.voice_floating_w = config.getint( + "main", "floating_w", fallback=400) + self.voice_floating_h = config.getint( + "main", "floating_h", fallback=400) + + if config.getboolean("main", "floating", fallback=False): + self.widget['voice_floating'].set_active(True) + else: + self.widget['voice_anchor_to_edge'].set_active(True) + self.widget['voice_align_1'].set_active( + config.getboolean("main", "rightalign", fallback=False)) + self.widget['voice_align_2'].set_active( + config.getint("main", "topalign", fallback=1)) + + self.widget['voice_monitor'].set_active(self.get_monitor_index( + config.get("main", "monitor", fallback="None"))) + + font = config.get("main", "font", fallback=None) + if font: + self.widget['voice_font'].set_font(font) + title_font = config.get("main", "title_font", fallback=None) + if title_font: + self.widget['voice_title_font'].set_font(font) + + self.widget['voice_icon_spacing'].set_value( + config.getint("main", "icon_spacing", fallback=8)) + + self.widget['voice_text_padding'].set_value( + config.getint("main", "text_padding", fallback=6)) + + self.widget['voice_text_vertical_offset'].set_value( + config.getint("main", "text_baseline_adj", fallback=0)) + + self.widget['voice_vertical_padding'].set_value( + config.getint("main", "vert_edge_padding", fallback=0)) + + self.widget['voice_horizontal_padding'].set_value( + config.getint("main", "horz_edge_padding", fallback=0)) + + self.widget['voice_display_horizontally'].set_active( + config.getboolean("main", "horizontal", fallback=False)) + + self.widget['voice_highlight_self'].set_active( + config.getboolean("main", "highlight_self", fallback=False)) + + self.widget['voice_display_speakers_only'].set_active( + config.getboolean("main", "only_speaking", fallback=False)) + + self.widget['voice_talking_foreground'].set_rgba(self.make_colour(config.get( + "main", "fg_hi_col", fallback="[1.0,1.0,1.0,1.0]"))) + + self.widget['voice_talking_background'].set_rgba(self.make_colour(config.get( + "main", "hi_col", fallback="[0.0,0.0,0.0,0.5]"))) + + self.widget['voice_talking_border'].set_rgba(self.make_colour(config.get( + "main", "tk_col", fallback="[0.0,0.7,0.0,1.0]"))) + + self.widget['voice_idle_foreground'].set_rgba(self.make_colour(config.get( + "main", "fg_col", fallback="[1.0,1.0,1.0,1.0]"))) + + self.widget['voice_idle_background'].set_rgba(self.make_colour(config.get( + "main", "bg_col", fallback="[0.0,0.0,0.0,0.5]"))) + + self.widget['voice_idle_border'].set_rgba(self.make_colour(config.get( + "main", "bo_col", fallback="[0.0,0.0,0.0,0.0]"))) + + self.widget['voice_mute_foreground'].set_rgba(self.make_colour(config.get( + "main", "mt_col", fallback="[0.6,0.0,0.0,1.0]"))) + + self.widget['voice_mute_background'].set_rgba(self.make_colour(config.get( + "main", "mt_bg_col", fallback="[0.0,0.0,0.0,0.5]"))) + + self.widget['voice_avatar_background'].set_rgba(self.make_colour(config.get( + "main", "avatar_bg_col", fallback="[0.0,0.0,0.0,0.0]"))) + + self.widget['voice_avatar_opacity'].set_value(config.getfloat( + "main", "icon_transparency", fallback=1.0)) + + self.widget['voice_avatar_size'].set_value( + config.getint("main", "avatar_size", fallback=48)) + + self.widget['voice_display_icon_only'].set_active(config.getboolean( + "main", "icon_only", fallback=False)) + + self.widget['voice_square_avatar'].set_active(config.getboolean( + "main", "square_avatar", fallback=True)) + + self.widget['voice_fancy_avatar_shapes'].set_active(config.getboolean("main", + "fancy_border", fallback=True)) + + self.widget['voice_order_avatars_by'].set_active( + config.getint("main", "order", fallback=0)) + + self.widget['voice_border_width'].set_value( + config.getint("main", "border_width", fallback=2)) + + self.widget['voice_overflow_style'].set_active( + config.getint("main", "overflow", fallback=0)) + + self.widget['voice_show_title'].set_active(config.getboolean( + "main", "show_title", fallback=False)) + + self.widget['voice_show_connection_status'].set_active(config.getboolean( + "main", "show_connection", fallback=False)) + + self.widget['voice_show_disconnected'].set_active(config.getboolean( + "main", "show_disconnected", fallback=False)) + + # Read Text section + + self.widget['text_enable'].set_active( + config.getboolean("text", "enabled", fallback=False)) + + self.widget['text_popup_style'].set_active( + config.getboolean("text", "popup_style", fallback=False)) + + # TODO Find server & channel in lists. TODO Have lists + self.voice_guild = config.get("text", "guild", fallback="0") + self.widget['text_server'].set_active(0) + + self.voice_channel = config.get("text", "channel", fallback="0") + self.widget['text_channel'].set_active(0) + + font = config.get("text", "font", fallback=None) + if font: + self.widget['text_font'].set_font(font) + + self.widget['text_colour'].set_rgba(self.make_colour(config.get( + "text", "fg_col", fallback="[1.0,1.0,1.0,1.0]"))) + + self.widget['text_background_colour'].set_rgba(self.make_colour(config.get( + "text", "bg_col", fallback="[0.0,0.0,0.0,0.5]"))) + + self.widget['text_monitor'].set_active(self.get_monitor_index( + config.get("text", "monitor", fallback="None"))) + + self.widget['text_show_attachments'].set_active(config.getboolean( + "text", "show_attach", fallback=True)) + + self.widget['text_line_limit'].set_value( + config.getint("text", "line_limit", fallback=20)) + + # Read Notification section + + # Read Core section + + def make_colour(self, col): + col = json.loads(col) + return Gdk.RGBA(col[0], col[1], col[2], col[3]) + + def parse_guild_ids(self, guild_ids_str): + """Parse the guild_ids from a str and return them in a list""" + guild_ids = [] + for guild_id in guild_ids_str.split(","): + guild_id = guild_id.strip() + if guild_id != "": + guild_ids.append(guild_id) + return guild_ids + + def get_monitor_index(self, name): + """ + Helper function to find the index number of the monitor + """ + display = Gdk.Display.get_default() + if "get_n_monitors" in dir(display): + for i in range(0, display.get_n_monitors()): + if display.get_monitor(i).get_model() == name: + return i + return 0 + + def get_monitor_obj(self, name): + """ + Helper function to find the monitor object of the monitor + """ + display = Gdk.Display.get_default() + if "get_n_monitors" in dir(display): + for i in range(0, display.get_n_monitors()): + if display.get_monitor(i).get_model() == name: + return display.get_monitor(i) + + return None + + def make_sys_tray_icon(self, menu): + """ + Attempt to create an AppIndicator icon, failing that attempt to make + a systemtray icon + """ + try: + gi.require_version('AppIndicator3', '0.1') + # pylint: disable=import-outside-toplevel + from gi.repository import AppIndicator3 + self.ind = AppIndicator3.Indicator.new( + "discover_overlay", + "discover-overlay-tray", + AppIndicator3.IndicatorCategory.APPLICATION_STATUS) + # 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 + log.info("Falling back to Systray : %s", exception) + 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 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 make_menu(self): + """ + Create System Menu + """ + menu = Gtk.Menu() + settings_opt = Gtk.MenuItem.new_with_label(_("Settings")) + close_opt = Gtk.MenuItem.new_with_label(_("Close")) + + menu.append(settings_opt) + menu.append(close_opt) + + settings_opt.connect("activate", self.present_settings) + close_opt.connect("activate", self.close_window) + menu.show_all() + return menu + + def voice_toggle_test_content(self, button): + self.voice_overlay.set_show_dummy(button.get_active()) + self.show_dummy = button.get_active() + if self.show_dummy: + self.voice_overlay.set_enabled(True) + self.voice_overlay.set_hidden(False) + + def overview_close(self, button): + log.info("Quit pressed") + sys.exit(0) + + def voice_place_window(self, button): + pass + + def text_place_window(self, button): + pass + + def voice_floating_changed(self, button): + pass + + def voice_monitor_changed(self, button): + pass + + def text_server_refresh(self, button): + # TODO Implement refresh request via RPC + pass + + def text_channel_refresh(self, button): + # TODO Implement refresh request via RPC + pass + + def config_set(self, context, key, value): + config = ConfigParser(interpolation=None) + config.read(self.config_file) + config.set(context, key, value) + with open(self.config_file, 'w') as file: + config.write(file) + + def voice_font_changed(self, button): + self.config_set("main", "font", button.get_font()) diff --git a/setup.py b/setup.py index 3d45071..b51cd8c 100644 --- a/setup.py +++ b/setup.py @@ -50,7 +50,7 @@ setup( 'Topic :: Communications :: Conferencing', ], package_data={ - 'discover_overlay': ['locales/*/LC_MESSAGES/*.mo'] + 'discover_overlay': ['locales/*/LC_MESSAGES/*.mo', 'glade/*'] }, keywords='discord overlay voice linux', license='GPLv3+',