Skip to content

Commit

Permalink
Merge pull request #150 from oskarsh/beta
Browse files Browse the repository at this point in the history
Bug fixes
  • Loading branch information
l0drex authored Jan 2, 2023
2 parents a82bcb2 + 0250aea commit 333a72a
Show file tree
Hide file tree
Showing 8 changed files with 172 additions and 49 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/python-app.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ jobs:
${{ runner.os }}-
- name: Install dependencies
run: |
sudo apt install qt6-base-dev
sudo apt install qt6-base-dev libsystemd-dev gcc
python -m pip install --upgrade pip
pip install flake8 pytest
if [ -f requirements.txt ]; then pip install -r requirements.txt; fi
Expand Down
27 changes: 23 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,30 @@ and also themes your favourite editors like VSCode or Atom.
## Installation

To install Yin-Yang:
1. Install the dependencies: `systemd`, `python-systemd` and optionally `pyside6` (from your system package manager) for native widget style
2. Copy and run the command below and follow the instructions:
### Dependencies:
Yin-Yang depends on `python-systemd` and `pyside6` from pypi. `python-systemd` requires you have installed the systemd-headers from your package manager.

For CentOS, RHEL, and Fedora:
```bash
sudo dnf install gcc systemd-devel
```

For Debian, Ubuntu, etc.
```bash
sudo apt update
sudo apt install libsystemd-dev gcc
```

### Yin-Yang
```bash
git clone https://github.com/oskarsh/Yin-Yang && cd Yin-Yang && ./scripts/install.sh
git clone https://github.com/oskarsh/Yin-Yang && cd Yin-Yang
## Create virtual environment for pypi packages
python3 -m venv .venv
source .venv/bin/activate
# Install pip requirements
pip3 install -r requirements.txt
# Install Yin-Yang
./scripts/install.sh
```

## Documentation
Expand Down
61 changes: 56 additions & 5 deletions designer/main_window.ui
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,26 @@
<ui version="4.0">
<class>main_window</class>
<widget class="QMainWindow" name="main_window">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>550</width>
<height>800</height>
</rect>
</property>
<property name="sizePolicy">
<sizepolicy hsizetype="MinimumExpanding" vsizetype="MinimumExpanding">
<sizepolicy hsizetype="Preferred" vsizetype="MinimumExpanding">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="minimumSize">
<size>
<width>400</width>
<height>600</height>
</size>
</property>
<property name="windowTitle">
<string notr="true">Yin &amp; Yang</string>
</property>
Expand All @@ -29,7 +43,7 @@
</size>
</property>
<property name="currentIndex">
<number>0</number>
<number>1</number>
</property>
<widget class="QWidget" name="settings">
<attribute name="title">
Expand Down Expand Up @@ -316,11 +330,48 @@
<rect>
<x>0</x>
<y>0</y>
<width>348</width>
<height>451</height>
<width>523</width>
<height>663</height>
</rect>
</property>
<layout class="QVBoxLayout" name="plugins_scroll_content_layout"/>
<layout class="QVBoxLayout" name="plugins_scroll_content_layout">
<item>
<layout class="QHBoxLayout" name="horizontalLayout">
<item>
<widget class="QGroupBox" name="samplePluginGroupBox">
<property name="title">
<string>Sample Plugin</string>
</property>
<layout class="QHBoxLayout" name="horizontalLayout_2">
<item>
<widget class="QComboBox" name="comboBox">
<property name="sizeAdjustPolicy">
<enum>QComboBox::AdjustToContentsOnFirstShow</enum>
</property>
<property name="placeholderText">
<string>[email protected]</string>
</property>
</widget>
</item>
<item>
<widget class="QComboBox" name="comboBox_2">
<property name="currentText">
<string notr="true"/>
</property>
<property name="sizeAdjustPolicy">
<enum>QComboBox::AdjustToContentsOnFirstShow</enum>
</property>
<property name="placeholderText">
<string>[email protected]</string>
</property>
</widget>
</item>
</layout>
</widget>
</item>
</layout>
</item>
</layout>
</widget>
</widget>
</item>
Expand Down
13 changes: 10 additions & 3 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
PySide6>=6.0.0
suntime~=1.2.5
psutil~=5.9.1
numpy==1.23.5
psutil==5.9.4
PySide6==6.4.1
PySide6-Addons==6.4.1
PySide6-Essentials==6.4.1
python-dateutil==2.8.2
shiboken6==6.4.1
six==1.16.0
suntime==1.2.5
systemd-python==234
37 changes: 18 additions & 19 deletions src/plugins/_plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,32 +87,31 @@ def get_input(self, widget):
inputs = [QComboBox(widget), QComboBox(widget)]

