- Pass channel data between settings & overlay
This commit is contained in:
parent
16dacf9e97
commit
6f442524a4
5 changed files with 126 additions and 62 deletions
|
|
@ -56,6 +56,7 @@ class DiscordConnector:
|
|||
self.current_guild = "0"
|
||||
self.current_voice = "0"
|
||||
self.current_text = "0"
|
||||
self.current_text_guild = "0"
|
||||
self.list_altered = False
|
||||
self.text_altered = False
|
||||
self.text = []
|
||||
|
|
@ -118,15 +119,20 @@ class DiscordConnector:
|
|||
if need_req:
|
||||
self.req_channel_details(channel)
|
||||
|
||||
def set_text_channel(self, channel, need_req=True):
|
||||
def set_text_channel(self, channel, guild, need_req=True):
|
||||
"""
|
||||
Set currently active text channel
|
||||
"""
|
||||
if not channel:
|
||||
self.current_text = "0"
|
||||
self.current_text_guild = "0"
|
||||
return
|
||||
if guild != self.current_text_guild:
|
||||
self.current_text_guild = guild
|
||||
self.request_text_rooms_for_guild(guild)
|
||||
if channel != self.current_text:
|
||||
self.current_text = channel
|
||||
self.current_text_guild = guild
|
||||
self.start_listening_text(channel)
|
||||
if need_req:
|
||||
self.req_channel_details(channel)
|
||||
|
|
@ -346,6 +352,7 @@ class DiscordConnector:
|
|||
elif j["cmd"] == "GET_GUILDS":
|
||||
for guild in j["data"]["guilds"]:
|
||||
self.guilds[guild["id"]] = guild
|
||||
self.dump_channel_data()
|
||||
# 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:
|
||||
|
|
@ -358,6 +365,8 @@ class DiscordConnector:
|
|||
# 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"])
|
||||
self.dump_channel_data()
|
||||
|
||||
return
|
||||
elif j["cmd"] == "GET_CHANNELS":
|
||||
self.guilds[j['nonce']]["channels"] = j["data"]["channels"]
|
||||
|
|
@ -367,6 +376,8 @@ class DiscordConnector:
|
|||
self.channels[channel["id"]] = channel
|
||||
if channel["type"] == 2:
|
||||
self.req_channel_details(channel["id"])
|
||||
self.dump_channel_data()
|
||||
|
||||
# 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(
|
||||
|
|
@ -425,6 +436,10 @@ class DiscordConnector:
|
|||
elif j["cmd"] == "GET_VOICE_SETTINGS":
|
||||
return
|
||||
log.warning(j)
|
||||
|
||||
def dump_channel_data(self):
|
||||
with open(self.discover.channel_file, 'w') as f:
|
||||
f.write(json.dumps({'channels': self.channels, 'guild': self.guilds}))
|
||||
|
||||
def on_connected(self):
|
||||
"""
|
||||
|
|
@ -714,8 +729,9 @@ class DiscordConnector:
|
|||
self.text, self.text_altered)
|
||||
self.text_altered = False
|
||||
|
||||
if len(self.rate_limited_channels) > 0:
|
||||
if self.authed and len(self.rate_limited_channels) > 0:
|
||||
guild = self.rate_limited_channels.pop()
|
||||
|
||||
cmd = {
|
||||
"cmd": "GET_CHANNELS",
|
||||
"args": {
|
||||
|
|
@ -763,8 +779,8 @@ class DiscordConnector:
|
|||
"""
|
||||
if(guild_id == 0):
|
||||
return
|
||||
if guild_id in self.guilds:
|
||||
self.req_guild(guild_id, "refresh")
|
||||
self.rate_limited_channels.append(guild_id)
|
||||
|
||||
|
||||
def connect(self):
|
||||
"""
|
||||
|
|
|
|||
|
|
@ -48,7 +48,7 @@ _ = t.gettext
|
|||
class Discover:
|
||||
"""Main application class"""
|
||||
|
||||
def __init__(self, rpc_file, config_file, debug_file, args):
|
||||
def __init__(self, rpc_file, config_file, channel_file, debug_file, args):
|
||||
self.mix_settings = False
|
||||
self.ind = None
|
||||
self.tray = None
|
||||
|
|
@ -58,6 +58,7 @@ class Discover:
|
|||
self.settings = None
|
||||
|
||||
self.debug_file = debug_file
|
||||
self.channel_file = channel_file
|
||||
|
||||
self.do_args(args, True)
|
||||
if "GAMESCOPE_WAYLAND_DISPLAY" in os.environ:
|
||||
|
|
@ -167,10 +168,17 @@ class Discover:
|
|||
if "--undeaf" in data:
|
||||
if self.connection:
|
||||
self.connection.set_deaf(False)
|
||||
if "--refresh-guilds" in data:
|
||||
if self.connection:
|
||||
self.connection.req_guilds()
|
||||
pattern = re.compile("--moveto=([0-9]+)")
|
||||
if any((match := pattern.match(x)) for x in data):
|
||||
if self.connection:
|
||||
self.connection.change_voice_room(match.group(1))
|
||||
guild_pattern = re.compile("--guild-request=([0-9]+)")
|
||||
if any((match := guild_pattern.match(x)) for x in data):
|
||||
if self.connection:
|
||||
self.connection.request_text_rooms_for_guild(match.group(1))
|
||||
|
||||
def rpc_changed(self, _a=None, _b=None, _c=None, _d=None):
|
||||
"""
|
||||
|
|
@ -288,13 +296,16 @@ class Discover:
|
|||
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")
|
||||
floating = config.getboolean("text", "floating", fallback=True)
|
||||
floating_x = config.getint("text", "floating_x", fallback=0)
|
||||
floating_y = config.getint("text", "floating_y", fallback=0)
|
||||
floating_w = config.getint("text", "floating_w", fallback=400)
|
||||
floating_h = config.getint("text", "floating_h", fallback=400)
|
||||
|
||||
channel = config.get("text", "channel", fallback="0")
|
||||
guild = config.get("text", "guild", fallback="0")
|
||||
self.connection.set_text_channel(channel, guild)
|
||||
|
||||
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]")))
|
||||
|
|
@ -481,8 +492,8 @@ def entrypoint():
|
|||
for arg in sys.argv[1:]:
|
||||
line = "%s %s" % (line, arg)
|
||||
|
||||
pid_file = os.path.join(config_dir, "discover_overlay.pid")
|
||||
rpc_file = os.path.join(config_dir, "discover_overlay.rpc")
|
||||
channel_file = os.path.join(config_dir, "channels.rpc")
|
||||
config_file = os.path.join(config_dir, "config.ini")
|
||||
debug_file = os.path.join(config_dir, "output.txt")
|
||||
logging.getLogger().setLevel(logging.INFO)
|
||||
|
|
@ -502,12 +513,12 @@ def entrypoint():
|
|||
log.warning("Sent RPC command")
|
||||
else:
|
||||
if "-c" in sys.argv or "--configure" in sys.argv:
|
||||
settings = MainSettingsWindow(config_file)
|
||||
settings = MainSettingsWindow(config_file, rpc_file, channel_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:])
|
||||
Discover(rpc_file, config_file, channel_file, debug_file, sys.argv[1:])
|
||||
return
|
||||
|
||||
except Exception as ex:
|
||||
|
|
|
|||
|
|
@ -1448,20 +1448,6 @@
|
|||
<property name="top-attach">2</property>
|
||||
</packing>
|
||||
</child>
|
||||
<child>
|
||||
<object class="GtkButton">
|
||||
<property name="label" translatable="yes">Refresh List</property>
|
||||
<property name="name">text_refresh_channel_button</property>
|
||||
<property name="visible">True</property>
|
||||
<property name="can-focus">True</property>
|
||||
<property name="receives-default">True</property>
|
||||
<signal name="pressed" handler="text_channel_refresh" swapped="no"/>
|
||||
</object>
|
||||
<packing>
|
||||
<property name="left-attach">2</property>
|
||||
<property name="top-attach">3</property>
|
||||
</packing>
|
||||
</child>
|
||||
<child>
|
||||
<object class="GtkFontButton">
|
||||
<property name="name">text_font</property>
|
||||
|
|
@ -1552,7 +1538,6 @@
|
|||
<property name="name">text_server</property>
|
||||
<property name="visible">True</property>
|
||||
<property name="can-focus">False</property>
|
||||
<signal name="changed" handler="text_server_changed" swapped="no"/>
|
||||
</object>
|
||||
<packing>
|
||||
<property name="left-attach">1</property>
|
||||
|
|
@ -1564,7 +1549,6 @@
|
|||
<property name="name">text_channel</property>
|
||||
<property name="visible">True</property>
|
||||
<property name="can-focus">False</property>
|
||||
<signal name="changed" handler="text_channel_changed" swapped="no"/>
|
||||
</object>
|
||||
<packing>
|
||||
<property name="left-attach">1</property>
|
||||
|
|
@ -1610,6 +1594,9 @@
|
|||
<child>
|
||||
<placeholder/>
|
||||
</child>
|
||||
<child>
|
||||
<placeholder/>
|
||||
</child>
|
||||
</object>
|
||||
<packing>
|
||||
<property name="position">2</property>
|
||||
|
|
|
|||
|
|
@ -1448,20 +1448,6 @@
|
|||
<property name="top-attach">2</property>
|
||||
</packing>
|
||||
</child>
|
||||
<child>
|
||||
<object class="GtkButton">
|
||||
<property name="label" translatable="yes">Refresh List</property>
|
||||
<property name="name">text_refresh_channel_button</property>
|
||||
<property name="visible">True</property>
|
||||
<property name="can-focus">True</property>
|
||||
<property name="receives-default">True</property>
|
||||
<signal name="pressed" handler="text_channel_refresh" swapped="no"/>
|
||||
</object>
|
||||
<packing>
|
||||
<property name="left-attach">2</property>
|
||||
<property name="top-attach">3</property>
|
||||
</packing>
|
||||
</child>
|
||||
<child>
|
||||
<object class="GtkFontButton">
|
||||
<property name="name">text_font</property>
|
||||
|
|
@ -1484,6 +1470,7 @@
|
|||
<property name="visible">True</property>
|
||||
<property name="can-focus">True</property>
|
||||
<property name="receives-default">True</property>
|
||||
<property name="use-alpha">True</property>
|
||||
<signal name="color-set" handler="text_colour_changed" swapped="no"/>
|
||||
</object>
|
||||
<packing>
|
||||
|
|
@ -1497,6 +1484,7 @@
|
|||
<property name="visible">True</property>
|
||||
<property name="can-focus">True</property>
|
||||
<property name="receives-default">True</property>
|
||||
<property name="use-alpha">True</property>
|
||||
<signal name="color-set" handler="text_background_colour_changed" swapped="no"/>
|
||||
</object>
|
||||
<packing>
|
||||
|
|
@ -1608,6 +1596,9 @@
|
|||
<child>
|
||||
<placeholder/>
|
||||
</child>
|
||||
<child>
|
||||
<placeholder/>
|
||||
</child>
|
||||
</object>
|
||||
<packing>
|
||||
<property name="position">2</property>
|
||||
|
|
@ -1837,6 +1828,7 @@
|
|||
<property name="visible">True</property>
|
||||
<property name="can-focus">True</property>
|
||||
<property name="receives-default">True</property>
|
||||
<property name="use-alpha">True</property>
|
||||
<signal name="color-set" handler="notification_text_colour_changed" swapped="no"/>
|
||||
</object>
|
||||
<packing>
|
||||
|
|
@ -1850,6 +1842,7 @@
|
|||
<property name="visible">True</property>
|
||||
<property name="can-focus">True</property>
|
||||
<property name="receives-default">True</property>
|
||||
<property name="use-alpha">True</property>
|
||||
<signal name="color-set" handler="notification_background_colour_changed" swapped="no"/>
|
||||
</object>
|
||||
<packing>
|
||||
|
|
|
|||
|
|
@ -23,7 +23,7 @@ from .autostart import Autostart
|
|||
from configparser import ConfigParser
|
||||
gi.require_version("Gtk", "3.0")
|
||||
# pylint: disable=wrong-import-position,wrong-import-order
|
||||
from gi.repository import Gtk, Gdk # nopep8
|
||||
from gi.repository import Gtk, Gdk ,Gio # nopep8
|
||||
|
||||
log = logging.getLogger(__name__)
|
||||
t = gettext.translation(
|
||||
|
|
@ -34,15 +34,21 @@ _ = t.gettext
|
|||
class MainSettingsWindow():
|
||||
"""Settings class"""
|
||||
|
||||
def __init__(self, config_file):
|
||||
def __init__(self, config_file, rpc_file, channel_file):
|
||||
self.voice_advanced = False
|
||||
self.autostart_helper = Autostart("discover_overlay")
|
||||
self.ind = None
|
||||
self.guild_ids = []
|
||||
self.channel_ids = []
|
||||
self.current_guild = "0"
|
||||
self.current_channel="0"
|
||||
|
||||
self.menu = self.make_menu()
|
||||
self.make_sys_tray_icon(self.menu)
|
||||
|
||||
self.config_file = config_file
|
||||
self.rpc_file = rpc_file
|
||||
self.channel_file = channel_file
|
||||
|
||||
builder = Gtk.Builder.new_from_file(pkg_resources.resource_filename(
|
||||
'discover_overlay', 'glade/settings.glade'))
|
||||
|
|
@ -92,14 +98,59 @@ class MainSettingsWindow():
|
|||
css, Gtk.STYLE_PROVIDER_PRIORITY_USER)
|
||||
self.window = window
|
||||
|
||||
# Fill monitor menus
|
||||
# Fill monitor & guild menus
|
||||
self.populate_monitor_menus()
|
||||
window.get_screen().connect("monitors-changed", self.populate_monitor_menus)
|
||||
|
||||
channel_file = Gio.File.new_for_path(channel_file)
|
||||
self.monitor_channel = channel_file.monitor_file(0, None)
|
||||
self.monitor_channel.connect("changed", self.populate_guild_menu)
|
||||
|
||||
self.read_config()
|
||||
self.server_handler = self.widget['text_server'].connect('changed', self.text_server_changed)
|
||||
self.channel_handler = self.widget['text_channel'].connect('changed', self.text_channel_changed)
|
||||
|
||||
self.populate_guild_menu()
|
||||
|
||||
builder.connect_signals(self)
|
||||
|
||||
window.show()
|
||||
|
||||
def request_channels_from_guild(self, guild_id):
|
||||
with open(self.rpc_file, 'w') as f:
|
||||
f.write('--rpc --guild-request=%s' % (guild_id))
|
||||
|
||||
def populate_guild_menu(self, _a=None, _b=None, _c=None, _d=None):
|
||||
g = self.widget['text_server']
|
||||
c = self.widget['text_channel']
|
||||
g.handler_block(self.server_handler)
|
||||
c.handler_block(self.channel_handler)
|
||||
with open(self.channel_file, "r") as tfile:
|
||||
data = tfile.readlines()
|
||||
if len(data) >= 1:
|
||||
data = json.loads(data[0])
|
||||
self.guild_ids = []
|
||||
self.channel_ids = []
|
||||
g.remove_all()
|
||||
c.remove_all()
|
||||
for guild in data['guild'].values():
|
||||
g.append_text(guild['name'])
|
||||
self.guild_ids.append(guild['id'])
|
||||
if guild['id'] == self.current_guild and 'channels' in guild:
|
||||
for channel in guild['channels']:
|
||||
c.append_text(channel['name'])
|
||||
self.channel_ids.append(channel['id'])
|
||||
|
||||
|
||||
if self.current_guild != "0" and self.current_guild in self.guild_ids:
|
||||
g.set_active(self.guild_ids.index(self.current_guild))
|
||||
|
||||
if self.current_channel != "0" and self.current_channel in self.channel_ids:
|
||||
c.set_active(self.channel_ids.index(self.current_channel))
|
||||
|
||||
g.handler_unblock(self.server_handler)
|
||||
c.handler_unblock(self.channel_handler)
|
||||
|
||||
def populate_monitor_menus(self, _a = None, _b = None):
|
||||
v= self.widget['voice_monitor']
|
||||
t= self.widget['text_monitor']
|
||||
|
|
@ -269,12 +320,9 @@ class MainSettingsWindow():
|
|||
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.current_guild = config.get("text", "guild", fallback="0")
|
||||
|
||||
self.voice_channel = config.get("text", "channel", fallback="0")
|
||||
self.widget['text_channel'].set_active(0)
|
||||
self.current_channel = config.get("text", "channel", fallback="0")
|
||||
|
||||
font = config.get("text", "font", fallback=None)
|
||||
if font:
|
||||
|
|
@ -459,12 +507,8 @@ class MainSettingsWindow():
|
|||
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
|
||||
with open(self.rpc_file, 'w') as f:
|
||||
f.write('--rpc --refresh-guilds')
|
||||
|
||||
def config_set(self, context, key, value):
|
||||
config = ConfigParser(interpolation=None)
|
||||
|
|
@ -620,10 +664,23 @@ class MainSettingsWindow():
|
|||
self.config_set("text", "popup_style", "%s" % (button.get_active()))
|
||||
|
||||
def text_server_changed(self, button):
|
||||
self.config_set("text", "guild", button.get_active_text())
|
||||
if button.get_active() < 0:
|
||||
self.config_set("text", "guild", "0")
|
||||
return
|
||||
guild = self.guild_ids[button.get_active()]
|
||||
if guild and self.current_guild!=guild:
|
||||
self.current_guild = guild
|
||||
self.config_set("text", "guild", guild)
|
||||
self.request_channels_from_guild(guild)
|
||||
|
||||
def text_channel_changed(self, button):
|
||||
self.config_set("text", "channel", button.get_active_text())
|
||||
if button.get_active() < 0:
|
||||
self.config_set("text", "channel", "0")
|
||||
return
|
||||
channel = self.channel_ids[button.get_active()]
|
||||
if channel:
|
||||
self.current_channel = channel
|
||||
self.config_set("text", "channel", channel)
|
||||
|
||||
def text_font_changed(self, button):
|
||||
self.config_set("text", "font", button.get_font())
|
||||
|
|
@ -649,7 +706,7 @@ class MainSettingsWindow():
|
|||
self.config_set("text", "show_attach", "%s" % (button.get_active()))
|
||||
|
||||
def text_line_limit_changed(self, button):
|
||||
self.config_set("text", "line_limit", "%s" % (int(button.get_active())))
|
||||
self.config_set("text", "line_limit", "%s" % (int(button.get_value())))
|
||||
|
||||
def notification_enable_changed(self, button):
|
||||
self.config_set("notification", "enabled", "%s" % (button.get_active()))
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue