GeneralGUIPrefGroupUI.py 34 KB

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