olivier.massot 7 роки тому
батько
коміт
94e6cf25dd
3 змінених файлів з 50 додано та 130 видалено
  1. 12 34
      Viewer.py
  2. 38 17
      core.py
  3. 0 79
      qt_warning.ui

+ 12 - 34
Viewer.py

@@ -13,14 +13,12 @@ from PyQt5.Qt import Qt, QEvent, QGraphicsScene, QPointF, QFileDialog, \
 from PyQt5.QtWidgets import QMainWindow, QGraphicsView
 from path import Path
 
-from core import Mention
 import core
 
 
 Ui_window, _ = uic.loadUiType(Path(__file__).parent / 'qt_viewer.ui')
 Ui_details, _ = uic.loadUiType(Path(__file__).parent / 'qt_details.ui')
 Ui_select, _ = uic.loadUiType(Path(__file__).parent / 'qt_select_object.ui')
-Ui_warning, _ = uic.loadUiType(Path(__file__).parent / 'qt_warning.ui')
 
 palette = {
             "Table": QColor(240, 240, 20),
@@ -406,15 +404,6 @@ class Viewer(QMainWindow):
         self.ui.txtPanel.clear()
         self.load()
 
-        duplicates = core.Analyse.duplicates()
-        if duplicates:
-            msg = "Les noms d'objets suivants sont utilisés simultanément par plusieurs objets:\n"
-            msg += "\n".join(["- {} ({})".format(key, ", ".join([obj.type_ for obj in val])) for key, val in duplicates.items()])
-            msg += "\n Veuillez corriger manuellement les rélérences des objets succeptibles de contenir des erreurs."
-            dlg = WarningDialog(msg, parent=self)
-            dlg.show()
-            dlg.exec_()
-
         QMessageBox.information(self, "Analyse", "Analyse terminée: {} objets chargés en mémoire".format(len(core.Analyse.objects)))
 
     def load(self):
@@ -435,7 +424,7 @@ class Viewer(QMainWindow):
                 topitem.addChild(item)
 
             item = QTreeWidgetItem()
-            if any(m.warning for m in obj.mentions):
+            if any(len(m.warnings) > 0 for m in obj.mentions):
                 item.setIcon(0, QIcon(QPixmap(core.here / "rsc\\warning_16.png")))
             item.setText(1, obj.name_)
             item.setData(2, 0, index)
@@ -552,7 +541,7 @@ class Viewer(QMainWindow):
         if r:
             core.Analyse.build_trees()
             self.maj_view_with(obj)
-            if any(m.warning for m in obj.mentions):
+            if any(len(m.warnings) > 0 for m in obj.mentions):
                 self.ui.treeWidget.currentItem().setIcon(0, QIcon(QPixmap(core.here / "rsc\\warning_16.png")))
             else:
                 self.ui.treeWidget.currentItem().setIcon(0, QIcon())
@@ -582,7 +571,8 @@ class DetailsDialog(QDialog):
         self.ui = Ui_details()
         self.ui.setupUi(self)
 
-        self.ui.tbl_mentions.verticalHeader().sectionClicked.connect(self.verticalHeaderClicked)
+        self.ui.tbl_mentions.verticalHeader().sectionDoubleClicked.connect(self.verticalHeaderDoubleClicked)
+
         self.ui.tbl_mentions.itemClicked.connect(self.itemClicked)
         self.ui.btn_add.clicked.connect(self.add_mention)
         self.ui.btn_edit.clicked.connect(self.edit_mention)
@@ -606,9 +596,9 @@ class DetailsDialog(QDialog):
         for index, mention in enumerate(self.obj.mentions):
 
             item = QTableWidgetItem("")
-            if mention.warning:
+            if len(mention.warnings) > 0:
                 item.setIcon(QIcon(QPixmap(core.here / "rsc\\warning_16.png")))
-                item.setToolTip(mention.warning)
+                item.setToolTip("\n".join([w.text for w in mention.warnings]) + "\n\nDoucle-cliquer pour supprimer l'avertissement.")
             self.ui.tbl_mentions.setVerticalHeaderItem(index, item)
 
             item = QTableWidgetItem("")
@@ -634,13 +624,13 @@ class DetailsDialog(QDialog):
         self.ui.btn_edit.setEnabled(True)
         self.ui.btn_del.setEnabled(True)
 
-    def verticalHeaderClicked(self, row):
+    def verticalHeaderDoubleClicked(self, row):
         index = self.ui.tbl_mentions.item(row, 0).data(0)
         mention = self.obj.mentions[index]
-        if mention.warning:
+        if mention.warnings:
             if QMessageBox.question(self, "Confirmation", "Voulez-vous supprimer cet avertissement?") == QMessageBox.Yes:
-                mention.warning = ""
-                self.ui.tbl_mentions.setVerticalHeaderItem(row, QTableWidgetItem(""))
+                del mention.warnings[:]
+                self.ui.tbl_mentions.verticalHeaderItem(row).setIcon(QIcon())
 
     def add_mention(self):
         dlg = ObjectSelectorDialog(parent=self)
@@ -648,7 +638,7 @@ class DetailsDialog(QDialog):
         r = dlg.exec_()
         if not r:
             return
-        mention = Mention(0, dlg.obj.name_, "(ajouté manuellement)", dlg.obj)
+        mention = core.Mention(0, dlg.obj.name_, "(ajouté manuellement)", dlg.obj)
 
         linenum, _ = QInputDialog.getInt(self, "Ligne", "Numéro de ligne correspondant dans le code-source? (facultatif)", 0)
         if linenum > 0:
@@ -747,16 +737,4 @@ class ObjectSelectorDialog(QDialog):
     def done(self, status):
         if not status:
             self.obj = None
-        super(ObjectSelectorDialog, self).done(status)
-
-
-class WarningDialog(QDialog):
-
-    def __init__(self, msg="", parent=None):
-        super (WarningDialog, self).__init__(parent)
-        self.createWidgets()
-        self.ui.displayText.setPlainText(msg)
-
-    def createWidgets(self):
-        self.ui = Ui_warning()
-        self.ui.setupUi(self)
+        super(ObjectSelectorDialog, self).done(status)

+ 38 - 17
core.py

@@ -9,8 +9,6 @@ import re
 from _regex_core import MULTILINE
 from path import Path
 
-# TODO: Gérer les références circulaires
-
 here = Path(__file__).parent.abspath()
 
 def recurse(acc_obj):
@@ -24,13 +22,28 @@ def recurse(acc_obj):
 class InvalidFileExt(IOError):
     pass
 
+class Warn():
+    text = ""
+
+class WarnDuplicate(Warning):
+    text = "Plusieurs objets portant ce nom ont été trouvés, vérifiez qu'il s'agit bien de l'objet ci-contre"
+
+class WarnComment(Warning):
+    text = "La mention semble se trouver dans un commentaire"
+
+class WarnCaption(Warning):
+    text = "Cette mention semble être dans un label"
+
+class WarnRefItself(Warning):
+    text = "L'objet semble se mentionner lui-même"
+
 class Mention():
-    def __init__(self, line, objname, quote, obj, warning=""):
+    def __init__(self, line, objname, quote, obj=None, warnings=[]):
         self.line = line
         self.objname = objname
         self.quote = quote
         self.obj = obj
-        self.warning = warning
+        self.warnings = warnings
 
 class AccessObject():
     type_ = "<unknown>"
@@ -150,7 +163,6 @@ class Analyse():
                         cls.index[fname] = []
                     cls.index[fname].append(obj)
 
-
     @classmethod
     def load_objects(cls, source_dir):
         source_dir = Path(source_dir)
@@ -194,24 +206,31 @@ class Analyse():
 
         # Indexe la position des lignes
         line_ends = [m.end() for m in re.finditer('.*\n', subject.sourcecode)]
-        warning = ""
 
         for match in rx.finditer(subject.sourcecode):
             line = next(i for i in range(len(line_ends)) if line_ends[i] > match.start(1)) + 1
-            quote = match.group(1).strip()
+            quote = match.group(1).replace("\r", "").replace("\n", "").strip()
             objname = match.group(2)
-            if len(cls.index[objname]) == 1:
-                obj = cls.index[objname][0]
+            warnings = []
+
+            if objname == subject.name_:
+                obj = subject
+                warnings.append(WarnRefItself())
             else:
-                # plusieurs objets portent le même nom
-                warning = "Plusieurs objets portant ce nom ont été trouvés, vérifiez qu'il s'agit bien de l'objet ci-contre."
-                if objname == subject.name_:
-                    # si l'objet mentionné porte le même nom que le sujet, on part du principe qu'il se mentione lui-même
-                    obj = subject
-                else:
-                    obj = cls.index[objname][0]
+                obj = cls.index[objname][0]
+
+            if len(cls.index[objname]) > 1:
+                warnings.append(WarnDuplicate())
+
+            if type(subject) is ModuleObject:
+                if re.match(r"^[^\"]*(?:\"(?:[^\"]*?)\")*[^\"]*'.*({})".format(objname), quote):
+                    warnings.append(WarnComment())
+
+            if type(subject) in (FormObject, ReportObject):
+                if re.match(r"Caption =\".*{}.*\"".format(objname), quote):
+                    warnings.append(WarnCaption())
 
-            subject.mentions.append(Mention(line, objname, quote, obj, warning))
+            subject.mentions.append(Mention(line, objname, quote, obj, warnings))
 
     @classmethod
     def parse_all(cls):
@@ -293,6 +312,8 @@ if __name__ == "__main__":
                 msg += "\n\t Détail:"
                 for mention in obj.mentions:
                     msg += "\n\t\t'{}'\t\tLine: {}\t>>\t{}".format(mention.objname, mention.line, mention.quote)
+                    if mention.warnings:
+                        msg += "\n\t\t\t! Avertissements: {}".format("|".join([w.text for w in mention.warnings]))
 
             msg += "\n"
             f.write(msg)

+ 0 - 79
qt_warning.ui

@@ -1,79 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<ui version="4.0">
- <class>Dialog</class>
- <widget class="QDialog" name="Dialog">
-  <property name="geometry">
-   <rect>
-    <x>0</x>
-    <y>0</y>
-    <width>482</width>
-    <height>253</height>
-   </rect>
-  </property>
-  <property name="minimumSize">
-   <size>
-    <width>249</width>
-    <height>253</height>
-   </size>
-  </property>
-  <property name="maximumSize">
-   <size>
-    <width>674</width>
-    <height>664</height>
-   </size>
-  </property>
-  <property name="font">
-   <font>
-    <family>Verdana</family>
-   </font>
-  </property>
-  <property name="windowTitle">
-   <string>Warning</string>
-  </property>
-  <property name="windowIcon">
-   <iconset>
-    <normaloff>rsc/icon.svg</normaloff>rsc/icon.svg</iconset>
-  </property>
-  <layout class="QVBoxLayout" name="verticalLayout">
-   <item>
-    <layout class="QHBoxLayout" name="horizontalLayout">
-     <item>
-      <widget class="QLabel" name="label_2">
-       <property name="maximumSize">
-        <size>
-         <width>40</width>
-         <height>40</height>
-        </size>
-       </property>
-       <property name="text">
-        <string/>
-       </property>
-       <property name="pixmap">
-        <pixmap>rsc/warning_32.png</pixmap>
-       </property>
-      </widget>
-     </item>
-     <item>
-      <widget class="QLabel" name="label">
-       <property name="font">
-        <font>
-         <pointsize>12</pointsize>
-         <weight>75</weight>
-         <bold>true</bold>
-        </font>
-       </property>
-       <property name="text">
-        <string>Avertissement(s)</string>
-       </property>
-      </widget>
-     </item>
-    </layout>
-   </item>
-   <item>
-    <widget class="QPlainTextEdit" name="displayText"/>
-   </item>
-  </layout>
- </widget>
- <resources/>
- <connections/>
-</ui>