From 0868a351a3a06239f11c83144eccff4b507ad05b Mon Sep 17 00:00:00 2001 From: Adrian Edwards <17362949+MoralCode@users.noreply.github.com> Date: Wed, 14 Oct 2020 12:25:10 -0700 Subject: [PATCH 01/29] Copy and tweak channel selection box to use for guild selection --- discover_overlay/text_settings.py | 46 ++++++++++++++++++++----------- 1 file changed, 30 insertions(+), 16 deletions(-) diff --git a/discover_overlay/text_settings.py b/discover_overlay/text_settings.py index 2e40128..5715775 100644 --- a/discover_overlay/text_settings.py +++ b/discover_overlay/text_settings.py @@ -254,6 +254,16 @@ class TextSettingsWindow(SettingsWindow): channel.add_attribute(rt, "text", 0) channel.add_attribute(rt, 'sensitive', 1) + guild_label = Gtk.Label.new("Server") + guild = Gtk.ComboBox.new() + + guild.connect("changed", self.change_guild) + guild_rt = Gtk.CellRendererText() + #guild.set_row_separator_func(lambda model, path: model[path][1]) + guild.pack_start(rt, True) + guild.add_attribute(rt, "text", 0) + guild.add_attribute(rt, 'sensitive', 1) + # Show Attachments show_attach_label = Gtk.Label.new("Show Attachments") show_attach = Gtk.CheckButton.new() @@ -264,6 +274,7 @@ class TextSettingsWindow(SettingsWindow): self.align_y_widget = align_y self.align_monitor_widget = monitor self.align_placement_widget = align_placement_button + self.guild_widget = guild self.channel_widget = channel self.text_time_widget = text_time self.text_time_label_widget = text_time_label @@ -274,22 +285,25 @@ class TextSettingsWindow(SettingsWindow): box.attach(popup_style, 1, 1, 1, 1) box.attach(text_time_label, 0, 2, 1, 1) box.attach(text_time, 1, 2, 1, 1) - box.attach(channel_label, 0, 3, 1, 1) - box.attach(channel, 1, 3, 1, 1) - box.attach(font_label, 0, 4, 1, 1) - box.attach(font, 1, 4, 1, 1) - box.attach(fg_col_label, 0, 5, 1, 1) - box.attach(fg_col, 1, 5, 1, 1) - box.attach(bg_col_label, 0, 6, 1, 1) - box.attach(bg_col, 1, 6, 1, 1) - box.attach(align_label, 0, 7, 1, 5) - #box.attach(align_type_box, 1, 7, 1, 1) - box.attach(monitor, 1, 8, 1, 1) - box.attach(align_x, 1, 9, 1, 1) - box.attach(align_y, 1, 10, 1, 1) - box.attach(align_placement_button, 1, 11, 1, 1) - box.attach(show_attach_label, 0, 12, 1, 1) - box.attach(show_attach, 1, 12, 1, 1) + box.attach(guild_label, 0, 3, 1, 1) + box.attach(guild, 1, 3, 1, 1) + + box.attach(channel_label, 0, 4, 1, 1) + box.attach(channel, 1, 4, 1, 1) + box.attach(font_label, 0, 5, 1, 1) + box.attach(font, 1, 5, 1, 1) + box.attach(fg_col_label, 0, 6, 1, 1) + box.attach(fg_col, 1, 6, 1, 1) + box.attach(bg_col_label, 0, 7, 1, 1) + box.attach(bg_col, 1, 7, 1, 1) + box.attach(align_label, 0, 8, 1, 5) + #box.attach(align_type_box, 1, 8, 1, 1) + box.attach(monitor, 1, 9, 1, 1) + box.attach(align_x, 1, 10, 1, 1) + box.attach(align_y, 1, 11, 1, 1) + box.attach(align_placement_button, 1, 12, 1, 1) + box.attach(show_attach_label, 0, 13, 1, 1) + box.attach(show_attach, 1, 13, 1, 1) self.add(box) From 8f6c8690cf0958989c362864a8c0f9c9be46ec02 Mon Sep 17 00:00:00 2001 From: Adrian Edwards <17362949+MoralCode@users.noreply.github.com> Date: Wed, 14 Oct 2020 12:25:56 -0700 Subject: [PATCH 02/29] add guild option to config --- discover_overlay/text_settings.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/discover_overlay/text_settings.py b/discover_overlay/text_settings.py index 5715775..9fae97a 100644 --- a/discover_overlay/text_settings.py +++ b/discover_overlay/text_settings.py @@ -96,6 +96,7 @@ class TextSettingsWindow(SettingsWindow): 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.bg_col = json.loads(config.get( "text", "bg_col", fallback="[0.0,0.0,0.0,0.5]")) @@ -139,6 +140,7 @@ class TextSettingsWindow(SettingsWindow): config.set("text", "floating_w", "%s" % (self.floating_w)) config.set("text", "floating_h", "%s" % (self.floating_h)) config.set("text", "channel", self.channel) + config.set("text", "guild", self.guild) config.set("text", "bg_col", json.dumps(self.bg_col)) config.set("text", "fg_col", json.dumps(self.fg_col)) config.set("text", "popup_style", "%s" % (int(self.popup_style))) From 75a25f3ec4d5a0e0f4ce3b9ee4d8a8906f779656 Mon Sep 17 00:00:00 2001 From: Adrian Edwards <17362949+MoralCode@users.noreply.github.com> Date: Wed, 14 Oct 2020 12:27:10 -0700 Subject: [PATCH 03/29] duplicate and tweak `change_channel` to use as `change_guild` --- discover_overlay/text_settings.py | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/discover_overlay/text_settings.py b/discover_overlay/text_settings.py index 9fae97a..8526c5f 100644 --- a/discover_overlay/text_settings.py +++ b/discover_overlay/text_settings.py @@ -20,6 +20,7 @@ class TextSettingsWindow(SettingsWindow): self.list_channels_keys = [] self.list_channels = {} self.ignore_channel_change = False + self.ignore_guild_change = False self.create_gui() def present(self): @@ -326,6 +327,21 @@ class TextSettingsWindow(SettingsWindow): c = self.channel_lookup[button.get_active()] self.channel = c self.save_config() + + + def change_guild(self, button): + if self.ignore_guild_change: + return + + g = self.guild if self.guild != "0" else "0" + for guild in self.guild_list(): + guild_id, guild_name = guild + selected = button.get_active() + if selected == guild_name: + g = selected + + self.guild = g + self.save_config() def change_placement(self, button): if self.placement_window: From 741edc96d43b1a9486af3b36e71af69332c9590c Mon Sep 17 00:00:00 2001 From: Adrian Edwards <17362949+MoralCode@users.noreply.github.com> Date: Sun, 18 Oct 2020 16:04:26 -0700 Subject: [PATCH 04/29] rename channel model temp variable to c_model --- discover_overlay/text_settings.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/discover_overlay/text_settings.py b/discover_overlay/text_settings.py index 8526c5f..7b08733 100644 --- a/discover_overlay/text_settings.py +++ b/discover_overlay/text_settings.py @@ -43,20 +43,20 @@ class TextSettingsWindow(SettingsWindow): self.text_time_widget.hide() self.text_time_label_widget.hide() - model = Gtk.ListStore(str, bool) + c_model = Gtk.ListStore(str, bool) self.channel_lookup = [] for guild in self.guild_list(): guild_id, guild_name = guild self.channel_lookup.append('0') - model.append([guild_name, False]) + c_model.append([guild_name, False]) for c in self.list_channels_keys: chan = self.list_channels[c] if chan['guild_id'] == guild_id: - model.append([chan["name"], True]) + c_model.append([chan["name"], True]) self.channel_lookup.append(c) - self.channel_widget.set_model(model) - self.channel_model = model + self.channel_widget.set_model(c_model) + self.channel_model = c_model idx = 0 for c in self.channel_lookup: From 5a907309a099ea935864cefd0eb7c9b8c8cbefc5 Mon Sep 17 00:00:00 2001 From: Adrian Edwards <17362949+MoralCode@users.noreply.github.com> Date: Sun, 18 Oct 2020 16:07:13 -0700 Subject: [PATCH 05/29] create and populate g_model and guild_lookup --- discover_overlay/text_settings.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/discover_overlay/text_settings.py b/discover_overlay/text_settings.py index 7b08733..6d9552d 100644 --- a/discover_overlay/text_settings.py +++ b/discover_overlay/text_settings.py @@ -44,11 +44,16 @@ class TextSettingsWindow(SettingsWindow): self.text_time_label_widget.hide() c_model = Gtk.ListStore(str, bool) + g_model = Gtk.ListStore(str, bool) self.channel_lookup = [] + self.guild_lookup = ["0"] + for guild in self.guild_list(): guild_id, guild_name = guild self.channel_lookup.append('0') c_model.append([guild_name, False]) + self.guild_lookup.append(guild) + g_model.append([guild_name, True]) for c in self.list_channels_keys: chan = self.list_channels[c] if chan['guild_id'] == guild_id: From 59d9b877c9dcd95ff77a52ff359ebad6c1015966 Mon Sep 17 00:00:00 2001 From: Adrian Edwards <17362949+MoralCode@users.noreply.github.com> Date: Sun, 18 Oct 2020 16:07:33 -0700 Subject: [PATCH 06/29] set the guild model for the guild widget/UI --- discover_overlay/text_settings.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/discover_overlay/text_settings.py b/discover_overlay/text_settings.py index 6d9552d..890de52 100644 --- a/discover_overlay/text_settings.py +++ b/discover_overlay/text_settings.py @@ -60,6 +60,8 @@ class TextSettingsWindow(SettingsWindow): c_model.append([chan["name"], True]) self.channel_lookup.append(c) + self.guild_widget.set_model(g_model) + self.guild_model = g_model self.channel_widget.set_model(c_model) self.channel_model = c_model From e145437c62fe7f42e673b95002627a6dfee6255b Mon Sep 17 00:00:00 2001 From: Adrian Edwards <17362949+MoralCode@users.noreply.github.com> Date: Sun, 18 Oct 2020 16:09:15 -0700 Subject: [PATCH 07/29] populate the channel model with only channels from the selected guild (if there is one) --- discover_overlay/text_settings.py | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/discover_overlay/text_settings.py b/discover_overlay/text_settings.py index 890de52..36535d1 100644 --- a/discover_overlay/text_settings.py +++ b/discover_overlay/text_settings.py @@ -51,12 +51,19 @@ class TextSettingsWindow(SettingsWindow): for guild in self.guild_list(): guild_id, guild_name = guild self.channel_lookup.append('0') - c_model.append([guild_name, False]) self.guild_lookup.append(guild) g_model.append([guild_name, True]) + + if self.guild == "0": + c_model.append([guild_name, False]) + guilds_by_id = guild_id + else: + guilds_by_id = self.guild + + for c in self.list_channels_keys: chan = self.list_channels[c] - if chan['guild_id'] == guild_id: + if chan['guild_id'] == guilds_by_id: c_model.append([chan["name"], True]) self.channel_lookup.append(c) From fbd3c5b28eaa9afe2861728aa7c538af326d9ab3 Mon Sep 17 00:00:00 2001 From: Adrian Edwards <17362949+MoralCode@users.noreply.github.com> Date: Sun, 18 Oct 2020 16:10:07 -0700 Subject: [PATCH 08/29] prepopoulate the selected guild in the dropdown if one is already selected --- discover_overlay/text_settings.py | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/discover_overlay/text_settings.py b/discover_overlay/text_settings.py index 36535d1..a315376 100644 --- a/discover_overlay/text_settings.py +++ b/discover_overlay/text_settings.py @@ -81,6 +81,15 @@ class TextSettingsWindow(SettingsWindow): break idx += 1 + idxg = 0 + for g in self.guild_lookup: + if g == self.guild: + self.ignore_guild_change = True + self.guild_widget.set_active(idxg) + self.ignore_guild_change = False + break + idxg += 1 + def guild_list(self): guilds = [] done = [] From d663886670608ac0e01c3bea9d8baa7a3f5e3c3e Mon Sep 17 00:00:00 2001 From: Adrian Edwards <17362949+MoralCode@users.noreply.github.com> Date: Sun, 18 Oct 2020 16:10:58 -0700 Subject: [PATCH 09/29] create class-level guild lists for more lookup --- discover_overlay/text_settings.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/discover_overlay/text_settings.py b/discover_overlay/text_settings.py index a315376..5028b8a 100644 --- a/discover_overlay/text_settings.py +++ b/discover_overlay/text_settings.py @@ -19,6 +19,8 @@ class TextSettingsWindow(SettingsWindow): self.init_config() self.list_channels_keys = [] self.list_channels = {} + self.list_guilds_keys = [] + self.list_guilds = {} self.ignore_channel_change = False self.ignore_guild_change = False self.create_gui() From 7fb5e45b09d2ed2089a1ff1da4c98be37472b877 Mon Sep 17 00:00:00 2001 From: Adrian Edwards <17362949+MoralCode@users.noreply.github.com> Date: Sun, 18 Oct 2020 16:11:40 -0700 Subject: [PATCH 10/29] change copy-pasted guild_list function to look up guilds not channels --- discover_overlay/text_settings.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/discover_overlay/text_settings.py b/discover_overlay/text_settings.py index 5028b8a..03ca804 100644 --- a/discover_overlay/text_settings.py +++ b/discover_overlay/text_settings.py @@ -95,10 +95,10 @@ class TextSettingsWindow(SettingsWindow): def guild_list(self): guilds = [] done = [] - for channel in self.list_channels.values(): - if not channel["guild_id"] in done: - done.append(channel["guild_id"]) - guilds.append([channel["guild_id"], channel["guild_name"]]) + for guild in self.list_guilds.values(): + if not guild["id"] in done: + done.append(guild["id"]) + guilds.append([guild["id"], guild["name"]]) return guilds def set_channels(self, in_list): From 8e5232ef80e0b497e3c6b62bf17cce416a1603f4 Mon Sep 17 00:00:00 2001 From: Adrian Edwards <17362949+MoralCode@users.noreply.github.com> Date: Sun, 18 Oct 2020 16:12:12 -0700 Subject: [PATCH 11/29] create a function for populating top-level guild lookup lists --- discover_overlay/text_settings.py | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/discover_overlay/text_settings.py b/discover_overlay/text_settings.py index 03ca804..295005a 100644 --- a/discover_overlay/text_settings.py +++ b/discover_overlay/text_settings.py @@ -108,6 +108,13 @@ class TextSettingsWindow(SettingsWindow): if in_list[key]["type"] == 0: self.list_channels_keys.append(key) self.list_channels_keys.sort() + + def set_guilds(self, in_list): + self.list_guilds = in_list + self.list_guilds_keys = [] + for key in in_list.keys(): + self.list_guilds_keys.append(key) + self.list_guilds_keys.sort() def read_config(self): config = ConfigParser(interpolation=None) From cde125874ce31bbfbaeafe237179ec7923df4800 Mon Sep 17 00:00:00 2001 From: Adrian Edwards <17362949+MoralCode@users.noreply.github.com> Date: Sun, 18 Oct 2020 16:12:39 -0700 Subject: [PATCH 12/29] call the function to populate the top level lists --- discover_overlay/discord_connector.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/discover_overlay/discord_connector.py b/discover_overlay/discord_connector.py index 09ee2a5..f979a62 100644 --- a/discover_overlay/discord_connector.py +++ b/discover_overlay/discord_connector.py @@ -413,6 +413,8 @@ class DiscordConnector: self.text_altered = False # Update text channels self.text_settings.set_channels(self.channels) + # Update guilds + self.text_settings.set_guilds(self.guilds) # Check for changed channel if self.authed: self.set_text_channel(self.text_settings.get_channel()) From b1115a3fe442c8e4b7cd63786edba17121f70439 Mon Sep 17 00:00:00 2001 From: Adrian Edwards <17362949+MoralCode@users.noreply.github.com> Date: Sun, 18 Oct 2020 16:12:56 -0700 Subject: [PATCH 13/29] simplify guild lookup when changing guilds --- discover_overlay/text_settings.py | 9 +-------- 1 file changed, 1 insertion(+), 8 deletions(-) diff --git a/discover_overlay/text_settings.py b/discover_overlay/text_settings.py index 295005a..2819869 100644 --- a/discover_overlay/text_settings.py +++ b/discover_overlay/text_settings.py @@ -364,14 +364,7 @@ class TextSettingsWindow(SettingsWindow): def change_guild(self, button): if self.ignore_guild_change: return - - g = self.guild if self.guild != "0" else "0" - for guild in self.guild_list(): - guild_id, guild_name = guild - selected = button.get_active() - if selected == guild_name: - g = selected - + g = self.guild_lookup[button.get_active()] self.guild = g self.save_config() From 7dd5a44c70ba4a8357179a4c5fba86e55c52320e Mon Sep 17 00:00:00 2001 From: Adrian Edwards <17362949+MoralCode@users.noreply.github.com> Date: Sun, 18 Oct 2020 16:13:22 -0700 Subject: [PATCH 14/29] link to documentation explaining the magic number for channel type --- discover_overlay/text_settings.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/discover_overlay/text_settings.py b/discover_overlay/text_settings.py index 2819869..5057c0b 100644 --- a/discover_overlay/text_settings.py +++ b/discover_overlay/text_settings.py @@ -105,6 +105,8 @@ class TextSettingsWindow(SettingsWindow): self.list_channels = in_list self.list_channels_keys = [] for key in in_list.keys(): + # filter for only text channels + # https://discord.com/developers/docs/resources/channel#channel-object-channel-types if in_list[key]["type"] == 0: self.list_channels_keys.append(key) self.list_channels_keys.sort() From b1adea41991c344fa2a78eb132251905623d4f8b Mon Sep 17 00:00:00 2001 From: Adrian Edwards <17362949+MoralCode@users.noreply.github.com> Date: Sun, 18 Oct 2020 16:30:08 -0700 Subject: [PATCH 15/29] fix guild selection not populating previously selected value --- discover_overlay/text_settings.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/discover_overlay/text_settings.py b/discover_overlay/text_settings.py index 5057c0b..12ff921 100644 --- a/discover_overlay/text_settings.py +++ b/discover_overlay/text_settings.py @@ -85,7 +85,7 @@ class TextSettingsWindow(SettingsWindow): idxg = 0 for g in self.guild_lookup: - if g == self.guild: + if g[0] == self.guild: self.ignore_guild_change = True self.guild_widget.set_active(idxg) self.ignore_guild_change = False From e11ba8eb96ff98ddb19c7c50e8822e4e429abb52 Mon Sep 17 00:00:00 2001 From: Adrian Edwards <17362949+MoralCode@users.noreply.github.com> Date: Sun, 18 Oct 2020 16:30:28 -0700 Subject: [PATCH 16/29] set the guild as well if guild and channel do not match --- discover_overlay/text_settings.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/discover_overlay/text_settings.py b/discover_overlay/text_settings.py index 12ff921..7ed642e 100644 --- a/discover_overlay/text_settings.py +++ b/discover_overlay/text_settings.py @@ -360,6 +360,9 @@ class TextSettingsWindow(SettingsWindow): return c = self.channel_lookup[button.get_active()] self.channel = c + # if the channel is not from the current guild, set the guild too + if c["guild_id"] != self.guild: + self.guild = c["guild_id"] self.save_config() From f6da14636a188bca6703967512d168635fcf3c35 Mon Sep 17 00:00:00 2001 From: Adrian Edwards <17362949+MoralCode@users.noreply.github.com> Date: Sun, 18 Oct 2020 16:30:51 -0700 Subject: [PATCH 17/29] remove needless appending of "0" to channel_lookup --- discover_overlay/text_settings.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/discover_overlay/text_settings.py b/discover_overlay/text_settings.py index 7ed642e..dbb328d 100644 --- a/discover_overlay/text_settings.py +++ b/discover_overlay/text_settings.py @@ -47,12 +47,11 @@ class TextSettingsWindow(SettingsWindow): c_model = Gtk.ListStore(str, bool) g_model = Gtk.ListStore(str, bool) - self.channel_lookup = [] + self.channel_lookup = ["0"] self.guild_lookup = ["0"] for guild in self.guild_list(): guild_id, guild_name = guild - self.channel_lookup.append('0') self.guild_lookup.append(guild) g_model.append([guild_name, True]) From 52d3d39241e3cadc944e5085173e4b0b58c0ef64 Mon Sep 17 00:00:00 2001 From: Adrian Edwards <17362949+MoralCode@users.noreply.github.com> Date: Sun, 18 Oct 2020 16:31:45 -0700 Subject: [PATCH 18/29] set the guild's id as the config value because lists arent allowed and this is apparently a list --- discover_overlay/text_settings.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/discover_overlay/text_settings.py b/discover_overlay/text_settings.py index dbb328d..a00aef3 100644 --- a/discover_overlay/text_settings.py +++ b/discover_overlay/text_settings.py @@ -368,8 +368,9 @@ class TextSettingsWindow(SettingsWindow): def change_guild(self, button): if self.ignore_guild_change: return - g = self.guild_lookup[button.get_active()] - self.guild = g + g = self.guild_lookup[button.get_active()] + # get the guilds ID because config values must be strings + self.guild = g[0] self.save_config() def change_placement(self, button): From 866145e61e18e5b0de8e483ef33f49a529cdef82 Mon Sep 17 00:00:00 2001 From: Adrian Edwards <17362949+MoralCode@users.noreply.github.com> Date: Sun, 18 Oct 2020 16:32:14 -0700 Subject: [PATCH 19/29] set a default value for guilds_by_id middleman variable so that it has the right scope (?) --- discover_overlay/text_settings.py | 1 + 1 file changed, 1 insertion(+) diff --git a/discover_overlay/text_settings.py b/discover_overlay/text_settings.py index a00aef3..896c67c 100644 --- a/discover_overlay/text_settings.py +++ b/discover_overlay/text_settings.py @@ -55,6 +55,7 @@ class TextSettingsWindow(SettingsWindow): self.guild_lookup.append(guild) g_model.append([guild_name, True]) + guilds_by_id = "0" if self.guild == "0": c_model.append([guild_name, False]) guilds_by_id = guild_id From d45065a51cabe03a3d05455fa438259102fb387b Mon Sep 17 00:00:00 2001 From: Adrian Edwards <17362949+MoralCode@users.noreply.github.com> Date: Sun, 18 Oct 2020 16:42:46 -0700 Subject: [PATCH 20/29] create a constant to store the default guild id --- discover_overlay/text_settings.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/discover_overlay/text_settings.py b/discover_overlay/text_settings.py index 896c67c..cfa92c0 100644 --- a/discover_overlay/text_settings.py +++ b/discover_overlay/text_settings.py @@ -7,6 +7,7 @@ from .settings import SettingsWindow from gi.repository import Gtk, Gdk, Pango import logging +GUILD_DEFAULT_VALUE = "0" class TextSettingsWindow(SettingsWindow): def __init__(self, overlay): @@ -48,7 +49,7 @@ class TextSettingsWindow(SettingsWindow): c_model = Gtk.ListStore(str, bool) g_model = Gtk.ListStore(str, bool) self.channel_lookup = ["0"] - self.guild_lookup = ["0"] + self.guild_lookup = [GUILD_DEFAULT_VALUE] for guild in self.guild_list(): guild_id, guild_name = guild @@ -56,7 +57,7 @@ class TextSettingsWindow(SettingsWindow): g_model.append([guild_name, True]) guilds_by_id = "0" - if self.guild == "0": + if self.guild == GUILD_DEFAULT_VALUE: c_model.append([guild_name, False]) guilds_by_id = guild_id else: @@ -131,7 +132,7 @@ class TextSettingsWindow(SettingsWindow): 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.guild = config.get("text", "guild", fallback=GUILD_DEFAULT_VALUE) self.font = config.get("text", "font", fallback=None) self.bg_col = json.loads(config.get( "text", "bg_col", fallback="[0.0,0.0,0.0,0.5]")) From 11c8b257d196e8992c107a3c762c0989e5e59aa6 Mon Sep 17 00:00:00 2001 From: Adrian Edwards <17362949+MoralCode@users.noreply.github.com> Date: Sun, 18 Oct 2020 16:45:38 -0700 Subject: [PATCH 21/29] fix duplicate channels in channel list for one guild --- discover_overlay/text_settings.py | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/discover_overlay/text_settings.py b/discover_overlay/text_settings.py index cfa92c0..3464e36 100644 --- a/discover_overlay/text_settings.py +++ b/discover_overlay/text_settings.py @@ -56,17 +56,20 @@ class TextSettingsWindow(SettingsWindow): self.guild_lookup.append(guild) g_model.append([guild_name, True]) - guilds_by_id = "0" + # if no guild is specified, poulate channel list with every channel from each guild if self.guild == GUILD_DEFAULT_VALUE: c_model.append([guild_name, False]) - guilds_by_id = guild_id - else: - guilds_by_id = self.guild - - + for c in self.list_channels_keys: + chan = self.list_channels[c] + if chan['guild_id'] == guild_id: + c_model.append([chan["name"], True]) + self.channel_lookup.append(c) + + # if a guild is specified, poulate channel list with every channel from *just that guild* + if self.guild != GUILD_DEFAULT_VALUE: for c in self.list_channels_keys: chan = self.list_channels[c] - if chan['guild_id'] == guilds_by_id: + if chan['guild_id'] == self.guild: c_model.append([chan["name"], True]) self.channel_lookup.append(c) From 145586a85ea40f3b75a61962e95edd5fa6d2f2ad Mon Sep 17 00:00:00 2001 From: Adrian Edwards <17362949+MoralCode@users.noreply.github.com> Date: Sun, 18 Oct 2020 16:46:02 -0700 Subject: [PATCH 22/29] correctly fetch the guild ID for a channel when setting it in change_channel --- discover_overlay/text_settings.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/discover_overlay/text_settings.py b/discover_overlay/text_settings.py index 3464e36..46d0196 100644 --- a/discover_overlay/text_settings.py +++ b/discover_overlay/text_settings.py @@ -364,9 +364,10 @@ class TextSettingsWindow(SettingsWindow): return c = self.channel_lookup[button.get_active()] self.channel = c + channel_guild = self.list_channels[c]["guild_id"] # if the channel is not from the current guild, set the guild too - if c["guild_id"] != self.guild: - self.guild = c["guild_id"] + if channel_guild != self.guild: + self.guild = channel_guild self.save_config() From 3bafb21ab3675831437a2ff90999efb278b929ff Mon Sep 17 00:00:00 2001 From: Adrian Edwards <17362949+MoralCode@users.noreply.github.com> Date: Sun, 18 Oct 2020 16:57:56 -0700 Subject: [PATCH 23/29] create update_channel_model function to update the channel selections when the guild is changed --- discover_overlay/text_settings.py | 32 ++++++++++++++++++------------- 1 file changed, 19 insertions(+), 13 deletions(-) diff --git a/discover_overlay/text_settings.py b/discover_overlay/text_settings.py index 46d0196..a6e880b 100644 --- a/discover_overlay/text_settings.py +++ b/discover_overlay/text_settings.py @@ -46,9 +46,7 @@ class TextSettingsWindow(SettingsWindow): self.text_time_widget.hide() self.text_time_label_widget.hide() - c_model = Gtk.ListStore(str, bool) g_model = Gtk.ListStore(str, bool) - self.channel_lookup = ["0"] self.guild_lookup = [GUILD_DEFAULT_VALUE] for guild in self.guild_list(): @@ -56,6 +54,25 @@ class TextSettingsWindow(SettingsWindow): self.guild_lookup.append(guild) g_model.append([guild_name, True]) + self.guild_widget.set_model(g_model) + self.guild_model = g_model + self.update_channel_model() + + idxg = 0 + for g in self.guild_lookup: + if g[0] == self.guild: + self.ignore_guild_change = True + self.guild_widget.set_active(idxg) + self.ignore_guild_change = False + break + idxg += 1 + + def update_channel_model(self): + c_model = Gtk.ListStore(str, bool) + self.channel_lookup = ["0"] + + for guild in self.guild_list(): + guild_id, guild_name = guild # if no guild is specified, poulate channel list with every channel from each guild if self.guild == GUILD_DEFAULT_VALUE: c_model.append([guild_name, False]) @@ -73,8 +90,6 @@ class TextSettingsWindow(SettingsWindow): c_model.append([chan["name"], True]) self.channel_lookup.append(c) - self.guild_widget.set_model(g_model) - self.guild_model = g_model self.channel_widget.set_model(c_model) self.channel_model = c_model @@ -87,15 +102,6 @@ class TextSettingsWindow(SettingsWindow): break idx += 1 - idxg = 0 - for g in self.guild_lookup: - if g[0] == self.guild: - self.ignore_guild_change = True - self.guild_widget.set_active(idxg) - self.ignore_guild_change = False - break - idxg += 1 - def guild_list(self): guilds = [] done = [] From 31b7cbd32402bd4d8bfd79483db80ee301d7ad93 Mon Sep 17 00:00:00 2001 From: Adrian Edwards <17362949+MoralCode@users.noreply.github.com> Date: Sun, 18 Oct 2020 16:58:27 -0700 Subject: [PATCH 24/29] move update_channel_model above present() as it is called there --- discover_overlay/text_settings.py | 71 ++++++++++++++++--------------- 1 file changed, 36 insertions(+), 35 deletions(-) diff --git a/discover_overlay/text_settings.py b/discover_overlay/text_settings.py index a6e880b..b821f03 100644 --- a/discover_overlay/text_settings.py +++ b/discover_overlay/text_settings.py @@ -26,6 +26,42 @@ class TextSettingsWindow(SettingsWindow): self.ignore_guild_change = False self.create_gui() + def update_channel_model(self): + c_model = Gtk.ListStore(str, bool) + self.channel_lookup = ["0"] + + for guild in self.guild_list(): + guild_id, guild_name = guild + # if no guild is specified, poulate channel list with every channel from each guild + if self.guild == GUILD_DEFAULT_VALUE: + c_model.append([guild_name, False]) + for c in self.list_channels_keys: + chan = self.list_channels[c] + if chan['guild_id'] == guild_id: + c_model.append([chan["name"], True]) + self.channel_lookup.append(c) + + # if a guild is specified, poulate channel list with every channel from *just that guild* + if self.guild != GUILD_DEFAULT_VALUE: + for c in self.list_channels_keys: + chan = self.list_channels[c] + if chan['guild_id'] == self.guild: + c_model.append([chan["name"], True]) + self.channel_lookup.append(c) + + self.channel_widget.set_model(c_model) + self.channel_model = c_model + + idx = 0 + for c in self.channel_lookup: + if c == self.channel: + self.ignore_channel_change = True + self.channel_widget.set_active(idx) + self.ignore_channel_change = False + break + idx += 1 + + def present(self): self.show_all() if not self.floating: @@ -67,41 +103,6 @@ class TextSettingsWindow(SettingsWindow): break idxg += 1 - def update_channel_model(self): - c_model = Gtk.ListStore(str, bool) - self.channel_lookup = ["0"] - - for guild in self.guild_list(): - guild_id, guild_name = guild - # if no guild is specified, poulate channel list with every channel from each guild - if self.guild == GUILD_DEFAULT_VALUE: - c_model.append([guild_name, False]) - for c in self.list_channels_keys: - chan = self.list_channels[c] - if chan['guild_id'] == guild_id: - c_model.append([chan["name"], True]) - self.channel_lookup.append(c) - - # if a guild is specified, poulate channel list with every channel from *just that guild* - if self.guild != GUILD_DEFAULT_VALUE: - for c in self.list_channels_keys: - chan = self.list_channels[c] - if chan['guild_id'] == self.guild: - c_model.append([chan["name"], True]) - self.channel_lookup.append(c) - - self.channel_widget.set_model(c_model) - self.channel_model = c_model - - idx = 0 - for c in self.channel_lookup: - if c == self.channel: - self.ignore_channel_change = True - self.channel_widget.set_active(idx) - self.ignore_channel_change = False - break - idx += 1 - def guild_list(self): guilds = [] done = [] From 9f7d0b44e950af157984281f664b24fc4d7281f5 Mon Sep 17 00:00:00 2001 From: Adrian Edwards <17362949+MoralCode@users.noreply.github.com> Date: Sun, 18 Oct 2020 17:25:09 -0700 Subject: [PATCH 25/29] fix consistency of guild_lookup data --- discover_overlay/text_settings.py | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/discover_overlay/text_settings.py b/discover_overlay/text_settings.py index b821f03..0084431 100644 --- a/discover_overlay/text_settings.py +++ b/discover_overlay/text_settings.py @@ -87,7 +87,7 @@ class TextSettingsWindow(SettingsWindow): for guild in self.guild_list(): guild_id, guild_name = guild - self.guild_lookup.append(guild) + self.guild_lookup.append(guild_id) g_model.append([guild_name, True]) self.guild_widget.set_model(g_model) @@ -95,8 +95,8 @@ class TextSettingsWindow(SettingsWindow): self.update_channel_model() idxg = 0 - for g in self.guild_lookup: - if g[0] == self.guild: + for guild_id in self.guild_lookup: + if guild_id == self.guild: self.ignore_guild_change = True self.guild_widget.set_active(idxg) self.ignore_guild_change = False @@ -381,9 +381,8 @@ class TextSettingsWindow(SettingsWindow): def change_guild(self, button): if self.ignore_guild_change: return - g = self.guild_lookup[button.get_active()] - # get the guilds ID because config values must be strings - self.guild = g[0] + guild_id = self.guild_lookup[button.get_active()] + self.guild = guild_id self.save_config() def change_placement(self, button): From 87df7c85cabf405044f65723778166156e375e64 Mon Sep 17 00:00:00 2001 From: Adrian Edwards <17362949+MoralCode@users.noreply.github.com> Date: Sun, 18 Oct 2020 19:05:05 -0700 Subject: [PATCH 26/29] update comments --- discover_overlay/text_settings.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/discover_overlay/text_settings.py b/discover_overlay/text_settings.py index 0084431..96af101 100644 --- a/discover_overlay/text_settings.py +++ b/discover_overlay/text_settings.py @@ -27,12 +27,14 @@ class TextSettingsWindow(SettingsWindow): self.create_gui() def update_channel_model(self): + # potentially organize channels by their group/parent_id + # https://discord.com/developers/docs/resources/channel#channel-object-channel-structure c_model = Gtk.ListStore(str, bool) self.channel_lookup = ["0"] for guild in self.guild_list(): guild_id, guild_name = guild - # if no guild is specified, poulate channel list with every channel from each guild + # if no guild is specified, populate channel list with every channel from each guild if self.guild == GUILD_DEFAULT_VALUE: c_model.append([guild_name, False]) for c in self.list_channels_keys: From 1215e6f5613496ab2ef8709a6cfeab74eac80eab Mon Sep 17 00:00:00 2001 From: Adrian Edwards <17362949+MoralCode@users.noreply.github.com> Date: Sun, 18 Oct 2020 19:05:39 -0700 Subject: [PATCH 27/29] fix off-by-one issue when selecting a guild --- discover_overlay/text_settings.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/discover_overlay/text_settings.py b/discover_overlay/text_settings.py index 96af101..4a681a0 100644 --- a/discover_overlay/text_settings.py +++ b/discover_overlay/text_settings.py @@ -85,7 +85,7 @@ class TextSettingsWindow(SettingsWindow): self.text_time_label_widget.hide() g_model = Gtk.ListStore(str, bool) - self.guild_lookup = [GUILD_DEFAULT_VALUE] + self.guild_lookup = [] for guild in self.guild_list(): guild_id, guild_name = guild From e3bcddcf4f8838261d6dd289e87b04f78bd85e46 Mon Sep 17 00:00:00 2001 From: Adrian Edwards <17362949+MoralCode@users.noreply.github.com> Date: Sun, 18 Oct 2020 19:07:10 -0700 Subject: [PATCH 28/29] update channel list when a new server is selected --- discover_overlay/text_settings.py | 1 + 1 file changed, 1 insertion(+) diff --git a/discover_overlay/text_settings.py b/discover_overlay/text_settings.py index 4a681a0..28864a8 100644 --- a/discover_overlay/text_settings.py +++ b/discover_overlay/text_settings.py @@ -386,6 +386,7 @@ class TextSettingsWindow(SettingsWindow): guild_id = self.guild_lookup[button.get_active()] self.guild = guild_id self.save_config() + self.update_channel_model() def change_placement(self, button): if self.placement_window: From a20f80ac79ab4a471108895da4b02ec1f6279a7d Mon Sep 17 00:00:00 2001 From: Adrian Edwards <17362949+MoralCode@users.noreply.github.com> Date: Sun, 18 Oct 2020 19:09:52 -0700 Subject: [PATCH 29/29] remove guild update from channel update function --- discover_overlay/text_settings.py | 4 ---- 1 file changed, 4 deletions(-) diff --git a/discover_overlay/text_settings.py b/discover_overlay/text_settings.py index 28864a8..f06f440 100644 --- a/discover_overlay/text_settings.py +++ b/discover_overlay/text_settings.py @@ -373,10 +373,6 @@ class TextSettingsWindow(SettingsWindow): return c = self.channel_lookup[button.get_active()] self.channel = c - channel_guild = self.list_channels[c]["guild_id"] - # if the channel is not from the current guild, set the guild too - if channel_guild != self.guild: - self.guild = channel_guild self.save_config()