# add all theme names
for i, inp in enumerate(inputs):
inp: QComboBox
for i, curComboBox in enumerate(inputs):
themes = list(self.available_themes.values())
themes.sort()
inp.addItems(themes)
curComboBox.addItems(themes)
curComboBox.setMinimumContentsLength(4)
# set index
is_dark = i == 1
theme: str = self.theme_dark if is_dark else self.theme_light
if theme == '':
logger.warning(f'Used theme is unknown for plugin {self.name}')
inp.setCurrentIndex(0)
else:
inp.setCurrentIndex(themes.index(self.available_themes[theme]))

try:
curComboBox.setCurrentIndex(themes.index(self.available_themes[theme]))
except (KeyError, ValueError):
logger.warning(f'Couldn\'t find theme {theme} in plugin {self.name}')
curComboBox.setCurrentIndex(0)
return inputs
else:
for is_dark in [False, True]:
theme = 'Dark' if is_dark else 'Light'
# provide a line edit, if the possible themes are unknown
inp: QLineEdit = QLineEdit(widget)
inp.setObjectName(f'inp_{theme}')
inp.setPlaceholderText(f'{theme} Theme')
inp.setText(self.theme_dark if is_dark else self.theme_light)
inputs.append(inp)

for is_dark in [False, True]:
theme = 'Dark' if is_dark else 'Light'
# provide a line edit, if the possible themes are unknown
inp: QLineEdit = QLineEdit(widget)
inp.setObjectName(f'inp_{theme}')
inp.setPlaceholderText(f'{theme} Theme')
inp.setText(self.theme_dark if is_dark else self.theme_light)
inputs.append(inp)

return inputs
return inputs

def __str__(self):
return self.name.lower()
Expand Down
17 changes: 12 additions & 5 deletions src/plugins/firefox.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
import json
from configparser import ConfigParser
import logging
from os.path import isdir
from pathlib import Path

from PySide6.QtWidgets import QGroupBox

from ._plugin import ExternalPlugin

logger = logging.getLogger(__name__)


def get_default_profile_path() -> str:
path = str(Path.home()) + '/.mozilla/firefox/'
Expand All @@ -33,11 +36,15 @@ def available_themes(self) -> dict:
path = get_default_profile_path() + '/extensions.json'
themes: dict[str, str] = {}

with open(path, 'r') as file:
content = json.load(file)
for addon in content['addons']:
if addon['type'] == 'theme':
themes[addon['id']] = addon['defaultLocale']['name']
try:
with open(path, 'r') as file:
content = json.load(file)
for addon in content['addons']:
if addon['type'] == 'theme':
themes[addon['id']] = addon['defaultLocale']['name']
except FileNotFoundError as e:
logger.error(f'Error: {e}.')
return {}

assert themes != {}, 'No themes found!'
return themes
Expand Down
52 changes: 43 additions & 9 deletions src/ui/main_window.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
################################################################################
## Form generated from reading UI file 'main_window.ui'
##
## Created by: Qt User Interface Compiler version 6.3.1
## Created by: Qt User Interface Compiler version 6.4.1
##
## WARNING! All changes made in this file will be lost when recompiling UI file!
################################################################################
Expand All @@ -15,30 +15,33 @@
QFont, QFontDatabase, QGradient, QIcon,
QImage, QKeySequence, QLinearGradient, QPainter,
QPalette, QPixmap, QRadialGradient, QTransform)
from PySide6.QtWidgets import (QAbstractButton, QApplication, QCheckBox, QDialogButtonBox,
QDoubleSpinBox, QFormLayout, QFrame, QLabel,
QMainWindow, QRadioButton, QScrollArea, QSizePolicy,
QSpacerItem, QStatusBar, QTabWidget, QTimeEdit,
QVBoxLayout, QWidget)
from PySide6.QtWidgets import (QAbstractButton, QApplication, QCheckBox, QComboBox,
QDialogButtonBox, QDoubleSpinBox, QFormLayout, QFrame,
QGroupBox, QHBoxLayout, QLabel, QMainWindow,
QRadioButton, QScrollArea, QSizePolicy, QSpacerItem,
QStatusBar, QTabWidget, QTimeEdit, QVBoxLayout,
QWidget)
import resources_rc

class Ui_main_window(object):
def setupUi(self, main_window):
if not main_window.objectName():
main_window.setObjectName(u"main_window")
sizePolicy = QSizePolicy(QSizePolicy.MinimumExpanding, QSizePolicy.MinimumExpanding)
main_window.resize(550, 800)
sizePolicy = QSizePolicy(QSizePolicy.Preferred, QSizePolicy.MinimumExpanding)
sizePolicy.setHorizontalStretch(0)
sizePolicy.setVerticalStretch(0)
sizePolicy.setHeightForWidth(main_window.sizePolicy().hasHeightForWidth())
main_window.setSizePolicy(sizePolicy)
main_window.setMinimumSize(QSize(400, 600))
main_window.setWindowTitle(u"Yin & Yang")
icon = QIcon()
iconThemeName = u"yin_yang"
if QIcon.hasThemeIcon(iconThemeName):
icon = QIcon.fromTheme(iconThemeName)
else:
icon.addFile(u":/icons/logo", QSize(), QIcon.Normal, QIcon.Off)

