- Remove unused classes

This commit is contained in:
trigg 2022-07-14 23:06:27 +01:00
parent 64e48f2c9a
commit 199458cbbd
6 changed files with 1 additions and 2650 deletions

View file

@ -1,154 +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 <https://www.gnu.org/licenses/>.
"""Core Settings Tab"""
import gettext
from configparser import ConfigParser
import gi
import pkg_resources
from .settings import SettingsWindow
from .autostart import Autostart
gi.require_version("Gtk", "3.0")
# pylint: disable=wrong-import-position,wrong-import-order
from gi.repository import Gtk # nopep8
t = gettext.translation(
'default', pkg_resources.resource_filename('discover_overlay', 'locales'), fallback=True)
_ = t.gettext
class GeneralSettingsWindow(SettingsWindow):
"""Core Settings Tab"""
def __init__(self, discover):
SettingsWindow.__init__(self, discover)
self.discover = discover
self.xshape = None
self.show_sys_tray_icon = None
self.show_task = None
self.set_size_request(400, 200)
self.connect("destroy", self.close_window)
self.connect("delete-event", self.close_window)
self.init_config()
self.autostart_helper = Autostart("discover_overlay")
self.placement_window = None
self.create_gui()
def read_config(self):
"""
Read in the 'general' section of config and set overlays
"""
config = ConfigParser(interpolation=None)
config.read(self.config_file)
self.xshape = config.getboolean("general", "xshape", fallback=False)
self.show_sys_tray_icon = config.getboolean(
"general", "showsystray", fallback=True)
self.show_task = config.getboolean(
"general", "showtask", fallback=False)
# Pass all of our config over to the overlay
self.discover.set_force_xshape(self.xshape)
self.discover.set_sys_tray_icon_visible(self.show_sys_tray_icon)
def save_config(self):
"""
Save the 'general' section of config
"""
config = ConfigParser(interpolation=None)
config.read(self.config_file)
if not config.has_section("general"):
config.add_section("general")
config.set("general", "xshape", "%d" % (int(self.xshape)))
config.set("general", "showsystray",
"yes" if self.show_sys_tray_icon else "no")
config.set("general", "showtask", "yes" if self.show_task else "no")
with open(self.config_file, 'w') as file:
config.write(file)
def create_gui(self):
"""
Prepare the GUI
"""
box = Gtk.Grid()
# Auto start
autostart_label = Gtk.Label.new(_("Autostart on boot"))
autostart_label.set_xalign(0)
autostart = Gtk.CheckButton.new()
autostart.set_active(self.autostart_helper.is_auto())
autostart.connect("toggled", self.change_autostart)
# Force XShape
xshape_label = Gtk.Label.new(_("Force XShape"))
xshape_label.set_xalign(0)
xshape = Gtk.CheckButton.new()
xshape.set_active(self.xshape)
xshape.connect("toggled", self.change_xshape)
# Show sys tray
show_sys_tray_icon_label = Gtk.Label.new(_("Show tray icon"))
show_sys_tray_icon_label.set_xalign(0)
show_sys_tray_icon = Gtk.CheckButton.new()
show_sys_tray_icon.set_active(self.show_sys_tray_icon)
show_sys_tray_icon.connect("toggled", self.change_show_sys_tray_icon)
# Show taskbar
show_task_label = Gtk.Label.new(_("Show on taskbar"))
show_task_label.set_xalign(0)
show_task = Gtk.CheckButton.new()
show_task.set_active(self.show_task)
show_task.connect("toggled", self.change_show_task)
box.attach(autostart_label, 0, 0, 1, 1)
box.attach(autostart, 1, 0, 1, 1)
box.attach(xshape_label, 0, 1, 1, 1)
box.attach(xshape, 1, 1, 1, 1)
box.attach(show_sys_tray_icon_label, 0, 2, 1, 1)
box.attach(show_sys_tray_icon, 1, 2, 1, 1)
box.attach(show_task_label, 0, 3, 1, 1)
box.attach(show_task, 1, 3, 1, 1)
self.add(box)
def change_autostart(self, button):
"""
Autostart setting changed
"""
autostart = button.get_active()
self.autostart_helper.set_autostart(autostart)
def change_xshape(self, button):
"""
XShape setting changed
"""
self.discover.set_force_xshape(button.get_active())
self.xshape = button.get_active()
self.save_config()
def change_show_sys_tray_icon(self, button):
"""
Show tray icon setting changed
"""
self.discover.set_sys_tray_icon_visible(button.get_active())
self.show_sys_tray_icon = button.get_active()
self.save_config()
def change_show_task(self, button):
"""
Show in task bar changed
"""
self.discover.set_show_task(button.get_active())
self.show_task = button.get_active()
self.save_config()

View file

