fixtracks/fixtracks/mainwindow.py

153 lines
6.1 KiB
Python

from PySide6.QtCore import QSize, Qt
from PySide6.QtWidgets import QMainWindow, QWidget, QToolBar, QSizePolicy, QFileDialog
from PySide6.QtGui import QKeySequence, QAction, QIcon
from fixtracks.widgets.centralwidget import CentralWidget
from fixtracks.dialogs.previewdialog import PreviewDialog
from fixtracks.dialogs.about import AboutDialog
from fixtracks.dialogs.help import HelpDialog
import fixtracks.resources
class MainWindow(QMainWindow):
def __init__(self, darkmode):
super().__init__()
self._iconsuffix = "_dark" if darkmode else "_light"
self._top_toolbar = None
self._side_toolbar = None
self._cw = CentralWidget(darkmode)
self.setCentralWidget(self._cw)
self.create_actions()
# cw.exit_signal.connect(self.exit_request)
def create_actions(self):
# self._file_open_action = QAction(QIcon(":/icons/open" + self._iconsuffix), "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(":/icons/file_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(":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.exit_request)
# self._plot_action = QAction(QIcon(":/icons/show_plot"), "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(":/icons/show_table"), "Show table", self)
# self._table_action.setStatusTip("Show data as table")
# self._table_action.setShortcut(QKeySequence("Ctrl+t"))
# self._table_action.setEnabled(False)
# self._table_action.triggered.connect(self.on_item_show_table)
self._about_action = QAction("about")
self._about_action.setStatusTip("Show about dialog")
self._about_action.setEnabled(True)
self._about_action.triggered.connect(self.on_about)
self._help_action = QAction(QIcon(":help"), "help")
self._help_action.setStatusTip("Show help dialog")
self._help_action.setShortcut(QKeySequence("F1"))
self._help_action.setEnabled(True)
self._help_action.triggered.connect(self.on_help)
self._mergeview_action = QAction("View merge results")
self._mergeview_action.setStatusTip("Show help dialog")
self._mergeview_action.setEnabled(True)
self._mergeview_action.triggered.connect(self.on_mergeview)
self.create_toolbar()
self.create_menu()
def create_menu(self):
menu_bar = self.menuBar()
file_menu = menu_bar.addMenu("&File")
# file_menu.addAction(self._file_close_action)
tools_menu = menu_bar.addMenu("&Tools")
tools_menu.addAction(self._mergeview_action)
help_menu = menu_bar.addMenu("&Help")
help_menu.addAction(self._about_action)
help_menu.addAction(self._help_action)
menus = {"File": file_menu, "Tools": tools_menu}
for k in self._cw.menuActions:
actions = self._cw.menuActions[k]
if k in menus:
menu = menus[k]
else:
menu = menu_bar.addMenu(k)
for a in actions:
menu.addAction(a)
file_menu.addSeparator()
file_menu.addAction(self._quit_action)
self.setMenuBar(menu_bar)
def create_toolbar(self):
self._top_toolbar = QToolBar("My main toolbar")
self._top_toolbar.setAllowedAreas(Qt.ToolBarArea.TopToolBarArea)
self._top_toolbar.setFloatable(False)
self._top_toolbar.setIconSize(QSize(32, 32))
self._side_toolbar = QToolBar("Tools toolbar")
self._side_toolbar.setAllowedAreas(Qt.ToolBarArea.LeftToolBarArea)
self._top_toolbar.setIconSize(QSize(64, 64))
#self._toolbar.setStyleSheet("QToolButton:!hover {background-color:none}")
# self._top_toolbar.addAction(self._file_open_action)
# self._toolbar.addAction(self._file_close_action)
self._top_toolbar.addSeparator()
self._top_toolbar.addAction(self._mergeview_action)
# self._toolbar.addAction(self._plot_action)
# self._toolbar.addAction(self._table_action)
for a in self._cw.toolbarActions:
self._side_toolbar.addAction(a)
self._side_toolbar.addAction(self._help_action)
empty = QWidget()
empty.setSizePolicy(QSizePolicy.Policy.Expanding, QSizePolicy.Policy.Expanding)
self._side_toolbar.addWidget(empty)
self._side_toolbar.addSeparator()
self._side_toolbar.addAction(self._quit_action)
self.addToolBar(Qt.LeftToolBarArea, self._side_toolbar)
# self.addToolBar(Qt.TopToolBarArea, self._top_toolbar)
def on_file_open(self, s):
QFileDialog.getExistingDirectory()
# dlg = QFileDialog(self, 'Open dataset folder data file', '', "NIX files (*.h5 *.nix)")
# dlg.setFileMode(QFileDialog.ExistingFile)
# filenames = None
# if dlg.exec_():
# filenames = dlg.selectedFiles()
# self.open_file(filenames[0])
def on_mergeview(self):
print("Display merging results")
dlg = PreviewDialog(self)
dlg.setModal(True)
dlg.exec()
def on_about(self, s):
about = AboutDialog(self)
about.show()
def on_help(self, s):
help_dlg = HelpDialog(self)
help_dlg.show()
# @Slot(None)
def exit_request(self):
self.close()