GeneralGUIPrefGroupUI.py 33 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750
  1. from PyQt5 import QtWidgets, QtCore, QtGui
  2. from PyQt5.QtCore import QSettings, Qt
  3. from AppGUI.GUIElements import RadioSet, FCCheckBox, FCComboBox, FCEntry, FCSpinner, FCSliderWithSpinner
  4. from AppGUI.preferences.OptionsGroupUI import OptionsGroupUI
  5. import gettext
  6. import AppTranslation 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 the application.\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 the application.\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 the application.\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 the application.\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 the application 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 the application 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.left_right_alpha_label = QtWidgets.QLabel('%s:' % _('Alpha'))
  158. self.left_right_alpha_label.setToolTip(
  159. _("Set the fill transparency for the 'left to right' selection box.")
  160. )
  161. self.left_right_alpha_entry = FCSliderWithSpinner(0, 255, 1)
  162. grid0.addWidget(self.left_right_alpha_label, 18, 0)
  163. grid0.addWidget(self.left_right_alpha_entry, 18, 1)
  164. separator_line = QtWidgets.QFrame()
  165. separator_line.setFrameShape(QtWidgets.QFrame.HLine)
  166. separator_line.setFrameShadow(QtWidgets.QFrame.Sunken)
  167. grid0.addWidget(separator_line, 19, 0, 1, 2)
  168. # Plot Selection (left - right) Color
  169. self.sel_rl_label = QtWidgets.QLabel('<b>%s</b>' % _('Right-Left Selection Color'))
  170. grid0.addWidget(self.sel_rl_label, 20, 0, 1, 2)
  171. # Plot Selection (right - left) Line Color
  172. self.alt_sl_color_label = QtWidgets.QLabel('%s:' % _('Outline'))
  173. self.alt_sl_color_label.setToolTip(
  174. _("Set the line color for the 'right to left' selection box.")
  175. )
  176. self.alt_sl_color_entry = FCEntry()
  177. self.alt_sl_color_button = QtWidgets.QPushButton()
  178. self.alt_sl_color_button.setFixedSize(15, 15)
  179. self.form_box_child_7 = QtWidgets.QHBoxLayout()
  180. self.form_box_child_7.addWidget(self.alt_sl_color_entry)
  181. self.form_box_child_7.addWidget(self.alt_sl_color_button)
  182. self.form_box_child_7.setAlignment(QtCore.Qt.AlignLeft | QtCore.Qt.AlignVCenter)
  183. grid0.addWidget(self.alt_sl_color_label, 21, 0)
  184. grid0.addLayout(self.form_box_child_7, 21, 1)
  185. # Plot Selection (right - left) Fill Color
  186. self.alt_sf_color_label = QtWidgets.QLabel('%s:' % _('Fill'))
  187. self.alt_sf_color_label.setToolTip(
  188. _("Set the fill color for the selection box\n"
  189. "in case that the selection is done from right to left.\n"
  190. "First 6 digits are the color and the last 2\n"
  191. "digits are for alpha (transparency) level.")
  192. )
  193. self.alt_sf_color_entry = FCEntry()
  194. self.alt_sf_color_button = QtWidgets.QPushButton()
  195. self.alt_sf_color_button.setFixedSize(15, 15)
  196. self.form_box_child_8 = QtWidgets.QHBoxLayout()
  197. self.form_box_child_8.addWidget(self.alt_sf_color_entry)
  198. self.form_box_child_8.addWidget(self.alt_sf_color_button)
  199. self.form_box_child_8.setAlignment(QtCore.Qt.AlignLeft | QtCore.Qt.AlignVCenter)
  200. grid0.addWidget(self.alt_sf_color_label, 22, 0)
  201. grid0.addLayout(self.form_box_child_8, 22, 1)
  202. # Plot Selection (right - left) Fill Transparency Level
  203. self.right_left_alpha_label = QtWidgets.QLabel('%s:' % _('Alpha'))
  204. self.right_left_alpha_label.setToolTip(
  205. _("Set the fill transparency for selection 'right to left' box.")
  206. )
  207. self.right_left_alpha_entry = FCSliderWithSpinner(0 , 255, 1)
  208. grid0.addWidget(self.right_left_alpha_label, 23, 0)
  209. grid0.addWidget(self.right_left_alpha_entry, 23, 1)
  210. separator_line = QtWidgets.QFrame()
  211. separator_line.setFrameShape(QtWidgets.QFrame.HLine)
  212. separator_line.setFrameShadow(QtWidgets.QFrame.Sunken)
  213. grid0.addWidget(separator_line, 24, 0, 1, 2)
  214. # ------------------------------------------------------------------
  215. # ----------------------- Editor Color -----------------------------
  216. # ------------------------------------------------------------------
  217. self.editor_color_label = QtWidgets.QLabel('<b>%s</b>' % _('Editor Color'))
  218. grid0.addWidget(self.editor_color_label, 25, 0, 1, 2)
  219. # Editor Draw Color
  220. self.draw_color_label = QtWidgets.QLabel('%s:' % _('Drawing'))
  221. self.alt_sf_color_label.setToolTip(
  222. _("Set the color for the shape.")
  223. )
  224. self.draw_color_entry = FCEntry()
  225. self.draw_color_button = QtWidgets.QPushButton()
  226. self.draw_color_button.setFixedSize(15, 15)
  227. self.form_box_child_10 = QtWidgets.QHBoxLayout()
  228. self.form_box_child_10.addWidget(self.draw_color_entry)
  229. self.form_box_child_10.addWidget(self.draw_color_button)
  230. self.form_box_child_10.setAlignment(QtCore.Qt.AlignLeft | QtCore.Qt.AlignVCenter)
  231. grid0.addWidget(self.draw_color_label, 26, 0)
  232. grid0.addLayout(self.form_box_child_10, 26, 1)
  233. # Editor Draw Selection Color
  234. self.sel_draw_color_label = QtWidgets.QLabel('%s:' % _('Selection'))
  235. self.sel_draw_color_label.setToolTip(
  236. _("Set the color of the shape when selected.")
  237. )
  238. self.sel_draw_color_entry = FCEntry()
  239. self.sel_draw_color_button = QtWidgets.QPushButton()
  240. self.sel_draw_color_button.setFixedSize(15, 15)
  241. self.form_box_child_11 = QtWidgets.QHBoxLayout()
  242. self.form_box_child_11.addWidget(self.sel_draw_color_entry)
  243. self.form_box_child_11.addWidget(self.sel_draw_color_button)
  244. self.form_box_child_11.setAlignment(QtCore.Qt.AlignLeft | QtCore.Qt.AlignVCenter)
  245. grid0.addWidget(self.sel_draw_color_label, 27, 0)
  246. grid0.addLayout(self.form_box_child_11, 27, 1)
  247. separator_line = QtWidgets.QFrame()
  248. separator_line.setFrameShape(QtWidgets.QFrame.HLine)
  249. separator_line.setFrameShadow(QtWidgets.QFrame.Sunken)
  250. grid0.addWidget(separator_line, 28, 0, 1, 2)
  251. # ------------------------------------------------------------------
  252. # ----------------------- Project Settings -----------------------------
  253. # ------------------------------------------------------------------
  254. self.proj_settings_label = QtWidgets.QLabel('<b>%s</b>' % _('Project Items Color'))
  255. grid0.addWidget(self.proj_settings_label, 29, 0, 1, 2)
  256. # Project Tab items color
  257. self.proj_color_label = QtWidgets.QLabel('%s:' % _('Enabled'))
  258. self.proj_color_label.setToolTip(
  259. _("Set the color of the items in Project Tab Tree.")
  260. )
  261. self.proj_color_entry = FCEntry()
  262. self.proj_color_button = QtWidgets.QPushButton()
  263. self.proj_color_button.setFixedSize(15, 15)
  264. self.form_box_child_12 = QtWidgets.QHBoxLayout()
  265. self.form_box_child_12.addWidget(self.proj_color_entry)
  266. self.form_box_child_12.addWidget(self.proj_color_button)
  267. self.form_box_child_12.setAlignment(QtCore.Qt.AlignLeft | QtCore.Qt.AlignVCenter)
  268. grid0.addWidget(self.proj_color_label, 30, 0)
  269. grid0.addLayout(self.form_box_child_12, 30, 1)
  270. self.proj_color_dis_label = QtWidgets.QLabel('%s:' % _('Disabled'))
  271. self.proj_color_dis_label.setToolTip(
  272. _("Set the color of the items in Project Tab Tree,\n"
  273. "for the case when the items are disabled.")
  274. )
  275. self.proj_color_dis_entry = FCEntry()
  276. self.proj_color_dis_button = QtWidgets.QPushButton()
  277. self.proj_color_dis_button.setFixedSize(15, 15)
  278. self.form_box_child_13 = QtWidgets.QHBoxLayout()
  279. self.form_box_child_13.addWidget(self.proj_color_dis_entry)
  280. self.form_box_child_13.addWidget(self.proj_color_dis_button)
  281. self.form_box_child_13.setAlignment(QtCore.Qt.AlignLeft | QtCore.Qt.AlignVCenter)
  282. grid0.addWidget(self.proj_color_dis_label, 31, 0)
  283. grid0.addLayout(self.form_box_child_13, 31, 1)
  284. # Project autohide CB
  285. self.project_autohide_cb = FCCheckBox(label=_('Project AutoHide'))
  286. self.project_autohide_cb.setToolTip(
  287. _("Check this box if you want the project/selected/tool tab area to\n"
  288. "hide automatically when there are no objects loaded and\n"
  289. "to show whenever a new object is created.")
  290. )
  291. grid0.addWidget(self.project_autohide_cb, 32, 0, 1, 2)
  292. # Just to add empty rows
  293. grid0.addWidget(QtWidgets.QLabel(''), 33, 0, 1, 2)
  294. self.layout.addStretch()
  295. # #############################################################################
  296. # ############################# GUI COLORS SIGNALS ############################
  297. # #############################################################################
  298. # Setting selection (left - right) colors signals
  299. self.sf_color_entry.editingFinished.connect(self.on_sf_color_entry)
  300. self.sf_color_button.clicked.connect(self.on_sf_color_button)
  301. self.sl_color_entry.editingFinished.connect(self.on_sl_color_entry)
  302. self.sl_color_button.clicked.connect(self.on_sl_color_button)
  303. self.left_right_alpha_entry.valueChanged.connect(self.on_left_right_alpha_changed) # alpha
  304. # Setting selection (right - left) colors signals
  305. self.alt_sf_color_entry.editingFinished.connect(self.on_alt_sf_color_entry)
  306. self.alt_sf_color_button.clicked.connect(self.on_alt_sf_color_button)
  307. self.alt_sl_color_entry.editingFinished.connect(self.on_alt_sl_color_entry)
  308. self.alt_sl_color_button.clicked.connect(self.on_alt_sl_color_button)
  309. self.right_left_alpha_entry.valueChanged.connect(self.on_right_left_alpha_changed) # alpha
  310. # Setting Editor Draw colors signals
  311. self.draw_color_entry.editingFinished.connect(self.on_draw_color_entry)
  312. self.draw_color_button.clicked.connect(self.on_draw_color_button)
  313. self.sel_draw_color_entry.editingFinished.connect(self.on_sel_draw_color_entry)
  314. self.sel_draw_color_button.clicked.connect(self.on_sel_draw_color_button)
  315. self.proj_color_entry.editingFinished.connect(self.on_proj_color_entry)
  316. self.proj_color_button.clicked.connect(self.on_proj_color_button)
  317. self.proj_color_dis_entry.editingFinished.connect(self.on_proj_color_dis_entry)
  318. self.proj_color_dis_button.clicked.connect(self.on_proj_color_dis_button)
  319. self.layout_combo.activated.connect(self.on_layout)
  320. @staticmethod
  321. def handle_style(style):
  322. # set current style
  323. qsettings = QSettings("Open Source", "FlatCAM")
  324. qsettings.setValue('style', style)
  325. # This will write the setting to the platform specific storage.
  326. del qsettings
  327. @staticmethod
  328. def handle_hdpi(state):
  329. # set current HDPI
  330. qsettings = QSettings("Open Source", "FlatCAM")
  331. qsettings.setValue('hdpi', state)
  332. # This will write the setting to the platform specific storage.
  333. del qsettings
  334. # Setting selection colors (left - right) handlers
  335. def on_sf_color_entry(self):
  336. self.app.defaults['global_sel_fill'] = self.app.defaults['global_sel_fill'][7:9]
  337. self.sf_color_button.setStyleSheet("background-color:%s" % str(self.app.defaults['global_sel_fill'])[:7])
  338. def on_sf_color_button(self):
  339. current_color = QtGui.QColor(self.app.defaults['global_sel_fill'][:7])
  340. c_dialog = QtWidgets.QColorDialog()
  341. plot_fill_color = c_dialog.getColor(initial=current_color)
  342. if plot_fill_color.isValid() is False:
  343. return
  344. self.sf_color_button.setStyleSheet("background-color:%s" % str(plot_fill_color.name()))
  345. new_val = str(plot_fill_color.name()) + str(self.app.defaults['global_sel_fill'][7:9])
  346. self.sf_color_entry.set_value(new_val)
  347. self.app.defaults['global_sel_fill'] = new_val
  348. def on_left_right_alpha_changed(self, spinner_value):
  349. """
  350. Change the alpha level for the color of the selection box when selection is done left to right.
  351. Called on valueChanged of a FCSliderWithSpinner.
  352. :param spinner_value: passed value within [0, 255]
  353. :type spinner_value: int
  354. :return: None
  355. :rtype:
  356. """
  357. self.app.defaults['global_sel_fill'] = self.app.defaults['global_sel_fill'][:7] + \
  358. (hex(spinner_value)[2:] if int(hex(spinner_value)[2:], 16) > 0 else '00')
  359. self.app.defaults['global_sel_line'] = self.app.defaults['global_sel_line'][:7] + \
  360. (hex(spinner_value)[2:] if int(hex(spinner_value)[2:], 16) > 0 else '00')
  361. def on_sl_color_entry(self):
  362. self.app.defaults['global_sel_line'] = self.sl_color_entry.get_value()[:7] + \
  363. self.app.defaults['global_sel_line'][7:9]
  364. self.sl_color_button.setStyleSheet("background-color:%s" % str(self.app.defaults['global_sel_line'])[:7])
  365. def on_sl_color_button(self):
  366. current_color = QtGui.QColor(self.app.defaults['global_sel_line'][:7])
  367. c_dialog = QtWidgets.QColorDialog()
  368. plot_line_color = c_dialog.getColor(initial=current_color)
  369. if plot_line_color.isValid() is False:
  370. return
  371. self.sl_color_button.setStyleSheet("background-color:%s" % str(plot_line_color.name()))
  372. new_val_line = str(plot_line_color.name()) + str(self.app.defaults['global_sel_line'][7:9])
  373. self.sl_color_entry.set_value(new_val_line)
  374. self.app.defaults['global_sel_line'] = new_val_line
  375. # Setting selection colors (right - left) handlers
  376. def on_alt_sf_color_entry(self):
  377. self.app.defaults['global_alt_sel_fill'] = self.alt_sf_color_entry.get_value()[:7] + \
  378. self.app.defaults['global_alt_sel_fill'][7:9]
  379. self.alt_sf_color_button.setStyleSheet(
  380. "background-color:%s" % str(self.app.defaults['global_alt_sel_fill'])[:7]
  381. )
  382. def on_alt_sf_color_button(self):
  383. current_color = QtGui.QColor(self.app.defaults['global_alt_sel_fill'][:7])
  384. c_dialog = QtWidgets.QColorDialog()
  385. plot_fill_color = c_dialog.getColor(initial=current_color)
  386. if plot_fill_color.isValid() is False:
  387. return
  388. self.alt_sf_color_button.setStyleSheet("background-color:%s" % str(plot_fill_color.name()))
  389. new_val = str(plot_fill_color.name()) + str(self.app.defaults['global_alt_sel_fill'][7:9])
  390. self.alt_sf_color_entry.set_value(new_val)
  391. self.app.defaults['global_alt_sel_fill'] = new_val
  392. def on_right_left_alpha_changed(self, spinner_value):
  393. """
  394. Change the alpha level for the color of the selection box when selection is done right to left.
  395. Called on valueChanged of a FCSliderWithSpinner.
  396. :param spinner_value: passed value within [0, 255]
  397. :type spinner_value: int
  398. :return: None
  399. :rtype:
  400. """
  401. self.app.defaults['global_alt_sel_fill'] = self.app.defaults['global_alt_sel_fill'][:7] + \
  402. (hex(spinner_value)[2:] if int(hex(spinner_value)[2:], 16) > 0 else '00')
  403. self.app.defaults['global_alt_sel_line'] = self.app.defaults['global_alt_sel_line'][:7] + \
  404. (hex(spinner_value)[2:] if int(hex(spinner_value)[2:], 16) > 0 else '00')
  405. def on_alt_sf_color_slider(self):
  406. slider_value = self.alt_sf_color_alpha_slider.value()
  407. self.alt_sf_color_alpha_spinner.setValue(slider_value)
  408. def on_alt_sl_color_entry(self):
  409. self.app.defaults['global_alt_sel_line'] = self.alt_sl_color_entry.get_value()[:7] + \
  410. self.app.defaults['global_alt_sel_line'][7:9]
  411. self.alt_sl_color_button.setStyleSheet(
  412. "background-color:%s" % str(self.app.defaults['global_alt_sel_line'])[:7]
  413. )
  414. def on_alt_sl_color_button(self):
  415. current_color = QtGui.QColor(self.app.defaults['global_alt_sel_line'][:7])
  416. c_dialog = QtWidgets.QColorDialog()
  417. plot_line_color = c_dialog.getColor(initial=current_color)
  418. if plot_line_color.isValid() is False:
  419. return
  420. self.alt_sl_color_button.setStyleSheet("background-color:%s" % str(plot_line_color.name()))
  421. new_val_line = str(plot_line_color.name()) + str(self.app.defaults['global_alt_sel_line'][7:9])
  422. self.alt_sl_color_entry.set_value(new_val_line)
  423. self.app.defaults['global_alt_sel_line'] = new_val_line
  424. # Setting Editor colors
  425. def on_draw_color_entry(self):
  426. self.app.defaults['global_draw_color'] = self.draw_color_entry.get_value()
  427. self.draw_color_button.setStyleSheet("background-color:%s" % str(self.app.defaults['global_draw_color']))
  428. def on_draw_color_button(self):
  429. current_color = QtGui.QColor(self.app.defaults['global_draw_color'])
  430. c_dialog = QtWidgets.QColorDialog()
  431. draw_color = c_dialog.getColor(initial=current_color)
  432. if draw_color.isValid() is False:
  433. return
  434. self.draw_color_button.setStyleSheet("background-color:%s" % str(draw_color.name()))
  435. new_val = str(draw_color.name())
  436. self.draw_color_entry.set_value(new_val)
  437. self.app.defaults['global_draw_color'] = new_val
  438. def on_sel_draw_color_entry(self):
  439. self.app.defaults['global_sel_draw_color'] = self.sel_draw_color_entry.get_value()
  440. self.sel_draw_color_button.setStyleSheet(
  441. "background-color:%s" % str(self.app.defaults['global_sel_draw_color']))
  442. def on_sel_draw_color_button(self):
  443. current_color = QtGui.QColor(self.app.defaults['global_sel_draw_color'])
  444. c_dialog = QtWidgets.QColorDialog()
  445. sel_draw_color = c_dialog.getColor(initial=current_color)
  446. if sel_draw_color.isValid() is False:
  447. return
  448. self.sel_draw_color_button.setStyleSheet("background-color:%s" % str(sel_draw_color.name()))
  449. new_val_sel = str(sel_draw_color.name())
  450. self.sel_draw_color_entry.set_value(new_val_sel)
  451. self.app.defaults['global_sel_draw_color'] = new_val_sel
  452. def on_proj_color_entry(self):
  453. self.app.defaults['global_proj_item_color'] = self.proj_color_entry.get_value()
  454. self.proj_color_button.setStyleSheet(
  455. "background-color:%s" % str(self.app.defaults['global_proj_item_color']))
  456. def on_proj_color_button(self):
  457. current_color = QtGui.QColor(self.app.defaults['global_proj_item_color'])
  458. c_dialog = QtWidgets.QColorDialog()
  459. proj_color = c_dialog.getColor(initial=current_color)
  460. if proj_color.isValid() is False:
  461. return
  462. self.proj_color_button.setStyleSheet("background-color:%s" % str(proj_color.name()))
  463. new_val_sel = str(proj_color.name())
  464. self.proj_color_entry.set_value(new_val_sel)
  465. self.app.defaults['global_proj_item_color'] = new_val_sel
  466. def on_proj_color_dis_entry(self):
  467. self.app.defaults['global_proj_item_dis_color'] = self.proj_color_dis_entry.get_value()
  468. self.proj_color_dis_button.setStyleSheet(
  469. "background-color:%s" % str(self.app.defaults['global_proj_item_dis_color']))
  470. def on_proj_color_dis_button(self):
  471. current_color = QtGui.QColor(self.app.defaults['global_proj_item_dis_color'])
  472. c_dialog = QtWidgets.QColorDialog()
  473. proj_color = c_dialog.getColor(initial=current_color)
  474. if proj_color.isValid() is False:
  475. return
  476. self.proj_color_dis_button.setStyleSheet("background-color:%s" % str(proj_color.name()))
  477. new_val_sel = str(proj_color.name())
  478. self.proj_color_dis_entry.set_value(new_val_sel)
  479. self.app.defaults['global_proj_item_dis_color'] = new_val_sel
  480. def on_layout(self, index=None, lay=None):
  481. """
  482. Set the toolbars layout (location)
  483. :param index:
  484. :param lay: Type of layout to be set on the toolbard
  485. :return: None
  486. """
  487. self.app.defaults.report_usage("on_layout()")
  488. if lay:
  489. current_layout = lay
  490. else:
  491. current_layout = self.layout_combo.get_value()
  492. lay_settings = QSettings("Open Source", "FlatCAM")
  493. lay_settings.setValue('layout', current_layout)
  494. # This will write the setting to the platform specific storage.
  495. del lay_settings
  496. # first remove the toolbars:
  497. try:
  498. self.app.ui.removeToolBar(self.app.ui.toolbarfile)
  499. self.app.ui.removeToolBar(self.app.ui.toolbaredit)
  500. self.app.ui.removeToolBar(self.app.ui.toolbarview)
  501. self.app.ui.removeToolBar(self.app.ui.toolbarshell)
  502. self.app.ui.removeToolBar(self.app.ui.toolbartools)
  503. self.app.ui.removeToolBar(self.app.ui.exc_edit_toolbar)
  504. self.app.ui.removeToolBar(self.app.ui.geo_edit_toolbar)
  505. self.app.ui.removeToolBar(self.app.ui.grb_edit_toolbar)
  506. self.app.ui.removeToolBar(self.app.ui.toolbarshell)
  507. except Exception:
  508. pass
  509. if current_layout == 'compact':
  510. # ## TOOLBAR INSTALLATION # ##
  511. self.app.ui.toolbarfile = QtWidgets.QToolBar('File Toolbar')
  512. self.app.ui.toolbarfile.setObjectName('File_TB')
  513. self.app.ui.addToolBar(Qt.LeftToolBarArea, self.app.ui.toolbarfile)
  514. self.app.ui.toolbaredit = QtWidgets.QToolBar('Edit Toolbar')
  515. self.app.ui.toolbaredit.setObjectName('Edit_TB')
  516. self.app.ui.addToolBar(Qt.LeftToolBarArea, self.app.ui.toolbaredit)
  517. self.app.ui.toolbarshell = QtWidgets.QToolBar('Shell Toolbar')
  518. self.app.ui.toolbarshell.setObjectName('Shell_TB')
  519. self.app.ui.addToolBar(Qt.LeftToolBarArea, self.app.ui.toolbarshell)
  520. self.app.ui.toolbartools = QtWidgets.QToolBar('Tools Toolbar')
  521. self.app.ui.toolbartools.setObjectName('Tools_TB')
  522. self.app.ui.addToolBar(Qt.LeftToolBarArea, self.app.ui.toolbartools)
  523. self.app.ui.geo_edit_toolbar = QtWidgets.QToolBar('Geometry Editor Toolbar')
  524. # self.app.ui.geo_edit_toolbar.setVisible(False)
  525. self.app.ui.geo_edit_toolbar.setObjectName('GeoEditor_TB')
  526. self.app.ui.addToolBar(Qt.RightToolBarArea, self.app.ui.geo_edit_toolbar)
  527. self.app.ui.toolbarview = QtWidgets.QToolBar('View Toolbar')
  528. self.app.ui.toolbarview.setObjectName('View_TB')
  529. self.app.ui.addToolBar(Qt.RightToolBarArea, self.app.ui.toolbarview)
  530. self.app.ui.addToolBarBreak(area=Qt.RightToolBarArea)
  531. self.app.ui.grb_edit_toolbar = QtWidgets.QToolBar('Gerber Editor Toolbar')
  532. # self.app.ui.grb_edit_toolbar.setVisible(False)
  533. self.app.ui.grb_edit_toolbar.setObjectName('GrbEditor_TB')
  534. self.app.ui.addToolBar(Qt.RightToolBarArea, self.app.ui.grb_edit_toolbar)
  535. self.app.ui.exc_edit_toolbar = QtWidgets.QToolBar('Excellon Editor Toolbar')
  536. self.app.ui.exc_edit_toolbar.setObjectName('ExcEditor_TB')
  537. self.app.ui.addToolBar(Qt.RightToolBarArea, self.app.ui.exc_edit_toolbar)
  538. else:
  539. # ## TOOLBAR INSTALLATION # ##
  540. self.app.ui.toolbarfile = QtWidgets.QToolBar('File Toolbar')
  541. self.app.ui.toolbarfile.setObjectName('File_TB')
  542. self.app.ui.addToolBar(self.app.ui.toolbarfile)
  543. self.app.ui.toolbaredit = QtWidgets.QToolBar('Edit Toolbar')
  544. self.app.ui.toolbaredit.setObjectName('Edit_TB')
  545. self.app.ui.addToolBar(self.app.ui.toolbaredit)
  546. self.app.ui.toolbarview = QtWidgets.QToolBar('View Toolbar')
  547. self.app.ui.toolbarview.setObjectName('View_TB')
  548. self.app.ui.addToolBar(self.app.ui.toolbarview)
  549. self.app.ui.toolbarshell = QtWidgets.QToolBar('Shell Toolbar')
  550. self.app.ui.toolbarshell.setObjectName('Shell_TB')
  551. self.app.ui.addToolBar(self.app.ui.toolbarshell)
  552. self.app.ui.toolbartools = QtWidgets.QToolBar('Tools Toolbar')
  553. self.app.ui.toolbartools.setObjectName('Tools_TB')
  554. self.app.ui.addToolBar(self.app.ui.toolbartools)
  555. self.app.ui.exc_edit_toolbar = QtWidgets.QToolBar('Excellon Editor Toolbar')
  556. # self.app.ui.exc_edit_toolbar.setVisible(False)
  557. self.app.ui.exc_edit_toolbar.setObjectName('ExcEditor_TB')
  558. self.app.ui.addToolBar(self.app.ui.exc_edit_toolbar)
  559. self.app.ui.addToolBarBreak()
  560. self.app.ui.geo_edit_toolbar = QtWidgets.QToolBar('Geometry Editor Toolbar')
  561. # self.app.ui.geo_edit_toolbar.setVisible(False)
  562. self.app.ui.geo_edit_toolbar.setObjectName('GeoEditor_TB')
  563. self.app.ui.addToolBar(self.app.ui.geo_edit_toolbar)
  564. self.app.ui.grb_edit_toolbar = QtWidgets.QToolBar('Gerber Editor Toolbar')
  565. # self.app.ui.grb_edit_toolbar.setVisible(False)
  566. self.app.ui.grb_edit_toolbar.setObjectName('GrbEditor_TB')
  567. self.app.ui.addToolBar(self.app.ui.grb_edit_toolbar)
  568. if current_layout == 'minimal':
  569. self.app.ui.toolbarview.setVisible(False)
  570. self.app.ui.toolbarshell.setVisible(False)
  571. self.app.ui.geo_edit_toolbar.setVisible(False)
  572. self.app.ui.grb_edit_toolbar.setVisible(False)
  573. self.app.ui.exc_edit_toolbar.setVisible(False)
  574. self.app.ui.lock_toolbar(lock=True)
  575. # add all the actions to the toolbars
  576. self.app.ui.populate_toolbars()
  577. # reconnect all the signals to the toolbar actions
  578. self.app.connect_toolbar_signals()
  579. self.app.ui.grid_snap_btn.setChecked(True)
  580. self.app.ui.corner_snap_btn.setVisible(False)
  581. self.app.ui.snap_magnet.setVisible(False)
  582. self.app.ui.grid_gap_x_entry.setText(str(self.app.defaults["global_gridx"]))
  583. self.app.ui.grid_gap_y_entry.setText(str(self.app.defaults["global_gridy"]))
  584. self.app.ui.snap_max_dist_entry.setText(str(self.app.defaults["global_snap_max"]))
  585. self.app.ui.grid_gap_link_cb.setChecked(True)