GeneralGUIPrefGroupUI.py 41 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935
  1. from PyQt5 import QtWidgets, QtCore, QtGui
  2. from PyQt5.QtCore import QSettings, Qt
  3. from flatcamGUI.GUIElements import RadioSet, FCCheckBox, FCButton, FCComboBox, FCEntry, FCSpinner
  4. from flatcamGUI.preferences.OptionsGroupUI import OptionsGroupUI, OptionsGroupUI2
  5. import gettext
  6. import FlatCAMTranslation as fcTranslate
  7. import builtins
  8. from flatcamGUI.preferences.OptionUI import OptionUI, BasicOptionUI, CheckboxOptionUI, RadioSetOptionUI, \
  9. SeparatorOptionUI, HeadingOptionUI, ComboboxOptionUI, ColorOptionUI, FullWidthButtonOptionUI
  10. fcTranslate.apply_language('strings')
  11. if '_' not in builtins.__dict__:
  12. _ = gettext.gettext
  13. settings = QSettings("Open Source", "FlatCAM")
  14. if settings.contains("machinist"):
  15. machinist_setting = settings.value('machinist', type=int)
  16. else:
  17. machinist_setting = 0
  18. class GeneralGUIPrefGroupUI2(OptionsGroupUI2):
  19. def __init__(self, decimals=4, **kwargs):
  20. super().__init__(**kwargs)
  21. self.decimals = decimals
  22. self.setTitle(str(_("GUI Preferences 2")))
  23. def build_options(self) -> [OptionUI]:
  24. return [
  25. RadioSetOptionUI(
  26. option="global_theme",
  27. label_text="Theme",
  28. label_tooltip="Select a theme for FlatCAM.\nIt will theme the plot area.",
  29. choices=[
  30. {"label": _("Light"), "value": "white"},
  31. {"label": _("Dark"), "value": "black"}
  32. ],
  33. orientation='vertical'
  34. ),
  35. CheckboxOptionUI(
  36. option="global_gray_icons",
  37. label_text="Use Gray Icons",
  38. 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."
  39. ),
  40. FullWidthButtonOptionUI(
  41. option="__button_apply_theme",
  42. label_text="Apply Theme",
  43. label_tooltip="Select a theme for FlatCAM.\n"
  44. "It will theme the plot area.\n"
  45. "The application will restart after change."
  46. ),
  47. SeparatorOptionUI(),
  48. ComboboxOptionUI(
  49. # FIXME!
  50. option="layout",
  51. label_text="Layout",
  52. label_tooltip="Select an layout for FlatCAM.\nIt is applied immediately.",
  53. choices=[
  54. "standard",
  55. "compact",
  56. "minimal"
  57. ]
  58. ),
  59. ComboboxOptionUI(
  60. #FIXME!
  61. option="style",
  62. label_text="Style",
  63. label_tooltip="Select an style for FlatCAM.\nIt will be applied at the next app start.",
  64. choices=QtWidgets.QStyleFactory.keys()
  65. ),
  66. CheckboxOptionUI(
  67. # FIXME
  68. option="hdpi",
  69. label_text='Activate HDPI Support',
  70. label_tooltip="Enable High DPI support for FlatCAM.\nIt will be applied at the next app start.",
  71. ),
  72. CheckboxOptionUI(
  73. option="global_hover",
  74. label_text='Display Hover Shape',
  75. 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.",
  76. ),
  77. CheckboxOptionUI(
  78. option="global_selection_shape",
  79. label_text='Display Selection Shape',
  80. label_tooltip="Enable the display of a selection shape for FlatCAM objects.\n"
  81. "It is displayed whenever the mouse selects an object\n"
  82. "either by clicking or dragging mouse from left to right or\n"
  83. "right to left."
  84. ),
  85. SeparatorOptionUI(),
  86. HeadingOptionUI(label_text="Left-Right Selection Color", label_tooltip=None),
  87. ColorOptionUI(
  88. option="global_sel_line",
  89. label_text="Outline",
  90. label_tooltip="Set the line color for the 'left to right' selection box."
  91. ),
  92. ColorOptionUI(
  93. option="global_sel_fill",
  94. label_text="Fill",
  95. label_tooltip="Set the fill color for the selection box\n"
  96. "in case that the selection is done from left to right.\n"
  97. "First 6 digits are the color and the last 2\n"
  98. "digits are for alpha (transparency) level."
  99. ),
  100. HeadingOptionUI(label_text="Right-Left Selection Color", label_tooltip=None),
  101. ColorOptionUI(
  102. option="global_alt_sel_line",
  103. label_text="Outline",
  104. label_tooltip="Set the line color for the 'right to left' selection box."
  105. ),
  106. ColorOptionUI(
  107. option="global_alt_sel_fill",
  108. label_text="Fill",
  109. label_tooltip="Set the fill color for the selection box\n"
  110. "in case that the selection is done from right to left.\n"
  111. "First 6 digits are the color and the last 2\n"
  112. "digits are for alpha (transparency) level."
  113. ),
  114. # FIXME: opacity slider?
  115. SeparatorOptionUI(),
  116. HeadingOptionUI(label_text='Editor Color', label_tooltip=None),
  117. ColorOptionUI(
  118. option="global_draw_color",
  119. label_text="Drawing",
  120. label_tooltip="Set the color for the shape."
  121. ),
  122. ColorOptionUI(
  123. option="global_sel_draw_color",
  124. label_text="Selection",
  125. label_tooltip="Set the color of the shape when selected."
  126. ),
  127. SeparatorOptionUI(),
  128. HeadingOptionUI(label_text='Project Items Color', label_tooltip=None),
  129. ColorOptionUI(
  130. option="global_proj_item_color",
  131. label_text="Enabled",
  132. label_tooltip="Set the color of the items in Project Tab Tree."
  133. ),
  134. ColorOptionUI(
  135. option="global_proj_item_dis_color",
  136. label_text="Disabled",
  137. label_tooltip="Set the color of the items in Project Tab Tree,\n"
  138. "for the case when the items are disabled."
  139. ),
  140. CheckboxOptionUI(
  141. option="global_project_autohide",
  142. label_text="Project AutoHide",
  143. label_tooltip="Check this box if you want the project/selected/tool tab area to\n"
  144. "hide automatically when there are no objects loaded and\n"
  145. "to show whenever a new object is created."
  146. ),
  147. ]
  148. class GeneralGUIPrefGroupUI(OptionsGroupUI):
  149. def __init__(self, decimals=4, **kwargs):
  150. # region Description
  151. super().__init__(**kwargs)
  152. self.setTitle(str(_("GUI Preferences")))
  153. self.decimals = decimals
  154. # Create a grid layout for the Application general settings
  155. grid0 = QtWidgets.QGridLayout()
  156. self.layout.addLayout(grid0)
  157. grid0.setColumnStretch(0, 0)
  158. grid0.setColumnStretch(1, 1)
  159. # Theme selection
  160. self.theme_label = QtWidgets.QLabel('%s:' % _('Theme'))
  161. self.theme_label.setToolTip(
  162. _("Select a theme for FlatCAM.\n"
  163. "It will theme the plot area.")
  164. )
  165. self.theme_radio = RadioSet([
  166. {"label": _("Light"), "value": "white"},
  167. {"label": _("Dark"), "value": "black"}
  168. ], orientation='vertical')
  169. grid0.addWidget(self.theme_label, 0, 0)
  170. grid0.addWidget(self.theme_radio, 0, 1)
  171. # Enable Gray Icons
  172. self.gray_icons_cb = FCCheckBox('%s' % _('Use Gray Icons'))
  173. self.gray_icons_cb.setToolTip(
  174. _("Check this box to use a set of icons with\n"
  175. "a lighter (gray) color. To be used when a\n"
  176. "full dark theme is applied.")
  177. )
  178. grid0.addWidget(self.gray_icons_cb, 1, 0, 1, 3)
  179. self.theme_button = FCButton(_("Apply Theme"))
  180. self.theme_button.setToolTip(
  181. _("Select a theme for FlatCAM.\n"
  182. "It will theme the plot area.\n"
  183. "The application will restart after change.")
  184. )
  185. grid0.addWidget(self.theme_button, 2, 0, 1, 3)
  186. separator_line = QtWidgets.QFrame()
  187. separator_line.setFrameShape(QtWidgets.QFrame.HLine)
  188. separator_line.setFrameShadow(QtWidgets.QFrame.Sunken)
  189. grid0.addWidget(separator_line, 3, 0, 1, 2)
  190. # Layout selection
  191. self.layout_label = QtWidgets.QLabel('%s:' % _('Layout'))
  192. self.layout_label.setToolTip(
  193. _("Select an layout for FlatCAM.\n"
  194. "It is applied immediately.")
  195. )
  196. self.layout_combo = FCComboBox()
  197. # don't translate the QCombo items as they are used in QSettings and identified by name
  198. self.layout_combo.addItem("standard")
  199. self.layout_combo.addItem("compact")
  200. self.layout_combo.addItem("minimal")
  201. grid0.addWidget(self.layout_label, 4, 0)
  202. grid0.addWidget(self.layout_combo, 4, 1)
  203. # Set the current index for layout_combo
  204. qsettings = QSettings("Open Source", "FlatCAM")
  205. if qsettings.contains("layout"):
  206. layout = qsettings.value('layout', type=str)
  207. idx = self.layout_combo.findText(layout.capitalize())
  208. self.layout_combo.setCurrentIndex(idx)
  209. # Style selection
  210. self.style_label = QtWidgets.QLabel('%s:' % _('Style'))
  211. self.style_label.setToolTip(
  212. _("Select an style for FlatCAM.\n"
  213. "It will be applied at the next app start.")
  214. )
  215. self.style_combo = FCComboBox()
  216. self.style_combo.addItems(QtWidgets.QStyleFactory.keys())
  217. # find current style
  218. index = self.style_combo.findText(QtWidgets.qApp.style().objectName(), QtCore.Qt.MatchFixedString)
  219. self.style_combo.setCurrentIndex(index)
  220. self.style_combo.activated[str].connect(self.handle_style)
  221. grid0.addWidget(self.style_label, 5, 0)
  222. grid0.addWidget(self.style_combo, 5, 1)
  223. # Enable High DPI Support
  224. self.hdpi_cb = FCCheckBox('%s' % _('Activate HDPI Support'))
  225. self.hdpi_cb.setToolTip(
  226. _("Enable High DPI support for FlatCAM.\n"
  227. "It will be applied at the next app start.")
  228. )
  229. qsettings = QSettings("Open Source", "FlatCAM")
  230. if qsettings.contains("hdpi"):
  231. self.hdpi_cb.set_value(qsettings.value('hdpi', type=int))
  232. else:
  233. self.hdpi_cb.set_value(False)
  234. self.hdpi_cb.stateChanged.connect(self.handle_hdpi)
  235. grid0.addWidget(self.hdpi_cb, 6, 0, 1, 3)
  236. # Enable Hover box
  237. self.hover_cb = FCCheckBox('%s' % _('Display Hover Shape'))
  238. self.hover_cb.setToolTip(
  239. _("Enable display of a hover shape for FlatCAM objects.\n"
  240. "It is displayed whenever the mouse cursor is hovering\n"
  241. "over any kind of not-selected object.")
  242. )
  243. grid0.addWidget(self.hover_cb, 8, 0, 1, 3)
  244. # Enable Selection box
  245. self.selection_cb = FCCheckBox('%s' % _('Display Selection Shape'))
  246. self.selection_cb.setToolTip(
  247. _("Enable the display of a selection shape for FlatCAM objects.\n"
  248. "It is displayed whenever the mouse selects an object\n"
  249. "either by clicking or dragging mouse from left to right or\n"
  250. "right to left.")
  251. )
  252. grid0.addWidget(self.selection_cb, 9, 0, 1, 3)
  253. separator_line = QtWidgets.QFrame()
  254. separator_line.setFrameShape(QtWidgets.QFrame.HLine)
  255. separator_line.setFrameShadow(QtWidgets.QFrame.Sunken)
  256. grid0.addWidget(separator_line, 14, 0, 1, 2)
  257. # Plot Selection (left - right) Color
  258. self.sel_lr_label = QtWidgets.QLabel('<b>%s</b>' % _('Left-Right Selection Color'))
  259. grid0.addWidget(self.sel_lr_label, 15, 0, 1, 2)
  260. self.sl_color_label = QtWidgets.QLabel('%s:' % _('Outline'))
  261. self.sl_color_label.setToolTip(
  262. _("Set the line color for the 'left to right' selection box.")
  263. )
  264. self.sl_color_entry = FCEntry()
  265. self.sl_color_button = QtWidgets.QPushButton()
  266. self.sl_color_button.setFixedSize(15, 15)
  267. self.form_box_child_4 = QtWidgets.QHBoxLayout()
  268. self.form_box_child_4.addWidget(self.sl_color_entry)
  269. self.form_box_child_4.addWidget(self.sl_color_button)
  270. self.form_box_child_4.setAlignment(QtCore.Qt.AlignLeft | QtCore.Qt.AlignVCenter)
  271. grid0.addWidget(self.sl_color_label, 16, 0)
  272. grid0.addLayout(self.form_box_child_4, 16, 1)
  273. self.sf_color_label = QtWidgets.QLabel('%s:' % _('Fill'))
  274. self.sf_color_label.setToolTip(
  275. _("Set the fill color for the selection box\n"
  276. "in case that the selection is done from left to right.\n"
  277. "First 6 digits are the color and the last 2\n"
  278. "digits are for alpha (transparency) level.")
  279. )
  280. self.sf_color_entry = FCEntry()
  281. self.sf_color_button = QtWidgets.QPushButton()
  282. self.sf_color_button.setFixedSize(15, 15)
  283. self.form_box_child_5 = QtWidgets.QHBoxLayout()
  284. self.form_box_child_5.addWidget(self.sf_color_entry)
  285. self.form_box_child_5.addWidget(self.sf_color_button)
  286. self.form_box_child_5.setAlignment(QtCore.Qt.AlignLeft | QtCore.Qt.AlignVCenter)
  287. grid0.addWidget(self.sf_color_label, 17, 0)
  288. grid0.addLayout(self.form_box_child_5, 17, 1)
  289. # Plot Selection (left - right) Fill Transparency Level
  290. self.sf_alpha_label = QtWidgets.QLabel('%s:' % _('Alpha'))
  291. self.sf_alpha_label.setToolTip(
  292. _("Set the fill transparency for the 'left to right' selection box.")
  293. )
  294. self.sf_color_alpha_slider = QtWidgets.QSlider(QtCore.Qt.Horizontal)
  295. self.sf_color_alpha_slider.setMinimum(0)
  296. self.sf_color_alpha_slider.setMaximum(255)
  297. self.sf_color_alpha_slider.setSingleStep(1)
  298. self.sf_color_alpha_spinner = FCSpinner()
  299. self.sf_color_alpha_spinner.setMinimumWidth(70)
  300. self.sf_color_alpha_spinner.set_range(0, 255)
  301. self.form_box_child_6 = QtWidgets.QHBoxLayout()
  302. self.form_box_child_6.addWidget(self.sf_color_alpha_slider)
  303. self.form_box_child_6.addWidget(self.sf_color_alpha_spinner)
  304. grid0.addWidget(self.sf_alpha_label, 18, 0)
  305. grid0.addLayout(self.form_box_child_6, 18, 1)
  306. separator_line = QtWidgets.QFrame()
  307. separator_line.setFrameShape(QtWidgets.QFrame.HLine)
  308. separator_line.setFrameShadow(QtWidgets.QFrame.Sunken)
  309. grid0.addWidget(separator_line, 19, 0, 1, 2)
  310. # Plot Selection (left - right) Color
  311. self.sel_rl_label = QtWidgets.QLabel('<b>%s</b>' % _('Right-Left Selection Color'))
  312. grid0.addWidget(self.sel_rl_label, 20, 0, 1, 2)
  313. # Plot Selection (right - left) Line Color
  314. self.alt_sl_color_label = QtWidgets.QLabel('%s:' % _('Outline'))
  315. self.alt_sl_color_label.setToolTip(
  316. _("Set the line color for the 'right to left' selection box.")
  317. )
  318. self.alt_sl_color_entry = FCEntry()
  319. self.alt_sl_color_button = QtWidgets.QPushButton()
  320. self.alt_sl_color_button.setFixedSize(15, 15)
  321. self.form_box_child_7 = QtWidgets.QHBoxLayout()
  322. self.form_box_child_7.addWidget(self.alt_sl_color_entry)
  323. self.form_box_child_7.addWidget(self.alt_sl_color_button)
  324. self.form_box_child_7.setAlignment(QtCore.Qt.AlignLeft | QtCore.Qt.AlignVCenter)
  325. grid0.addWidget(self.alt_sl_color_label, 21, 0)
  326. grid0.addLayout(self.form_box_child_7, 21, 1)
  327. # Plot Selection (right - left) Fill Color
  328. self.alt_sf_color_label = QtWidgets.QLabel('%s:' % _('Fill'))
  329. self.alt_sf_color_label.setToolTip(
  330. _("Set the fill color for the selection box\n"
  331. "in case that the selection is done from right to left.\n"
  332. "First 6 digits are the color and the last 2\n"
  333. "digits are for alpha (transparency) level.")
  334. )
  335. self.alt_sf_color_entry = FCEntry()
  336. self.alt_sf_color_button = QtWidgets.QPushButton()
  337. self.alt_sf_color_button.setFixedSize(15, 15)
  338. self.form_box_child_8 = QtWidgets.QHBoxLayout()
  339. self.form_box_child_8.addWidget(self.alt_sf_color_entry)
  340. self.form_box_child_8.addWidget(self.alt_sf_color_button)
  341. self.form_box_child_8.setAlignment(QtCore.Qt.AlignLeft | QtCore.Qt.AlignVCenter)
  342. grid0.addWidget(self.alt_sf_color_label, 22, 0)
  343. grid0.addLayout(self.form_box_child_8, 22, 1)
  344. # Plot Selection (right - left) Fill Transparency Level
  345. self.alt_sf_alpha_label = QtWidgets.QLabel('%s:' % _('Alpha'))
  346. self.alt_sf_alpha_label.setToolTip(
  347. _("Set the fill transparency for selection 'right to left' box.")
  348. )
  349. self.alt_sf_color_alpha_slider = QtWidgets.QSlider(QtCore.Qt.Horizontal)
  350. self.alt_sf_color_alpha_slider.setMinimum(0)
  351. self.alt_sf_color_alpha_slider.setMaximum(255)
  352. self.alt_sf_color_alpha_slider.setSingleStep(1)
  353. self.alt_sf_color_alpha_spinner = FCSpinner()
  354. self.alt_sf_color_alpha_spinner.setMinimumWidth(70)
  355. self.alt_sf_color_alpha_spinner.set_range(0, 255)
  356. self.form_box_child_9 = QtWidgets.QHBoxLayout()
  357. self.form_box_child_9.addWidget(self.alt_sf_color_alpha_slider)
  358. self.form_box_child_9.addWidget(self.alt_sf_color_alpha_spinner)
  359. grid0.addWidget(self.alt_sf_alpha_label, 23, 0)
  360. grid0.addLayout(self.form_box_child_9, 23, 1)
  361. separator_line = QtWidgets.QFrame()
  362. separator_line.setFrameShape(QtWidgets.QFrame.HLine)
  363. separator_line.setFrameShadow(QtWidgets.QFrame.Sunken)
  364. grid0.addWidget(separator_line, 24, 0, 1, 2)
  365. # ------------------------------------------------------------------
  366. # ----------------------- Editor Color -----------------------------
  367. # ------------------------------------------------------------------
  368. self.editor_color_label = QtWidgets.QLabel('<b>%s</b>' % _('Editor Color'))
  369. grid0.addWidget(self.editor_color_label, 25, 0, 1, 2)
  370. # Editor Draw Color
  371. self.draw_color_label = QtWidgets.QLabel('%s:' % _('Drawing'))
  372. self.alt_sf_color_label.setToolTip(
  373. _("Set the color for the shape.")
  374. )
  375. self.draw_color_entry = FCEntry()
  376. self.draw_color_button = QtWidgets.QPushButton()
  377. self.draw_color_button.setFixedSize(15, 15)
  378. self.form_box_child_10 = QtWidgets.QHBoxLayout()
  379. self.form_box_child_10.addWidget(self.draw_color_entry)
  380. self.form_box_child_10.addWidget(self.draw_color_button)
  381. self.form_box_child_10.setAlignment(QtCore.Qt.AlignLeft | QtCore.Qt.AlignVCenter)
  382. grid0.addWidget(self.draw_color_label, 26, 0)
  383. grid0.addLayout(self.form_box_child_10, 26, 1)
  384. # Editor Draw Selection Color
  385. self.sel_draw_color_label = QtWidgets.QLabel('%s:' % _('Selection'))
  386. self.sel_draw_color_label.setToolTip(
  387. _("Set the color of the shape when selected.")
  388. )
  389. self.sel_draw_color_entry = FCEntry()
  390. self.sel_draw_color_button = QtWidgets.QPushButton()
  391. self.sel_draw_color_button.setFixedSize(15, 15)
  392. self.form_box_child_11 = QtWidgets.QHBoxLayout()
  393. self.form_box_child_11.addWidget(self.sel_draw_color_entry)
  394. self.form_box_child_11.addWidget(self.sel_draw_color_button)
  395. self.form_box_child_11.setAlignment(QtCore.Qt.AlignLeft | QtCore.Qt.AlignVCenter)
  396. grid0.addWidget(self.sel_draw_color_label, 27, 0)
  397. grid0.addLayout(self.form_box_child_11, 27, 1)
  398. separator_line = QtWidgets.QFrame()
  399. separator_line.setFrameShape(QtWidgets.QFrame.HLine)
  400. separator_line.setFrameShadow(QtWidgets.QFrame.Sunken)
  401. grid0.addWidget(separator_line, 28, 0, 1, 2)
  402. # endregion
  403. # ------------------------------------------------------------------
  404. # ----------------------- Project Settings -----------------------------
  405. # ------------------------------------------------------------------
  406. self.proj_settings_label = QtWidgets.QLabel('<b>%s</b>' % _('Project Items Color'))
  407. grid0.addWidget(self.proj_settings_label, 29, 0, 1, 2)
  408. # Project Tab items color
  409. self.proj_color_label = QtWidgets.QLabel('%s:' % _('Enabled'))
  410. self.proj_color_label.setToolTip(
  411. _("Set the color of the items in Project Tab Tree.")
  412. )
  413. self.proj_color_entry = FCEntry()
  414. self.proj_color_button = QtWidgets.QPushButton()
  415. self.proj_color_button.setFixedSize(15, 15)
  416. self.form_box_child_12 = QtWidgets.QHBoxLayout()
  417. self.form_box_child_12.addWidget(self.proj_color_entry)
  418. self.form_box_child_12.addWidget(self.proj_color_button)
  419. self.form_box_child_12.setAlignment(QtCore.Qt.AlignLeft | QtCore.Qt.AlignVCenter)
  420. grid0.addWidget(self.proj_color_label, 30, 0)
  421. grid0.addLayout(self.form_box_child_12, 30, 1)
  422. self.proj_color_dis_label = QtWidgets.QLabel('%s:' % _('Disabled'))
  423. self.proj_color_dis_label.setToolTip(
  424. _("Set the color of the items in Project Tab Tree,\n"
  425. "for the case when the items are disabled.")
  426. )
  427. self.proj_color_dis_entry = FCEntry()
  428. self.proj_color_dis_button = QtWidgets.QPushButton()
  429. self.proj_color_dis_button.setFixedSize(15, 15)
  430. self.form_box_child_13 = QtWidgets.QHBoxLayout()
  431. self.form_box_child_13.addWidget(self.proj_color_dis_entry)
  432. self.form_box_child_13.addWidget(self.proj_color_dis_button)
  433. self.form_box_child_13.setAlignment(QtCore.Qt.AlignLeft | QtCore.Qt.AlignVCenter)
  434. grid0.addWidget(self.proj_color_dis_label, 31, 0)
  435. grid0.addLayout(self.form_box_child_13, 31, 1)
  436. # Project autohide CB
  437. self.project_autohide_cb = FCCheckBox(label=_('Project AutoHide'))
  438. self.project_autohide_cb.setToolTip(
  439. _("Check this box if you want the project/selected/tool tab area to\n"
  440. "hide automatically when there are no objects loaded and\n"
  441. "to show whenever a new object is created.")
  442. )
  443. grid0.addWidget(self.project_autohide_cb, 32, 0, 1, 2)
  444. # Just to add empty rows
  445. grid0.addWidget(QtWidgets.QLabel(''), 33, 0, 1, 2)
  446. self.layout.addStretch()
  447. self.theme_button.clicked.connect(self.on_theme_change)
  448. # #############################################################################
  449. # ############################# GUI COLORS SIGNALS ############################
  450. # #############################################################################
  451. # Setting selection (left - right) colors signals
  452. self.sf_color_entry.editingFinished.connect(self.on_sf_color_entry)
  453. self.sf_color_button.clicked.connect(self.on_sf_color_button)
  454. self.sf_color_alpha_spinner.valueChanged.connect(self.on_sf_color_spinner)
  455. self.sf_color_alpha_slider.valueChanged.connect(self.on_sf_color_slider)
  456. self.sl_color_entry.editingFinished.connect(self.on_sl_color_entry)
  457. self.sl_color_button.clicked.connect(self.on_sl_color_button)
  458. # Setting selection (right - left) colors signals
  459. self.alt_sf_color_entry.editingFinished.connect(self.on_alt_sf_color_entry)
  460. self.alt_sf_color_button.clicked.connect(self.on_alt_sf_color_button)
  461. self.alt_sf_color_alpha_spinner.valueChanged.connect(self.on_alt_sf_color_spinner)
  462. self.alt_sf_color_alpha_slider.valueChanged.connect(self.on_alt_sf_color_slider)
  463. self.alt_sl_color_entry.editingFinished.connect(self.on_alt_sl_color_entry)
  464. self.alt_sl_color_button.clicked.connect(self.on_alt_sl_color_button)
  465. # Setting Editor Draw colors signals
  466. self.draw_color_entry.editingFinished.connect(self.on_draw_color_entry)
  467. self.draw_color_button.clicked.connect(self.on_draw_color_button)
  468. self.sel_draw_color_entry.editingFinished.connect(self.on_sel_draw_color_entry)
  469. self.sel_draw_color_button.clicked.connect(self.on_sel_draw_color_button)
  470. self.proj_color_entry.editingFinished.connect(self.on_proj_color_entry)
  471. self.proj_color_button.clicked.connect(self.on_proj_color_button)
  472. self.proj_color_dis_entry.editingFinished.connect(self.on_proj_color_dis_entry)
  473. self.proj_color_dis_button.clicked.connect(self.on_proj_color_dis_button)
  474. self.layout_combo.activated.connect(self.on_layout)
  475. def on_theme_change(self):
  476. val = self.theme_radio.get_value()
  477. qsettings = QSettings("Open Source", "FlatCAM")
  478. qsettings.setValue('theme', val)
  479. # This will write the setting to the platform specific storage.
  480. del qsettings
  481. self.app.on_app_restart()
  482. @staticmethod
  483. def handle_style(style):
  484. # set current style
  485. qsettings = QSettings("Open Source", "FlatCAM")
  486. qsettings.setValue('style', style)
  487. # This will write the setting to the platform specific storage.
  488. del qsettings
  489. @staticmethod
  490. def handle_hdpi(state):
  491. # set current HDPI
  492. qsettings = QSettings("Open Source", "FlatCAM")
  493. qsettings.setValue('hdpi', state)
  494. # This will write the setting to the platform specific storage.
  495. del qsettings
  496. # Setting selection colors (left - right) handlers
  497. def on_sf_color_entry(self):
  498. self.app.defaults['global_sel_fill'] = self.app.defaults['global_sel_fill'][7:9]
  499. self.sf_color_button.setStyleSheet("background-color:%s" % str(self.app.defaults['global_sel_fill'])[:7])
  500. def on_sf_color_button(self):
  501. current_color = QtGui.QColor(self.app.defaults['global_sel_fill'][:7])
  502. c_dialog = QtWidgets.QColorDialog()
  503. plot_fill_color = c_dialog.getColor(initial=current_color)
  504. if plot_fill_color.isValid() is False:
  505. return
  506. self.sf_color_button.setStyleSheet("background-color:%s" % str(plot_fill_color.name()))
  507. new_val = str(plot_fill_color.name()) + str(self.app.defaults['global_sel_fill'][7:9])
  508. self.sf_color_entry.set_value(new_val)
  509. self.app.defaults['global_sel_fill'] = new_val
  510. def on_sf_color_spinner(self):
  511. spinner_value = self.sf_color_alpha_spinner.value()
  512. self.sf_color_alpha_slider.setValue(spinner_value)
  513. self.app.defaults['global_sel_fill'] = self.app.defaults['global_sel_fill'][:7] + \
  514. (hex(spinner_value)[2:] if int(hex(spinner_value)[2:], 16) > 0 else '00')
  515. self.app.defaults['global_sel_line'] = self.app.defaults['global_sel_line'][:7] + \
  516. (hex(spinner_value)[2:] if int(hex(spinner_value)[2:], 16) > 0 else '00')
  517. def on_sf_color_slider(self):
  518. slider_value = self.sf_color_alpha_slider.value()
  519. self.sf_color_alpha_spinner.setValue(slider_value)
  520. def on_sl_color_entry(self):
  521. self.app.defaults['global_sel_line'] = self.sl_color_entry.get_value()[:7] + \
  522. self.app.defaults['global_sel_line'][7:9]
  523. self.sl_color_button.setStyleSheet("background-color:%s" % str(self.app.defaults['global_sel_line'])[:7])
  524. def on_sl_color_button(self):
  525. current_color = QtGui.QColor(self.app.defaults['global_sel_line'][:7])
  526. c_dialog = QtWidgets.QColorDialog()
  527. plot_line_color = c_dialog.getColor(initial=current_color)
  528. if plot_line_color.isValid() is False:
  529. return
  530. self.sl_color_button.setStyleSheet("background-color:%s" % str(plot_line_color.name()))
  531. new_val_line = str(plot_line_color.name()) + str(self.app.defaults['global_sel_line'][7:9])
  532. self.sl_color_entry.set_value(new_val_line)
  533. self.app.defaults['global_sel_line'] = new_val_line
  534. # Setting selection colors (right - left) handlers
  535. def on_alt_sf_color_entry(self):
  536. self.app.defaults['global_alt_sel_fill'] = self.alt_sf_color_entry.get_value()[:7] + \
  537. self.app.defaults['global_alt_sel_fill'][7:9]
  538. self.alt_sf_color_button.setStyleSheet(
  539. "background-color:%s" % str(self.app.defaults['global_alt_sel_fill'])[:7]
  540. )
  541. def on_alt_sf_color_button(self):
  542. current_color = QtGui.QColor(self.app.defaults['global_alt_sel_fill'][:7])
  543. c_dialog = QtWidgets.QColorDialog()
  544. plot_fill_color = c_dialog.getColor(initial=current_color)
  545. if plot_fill_color.isValid() is False:
  546. return
  547. self.alt_sf_color_button.setStyleSheet("background-color:%s" % str(plot_fill_color.name()))
  548. new_val = str(plot_fill_color.name()) + str(self.app.defaults['global_alt_sel_fill'][7:9])
  549. self.alt_sf_color_entry.set_value(new_val)
  550. self.app.defaults['global_alt_sel_fill'] = new_val
  551. def on_alt_sf_color_spinner(self):
  552. spinner_value = self.alt_sf_color_alpha_spinner.value()
  553. self.alt_sf_color_alpha_slider.setValue(spinner_value)
  554. self.app.defaults['global_alt_sel_fill'] = self.app.defaults['global_alt_sel_fill'][:7] + \
  555. (hex(spinner_value)[2:] if int(hex(spinner_value)[2:], 16) > 0 else '00')
  556. self.app.defaults['global_alt_sel_line'] = self.app.defaults['global_alt_sel_line'][:7] + \
  557. (hex(spinner_value)[2:] if int(hex(spinner_value)[2:], 16) > 0 else '00')
  558. def on_alt_sf_color_slider(self):
  559. slider_value = self.alt_sf_color_alpha_slider.value()
  560. self.alt_sf_color_alpha_spinner.setValue(slider_value)
  561. def on_alt_sl_color_entry(self):
  562. self.app.defaults['global_alt_sel_line'] = self.alt_sl_color_entry.get_value()[:7] + \
  563. self.app.defaults['global_alt_sel_line'][7:9]
  564. self.alt_sl_color_button.setStyleSheet(
  565. "background-color:%s" % str(self.app.defaults['global_alt_sel_line'])[:7]
  566. )
  567. def on_alt_sl_color_button(self):
  568. current_color = QtGui.QColor(self.app.defaults['global_alt_sel_line'][:7])
  569. c_dialog = QtWidgets.QColorDialog()
  570. plot_line_color = c_dialog.getColor(initial=current_color)
  571. if plot_line_color.isValid() is False:
  572. return
  573. self.alt_sl_color_button.setStyleSheet("background-color:%s" % str(plot_line_color.name()))
  574. new_val_line = str(plot_line_color.name()) + str(self.app.defaults['global_alt_sel_line'][7:9])
  575. self.alt_sl_color_entry.set_value(new_val_line)
  576. self.app.defaults['global_alt_sel_line'] = new_val_line
  577. # Setting Editor colors
  578. def on_draw_color_entry(self):
  579. self.app.defaults['global_draw_color'] = self.draw_color_entry.get_value()
  580. self.draw_color_button.setStyleSheet("background-color:%s" % str(self.app.defaults['global_draw_color']))
  581. def on_draw_color_button(self):
  582. current_color = QtGui.QColor(self.app.defaults['global_draw_color'])
  583. c_dialog = QtWidgets.QColorDialog()
  584. draw_color = c_dialog.getColor(initial=current_color)
  585. if draw_color.isValid() is False:
  586. return
  587. self.draw_color_button.setStyleSheet("background-color:%s" % str(draw_color.name()))
  588. new_val = str(draw_color.name())
  589. self.draw_color_entry.set_value(new_val)
  590. self.app.defaults['global_draw_color'] = new_val
  591. def on_sel_draw_color_entry(self):
  592. self.app.defaults['global_sel_draw_color'] = self.sel_draw_color_entry.get_value()
  593. self.sel_draw_color_button.setStyleSheet(
  594. "background-color:%s" % str(self.app.defaults['global_sel_draw_color']))
  595. def on_sel_draw_color_button(self):
  596. current_color = QtGui.QColor(self.app.defaults['global_sel_draw_color'])
  597. c_dialog = QtWidgets.QColorDialog()
  598. sel_draw_color = c_dialog.getColor(initial=current_color)
  599. if sel_draw_color.isValid() is False:
  600. return
  601. self.sel_draw_color_button.setStyleSheet("background-color:%s" % str(sel_draw_color.name()))
  602. new_val_sel = str(sel_draw_color.name())
  603. self.sel_draw_color_entry.set_value(new_val_sel)
  604. self.app.defaults['global_sel_draw_color'] = new_val_sel
  605. def on_proj_color_entry(self):
  606. self.app.defaults['global_proj_item_color'] = self.proj_color_entry.get_value()
  607. self.proj_color_button.setStyleSheet(
  608. "background-color:%s" % str(self.app.defaults['global_proj_item_color']))
  609. def on_proj_color_button(self):
  610. current_color = QtGui.QColor(self.app.defaults['global_proj_item_color'])
  611. c_dialog = QtWidgets.QColorDialog()
  612. proj_color = c_dialog.getColor(initial=current_color)
  613. if proj_color.isValid() is False:
  614. return
  615. self.proj_color_button.setStyleSheet("background-color:%s" % str(proj_color.name()))
  616. new_val_sel = str(proj_color.name())
  617. self.proj_color_entry.set_value(new_val_sel)
  618. self.app.defaults['global_proj_item_color'] = new_val_sel
  619. def on_proj_color_dis_entry(self):
  620. self.app.defaults['global_proj_item_dis_color'] = self.proj_color_dis_entry.get_value()
  621. self.proj_color_dis_button.setStyleSheet(
  622. "background-color:%s" % str(self.app.defaults['global_proj_item_dis_color']))
  623. def on_proj_color_dis_button(self):
  624. current_color = QtGui.QColor(self.app.defaults['global_proj_item_dis_color'])
  625. c_dialog = QtWidgets.QColorDialog()
  626. proj_color = c_dialog.getColor(initial=current_color)
  627. if proj_color.isValid() is False:
  628. return
  629. self.proj_color_dis_button.setStyleSheet("background-color:%s" % str(proj_color.name()))
  630. new_val_sel = str(proj_color.name())
  631. self.proj_color_dis_entry.set_value(new_val_sel)
  632. self.app.defaults['global_proj_item_dis_color'] = new_val_sel
  633. def on_layout(self, index=None, lay=None):
  634. """
  635. Set the toolbars layout (location)
  636. :param index:
  637. :param lay: Type of layout to be set on the toolbard
  638. :return: None
  639. """
  640. self.app.defaults.report_usage("on_layout()")
  641. if lay:
  642. current_layout = lay
  643. else:
  644. current_layout = self.layout_combo.get_value()
  645. lay_settings = QSettings("Open Source", "FlatCAM")
  646. lay_settings.setValue('layout', current_layout)
  647. # This will write the setting to the platform specific storage.
  648. del lay_settings
  649. # first remove the toolbars:
  650. try:
  651. self.app.ui.removeToolBar(self.app.ui.toolbarfile)
  652. self.app.ui.removeToolBar(self.app.ui.toolbargeo)
  653. self.app.ui.removeToolBar(self.app.ui.toolbarview)
  654. self.app.ui.removeToolBar(self.app.ui.toolbarshell)
  655. self.app.ui.removeToolBar(self.app.ui.toolbartools)
  656. self.app.ui.removeToolBar(self.app.ui.exc_edit_toolbar)
  657. self.app.ui.removeToolBar(self.app.ui.geo_edit_toolbar)
  658. self.app.ui.removeToolBar(self.app.ui.grb_edit_toolbar)
  659. self.app.ui.removeToolBar(self.app.ui.snap_toolbar)
  660. self.app.ui.removeToolBar(self.app.ui.toolbarshell)
  661. except Exception:
  662. pass
  663. if current_layout == 'compact':
  664. # ## TOOLBAR INSTALLATION # ##
  665. self.app.ui.toolbarfile = QtWidgets.QToolBar('File Toolbar')
  666. self.app.ui.toolbarfile.setObjectName('File_TB')
  667. self.app.ui.addToolBar(Qt.LeftToolBarArea, self.app.ui.toolbarfile)
  668. self.app.ui.toolbargeo = QtWidgets.QToolBar('Edit Toolbar')
  669. self.app.ui.toolbargeo.setObjectName('Edit_TB')
  670. self.app.ui.addToolBar(Qt.LeftToolBarArea, self.app.ui.toolbargeo)
  671. self.app.ui.toolbarshell = QtWidgets.QToolBar('Shell Toolbar')
  672. self.app.ui.toolbarshell.setObjectName('Shell_TB')
  673. self.app.ui.addToolBar(Qt.LeftToolBarArea, self.app.ui.toolbarshell)
  674. self.app.ui.toolbartools = QtWidgets.QToolBar('Tools Toolbar')
  675. self.app.ui.toolbartools.setObjectName('Tools_TB')
  676. self.app.ui.addToolBar(Qt.LeftToolBarArea, self.app.ui.toolbartools)
  677. self.app.ui.geo_edit_toolbar = QtWidgets.QToolBar('Geometry Editor Toolbar')
  678. # self.app.ui.geo_edit_toolbar.setVisible(False)
  679. self.app.ui.geo_edit_toolbar.setObjectName('GeoEditor_TB')
  680. self.app.ui.addToolBar(Qt.RightToolBarArea, self.app.ui.geo_edit_toolbar)
  681. self.app.ui.toolbarview = QtWidgets.QToolBar('View Toolbar')
  682. self.app.ui.toolbarview.setObjectName('View_TB')
  683. self.app.ui.addToolBar(Qt.RightToolBarArea, self.app.ui.toolbarview)
  684. self.app.ui.addToolBarBreak(area=Qt.RightToolBarArea)
  685. self.app.ui.grb_edit_toolbar = QtWidgets.QToolBar('Gerber Editor Toolbar')
  686. # self.app.ui.grb_edit_toolbar.setVisible(False)
  687. self.app.ui.grb_edit_toolbar.setObjectName('GrbEditor_TB')
  688. self.app.ui.addToolBar(Qt.RightToolBarArea, self.app.ui.grb_edit_toolbar)
  689. self.app.ui.exc_edit_toolbar = QtWidgets.QToolBar('Excellon Editor Toolbar')
  690. self.app.ui.exc_edit_toolbar.setObjectName('ExcEditor_TB')
  691. self.app.ui.addToolBar(Qt.RightToolBarArea, self.app.ui.exc_edit_toolbar)
  692. self.app.ui.snap_toolbar = QtWidgets.QToolBar('Grid Toolbar')
  693. self.app.ui.snap_toolbar.setObjectName('Snap_TB')
  694. self.app.ui.snap_toolbar.setMaximumHeight(30)
  695. self.app.ui.splitter_left.addWidget(self.app.ui.snap_toolbar)
  696. self.app.ui.corner_snap_btn.setVisible(True)
  697. self.app.ui.snap_magnet.setVisible(True)
  698. else:
  699. # ## TOOLBAR INSTALLATION # ##
  700. self.app.ui.toolbarfile = QtWidgets.QToolBar('File Toolbar')
  701. self.app.ui.toolbarfile.setObjectName('File_TB')
  702. self.app.ui.addToolBar(self.app.ui.toolbarfile)
  703. self.app.ui.toolbargeo = QtWidgets.QToolBar('Edit Toolbar')
  704. self.app.ui.toolbargeo.setObjectName('Edit_TB')
  705. self.app.ui.addToolBar(self.app.ui.toolbargeo)
  706. self.app.ui.toolbarview = QtWidgets.QToolBar('View Toolbar')
  707. self.app.ui.toolbarview.setObjectName('View_TB')
  708. self.app.ui.addToolBar(self.app.ui.toolbarview)
  709. self.app.ui.toolbarshell = QtWidgets.QToolBar('Shell Toolbar')
  710. self.app.ui.toolbarshell.setObjectName('Shell_TB')
  711. self.app.ui.addToolBar(self.app.ui.toolbarshell)
  712. self.app.ui.toolbartools = QtWidgets.QToolBar('Tools Toolbar')
  713. self.app.ui.toolbartools.setObjectName('Tools_TB')
  714. self.app.ui.addToolBar(self.app.ui.toolbartools)
  715. self.app.ui.exc_edit_toolbar = QtWidgets.QToolBar('Excellon Editor Toolbar')
  716. # self.app.ui.exc_edit_toolbar.setVisible(False)
  717. self.app.ui.exc_edit_toolbar.setObjectName('ExcEditor_TB')
  718. self.app.ui.addToolBar(self.app.ui.exc_edit_toolbar)
  719. self.app.ui.addToolBarBreak()
  720. self.app.ui.geo_edit_toolbar = QtWidgets.QToolBar('Geometry Editor Toolbar')
  721. # self.app.ui.geo_edit_toolbar.setVisible(False)
  722. self.app.ui.geo_edit_toolbar.setObjectName('GeoEditor_TB')
  723. self.app.ui.addToolBar(self.app.ui.geo_edit_toolbar)
  724. self.app.ui.grb_edit_toolbar = QtWidgets.QToolBar('Gerber Editor Toolbar')
  725. # self.app.ui.grb_edit_toolbar.setVisible(False)
  726. self.app.ui.grb_edit_toolbar.setObjectName('GrbEditor_TB')
  727. self.app.ui.addToolBar(self.app.ui.grb_edit_toolbar)
  728. self.app.ui.snap_toolbar = QtWidgets.QToolBar('Grid Toolbar')
  729. self.app.ui.snap_toolbar.setObjectName('Snap_TB')
  730. # self.app.ui.snap_toolbar.setMaximumHeight(30)
  731. self.app.ui.addToolBar(self.app.ui.snap_toolbar)
  732. self.app.ui.corner_snap_btn.setVisible(False)
  733. self.app.ui.snap_magnet.setVisible(False)
  734. if current_layout == 'minimal':
  735. self.app.ui.toolbarview.setVisible(False)
  736. self.app.ui.toolbarshell.setVisible(False)
  737. self.app.ui.snap_toolbar.setVisible(False)
  738. self.app.ui.geo_edit_toolbar.setVisible(False)
  739. self.app.ui.grb_edit_toolbar.setVisible(False)
  740. self.app.ui.exc_edit_toolbar.setVisible(False)
  741. self.app.ui.lock_toolbar(lock=True)
  742. # add all the actions to the toolbars
  743. self.app.ui.populate_toolbars()
  744. # reconnect all the signals to the toolbar actions
  745. self.app.connect_toolbar_signals()
  746. self.app.ui.grid_snap_btn.setChecked(True)
  747. self.app.on_grid_snap_triggered(state=True)
  748. self.app.ui.grid_gap_x_entry.setText(str(self.app.defaults["global_gridx"]))
  749. self.app.ui.grid_gap_y_entry.setText(str(self.app.defaults["global_gridy"]))
  750. self.app.ui.snap_max_dist_entry.setText(str(self.app.defaults["global_snap_max"]))
  751. self.app.ui.grid_gap_link_cb.setChecked(True)