[app] make icon loading platform independent

This commit is contained in:
Jan Grewe 2021-01-09 12:14:12 +01:00
parent c5336de226
commit f3b13999e4
3 changed files with 21 additions and 18 deletions

View File

@ -196,7 +196,7 @@ class SplashScreen(QWidget):
self.setLayout(layout) self.setLayout(layout)
label = QLabel() label = QLabel()
label.setPixmap(QPixmap("./icons/nixview_transparent.png")) label.setPixmap(QPixmap(os.path.join(cnst.ICONS_FOLDER, "nixview_transparent.png")))
label.setMaximumWidth(300) label.setMaximumWidth(300)
label.setAlignment(Qt.AlignCenter) label.setAlignment(Qt.AlignCenter)
layout.addWidget(label, 1, 1, 1, 3, Qt.AlignCenter) layout.addWidget(label, 1, 1, 1, 3, Qt.AlignCenter)

View File

@ -1,3 +1,4 @@
import os
import sys import sys
from PyQt5.QtWidgets import QWidget, QFileDialog, QMainWindow, QMenuBar, QToolBar, QAction, QStatusBar, QSizePolicy from PyQt5.QtWidgets import QWidget, QFileDialog, QMainWindow, QMenuBar, QToolBar, QAction, QStatusBar, QSizePolicy
from PyQt5.QtGui import QIcon, QKeySequence from PyQt5.QtGui import QIcon, QKeySequence
@ -15,7 +16,7 @@ class NixView(QMainWindow):
super(NixView, self).__init__(*args, **kwargs) super(NixView, self).__init__(*args, **kwargs)
self._current_item = None self._current_item = None
self.setWindowTitle("NixView") self.setWindowTitle("NixView")
self.setWindowIcon(QIcon('./icons/nixview.icns')) self.setWindowIcon(QIcon(os.path.join(cnst.ICONS_FOLDER, 'nixview.icns')))
self._file_handler = FileHandler() self._file_handler = FileHandler()
self.setStatusBar(QStatusBar(self)) self.setStatusBar(QStatusBar(self))
@ -40,29 +41,29 @@ class NixView(QMainWindow):
self._table_action.setEnabled(enable) self._table_action.setEnabled(enable)
def create_actions(self): def create_actions(self):
self._file_open_action = QAction(QIcon("./icons/nix_open.png"), "Open", self) self._file_open_action = QAction(QIcon(os.path.join(cnst.ICONS_FOLDER, "nix_open.png")), "Open", self)
self._file_open_action.setStatusTip("Open nix file") self._file_open_action.setStatusTip("Open nix file")
self._file_open_action.setShortcut(QKeySequence("Ctrl+o")) self._file_open_action.setShortcut(QKeySequence("Ctrl+o"))
self._file_open_action.triggered.connect(self.on_file_open) self._file_open_action.triggered.connect(self.on_file_open)
self._file_close_action = QAction(QIcon("./icons/nix_close.png"), "Close", self) self._file_close_action = QAction(QIcon(os.path.join(cnst.ICONS_FOLDER, "nix_close.png")), "Close", self)
self._file_close_action.setStatusTip("Close current nix file") self._file_close_action.setStatusTip("Close current nix file")
self._file_close_action.setShortcut(QKeySequence("Ctrl+w")) self._file_close_action.setShortcut(QKeySequence("Ctrl+w"))
self._file_close_action.setEnabled(False) self._file_close_action.setEnabled(False)
self._file_close_action.triggered.connect(self.on_file_close) self._file_close_action.triggered.connect(self.on_file_close)
self._quit_action = QAction(QIcon("./icons/quit.png"), "Quit", self) self._quit_action = QAction(QIcon(os.path.join(cnst.ICONS_FOLDER, "quit.png")), "Quit", self)
self._quit_action.setStatusTip("Close current file and quit") self._quit_action.setStatusTip("Close current file and quit")
self._quit_action.setShortcut(QKeySequence("Ctrl+q")) self._quit_action.setShortcut(QKeySequence("Ctrl+q"))
self._quit_action.triggered.connect(self.on_quit) self._quit_action.triggered.connect(self.on_quit)
self._plot_action = QAction(QIcon("./icons/nix_plot.png"), "Plot", self) self._plot_action = QAction(QIcon(os.path.join(cnst.ICONS_FOLDER, "nix_plot.png")), "Plot", self)
self._plot_action.setStatusTip("Plot currently selected entity") self._plot_action.setStatusTip("Plot currently selected entity")
self._plot_action.setShortcut(QKeySequence("Ctrl+p")) self._plot_action.setShortcut(QKeySequence("Ctrl+p"))
self._plot_action.setEnabled(False) self._plot_action.setEnabled(False)
self._plot_action.triggered.connect(self.on_item_plot) self._plot_action.triggered.connect(self.on_item_plot)
self._table_action = QAction(QIcon("./icons/nix_table.png"), "Show table", self) self._table_action = QAction(QIcon(os.path.join(cnst.ICONS_FOLDER, "nix_table.png")), "Show table", self)
self._table_action.setStatusTip("Show data as table") self._table_action.setStatusTip("Show data as table")
self._table_action.setShortcut(QKeySequence("Ctrl+t")) self._table_action.setShortcut(QKeySequence("Ctrl+t"))
self._table_action.setEnabled(False) self._table_action.setEnabled(False)