main_window.setWindowIcon(icon)
main_window.setLocale(QLocale(QLocale.English, QLocale.UnitedKingdom))
self.central_widget = QWidget(main_window)
Expand Down Expand Up @@ -240,11 +243,39 @@ def setupUi(self, main_window):
self.plugins_scroll.setWidgetResizable(True)
self.plugins_scroll_content = QWidget()
self.plugins_scroll_content.setObjectName(u"plugins_scroll_content")
self.plugins_scroll_content.setGeometry(QRect(0, 0, 348, 451))
self.plugins_scroll_content.setGeometry(QRect(0, 0, 523, 663))
self.plugins_scroll_content_layout = QVBoxLayout(self.plugins_scroll_content)
self.plugins_scroll_content_layout.setSpacing(6)
self.plugins_scroll_content_layout.setContentsMargins(11, 11, 11, 11)
self.plugins_scroll_content_layout.setObjectName(u"plugins_scroll_content_layout")
self.horizontalLayout = QHBoxLayout()
self.horizontalLayout.setSpacing(6)
self.horizontalLayout.setObjectName(u"horizontalLayout")
self.samplePluginGroupBox = QGroupBox(self.plugins_scroll_content)
self.samplePluginGroupBox.setObjectName(u"samplePluginGroupBox")
self.horizontalLayout_2 = QHBoxLayout(self.samplePluginGroupBox)
self.horizontalLayout_2.setSpacing(6)
self.horizontalLayout_2.setContentsMargins(11, 11, 11, 11)
self.horizontalLayout_2.setObjectName(u"horizontalLayout_2")
self.comboBox = QComboBox(self.samplePluginGroupBox)
self.comboBox.setObjectName(u"comboBox")
self.comboBox.setSizeAdjustPolicy(QComboBox.AdjustToContentsOnFirstShow)

self.horizontalLayout_2.addWidget(self.comboBox)

self.comboBox_2 = QComboBox(self.samplePluginGroupBox)
self.comboBox_2.setObjectName(u"comboBox_2")
self.comboBox_2.setCurrentText(u"")
self.comboBox_2.setSizeAdjustPolicy(QComboBox.AdjustToContentsOnFirstShow)

self.horizontalLayout_2.addWidget(self.comboBox_2)


self.horizontalLayout.addWidget(self.samplePluginGroupBox)


self.plugins_scroll_content_layout.addLayout(self.horizontalLayout)

self.plugins_scroll.setWidget(self.plugins_scroll_content)

self.plugins_layout.addWidget(self.plugins_scroll)
Expand Down Expand Up @@ -287,6 +318,9 @@ def retranslateUi(self, main_window):
self.toggle_sound.setText(QCoreApplication.translate("main_window", u"Make a sound when switching the theme", None))
self.toggle_notification.setText(QCoreApplication.translate("main_window", u"Send a notification", None))
self.tab_widget.setTabText(self.tab_widget.indexOf(self.settings), QCoreApplication.translate("main_window", u"Settings", None))
self.samplePluginGroupBox.setTitle(QCoreApplication.translate("main_window", u"Sample Plugin", None))
self.comboBox.setPlaceholderText(QCoreApplication.translate("main_window", u"[email protected]", None))
self.comboBox_2.setPlaceholderText(QCoreApplication.translate("main_window", u"[email protected]", None))
self.tab_widget.setTabText(self.tab_widget.indexOf(self.plugins), QCoreApplication.translate("main_window", u"Plugins", None))
pass
# retranslateUi
Expand Down
12 changes: 9 additions & 3 deletions src/ui/main_window_connector.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import logging
from typing import cast

from PySide6 import QtWidgets
from PySide6.QtCore import QStandardPaths
from PySide6.QtGui import QScreen, QColor
from PySide6.QtWidgets import QFileDialog, QMessageBox, QDialogButtonBox, QColorDialog
from PySide6.QtWidgets import QFileDialog, QMessageBox, QDialogButtonBox, QColorDialog,QGroupBox

from src.ui.main_window import Ui_main_window

Expand Down Expand Up @@ -109,13 +110,18 @@ def load_location(self):
self.ui.inp_longitude.setValue(coordinates[1])

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


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

widget = self.ui.plugins_scroll_content.findChild(QtWidgets.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 333a72a

Please sign in to comment.