diff --git a/discover_overlay/autostart.py b/discover_overlay/autostart.py index 50b653e..e489a25 100644 --- a/discover_overlay/autostart.py +++ b/discover_overlay/autostart.py @@ -21,6 +21,7 @@ except ModuleNotFoundError: log = logging.getLogger(__name__) + class Autostart: """A class to assist auto-start""" @@ -35,7 +36,7 @@ class Autostart: self.auto = self.find_auto() self.desktop = self.find_desktop() log.info("Autostart info : desktop %s auto %s", - self.desktop, self.auto) + self.desktop, self.auto) def find_auto(self): """Check all known locations for auto-started apps""" @@ -69,17 +70,19 @@ class Autostart: """Check if it's already set to auto-start""" return True if self.auto else False + class BazziteAutostart: """A class to assist auto-start""" + def __init__(self): - self.auto= False + self.auto = False with open("/etc/default/discover-overlay") as f: content = f.readlines() for line in content: if line.startswith("AUTO_LAUNCH_DISCOVER_OVERLAY="): self.auto = int(line.split("=")[1]) > 0 log.info("Bazzite Autostart info : %s", - self.auto) + self.auto) def set_autostart(self, enable): """Set or Unset auto-start state""" @@ -88,15 +91,16 @@ class BazziteAutostart: elif not enable and self.auto: self.change_file("0") self.auto = enable - + def change_file(self, value): newcontent = [] with open("/etc/default/discover-overlay") as f: content = f.readlines() for line in content: if line.startswith("AUTO_LAUNCH_DISCOVER_OVERLAY="): - newcontent.append( "AUTO_LAUNCH_DISCOVER_OVERLAY=%s\n" % value) - elif len(line)<2: + newcontent.append( + "AUTO_LAUNCH_DISCOVER_OVERLAY=%s\n" % value) + elif len(line) < 2: pass else: newcontent.append(line) @@ -105,4 +109,4 @@ class BazziteAutostart: def is_auto(self): """Check if it's already set to auto-start""" - return self.auto \ No newline at end of file + return self.auto diff --git a/discover_overlay/discord_connector.py b/discover_overlay/discord_connector.py index f8408f7..d9a7653 100644 --- a/discover_overlay/discord_connector.py +++ b/discover_overlay/discord_connector.py @@ -30,9 +30,7 @@ import websocket import requests import gi -gi.require_version("Gtk", "3.0") -# pylint: disable=wrong-import-position,wrong-import-order -from gi.repository import GLib # nopep8 +from gi.repository import GLib log = logging.getLogger(__name__) @@ -47,10 +45,10 @@ class DiscordConnector: def __init__(self, discover): self.discover = discover self.websocket = None - self.access_token = discover.config().get("cache", "access_token", fallback= None) + self.access_token = discover.config().get( + "cache", "access_token", fallback=None) self.oauth_token = "207646673902501888" self.access_delay = 0 - self.warn_connection = True self.guilds = {} self.channels = {} @@ -175,7 +173,7 @@ class DiscordConnector: epoch_time = calendar.timegm(utc_time) username = message["author"]["username"] - if("nick" in message and message['nick'] and len(message["nick"]) > 1 + if ("nick" in message and message['nick'] and len(message["nick"]) > 1 and 'object Object' not in json.dumps(message["nick"])): username = message["nick"] colour = "#ffffff" @@ -359,7 +357,8 @@ class DiscordConnector: self.get_access_token_stage1() return else: - self.discover.config_set("cache","access_token",self.access_token) + self.discover.config_set( + "cache", "access_token", self.access_token) self.req_guilds() self.user = j["data"]["user"] log.info( @@ -723,7 +722,7 @@ class DiscordConnector: if self.authed and len(self.rate_limited_channels) > 0: now = time.time() - if self.last_rate_limit_send < now - 60: + if self.last_rate_limit_send < now - 60: guild = self.rate_limited_channels.pop() cmd = { @@ -756,7 +755,7 @@ class DiscordConnector: This will be mixed in with 'None' in the list where a voice channel is """ - if(guild_id == 0): + if (guild_id == 0): return self.rate_limited_channels.append(guild_id) @@ -786,14 +785,11 @@ class DiscordConnector: origin="http://localhost:3000", timeout=0.1 ) - self.warn_connection=True # Warn on next disconnect if self.socket_watch: GLib.source_remove(self.socket_watch) - self.socket_watch = GLib.io_add_watch(self.websocket.sock, GLib.IOCondition.HUP | GLib.IOCondition.IN | GLib.IOCondition.ERR, self.socket_glib) + self.socket_watch = GLib.io_add_watch( + self.websocket.sock, GLib.IOCondition.HUP | GLib.IOCondition.IN | GLib.IOCondition.ERR, self.socket_glib) except ConnectionError as error: - if self.warn_connection: - log.error(error) - self.warn_connection=False self.schedule_reconnect() def socket_glib(self, a=None, b=None): @@ -807,7 +803,8 @@ class DiscordConnector: if not self.websocket: # Connection was closed in the meantime break - recv, _w, _e = select.select((self.websocket.sock,), (), (), 0) + recv, _w, _e = select.select( + (self.websocket.sock,), (), (), 0) except (websocket.WebSocketConnectionClosedException, json.decoder.JSONDecodeError): self.on_close() break diff --git a/discover_overlay/discover_overlay.py b/discover_overlay/discover_overlay.py index 0057701..302e141 100755 --- a/discover_overlay/discover_overlay.py +++ b/discover_overlay/discover_overlay.py @@ -262,7 +262,8 @@ class Discover: 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_show_avatar(config.getboolean("main", "show_avatar", fallback=True)) + self.voice_overlay.set_show_avatar( + config.getboolean("main", "show_avatar", fallback=True)) self.voice_overlay.set_fancy_border(config.getboolean("main", "fancy_border", fallback=True)) self.voice_overlay.set_show_dummy(config.getboolean("main", diff --git a/discover_overlay/draggable_window.py b/discover_overlay/draggable_window.py index 1581c24..43f0d97 100644 --- a/discover_overlay/draggable_window.py +++ b/discover_overlay/draggable_window.py @@ -20,6 +20,7 @@ from gi.repository import Gtk, Gdk # nopep8 log = logging.getLogger(__name__) + class DraggableWindow(Gtk.Window): """An X11 window which can be moved and resized""" @@ -56,7 +57,7 @@ class DraggableWindow(Gtk.Window): self.drag_y = 0 self.force_location() self.show_all() - + def force_location(self): """ Move the window to previously given co-ords. diff --git a/discover_overlay/notification_overlay.py b/discover_overlay/notification_overlay.py index 94e0729..64327e9 100644 --- a/discover_overlay/notification_overlay.py +++ b/discover_overlay/notification_overlay.py @@ -267,7 +267,7 @@ class NotificationOverlayWindow(OverlayWindow): if self.testing: return self.test_content return self.content - + def overlay_draw(self, _w, context, data=None): """ Draw the overlay @@ -388,8 +388,8 @@ class NotificationOverlayWindow(OverlayWindow): # self.context.rectangle(0, self.border_radius, # shape_width, shape_height - (self.border_radius * 2)) - #self.context.arc(0.7, 0.3, 0.035, 1.25 * math.pi, 2.25 * math.pi) - #self.context.arc(0.3, 0.7, 0.035, .25 * math.pi, 1.25 * math.pi) + # self.context.arc(0.7, 0.3, 0.035, 1.25 * math.pi, 2.25 * math.pi) + # self.context.arc(0.3, 0.7, 0.035, .25 * math.pi, 1.25 * math.pi) if self.border_radius == 0: self.context.move_to(0.0, 0.0) diff --git a/discover_overlay/overlay.py b/discover_overlay/overlay.py index 27d9be6..aca6ba5 100644 --- a/discover_overlay/overlay.py +++ b/discover_overlay/overlay.py @@ -98,7 +98,7 @@ class OverlayWindow(Gtk.Window): self.force_xshape = False self.context = None self.autohide = False - + self.redraw_id = None self.timer_after_draw = None @@ -109,7 +109,6 @@ class OverlayWindow(Gtk.Window): self.get_screen().connect("monitors-changed", self.screen_changed) self.get_screen().connect("size-changed", self.screen_changed) - def set_gamescope_xatom(self, enabled): if self.piggyback_parent: return @@ -256,7 +255,7 @@ class OverlayWindow(Gtk.Window): self.width = width self.height = height self.set_needs_redraw() - + def set_needs_redraw(self): if not self.hidden and self.enabled: if self.piggyback_parent: @@ -311,7 +310,7 @@ class OverlayWindow(Gtk.Window): Set the monitor this overlay should display on. """ if type(idx) is str: - idx=0 + idx = 0 self.monitor = idx if self.is_wayland: display = Gdk.Display.get_default() @@ -391,4 +390,3 @@ class OverlayWindow(Gtk.Window): def screen_changed(self, screen=None): self.set_monitor(self.monitor) - diff --git a/discover_overlay/settings_window.py b/discover_overlay/settings_window.py index 89dac5d..bc8916f 100644 --- a/discover_overlay/settings_window.py +++ b/discover_overlay/settings_window.py @@ -39,7 +39,8 @@ class MainSettingsWindow(): def __init__(self, config_file, rpc_file, channel_file, args): self.args = args # Detect Bazzite autostart - self.alternative_autostart = os.path.exists("/etc/default/discover-overlay") + self.alternative_autostart = os.path.exists( + "/etc/default/discover-overlay") # Detect flatpak en self.disable_autostart = 'container' in os.environ self.steamos = False @@ -288,8 +289,6 @@ class MainSettingsWindow(): self.widget['voice_align_2'].set_active( config.getint("main", "topalign", fallback=1)) - - monitor = 0 try: config.getint("main", "monitor", fallback=0) @@ -298,7 +297,6 @@ class MainSettingsWindow(): self.widget['voice_monitor'].set_active(monitor) - font = config.get("main", "font", fallback=None) if font: self.widget['voice_font'].set_font(font) @@ -425,7 +423,7 @@ class MainSettingsWindow(): config.getboolean("text", "popup_style", fallback=False)) self.widget['text_popup_time'].set_value( - config.getint("text","text_time", fallback=30) + config.getint("text", "text_time", fallback=30) ) self.current_guild = config.get("text", "guild", fallback="0") @@ -442,7 +440,6 @@ class MainSettingsWindow(): self.widget['text_background_colour'].set_rgba(self.make_colour(config.get( "text", "bg_col", fallback="[0.0,0.0,0.0,0.5]"))) - monitor = 0 try: config.getint("text", "monitor", fallback=0) @@ -479,7 +476,6 @@ class MainSettingsWindow(): self.widget['notification_background_colour'].set_rgba(self.make_colour(config.get( "notification", "bg_col", fallback="[0.0,0.0,0.0,0.5]"))) - monitor = 0 try: config.getint("notification", "monitor", fallback=0) @@ -547,7 +543,6 @@ class MainSettingsWindow(): self.loading_config = False - def make_colour(self, col): col = json.loads(col) return Gdk.RGBA(col[0], col[1], col[2], col[3]) @@ -854,7 +849,8 @@ class MainSettingsWindow(): self.config_set("main", "only_speaking", "%s" % (button.get_active())) def voice_display_speakers_grace_period(self, button): - self.config_set("main", "only_speaking_grace", "%s" % (int(button.get_value()))) + self.config_set("main", "only_speaking_grace", "%s" % + (int(button.get_value()))) def voice_toggle_test_content(self, button): self.config_set("main", "show_dummy", "%s" % (button.get_active())) @@ -1062,7 +1058,8 @@ class MainSettingsWindow(): self.config_set("notification", "bg_col", json.dumps(colour)) def notification_monitor_changed(self, button): - self.config_set("notification", "monitor", "%s" % (button.get_active())) + self.config_set("notification", "monitor", "%s" % + (button.get_active())) def notification_align_1_changed(self, button): self.config_set("notification", "rightalign", "%s" % @@ -1123,7 +1120,7 @@ class MainSettingsWindow(): def core_reset_all(self, button): self.config_remove_section("general") self.read_config() - + def voice_reset_all(self, button): self.config_remove_section("main") self.read_config() @@ -1134,4 +1131,4 @@ class MainSettingsWindow(): def notification_reset_all(self, button): self.config_remove_section("notification") - self.read_config() \ No newline at end of file + self.read_config() diff --git a/discover_overlay/voice_overlay.py b/discover_overlay/voice_overlay.py index 1ddd9c2..a1686e7 100644 --- a/discover_overlay/voice_overlay.py +++ b/discover_overlay/voice_overlay.py @@ -605,7 +605,6 @@ class VoiceOverlayWindow(OverlayWindow): offset_x_mult = -1 current_x = self.width - avatar_size - self.horz_edge_padding - # Choose where to start drawing current_y = 0 + self.vert_edge_padding if self.align_vert == 1: @@ -749,7 +748,7 @@ class VoiceOverlayWindow(OverlayWindow): Draw avatar at given Y position. Includes both text and image based on settings """ # Ensure pixbuf for avatar - if user["id"] not in self.avatars and user["avatar"] and avatar_size>0: + if user["id"] not in self.avatars and user["avatar"] and avatar_size > 0: url = "https://cdn.discordapp.com/avatars/%s/%s.png" % ( user['id'], user['avatar']) get_surface(self.recv_avatar, url, user["id"],