network: Change network window to mainwindow.

mesh
Pierre-Antoine Rouby 2023-04-27 15:53:55 +02:00
parent bd74fb5679
commit 094ecb3ca3
3 changed files with 321 additions and 276 deletions

View File

@ -5,6 +5,8 @@ import csv
from io import StringIO from io import StringIO
from tools import trace
from PyQt5.QtCore import Qt from PyQt5.QtCore import Qt
from PyQt5.QtWidgets import ( from PyQt5.QtWidgets import (
@ -13,7 +15,7 @@ from PyQt5.QtWidgets import (
QPushButton, QLineEdit, QCheckBox, QPushButton, QLineEdit, QCheckBox,
QTimeEdit, QSpinBox, QTextEdit, QTimeEdit, QSpinBox, QTextEdit,
QRadioButton, QComboBox, QFileDialog, QRadioButton, QComboBox, QFileDialog,
QMessageBox, QTableView, QMessageBox, QTableView, QAction,
) )
from PyQt5.QtCore import ( from PyQt5.QtCore import (
QTime, QTime,
@ -101,26 +103,9 @@ class WindowToolKit(object):
msg.exec_() msg.exec_()
class ASubWindow(QDialog, WindowToolKit): class ASubWindowFeatures(object):
def __init__(self, name="", ui="dummy", parent=None): def __init__(self, parent=None):
super(ASubWindow, self).__init__(parent=parent) super(ASubWindowFeatures, self).__init__()
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)
# Commun use features # Commun use features
@ -140,21 +125,6 @@ class ASubWindow(QDialog, WindowToolKit):
return qtype 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): def set_line_edit_text(self, name:str, text:str):
"""Set text of line edit component """Set text of line edit component
@ -275,6 +245,30 @@ class ASubWindow(QDialog, WindowToolKit):
""" """
return self.find(QSpinBox, name).value() 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): def set_push_button_checkable(self, name:str, checked:bool):
"""Set value of push button component """Set value of push button component
@ -355,3 +349,66 @@ class ASubWindow(QDialog, WindowToolKit):
Current text Current text
""" """
return self.find(QComboBox, name).currentText() 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)

View File

