From 49bdfc0d39319544690a1f44d21a1321f6afdf0d Mon Sep 17 00:00:00 2001 From: Rebecca Breu Date: Fri, 9 Jul 2021 21:39:08 +0200 Subject: [PATCH] Fix custom cursor size on Windows --- beeref/assets.py | 9 ++++--- beeref/assets/__init__.py | 54 +++++++++++++++++++++++++++++++++++++++ beeref/fileio/sql.py | 2 +- setup.py | 6 ++--- 4 files changed, 63 insertions(+), 8 deletions(-) create mode 100644 beeref/assets/__init__.py diff --git a/beeref/assets.py b/beeref/assets.py index 5bb7658..99b325a 100644 --- a/beeref/assets.py +++ b/beeref/assets.py @@ -18,7 +18,7 @@ import logging import os.path -from PyQt6 import QtGui +from PyQt6 import QtGui, QtWidgets logger = logging.getLogger(__name__) @@ -46,6 +46,9 @@ class BeeAssets: 'cursor_flip_v.png', (20, 20)) def cursor_from_image(self, filename, hotspot): + app = QtWidgets.QApplication.instance() + scaling = app.primaryScreen().devicePixelRatio() img = QtGui.QImage(os.path.join(self.PATH, filename)) - return QtGui.QCursor( - QtGui.QPixmap.fromImage(img), hotspot[0], hotspot[1]) + pixmap = QtGui.QPixmap.fromImage(img) + pixmap.setDevicePixelRatio(scaling) + return QtGui.QCursor(pixmap, hotspot[0]/scaling, hotspot[1]/scaling) diff --git a/beeref/assets/__init__.py b/beeref/assets/__init__.py new file mode 100644 index 0000000..99b325a --- /dev/null +++ b/beeref/assets/__init__.py @@ -0,0 +1,54 @@ +#!/usr/bin/env python3 + +# This file is part of BeeRef. +# +# BeeRef 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. +# +# BeeRef 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 BeeRef. If not, see . + +import logging +import os.path + +from PyQt6 import QtGui, QtWidgets + + +logger = logging.getLogger(__name__) + + +class BeeAssets: + _instance = None + PATH = os.path.join(os.path.dirname(__file__), 'assets') + + def __new__(cls, *args, **kwargs): + if not cls._instance: + cls._instance = super().__new__(cls, *args, **kwargs) + cls._instance.on_new() + return cls._instance + + def on_new(self): + logger.debug(f'Assets path: {self.PATH}') + + self.logo = QtGui.QIcon(os.path.join(self.PATH, 'logo.png')) + self.cursor_rotate = self.cursor_from_image( + 'cursor_rotate.png', (20, 20)) + self.cursor_flip_h = self.cursor_from_image( + 'cursor_flip_h.png', (20, 20)) + self.cursor_flip_v = self.cursor_from_image( + 'cursor_flip_v.png', (20, 20)) + + def cursor_from_image(self, filename, hotspot): + app = QtWidgets.QApplication.instance() + scaling = app.primaryScreen().devicePixelRatio() + img = QtGui.QImage(os.path.join(self.PATH, filename)) + pixmap = QtGui.QPixmap.fromImage(img) + pixmap.setDevicePixelRatio(scaling) + return QtGui.QCursor(pixmap, hotspot[0]/scaling, hotspot[1]/scaling) diff --git a/beeref/fileio/sql.py b/beeref/fileio/sql.py index 4b2e647..f81d456 100644 --- a/beeref/fileio/sql.py +++ b/beeref/fileio/sql.py @@ -87,7 +87,7 @@ class SQLiteIO: uri = pathlib.Path(self.filename).resolve().as_uri() if self.readonly: uri = f'{uri}?mode=ro' - self._connection = sqlite3.connect(uri) + self._connection = sqlite3.connect(uri, uri=True) self._cursor = self.connection.cursor() @property diff --git a/setup.py b/setup.py index a8baef0..5670c42 100644 --- a/setup.py +++ b/setup.py @@ -28,9 +28,7 @@ setup( }, include_package_data=True, package_data={ - 'beeref': [ - 'assets/*.png', - 'documentation/*.html' - ], + 'beeref.assets': ['*.png'], + 'beeref': ['documentation/*.html'], }, )