GeneralGUIPrefGroupUI.py 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355
  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 GeneralGUIPrefGroupUI(OptionsGroupUI2):
  13. def __init__(self, decimals=4, **kwargs):
  14. super().__init__(**kwargs)
  15. self.decimals = decimals
  16. self.setTitle(str(_("GUI Preferences")))
  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. # FIXME: opacity slider?
  108. SeparatorOptionUI(),
  109. HeadingOptionUI(label_text="Right-Left Selection Color", label_tooltip=None),
  110. ColorOptionUI(
  111. option="global_alt_sel_line",
  112. label_text="Outline",
  113. label_tooltip="Set the line color for the 'right to left' selection box."
  114. ),
  115. ColorOptionUI(
  116. option="global_alt_sel_fill",
  117. label_text="Fill",
  118. label_tooltip="Set the fill color for the selection box\n"
  119. "in case that the selection is done from right to left.\n"
  120. "First 6 digits are the color and the last 2\n"
  121. "digits are for alpha (transparency) level."
  122. ),
  123. # FIXME: opacity slider?
  124. SeparatorOptionUI(),
  125. HeadingOptionUI(label_text='Editor Color', label_tooltip=None),
  126. ColorOptionUI(
  127. option="global_draw_color",
  128. label_text="Drawing",
  129. label_tooltip="Set the color for the shape."
  130. ),
  131. ColorOptionUI(
  132. option="global_sel_draw_color",
  133. label_text="Selection",
  134. label_tooltip="Set the color of the shape when selected."
  135. ),
  136. SeparatorOptionUI(),
  137. HeadingOptionUI(label_text='Project Items Color', label_tooltip=None),
  138. ColorOptionUI(
  139. option="global_proj_item_color",
  140. label_text="Enabled",
  141. label_tooltip="Set the color of the items in Project Tab Tree."
  142. ),
  143. ColorOptionUI(
  144. option="global_proj_item_dis_color",
  145. label_text="Disabled",
  146. label_tooltip="Set the color of the items in Project Tab Tree,\n"
  147. "for the case when the items are disabled."
  148. ),
  149. CheckboxOptionUI(
  150. option="global_project_autohide",
  151. label_text="Project AutoHide",
  152. label_tooltip="Check this box if you want the project/selected/tool tab area to\n"
  153. "hide automatically when there are no objects loaded and\n"
  154. "to show whenever a new object is created."
  155. ),
  156. ]
  157. def on_theme_change(self):
  158. # FIXME: this should be moved out to a view model
  159. val = self.theme_field.get_value()
  160. qsettings = QSettings("Open Source", "FlatCAM")
  161. qsettings.setValue("theme", val)
  162. # This will write the setting to the platform specific storage.
  163. del qsettings
  164. self.app.on_app_restart()
  165. def on_layout(self, index=None, lay=None):
  166. # FIXME: this should be moved out somewhere else
  167. """
  168. Set the toolbars layout (location)
  169. :param index:
  170. :param lay: Type of layout to be set on the toolbard
  171. :return: None
  172. """
  173. self.app.defaults.report_usage("on_layout()")
  174. if lay:
  175. current_layout = lay
  176. else:
  177. current_layout = self.layout_field.get_value()
  178. lay_settings = QSettings("Open Source", "FlatCAM")
  179. lay_settings.setValue('layout', current_layout)
  180. # This will write the setting to the platform specific storage.
  181. del lay_settings
  182. # first remove the toolbars:
  183. try:
  184. self.app.ui.removeToolBar(self.app.ui.toolbarfile)
  185. self.app.ui.removeToolBar(self.app.ui.toolbargeo)
  186. self.app.ui.removeToolBar(self.app.ui.toolbarview)
  187. self.app.ui.removeToolBar(self.app.ui.toolbarshell)
  188. self.app.ui.removeToolBar(self.app.ui.toolbartools)
  189. self.app.ui.removeToolBar(self.app.ui.exc_edit_toolbar)
  190. self.app.ui.removeToolBar(self.app.ui.geo_edit_toolbar)
  191. self.app.ui.removeToolBar(self.app.ui.grb_edit_toolbar)
  192. self.app.ui.removeToolBar(self.app.ui.snap_toolbar)
  193. self.app.ui.removeToolBar(self.app.ui.toolbarshell)
  194. except Exception:
  195. pass
  196. if current_layout == 'compact':
  197. # ## TOOLBAR INSTALLATION # ##
  198. self.app.ui.toolbarfile = QtWidgets.QToolBar('File Toolbar')
  199. self.app.ui.toolbarfile.setObjectName('File_TB')
  200. self.app.ui.addToolBar(Qt.LeftToolBarArea, self.app.ui.toolbarfile)
  201. self.app.ui.toolbargeo = QtWidgets.QToolBar('Edit Toolbar')
  202. self.app.ui.toolbargeo.setObjectName('Edit_TB')
  203. self.app.ui.addToolBar(Qt.LeftToolBarArea, self.app.ui.toolbargeo)
  204. self.app.ui.toolbarshell = QtWidgets.QToolBar('Shell Toolbar')
  205. self.app.ui.toolbarshell.setObjectName('Shell_TB')
  206. self.app.ui.addToolBar(Qt.LeftToolBarArea, self.app.ui.toolbarshell)
  207. self.app.ui.toolbartools = QtWidgets.QToolBar('Tools Toolbar')
  208. self.app.ui.toolbartools.setObjectName('Tools_TB')
  209. self.app.ui.addToolBar(Qt.LeftToolBarArea, self.app.ui.toolbartools)
  210. self.app.ui.geo_edit_toolbar = QtWidgets.QToolBar('Geometry Editor Toolbar')
  211. # self.app.ui.geo_edit_toolbar.setVisible(False)
  212. self.app.ui.geo_edit_toolbar.setObjectName('GeoEditor_TB')
  213. self.app.ui.addToolBar(Qt.RightToolBarArea, self.app.ui.geo_edit_toolbar)
  214. self.app.ui.toolbarview = QtWidgets.QToolBar('View Toolbar')
  215. self.app.ui.toolbarview.setObjectName('View_TB')
  216. self.app.ui.addToolBar(Qt.RightToolBarArea, self.app.ui.toolbarview)
  217. self.app.ui.addToolBarBreak(area=Qt.RightToolBarArea)
  218. self.app.ui.grb_edit_toolbar = QtWidgets.QToolBar('Gerber Editor Toolbar')
  219. # self.app.ui.grb_edit_toolbar.setVisible(False)
  220. self.app.ui.grb_edit_toolbar.setObjectName('GrbEditor_TB')
  221. self.app.ui.addToolBar(Qt.RightToolBarArea, self.app.ui.grb_edit_toolbar)
  222. self.app.ui.exc_edit_toolbar = QtWidgets.QToolBar('Excellon Editor Toolbar')
  223. self.app.ui.exc_edit_toolbar.setObjectName('ExcEditor_TB')
  224. self.app.ui.addToolBar(Qt.RightToolBarArea, self.app.ui.exc_edit_toolbar)
  225. self.app.ui.snap_toolbar = QtWidgets.QToolBar('Grid Toolbar')
  226. self.app.ui.snap_toolbar.setObjectName('Snap_TB')
  227. self.app.ui.snap_toolbar.setMaximumHeight(30)
  228. self.app.ui.splitter_left.addWidget(self.app.ui.snap_toolbar)
  229. self.app.ui.corner_snap_btn.setVisible(True)
  230. self.app.ui.snap_magnet.setVisible(True)
  231. else:
  232. # ## TOOLBAR INSTALLATION # ##
  233. self.app.ui.toolbarfile = QtWidgets.QToolBar('File Toolbar')
  234. self.app.ui.toolbarfile.setObjectName('File_TB')
  235. self.app.ui.addToolBar(self.app.ui.toolbarfile)
  236. self.app.ui.toolbargeo = QtWidgets.QToolBar('Edit Toolbar')
  237. self.app.ui.toolbargeo.setObjectName('Edit_TB')
  238. self.app.ui.addToolBar(self.app.ui.toolbargeo)
  239. self.app.ui.toolbarview = QtWidgets.QToolBar('View Toolbar')
  240. self.app.ui.toolbarview.setObjectName('View_TB')
  241. self.app.ui.addToolBar(self.app.ui.toolbarview)
  242. self.app.ui.toolbarshell = QtWidgets.QToolBar('Shell Toolbar')
  243. self.app.ui.toolbarshell.setObjectName('Shell_TB')
  244. self.app.ui.addToolBar(self.app.ui.toolbarshell)
  245. self.app.ui.toolbartools = QtWidgets.QToolBar('Tools Toolbar')
  246. self.app.ui.toolbartools.setObjectName('Tools_TB')
  247. self.app.ui.addToolBar(self.app.ui.toolbartools)
  248. self.app.ui.exc_edit_toolbar = QtWidgets.QToolBar('Excellon Editor Toolbar')
  249. # self.app.ui.exc_edit_toolbar.setVisible(False)
  250. self.app.ui.exc_edit_toolbar.setObjectName('ExcEditor_TB')
  251. self.app.ui.addToolBar(self.app.ui.exc_edit_toolbar)
  252. self.app.ui.addToolBarBreak()
  253. self.app.ui.geo_edit_toolbar = QtWidgets.QToolBar('Geometry Editor Toolbar')
  254. # self.app.ui.geo_edit_toolbar.setVisible(False)
  255. self.app.ui.geo_edit_toolbar.setObjectName('GeoEditor_TB')
  256. self.app.ui.addToolBar(self.app.ui.geo_edit_toolbar)
  257. self.app.ui.grb_edit_toolbar = QtWidgets.QToolBar('Gerber Editor Toolbar')
  258. # self.app.ui.grb_edit_toolbar.setVisible(False)
  259. self.app.ui.grb_edit_toolbar.setObjectName('GrbEditor_TB')
  260. self.app.ui.addToolBar(self.app.ui.grb_edit_toolbar)
  261. self.app.ui.snap_toolbar = QtWidgets.QToolBar('Grid Toolbar')
  262. self.app.ui.snap_toolbar.setObjectName('Snap_TB')
  263. # self.app.ui.snap_toolbar.setMaximumHeight(30)
  264. self.app.ui.addToolBar(self.app.ui.snap_toolbar)
  265. self.app.ui.corner_snap_btn.setVisible(False)
  266. self.app.ui.snap_magnet.setVisible(False)
  267. if current_layout == 'minimal':
  268. self.app.ui.toolbarview.setVisible(False)
  269. self.app.ui.toolbarshell.setVisible(False)
  270. self.app.ui.snap_toolbar.setVisible(False)
  271. self.app.ui.geo_edit_toolbar.setVisible(False)
  272. self.app.ui.grb_edit_toolbar.setVisible(False)
  273. self.app.ui.exc_edit_toolbar.setVisible(False)
  274. self.app.ui.lock_toolbar(lock=True)
  275. # add all the actions to the toolbars
  276. self.app.ui.populate_toolbars()
  277. # reconnect all the signals to the toolbar actions
  278. self.app.connect_toolbar_signals()
  279. self.app.ui.grid_snap_btn.setChecked(True)
  280. self.app.on_grid_snap_triggered(state=True)
  281. self.app.ui.grid_gap_x_entry.setText(str(self.app.defaults["global_gridx"]))
  282. self.app.ui.grid_gap_y_entry.setText(str(self.app.defaults["global_gridy"]))
  283. self.app.ui.snap_max_dist_entry.setText(str(self.app.defaults["global_snap_max"]))
  284. self.app.ui.grid_gap_link_cb.setChecked(True)
  285. @staticmethod
  286. def handle_style(style):
  287. # FIXME: this should be moved out to a view model
  288. # set current style
  289. qsettings = QSettings("Open Source", "FlatCAM")
  290. qsettings.setValue('style', style)
  291. # This will write the setting to the platform specific storage.
  292. del qsettings
  293. @staticmethod
  294. def handle_hdpi(state):
  295. # FIXME: this should be moved out to a view model
  296. # set current HDPI
  297. qsettings = QSettings("Open Source", "FlatCAM")
  298. qsettings.setValue('hdpi', state)
  299. # This will write the setting to the platform specific storage.
  300. del qsettings