@ -1,529 +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 <https://www.gnu.org/licenses/>.
"""Notification setting tab on settings window"""
import gettext
import json
import pkg_resources
from configparser import ConfigParser
import gi
from .settings import SettingsWindow
gi.require_version("Gtk", "3.0")
# pylint: disable=wrong-import-position,wrong-import-order
from gi.repository import Gtk, Gdk # nopep8
GUILD_DEFAULT_VALUE = "0"
t = gettext.translation(
'default', pkg_resources.resource_filename('discover_overlay', 'locales'), fallback=True)
_ = t.gettext
class NotificationSettingsWindow(SettingsWindow):
"""Notification setting tab on settings window"""
def __init__(self, overlay, discover):
SettingsWindow.__init__(self, discover)
self.overlay = overlay
self.placement_window = None
self.init_config()
self.align_x = None
self.align_y = None
self.monitor = None
self.floating = None
self.font = None
self.bg_col = None
self.fg_col = None
self.text_time = None
self.show_icon = None
self.enabled = None
self.limit_width = None
self.icon_left = None
self.padding = None
self.icon_padding = None
self.icon_size = None
self.border_radius = None
self.set_size_request(400, 200)
self.connect("destroy", self.close_window)
self.connect("delete-event", self.close_window)
if overlay:
self.init_config()
self.create_gui()
def present_settings(self):
"""
Show contents of tab and update lists
"""
if not self.overlay:
return
self.show_all()
if not self.floating:
self.align_x_widget.show()
self.align_y_widget.show()
self.align_monitor_widget.show()
self.align_placement_widget.hide()
else:
self.align_x_widget.hide()
self.align_y_widget.hide()
self.align_monitor_widget.show()
self.align_placement_widget.show()
def read_config(self):
"""
Read in the 'text' section of the config
"""
if not self.overlay:
return
config = ConfigParser(interpolation=None)
config.read(self.config_file)
self.enabled = config.getboolean(
"notification", "enabled", fallback=False)
self.align_x = config.getboolean(
"notification", "rightalign", fallback=True)
self.align_y = config.getint("notification", "topalign", fallback=2)
self.monitor = config.get("notification", "monitor", fallback="None")
self.floating = config.getboolean(
"notification", "floating", fallback=False)
self.floating_x = config.getint(
"notification", "floating_x", fallback=0)
self.floating_y = config.getint(
"notification", "floating_y", fallback=0)
self.floating_w = config.getint(
"notification", "floating_w", fallback=400)
self.floating_h = config.getint(
"notification", "floating_h", fallback=400)
self.font = config.get("notification", "font", fallback=None)
self.bg_col = json.loads(config.get(
"notification", "bg_col", fallback="[0.0,0.0,0.0,0.5]"))
self.fg_col = json.loads(config.get(
"notification", "fg_col", fallback="[1.0,1.0,1.0,1.0]"))
self.text_time = config.getint(
"notification", "text_time", fallback=10)
self.show_icon = config.getboolean(
"notification", "show_icon", fallback=True)
self.reverse_order = config.getboolean(
"notification", "rev", fallback=False)
self.limit_width = config.getint(
"notification", "limit_width", fallback=400)
self.icon_left = config.getboolean(
"notification", "icon_left", fallback=True)
self.icon_padding = config.getint(
"notification", "icon_padding", fallback=8)
self.icon_size = config.getint(
"notification", "icon_size", fallback=32)
self.padding = config.getint(
"notification", "padding", fallback=8)
self.border_radius = config.getint(
"notification", "border_radius", fallback=8)
# Pass all of our config over to the overlay
self.overlay.set_enabled(self.enabled)
self.overlay.set_align_x(self.align_x)
self.overlay.set_align_y(self.align_y)
self.overlay.set_monitor(self.get_monitor_index(
self.monitor), self.get_monitor_obj(self.monitor))
self.overlay.set_floating(
self.floating, self.floating_x, self.floating_y, self.floating_w, self.floating_h)
self.overlay.set_bg(self.bg_col)
self.overlay.set_fg(self.fg_col)
self.overlay.set_text_time(self.text_time)
self.overlay.set_show_icon(self.show_icon)
self.overlay.set_reverse_order(self.reverse_order)
self.overlay.set_limit_width(self.limit_width)
self.overlay.set_icon_left(self.icon_left)
self.overlay.set_icon_size(self.icon_size)
self.overlay.set_icon_pad(self.icon_padding)
self.overlay.set_padding(self.padding)
self.overlay.set_border_radius(self.border_radius)
if self.font:
self.overlay.set_font(self.font)
def save_config(self):
"""
Save the current settings to the 'text' section of the config
"""
config = ConfigParser(interpolation=None)
config.read(self.config_file)
if not config.has_section("notification"):
config.add_section("notification")
config.set("notification", "rightalign", "%d" % (int(self.align_x)))
config.set("notification", "topalign", "%d" % (self.align_y))
config.set("notification", "monitor", self.monitor)
config.set("notification", "enabled", "%d" % (int(self.enabled)))
config.set("notification", "floating", "%s" % (int(self.floating)))
config.set("notification", "floating_x", "%s" % (int(self.floating_x)))
config.set("notification", "floating_y", "%s" % (int(self.floating_y)))
config.set("notification", "floating_w", "%s" % (int(self.floating_w)))
config.set("notification", "floating_h", "%s" % (int(self.floating_h)))
config.set("notification", "bg_col", json.dumps(self.bg_col))
config.set("notification", "fg_col", json.dumps(self.fg_col))
config.set("notification", "text_time", "%s" % (int(self.text_time)))
config.set("notification", "show_icon", "%s" %
(int(self.show_icon)))
config.set("notification", "rev", "%s" %
(int(self.reverse_order)))
config.set("notification", "limit_width", "%d" %
(int(self.limit_width)))
config.set("notification", "icon_left", "%d" % (int(self.icon_left)))
config.set("notification", "icon_padding", "%d" %
(int(self.icon_padding)))
config.set("notification", "icon_size", "%d" % (int(self.icon_size)))
config.set("notification", "padding", "%d" % (int(self.padding)))
config.set("notification", "border_radius", "%d" %
(int(self.border_radius)))
if self.font:
config.set("notification", "font", self.font)
with open(self.config_file, 'w') as file:
config.write(file)
def create_gui(self):
"""
Prepare the gui
"""
box = Gtk.Grid()
# Enabled
enabled_label = Gtk.Label.new(_("Enable"))
enabled_label.set_xalign(0)
enabled = Gtk.CheckButton.new()
enabled.set_active(self.enabled)
enabled.connect("toggled", self.change_enabled)
# Enabled
testing_label = Gtk.Label.new(_("Show test content"))
testing_label.set_xalign(0)
testing = Gtk.CheckButton.new()
testing.connect("toggled", self.change_testing)
# Order
reverse_label = Gtk.Label.new(_("Reverse Order"))
reverse_label.set_xalign(0)
reverse = Gtk.CheckButton.new()
reverse.set_active(self.reverse_order)
reverse.connect("toggled", self.change_reverse_order)
# Popup timer
text_time_label = Gtk.Label.new(_("Popup timer"))
text_time_label.set_xalign(0)
text_time_adjustment = Gtk.Adjustment.new(
self.text_time, 8, 9000, 1, 1, 8)
text_time = Gtk.SpinButton.new(text_time_adjustment, 0, 0)
text_time.connect("value-changed", self.change_text_time)
# Limit width
limit_width_label = Gtk.Label.new(_("Limit popup width"))
limit_width_label.set_xalign(0)
limit_width_adjustment = Gtk.Adjustment.new(
self.limit_width, 100, 9000, 1, 1, 8)
limit_width = Gtk.SpinButton.new(limit_width_adjustment, 0, 0)
limit_width.connect("value-changed", self.change_limit_width)
# Font chooser
font_label = Gtk.Label.new(_("Font"))
font_label.set_xalign(0)
font = Gtk.FontButton()
if self.font:
font.set_font(self.font)
font.connect("font-set", self.change_font)
# Icon alignment
align_icon_label = Gtk.Label.new(_("Icon position"))
align_icon_label.set_xalign(0)
align_icon_store = Gtk.ListStore(str)
align_icon_store.append([_("Left")])
align_icon_store.append([_("Right")])
align_icon = Gtk.ComboBox.new_with_model(align_icon_store)
align_icon.set_active(not self.icon_left)
align_icon.connect("changed", self.change_icon_left)
renderer_text = Gtk.CellRendererText()
align_icon.pack_start(renderer_text, True)
align_icon.add_attribute(renderer_text, "text", 0)
# Colours
bg_col_label = Gtk.Label.new(_("Background colour"))
bg_col_label.set_xalign(0)
bg_col = Gtk.ColorButton.new_with_rgba(
Gdk.RGBA(self.bg_col[0], self.bg_col[1], self.bg_col[2], self.bg_col[3]))
fg_col_label = Gtk.Label.new(_("Text colour"))
fg_col_label.set_xalign(0)
fg_col = Gtk.ColorButton.new_with_rgba(
Gdk.RGBA(self.fg_col[0], self.fg_col[1], self.fg_col[2], self.fg_col[3]))
bg_col.set_use_alpha(True)
fg_col.set_use_alpha(True)
bg_col.connect("color-set", self.change_bg)
fg_col.connect("color-set", self.change_fg)
# Monitor & Alignment
align_label = Gtk.Label.new(_("Overlay Location"))
align_label.set_xalign(0)
align_type_box = Gtk.HBox()
align_type_edge = Gtk.RadioButton.new_with_label(
None, _("Anchor to edge"))
align_type_floating = Gtk.RadioButton.new_with_label_from_widget(
align_type_edge, _("Floating"))
if self.floating:
align_type_floating.set_active(True)
align_type_box.add(align_type_edge)
align_type_box.add(align_type_floating)
monitor_store = Gtk.ListStore(str)
display = Gdk.Display.get_default()
if "get_n_monitors" in dir(display):
for i in range(0, display.get_n_monitors()):
monitor_store.append([display.get_monitor(i).get_model()])
monitor = Gtk.ComboBox.new_with_model(monitor_store)
monitor.set_active(self.get_monitor_index(self.monitor))
monitor.connect("changed", self.change_monitor)
renderer_text = Gtk.CellRendererText()
monitor.pack_start(renderer_text, True)
monitor.add_attribute(renderer_text, "text", 0)
align_x_store = Gtk.ListStore(str)
align_x_store.append([_("Left")])
align_x_store.append([_("Right")])
align_x = Gtk.ComboBox.new_with_model(align_x_store)
align_x.set_active(True if self.align_x else False)
align_x.connect("changed", self.change_align_x)
renderer_text = Gtk.CellRendererText()
align_x.pack_start(renderer_text, True)
align_x.add_attribute(renderer_text, "text", 0)
align_y_store = Gtk.ListStore(str)
align_y_store.append([_("Top")])
align_y_store.append([_("Middle")])
align_y_store.append([_("Bottom")])
align_y = Gtk.ComboBox.new_with_model(align_y_store)
align_y.set_active(self.align_y)
align_y.connect("changed", self.change_align_y)
renderer_text = Gtk.CellRendererText()
align_y.pack_start(renderer_text, True)
align_y.add_attribute(renderer_text, "text", 0)
align_placement_button = Gtk.Button.new_with_label(_("Place Window"))
align_type_edge.connect("toggled", self.change_align_type_edge)
align_type_floating.connect("toggled", self.change_align_type_floating)
align_placement_button.connect("pressed", self.change_placement)
# Show Icons
show_icon_label = Gtk.Label.new(_("Show Icon"))
show_icon_label.set_xalign(0)
show_icon = Gtk.CheckButton.new()
show_icon.set_active(self.show_icon)
show_icon.connect("toggled", self.change_show_icon)
# Icon Padding
icon_padding_label = Gtk.Label.new(_("Icon padding"))
icon_padding_label.set_xalign(0)
icon_padding_adjustment = Gtk.Adjustment.new(
self.icon_padding, 0, 150, 1, 1, 8)
icon_padding = Gtk.SpinButton.new(icon_padding_adjustment, 0, 0)
icon_padding.connect("value-changed", self.change_icon_pad)
# Icon Size
icon_size_label = Gtk.Label.new(_("Icon size"))
icon_size_label.set_xalign(0)
icon_size_adjustment = Gtk.Adjustment.new(
self.icon_size, 0, 128, 1, 1, 8)
icon_size = Gtk.SpinButton.new(icon_size_adjustment, 0, 0)
icon_size.connect("value-changed", self.change_icon_size)
# Padding
padding_label = Gtk.Label.new(_("Notification padding"))
padding_label.set_xalign(0)
padding_adjustment = Gtk.Adjustment.new(
self.padding, 0, 150, 1, 1, 8)
padding = Gtk.SpinButton.new(padding_adjustment, 0, 0)
padding.connect("value-changed", self.change_padding)
# Border Radius
border_radius_label = Gtk.Label.new(_("Border radius"))
border_radius_label.set_xalign(0)
border_radius_adjustment = Gtk.Adjustment.new(
self.border_radius, 0, 50, 1, 1, 8)
border_radius = Gtk.SpinButton.new(border_radius_adjustment, 0, 0)
border_radius.connect(
"value-changed", self.change_border_radius)
self.align_x_widget = align_x
self.align_y_widget = align_y
self.align_monitor_widget = monitor
self.align_placement_widget = align_placement_button
self.text_time_widget = text_time
self.text_time_label_widget = text_time_label
box.attach(enabled_label, 0, 0, 1, 1)
box.attach(enabled, 1, 0, 1, 1)
box.attach(reverse_label, 0, 1, 1, 1)
box.attach(reverse, 1, 1, 1, 1)
box.attach(text_time_label, 0, 3, 1, 1)
box.attach(text_time, 1, 3, 1, 1)
box.attach(limit_width_label, 0, 4, 1, 1)
box.attach(limit_width, 1, 4, 1, 1)
box.attach(font_label, 0, 6, 1, 1)
box.attach(font, 1, 6, 1, 1)
box.attach(fg_col_label, 0, 7, 1, 1)
box.attach(fg_col, 1, 7, 1, 1)
box.attach(bg_col_label, 0, 8, 1, 1)
box.attach(bg_col, 1, 8, 1, 1)
box.attach(align_label, 0, 9, 1, 5)
#box.attach(align_type_box, 1, 8, 1, 1)
box.attach(monitor, 1, 10, 1, 1)
box.attach(align_x, 1, 11, 1, 1)
box.attach(align_y, 1, 12, 1, 1)
box.attach(align_placement_button, 1, 13, 1, 1)
box.attach(show_icon_label, 0, 14, 1, 1)
box.attach(show_icon, 1, 14, 1, 1)
box.attach(align_icon_label, 0, 15, 1, 1)
box.attach(align_icon, 1, 15, 1, 1)
box.attach(icon_padding_label, 0, 16, 1, 1)
box.attach(icon_padding, 1, 16, 1, 1)
box.attach(icon_size_label, 0, 17, 1, 1)
box.attach(icon_size, 1, 17, 1, 1)
box.attach(padding_label, 0, 18, 1, 1)
box.attach(padding, 1, 18, 1, 1)
box.attach(border_radius_label, 0, 19, 1, 1)
box.attach(border_radius, 1, 19, 1, 1)
box.attach(testing_label, 0, 20, 1, 1)
box.attach(testing, 1, 20, 1, 1)
self.add(box)
def change_padding(self, button):
"""
Padding between notifications changed
"""
self.overlay.set_padding(button.get_value())
self.padding = button.get_value()
self.save_config()
def change_border_radius(self, button):
"""
Border radius changed
"""
self.overlay.set_border_radius(button.get_value())
self.border_radius = button.get_value()
self.save_config()
def change_icon_size(self, button):
"""
Icon size changed
"""
self.overlay.set_icon_size(button.get_value())
self.icon_size = button.get_value()
self.save_config()
def change_icon_pad(self, button):
"""
Icon padding changed
"""
self.overlay.set_icon_pad(button.get_value())
self.icon_pad = button.get_value()
self.save_config()
def change_icon_left(self, button):
"""
Icon alignment changed
"""
self.overlay.set_icon_left(button.get_active() != 1)
self.icon_left = (button.get_active() != 1)
self.save_config()
def change_font(self, button):
"""
Font settings changed
"""
font = button.get_font()
self.overlay.set_font(font)
self.font = font
self.save_config()
def change_text_time(self, button):
"""
Popup style setting changed
"""
self.overlay.set_text_time(button.get_value())
self.text_time = button.get_value()
self.save_config()
def change_limit_width(self, button):
"""
Popup width limiter
"""
self.overlay.set_limit_width(button.get_value())
self.limit_width = button.get_value()
self.save_config()
def change_bg(self, button):
"""
Background colour changed
"""
colour = button.get_rgba()
colour = [colour.red, colour.green, colour.blue, colour.alpha]
self.overlay.set_bg(colour)
self.bg_col = colour
self.save_config()
def change_fg(self, button):
"""
Foreground colour changed
"""
colour = button.get_rgba()
colour = [colour.red, colour.green, colour.blue, colour.alpha]
self.overlay.set_fg(colour)
self.fg_col = colour
self.save_config()
def change_show_icon(self, button):
"""
Icon setting changed
"""
self.overlay.set_show_icon(button.get_active())
self.show_icon = button.get_active()
self.save_config()
def change_reverse_order(self, button):
"""
Reverse Order changed
"""
self.overlay.set_reverse_order(button.get_active())
self.reverse_order = button.get_active()
self.save_config()
def change_testing(self, button):
self.overlay.set_testing(button.get_active())
def change_enabled(self, button):
"""
Overlay active state toggled
"""
self.overlay.set_enabled(button.get_active())
self.enabled = button.get_active()
self.save_config()

