From 22ce6c9c66105c5bb1ef20f3c3b840c36b8abcf2 Mon Sep 17 00:00:00 2001 From: Oscar Gustafsson <oscar.gustafsson@gmail.com> Date: Wed, 15 Feb 2023 11:57:39 +0100 Subject: [PATCH] Move about window and use in scheduler GUI as well --- b_asic/GUI/main_window.py | 3 +- .../GUI/{about_window.py => util_dialogs.py} | 104 +---------------- b_asic/gui_utils/about_window.py | 108 ++++++++++++++++++ b_asic/scheduler_gui/main_window.py | 6 + docs_sphinx/GUI.rst | 22 ++-- 5 files changed, 129 insertions(+), 114 deletions(-) rename b_asic/GUI/{about_window.py => util_dialogs.py} (61%) create mode 100644 b_asic/gui_utils/about_window.py diff --git a/b_asic/GUI/main_window.py b/b_asic/GUI/main_window.py index 16c80708..34cd0d34 100644 --- a/b_asic/GUI/main_window.py +++ b/b_asic/GUI/main_window.py @@ -30,14 +30,15 @@ from qtpy.QtWidgets import ( import b_asic.core_operations import b_asic.special_operations from b_asic.GUI._preferences import GAP, GRID, MINBUTTONSIZE, PORTHEIGHT -from b_asic.GUI.about_window import AboutWindow, FaqWindow, KeybindsWindow from b_asic.GUI.arrow import Arrow from b_asic.GUI.drag_button import DragButton from b_asic.GUI.gui_interface import Ui_main_window from b_asic.GUI.select_sfg_window import SelectSFGWindow from b_asic.GUI.show_pc_window import ShowPCWindow from b_asic.GUI.simulate_sfg_window import Plot, SimulateSFGWindow +from b_asic.GUI.util_dialogs import FaqWindow, KeybindsWindow from b_asic.GUI.utils import decorate_class, handle_error +from b_asic.gui_utils.about_window import AboutWindow from b_asic.port import OutputPort from b_asic.save_load_structure import python_to_sfg, sfg_to_python from b_asic.signal_flow_graph import SFG diff --git a/b_asic/GUI/about_window.py b/b_asic/GUI/util_dialogs.py similarity index 61% rename from b_asic/GUI/about_window.py rename to b_asic/GUI/util_dialogs.py index 6252c7d0..e5a8d3f3 100644 --- a/b_asic/GUI/about_window.py +++ b/b_asic/GUI/util_dialogs.py @@ -1,22 +1,14 @@ -import sys # ONLY FOR DEBUG - from qtpy.QtCore import Qt -from qtpy.QtGui import QCursor, QPixmap -from qtpy.QtWidgets import QApplication # ONLY FOR DEBUG from qtpy.QtWidgets import ( QDialog, QFrame, QHBoxLayout, QLabel, - QPushButton, QScrollArea, - QToolTip, QVBoxLayout, ) -from b_asic._version import __version__ - -QUESTIONS = { +_QUESTIONS = { "Adding operations": ( "Select an operation under 'Special operations' or 'Core operations' " "to add it to the workspace." @@ -115,84 +107,6 @@ class KeybindsWindow(QDialog): self.dialog_layout.addWidget(keybinds_label) -class AboutWindow(QDialog): - def __init__(self, window): - super().__init__() - self._window = window - self.setWindowFlags(Qt.WindowTitleHint | Qt.WindowCloseButtonHint) - self.setWindowTitle("About B-ASIC") - - self.dialog_layout = QVBoxLayout() - self.setLayout(self.dialog_layout) - - self.add_information_to_layout() - - def hoverText(self, url): - # self.setWindowTitle(url) # When removing mouse, the title gets "B-ASIC Scheduler". Where does THAT come from? - if url: - QToolTip.showText(QCursor.pos(), url) - else: - QToolTip.hideText() - - def add_information_to_layout(self): - # |1 Title |2 | - # | License | Logo | <- layout12 - # | Version | | - # ---------------------- - # |3 links |4 OK | <- layout34 - - label1 = QLabel( - "# B-ASIC / Better ASIC Toolbox\n*Construct, simulate and analyze" - " components of an ASIC.*\n\nB-ASIC is an open source tool using" - " the B-ASIC library to construct, simulate and analyze" - " ASICs.\n\nB-ASIC is developed under the MIT-license and any" - " extension to the program should follow that same license.\n\nTo" - " read more about how the GUI works please refer to the FAQ under" - f" 'Help'.\n\n*Version: {__version__}*" - ) - label1.setTextFormat(Qt.MarkdownText) - label1.setWordWrap(True) - label1.setOpenExternalLinks(True) - label1.linkHovered.connect(self.hoverText) - - self.logo2 = QLabel(self) - self.logo2.setPixmap( - QPixmap("../../small_logo.png").scaledToWidth(100) - ) - self.logo2.setFixedWidth(100) - - label3 = QLabel( - """See: <a href="https://da.gitlab-pages.liu.se/B-ASIC/">documentation</a>,""" - """ <a href="https://gitlab.liu.se/da/B-ASIC/">git</a>,""" - """ <a href="https://www.liu.se/?l=en">liu.se</a>,""" - """ <a href="https://liu.se/organisation/liu/isy/da">Computer Engineering</a>.""" - ) - label3.setOpenExternalLinks(True) - label3.linkHovered.connect(self.hoverText) - - button4 = QPushButton() - button4.setText("OK") - button4.setFixedWidth(80) - button4.clicked.connect(self.close) - - layout12 = QHBoxLayout() - layout34 = QHBoxLayout() - - layout12.addWidget(label1) - layout12.addWidget(self.logo2) - - layout34.addWidget(label3) - layout34.addWidget(button4) - - hline = QFrame() - hline.setFrameShape(QFrame.HLine) - hline.setFrameShadow(QFrame.Sunken) - - self.dialog_layout.addLayout(layout12) - self.dialog_layout.addWidget(hline) - self.dialog_layout.addLayout(layout34) - - class FaqWindow(QDialog): def __init__(self, window): super().__init__() @@ -203,7 +117,7 @@ class FaqWindow(QDialog): self.dialog_layout = QVBoxLayout() self.scroll_area = QScrollArea() self.setLayout(self.dialog_layout) - for question, answer in QUESTIONS.items(): + for question, answer in _QUESTIONS.items(): self.add_question_to_layout(question, answer) self.scroll_area.setWidget(self) @@ -226,17 +140,3 @@ class FaqWindow(QDialog): question_layout.addLayout(answer_layout) self.dialog_layout.addLayout(question_layout) - - -# ONLY FOR DEBUG below - - -def start_about_window(): - app = QApplication(sys.argv) - window = AboutWindow(QDialog) - window.show() - sys.exit(app.exec_()) - - -if __name__ == "__main__": - start_about_window() diff --git a/b_asic/gui_utils/about_window.py b/b_asic/gui_utils/about_window.py new file mode 100644 index 00000000..03e80415 --- /dev/null +++ b/b_asic/gui_utils/about_window.py @@ -0,0 +1,108 @@ +import sys # ONLY FOR DEBUG + +from qtpy.QtCore import Qt +from qtpy.QtGui import QCursor, QPixmap +from qtpy.QtWidgets import QApplication # ONLY FOR DEBUG +from qtpy.QtWidgets import ( + QDialog, + QFrame, + QHBoxLayout, + QLabel, + QPushButton, + QToolTip, + QVBoxLayout, +) + +from b_asic._version import __version__ + + +class AboutWindow(QDialog): + def __init__(self, window): + super().__init__() + self._window = window + self.setWindowFlags(Qt.WindowTitleHint | Qt.WindowCloseButtonHint) + self.setWindowTitle("About B-ASIC") + + self.dialog_layout = QVBoxLayout() + self.setLayout(self.dialog_layout) + + self.add_information_to_layout() + + def hoverText(self, url): + # self.setWindowTitle(url) # When removing mouse, the title gets "B-ASIC Scheduler". Where does THAT come from? + if url: + QToolTip.showText(QCursor.pos(), url) + else: + QToolTip.hideText() + + def add_information_to_layout(self): + # |1 Title |2 | + # | License | Logo | <- layout12 + # | Version | | + # ---------------------- + # |3 links |4 OK | <- layout34 + + label1 = QLabel( + "# B-ASIC / Better ASIC Toolbox\n*Construct, simulate and analyze" + " components of an ASIC.*\n\nB-ASIC is an open source tool using" + " the B-ASIC library to construct, simulate and analyze" + " ASICs.\n\nB-ASIC is developed under the MIT-license and any" + " extension to the program should follow that same license.\n\nTo" + " read more about how the GUI works please refer to the FAQ under" + f" 'Help'.\n\n*Version: {__version__}*" + ) + label1.setTextFormat(Qt.MarkdownText) + label1.setWordWrap(True) + label1.setOpenExternalLinks(True) + label1.linkHovered.connect(self.hoverText) + + self.logo2 = QLabel(self) + self.logo2.setPixmap( + QPixmap("../../small_logo.png").scaledToWidth(100) + ) + self.logo2.setFixedWidth(100) + + label3 = QLabel( + """See: <a href="https://da.gitlab-pages.liu.se/B-ASIC/">documentation</a>,""" + """ <a href="https://gitlab.liu.se/da/B-ASIC/">git</a>,""" + """ <a href="https://www.liu.se/?l=en">liu.se</a>,""" + """ <a href="https://liu.se/organisation/liu/isy/da">Computer Engineering</a>.""" + ) + label3.setOpenExternalLinks(True) + label3.linkHovered.connect(self.hoverText) + + button4 = QPushButton() + button4.setText("OK") + button4.setFixedWidth(80) + button4.clicked.connect(self.close) + + layout12 = QHBoxLayout() + layout34 = QHBoxLayout() + + layout12.addWidget(label1) + layout12.addWidget(self.logo2) + + layout34.addWidget(label3) + layout34.addWidget(button4) + + hline = QFrame() + hline.setFrameShape(QFrame.HLine) + hline.setFrameShadow(QFrame.Sunken) + + self.dialog_layout.addLayout(layout12) + self.dialog_layout.addWidget(hline) + self.dialog_layout.addLayout(layout34) + + +# ONLY FOR DEBUG below + + +def start_about_window(): + app = QApplication(sys.argv) + window = AboutWindow(QDialog) + window.show() + sys.exit(app.exec_()) + + +if __name__ == "__main__": + start_about_window() diff --git a/b_asic/scheduler_gui/main_window.py b/b_asic/scheduler_gui/main_window.py index ed8fca68..97a70d96 100644 --- a/b_asic/scheduler_gui/main_window.py +++ b/b_asic/scheduler_gui/main_window.py @@ -46,6 +46,7 @@ from qtpy.QtWidgets import ( import b_asic.scheduler_gui.logger as logger from b_asic._version import __version__ from b_asic.graph_component import GraphComponent, GraphID +from b_asic.gui_utils.about_window import AboutWindow from b_asic.schedule import Schedule from b_asic.scheduler_gui.axes_item import AxesItem from b_asic.scheduler_gui.operation_item import OperationItem @@ -133,6 +134,7 @@ class MainWindow(QMainWindow, Ui_MainWindow): self.actionT.triggered.connect(self._actionTbtn) self.splitter.splitterMoved.connect(self._splitter_moved) self.actionDocumentation.triggered.connect(self._open_documentation) + self.actionAbout.triggered.connect(self._open_about_window) # Setup event member functions self.closeEvent = self._close_event @@ -461,6 +463,10 @@ class MainWindow(QMainWindow, Ui_MainWindow): else: event.ignore() + def _open_about_window(self, event=None): + self.about_page = AboutWindow(self) + self.about_page.show() + ########################### # Helper member functions # ########################### diff --git a/docs_sphinx/GUI.rst b/docs_sphinx/GUI.rst index a8a9bee0..bbe6459b 100644 --- a/docs_sphinx/GUI.rst +++ b/docs_sphinx/GUI.rst @@ -12,10 +12,10 @@ Module contents Submodules ---------- -GUI.about\_window module ------------------------- +GUI.main\_window module +----------------------- -.. automodule:: b_asic.GUI.about_window +.. automodule:: b_asic.GUI.main_window :members: :undoc-members: :show-inheritance: @@ -44,14 +44,6 @@ GUI.gui\_interface module :undoc-members: :show-inheritance: -GUI.main\_window module ------------------------ - -.. automodule:: b_asic.GUI.main_window - :members: - :undoc-members: - :show-inheritance: - GUI.port\_button module ----------------------- @@ -92,6 +84,14 @@ GUI.simulate\_sfg\_window module :undoc-members: :show-inheritance: +GUI.util\_dialogs module +------------------------ + +.. automodule:: b_asic.GUI.util_dialogs + :members: + :undoc-members: + :show-inheritance: + GUI.utils module ---------------- -- GitLab