Skip to content

Commit

Permalink
Code cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
l0drex committed Jan 16, 2024
1 parent 4898ce2 commit c7e7ee6
Show file tree
Hide file tree
Showing 8 changed files with 32 additions and 23 deletions.
13 changes: 10 additions & 3 deletions yin_yang/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ def setup_logger(use_systemd_journal: bool):
)
logging.root.addHandler(file_handler)


def systray_icon_clicked(reason: QSystemTrayIcon.ActivationReason):
match reason:
case QSystemTrayIcon.ActivationReason.MiddleClick:
Expand Down Expand Up @@ -122,9 +123,15 @@ def systray_icon_clicked(reason: QSystemTrayIcon.ActivationReason):
icon.setToolTip('Yin & Yang')

menu = QMenu('Yin & Yang')
menu.addAction(app.translate('systray', 'Open Yin Yang', 'Context menu action in the systray'), lambda: window.show())
menu.addAction(app.translate('systray', 'Toggle theme', 'Context menu action in the systray'), lambda: theme_switcher.set_mode(not config.dark_mode))
menu.addAction(QIcon.fromTheme('application-exit'), app.translate('systray', 'Quit', 'Context menu action in the systray'), app.quit)
menu.addAction(
app.translate('systray', 'Open Yin Yang', 'Context menu action in the systray'),
lambda: window.show())
menu.addAction(
app.translate('systray', 'Toggle theme', 'Context menu action in the systray'),
lambda: theme_switcher.set_mode(not config.dark_mode))
menu.addAction(QIcon.fromTheme('application-exit'),
app.translate('systray', 'Quit', 'Context menu action in the systray'),
app.quit)

icon.setContextMenu(menu)
icon.show()
Expand Down
2 changes: 1 addition & 1 deletion yin_yang/communicate.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
logger = logging.getLogger(__name__)


