Visitar URL original
Use gui_assets for icons and pixmaps · DeepLabCut/DeepLabCut@44ba095 · GitHub
Skip to content

Commit 44ba095

Browse files
committed
Use gui_assets for icons and pixmaps
Replace direct filesystem asset loading (BASE_DIR/assets and manual Path lookups) with centralized gui_assets helpers (icon_from_resource, pixmap_from_resource, get_style_qss/get_assets_dir) across multiple GUI modules. Updated imports and calls in components, launch_script, create_project, modelzoo, open_project, train_network, and window to use the new resource functions and remove redundant logo path handling, improving resource access and packaging robustness.
1 parent c8a4a26 commit 44ba095

7 files changed

Lines changed: 34 additions & 42 deletions

File tree

‎deeplabcut/gui/components.py‎

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,10 @@
1414

1515
from PySide6 import QtWidgets
1616
from PySide6.QtCore import Qt, Slot
17-
from PySide6.QtGui import QIcon
1817

1918
from deeplabcut.core.config import read_config_as_dict
2019
from deeplabcut.gui.dlc_params import DLCParams
20+
from deeplabcut.gui.gui_assets import icon_from_resource
2121
from deeplabcut.gui.widgets import ConfigEditor
2222

2323

@@ -671,8 +671,9 @@ def _create_message_box(text, info_text):
671671

672672
msg.setWindowTitle("Info")
673673
msg.setMinimumWidth(900)
674-
logo = Path("logo.png").resolve().parent / "assets" / "logo.png"
675-
msg.setWindowIcon(QIcon(str(logo)))
674+
# logo = Path("logo.png").resolve().parent / "assets" / "logo.png"
675+
icon = icon_from_resource("logo.png")
676+
msg.setWindowIcon(icon)
676677
msg.setStandardButtons(QtWidgets.QMessageBox.Ok)
677678
return msg
678679

@@ -685,8 +686,8 @@ def _create_confirmation_box(title, description):
685686

686687
msg.setWindowTitle("Confirmation")
687688
msg.setMinimumWidth(900)
688-
logo = Path("logo.png").resolve().parent / "assets" / "logo.png"
689-
msg.setWindowIcon(QIcon(str(logo)))
689+
icon = icon_from_resource("logo.png")
690+
msg.setWindowIcon(icon)
690691
msg.setStandardButtons(QtWidgets.QMessageBox.Yes | QtWidgets.QMessageBox.No)
691692
return msg
692693

‎deeplabcut/gui/launch_script.py‎

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,18 +24,16 @@
2424
import PySide6.QtWidgets as QtWidgets
2525
import qdarkstyle
2626
from PySide6.QtCore import Qt
27-
from PySide6.QtGui import QIcon, QPixmap
2827

2928
from deeplabcut.gui import BASE_DIR
29+
from deeplabcut.gui.gui_assets import icon_from_resource, pixmap_from_resource
3030

3131

3232
def launch_dlc():
3333
app = QtWidgets.QApplication(sys.argv)
34-
app.setWindowIcon(QIcon(str(BASE_DIR / "assets" / "logo.png")))
34+
app.setWindowIcon(icon_from_resource("logo.png"))
3535
screen_size = app.screens()[0].size()
36-
pixmap = QPixmap(str(BASE_DIR / "assets" / "welcome.png")).scaledToWidth(
37-
int(0.7 * screen_size.width()), Qt.SmoothTransformation
38-
)
36+
pixmap = pixmap_from_resource("welcome.png").scaledToWidth(int(0.7 * screen_size.width()), Qt.SmoothTransformation)
3937
splash = QtWidgets.QSplashScreen(pixmap)
4038
splash.show()
4139

‎deeplabcut/gui/tabs/create_project.py‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,11 @@
1212
from pathlib import Path
1313

1414
from PySide6 import QtCore, QtWidgets
15-
from PySide6.QtGui import QBrush, QColor, QDesktopServices, QIcon, QPainter, QPen
15+
from PySide6.QtGui import QBrush, QColor, QDesktopServices, QPainter, QPen
1616

