Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor DBus plugin and its child plugins #290

Closed
wants to merge 14 commits into from
Prev Previous commit
Next Next commit
Refactor DBusPlugin
heddxh committed Apr 26, 2024
commit 9832e73abd2efd12ea4edbfd0f816ea71fea0ac1
19 changes: 12 additions & 7 deletions yin_yang/plugins/_plugin.py
Original file line number Diff line number Diff line change
@@ -4,13 +4,13 @@
from abc import ABC, abstractmethod
from configparser import ConfigParser
from pathlib import Path
from typing import Optional, List
from typing import List, Optional

from PySide6.QtDBus import QDBusConnection, QDBusMessage
from PySide6.QtGui import QColor, QRgba64
from PySide6.QtWidgets import QGroupBox, QHBoxLayout, QLineEdit, QComboBox
from PySide6.QtWidgets import QComboBox, QGroupBox, QHBoxLayout, QLineEdit

from ..meta import UnsupportedDesktopError, FileFormat
from ..meta import FileFormat, UnsupportedDesktopError

logger = logging.getLogger(__name__)

@@ -253,25 +253,30 @@ def set_theme(self, theme: str):


class DBusPlugin(Plugin):
"""A class for plugins that mainly switching theme via DBus"""
def __init__(self):
super().__init__()
self.connection = QDBusConnection.sessionBus()
self.message = QDBusMessage()
self.message_data: List[str] = ['' for _ in range(4)] # Store DBusMessage data(destination, path, interface, method)

def set_theme(self, theme: str):
"""Check arguments, create DBus message and then call"""
if not (self.available and self.enabled):
return

if not theme:
raise ValueError(f'Theme \"{theme}\" is invalid')

self.call(self.create_message(theme))
self.create_message(theme)
self.call()

@abstractmethod
def create_message(self, theme: str) -> QDBusMessage:
def create_message(self, theme: str) -> None:
heddxh marked this conversation as resolved.
Show resolved Hide resolved
raise NotImplementedError(f'Plugin {self.name} did not implement create_message()')

def call(self, message) -> QDBusMessage:
return self.connection.call(message)
def call(self) -> QDBusMessage:
return self.connection.call(self.message)


class ConfigFilePlugin(Plugin):