diff --git a/src/View/ASubWindow.py b/src/View/ASubWindow.py index 9dd04f123c82ca477681ccabf796aac258dccbb2..3e1a138f4ff633124331c45e949815c728a77932 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 d2a7aa362382fc1541d96f4bffadc53aa0a5e598..b3b22cdfa63395bb706893df215a7aa22aada037 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 202fc2faf924129d66bcbde9995f147ed4c13f70..134ce15317283bebbe33d3d982c3e6de77381e80 100644 --- a/src/View/ui/Network.ui +++ b/src/View/ui/Network.ui @@ -1,246 +1,230 @@ <?xml version="1.0" encoding="UTF-8"?> <ui version="4.0"> - <class>Dialog</class> - <widget class="QDialog" name="Dialog"> + <class>MainWindow</class> + <widget class="QMainWindow" name="MainWindow"> <property name="geometry"> <rect> <x>0</x> <y>0</y> <width>990</width> - <height>690</height> + <height>600</height> </rect> </property> <property name="windowTitle"> - <string>Dialog</string> + <string>MainWindow</string> </property> - <property name="sizeGripEnabled"> - <bool>false</bool> - </property> - <layout class="QGridLayout" name="gridLayout"> - <property name="sizeConstraint"> - <enum>QLayout::SetDefaultConstraint</enum> + <widget class="QWidget" name="centralwidget"> + <layout class="QGridLayout" name="gridLayout"> + <item row="0" column="0" colspan="2"> + <layout class="QHBoxLayout" name="horizontalLayout_8"> + <item> + <layout class="QHBoxLayout" name="horizontalLayout_graph"/> + </item> + </layout> + </item> + <item row="1" column="0"> + <layout class="QVBoxLayout" name="verticalLayout_9"> + <item> + <layout class="QHBoxLayout" name="horizontalLayout_10"> + <item> + <widget class="QPushButton" name="pushButton_26"> + <property name="text"> + <string/> + </property> + <property name="icon"> + <iconset> + <normaloff>ressources/gtk-sort-descending.png</normaloff>ressources/gtk-sort-descending.png</iconset> + </property> + </widget> + </item> + <item> + <widget class="QPushButton" name="pushButton_27"> + <property name="text"> + <string/> + </property> + <property name="icon"> + <iconset> + <normaloff>ressources/go-up2.png</normaloff>ressources/go-up2.png</iconset> + </property> + </widget> + </item> + <item> + <widget class="QPushButton" name="pushButton_28"> + <property name="text"> + <string/> + </property> + <property name="icon"> + <iconset> + <normaloff>ressources/go-down1.png</normaloff>ressources/go-down1.png</iconset> + </property> + </widget> + </item> + <item> + <widget class="QPushButton" name="pushButton_reverse"> + <property name="text"> + <string>Reverse</string> + </property> + </widget> + </item> + <item> + <spacer name="horizontalSpacer_9"> + <property name="orientation"> + <enum>Qt::Horizontal</enum> + </property> + <property name="sizeHint" stdset="0"> + <size> + <width>40</width> + <height>20</height> + </size> + </property> + </spacer> + </item> + </layout> + </item> + <item> + <widget class="QTableView" name="tableView_reachs"> + <property name="minimumSize"> + <size> + <width>650</width> + <height>150</height> + </size> + </property> + <property name="maximumSize"> + <size> + <width>16777215</width> + <height>200</height> + </size> + </property> + </widget> + </item> + </layout> + </item> + <item row="1" column="1"> + <layout class="QVBoxLayout" name="verticalLayout_8"> + <item> + <layout class="QHBoxLayout" name="horizontalLayout_9"> + <item> + <widget class="QPushButton" name="pushButton_23"> + <property name="text"> + <string/> + </property> + <property name="icon"> + <iconset> + <normaloff>ressources/gtk-sort-descending.png</normaloff>ressources/gtk-sort-descending.png</iconset> + </property> + </widget> + </item> + <item> + <widget class="QPushButton" name="pushButton_24"> + <property name="text"> + <string/> + </property> + <property name="icon"> + <iconset> + <normaloff>ressources/go-up2.png</normaloff>ressources/go-up2.png</iconset> + </property> + </widget> + </item> + <item> + <widget class="QPushButton" name="pushButton_25"> + <property name="text"> + <string/> + </property> + <property name="icon"> + <iconset> + <normaloff>ressources/go-down1.png</normaloff>ressources/go-down1.png</iconset> + </property> + </widget> + </item> + <item> + <spacer name="horizontalSpacer_8"> + <property name="orientation"> + <enum>Qt::Horizontal</enum> + </property> + <property name="sizeHint" stdset="0"> + <size> + <width>40</width> + <height>20</height> + </size> + </property> + </spacer> + </item> + </layout> + </item> + <item> + <widget class="QTableView" name="tableView_nodes"> + <property name="minimumSize"> + <size> + <width>0</width> + <height>150</height> + </size> + </property> + <property name="maximumSize"> + <size> + <width>16777215</width> + <height>200</height> + </size> + </property> + </widget> + </item> + </layout> + </item> + </layout> + </widget> + <widget class="QMenuBar" name="menubar"> + <property name="geometry"> + <rect> + <x>0</x> + <y>0</y> + <width>990</width> + <height>22</height> + </rect> + </property> + </widget> + <widget class="QStatusBar" name="statusbar"/> + <widget class="QToolBar" name="toolBar"> + <property name="enabled"> + <bool>true</bool> + </property> + <property name="windowTitle"> + <string>toolBar</string> + </property> + <property name="orientation"> + <enum>Qt::Horizontal</enum> + </property> + <attribute name="toolBarArea"> + <enum>TopToolBarArea</enum> + </attribute> + <attribute name="toolBarBreak"> + <bool>false</bool> + </attribute> + <addaction name="action_toolBar_add"/> + <addaction name="action_toolBar_del"/> + </widget> + <action name="action_toolBar_add"> + <property name="icon"> + <iconset> + <normaloff>ressources/gtk-add.png</normaloff>ressources/gtk-add.png</iconset> + </property> + <property name="text"> + <string>Add node or edge</string> + </property> + <property name="toolTip"> + <string>Add node or edge</string> + </property> + </action> + <action name="action_toolBar_del"> + <property name="icon"> + <iconset> + <normaloff>ressources/gtk-remove.png</normaloff>ressources/gtk-remove.png</iconset> + </property> + <property name="text"> + <string>Remove node or edge</string> + </property> + <property name="toolTip"> + <string>Remove node or edge</string> </property> - <item row="0" column="0" colspan="2"> - <layout class="QHBoxLayout" name="horizontalLayout_2"> - <item> - <layout class="QVBoxLayout" name="verticalLayout"> - <item> - <widget class="QPushButton" name="pushButton_add"> - <property name="maximumSize"> - <size> - <width>40</width> - <height>16777215</height> - </size> - </property> - <property name="text"> - <string/> - </property> - <property name="icon"> - <iconset> - <normaloff>ressources/gtk_add.png</normaloff>ressources/gtk_add.png</iconset> - </property> - <property name="checkable"> - <bool>true</bool> - </property> - <property name="autoRepeat"> - <bool>false</bool> - </property> - <property name="default"> - <bool>false</bool> - </property> - <property name="flat"> - <bool>false</bool> - </property> - </widget> - </item> - <item> - <widget class="QPushButton" name="pushButton_del"> - <property name="maximumSize"> - <size> - <width>40</width> - <height>16777215</height> - </size> - </property> - <property name="text"> - <string/> - </property> - <property name="icon"> - <iconset> - <normaloff>ressources/gtk-remove.png</normaloff>ressources/gtk-remove.png</iconset> - </property> - <property name="checkable"> - <bool>true</bool> - </property> - </widget> - </item> - <item> - <spacer name="verticalSpacer"> - <property name="orientation"> - <enum>Qt::Vertical</enum> - </property> - <property name="sizeHint" stdset="0"> - <size> - <width>20</width> - <height>40</height> - </size> - </property> - </spacer> - </item> - </layout> - </item> - <item> - <layout class="QHBoxLayout" name="horizontalLayout_graph"/> - </item> - </layout> - </item> - <item row="1" column="0"> - <layout class="QVBoxLayout" name="verticalLayout_5"> - <item> - <layout class="QHBoxLayout" name="horizontalLayout_5"> - <item> - <widget class="QPushButton" name="pushButton_14"> - <property name="text"> - <string/> - </property> - <property name="icon"> - <iconset> - <normaloff>ressources/gtk-sort-descending.png</normaloff>ressources/gtk-sort-descending.png</iconset> - </property> - </widget> - </item> - <item> - <widget class="QPushButton" name="pushButton_15"> - <property name="text"> - <string/> - </property> - <property name="icon"> - <iconset> - <normaloff>ressources/go-up2.png</normaloff>ressources/go-up2.png</iconset> - </property> - </widget> - </item> - <item> - <widget class="QPushButton" name="pushButton_16"> - <property name="text"> - <string/> - </property> - <property name="icon"> - <iconset> - <normaloff>ressources/go-down1.png</normaloff>ressources/go-down1.png</iconset> - </property> - </widget> - </item> - <item> - <widget class="QPushButton" name="pushButton_reverse"> - <property name="text"> - <string>Reverse</string> - </property> - </widget> - </item> - <item> - <spacer name="horizontalSpacer_5"> - <property name="orientation"> - <enum>Qt::Horizontal</enum> - </property> - <property name="sizeHint" stdset="0"> - <size> - <width>40</width> - <height>20</height> - </size> - </property> - </spacer> - </item> - </layout> - </item> - <item> - <widget class="QTableView" name="tableView_reachs"> - <property name="minimumSize"> - <size> - <width>650</width> - <height>150</height> - </size> - </property> - <property name="maximumSize"> - <size> - <width>16777215</width> - <height>200</height> - </size> - </property> - </widget> - </item> - </layout> - </item> - <item row="1" column="1"> - <layout class="QVBoxLayout" name="verticalLayout_4"> - <item> - <layout class="QHBoxLayout" name="horizontalLayout_4"> - <item> - <widget class="QPushButton" name="pushButton_11"> - <property name="text"> - <string/> - </property> - <property name="icon"> - <iconset> - <normaloff>ressources/gtk-sort-descending.png</normaloff>ressources/gtk-sort-descending.png</iconset> - </property> - </widget> - </item> - <item> - <widget class="QPushButton" name="pushButton_12"> - <property name="text"> - <string/> - </property> - <property name="icon"> - <iconset> - <normaloff>ressources/go-up2.png</normaloff>ressources/go-up2.png</iconset> - </property> - </widget> - </item> - <item> - <widget class="QPushButton" name="pushButton_13"> - <property name="text"> - <string/> - </property> - <property name="icon"> - <iconset> - <normaloff>ressources/go-down1.png</normaloff>ressources/go-down1.png</iconset> - </property> - </widget> - </item> - <item> - <spacer name="horizontalSpacer_4"> - <property name="orientation"> - <enum>Qt::Horizontal</enum> - </property> - <property name="sizeHint" stdset="0"> - <size> - <width>40</width> - <height>20</height> - </size> - </property> - </spacer> - </item> - </layout> - </item> - <item> - <widget class="QTableView" name="tableView_nodes"> - <property name="minimumSize"> - <size> - <width>0</width> - <height>150</height> - </size> - </property> - <property name="maximumSize"> - <size> - <width>16777215</width> - <height>200</height> - </size> - </property> - </widget> - </item> - </layout> - </item> - </layout> + </action> </widget> <resources/> <connections/>