[help dialog] new dialog for docu
This commit is contained in:
parent
65e147c48b
commit
6fbd958eec
65
nixview/ui/helpdialog.py
Normal file
65
nixview/ui/helpdialog.py
Normal file
@ -0,0 +1,65 @@
|
||||
import os
|
||||
from PyQt5.QtGui import QIcon
|
||||
from PyQt5.QtWidgets import QDialog, QDialogButtonBox, QFrame, QHBoxLayout, QPushButton, QSizePolicy, QTextBrowser, QVBoxLayout, QWidget
|
||||
from PyQt5.QtCore import QUrl
|
||||
|
||||
import nixview.constants as cnst
|
||||
|
||||
class HelpDialog(QDialog):
|
||||
|
||||
def __init__(self, parent = None) -> None:
|
||||
super().__init__(parent=parent)
|
||||
|
||||
self.setModal(True)
|
||||
self.setMinimumSize(500, 750)
|
||||
|
||||
self.help = HelpBrowser()
|
||||
|
||||
self.help._edit.historyChanged.connect(self._on_history_changed)
|
||||
|
||||
self.back_btn = QPushButton(QIcon(os.path.join(cnst.ICONS_FOLDER, "back_btn")), "back")
|
||||
self.back_btn.setEnabled(False)
|
||||
self.back_btn.clicked.connect(self.help._edit.backward)
|
||||
self.home_btn = QPushButton(QIcon(os.path.join(cnst.ICONS_FOLDER, "home_btn")),"home")
|
||||
self.home_btn.clicked.connect(self.help._edit.home)
|
||||
self.fwd_btn = QPushButton(QIcon(os.path.join(cnst.ICONS_FOLDER, "fwd_btn")),"forward")
|
||||
self.fwd_btn.setEnabled(False)
|
||||
self.fwd_btn.clicked.connect(self.help._edit.forward)
|
||||
|
||||
empty = QWidget()
|
||||
empty.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Preferred)
|
||||
|
||||
hbox = QHBoxLayout()
|
||||
hbox.addWidget(self.back_btn)
|
||||
hbox.addWidget(self.home_btn)
|
||||
hbox.addWidget(self.fwd_btn)
|
||||
hbox.addWidget(empty)
|
||||
|
||||
bbox = QDialogButtonBox(QDialogButtonBox.StandardButton.Ok)
|
||||
bbox.accepted.connect(self.accept)
|
||||
layout = QVBoxLayout()
|
||||
|
||||
layout.addLayout(hbox)
|
||||
layout.addWidget(self.help)
|
||||
layout.addWidget(bbox)
|
||||
self.setLayout(layout)
|
||||
|
||||
def _on_history_changed(self):
|
||||
self.back_btn.setEnabled(self.help._edit.isBackwardAvailable())
|
||||
self.fwd_btn.setEnabled(self.help._edit.isForwardAvailable())
|
||||
|
||||
|
||||
class HelpBrowser(QWidget):
|
||||
def __init__(self, parent=None) -> None:
|
||||
super().__init__(parent=parent)
|
||||
self.setLayout(QVBoxLayout())
|
||||
|
||||
doc_url = QUrl.fromLocalFile(cnst.DOCS_ROOT_FILE)
|
||||
self._edit = QTextBrowser()
|
||||
self._edit.setOpenLinks(True)
|
||||
self._edit.setOpenExternalLinks(True)
|
||||
self._edit.setSource(doc_url)
|
||||
self._edit.setEnabled(True)
|
||||
self._edit.setFrameShape(QFrame.NoFrame)
|
||||
|
||||
self.layout().addWidget(self._edit)
|
@ -9,6 +9,7 @@ import nixview.constants as cnst
|
||||
import nixview.communicator as comm
|
||||
from nixview.ui.central_widget import CentralWidget
|
||||
from nixview.ui.about import AboutDialog
|
||||
from nixview.ui.helpdialog import HelpDialog
|
||||
|
||||
|
||||
class NixView(QMainWindow):
|
||||
@ -42,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, "nix_open.png")), "Open", self)
|
||||
self._file_open_action = QAction(QIcon(os.path.join(cnst.ICONS_FOLDER, "nixview_open.png")), "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, "nix_close.png")), "Close", self)
|
||||
self._file_close_action = QAction(QIcon(os.path.join(cnst.ICONS_FOLDER, "nixview_close.png")), "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, "quit.png")), "Quit", self)
|
||||
self._quit_action = QAction(QIcon(os.path.join(cnst.ICONS_FOLDER, "nix_quit.png")), "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_plot.png")), "Plot", self)
|
||||
self._plot_action = QAction(QIcon(os.path.join(cnst.ICONS_FOLDER, "nix_data_array.png")), "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_table.png")), "Show table", self)
|
||||
self._table_action = QAction(QIcon(os.path.join(cnst.ICONS_FOLDER, "nix_data_frame.png")), "Show table", self)
|
||||
self._table_action.setStatusTip("Show data as table")
|
||||
self._table_action.setShortcut(QKeySequence("Ctrl+t"))
|
||||
self._table_action.setEnabled(False)
|
||||
@ -75,6 +76,13 @@ 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.setStatusTip("Show help dialog")
|
||||
self._table_action.setShortcut(QKeySequence("F1"))
|
||||
|
||||
self._help_action.setEnabled(True)
|
||||
self._help_action.triggered.connect(self.on_help)
|
||||
|
||||
self.create_toolbar()
|
||||
self.create_menu()
|
||||
|
||||
@ -89,6 +97,7 @@ class NixView(QMainWindow):
|
||||
self._toolbar.addSeparator()
|
||||
self._toolbar.addAction(self._plot_action)
|
||||
self._toolbar.addAction(self._table_action)
|
||||
self._toolbar.addAction(self._help_action)
|
||||
|
||||
empty = QWidget()
|
||||
empty.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Expanding)
|
||||
@ -112,6 +121,7 @@ class NixView(QMainWindow):
|
||||
|
||||
help_menu = menu.addMenu("&Help")
|
||||
help_menu.addAction(self._about_action)
|
||||
help_menu.addAction(self._help_action)
|
||||
self.setMenuBar(menu)
|
||||
|
||||
def _update_recent_files(self, filename):
|
||||
@ -159,4 +169,8 @@ class NixView(QMainWindow):
|
||||
|
||||
def on_about(self, e):
|
||||
about = AboutDialog(self)
|
||||
about.show()
|
||||
|
||||
def on_help(self, e):
|
||||
about = HelpDialog(self)
|
||||
about.show()
|
Loading…
Reference in New Issue
Block a user