|
|
@@ -8,15 +8,18 @@ from PyQt5.Qt import Qt, QEvent, QGraphicsScene, QPointF, QFileDialog, \
|
|
|
QGraphicsTextItem, QGraphicsItem, QGraphicsRectItem, \
|
|
|
QBrush, QColor, QGraphicsLineItem, QLineF, \
|
|
|
QPen, QPainter, QSvgGenerator, QSize, QRect, QGraphicsItemGroup, \
|
|
|
- QGraphicsColorizeEffect, QFont, QDialog, QTableWidgetItem
|
|
|
+ QGraphicsColorizeEffect, QFont, QDialog, QTableWidgetItem, QAbstractItemView, \
|
|
|
+ QListWidgetItem, QFrame, QInputDialog, QIcon, QPixmap
|
|
|
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')
|
|
|
|
|
|
palette = {
|
|
|
"Table": QColor(240, 240, 20),
|
|
|
@@ -503,8 +506,9 @@ class DetailsDialog(QDialog):
|
|
|
|
|
|
self.ui.tbl_mentions.hideColumn(0)
|
|
|
self.ui.tbl_mentions.setColumnWidth(1, 50)
|
|
|
- self.ui.tbl_mentions.setColumnWidth(2, 200)
|
|
|
- self.ui.tbl_mentions.setColumnWidth(3, 70)
|
|
|
+ self.ui.tbl_mentions.setColumnWidth(2, 70)
|
|
|
+ self.ui.tbl_mentions.setColumnWidth(3, 150)
|
|
|
+
|
|
|
|
|
|
self.load_table()
|
|
|
|
|
|
@@ -515,6 +519,12 @@ class DetailsDialog(QDialog):
|
|
|
|
|
|
for index, mention in enumerate(self.obj.mentions):
|
|
|
|
|
|
+ item = QTableWidgetItem("")
|
|
|
+ if mention.warning:
|
|
|
+ item.setIcon(QIcon(QPixmap(core.here / "rsc\\warning_16.png")))
|
|
|
+ item.setToolTip(mention.warning)
|
|
|
+ self.ui.tbl_mentions.setVerticalHeaderItem(index, item)
|
|
|
+
|
|
|
item = QTableWidgetItem("")
|
|
|
item.setData(0, index)
|
|
|
self.ui.tbl_mentions.setItem(index, 0, item)
|
|
|
@@ -522,10 +532,10 @@ class DetailsDialog(QDialog):
|
|
|
item = QTableWidgetItem("{}".format(mention.line))
|
|
|
self.ui.tbl_mentions.setItem(index, 1, item)
|
|
|
|
|
|
- item = QTableWidgetItem("{}".format(mention.objname))
|
|
|
+ item = QTableWidgetItem("{}".format(mention.obj.type_))
|
|
|
self.ui.tbl_mentions.setItem(index, 2, item)
|
|
|
|
|
|
- item = QTableWidgetItem("{}".format(mention.obj.type_))
|
|
|
+ item = QTableWidgetItem("{}".format(mention.objname))
|
|
|
self.ui.tbl_mentions.setItem(index, 3, item)
|
|
|
|
|
|
item = QTableWidgetItem("{}".format(mention.quote))
|
|
|
@@ -539,13 +549,50 @@ class DetailsDialog(QDialog):
|
|
|
self.ui.btn_del.setEnabled(True)
|
|
|
|
|
|
def add_mention(self):
|
|
|
- pass
|
|
|
+ dlg = ObjectSelectorDialog(parent=self)
|
|
|
+ dlg.show()
|
|
|
+ r = dlg.exec_()
|
|
|
+ if not r:
|
|
|
+ return
|
|
|
+ mention = 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:
|
|
|
+ mention.line = linenum
|
|
|
+ try:
|
|
|
+ with open(self.obj.sourcefile, "r", encoding='utf-8') as f:
|
|
|
+ mention.quote = next((line.strip() for i, line in enumerate(f) if i == linenum - 1)).strip()
|
|
|
+ except FileNotFoundError:
|
|
|
+ pass
|
|
|
+
|
|
|
+ self.obj.mentions.append(mention)
|
|
|
+ self.load_table()
|
|
|
|
|
|
def selected_index(self):
|
|
|
- return self.ui.tbl_mentions.item(self.ui.tbl_mentions.currentRow(), 0).data(0)
|
|
|
+ row = self.ui.tbl_mentions.currentRow()
|
|
|
+ if row < 0:
|
|
|
+ return None
|
|
|
+ return self.ui.tbl_mentions.item(row, 0).data(0)
|
|
|
|
|
|
def edit_mention(self):
|
|
|
- pass
|
|
|
+ row = self.ui.tbl_mentions.currentRow()
|
|
|
+ if row < 0:
|
|
|
+ return
|
|
|
+
|
|
|
+ item = QTableWidgetItem("")
|
|
|
+ item.setIcon(QIcon(QPixmap(core.here / "rsc\\edit_16.png")))
|
|
|
+ self.ui.tbl_mentions.setVerticalHeaderItem(row, item)
|
|
|
+
|
|
|
+ index = self.ui.tbl_mentions.item(row, 0).data(0)
|
|
|
+ mention = self.obj.mentions[index]
|
|
|
+
|
|
|
+ dlg = ObjectSelectorDialog(filterStr=mention.objname, parent=self)
|
|
|
+ dlg.show()
|
|
|
+ r = dlg.exec_()
|
|
|
+ if r:
|
|
|
+ mention.obj = dlg.obj
|
|
|
+ mention.warning = ""
|
|
|
+ self.load_table()
|
|
|
|
|
|
def del_mention(self):
|
|
|
index = self.selected_index()
|
|
|
@@ -557,3 +604,47 @@ class DetailsDialog(QDialog):
|
|
|
def ok(self):
|
|
|
self.done(1)
|
|
|
|
|
|
+
|
|
|
+class ObjectSelectorDialog(QDialog):
|
|
|
+
|
|
|
+ def __init__(self, filterStr="", parent=None):
|
|
|
+ self.obj = None
|
|
|
+ super (ObjectSelectorDialog, self).__init__(parent)
|
|
|
+ self.createWidgets()
|
|
|
+ self.ui.searchBox.setText(filterStr)
|
|
|
+
|
|
|
+ def createWidgets(self):
|
|
|
+ self.ui = Ui_select()
|
|
|
+ self.ui.setupUi(self)
|
|
|
+
|
|
|
+ for obj in core.Analyse.objects:
|
|
|
+ item = QListWidgetItem("{} - {}".format(obj.type_, obj.name_))
|
|
|
+ item.obj = obj
|
|
|
+ self.ui.listWidget.addItem(item)
|
|
|
+
|
|
|
+ self.ui.searchBox.textChanged.connect(self.filter)
|
|
|
+ self.ui.listWidget.itemClicked.connect(self.itemClicked)
|
|
|
+ self.ui.listWidget.itemDoubleClicked.connect(self.itemDoubleClicked)
|
|
|
+ self.ui.btn_ok.clicked.connect(self.ok)
|
|
|
+
|
|
|
+ def itemClicked(self, item):
|
|
|
+ self.obj = item.obj
|
|
|
+ self.ui.btn_ok.setEnabled(True)
|
|
|
+
|
|
|
+ def itemDoubleClicked(self, item):
|
|
|
+ self.itemClicked(item)
|
|
|
+ self.ok()
|
|
|
+
|
|
|
+ def filter(self, filterStr):
|
|
|
+ for i in range(self.ui.listWidget.count()):
|
|
|
+ item = self.ui.listWidget.item(i)
|
|
|
+ item.setHidden(filterStr.lower() not in item.text().lower())
|
|
|
+
|
|
|
+ def ok(self):
|
|
|
+ self.done(1)
|
|
|
+
|
|
|
+ def done(self, status):
|
|
|
+ if not status:
|
|
|
+ self.obj = None
|
|
|
+ super(ObjectSelectorDialog, self).done(status)
|
|
|
+
|