GeneralGUIPrefGroupUI.py 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409
  1. from PyQt5 import QtWidgets, QtCore, QtGui
  2. from PyQt5.QtCore import QSettings, Qt
  3. from appGUI.GUIElements import RadioSet, FCCheckBox, FCComboBox, FCSliderWithSpinner, FCColorEntry
  4. from appGUI.preferences.OptionsGroupUI import OptionsGroupUI
  5. import gettext
  6. import appTranslation as fcTranslate
  7. import builtins
  8. fcTranslate.apply_language('strings')
  9. if '_' not in builtins.__dict__:
  10. _ = gettext.gettext
  11. settings = QSettings("Open Source", "FlatCAM")
  12. if settings.contains("machinist"):
  13. machinist_setting = settings.value('machinist', type=int)
  14. else:
  15. machinist_setting = 0
  16. class GeneralGUIPrefGroupUI(OptionsGroupUI):
  17. def __init__(self, decimals=4, parent=None):
  18. super(GeneralGUIPrefGroupUI, self).__init__(self, parent=parent)
  19. self.setTitle(str(_("GUI Preferences")))
  20. self.decimals = decimals
  21. # Create a grid layout for the Application general settings
  22. grid0 = QtWidgets.QGridLayout()
  23. self.layout.addLayout(grid0)
  24. grid0.setColumnStretch(0, 0)
  25. grid0.setColumnStretch(1, 1)
  26. # Theme selection
  27. self.theme_label = QtWidgets.QLabel('%s:' % _('Theme'))
  28. self.theme_label.setToolTip(
  29. _("Select a theme for the application.\n"
  30. "It will theme the plot area.")
  31. )
  32. self.theme_radio = RadioSet([
  33. {"label": _("Light"), "value": "white"},
  34. {"label": _("Dark"), "value": "black"}
  35. ], orientation='vertical')
  36. grid0.addWidget(self.theme_label, 0, 0)
  37. grid0.addWidget(self.theme_radio, 0, 1)
  38. # Enable Gray Icons
  39. self.gray_icons_cb = FCCheckBox('%s' % _('Use Gray Icons'))
  40. self.gray_icons_cb.setToolTip(
  41. _("Check this box to use a set of icons with\n"
  42. "a lighter (gray) color. To be used when a\n"
  43. "full dark theme is applied.")
  44. )
  45. grid0.addWidget(self.gray_icons_cb, 1, 0, 1, 3)
  46. # self.theme_button = FCButton(_("Apply Theme"))
  47. # self.theme_button.setToolTip(
  48. # _("Select a theme for FlatCAM.\n"
  49. # "It will theme the plot area.\n"
  50. # "The application will restart after change.")
  51. # )
  52. # grid0.addWidget(self.theme_button, 2, 0, 1, 3)
  53. separator_line = QtWidgets.QFrame()
  54. separator_line.setFrameShape(QtWidgets.QFrame.HLine)
  55. separator_line.setFrameShadow(QtWidgets.QFrame.Sunken)
  56. grid0.addWidget(separator_line, 3, 0, 1, 2)
  57. # Layout selection
  58. self.layout_label = QtWidgets.QLabel('%s:' % _('Layout'))
  59. self.layout_label.setToolTip(
  60. _("Select a layout for the application.\n"
  61. "It is applied immediately.")
  62. )
  63. self.layout_combo = FCComboBox()
  64. # don't translate the QCombo items as they are used in QSettings and identified by name
  65. self.layout_combo.addItem("standard")
  66. self.layout_combo.addItem("compact")
  67. self.layout_combo.addItem("minimal")
  68. grid0.addWidget(self.layout_label, 4, 0)
  69. grid0.addWidget(self.layout_combo, 4, 1)
  70. # Set the current index for layout_combo
  71. qsettings = QSettings("Open Source", "FlatCAM")
  72. if qsettings.contains("layout"):
  73. layout = qsettings.value('layout', type=str)
  74. idx = self.layout_combo.findText(layout.capitalize())
  75. self.layout_combo.setCurrentIndex(idx)
  76. # Style selection
  77. self.style_label = QtWidgets.QLabel('%s:' % _('Style'))
  78. self.style_label.setToolTip(
  79. _("Select a style for the application.\n"
  80. "It will be applied at the next app start.")
  81. )
  82. self.style_combo = FCComboBox()
  83. self.style_combo.addItems(QtWidgets.QStyleFactory.keys())
  84. # find current style
  85. index = self.style_combo.findText(QtWidgets.qApp.style().objectName(), QtCore.Qt.MatchFixedString)
  86. self.style_combo.setCurrentIndex(index)
  87. self.style_combo.activated[str].connect(self.handle_style)
  88. grid0.addWidget(self.style_label, 5, 0)
  89. grid0.addWidget(self.style_combo, 5, 1)
  90. # Enable High DPI Support
  91. self.hdpi_cb = FCCheckBox('%s' % _('HDPI Support'))
  92. self.hdpi_cb.setToolTip(
  93. _("Enable High DPI support for the application.\n"
  94. "It will be applied at the next app start.")
  95. )
  96. qsettings = QSettings("Open Source", "FlatCAM")
  97. if qsettings.contains("hdpi"):
  98. self.hdpi_cb.set_value(qsettings.value('hdpi', type=int))
  99. else:
  100. self.hdpi_cb.set_value(False)
  101. self.hdpi_cb.stateChanged.connect(self.handle_hdpi)
  102. grid0.addWidget(self.hdpi_cb, 6, 0, 1, 3)
  103. # Enable Hover box
  104. self.hover_cb = FCCheckBox('%s' % _('Hover Shape'))
  105. self.hover_cb.setToolTip(
  106. _("Enable display of a hover shape for the application objects.\n"
  107. "It is displayed whenever the mouse cursor is hovering\n"
  108. "over any kind of not-selected object.")
  109. )
  110. grid0.addWidget(self.hover_cb, 8, 0, 1, 3)
  111. # Enable Selection box
  112. self.selection_cb = FCCheckBox('%s' % _('Selection Shape'))
  113. self.selection_cb.setToolTip(
  114. _("Enable the display of a selection shape for the application objects.\n"
  115. "It is displayed whenever the mouse selects an object\n"
  116. "either by clicking or dragging mouse from left to right or\n"
  117. "right to left.")
  118. )
  119. grid0.addWidget(self.selection_cb, 9, 0, 1, 3)
  120. separator_line = QtWidgets.QFrame()
  121. separator_line.setFrameShape(QtWidgets.QFrame.HLine)
  122. separator_line.setFrameShadow(QtWidgets.QFrame.Sunken)
  123. grid0.addWidget(separator_line, 14, 0, 1, 2)
  124. # Plot Selection (left - right) Color
  125. self.sel_lr_label = QtWidgets.QLabel('<b>%s</b>' % _('Left-Right Selection Color'))
  126. grid0.addWidget(self.sel_lr_label, 15, 0, 1, 2)
  127. self.sl_color_label = QtWidgets.QLabel('%s:' % _('Outline'))
  128. self.sl_color_label.setToolTip(
  129. _("Set the line color for the 'left to right' selection box.")
  130. )
  131. self.sl_color_entry = FCColorEntry()
  132. grid0.addWidget(self.sl_color_label, 16, 0)
  133. grid0.addWidget(self.sl_color_entry, 16, 1)
  134. self.sf_color_label = QtWidgets.QLabel('%s:' % _('Fill'))
  135. self.sf_color_label.setToolTip(
  136. _("Set the fill color for the selection box\n"
  137. "in case that the selection is done from left to right.\n"
  138. "First 6 digits are the color and the last 2\n"
  139. "digits are for alpha (transparency) level.")
  140. )
  141. self.sf_color_entry = FCColorEntry()
  142. grid0.addWidget(self.sf_color_label, 17, 0)
  143. grid0.addWidget(self.sf_color_entry, 17, 1)
  144. # Plot Selection (left - right) Fill Transparency Level
  145. self.left_right_alpha_label = QtWidgets.QLabel('%s:' % _('Alpha'))
  146. self.left_right_alpha_label.setToolTip(
  147. _("Set the fill transparency for the 'left to right' selection box.")
  148. )
  149. self.left_right_alpha_entry = FCSliderWithSpinner(0, 255, 1)
  150. grid0.addWidget(self.left_right_alpha_label, 18, 0)
  151. grid0.addWidget(self.left_right_alpha_entry, 18, 1)
  152. separator_line = QtWidgets.QFrame()
  153. separator_line.setFrameShape(QtWidgets.QFrame.HLine)
  154. separator_line.setFrameShadow(QtWidgets.QFrame.Sunken)
  155. grid0.addWidget(separator_line, 19, 0, 1, 2)
  156. # Plot Selection (left - right) Color
  157. self.sel_rl_label = QtWidgets.QLabel('<b>%s</b>' % _('Right-Left Selection Color'))
  158. grid0.addWidget(self.sel_rl_label, 20, 0, 1, 2)
  159. # Plot Selection (right - left) Line Color
  160. self.alt_sl_color_label = QtWidgets.QLabel('%s:' % _('Outline'))
  161. self.alt_sl_color_label.setToolTip(
  162. _("Set the line color for the 'right to left' selection box.")
  163. )
  164. self.alt_sl_color_entry = FCColorEntry()
  165. grid0.addWidget(self.alt_sl_color_label, 21, 0)
  166. grid0.addWidget(self.alt_sl_color_entry, 21, 1)
  167. # Plot Selection (right - left) Fill Color
  168. self.alt_sf_color_label = QtWidgets.QLabel('%s:' % _('Fill'))
  169. self.alt_sf_color_label.setToolTip(
  170. _("Set the fill color for the selection box\n"
  171. "in case that the selection is done from right to left.\n"
  172. "First 6 digits are the color and the last 2\n"
  173. "digits are for alpha (transparency) level.")
  174. )
  175. self.alt_sf_color_entry = FCColorEntry()
  176. grid0.addWidget(self.alt_sf_color_label, 22, 0)
  177. grid0.addWidget(self.alt_sf_color_entry, 22, 1)
  178. # Plot Selection (right - left) Fill Transparency Level
  179. self.right_left_alpha_label = QtWidgets.QLabel('%s:' % _('Alpha'))
  180. self.right_left_alpha_label.setToolTip(
  181. _("Set the fill transparency for selection 'right to left' box.")
  182. )
  183. self.right_left_alpha_entry = FCSliderWithSpinner(0, 255, 1)
  184. grid0.addWidget(self.right_left_alpha_label, 23, 0)
  185. grid0.addWidget(self.right_left_alpha_entry, 23, 1)
  186. separator_line = QtWidgets.QFrame()
  187. separator_line.setFrameShape(QtWidgets.QFrame.HLine)
  188. separator_line.setFrameShadow(QtWidgets.QFrame.Sunken)
  189. grid0.addWidget(separator_line, 24, 0, 1, 2)
  190. # ------------------------------------------------------------------
  191. # ----------------------- Editor Color -----------------------------
  192. # ------------------------------------------------------------------
  193. self.editor_color_label = QtWidgets.QLabel('<b>%s</b>' % _('Editor Color'))
  194. grid0.addWidget(self.editor_color_label, 25, 0, 1, 2)
  195. # Editor Draw Color
  196. self.draw_color_label = QtWidgets.QLabel('%s:' % _('Drawing'))
  197. self.alt_sf_color_label.setToolTip(
  198. _("Set the color for the shape.")
  199. )
  200. self.draw_color_entry = FCColorEntry()
  201. grid0.addWidget(self.draw_color_label, 26, 0)
  202. grid0.addWidget(self.draw_color_entry, 26, 1)
  203. # Editor Draw Selection Color
  204. self.sel_draw_color_label = QtWidgets.QLabel('%s:' % _('Selection'))
  205. self.sel_draw_color_label.setToolTip(
  206. _("Set the color of the shape when selected.")
  207. )
  208. self.sel_draw_color_entry = FCColorEntry()
  209. grid0.addWidget(self.sel_draw_color_label, 27, 0)
  210. grid0.addWidget(self.sel_draw_color_entry, 27, 1)
  211. separator_line = QtWidgets.QFrame()
  212. separator_line.setFrameShape(QtWidgets.QFrame.HLine)
  213. separator_line.setFrameShadow(QtWidgets.QFrame.Sunken)
  214. grid0.addWidget(separator_line, 28, 0, 1, 2)
  215. # ------------------------------------------------------------------
  216. # ----------------------- Project Settings -----------------------------
  217. # ------------------------------------------------------------------
  218. self.proj_settings_label = QtWidgets.QLabel('<b>%s</b>' % _('Project Items Color'))
  219. grid0.addWidget(self.proj_settings_label, 29, 0, 1, 2)
  220. # Project Tab items color
  221. self.proj_color_label = QtWidgets.QLabel('%s:' % _('Enabled'))
  222. self.proj_color_label.setToolTip(
  223. _("Set the color of the items in Project Tab Tree.")
  224. )
  225. self.proj_color_entry = FCColorEntry()
  226. grid0.addWidget(self.proj_color_label, 30, 0)
  227. grid0.addWidget(self.proj_color_entry, 30, 1)
  228. self.proj_color_dis_label = QtWidgets.QLabel('%s:' % _('Disabled'))
  229. self.proj_color_dis_label.setToolTip(
  230. _("Set the color of the items in Project Tab Tree,\n"
  231. "for the case when the items are disabled.")
  232. )
  233. self.proj_color_dis_entry = FCColorEntry()
  234. grid0.addWidget(self.proj_color_dis_label, 31, 0)
  235. grid0.addWidget(self.proj_color_dis_entry, 31, 1)
  236. # Project autohide CB
  237. self.project_autohide_cb = FCCheckBox(label=_('Project AutoHide'))
  238. self.project_autohide_cb.setToolTip(
  239. _("Check this box if you want the project/selected/tool tab area to\n"
  240. "hide automatically when there are no objects loaded and\n"
  241. "to show whenever a new object is created.")
  242. )
  243. grid0.addWidget(self.project_autohide_cb, 32, 0, 1, 2)
  244. # Just to add empty rows
  245. grid0.addWidget(QtWidgets.QLabel(''), 33, 0, 1, 2)
  246. self.layout.addStretch()
  247. # #############################################################################
  248. # ############################# GUI COLORS SIGNALS ############################
  249. # #############################################################################
  250. # Setting selection (left - right) colors signals
  251. self.sf_color_entry.editingFinished.connect(self.on_sf_color_entry)
  252. self.sl_color_entry.editingFinished.connect(self.on_sl_color_entry)
  253. self.left_right_alpha_entry.valueChanged.connect(self.on_left_right_alpha_changed) # alpha
  254. # Setting selection (right - left) colors signals
  255. self.alt_sf_color_entry.editingFinished.connect(self.on_alt_sf_color_entry)
  256. self.alt_sl_color_entry.editingFinished.connect(self.on_alt_sl_color_entry)
  257. self.right_left_alpha_entry.valueChanged.connect(self.on_right_left_alpha_changed) # alpha
  258. # Setting Editor Draw colors signals
  259. self.draw_color_entry.editingFinished.connect(self.on_draw_color_entry)
  260. self.sel_draw_color_entry.editingFinished.connect(self.on_sel_draw_color_entry)
  261. self.proj_color_entry.editingFinished.connect(self.on_proj_color_entry)
  262. self.proj_color_dis_entry.editingFinished.connect(self.on_proj_color_dis_entry)
  263. self.layout_combo.activated.connect(self.app.on_layout)
  264. @staticmethod
  265. def handle_style(style):
  266. # set current style
  267. qsettings = QSettings("Open Source", "FlatCAM")
  268. qsettings.setValue('style', style)
  269. # This will write the setting to the platform specific storage.
  270. del qsettings
  271. @staticmethod
  272. def handle_hdpi(state):
  273. # set current HDPI
  274. qsettings = QSettings("Open Source", "FlatCAM")
  275. qsettings.setValue('hdpi', state)
  276. # This will write the setting to the platform specific storage.
  277. del qsettings
  278. # Setting selection colors (left - right) handlers
  279. def on_sf_color_entry(self):
  280. self.app.defaults['global_sel_fill'] = self.app.defaults['global_sel_fill'][7:9]
  281. def on_sl_color_entry(self):
  282. self.app.defaults['global_sel_line'] = self.sl_color_entry.get_value()[:7] + \
  283. self.app.defaults['global_sel_line'][7:9]
  284. def on_left_right_alpha_changed(self, spinner_value):
  285. """
  286. Change the alpha level for the color of the selection box when selection is done left to right.
  287. Called on valueChanged of a FCSliderWithSpinner.
  288. :param spinner_value: passed value within [0, 255]
  289. :type spinner_value: int
  290. :return: None
  291. :rtype:
  292. """
  293. self.app.defaults['global_sel_fill'] = self.app.defaults['global_sel_fill'][:7] + \
  294. (hex(spinner_value)[2:] if int(hex(spinner_value)[2:], 16) > 0 else '00')
  295. self.app.defaults['global_sel_line'] = self.app.defaults['global_sel_line'][:7] + \
  296. (hex(spinner_value)[2:] if int(hex(spinner_value)[2:], 16) > 0 else '00')
  297. # Setting selection colors (right - left) handlers
  298. def on_alt_sf_color_entry(self):
  299. self.app.defaults['global_alt_sel_fill'] = self.alt_sf_color_entry.get_value()[:7] + \
  300. self.app.defaults['global_alt_sel_fill'][7:9]
  301. def on_alt_sl_color_entry(self):
  302. self.app.defaults['global_alt_sel_line'] = self.alt_sl_color_entry.get_value()[:7] + \
  303. self.app.defaults['global_alt_sel_line'][7:9]
  304. def on_right_left_alpha_changed(self, spinner_value):
  305. """
  306. Change the alpha level for the color of the selection box when selection is done right to left.
  307. Called on valueChanged of a FCSliderWithSpinner.
  308. :param spinner_value: passed value within [0, 255]
  309. :type spinner_value: int
  310. :return: None
  311. :rtype:
  312. """
  313. self.app.defaults['global_alt_sel_fill'] = self.app.defaults['global_alt_sel_fill'][:7] + \
  314. (hex(spinner_value)[2:] if int(hex(spinner_value)[2:], 16) > 0 else '00')
  315. self.app.defaults['global_alt_sel_line'] = self.app.defaults['global_alt_sel_line'][:7] + \
  316. (hex(spinner_value)[2:] if int(hex(spinner_value)[2:], 16) > 0 else '00')
  317. # Setting Editor colors
  318. def on_draw_color_entry(self):
  319. self.app.defaults['global_draw_color'] = self.draw_color_entry.get_value()
  320. def on_sel_draw_color_entry(self):
  321. self.app.defaults['global_sel_draw_color'] = self.sel_draw_color_entry.get_value()
  322. def on_proj_color_entry(self):
  323. self.app.defaults['global_proj_item_color'] = self.proj_color_entry.get_value()
  324. def on_proj_color_dis_entry(self):
  325. self.app.defaults['global_proj_item_dis_color'] = self.proj_color_dis_entry.get_value()