GeneralGUIPrefGroupUI.py 34 KB

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