View file

@ -1,249 +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 <https://www.gnu.org/licenses/>.
"""
Settings tab parent class. Helpful if we need more
overlay types without copy-and-pasting too much code
"""
import gettext
import os
import logging
import pkg_resources
import gi
from .draggable_window import DraggableWindow
from .draggable_window_wayland import DraggableWindowWayland
gi.require_version("Gtk", "3.0")
# pylint: disable=wrong-import-position,wrong-import-order
from gi.repository import Gtk, Gdk # nopep8
try:
from xdg.BaseDirectory import xdg_config_home
except ModuleNotFoundError:
from xdg import XDG_CONFIG_HOME as xdg_config_home
log = logging.getLogger(__name__)
t = gettext.translation(
'default', pkg_resources.resource_filename('discover_overlay', 'locales'), fallback=True)
_ = t.gettext
class SettingsWindow(Gtk.VBox):
"""
Settings tab parent class. Helpful if we need more
overlay types without copy-and-pasting too much code
"""
def __init__(self, discover):
Gtk.VBox.__init__(self)
self.placement_window = None
self.config_dir = None
self.config_file = None
self.overlay = None
self.floating = None
self.floating_x = None
self.floating_y = None
self.floating_w = None
self.floating_h = None
self.align_x_widget = None
self.align_y_widget = None
self.align_monitor_widget = None
self.align_placement_widget = None
self.monitor = None
self.align_x = None
self.align_y = None
self.enabled = None
self.autohide = None
self.discover = discover
def init_config(self):
"""
Locate the config and then read
"""
self.config_dir = os.path.join(xdg_config_home, "discover_overlay")
os.makedirs(self.config_dir, exist_ok=True)
self.config_file = os.path.join(self.config_dir, "config.ini")
self.read_config()
def close_window(self, _a=None, _b=None):
"""
Helper to ensure we don't lose changes to floating windows
Hide for later
"""
if self.placement_window:
(pos_x, pos_y, width, height) = self.placement_window.get_coords()
self.floating_x = pos_x
self.floating_y = pos_y
self.floating_w = width
self.floating_h = height
self.overlay.set_floating(True, pos_x, pos_y, width, height)
self.save_config()
self.placement_window.close()
self.placement_window = None
self.hide()
return True
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 present_settings(self):
"""
Show settings
"""
self.show_all()
def read_config(self):
"""
Stub called when settings are needed to be read
"""
def save_config(self):
"""
Stub called when settings are needed to be written
"""
def change_placement(self, button):
"""
Placement window button pressed.
"""
if self.placement_window:
(pos_x, pos_y, width, height) = self.placement_window.get_coords()
self.floating_x = pos_x
self.floating_y = pos_y
self.floating_w = width
self.floating_h = height
log.info("Positioned overlay : %s , %s %s x %s", self.floating_x,
self.floating_y, self.floating_w, self.floating_h)
self.overlay.set_floating(True, pos_x, pos_y, width, height)
self.save_config()
if button:
button.set_label(_("Place Window"))
self.placement_window.close()
self.placement_window = None
if self.discover.steamos:
self.discover.show_settings()
else:
if self.discover.steamos:
self.discover.hide_settings()
if self.overlay.is_wayland or self.discover.steamos:
self.placement_window = DraggableWindowWayland(
pos_x=self.floating_x, pos_y=self.floating_y,
width=self.floating_w, height=self.floating_h,
message=_("Place & resize this window then press Green!"), settings=self,
steamos=self.discover.steamos,
monitor=self.get_monitor_obj(self.monitor))
else:
self.placement_window = DraggableWindow(
pos_x=self.floating_x, pos_y=self.floating_y,
width=self.floating_w, height=self.floating_h,
message=_("Place & resize this window then press Save!"), settings=self)
if button:
button.set_label(_("Save this position"))
def change_align_type_edge(self, button):
"""
Alignment setting changed
"""
if button.get_active():
self.overlay.set_floating(
False, self.floating_x, self.floating_y, self.floating_w, self.floating_h)
self.floating = False
self.save_config()
# Re-sort the screen
self.align_x_widget.show()
self.align_y_widget.show()
self.align_monitor_widget.show()
self.align_placement_widget.hide()
def change_align_type_floating(self, button):
"""
Alignment setting changed
"""
if button.get_active():
self.overlay.set_floating(
True, self.floating_x, self.floating_y, self.floating_w, self.floating_h)
self.floating = True
self.save_config()
self.align_x_widget.hide()
self.align_y_widget.hide()
self.align_placement_widget.show()
def change_monitor(self, button):
"""
Alignment setting changed
"""
display = Gdk.Display.get_default()
if "get_monitor" in dir(display):
mon = display.get_monitor(button.get_active())
m_s = mon.get_model()
self.overlay.set_monitor(button.get_active(), mon)
self.monitor = m_s
self.save_config()
def change_align_x(self, button):
"""
Alignment setting changed
"""
self.overlay.set_align_x(button.get_active() == 1)
self.align_x = (button.get_active() == 1)
self.save_config()
def change_align_y(self, button):
"""
Alignment setting changed
"""
self.overlay.set_align_y(button.get_active())
self.align_y = button.get_active()
self.save_config()
def change_enabled(self, button):
"""
Overlay active state toggled
"""
self.overlay.set_enabled(button.get_active())
self.enabled = button.get_active()
self.save_config()
def change_hide_on_mouseover(self, button):
"""
Autohide setting changed
"""
self.overlay.set_hide_on_mouseover(button.get_active())
self.autohide = button.get_active()
self.save_config()

