Skip to content

Commit

Permalink
chore: do not use deprecated pkg_resources
Browse files Browse the repository at this point in the history
  • Loading branch information
raimund-schluessler committed Jun 4, 2024
1 parent 25ebe41 commit d735ab5
Show file tree
Hide file tree
Showing 7 changed files with 44 additions and 40 deletions.
9 changes: 5 additions & 4 deletions bmicro/__main__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
def main():
import os
import pkg_resources
from importlib import resources
import sys
import logging

Expand All @@ -13,9 +13,10 @@ def main():
"""
app = QtWidgets.QApplication(sys.argv)
# set window icon
imdir = pkg_resources.resource_filename("bmicro", "img")
icon_path = os.path.join(imdir, "icon.png")
app.setWindowIcon(QtGui.QIcon(icon_path))
ref = resources.files('bmicro') / 'img'
with resources.as_file(ref) as imdir:
icon_path = os.path.join(imdir, "icon.png")
app.setWindowIcon(QtGui.QIcon(icon_path))

window = BMicro()
window.show()
Expand Down
14 changes: 7 additions & 7 deletions bmicro/gui/calibration/calibration_view.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import pkg_resources
from importlib import resources
import logging

from PyQt6 import QtWidgets, QtCore, uic
Expand Down Expand Up @@ -31,9 +31,9 @@ class CalibrationView(QtWidgets.QWidget):
def __init__(self, *args, **kwargs):
super(CalibrationView, self).__init__(*args, **kwargs)

ui_file = pkg_resources.resource_filename(
'bmicro.gui.calibration', 'calibration_view.ui')
uic.loadUi(ui_file, self)
ref = resources.files('bmicro.gui.calibration') / 'calibration_view.ui'
with resources.as_file(ref) as ui_file:
uic.loadUi(ui_file, self)

self.mplcanvas = MplCanvas(self.image_widget,
toolbar=('Home', 'Pan', 'Zoom'))
Expand Down Expand Up @@ -422,14 +422,14 @@ def find_peaks(self):
self.refresh_plot()

def show_options(self):
ui_file = pkg_resources.resource_filename(
'bmicro.gui.calibration', 'calibration_options.ui')
self.options_dialog = QtWidgets.QDialog(
self,
QtCore.Qt.WindowType.WindowTitleHint |
QtCore.Qt.WindowType.WindowCloseButtonHint
)
uic.loadUi(ui_file, self.options_dialog)
ref = resources.files('bmicro.gui.calibration') / 'calibration_options.ui'
with resources.as_file(ref) as ui_file:
uic.loadUi(ui_file, self.options_dialog)
self.options_dialog.setWindowTitle('Calibration options')
self.options_dialog.setWindowModality(
QtCore.Qt.WindowModality.ApplicationModal)
Expand Down
8 changes: 4 additions & 4 deletions bmicro/gui/data/data_view.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import pkg_resources
from importlib import resources
import logging

from PyQt6 import uic, QtWidgets
Expand All @@ -24,9 +24,9 @@ class DataView(QtWidgets.QWidget):
def __init__(self, *args, **kwargs):
super(DataView, self).__init__(*args, **kwargs)

ui_file = pkg_resources.resource_filename(
'bmicro.gui.data', 'data_view.ui')
uic.loadUi(ui_file, self)
ref = resources.files('bmicro.gui.data') / 'data_view.ui'
with resources.as_file(ref) as ui_file:
uic.loadUi(ui_file, self)

self.mplcanvas = MplCanvas(self.image_preview_widget)
self.preview = self.mplcanvas.get_figure().add_subplot(111)
Expand Down
14 changes: 7 additions & 7 deletions bmicro/gui/evaluation/evaluation_view.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import pkg_resources
from importlib import resources
import logging
import numpy as np
import matplotlib
Expand Down Expand Up @@ -43,9 +43,9 @@ class EvaluationView(QtWidgets.QWidget):
def __init__(self, *args, **kwargs):
super(EvaluationView, self).__init__(*args, **kwargs)

ui_file = pkg_resources.resource_filename(
'bmicro.gui.evaluation', 'evaluation_view.ui')
uic.loadUi(ui_file, self)
ref = resources.files('bmicro.gui.evaluation') / 'evaluation_view.ui'
with resources.as_file(ref) as ui_file:
uic.loadUi(ui_file, self)

self.mplcanvas = MplCanvas(self.image_widget,
toolbar=('Home', 'Pan', 'Zoom'))
Expand Down Expand Up @@ -314,16 +314,16 @@ def on_click_image(self, event):

def open_image_spectrum(self):
if self.image_spectrum_dialog is None:
ui_file = pkg_resources.resource_filename(
'bmicro.gui.evaluation', 'spectrum_view.ui')
self.image_spectrum_dialog = QtWidgets.QDialog(
self,
QtCore.Qt.WindowType.WindowTitleHint |
QtCore.Qt.WindowType.WindowCloseButtonHint |
QtCore.Qt.WindowType.WindowMaximizeButtonHint |
QtCore.Qt.WindowType.WindowMinimizeButtonHint
)
uic.loadUi(ui_file, self.image_spectrum_dialog)
ref = resources.files('bmicro.gui.evaluation') / 'spectrum_view.ui'
with resources.as_file(ref) as ui_file:
uic.loadUi(ui_file, self.image_spectrum_dialog)
self.image_spectrum_dialog\
.setWindowTitle('Camera image & spectrum')
self.image_spectrum_dialog.setWindowModality(
Expand Down
8 changes: 4 additions & 4 deletions bmicro/gui/extraction/extraction_view.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import pkg_resources
from importlib import resources
import logging

from PyQt6 import QtWidgets, QtCore, uic
Expand Down Expand Up @@ -28,9 +28,9 @@ class ExtractionView(QtWidgets.QWidget):
def __init__(self, *args, **kwargs):
super(ExtractionView, self).__init__(*args, **kwargs)

ui_file = pkg_resources.resource_filename(
'bmicro.gui.extraction', 'extraction_view.ui')
uic.loadUi(ui_file, self)
ref = resources.files('bmicro.gui.extraction') / 'extraction_view.ui'
with resources.as_file(ref) as ui_file:
uic.loadUi(ui_file, self)

self.mode = MODE_DEFAULT
self.current_frame = 0
Expand Down
23 changes: 13 additions & 10 deletions bmicro/gui/main.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import pathlib
import pkg_resources
from importlib import resources
import hashlib
import signal
import sys
Expand Down Expand Up @@ -64,11 +64,14 @@ def __init__(self, *args, **kwargs):

""" Initializes BMicro."""
super(BMicro, self).__init__(*args, **kwargs)
ui_file = pkg_resources.resource_filename('bmicro.gui', 'main.ui')
uic.loadUi(ui_file, self)
ref = resources.files('bmicro.gui') / 'main.ui'
with resources.as_file(ref) as ui_file:
uic.loadUi(ui_file, self)
QtCore.QCoreApplication.setApplicationName('BMicro')

self.imdir = pkg_resources.resource_filename("bmicro", "img")
ref = resources.files('bmicro') / 'img'
with resources.as_file(ref) as imdir:
self.imdir = imdir

self.tabWidget.currentChanged.connect(self.update_ui)

Expand Down Expand Up @@ -200,14 +203,14 @@ def close_file(self):
self.reset_ui()

def on_action_export_file(self):
ui_file = pkg_resources.resource_filename(
'bmicro.gui', 'export_configuration.ui')
self.export_dialog = QtWidgets.QDialog(
self,
QtCore.Qt.WindowType.WindowTitleHint |
QtCore.Qt.WindowType.WindowCloseButtonHint
)
uic.loadUi(ui_file, self.export_dialog)
ref = resources.files('bmicro.gui') / 'export_configuration.ui'
with resources.as_file(ref) as ui_file:
uic.loadUi(ui_file, self.export_dialog)
self.export_dialog.setWindowTitle('Export configuration')
self.export_dialog.setWindowModality(
QtCore.Qt.WindowModality.ApplicationModal)
Expand Down Expand Up @@ -402,16 +405,16 @@ def on_action_about(self):
f"BMicro {bmicroversion}", about_text)

def on_action_batch_evaluation(self):
ui_file = pkg_resources.resource_filename(
'bmicro.gui', 'batch_evaluation.ui')
self.batch_dialog = QtWidgets.QDialog(
self,
QtCore.Qt.WindowType.WindowTitleHint |
QtCore.Qt.WindowType.WindowCloseButtonHint |
QtCore.Qt.WindowType.WindowMaximizeButtonHint |
QtCore.Qt.WindowType.WindowMinimizeButtonHint
)
uic.loadUi(ui_file, self.batch_dialog)
ref = resources.files('bmicro.gui') / 'batch_evaluation.ui'
with resources.as_file(ref) as ui_file:
uic.loadUi(ui_file, self.batch_dialog)
self.batch_dialog.setWindowTitle('Batch evaluation')
self.batch_dialog.setWindowModality(
QtCore.Qt.WindowModality.ApplicationModal)
Expand Down
8 changes: 4 additions & 4 deletions bmicro/gui/peak_selection/peak_selection_view.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import pkg_resources
from importlib import resources
import logging

from PyQt6 import QtWidgets, uic
Expand Down Expand Up @@ -27,9 +27,9 @@ class PeakSelectionView(QtWidgets.QWidget):
def __init__(self, *args, **kwargs):
super(PeakSelectionView, self).__init__(*args, **kwargs)

ui_file = pkg_resources.resource_filename(
'bmicro.gui.peak_selection', 'peak_selection_view.ui')
uic.loadUi(ui_file, self)
ref = resources.files('bmicro.gui.peak_selection') / 'peak_selection_view.ui'
with resources.as_file(ref) as ui_file:
uic.loadUi(ui_file, self)

self.mplcanvas = MplCanvas(self.image_widget,
toolbar=('Home', 'Pan', 'Zoom'))
Expand Down

0 comments on commit d735ab5

Please sign in to comment.