Skip to content

Commit

Permalink
fix: update to pyqt6 (#90)
Browse files Browse the repository at this point in the history
* fix: started work on update to PyQt6

* fix: continued work on update to PyQt6

Co-authored-by: Erik Bjäreholt <erik@bjareho.lt>
  • Loading branch information
maciekstosio and ErikBjare authored Sep 23, 2022
1 parent 730575b commit 79be33b
Show file tree
Hide file tree
Showing 7 changed files with 233 additions and 140 deletions.
5 changes: 2 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

build:
poetry install
make aw_qt/resources.py

install:
bash scripts/config-autostart.sh
Expand Down Expand Up @@ -31,5 +30,5 @@ clean:
rm -rf build dist
rm -rf __pycache__ aw_qt/__pycache__

aw_qt/resources.py: aw_qt/resources.qrc
poetry run pyrcc5 -o aw_qt/resources.py aw_qt/resources.qrc
#aw_qt/resources.py: aw_qt/resources.qrc
# poetry run pyrcc5 -o aw_qt/resources.py aw_qt/resources.qrc
6 changes: 3 additions & 3 deletions aw-qt.spec
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ if platform.system() == "Windows":
# The Windows version includes paths to Qt binaries which are
# not automatically found due to bug in PyInstaller 3.2.
# See: https://github.com/pyinstaller/pyinstaller/issues/2152
import PyQt5
pyqt_path = os.path.dirname(PyQt5.__file__)
import PyQt6
pyqt_path = os.path.dirname(PyQt6.__file__)
extra_pathex.append(pyqt_path + "\\Qt\\bin")


Expand All @@ -27,7 +27,7 @@ block_cipher = None
a = Analysis(['aw_qt/__main__.py'],
pathex=[] + extra_pathex,
binaries=None,
datas=[('resources/aw-qt.desktop', '.')],
datas=[('resources/aw-qt.desktop', '.'), ('media', 'media')],
hiddenimports=[],
hookspath=[],
runtime_hooks=[],
Expand Down
2 changes: 1 addition & 1 deletion aw_qt/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
from . import resources
#from . import resources

from .main import main
7 changes: 0 additions & 7 deletions aw_qt/resources.qrc

This file was deleted.

34 changes: 18 additions & 16 deletions aw_qt/trayicon.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,16 @@
from typing import Any, Optional, Dict
import webbrowser

from PyQt5 import QtCore
from PyQt5.QtWidgets import (
from PyQt6 import QtCore
from PyQt6.QtWidgets import (
QApplication,
QSystemTrayIcon,
QMessageBox,
QMenu,
QWidget,
QPushButton,
)
from PyQt5.QtGui import QIcon
from PyQt6.QtGui import QIcon

import aw_core

Expand Down Expand Up @@ -92,7 +92,7 @@ def __init__(
self._build_rootmenu()

def on_activated(self, reason: QSystemTrayIcon.ActivationReason) -> None:
if reason == QSystemTrayIcon.DoubleClick:
if reason == QSystemTrayIcon.ActivationReason.DoubleClick:
open_webui(self.root_url)

def _build_rootmenu(self) -> None:
Expand Down Expand Up @@ -132,14 +132,14 @@ def _build_rootmenu(self) -> None:

def show_module_failed_dialog(module: Module) -> None:
box = QMessageBox(self._parent)
box.setIcon(QMessageBox.Warning)
box.setIcon(QMessageBox.Icon.Warning)
box.setText(f"Module {module.name} quit unexpectedly")
box.setDetailedText(module.read_log(self.testing))

restart_button = QPushButton("Restart", box)
restart_button.clicked.connect(module.start)
box.addButton(restart_button, QMessageBox.AcceptRole)
box.setStandardButtons(QMessageBox.Cancel)
box.addButton(restart_button, QMessageBox.ButtonRole.AcceptRole)
box.setStandardButtons(QMessageBox.StandardButton.Cancel)

box.show()

Expand Down Expand Up @@ -207,34 +207,36 @@ def run(manager: Manager, testing: bool = False) -> Any:

app = QApplication(sys.argv)

# TODO: Set icon path correctly
QtCore.QDir.addSearchPath("icons", "media/logo/")
# QtCore.QDir.addSearchPath("icons", "../media/logo/")

# Without this, Ctrl+C will have no effect
signal.signal(signal.SIGINT, lambda *args: exit(manager))
# Ensure cleanup happens on SIGTERM
signal.signal(signal.SIGTERM, lambda *args: exit(manager))

# Allow pixmaps (e.g. trayicon) to use higher DPI images to make icons less
# blurry when fractional scaling is used
app.setAttribute(QtCore.Qt.AA_UseHighDpiPixmaps)

timer = QtCore.QTimer()
timer.start(100) # You may change this if you wish.
timer.timeout.connect(lambda: None) # Let the interpreter run each 500 ms.

# root widget
widget = QWidget()

if not QSystemTrayIcon.isSystemTrayAvailable():
QMessageBox.critical(
None,
widget,
"Systray",
"I couldn't detect any system tray on this system. Either get one or run the ActivityWatch modules from the console.",
)
sys.exit(1)

widget = QWidget()
if sys.platform == "darwin":
icon = QIcon(":/black-monochrome-logo.png")
icon = QIcon("icons:black-monochrome-logo.png")
# Allow macOS to use filters for changing the icon's color
icon.setIsMask(True)
else:
icon = QIcon(":/logo.png")
icon = QIcon("icons:logo.png")

trayIcon = TrayIcon(manager, icon, widget, testing=testing)
trayIcon.show()
Expand All @@ -243,4 +245,4 @@ def run(manager: Manager, testing: bool = False) -> Any:

logger.info("Initialized aw-qt and trayicon successfully")
# Run the application, blocks until quit
return app.exec_()
return app.exec()
Loading

0 comments on commit 79be33b

Please sign in to comment.