@ -2,7 +2,7 @@
from Model.River import RiverNode, RiverReach, River 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.GraphWidget import GraphWidget
from View.Network.TableModel import ( from View.Network.TableModel import (
GraphTableModel, ComboBoxDelegate, TrueFalseComboBoxDelegate, GraphTableModel, ComboBoxDelegate, TrueFalseComboBoxDelegate,
@ -16,10 +16,10 @@ from PyQt5.QtCore import (
from PyQt5.QtWidgets import ( from PyQt5.QtWidgets import (
QTableView, QItemDelegate, QComboBox, QLineEdit, QHBoxLayout, QSlider, QTableView, QItemDelegate, QComboBox, QLineEdit, QHBoxLayout, QSlider,
QPushButton, QCheckBox, QStyledItemDelegate, QStyleOptionButton, QStyle, 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): def __init__(self, model=None, title="River network", parent=None):
super(NetworkWindow, self).__init__(name=title, ui="Network", parent=parent) super(NetworkWindow, self).__init__(name=title, ui="Network", parent=parent)
self.ui.setWindowTitle(title) self.ui.setWindowTitle(title)
@ -79,26 +79,30 @@ class NetworkWindow(ASubWindow):
self.graph_widget.changeEdge.connect(self.reachs_model.update) self.graph_widget.changeEdge.connect(self.reachs_model.update)
self.graph_widget.changeNode.connect(self.nodes_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.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.clicked_del
) )
self.find(QPushButton, "pushButton_reverse").clicked.connect( self.find(QPushButton, "pushButton_reverse").clicked.connect(
self.reverse_edge self.reverse_edge
) )
def clicked_add(self): def clicked_add(self):
if self.get_push_button_checkable("pushButton_add"): if self.get_action_checkable("action_toolBar_add"):
self.set_push_button_checkable("pushButton_del", False) self.set_action_checkable("action_toolBar_del", False)
self.graph_widget.state("add") self.graph_widget.state("add")
else: else:
self.graph_widget.state("move") self.graph_widget.state("move")
def clicked_del(self): def clicked_del(self):
if self.get_push_button_checkable("pushButton_del"): if self.get_action_checkable("action_toolBar_del"):
self.set_push_button_checkable("pushButton_add", False) self.set_action_checkable("action_toolBar_add", False)
self.graph_widget.state("del") self.graph_widget.state("del")
else: else:
self.graph_widget.state("move") self.graph_widget.state("move")

View File

@ -1,246 +1,230 @@
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0"> <ui version="4.0">
<class>Dialog</class> <class>MainWindow</class>
<widget class="QDialog" name="Dialog"> <widget class="QMainWindow" name="MainWindow">
<property name="geometry"> <property name="geometry">
<rect> <rect>
<x>0</x> <x>0</x>
<y>0</y> <y>0</y>
<width>990</width> <width>990</width>
<height>690</height> <height>600</height>
</rect> </rect>
</property> </property>
<property name="windowTitle"> <property name="windowTitle">
<string>Dialog</string> <string>MainWindow</string>
</property> </property>
<property name="sizeGripEnabled"> <widget class="QWidget" name="centralwidget">
<bool>false</bool> <layout class="QGridLayout" name="gridLayout">
</property> <item row="0" column="0" colspan="2">
<layout class="QGridLayout" name="gridLayout"> <layout class="QHBoxLayout" name="horizontalLayout_8">
<property name="sizeConstraint"> <item>
<enum>QLayout::SetDefaultConstraint</enum> <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> </property>
<item row="0" column="0" colspan="2"> </widget>
<layout class="QHBoxLayout" name="horizontalLayout_2"> <widget class="QStatusBar" name="statusbar"/>
<item> <widget class="QToolBar" name="toolBar">
<layout class="QVBoxLayout" name="verticalLayout"> <property name="enabled">
<item> <bool>true</bool>
<widget class="QPushButton" name="pushButton_add"> </property>
<property name="maximumSize"> <property name="windowTitle">
<size> <string>toolBar</string>
<width>40</width> </property>
<height>16777215</height> <property name="orientation">
</size> <enum>Qt::Horizontal</enum>
</property> </property>
<property name="text"> <attribute name="toolBarArea">
<string/> <enum>TopToolBarArea</enum>
</property> </attribute>
<property name="icon"> <attribute name="toolBarBreak">
<iconset> <bool>false</bool>
<normaloff>ressources/gtk_add.png</normaloff>ressources/gtk_add.png</iconset> </attribute>
</property> <addaction name="action_toolBar_add"/>
<property name="checkable"> <addaction name="action_toolBar_del"/>
<bool>true</bool> </widget>
</property> <action name="action_toolBar_add">
<property name="autoRepeat"> <property name="icon">
<bool>false</bool> <iconset>
</property> <normaloff>ressources/gtk-add.png</normaloff>ressources/gtk-add.png</iconset>
<property name="default"> </property>
<bool>false</bool> <property name="text">
</property> <string>Add node or edge</string>
<property name="flat"> </property>
<bool>false</bool> <property name="toolTip">
</property> <string>Add node or edge</string>
</widget> </property>
</item> </action>
<item> <action name="action_toolBar_del">
<widget class="QPushButton" name="pushButton_del"> <property name="icon">
<property name="maximumSize"> <iconset>
<size> <normaloff>ressources/gtk-remove.png</normaloff>ressources/gtk-remove.png</iconset>
<width>40</width> </property>
<height>16777215</height> <property name="text">
</size> <string>Remove node or edge</string>
</property> </property>
<property name="text"> <property name="toolTip">
<string/> <string>Remove node or edge</string>
</property> </property>
<property name="icon"> </action>
<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>
</widget> </widget>
<resources/> <resources/>
<connections/> <connections/>