GeneralGUIPrefGroupUI.py 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353
  1. from PyQt5 import QtWidgets, QtCore
  2. from PyQt5.QtCore import QSettings, Qt
  3. from flatcamGUI.preferences.OptionsGroupUI import OptionsGroupUI2
  4. import gettext
  5. import FlatCAMTranslation as fcTranslate
  6. import builtins
  7. fcTranslate.apply_language('strings')
  8. if '_' not in builtins.__dict__:
  9. _ = gettext.gettext
  10. from flatcamGUI.preferences.OptionUI import OptionUI, CheckboxOptionUI, RadioSetOptionUI, \
  11. SeparatorOptionUI, HeadingOptionUI, ComboboxOptionUI, ColorOptionUI, FullWidthButtonOptionUI
  12. class GeneralGUIPrefGroupUI2(OptionsGroupUI2):
  13. def __init__(self, decimals=4, **kwargs):
  14. super().__init__(**kwargs)
  15. self.decimals = decimals
  16. self.setTitle(str(_("GUI Preferences 2")))
  17. self.layout_field = self.option_dict()["layout"].get_field()
  18. self.layout_field.activated.connect(self.on_layout)
  19. self.theme_field = self.option_dict()["global_theme"].get_field()
  20. self.theme_apply_button = self.option_dict()["__button_apply_theme"].get_field()
  21. self.theme_apply_button.clicked.connect(self.on_theme_change)
  22. self.style_field = self.option_dict()["style"].get_field()
  23. current_style_index = self.style_field.findText(QtWidgets.qApp.style().objectName(), QtCore.Qt.MatchFixedString)
  24. self.style_field.setCurrentIndex(current_style_index)
  25. self.style_field.activated[str].connect(self.handle_style)
  26. self.hdpi_field = self.option_dict()["hdpi"].get_field()
  27. qsettings = QSettings("Open Source", "FlatCAM")
  28. if qsettings.contains("hdpi"):
  29. self.hdpi_field.set_value(qsettings.value('hdpi', type=int))
  30. else:
  31. self.hdpi_field.set_value(False)
  32. self.hdpi_field.stateChanged.connect(self.handle_hdpi)
  33. def build_options(self) -> [OptionUI]:
  34. return [
  35. RadioSetOptionUI(
  36. option="global_theme",
  37. label_text="Theme",
  38. label_tooltip="Select a theme for FlatCAM.\nIt will theme the plot area.",
  39. choices=[
  40. {"label": _("Light"), "value": "white"},
  41. {"label": _("Dark"), "value": "black"}
  42. ],
  43. orientation='vertical'
  44. ),
  45. CheckboxOptionUI(
  46. option="global_gray_icons",
  47. label_text="Use Gray Icons",
  48. label_tooltip="Check this box to use a set of icons with\na lighter (gray) color. To be used when a\nfull dark theme is applied."
  49. ),
  50. FullWidthButtonOptionUI(
  51. option="__button_apply_theme",
  52. label_text="Apply Theme",
  53. label_tooltip="Select a theme for FlatCAM.\n"
  54. "It will theme the plot area.\n"
  55. "The application will restart after change."
  56. ),
  57. SeparatorOptionUI(),
  58. ComboboxOptionUI(
  59. option="layout",
  60. label_text="Layout",
  61. label_tooltip="Select an layout for FlatCAM.\nIt is applied immediately.",
  62. choices=[
  63. "standard",
  64. "compact",
  65. "minimal"
  66. ]
  67. ),
  68. ComboboxOptionUI(
  69. option="style",
  70. label_text="Style",
  71. label_tooltip="Select an style for FlatCAM.\nIt will be applied at the next app start.",
  72. choices=QtWidgets.QStyleFactory.keys()
  73. ),
  74. CheckboxOptionUI(
  75. option="hdpi",
  76. label_text='Activate HDPI Support',
  77. label_tooltip="Enable High DPI support for FlatCAM.\nIt will be applied at the next app start.",
  78. ),
  79. CheckboxOptionUI(
  80. option="global_hover",
  81. label_text='Display Hover Shape',
  82. label_tooltip="Enable display of a hover shape for FlatCAM objects.\nIt is displayed whenever the mouse cursor is hovering\nover any kind of not-selected object.",
  83. ),
  84. CheckboxOptionUI(
  85. option="global_selection_shape",
  86. label_text='Display Selection Shape',
  87. label_tooltip="Enable the display of a selection shape for FlatCAM objects.\n"
  88. "It is displayed whenever the mouse selects an object\n"
  89. "either by clicking or dragging mouse from left to right or\n"
  90. "right to left."
  91. ),
  92. SeparatorOptionUI(),
  93. HeadingOptionUI(label_text="Left-Right Selection Color", label_tooltip=None),
  94. ColorOptionUI(
  95. option="global_sel_line",
  96. label_text="Outline",
  97. label_tooltip="Set the line color for the 'left to right' selection box."
  98. ),
  99. ColorOptionUI(
  100. option="global_sel_fill",
  101. label_text="Fill",
  102. label_tooltip="Set the fill color for the selection box\n"
  103. "in case that the selection is done from left to right.\n"
  104. "First 6 digits are the color and the last 2\n"
  105. "digits are for alpha (transparency) level."
  106. ),
  107. HeadingOptionUI(label_text="Right-Left Selection Color", label_tooltip=None),
  108. ColorOptionUI(
  109. option="global_alt_sel_line",
  110. label_text="Outline",
  111. label_tooltip="Set the line color for the 'right to left' selection box."
  112. ),
  113. ColorOptionUI(
  114. option="global_alt_sel_fill",
  115. label_text="Fill",
  116. label_tooltip="Set the fill color for the selection box\n"
  117. "in case that the selection is done from right to left.\n"
  118. "First 6 digits are the color and the last 2\n"
  119. "digits are for alpha (transparency) level."
  120. ),
  121. # FIXME: opacity slider?
  122. SeparatorOptionUI(),
  123. HeadingOptionUI(label_text='Editor Color', label_tooltip=None),
  124. ColorOptionUI(
  125. option="global_draw_color",
  126. label_text="Drawing",
  127. label_tooltip="Set the color for the shape."
  128. ),
  129. ColorOptionUI(
  130. option="global_sel_draw_color",
  131. label_text="Selection",
  132. label_tooltip="Set the color of the shape when selected."
  133. ),
  134. SeparatorOptionUI(),
  135. HeadingOptionUI(label_text='Project Items Color', label_tooltip=None),
  136. ColorOptionUI(
  137. option="global_proj_item_color",
  138. label_text="Enabled",
  139. label_tooltip="Set the color of the items in Project Tab Tree."
  140. ),
  141. ColorOptionUI(
  142. option="global_proj_item_dis_color",
  143. label_text="Disabled",
  144. label_tooltip="Set the color of the items in Project Tab Tree,\n"
  145. "for the case when the items are disabled."
  146. ),
  147. CheckboxOptionUI(
  148. option="global_project_autohide",
  149. label_text="Project AutoHide",
  150. label_tooltip="Check this box if you want the project/selected/tool tab area to\n"
  151. "hide automatically when there are no objects loaded and\n"
  152. "to show whenever a new object is created."
  153. ),
  154. ]
  155. def on_theme_change(self):
  156. # FIXME: this should be moved out to a view model
  157. val = self.theme_field.get_value()
  158. qsettings = QSettings("Open Source", "FlatCAM")
  159. qsettings.setValue("theme", val)
  160. # This will write the setting to the platform specific storage.
  161. del qsettings
  162. self.app.on_app_restart()
  163. def on_layout(self, index=None, lay=None):
  164. # FIXME: this should be moved out somewhere else
  165. """
  166. Set the toolbars layout (location)
  167. :param index:
  168. :param lay: Type of layout to be set on the toolbard
  169. :return: None
  170. """
  171. self.app.defaults.report_usage("on_layout()")
  172. if lay:
  173. current_layout = lay
  174. else:
  175. current_layout = self.layout_field.get_value()
  176. lay_settings = QSettings("Open Source", "FlatCAM")
  177. lay_settings.setValue('layout', current_layout)
  178. # This will write the setting to the platform specific storage.
  179. del lay_settings
  180. # first remove the toolbars:
  181. try:
  182. self.app.ui.removeToolBar(self.app.ui.toolbarfile)
  183. self.app.ui.removeToolBar(self.app.ui.toolbargeo)
  184. self.app.ui.removeToolBar(self.app.ui.toolbarview)
  185. self.app.ui.removeToolBar(self.app.ui.toolbarshell)
  186. self.app.ui.removeToolBar(self.app.ui.toolbartools)
  187. self.app.ui.removeToolBar(self.app.ui.exc_edit_toolbar)
  188. self.app.ui.removeToolBar(self.app.ui.geo_edit_toolbar)
  189. self.app.ui.removeToolBar(self.app.ui.grb_edit_toolbar)
  190. self.app.ui.removeToolBar(self.app.ui.snap_toolbar)
  191. self.app.ui.removeToolBar(self.app.ui.toolbarshell)
  192. except Exception:
  193. pass
  194. if current_layout == 'compact':
  195. # ## TOOLBAR INSTALLATION # ##
  196. self.app.ui.toolbarfile = QtWidgets.QToolBar('File Toolbar')
  197. self.app.ui.toolbarfile.setObjectName('File_TB')
  198. self.app.ui.addToolBar(Qt.LeftToolBarArea, self.app.ui.toolbarfile)
  199. self.app.ui.toolbargeo = QtWidgets.QToolBar('Edit Toolbar')
  200. self.app.ui.toolbargeo.setObjectName('Edit_TB')
  201. self.app.ui.addToolBar(Qt.LeftToolBarArea, self.app.ui.toolbargeo)
  202. self.app.ui.toolbarshell = QtWidgets.QToolBar('Shell Toolbar')
  203. self.app.ui.toolbarshell.setObjectName('Shell_TB')
  204. self.app.ui.addToolBar(Qt.LeftToolBarArea, self.app.ui.toolbarshell)
  205. self.app.ui.toolbartools = QtWidgets.QToolBar('Tools Toolbar')
  206. self.app.ui.toolbartools.setObjectName('Tools_TB')
  207. self.app.ui.addToolBar(Qt.LeftToolBarArea, self.app.ui.toolbartools)
  208. self.app.ui.geo_edit_toolbar = QtWidgets.QToolBar('Geometry Editor Toolbar')
  209. # self.app.ui.geo_edit_toolbar.setVisible(False)
  210. self.app.ui.geo_edit_toolbar.setObjectName('GeoEditor_TB')
  211. self.app.ui.addToolBar(Qt.RightToolBarArea, self.app.ui.geo_edit_toolbar)
  212. self.app.ui.toolbarview = QtWidgets.QToolBar('View Toolbar')
  213. self.app.ui.toolbarview.setObjectName('View_TB')
  214. self.app.ui.addToolBar(Qt.RightToolBarArea, self.app.ui.toolbarview)
  215. self.app.ui.addToolBarBreak(area=Qt.RightToolBarArea)
  216. self.app.ui.grb_edit_toolbar = QtWidgets.QToolBar('Gerber Editor Toolbar')
  217. # self.app.ui.grb_edit_toolbar.setVisible(False)
  218. self.app.ui.grb_edit_toolbar.setObjectName('GrbEditor_TB')
  219. self.app.ui.addToolBar(Qt.RightToolBarArea, self.app.ui.grb_edit_toolbar)
  220. self.app.ui.exc_edit_toolbar = QtWidgets.QToolBar('Excellon Editor Toolbar')
  221. self.app.ui.exc_edit_toolbar.setObjectName('ExcEditor_TB')
  222. self.app.ui.addToolBar(Qt.RightToolBarArea, self.app.ui.exc_edit_toolbar)
  223. self.app.ui.snap_toolbar = QtWidgets.QToolBar('Grid Toolbar')
  224. self.app.ui.snap_toolbar.setObjectName('Snap_TB')
  225. self.app.ui.snap_toolbar.setMaximumHeight(30)
  226. self.app.ui.splitter_left.addWidget(self.app.ui.snap_toolbar)
  227. self.app.ui.corner_snap_btn.setVisible(True)
  228. self.app.ui.snap_magnet.setVisible(True)
  229. else:
  230. # ## TOOLBAR INSTALLATION # ##
  231. self.app.ui.toolbarfile = QtWidgets.QToolBar('File Toolbar')
  232. self.app.ui.toolbarfile.setObjectName('File_TB')
  233. self.app.ui.addToolBar(self.app.ui.toolbarfile)
  234. self.app.ui.toolbargeo = QtWidgets.QToolBar('Edit Toolbar')
  235. self.app.ui.toolbargeo.setObjectName('Edit_TB')
  236. self.app.ui.addToolBar(self.app.ui.toolbargeo)
  237. self.app.ui.toolbarview = QtWidgets.QToolBar('View Toolbar')
  238. self.app.ui.toolbarview.setObjectName('View_TB')
  239. self.app.ui.addToolBar(self.app.ui.toolbarview)
  240. self.app.ui.toolbarshell = QtWidgets.QToolBar('Shell Toolbar')
  241. self.app.ui.toolbarshell.setObjectName('Shell_TB')
  242. self.app.ui.addToolBar(self.app.ui.toolbarshell)
  243. self.app.ui.toolbartools = QtWidgets.QToolBar('Tools Toolbar')
  244. self.app.ui.toolbartools.setObjectName('Tools_TB')
  245. self.app.ui.addToolBar(self.app.ui.toolbartools)
  246. self.app.ui.exc_edit_toolbar = QtWidgets.QToolBar('Excellon Editor Toolbar')
  247. # self.app.ui.exc_edit_toolbar.setVisible(False)
  248. self.app.ui.exc_edit_toolbar.setObjectName('ExcEditor_TB')
  249. self.app.ui.addToolBar(self.app.ui.exc_edit_toolbar)
  250. self.app.ui.addToolBarBreak()
  251. self.app.ui.geo_edit_toolbar = QtWidgets.QToolBar('Geometry Editor Toolbar')
  252. # self.app.ui.geo_edit_toolbar.setVisible(False)
  253. self.app.ui.geo_edit_toolbar.setObjectName('GeoEditor_TB')
  254. self.app.ui.addToolBar(self.app.ui.geo_edit_toolbar)
  255. self.app.ui.grb_edit_toolbar = QtWidgets.QToolBar('Gerber Editor Toolbar')
  256. # self.app.ui.grb_edit_toolbar.setVisible(False)
  257. self.app.ui.grb_edit_toolbar.setObjectName('GrbEditor_TB')
  258. self.app.ui.addToolBar(self.app.ui.grb_edit_toolbar)
  259. self.app.ui.snap_toolbar = QtWidgets.QToolBar('Grid Toolbar')
  260. self.app.ui.snap_toolbar.setObjectName('Snap_TB')
  261. # self.app.ui.snap_toolbar.setMaximumHeight(30)
  262. self.app.ui.addToolBar(self.app.ui.snap_toolbar)
  263. self.app.ui.corner_snap_btn.setVisible(False)
  264. self.app.ui.snap_magnet.setVisible(False)
  265. if current_layout == 'minimal':
  266. self.app.ui.toolbarview.setVisible(False)
  267. self.app.ui.toolbarshell.setVisible(False)
  268. self.app.ui.snap_toolbar.setVisible(False)
  269. self.app.ui.geo_edit_toolbar.setVisible(False)
  270. self.app.ui.grb_edit_toolbar.setVisible(False)
  271. self.app.ui.exc_edit_toolbar.setVisible(False)
  272. self.app.ui.lock_toolbar(lock=True)
  273. # add all the actions to the toolbars
  274. self.app.ui.populate_toolbars()
  275. # reconnect all the signals to the toolbar actions
  276. self.app.connect_toolbar_signals()
  277. self.app.ui.grid_snap_btn.setChecked(True)
  278. self.app.on_grid_snap_triggered(state=True)
  279. self.app.ui.grid_gap_x_entry.setText(str(self.app.defaults["global_gridx"]))
  280. self.app.ui.grid_gap_y_entry.setText(str(self.app.defaults["global_gridy"]))
  281. self.app.ui.snap_max_dist_entry.setText(str(self.app.defaults["global_snap_max"]))
  282. self.app.ui.grid_gap_link_cb.setChecked(True)
  283. @staticmethod
  284. def handle_style(style):
  285. # FIXME: this should be moved out to a view model
  286. # set current style
  287. qsettings = QSettings("Open Source", "FlatCAM")
  288. qsettings.setValue('style', style)
  289. # This will write the setting to the platform specific storage.
  290. del qsettings
  291. @staticmethod
  292. def handle_hdpi(state):
  293. # FIXME: this should be moved out to a view model
  294. # set current HDPI
  295. qsettings = QSettings("Open Source", "FlatCAM")
  296. qsettings.setValue('hdpi', state)
  297. # This will write the setting to the platform specific storage.
  298. del qsettings