Fix custom cursor size on Windows

This commit is contained in:
Rebecca Breu 2021-07-09 21:39:08 +02:00
parent ff41aa4b69
commit 49bdfc0d39
4 changed files with 63 additions and 8 deletions

View file

@ -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)

54
beeref/assets/__init__.py Normal file
View file

@ -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 <https://www.gnu.org/licenses/>.
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)

View file

@ -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

View file

@ -28,9 +28,7 @@ setup(
},
include_package_data=True,
package_data={
'beeref': [
'assets/*.png',
'documentation/*.html'
],
'beeref.assets': ['*.png'],
'beeref': ['documentation/*.html'],
},
)