def _move_times(time_now: datetime, time_light: dt_time, time_dark: dt_time) -> list[int, int]:
def _move_times(time_now: datetime, time_light: dt_time, time_dark: dt_time) -> list[int]:
"""
Converts a time string to seconds since the epoch
:param time_now: the current time
Expand Down
18 changes: 10 additions & 8 deletions yin_yang/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -227,10 +227,10 @@ def load(self) -> None:
logger.error(e)
config_loaded = self.defaults

for pl in plugins:
pl.theme_light = config_loaded['plugins'][pl.name.lower()]['light_theme']
pl.theme_dark = config_loaded['plugins'][pl.name.lower()]['dark_theme']
pl.enabled = config_loaded['plugins'][pl.name.lower()]['enabled']
for p in plugins:
p.theme_light = config_loaded['plugins'][p.name.lower()]['light_theme']
p.theme_dark = config_loaded['plugins'][p.name.lower()]['dark_theme']
p.enabled = config_loaded['plugins'][p.name.lower()]['enabled']

self.update(config_loaded)

Expand Down Expand Up @@ -400,9 +400,11 @@ def location(self) -> tuple[float, float]:
return coordinate.latitude(), coordinate.longitude()
except TypeError as e:
logger.error('Unable to update position. Using config values as fallback.')
logger.error(e)
pass
except ValueError as e:
logger.error('Unable to update position. Using config values as fallback.')
logger.error(e)
pass

return self['coordinates']
Expand Down Expand Up @@ -473,7 +475,7 @@ def boot_offset(self, value: int):
logger.info('Detected desktop:', config.desktop)

# set plugin themes
for p in filter(lambda pl: pl.available, plugins):
p.enabled = config.get_plugin_key(p.name, PluginKey.ENABLED)
p.theme_bright = config.get_plugin_key(p.name, PluginKey.THEME_LIGHT)
p.theme_dark = config.get_plugin_key(p.name, PluginKey.THEME_DARK)
for pl in filter(lambda pl: pl.available, plugins):
pl.enabled = config.get_plugin_key(pl.name, PluginKey.ENABLED)
pl.theme_bright = config.get_plugin_key(pl.name, PluginKey.THEME_LIGHT)
pl.theme_dark = config.get_plugin_key(pl.name, PluginKey.THEME_DARK)
2 changes: 1 addition & 1 deletion yin_yang/plugins/firefox.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ def available_themes(self) -> dict:
for addon in content['addons']:
if addon['type'] == 'theme':
themes[addon['id']] = addon['defaultLocale']['name']
except FileNotFoundError as e:
except FileNotFoundError as _:
logger.warning(f'Firefox profile has no extensions installed: {path}')
continue

Expand Down
2 changes: 1 addition & 1 deletion yin_yang/plugins/konsole.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ def set_mode(self, dark: bool) -> bool:
logger.debug(f'Changing profile in konsole session {proc_id}')
set_profile(f'org.kde.konsole-{proc_id}', profile)

set_profile('org.kde.konsole', profile) # konsole may don't have session dbus like above
set_profile('org.kde.konsole', profile) # konsole may don't have session dbus like above
set_profile('org.kde.yakuake', profile)

process_ids = [
Expand Down
5 changes: 2 additions & 3 deletions yin_yang/plugins/kvantum.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ def __init__(self):
self.theme_dark = 'KvFlat'

@classmethod
def get_kvantum_theme_from_dir(cls, dir):
def get_kvantum_theme_from_dir(cls, directory):
result = set()
for _, _, filenames in os.walk(dir):
for _, _, filenames in os.walk(directory):
for filename in filenames:
if filename.endswith('.kvconfig'):
result.add(filename[:-9])
Expand All @@ -28,7 +28,6 @@ def available_themes(self) -> dict:
themes = list()
for path in paths:
themes = themes + self.get_kvantum_theme_from_dir(path)
themes_dict: dict = {}
assert len(themes) > 0, 'No themes were found'

themes.sort()
Expand Down
4 changes: 3 additions & 1 deletion yin_yang/plugins/okular.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@


class Okular(Plugin):
"""Inspired by: https://gitlab.com/LADlSLAV/yabotss/-/blob/main/darkman_examples_kde_plasma/dark-mode.d/10_set_theme_okular_dark.sh"""
"""Inspired by:
https://gitlab.com/LADlSLAV/yabotss/-/blob/main/darkman_examples_kde_plasma/dark-mode.d/10_set_theme_okular_dark.sh
"""

def __init__(self):
super().__init__()
Expand Down
9 changes: 4 additions & 5 deletions yin_yang/ui/main_window_connector.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from PySide6 import QtWidgets
from PySide6.QtCore import QStandardPaths
from PySide6.QtGui import QScreen, QColor
from PySide6.QtWidgets import QFileDialog, QMessageBox, QDialogButtonBox, QColorDialog,QGroupBox
from PySide6.QtWidgets import QFileDialog, QMessageBox, QDialogButtonBox, QColorDialog, QGroupBox

from .main_window import Ui_main_window
from ..theme_switcher import set_desired_theme, set_mode
Expand Down Expand Up @@ -111,17 +111,16 @@ def load_location(self):

def load_plugins(self):
# First, remove sample plugin
samplePlugin = cast(QGroupBox,self.ui.plugins_scroll_content.findChild(QGroupBox, 'samplePluginGroupBox'))
samplePlugin.hide()

sample_plugin = cast(QGroupBox, self.ui.plugins_scroll_content.findChild(QGroupBox, 'samplePluginGroupBox'))
sample_plugin.hide()

widget: QGroupBox
for plugin in plugins:
# filter out plugins for application
if plugin.name.casefold() in ['notification', 'sound']:
continue

widget = cast(QGroupBox,self.ui.plugins_scroll_content.findChild(QGroupBox, 'group' + plugin.name))
widget = cast(QGroupBox, self.ui.plugins_scroll_content.findChild(QGroupBox, 'group' + plugin.name))
if widget is None:
widget = plugin.get_widget(self.ui.plugins_scroll_content)
self.ui.plugins_scroll_content_layout.addWidget(widget)
Expand Down

0 comments on commit c7e7ee6

Please sign in to comment.