From 094ecb3ca3f75445a009bfd5032eafa7ddce68e3 Mon Sep 17 00:00:00 2001 From: Pierre-Antoine Rouby Date: Thu, 27 Apr 2023 15:53:55 +0200 Subject: [PATCH] network: Change network window to mainwindow. --- src/View/ASubWindow.py | 129 ++++++--- src/View/Network/NetworkWindow.py | 22 +- src/View/ui/Network.ui | 446 ++++++++++++++---------------- 3 files changed, 321 insertions(+), 276 deletions(-) diff --git a/src/View/ASubWindow.py b/src/View/ASubWindow.py index 9dd04f12..3e1a138f 100644 --- a/src/View/ASubWindow.py +++ b/src/View/ASubWindow.py @@ -5,6 +5,8 @@ import csv from io import StringIO +from tools import trace + from PyQt5.QtCore import Qt from PyQt5.QtWidgets import ( @@ -13,7 +15,7 @@ from PyQt5.QtWidgets import ( QPushButton, QLineEdit, QCheckBox, QTimeEdit, QSpinBox, QTextEdit, QRadioButton, QComboBox, QFileDialog, - QMessageBox, QTableView, + QMessageBox, QTableView, QAction, ) from PyQt5.QtCore import ( QTime, @@ -101,26 +103,9 @@ class WindowToolKit(object): msg.exec_() -class ASubWindow(QDialog, WindowToolKit): - def __init__(self, name="", ui="dummy", parent=None): - super(ASubWindow, self).__init__(parent=parent) - self.ui = loadUi( - os.path.join(os.path.dirname(__file__), "ui", f"{ui}.ui"), - self - ) - self.name = name - self.parent = parent - self.parent.sub_win_add(name, self) - # self.fixed_size() - - def fixed_size(self): - width = self.frameGeometry().width() - height = self.frameGeometry().height() - self.setFixedSize(width, height) - - def closeEvent(self, event): - if not self.parent is None: - self.parent.sub_win_del(self.name) +class ASubWindowFeatures(object): + def __init__(self, parent=None): + super(ASubWindowFeatures, self).__init__() # Commun use features @@ -140,21 +125,6 @@ class ASubWindow(QDialog, WindowToolKit): return qtype - def find(self, qtype, name): - """Find an ui component - - Args: - qtype: Type of QT component - name: Name for component - - Returns: - return the component - """ - if qtype is None: - qtype = self._qtype_from_component_name(name) - - return self.ui.findChild(qtype, name) - def set_line_edit_text(self, name:str, text:str): """Set text of line edit component @@ -275,6 +245,30 @@ class ASubWindow(QDialog, WindowToolKit): """ return self.find(QSpinBox, name).value() + def set_action_checkable(self, name:str, checked:bool): + """Set value of action + + Args: + name: The action component name + value: The new value + + Returns: + Nothing + """ + self.find(QAction, name).setChecked(checked) + + def get_action_checkable(self, name:str): + """Get status of action + + Args: + name: The action component name + + Returns: + The status of action + """ + return self.find(QAction, name).isChecked() + + def set_push_button_checkable(self, name:str, checked:bool): """Set value of push button component @@ -355,3 +349,66 @@ class ASubWindow(QDialog, WindowToolKit): Current text """ return self.find(QComboBox, name).currentText() + +# Top level interface + +class ASubMainWindow(QMainWindow, ASubWindowFeatures, WindowToolKit): + def __init__(self, name="", ui="dummy", parent=None): + super(ASubMainWindow, self).__init__(parent=parent) + self.ui = loadUi( + os.path.join(os.path.dirname(__file__), "ui", f"{ui}.ui"), + self + ) + self.name = name + self.parent = parent + self.parent.sub_win_add(name, self) + + def closeEvent(self, event): + if not self.parent is None: + self.parent.sub_win_del(self.name) + + def find(self, qtype, name): + """Find an ui component + + Args: + qtype: Type of QT component + name: Name for component + + Returns: + return the component + """ + if qtype is None: + qtype = self._qtype_from_component_name(name) + + return self.ui.findChild(qtype, name) + + +class ASubWindow(QDialog, ASubWindowFeatures, WindowToolKit): + def __init__(self, name="", ui="dummy", parent=None): + super(ASubWindow, self).__init__(parent=parent) + self.ui = loadUi( + os.path.join(os.path.dirname(__file__), "ui", f"{ui}.ui"), + self + ) + self.name = name + self.parent = parent + self.parent.sub_win_add(name, self) + + def closeEvent(self, event): + if not self.parent is None: + self.parent.sub_win_del(self.name) + + def find(self, qtype, name): + """Find an ui component + + Args: + qtype: Type of QT component + name: Name for component + + Returns: + return the component + """ + if qtype is None: + qtype = self._qtype_from_component_name(name) + + return self.ui.findChild(qtype, name) diff --git a/src/View/Network/NetworkWindow.py b/src/View/Network/NetworkWindow.py index d2a7aa36..b3b22cdf 100644 --- a/src/View/Network/NetworkWindow.py +++ b/src/View/Network/NetworkWindow.py @@ -2,7 +2,7 @@ from Model.River import RiverNode, RiverReach, River -from View.ASubWindow import ASubWindow +from View.ASubWindow import ASubMainWindow from View.Network.GraphWidget import GraphWidget from View.Network.TableModel import ( GraphTableModel, ComboBoxDelegate, TrueFalseComboBoxDelegate, @@ -16,10 +16,10 @@ from PyQt5.QtCore import ( from PyQt5.QtWidgets import ( QTableView, QItemDelegate, QComboBox, QLineEdit, QHBoxLayout, QSlider, QPushButton, QCheckBox, QStyledItemDelegate, QStyleOptionButton, QStyle, - QApplication, + QApplication, QToolBar, QAction, ) -class NetworkWindow(ASubWindow): +class NetworkWindow(ASubMainWindow): def __init__(self, model=None, title="River network", parent=None): super(NetworkWindow, self).__init__(name=title, ui="Network", parent=parent) self.ui.setWindowTitle(title) @@ -79,26 +79,30 @@ class NetworkWindow(ASubWindow): self.graph_widget.changeEdge.connect(self.reachs_model.update) self.graph_widget.changeNode.connect(self.nodes_model.update) - self.find(QPushButton, "pushButton_add").clicked.connect( + self.find(QAction, "action_toolBar_add").setCheckable(True) + self.find(QAction, "action_toolBar_add").triggered.connect( self.clicked_add ) - self.find(QPushButton, "pushButton_del").clicked.connect( + + self.find(QAction, "action_toolBar_del").setCheckable(True) + self.find(QAction, "action_toolBar_del").triggered.connect( self.clicked_del ) + self.find(QPushButton, "pushButton_reverse").clicked.connect( self.reverse_edge ) def clicked_add(self): - if self.get_push_button_checkable("pushButton_add"): - self.set_push_button_checkable("pushButton_del", False) + if self.get_action_checkable("action_toolBar_add"): + self.set_action_checkable("action_toolBar_del", False) self.graph_widget.state("add") else: self.graph_widget.state("move") def clicked_del(self): - if self.get_push_button_checkable("pushButton_del"): - self.set_push_button_checkable("pushButton_add", False) + if self.get_action_checkable("action_toolBar_del"): + self.set_action_checkable("action_toolBar_add", False) self.graph_widget.state("del") else: self.graph_widget.state("move") diff --git a/src/View/ui/Network.ui b/src/View/ui/Network.ui index 202fc2fa..134ce153 100644 --- a/src/View/ui/Network.ui +++ b/src/View/ui/Network.ui @@ -1,246 +1,230 @@ - Dialog - + MainWindow + 0 0 990 - 690 + 600 - Dialog + MainWindow - - false - - - - QLayout::SetDefaultConstraint + + + + + + + + + + + + + + + + + + + + + ressources/gtk-sort-descending.pngressources/gtk-sort-descending.png + + + + + + + + + + + ressources/go-up2.pngressources/go-up2.png + + + + + + + + + + + ressources/go-down1.pngressources/go-down1.png + + + + + + + Reverse + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + + + + 650 + 150 + + + + + 16777215 + 200 + + + + + + + + + + + + + + + + + + ressources/gtk-sort-descending.pngressources/gtk-sort-descending.png + + + + + + + + + + + ressources/go-up2.pngressources/go-up2.png + + + + + + + + + + + ressources/go-down1.pngressources/go-down1.png + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + + + + 0 + 150 + + + + + 16777215 + 200 + + + + + + + + + + + + 0 + 0 + 990 + 22 + - - - - - - - - - 40 - 16777215 - - - - - - - - ressources/gtk_add.pngressources/gtk_add.png - - - true - - - false - - - false - - - false - - - - - - - - 40 - 16777215 - - - - - - - - ressources/gtk-remove.pngressources/gtk-remove.png - - - true - - - - - - - Qt::Vertical - - - - 20 - 40 - - - - - - - - - - - - - - - - - - - - - - - ressources/gtk-sort-descending.pngressources/gtk-sort-descending.png - - - - - - - - - - - ressources/go-up2.pngressources/go-up2.png - - - - - - - - - - - ressources/go-down1.pngressources/go-down1.png - - - - - - - Reverse - - - - - - - Qt::Horizontal - - - - 40 - 20 - - - - - - - - - - - 650 - 150 - - - - - 16777215 - 200 - - - - - - - - - - - - - - - - - - ressources/gtk-sort-descending.pngressources/gtk-sort-descending.png - - - - - - - - - - - ressources/go-up2.pngressources/go-up2.png - - - - - - - - - - - ressources/go-down1.pngressources/go-down1.png - - - - - - - Qt::Horizontal - - - - 40 - 20 - - - - - - - - - - - 0 - 150 - - - - - 16777215 - 200 - - - - - - - + + + + + true + + + toolBar + + + Qt::Horizontal + + + TopToolBarArea + + + false + + + + + + + + ressources/gtk-add.pngressources/gtk-add.png + + + Add node or edge + + + Add node or edge + + + + + + ressources/gtk-remove.pngressources/gtk-remove.png + + + Remove node or edge + + + Remove node or edge + +