diff --git a/icons/nix_help.png b/icons/nixview_help.png similarity index 100% rename from icons/nix_help.png rename to icons/nixview_help.png diff --git a/nixview/constants.py b/nixview/constants.py index 42e5c75..c8d3023 100644 --- a/nixview/constants.py +++ b/nixview/constants.py @@ -1,4 +1,6 @@ import os +import glob +from PyQt5.QtGui import QIcon organization = "nixio" application = "nixview" @@ -10,3 +12,18 @@ settings_recent_file_max_count = 10 PACKAGE_ROOT = os.path.abspath(os.path.join(os.path.dirname(__file__), os.pardir)) ICONS_FOLDER = os.path.join(PACKAGE_ROOT, "icons") +DOCS_ROOT_FILE = os.path.join(PACKAGE_ROOT, "docs", "index.md") + +ICONS_PATHS = glob.glob(os.path.join(ICONS_FOLDER, "*.png")) +ICONS_PATHS.extend(glob.glob(os.path.join(ICONS_FOLDER, "*.icns"))) +ICONS_PATHS = sorted(ICONS_PATHS) +ICON_DICT = {} +for icon in ICONS_PATHS: + ICON_DICT[icon.split(os.sep)[-1].split(".")[0]] = icon + +def get_icon(name): + if name in ICON_DICT.keys(): + return QIcon(ICON_DICT[name]) + else: + return QIcon("nix_logo.png") + diff --git a/nixview/ui/mainwindow.py b/nixview/ui/mainwindow.py index c0f9351..5a29d40 100644 --- a/nixview/ui/mainwindow.py +++ b/nixview/ui/mainwindow.py @@ -18,7 +18,7 @@ class NixView(QMainWindow): super(NixView, self).__init__(*args, **kwargs) self._current_item = None self.setWindowTitle("NixView") - self.setWindowIcon(QIcon(os.path.join(cnst.ICONS_FOLDER, 'nixview.icns'))) + self.setWindowIcon(cnst.get_icon('nixview')) self._file_handler = FileHandler() self.setStatusBar(QStatusBar(self)) @@ -43,29 +43,29 @@ class NixView(QMainWindow): self._table_action.setEnabled(enable) def create_actions(self): - self._file_open_action = QAction(QIcon(os.path.join(cnst.ICONS_FOLDER, "nixview_open.png")), "Open", self) + self._file_open_action = QAction(cnst.get_icon("nixview_open"), "Open", self) self._file_open_action.setStatusTip("Open nix file") self._file_open_action.setShortcut(QKeySequence("Ctrl+o")) self._file_open_action.triggered.connect(self.on_file_open) - self._file_close_action = QAction(QIcon(os.path.join(cnst.ICONS_FOLDER, "nixview_close.png")), "Close", self) + self._file_close_action = QAction(cnst.get_icon("nixview_close"), "Close", self) self._file_close_action.setStatusTip("Close current nix file") self._file_close_action.setShortcut(QKeySequence("Ctrl+w")) self._file_close_action.setEnabled(False) self._file_close_action.triggered.connect(self.on_file_close) - self._quit_action = QAction(QIcon(os.path.join(cnst.ICONS_FOLDER, "nix_quit.png")), "Quit", self) + self._quit_action = QAction(cnst.get_icon("nixview_quit"), "Quit", self) self._quit_action.setStatusTip("Close current file and quit") self._quit_action.setShortcut(QKeySequence("Ctrl+q")) self._quit_action.triggered.connect(self.on_quit) - self._plot_action = QAction(QIcon(os.path.join(cnst.ICONS_FOLDER, "nix_data_array.png")), "Plot", self) + self._plot_action = QAction(cnst.get_icon("nix_data_array"), "Plot", self) self._plot_action.setStatusTip("Plot currently selected entity") self._plot_action.setShortcut(QKeySequence("Ctrl+p")) self._plot_action.setEnabled(False) self._plot_action.triggered.connect(self.on_item_plot) - self._table_action = QAction(QIcon(os.path.join(cnst.ICONS_FOLDER, "nix_data_frame.png")), "Show table", self) + self._table_action = QAction(cnst.get_icon("nix_data_frame"), "Show table", self) self._table_action.setStatusTip("Show data as table") self._table_action.setShortcut(QKeySequence("Ctrl+t")) self._table_action.setEnabled(False) @@ -76,7 +76,7 @@ class NixView(QMainWindow): self._about_action.setEnabled(True) self._about_action.triggered.connect(self.on_about) - self._help_action = QAction(QIcon(os.path.join(cnst.ICONS_FOLDER, "nix_help.png")), "help") + self._help_action = QAction(cnst.get_icon("nixview_help"), "help") self._help_action.setStatusTip("Show help dialog") self._table_action.setShortcut(QKeySequence("F1")) @@ -165,7 +165,7 @@ class NixView(QMainWindow): def on_item_plot(self, s): if self._current_item is not None: - self._cw.plot_item(self._current_item) + self._cw.plot_item(self._current_item.node_descriptor) def on_about(self, e): about = AboutDialog(self)