ListViewDialog.py 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. '''
  2. Created on 8 mars 2017
  3. @author: olinox
  4. '''
  5. from PyQt5.Qt import QDialog
  6. from gridviewer.qt_listview import Ui_window
  7. from pypog.geometry_objects import BaseGeometry
  8. class ListViewDialog(QDialog):
  9. def __init__(self, lst, parent=None):
  10. super (ListViewDialog, self).__init__(parent)
  11. self.parent = parent
  12. BaseGeometry.assertCoordinates(*lst)
  13. self._lst = lst
  14. self.createWidgets()
  15. def createWidgets(self):
  16. self.ui = Ui_window()
  17. self.ui.setupUi(self)
  18. self.ui.txt_list.setPlainText(str(self._lst))
  19. self.ui.btn_cancel.clicked.connect(self.cancel)
  20. self.ui.btn_ok.clicked.connect(self.ok)
  21. def ok(self):
  22. self._lst = list(eval(self.ui.txt_list.toPlainText()))
  23. self.done(1)
  24. def cancel(self):
  25. self.done(0)
  26. def exec_(self, *args, **kwargs):
  27. self.show()
  28. QDialog.exec_(self, *args, **kwargs)
  29. return self._lst
  30. @staticmethod
  31. def get(*args):
  32. return ListViewDialog(*args).exec_()
  33. if __name__ == "__main__":
  34. from PyQt5.Qt import QApplication
  35. app = QApplication([])
  36. lst = [(0, 0), (1, 1), (2, 2)]
  37. new_lst = ListViewDialog(lst).exec_()
  38. print(new_lst)