View file

@ -864,7 +864,7 @@ class MainSettingsWindow():
def core_run_on_startup_changed(self, button):
# TODO Startup
pass
self.autostart_helper.set_autostart(button.get_active())
def core_force_xshape_changed(self, button):
self.config_set("general", "xshape", "%s" % (button.get_active()))

View file

@ -1,620 +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 <https://www.gnu.org/licenses/>.
"""Text setting tab on settings window"""
import gettext
import json
import logging
import pkg_resources
from configparser import ConfigParser
import gi
from .settings import SettingsWindow
gi.require_version("Gtk", "3.0")
# pylint: disable=wrong-import-position,wrong-import-order
from gi.repository import Gtk, Gdk # nopep8
GUILD_DEFAULT_VALUE = "0"
log = logging.getLogger(__name__)
t = gettext.translation(
'default', pkg_resources.resource_filename('discover_overlay', 'locales'), fallback=True)
_ = t.gettext
class TextSettingsWindow(SettingsWindow):
"""Text setting tab on settings window"""
def __init__(self, overlay, discover):
SettingsWindow.__init__(self, discover)
self.overlay = overlay
self.placement_window = None
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.channel_lookup = None
self.channel_model = None
self.connector = None
self.guild_lookup = None
self.guild_model = None
self.guild_widget = None
self.align_x = None
self.align_y = None
self.monitor = None
self.floating = None
self.channel = None
self.guild = None
self.font = None
self.bg_col = None
self.fg_col = None
self.popup_style = None
self.text_time = None
self.show_attach = None
self.line_limit = None
self.enabled = None
self.set_size_request(400, 200)
self.connect("destroy", self.close_window)
self.connect("delete-event", self.close_window)
if overlay:
self.init_config()
self.create_gui()
def update_channel_model(self):
"""
Update the Channel selector.
Populate with all channels from guild.
Leave empty if guild is unselected
"""
# 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 = []
# If a guild is specified, populate channel list with every channel from *just that guild*
if self.guild != GUILD_DEFAULT_VALUE:
for position in self.list_channels_keys:
chan = self.list_channels[position]
channel_key = chan["id"]
if chan['guild_id'] == self.guild:
c_model.append([chan["name"], True])
self.channel_lookup.append(channel_key)
self.channel_widget.set_model(c_model)
self.channel_model = c_model
idx = 0
for channel in self.channel_lookup:
if channel == self.channel:
self.ignore_channel_change = True
self.channel_widget.set_active(idx)
self.ignore_channel_change = False
break
idx += 1
self.channel_widget.set_sensitive(True)
def add_connector(self, conn):
"""
Add the discord_connector reference
If the user has previously selected a text channel then tell it to subscribe
"""
self.connector = conn
if self.channel:
self.connector.set_text_channel(self.channel)
def present_settings(self):
"""
Show contents of tab and update lists
"""
if not self.overlay:
return
self.show_all()
if not self.floating:
self.align_x_widget.show()
self.align_y_widget.show()
self.align_monitor_widget.show()
self.align_placement_widget.hide()
else:
self.align_x_widget.hide()
self.align_y_widget.hide()
self.align_monitor_widget.show()
self.align_placement_widget.show()
if self.popup_style:
self.text_time_widget.show()
self.text_time_label_widget.show()
else:
self.text_time_widget.hide()
self.text_time_label_widget.hide()
self.update_guild_model()
def update_guild_model(self):
g_model = Gtk.ListStore(str, bool)
self.guild_lookup = []
for guild in self.guild_list():
guild_id, guild_name = guild
self.guild_lookup.append(guild_id)
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 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
break
idxg += 1
if self.guild is not None:
self.refresh_channel_list()
self.guild_widget.set_sensitive(True)
def guild_list(self):
"""
Return a list of all guilds
"""
guilds = []
done = []
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):
"""
Set the contents of list_channels
"""
self.list_channels = in_list
self.list_channels_keys = []
for (key, _value) in enumerate(in_list):
# Filter for only text channels
# https://discord.com/developers/docs/resources/channel#channel-object-channel-types
if in_list[key] is not None and in_list[key]["type"] == 0:
self.list_channels_keys.append(key)
self.list_channels_keys.sort()
self.update_channel_model()
def set_guilds(self, in_list):
"""
Set the contents of list_guilds
"""
self.guild_widget.set_sensitive(True)
if self.list_guilds == in_list:
return
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()
self.update_guild_model()
def read_config(self):
"""
Read in the 'text' section of the config
"""
if not self.overlay:
return
config = ConfigParser(interpolation=None)
config.read(self.config_file)
self.enabled = config.getboolean("text", "enabled", fallback=False)
self.align_x = config.getboolean("text", "rightalign", fallback=True)
self.align_y = config.getint("text", "topalign", fallback=2)
self.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=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]"))
self.fg_col = json.loads(config.get(
"text", "fg_col", fallback="[1.0,1.0,1.0,1.0]"))
self.popup_style = config.getboolean(
"text", "popup_style", fallback=False)
self.text_time = config.getint("text", "text_time", fallback=30)
self.show_attach = config.getboolean(
"text", "show_attach", fallback=True)
self.line_limit = config.getint("text", "line_limit", fallback=20)
self.autohide = config.getboolean("text", "autohide", fallback=False)
log.info(
"Loading saved channel %s", self.channel)
# Pass all of our config over to the overlay
self.overlay.set_enabled(self.enabled)
self.overlay.set_align_x(self.align_x)
self.overlay.set_align_y(self.align_y)
self.overlay.set_monitor(self.get_monitor_index(
self.monitor), self.get_monitor_obj(self.monitor))
self.overlay.set_floating(
self.floating, self.floating_x, self.floating_y, self.floating_w, self.floating_h)
self.overlay.set_bg(self.bg_col)
self.overlay.set_fg(self.fg_col)
self.overlay.set_popup_style(self.popup_style)
self.overlay.set_text_time(self.text_time)
self.overlay.set_show_attach(self.show_attach)
self.overlay.set_line_limit(self.line_limit)
self.overlay.set_hide_on_mouseover(self.autohide)
if self.font:
self.overlay.set_font(self.font)
def save_config(self):
"""
Save the current settings to the 'text' section of the config
"""
config = ConfigParser(interpolation=None)
config.read(self.config_file)
if not config.has_section("text"):
config.add_section("text")
config.set("text", "rightalign", "%d" % (int(self.align_x)))
config.set("text", "topalign", "%d" % (self.align_y))
config.set("text", "monitor", self.monitor)
config.set("text", "enabled", "%d" % (int(self.enabled)))
config.set("text", "floating", "%s" % (int(self.floating)))
config.set("text", "floating_x", "%s" % (int(self.floating_x)))
config.set("text", "floating_y", "%s" % (int(self.floating_y)))
config.set("text", "floating_w", "%s" % (int(self.floating_w)))
config.set("text", "floating_h", "%s" % (int(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)))
config.set("text", "text_time", "%s" % (int(self.text_time)))
config.set("text", "line_limit", "%s" % (int(self.line_limit)))
config.set("text", "show_attach", "%s" % (int(self.show_attach)))
if self.font:
config.set("text", "font", self.font)
with open(self.config_file, 'w') as file:
config.write(file)
def create_gui(self):
"""
Prepare the gui
"""
box = Gtk.Grid()
# Enabled
enabled_label = Gtk.Label.new(_("Enable"))
enabled_label.set_xalign(0)
enabled = Gtk.CheckButton.new()
enabled.set_active(self.enabled)
enabled.connect("toggled", self.change_enabled)
# Autohide
autohide_label = Gtk.Label.new(_("Hide on mouseover"))
autohide = Gtk.CheckButton.new()
autohide.set_active(self.autohide)
autohide.connect("toggled", self.change_hide_on_mouseover)
# Popup Style
popup_style_label = Gtk.Label.new(_("Popup Style"))
popup_style_label.set_xalign(0)
popup_style = Gtk.CheckButton.new()
popup_style.set_active(self.popup_style)
popup_style.connect("toggled", self.change_popup_style)
# Popup timer
text_time_label = Gtk.Label.new(_("Popup timer"))
text_time_label.set_xalign(0)
text_time_adjustment = Gtk.Adjustment.new(
self.text_time, 8, 9000, 1, 1, 8)
text_time = Gtk.SpinButton.new(text_time_adjustment, 0, 0)
text_time.connect("value-changed", self.change_text_time)
# Font chooser
font_label = Gtk.Label.new(_("Font"))
font_label.set_xalign(0)
font = Gtk.FontButton()
if self.font:
font.set_font(self.font)
font.connect("font-set", self.change_font)
# Colours
bg_col_label = Gtk.Label.new(_("Background colour"))
bg_col_label.set_xalign(0)
bg_col = Gtk.ColorButton.new_with_rgba(
Gdk.RGBA(self.bg_col[0], self.bg_col[1], self.bg_col[2], self.bg_col[3]))
fg_col_label = Gtk.Label.new(_("Text colour"))
fg_col_label.set_xalign(0)
fg_col = Gtk.ColorButton.new_with_rgba(
Gdk.RGBA(self.fg_col[0], self.fg_col[1], self.fg_col[2], self.fg_col[3]))
bg_col.set_use_alpha(True)
fg_col.set_use_alpha(True)
bg_col.connect("color-set", self.change_bg)
fg_col.connect("color-set", self.change_fg)
# Monitor & Alignment
align_label = Gtk.Label.new(_("Overlay Location"))
align_label.set_xalign(0)
align_type_box = Gtk.HBox()
align_type_edge = Gtk.RadioButton.new_with_label(
None, _("Anchor to edge"))
align_type_floating = Gtk.RadioButton.new_with_label_from_widget(
align_type_edge, _("Floating"))
if self.floating:
align_type_floating.set_active(True)
align_type_box.add(align_type_edge)
align_type_box.add(align_type_floating)
monitor_store = Gtk.ListStore(str)
display = Gdk.Display.get_default()
if "get_n_monitors" in dir(display):
for i in range(0, display.get_n_monitors()):
monitor_store.append([display.get_monitor(i).get_model()])
monitor = Gtk.ComboBox.new_with_model(monitor_store)
monitor.set_active(self.get_monitor_index(self.monitor))
monitor.connect("changed", self.change_monitor)
renderer_text = Gtk.CellRendererText()
monitor.pack_start(renderer_text, True)
monitor.add_attribute(renderer_text, "text", 0)
align_x_store = Gtk.ListStore(str)
align_x_store.append([_("Left")])
align_x_store.append([_("Right")])
align_x = Gtk.ComboBox.new_with_model(align_x_store)
align_x.set_active(True if self.align_x else False)
align_x.connect("changed", self.change_align_x)
renderer_text = Gtk.CellRendererText()
align_x.pack_start(renderer_text, True)
align_x.add_attribute(renderer_text, "text", 0)
align_y_store = Gtk.ListStore(str)
align_y_store.append([_("Top")])
align_y_store.append([_("Middle")])
align_y_store.append([_("Bottom")])
align_y = Gtk.ComboBox.new_with_model(align_y_store)
align_y.set_active(self.align_y)
align_y.connect("changed", self.change_align_y)
renderer_text = Gtk.CellRendererText()
align_y.pack_start(renderer_text, True)
align_y.add_attribute(renderer_text, "text", 0)
align_placement_button = Gtk.Button.new_with_label(_("Place Window"))
align_type_edge.connect("toggled", self.change_align_type_edge)
align_type_floating.connect("toggled", self.change_align_type_floating)
align_placement_button.connect("pressed", self.change_placement)
channel_label = Gtk.Label.new(_("Channel"))
channel_label.set_xalign(0)
channel = Gtk.ComboBox.new()
channel.connect("changed", self.change_channel)
renderer_text = Gtk.CellRendererText()
channel.pack_start(renderer_text, True)
channel.add_attribute(renderer_text, "text", 0)
channel.add_attribute(renderer_text, 'sensitive', 1)
channel_refresh = Gtk.Button.new_with_label(_("Refresh list"))
channel_refresh.connect("pressed", self.refresh_channel_list)
guild_label = Gtk.Label.new(_("Server"))
guild_label.set_xalign(0)
guild = Gtk.ComboBox.new()
guild.connect("changed", self.change_guild)
renderer_text = Gtk.CellRendererText()
guild.pack_start(renderer_text, True)
guild.add_attribute(renderer_text, "text", 0)
guild.add_attribute(renderer_text, 'sensitive', 1)
guild_refresh = Gtk.Button.new_with_label(_("Refresh list"))
guild_refresh.connect("pressed", self.refresh_guild_list)
# Show Attachments
show_attach_label = Gtk.Label.new(_("Show Attachments"))
show_attach_label.set_xalign(0)
show_attach = Gtk.CheckButton.new()
show_attach.set_active(self.show_attach)
show_attach.connect("toggled", self.change_show_attach)
# Line Limit
line_limit_label = Gtk.Label.new(_("Line limit"))
line_limit_label.set_xalign(0)
line_limit_adjustment = Gtk.Adjustment.new(
self.line_limit, 10, 400, 1, 1, 8)
line_limit = Gtk.SpinButton.new(line_limit_adjustment, 0, 0)
line_limit.connect("value-changed", self.change_line_limit)
self.align_x_widget = align_x
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
box.attach(enabled_label, 0, 0, 1, 1)
box.attach(enabled, 1, 0, 1, 1)
#box.attach(autohide_label, 0, 1, 1, 1)
#box.attach(autohide, 1, 1, 1, 1)
box.attach(popup_style_label, 0, 2, 1, 1)
box.attach(popup_style, 1, 2, 1, 1)
box.attach(text_time_label, 0, 3, 1, 1)
box.attach(text_time, 1, 3, 1, 1)
box.attach(guild_label, 0, 4, 1, 1)
box.attach(guild, 1, 4, 1, 1)
box.attach(guild_refresh, 2, 4, 1, 1)
box.attach(channel_label, 0, 5, 1, 1)
box.attach(channel, 1, 5, 1, 1)
box.attach(channel_refresh, 2, 5, 1, 1)
box.attach(font_label, 0, 6, 1, 1)
box.attach(font, 1, 6, 1, 1)
box.attach(fg_col_label, 0, 7, 1, 1)
box.attach(fg_col, 1, 7, 1, 1)
box.attach(bg_col_label, 0, 8, 1, 1)
box.attach(bg_col, 1, 8, 1, 1)
box.attach(align_label, 0, 9, 1, 5)
#box.attach(align_type_box, 1, 8, 1, 1)
box.attach(monitor, 1, 10, 1, 1)
box.attach(align_x, 1, 11, 1, 1)
box.attach(align_y, 1, 12, 1, 1)
box.attach(align_placement_button, 1, 13, 1, 1)
box.attach(show_attach_label, 0, 14, 1, 1)
box.attach(show_attach, 1, 14, 1, 1)
box.attach(line_limit_label, 0, 15, 1, 1)
box.attach(line_limit, 1, 15, 1, 1)
self.add(box)
def change_font(self, button):
"""
Font settings changed
"""
font = button.get_font()
self.overlay.set_font(font)
self.font = font
self.save_config()
def change_channel(self, button):
"""
Channel setting changed
"""
if self.ignore_channel_change:
return
channel = self.channel_lookup[button.get_active()]
self.connector.set_text_channel(channel)
self.channel = channel
self.save_config()
def change_guild(self, button):
"""
Guild setting changed
"""
if self.ignore_guild_change:
return
guild_id = self.guild_lookup[button.get_active()]
self.guild = guild_id
self.save_config()
self.refresh_channel_list()
def refresh_channel_list(self, _button=None):
self.channel_widget.set_sensitive(False)
self.connector.request_text_rooms_for_guild(self.guild)
def refresh_guild_list(self, _button=None):
self.guild_widget.set_sensitive(False)
self.channel_widget.set_sensitive(False)
self.connector.req_guilds()
self.connector.request_text_rooms_for_guild(self.guild)
def change_popup_style(self, button):
"""
Popup style setting changed
"""
self.overlay.set_popup_style(button.get_active())
self.popup_style = button.get_active()
self.save_config()
if button.get_active():
# We're using popup style
self.text_time_widget.show()
self.text_time_label_widget.show()
else:
self.text_time_widget.hide()
self.text_time_label_widget.hide()
def change_text_time(self, button):
"""
Popup style setting changed
"""
self.overlay.set_text_time(button.get_value())
self.text_time = button.get_value()
self.save_config()
def get_channel(self):
"""
Return selected channel
"""
return self.channel
def set_channel(self, channel="0"):
"""
Change the stored channel
"""
self.channel = channel
self.save_config()
def get_guild(self):
"""
Return selected guild
"""
return self.guild
def change_bg(self, button):
"""
Background colour changed
"""
colour = button.get_rgba()
colour = [colour.red, colour.green, colour.blue, colour.alpha]
self.overlay.set_bg(colour)
self.bg_col = colour
self.save_config()
def change_fg(self, button):
"""
Foreground colour changed
"""
colour = button.get_rgba()
colour = [colour.red, colour.green, colour.blue, colour.alpha]
self.overlay.set_fg(colour)
self.fg_col = colour
self.save_config()
def change_show_attach(self, button):
"""
Attachment setting changed
"""
self.overlay.set_show_attach(button.get_active())
self.show_attach = button.get_active()
self.save_config()
def change_line_limit(self, button):
"""
Line limit setting changed
"""
self.overlay.set_line_limit(button.get_value())
self.line_limit = button.get_value()
self.save_config()

File diff suppressed because it is too large Load diff