View File

@ -1,3 +1,5 @@
import os
import nixview.constants as cnst
from PyQt5.QtCore import QAbstractItemModel, QModelIndex, Qt, QSize from PyQt5.QtCore import QAbstractItemModel, QModelIndex, Qt, QSize
from PyQt5.QtGui import QIcon from PyQt5.QtGui import QIcon
from PyQt5.QtWidgets import QTreeView, QTreeWidgetItem, QAbstractItemView, QHeaderView from PyQt5.QtWidgets import QTreeView, QTreeWidgetItem, QAbstractItemView, QHeaderView
@ -261,17 +263,17 @@ class TreeModel(QAbstractItemModel):
def __init__(self, file_handler, tree_type=TreeType.Full, parent=None, root_section_id=None): def __init__(self, file_handler, tree_type=TreeType.Full, parent=None, root_section_id=None):
super(TreeModel, self).__init__(parent) super(TreeModel, self).__init__(parent)
nd = ItemDescriptor(file_handler.filename, type="Root item") nd = ItemDescriptor(file_handler.filename, type="Root item")
self.type_icons = {NodeType.Block: QIcon("./icons/nix_block_1d.png"), self.type_icons = {NodeType.Block: QIcon(os.path.join(cnst.ICONS_FOLDER, "nix_block_1d.png")),
NodeType.Source: QIcon("./icons/nix_source.png"), NodeType.Source: QIcon(os.path.join(cnst.ICONS_FOLDER, "nix_source.png")),
NodeType.DataArray: QIcon("./icons/nix_data_array.png"), NodeType.DataArray: QIcon(os.path.join(cnst.ICONS_FOLDER, "nix_data_array.png")),
NodeType.Dimension: QIcon("./icons/nix_dimension.png"), NodeType.Dimension: QIcon(os.path.join(cnst.ICONS_FOLDER, "nix_dimension.png")),
NodeType.DataFrame: QIcon("./icons/nix_data_frame.png"), NodeType.DataFrame: QIcon(os.path.join(cnst.ICONS_FOLDER, "nix_data_frame.png")),
NodeType.Section: QIcon("./icons/nix_section.png"), NodeType.Section: QIcon(os.path.join(cnst.ICONS_FOLDER, "nix_section.png")),
NodeType.Property: QIcon("./icons/nix_property.png"), NodeType.Property: QIcon(os.path.join(cnst.ICONS_FOLDER, "nix_property.png")),
NodeType.Tag: QIcon("./icons/nix_tag.png"), NodeType.Tag: QIcon(os.path.join(cnst.ICONS_FOLDER, "nix_tag.png")),
NodeType.MultiTag: QIcon("./icons/nix_tag.png"), NodeType.MultiTag: QIcon(os.path.join(cnst.ICONS_FOLDER, "nix_tag.png")),
NodeType.Group: QIcon("./icons/nix_group.png"), NodeType.Group: QIcon(os.path.join(cnst.ICONS_FOLDER, "icons/nix_group.png")),
NodeType.Feature: QIcon("./icons/nix_feature.png")} NodeType.Feature: QIcon(os.path.join(cnst.ICONS_FOLDER, "nix_feature.png"))}
if tree_type == TreeType.Full: if tree_type == TreeType.Full:
self.root_item = FileTreeItem(nd, file_handler, parent=None) self.root_item = FileTreeItem(nd, file_handler, parent=None)