|
|
@@ -0,0 +1,78 @@
|
|
|
+'''
|
|
|
+
|
|
|
+ Boite de dialogue qui prend une liste de strings en entrée,
|
|
|
+ permet d'en selectionner une ou plusieurs,
|
|
|
+ et retourne une liste des strings selectionnées
|
|
|
+
|
|
|
+ > utilisée par le script qgis_sync_compactage
|
|
|
+
|
|
|
+ @author: olivier.massot, mai 2018
|
|
|
+'''
|
|
|
+import sys
|
|
|
+
|
|
|
+from PyQt5 import uic
|
|
|
+from PyQt5.Qt import QApplication, QMessageBox, QTableWidgetItem, \
|
|
|
+ Qt, QDialog
|
|
|
+from path import Path
|
|
|
+
|
|
|
+
|
|
|
+Ui_window, _ = uic.loadUiType(Path(__file__).parent / 'select_list_dialog.ui')
|
|
|
+
|
|
|
+def exec_(input_list):
|
|
|
+
|
|
|
+ app = QApplication(sys.argv)
|
|
|
+
|
|
|
+ SYS_HOOK = sys.excepthook
|
|
|
+ def error_handler(typ, value, trace):
|
|
|
+ while QApplication.overrideCursor():
|
|
|
+ QApplication.restoreOverrideCursor()
|
|
|
+ QMessageBox.critical(dlg, typ.__name__, "{}".format(value))
|
|
|
+ SYS_HOOK(typ, value, trace)
|
|
|
+ sys.excepthook = error_handler
|
|
|
+
|
|
|
+ dlg = SelectListDialog(input_list)
|
|
|
+ dlg.show()
|
|
|
+ app.exec_()
|
|
|
+
|
|
|
+ return dlg.selection()
|
|
|
+
|
|
|
+class SelectListDialog(QDialog):
|
|
|
+
|
|
|
+ def __init__(self, input_list, title="Sélectionner les lignes"):
|
|
|
+ super (SelectListDialog, self).__init__()
|
|
|
+ self.input_list = input_list
|
|
|
+ self.title = title
|
|
|
+ self.createWidgets()
|
|
|
+
|
|
|
+ def createWidgets(self):
|
|
|
+ self.ui = Ui_window()
|
|
|
+ self.ui.setupUi(self)
|
|
|
+
|
|
|
+ self.setWindowModality(Qt.ApplicationModal)
|
|
|
+ self.ui.btn_ok.clicked.connect(self.ok)
|
|
|
+ self.ui.lbl_title.setText(self.title)
|
|
|
+
|
|
|
+ index = 0
|
|
|
+ for nomChantier in self.input_list:
|
|
|
+ self.ui.tbl_selection.insertRow(index)
|
|
|
+ self.ui.tbl_selection.setItem(index, 0, QTableWidgetItem(" {}".format(nomChantier)))
|
|
|
+ index += 1
|
|
|
+ self.ui.tbl_selection.sortItems(0, Qt.AscendingOrder)
|
|
|
+
|
|
|
+ def selection(self):
|
|
|
+ output_list = []
|
|
|
+
|
|
|
+ for model_index in self.ui.tbl_selection.selectedIndexes():
|
|
|
+ output_list.append(self.input_list[model_index.row()])
|
|
|
+
|
|
|
+ return output_list
|
|
|
+
|
|
|
+ def ok(self):
|
|
|
+ self.done(1)
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+if __name__ == "__main__":
|
|
|
+ selection = exec_(["1", "2", "3"])
|
|
|
+ print(selection)
|
|
|
+
|