1717
from deeplabcut.create_project import create_new_project, create_new_project_3d
18-
from deeplabcut.gui import BASE_DIR
1918
from deeplabcut.gui.dlc_params import DLCParams
19+
from deeplabcut.gui.gui_assets import icon_from_resource
2020
from deeplabcut.gui.tabs.docs import (
2121
URL_3D,
2222
URL_MA_CONFIGURE,
@@ -235,7 +235,7 @@ def lay_out_user_frame(self):
235235
self.loc_line = QtWidgets.QLineEdit(self.loc_default, user_frame)
236236
self.loc_line.setReadOnly(True)
237237
action = self.loc_line.addAction(
238-
QIcon(str(BASE_DIR / "assets" / "icons" / "open2.png")),
238+
icon_from_resource("icons", "open2.png"),
239239
QtWidgets.QLineEdit.TrailingPosition,
240240
)
241241
action.triggered.connect(self.on_click)

‎deeplabcut/gui/tabs/modelzoo.py‎

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,10 @@
1515
import dlclibrary
1616
from PySide6 import QtWidgets
1717
from PySide6.QtCore import QRegularExpression, QSize, Qt, QTimer, Signal, Slot
18-
from PySide6.QtGui import QIcon, QPixmap, QRegularExpressionValidator
18+
from PySide6.QtGui import QRegularExpressionValidator
1919

2020
import deeplabcut
2121
from deeplabcut.core.engine import Engine
22-
from deeplabcut.gui import BASE_DIR
2322
from deeplabcut.gui.components import (
2423
DefaultTab,
2524
VideoSelectionWidget,
@@ -28,6 +27,7 @@
2827
set_combo_items,
2928
set_layout_contents_visible,
3029
)
30+
from deeplabcut.gui.gui_assets import icon_from_resource, pixmap_from_resource
3131
from deeplabcut.gui.utils import move_to_separate_thread
3232
from deeplabcut.gui.widgets import ClickableLabel
3333
from deeplabcut.pose_estimation_pytorch.apis.utils import TORCHVISION_DETECTORS
@@ -212,7 +212,7 @@ def _add_output_settings_section(self, layout: QtWidgets.QGridLayout):
212212
)
213213
self.loc_line.setReadOnly(True)
214214
action = self.loc_line.addAction(
215-
QIcon(str(BASE_DIR / "assets" / "icons" / "open2.png")),
215+
icon_from_resource("icons", "open2.png"),
216216
QtWidgets.QLineEdit.TrailingPosition,
217217
)
218218
action.triggered.connect(self.select_folder)
@@ -250,7 +250,7 @@ def _add_tf_scales_row(self, layout: QtWidgets.QGridLayout):
250250
validator.validationChanged.connect(self._handle_validation_change)
251251
self.scales_line.setValidator(validator)
252252
tooltip_label = QtWidgets.QLabel()
253-
tooltip_label.setPixmap(QPixmap(str(BASE_DIR / "assets" / "icons" / "help2.png")).scaledToWidth(30))
253+
tooltip_label.setPixmap(pixmap_from_resource("icons", "help2.png").scaledToWidth(30))
254254
tooltip_label.setToolTip(
255255
"Approximate animal sizes in pixels, for spatial pyramid search. If left "
256256
"blank, defaults to video height +/- 50 pixels"
@@ -268,7 +268,7 @@ def _add_use_adaptation_row(self, layout: QtWidgets.QGridLayout, layout_row: int
268268
self.adapt_checkbox.setStyleSheet("font-weight: bold; font-size: 16px; padding: 6px 12px;")
269269
# Add help button
270270
adapt_help_btn = QtWidgets.QToolButton()
271-
adapt_help_btn.setIcon(QIcon(str(BASE_DIR / "assets" / "icons" / "help2.png")))
271+
adapt_help_btn.setIcon(icon_from_resource("icons", "help2.png"))
272272
adapt_help_btn.setIconSize(QSize(24, 24))
273273
adapt_help_btn.setToolTip("What is video adaptation?")
274274

‎deeplabcut/gui/tabs/open_project.py‎

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@
1111
from pathlib import Path
1212

1313
from PySide6 import QtCore, QtWidgets
14-
from PySide6.QtGui import QIcon
14+
15+
from deeplabcut.gui.gui_assets import icon_from_resource
1516

1617

1718
class OpenProject(QtWidgets.QDialog):
@@ -76,17 +77,13 @@ def open_project(self):
7677

7778
msg.setWindowTitle("Error")
7879
msg.setMinimumWidth(400)
79-
self.logo_dir = str(Path("logo.png").resolve().parent) + "/"
80-
self.logo = self.logo_dir + "/assets/logo.png"
81-
msg.setWindowIcon(QIcon(self.logo))
80+
icon = icon_from_resource("logo.png")
81+
msg.setWindowIcon(icon)
8282
msg.setStandardButtons(QtWidgets.QMessageBox.Ok)
8383
msg.exec_()
8484

8585
self.loaded = False
8686
else:
87-
self.logo_dir = str(Path("logo.png").resolve().parent) + "/"
88-
self.logo = self.logo_dir + "/assets/logo.png"
89-
9087
self.loaded = True
9188
self.accept()
9289
self.close()

‎deeplabcut/gui/tabs/train_network.py‎

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,9 @@
1111
from __future__ import annotations
1212

1313
from dataclasses import dataclass
14-
from pathlib import Path
1514

1615
from PySide6 import QtWidgets
1716
from PySide6.QtCore import Qt, Slot
18-
from PySide6.QtGui import QIcon
1917

2018
import deeplabcut.compat as compat
2119
from deeplabcut.core.engine import Engine
@@ -27,6 +25,7 @@
2725
_create_label_widget,
2826
)
2927
from deeplabcut.gui.displays.selected_shuffle_display import SelectedShuffleDisplay
28+
from deeplabcut.gui.gui_assets import icon_from_resource
3029
from deeplabcut.gui.widgets import ConfigEditor
3130

3231

@@ -244,9 +243,7 @@ def train_network(self):
244243

245244
msg.setWindowTitle("Info")
246245
msg.setMinimumWidth(900)
247-
self.logo_dir = str(Path("logo.png").resolve().parent) + "/"
248-
self.logo = self.logo_dir + "/assets/logo.png"
249-
msg.setWindowIcon(QIcon(self.logo))
246+
msg.setWindowIcon(icon_from_resource("logo.png"))
250247
msg.setStandardButtons(QtWidgets.QMessageBox.Ok)
251248
msg.exec_()
252249

‎deeplabcut/gui/window.py‎

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
from napari_deeplabcut import __version__ as NAPARI_DLC_VERSION
2121
from PySide6 import QtCore, QtGui, QtWidgets
2222
from PySide6.QtCore import Qt
23-
from PySide6.QtGui import QAction, QIcon, QPixmap
23+
from PySide6.QtGui import QAction, QPixmap
2424
from PySide6.QtWidgets import (
2525
QComboBox,
2626
QLabel,
@@ -36,8 +36,9 @@
3636
from deeplabcut import auxiliaryfunctions, compat
3737
from deeplabcut.core.debug import install_debug_recorder
3838
from deeplabcut.core.engine import Engine
39-
from deeplabcut.gui import BASE_DIR, components
39+
from deeplabcut.gui import components
4040
from deeplabcut.gui.dialogs import create_generate_debug_log_action
41+
from deeplabcut.gui.gui_assets import icon_from_resource, pixmap_from_resource
4142
from deeplabcut.gui.tabs import (
4243
AnalyzeVideos,
4344
CreateTrainingDataset,
@@ -213,9 +214,8 @@ def engine(self, e: Engine) -> None:
213214

214215
msg.setWindowTitle("Info")
215216
msg.setMinimumWidth(900)
216-
logo_dir = str(Path("logo.png").resolve().parent) + "/"
217-
logo = logo_dir + "/assets/logo.png"
218-
msg.setWindowIcon(QIcon(logo))
217+
icon = icon_from_resource("logo.png")
218+
msg.setWindowIcon(icon)
219219
msg.setStandardButtons(QtWidgets.QMessageBox.Ok)
220220
msg.exec_()
221221

@@ -511,8 +511,8 @@ def window_set(self):
511511
palette.setColor(QtGui.QPalette.Window, QtGui.QColor("#ffffff"))
512512
self.setPalette(palette)
513513

514-
icon = str(BASE_DIR / "assets" / "logo.png")
515-
self.setWindowIcon(QIcon(icon))
514+
# icon = str(BASE_DIR / "assets" / "logo.png")
515+
self.setWindowIcon(icon_from_resource("logo.png"))
516516

517517
# Set default window size and allow resizing
518518
self.resize(
@@ -545,8 +545,7 @@ def _generate_welcome_page(self):
545545
image_widget = QtWidgets.QLabel(self)
546546
image_widget.setAlignment(Qt.AlignCenter)
547547
image_widget.setContentsMargins(0, 0, 0, 0)
548-
logo = str(BASE_DIR / "assets" / "logo_transparent.png")
549-
pixmap = QtGui.QPixmap(logo)
548+
pixmap = pixmap_from_resource("logo_transparent.png")
550549
image_widget.setPixmap(pixmap.scaledToHeight(400, QtCore.Qt.SmoothTransformation))
551550
self.layout.addWidget(image_widget)
552551
description = (
@@ -602,15 +601,15 @@ def create_actions(self, names):
602601
self.newAction = QAction(self)
603602
self.newAction.setText("&New Project...")
604603

605-
self.newAction.setIcon(QIcon(str(BASE_DIR / "assets" / "icons" / names[0])))
604+
self.newAction.setIcon(icon_from_resource("icons", names[0]))
606605
self.newAction.setShortcut("Ctrl+N")
607606
self.newAction.setStatusTip("Create a new project...")
608607

609608
self.newAction.triggered.connect(self._create_project)
610609

611610
# Creating actions using the second constructor
612611
self.openAction = QAction("&Open...", self)
613-
self.openAction.setIcon(QIcon(str(BASE_DIR / "assets" / "icons" / names[1])))
612+
self.openAction.setIcon(icon_from_resource("icons", names[1]))
614613
self.openAction.setShortcut("Ctrl+O")
615614
self.openAction.setStatusTip("Open a project...")
616615
self.openAction.triggered.connect(self._open_project)
@@ -624,7 +623,7 @@ def create_actions(self, names):
624623
self.darkmodeAction.triggered.connect(self.darkmode)
625624

626625
self.helpAction = QAction("&Help", self)
627-
self.helpAction.setIcon(QIcon(str(BASE_DIR / "assets" / "icons" / names[2])))
626+
self.helpAction.setIcon(icon_from_resource("icons", names[2]))
628627
self.helpAction.setStatusTip("Ask for help...")
629628
self.helpAction.triggered.connect(self._ask_for_help)
630629

0 commit comments

Comments
 (0)