GridDialogBox.py 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. '''
  2. Created on 8 mars 2017
  3. @author: olinox
  4. '''
  5. from PyQt5.Qt import QDialog
  6. from gridviewer.qt_new_grid import Ui_window
  7. from pypog.grid_objects import FHexGrid, SquareGrid
  8. class GridDialogBox(QDialog):
  9. def __init__(self, parent=None):
  10. super (GridDialogBox, self).__init__(parent)
  11. self.parent = parent
  12. self._obj = None
  13. self.createWidgets()
  14. def createWidgets(self):
  15. self.ui = Ui_window()
  16. self.ui.setupUi(self)
  17. self.ui.btn_cancel.clicked.connect(self.cancel)
  18. self.ui.btn_create.clicked.connect(self.ok)
  19. def ok(self):
  20. cls = FHexGrid if self.ui.opt_hex else SquareGrid
  21. self._obj = cls(self.ui.spb_width.value(), self.ui.spb_height.value())
  22. self.done(1)
  23. def cancel(self):
  24. self.done(0)
  25. def exec_(self, *args, **kwargs):
  26. self.show()
  27. QDialog.exec_(self, *args, **kwargs)
  28. return self._obj
  29. @staticmethod
  30. def get(*args):
  31. return GridDialogBox(*args).exec_()
  32. if __name__ == "__main__":
  33. from PyQt5.Qt import QApplication
  34. app = QApplication([])
  35. grid = GridDialogBox().exec_()
  36. # or grid = GridDialogBox.get()
  37. if grid:
  38. print(grid, grid.width, grid.height)