ImageReaderUI.py 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157
  1. # Copyright (c) 2015 Ultimaker B.V.
  2. # Cura is released under the terms of the LGPLv3 or higher.
  3. import os
  4. import threading
  5. from PyQt5.QtCore import Qt, pyqtSignal, QObject
  6. from UM.FlameProfiler import pyqtSlot
  7. from UM.Application import Application
  8. from UM.PluginRegistry import PluginRegistry
  9. from UM.Logger import Logger
  10. from UM.i18n import i18nCatalog
  11. catalog = i18nCatalog("cura")
  12. class ImageReaderUI(QObject):
  13. show_config_ui_trigger = pyqtSignal()
  14. def __init__(self, image_reader):
  15. super(ImageReaderUI, self).__init__()
  16. self.image_reader = image_reader
  17. self._ui_view = None
  18. self.show_config_ui_trigger.connect(self._actualShowConfigUI)
  19. self.default_width = 120
  20. self.default_depth = 120
  21. self._aspect = 1
  22. self._width = self.default_width
  23. self._depth = self.default_depth
  24. self.base_height = 0.4
  25. self.peak_height = 2.5
  26. self.smoothing = 1
  27. self.lighter_is_higher = False;
  28. self.use_transparency_model = True;
  29. self.transmittance_1mm = 50.0; # based on pearl PLA
  30. self._ui_lock = threading.Lock()
  31. self._cancelled = False
  32. self._disable_size_callbacks = False
  33. def setWidthAndDepth(self, width, depth):
  34. self._aspect = width / depth
  35. self._width = width
  36. self._depth = depth
  37. def getWidth(self):
  38. return self._width
  39. def getDepth(self):
  40. return self._depth
  41. def getCancelled(self):
  42. return self._cancelled
  43. def waitForUIToClose(self):
  44. self._ui_lock.acquire()
  45. self._ui_lock.release()
  46. def showConfigUI(self):
  47. self._ui_lock.acquire()
  48. self._cancelled = False
  49. self.show_config_ui_trigger.emit()
  50. def _actualShowConfigUI(self):
  51. self._disable_size_callbacks = True
  52. if self._ui_view is None:
  53. self._createConfigUI()
  54. self._ui_view.show()
  55. self._ui_view.findChild(QObject, "Width").setProperty("text", str(self._width))
  56. self._ui_view.findChild(QObject, "Depth").setProperty("text", str(self._depth))
  57. self._disable_size_callbacks = False
  58. self._ui_view.findChild(QObject, "Base_Height").setProperty("text", str(self.base_height))
  59. self._ui_view.findChild(QObject, "Peak_Height").setProperty("text", str(self.peak_height))
  60. self._ui_view.findChild(QObject, "Transmittance").setProperty("text", str(self.transmittance_1mm))
  61. self._ui_view.findChild(QObject, "Smoothing").setProperty("value", self.smoothing)
  62. def _createConfigUI(self):
  63. if self._ui_view is None:
  64. Logger.log("d", "Creating ImageReader config UI")
  65. path = os.path.join(PluginRegistry.getInstance().getPluginPath("ImageReader"), "ConfigUI.qml")
  66. self._ui_view = Application.getInstance().createQmlComponent(path, {"manager": self})
  67. self._ui_view.setFlags(self._ui_view.flags() & ~Qt.WindowCloseButtonHint & ~Qt.WindowMinimizeButtonHint & ~Qt.WindowMaximizeButtonHint);
  68. self._disable_size_callbacks = False
  69. @pyqtSlot()
  70. def onOkButtonClicked(self):
  71. self._cancelled = False
  72. self._ui_view.close()
  73. self._ui_lock.release()
  74. @pyqtSlot()
  75. def onCancelButtonClicked(self):
  76. self._cancelled = True
  77. self._ui_view.close()
  78. self._ui_lock.release()
  79. @pyqtSlot(str)
  80. def onWidthChanged(self, value):
  81. if self._ui_view and not self._disable_size_callbacks:
  82. if len(value) > 0:
  83. self._width = float(value.replace(",", "."))
  84. else:
  85. self._width = 0
  86. self._depth = self._width / self._aspect
  87. self._disable_size_callbacks = True
  88. self._ui_view.findChild(QObject, "Depth").setProperty("text", str(self._depth))
  89. self._disable_size_callbacks = False
  90. @pyqtSlot(str)
  91. def onDepthChanged(self, value):
  92. if self._ui_view and not self._disable_size_callbacks:
  93. if len(value) > 0:
  94. self._depth = float(value.replace(",", "."))
  95. else:
  96. self._depth = 0
  97. self._width = self._depth * self._aspect
  98. self._disable_size_callbacks = True
  99. self._ui_view.findChild(QObject, "Width").setProperty("text", str(self._width))
  100. self._disable_size_callbacks = False
  101. @pyqtSlot(str)
  102. def onBaseHeightChanged(self, value):
  103. if (len(value) > 0):
  104. self.base_height = float(value.replace(",", "."))
  105. else:
  106. self.base_height = 0
  107. @pyqtSlot(str)
  108. def onPeakHeightChanged(self, value):
  109. if (len(value) > 0):
  110. self.peak_height = float(value.replace(",", "."))
  111. else:
  112. self.peak_height = 0
  113. @pyqtSlot(float)
  114. def onSmoothingChanged(self, value):
  115. self.smoothing = int(value)
  116. @pyqtSlot(int)
  117. def onImageColorInvertChanged(self, value):
  118. self.lighter_is_higher = (value == 1)
  119. @pyqtSlot(int)
  120. def onColorModelChanged(self, value):
  121. self.use_transparency_model = (value == 0)
  122. @pyqtSlot(int)
  123. def onTransmittanceChanged(self, value):
  124. self.transmittance_1mm = value