Skip to content

Commit

Permalink
Use importlib.resources instead of __file__
Browse files Browse the repository at this point in the history
  • Loading branch information
rbreu committed May 7, 2024
1 parent 8a19a91 commit 5b86ad9
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 11 deletions.
8 changes: 4 additions & 4 deletions beeref/assets/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@
# You should have received a copy of the GNU General Public License
# along with BeeRef. If not, see <https://www.gnu.org/licenses/>.

from importlib.resources import files as rsc_files
import logging
import os.path

from PyQt6 import QtGui, QtWidgets

Expand All @@ -26,7 +26,7 @@

class BeeAssets:
_instance = None
PATH = os.path.dirname(__file__)
PATH = rsc_files('beeref.assets')

def __new__(cls, *args, **kwargs):
if not cls._instance:
Expand All @@ -37,7 +37,7 @@ def __new__(cls, *args, **kwargs):
def on_new(self):
logger.debug(f'Assets path: {self.PATH}')

self.logo = QtGui.QIcon(os.path.join(self.PATH, 'logo.png'))
self.logo = QtGui.QIcon(str(self.PATH.joinpath('logo.png')))
assert self.logo.isNull() is False
self.cursor_rotate = self.cursor_from_image(
'cursor_rotate.png', (20, 20))
Expand All @@ -49,7 +49,7 @@ def on_new(self):
def cursor_from_image(self, filename, hotspot):
app = QtWidgets.QApplication.instance()
scaling = app.primaryScreen().devicePixelRatio()
img = QtGui.QImage(os.path.join(self.PATH, filename))
img = QtGui.QImage(str(self.PATH.joinpath(filename)))
assert img.isNull() is False
pixmap = QtGui.QPixmap.fromImage(img)
pixmap.setDevicePixelRatio(scaling)
Expand Down
10 changes: 4 additions & 6 deletions beeref/widgets/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@
# You should have received a copy of the GNU General Public License
# along with BeeRef. If not, see <https://www.gnu.org/licenses/>.

from importlib.resources import files as rsc_files
import logging
import os.path

from PyQt6 import QtCore, QtWidgets, QtGui
from PyQt6.QtCore import Qt
Expand Down Expand Up @@ -66,14 +66,12 @@ class HelpDialog(QtWidgets.QDialog):
def __init__(self, parent):
super().__init__(parent)
self.setWindowTitle(f'{constants.APPNAME} Help')
docdir = os.path.join(os.path.dirname(__file__),
'..',
'documentation')

tabs = QtWidgets.QTabWidget()

# Controls
with open(os.path.join(docdir, 'controls.html')) as f:
controls_txt = f.read()
controls_txt = rsc_files(
'beeref.documentation').joinpath('controls.html').read_text()
controls_label = QtWidgets.QLabel(controls_txt)
controls_label.setTextInteractionFlags(
Qt.TextInteractionFlag.TextSelectableByMouse)
Expand Down
5 changes: 4 additions & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
[flake8]
exclude = squashfs-root
exclude =
squashfs-root
build
dist

[coverage:run]
source = beeref
Expand Down

0 comments on commit 5b86ad9

Please sign in to comment.