From 5b33093ed17d644fc04b74c798cf4b4926c81f61 Mon Sep 17 00:00:00 2001
From: Pierre-Antoine Rouby <pierre-antoine.rouby@inrae.fr>
Date: Wed, 5 Apr 2023 14:24:12 +0200
Subject: [PATCH] pamhyr: Minor change.

---
 src/Model/Network/Graph.py |  5 ++---
 src/View/ASubWindow.py     | 21 ++++++++++++++++++++-
 src/View/MainWindow.py     |  1 +
 3 files changed, 23 insertions(+), 4 deletions(-)

diff --git a/src/Model/Network/Graph.py b/src/Model/Network/Graph.py
index 6e17c4ad..8cc6de21 100644
--- a/src/Model/Network/Graph.py
+++ b/src/Model/Network/Graph.py
@@ -67,9 +67,8 @@ class Graph(object):
 
     def add_edge(self, n1:Node, n2:Node):
         # This edge already exists ?
-        if list(filter(lambda e: (e.node1 == n1 and
-                                  e.node2 == n2),
-                       self._edges)):
+        if any(filter(lambda e: (e.node1 == n1 and e.node2 == n2),
+                      self._edges)):
             return None
 
         edge = Edge(self._edges_ids, "", n1, n2)
diff --git a/src/View/ASubWindow.py b/src/View/ASubWindow.py
index f4fb1dd3..03b0f9f3 100644
--- a/src/View/ASubWindow.py
+++ b/src/View/ASubWindow.py
@@ -10,7 +10,7 @@ from PyQt5.QtWidgets import (
     QPushButton, QLineEdit, QCheckBox,
     QTimeEdit, QSpinBox, QTextEdit,
     QRadioButton, QComboBox, QFileDialog,
-    QMessageBox,
+    QMessageBox, QTableView,
 )
 from PyQt5.QtCore import (
     QTime,
@@ -91,6 +91,22 @@ class ASubWindow(QDialog, WindowToolKit):
 
     # Commun use features
 
+    def _qtype_from_component_name(self, name):
+        qtype = None
+
+        if "action" in name:
+            qtype = QAction
+        elif "lineEdit" in name:
+            qtype = QLineEdit
+        elif "pushButton" in name:
+            qtype = QPushButton
+        elif "radioButton" in name:
+            qtype = QRadioButton
+        elif "tableView" in name:
+            qtype = QTableView
+
+        return qtype
+
     def find(self, qtype, name):
         """Find an ui component
 
@@ -101,6 +117,9 @@ class ASubWindow(QDialog, WindowToolKit):
         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):
diff --git a/src/View/MainWindow.py b/src/View/MainWindow.py
index 6f9a82be..3dcca5ed 100644
--- a/src/View/MainWindow.py
+++ b/src/View/MainWindow.py
@@ -59,6 +59,7 @@ class ApplicationWindow(QMainWindow, ListedSubWindow):
 
         # Model
         self.model = None
+
         # UI
         self.ui = loadUi(
             os.path.join(os.path.dirname(__file__), "ui", "MainWindow.ui"),
-- 
GitLab