GeneralGUIPrefGroupUI.py 35 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794
  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. self.theme_button.clicked.connect(self.on_theme_change)
  314. # #############################################################################
  315. # ############################# GUI COLORS SIGNALS ############################
  316. # #############################################################################
  317. # Setting selection (left - right) colors signals
  318. self.sf_color_entry.editingFinished.connect(self.on_sf_color_entry)
  319. self.sf_color_button.clicked.connect(self.on_sf_color_button)
  320. self.sf_color_alpha_spinner.valueChanged.connect(self.on_sf_color_spinner)
  321. self.sf_color_alpha_slider.valueChanged.connect(self.on_sf_color_slider)
  322. self.sl_color_entry.editingFinished.connect(self.on_sl_color_entry)
  323. self.sl_color_button.clicked.connect(self.on_sl_color_button)
  324. # Setting selection (right - left) colors signals
  325. self.alt_sf_color_entry.editingFinished.connect(self.on_alt_sf_color_entry)
  326. self.alt_sf_color_button.clicked.connect(self.on_alt_sf_color_button)
  327. self.alt_sf_color_alpha_spinner.valueChanged.connect(self.on_alt_sf_color_spinner)
  328. self.alt_sf_color_alpha_slider.valueChanged.connect(self.on_alt_sf_color_slider)
  329. self.alt_sl_color_entry.editingFinished.connect(self.on_alt_sl_color_entry)
  330. self.alt_sl_color_button.clicked.connect(self.on_alt_sl_color_button)
  331. # Setting Editor Draw colors signals
  332. self.draw_color_entry.editingFinished.connect(self.on_draw_color_entry)
  333. self.draw_color_button.clicked.connect(self.on_draw_color_button)
  334. self.sel_draw_color_entry.editingFinished.connect(self.on_sel_draw_color_entry)
  335. self.sel_draw_color_button.clicked.connect(self.on_sel_draw_color_button)
  336. self.proj_color_entry.editingFinished.connect(self.on_proj_color_entry)
  337. self.proj_color_button.clicked.connect(self.on_proj_color_button)
  338. self.proj_color_dis_entry.editingFinished.connect(self.on_proj_color_dis_entry)
  339. self.proj_color_dis_button.clicked.connect(self.on_proj_color_dis_button)
  340. self.layout_combo.activated.connect(self.on_layout)
  341. def on_theme_change(self):
  342. val = self.theme_radio.get_value()
  343. theme_settings = QtCore.QSettings("Open Source", "FlatCAM")
  344. if theme_settings.contains("theme"):
  345. theme = theme_settings.value('theme', type=str)
  346. else:
  347. theme = 'white'
  348. if val != theme:
  349. theme_settings.setValue('theme', val)
  350. # This will write the setting to the platform specific storage.
  351. del theme_settings
  352. self.app.on_app_restart()
  353. @staticmethod
  354. def handle_style(style):
  355. # set current style
  356. qsettings = QSettings("Open Source", "FlatCAM")
  357. qsettings.setValue('style', style)
  358. # This will write the setting to the platform specific storage.
  359. del qsettings
  360. @staticmethod
  361. def handle_hdpi(state):
  362. # set current HDPI
  363. qsettings = QSettings("Open Source", "FlatCAM")
  364. qsettings.setValue('hdpi', state)
  365. # This will write the setting to the platform specific storage.
  366. del qsettings
  367. # Setting selection colors (left - right) handlers
  368. def on_sf_color_entry(self):
  369. self.app.defaults['global_sel_fill'] = self.app.defaults['global_sel_fill'][7:9]
  370. self.sf_color_button.setStyleSheet("background-color:%s" % str(self.app.defaults['global_sel_fill'])[:7])
  371. def on_sf_color_button(self):
  372. current_color = QtGui.QColor(self.app.defaults['global_sel_fill'][:7])
  373. c_dialog = QtWidgets.QColorDialog()
  374. plot_fill_color = c_dialog.getColor(initial=current_color)
  375. if plot_fill_color.isValid() is False:
  376. return
  377. self.sf_color_button.setStyleSheet("background-color:%s" % str(plot_fill_color.name()))
  378. new_val = str(plot_fill_color.name()) + str(self.app.defaults['global_sel_fill'][7:9])
  379. self.sf_color_entry.set_value(new_val)
  380. self.app.defaults['global_sel_fill'] = new_val
  381. def on_sf_color_spinner(self):
  382. spinner_value = self.sf_color_alpha_spinner.value()
  383. self.sf_color_alpha_slider.setValue(spinner_value)
  384. self.app.defaults['global_sel_fill'] = self.app.defaults['global_sel_fill'][:7] + \
  385. (hex(spinner_value)[2:] if int(hex(spinner_value)[2:], 16) > 0 else '00')
  386. self.app.defaults['global_sel_line'] = self.app.defaults['global_sel_line'][:7] + \
  387. (hex(spinner_value)[2:] if int(hex(spinner_value)[2:], 16) > 0 else '00')
  388. def on_sf_color_slider(self):
  389. slider_value = self.sf_color_alpha_slider.value()
  390. self.sf_color_alpha_spinner.setValue(slider_value)
  391. def on_sl_color_entry(self):
  392. self.app.defaults['global_sel_line'] = self.sl_color_entry.get_value()[:7] + \
  393. self.app.defaults['global_sel_line'][7:9]
  394. self.sl_color_button.setStyleSheet("background-color:%s" % str(self.app.defaults['global_sel_line'])[:7])
  395. def on_sl_color_button(self):
  396. current_color = QtGui.QColor(self.app.defaults['global_sel_line'][:7])
  397. c_dialog = QtWidgets.QColorDialog()
  398. plot_line_color = c_dialog.getColor(initial=current_color)
  399. if plot_line_color.isValid() is False:
  400. return
  401. self.sl_color_button.setStyleSheet("background-color:%s" % str(plot_line_color.name()))
  402. new_val_line = str(plot_line_color.name()) + str(self.app.defaults['global_sel_line'][7:9])
  403. self.sl_color_entry.set_value(new_val_line)
  404. self.app.defaults['global_sel_line'] = new_val_line
  405. # Setting selection colors (right - left) handlers
  406. def on_alt_sf_color_entry(self):
  407. self.app.defaults['global_alt_sel_fill'] = self.alt_sf_color_entry.get_value()[:7] + \
  408. self.app.defaults['global_alt_sel_fill'][7:9]
  409. self.alt_sf_color_button.setStyleSheet(
  410. "background-color:%s" % str(self.app.defaults['global_alt_sel_fill'])[:7]
  411. )
  412. def on_alt_sf_color_button(self):
  413. current_color = QtGui.QColor(self.app.defaults['global_alt_sel_fill'][:7])
  414. c_dialog = QtWidgets.QColorDialog()
  415. plot_fill_color = c_dialog.getColor(initial=current_color)
  416. if plot_fill_color.isValid() is False:
  417. return
  418. self.alt_sf_color_button.setStyleSheet("background-color:%s" % str(plot_fill_color.name()))
  419. new_val = str(plot_fill_color.name()) + str(self.app.defaults['global_alt_sel_fill'][7:9])
  420. self.alt_sf_color_entry.set_value(new_val)
  421. self.app.defaults['global_alt_sel_fill'] = new_val
  422. def on_alt_sf_color_spinner(self):
  423. spinner_value = self.alt_sf_color_alpha_spinner.value()
  424. self.alt_sf_color_alpha_slider.setValue(spinner_value)
  425. self.app.defaults['global_alt_sel_fill'] = self.app.defaults['global_alt_sel_fill'][:7] + \
  426. (hex(spinner_value)[2:] if int(hex(spinner_value)[2:], 16) > 0 else '00')
  427. self.app.defaults['global_alt_sel_line'] = self.app.defaults['global_alt_sel_line'][:7] + \
  428. (hex(spinner_value)[2:] if int(hex(spinner_value)[2:], 16) > 0 else '00')
  429. def on_alt_sf_color_slider(self):
  430. slider_value = self.alt_sf_color_alpha_slider.value()
  431. self.alt_sf_color_alpha_spinner.setValue(slider_value)
  432. def on_alt_sl_color_entry(self):
  433. self.app.defaults['global_alt_sel_line'] = self.alt_sl_color_entry.get_value()[:7] + \
  434. self.app.defaults['global_alt_sel_line'][7:9]
  435. self.alt_sl_color_button.setStyleSheet(
  436. "background-color:%s" % str(self.app.defaults['global_alt_sel_line'])[:7]
  437. )
  438. def on_alt_sl_color_button(self):
  439. current_color = QtGui.QColor(self.app.defaults['global_alt_sel_line'][:7])
  440. c_dialog = QtWidgets.QColorDialog()
  441. plot_line_color = c_dialog.getColor(initial=current_color)
  442. if plot_line_color.isValid() is False:
  443. return
  444. self.alt_sl_color_button.setStyleSheet("background-color:%s" % str(plot_line_color.name()))
  445. new_val_line = str(plot_line_color.name()) + str(self.app.defaults['global_alt_sel_line'][7:9])
  446. self.alt_sl_color_entry.set_value(new_val_line)
  447. self.app.defaults['global_alt_sel_line'] = new_val_line
  448. # Setting Editor colors
  449. def on_draw_color_entry(self):
  450. self.app.defaults['global_draw_color'] = self.draw_color_entry.get_value()
  451. self.draw_color_button.setStyleSheet("background-color:%s" % str(self.app.defaults['global_draw_color']))
  452. def on_draw_color_button(self):
  453. current_color = QtGui.QColor(self.app.defaults['global_draw_color'])
  454. c_dialog = QtWidgets.QColorDialog()
  455. draw_color = c_dialog.getColor(initial=current_color)
  456. if draw_color.isValid() is False:
  457. return
  458. self.draw_color_button.setStyleSheet("background-color:%s" % str(draw_color.name()))
  459. new_val = str(draw_color.name())
  460. self.draw_color_entry.set_value(new_val)
  461. self.app.defaults['global_draw_color'] = new_val
  462. def on_sel_draw_color_entry(self):
  463. self.app.defaults['global_sel_draw_color'] = self.sel_draw_color_entry.get_value()
  464. self.sel_draw_color_button.setStyleSheet(
  465. "background-color:%s" % str(self.app.defaults['global_sel_draw_color']))
  466. def on_sel_draw_color_button(self):
  467. current_color = QtGui.QColor(self.app.defaults['global_sel_draw_color'])
  468. c_dialog = QtWidgets.QColorDialog()
  469. sel_draw_color = c_dialog.getColor(initial=current_color)
  470. if sel_draw_color.isValid() is False:
  471. return
  472. self.sel_draw_color_button.setStyleSheet("background-color:%s" % str(sel_draw_color.name()))
  473. new_val_sel = str(sel_draw_color.name())
  474. self.sel_draw_color_entry.set_value(new_val_sel)
  475. self.app.defaults['global_sel_draw_color'] = new_val_sel
  476. def on_proj_color_entry(self):
  477. self.app.defaults['global_proj_item_color'] = self.proj_color_entry.get_value()
  478. self.proj_color_button.setStyleSheet(
  479. "background-color:%s" % str(self.app.defaults['global_proj_item_color']))
  480. def on_proj_color_button(self):
  481. current_color = QtGui.QColor(self.app.defaults['global_proj_item_color'])
  482. c_dialog = QtWidgets.QColorDialog()
  483. proj_color = c_dialog.getColor(initial=current_color)
  484. if proj_color.isValid() is False:
  485. return
  486. self.proj_color_button.setStyleSheet("background-color:%s" % str(proj_color.name()))
  487. new_val_sel = str(proj_color.name())
  488. self.proj_color_entry.set_value(new_val_sel)
  489. self.app.defaults['global_proj_item_color'] = new_val_sel
  490. def on_proj_color_dis_entry(self):
  491. self.app.defaults['global_proj_item_dis_color'] = self.proj_color_dis_entry.get_value()
  492. self.proj_color_dis_button.setStyleSheet(
  493. "background-color:%s" % str(self.app.defaults['global_proj_item_dis_color']))
  494. def on_proj_color_dis_button(self):
  495. current_color = QtGui.QColor(self.app.defaults['global_proj_item_dis_color'])
  496. c_dialog = QtWidgets.QColorDialog()
  497. proj_color = c_dialog.getColor(initial=current_color)
  498. if proj_color.isValid() is False:
  499. return
  500. self.proj_color_dis_button.setStyleSheet("background-color:%s" % str(proj_color.name()))
  501. new_val_sel = str(proj_color.name())
  502. self.proj_color_dis_entry.set_value(new_val_sel)
  503. self.app.defaults['global_proj_item_dis_color'] = new_val_sel
  504. def on_layout(self, index=None, lay=None):
  505. """
  506. Set the toolbars layout (location)
  507. :param index:
  508. :param lay: Type of layout to be set on the toolbard
  509. :return: None
  510. """
  511. self.app.defaults.report_usage("on_layout()")
  512. if lay:
  513. current_layout = lay
  514. else:
  515. current_layout = self.layout_combo.get_value()
  516. lay_settings = QSettings("Open Source", "FlatCAM")
  517. lay_settings.setValue('layout', current_layout)
  518. # This will write the setting to the platform specific storage.
  519. del lay_settings
  520. # first remove the toolbars:
  521. try:
  522. self.app.ui.removeToolBar(self.app.ui.toolbarfile)
  523. self.app.ui.removeToolBar(self.app.ui.toolbargeo)
  524. self.app.ui.removeToolBar(self.app.ui.toolbarview)
  525. self.app.ui.removeToolBar(self.app.ui.toolbarshell)
  526. self.app.ui.removeToolBar(self.app.ui.toolbartools)
  527. self.app.ui.removeToolBar(self.app.ui.exc_edit_toolbar)
  528. self.app.ui.removeToolBar(self.app.ui.geo_edit_toolbar)
  529. self.app.ui.removeToolBar(self.app.ui.grb_edit_toolbar)
  530. self.app.ui.removeToolBar(self.app.ui.snap_toolbar)
  531. self.app.ui.removeToolBar(self.app.ui.toolbarshell)
  532. except Exception:
  533. pass
  534. if current_layout == 'compact':
  535. # ## TOOLBAR INSTALLATION # ##
  536. self.app.ui.toolbarfile = QtWidgets.QToolBar('File Toolbar')
  537. self.app.ui.toolbarfile.setObjectName('File_TB')
  538. self.app.ui.addToolBar(Qt.LeftToolBarArea, self.app.ui.toolbarfile)
  539. self.app.ui.toolbargeo = QtWidgets.QToolBar('Edit Toolbar')
  540. self.app.ui.toolbargeo.setObjectName('Edit_TB')
  541. self.app.ui.addToolBar(Qt.LeftToolBarArea, self.app.ui.toolbargeo)
  542. self.app.ui.toolbarshell = QtWidgets.QToolBar('Shell Toolbar')
  543. self.app.ui.toolbarshell.setObjectName('Shell_TB')
  544. self.app.ui.addToolBar(Qt.LeftToolBarArea, self.app.ui.toolbarshell)
  545. self.app.ui.toolbartools = QtWidgets.QToolBar('Tools Toolbar')
  546. self.app.ui.toolbartools.setObjectName('Tools_TB')
  547. self.app.ui.addToolBar(Qt.LeftToolBarArea, self.app.ui.toolbartools)
  548. self.app.ui.geo_edit_toolbar = QtWidgets.QToolBar('Geometry Editor Toolbar')
  549. # self.app.ui.geo_edit_toolbar.setVisible(False)
  550. self.app.ui.geo_edit_toolbar.setObjectName('GeoEditor_TB')
  551. self.app.ui.addToolBar(Qt.RightToolBarArea, self.app.ui.geo_edit_toolbar)
  552. self.app.ui.toolbarview = QtWidgets.QToolBar('View Toolbar')
  553. self.app.ui.toolbarview.setObjectName('View_TB')
  554. self.app.ui.addToolBar(Qt.RightToolBarArea, self.app.ui.toolbarview)
  555. self.app.ui.addToolBarBreak(area=Qt.RightToolBarArea)
  556. self.app.ui.grb_edit_toolbar = QtWidgets.QToolBar('Gerber Editor Toolbar')
  557. # self.app.ui.grb_edit_toolbar.setVisible(False)
  558. self.app.ui.grb_edit_toolbar.setObjectName('GrbEditor_TB')
  559. self.app.ui.addToolBar(Qt.RightToolBarArea, self.app.ui.grb_edit_toolbar)
  560. self.app.ui.exc_edit_toolbar = QtWidgets.QToolBar('Excellon Editor Toolbar')
  561. self.app.ui.exc_edit_toolbar.setObjectName('ExcEditor_TB')
  562. self.app.ui.addToolBar(Qt.RightToolBarArea, self.app.ui.exc_edit_toolbar)
  563. self.app.ui.snap_toolbar = QtWidgets.QToolBar('Grid Toolbar')
  564. self.app.ui.snap_toolbar.setObjectName('Snap_TB')
  565. self.app.ui.snap_toolbar.setMaximumHeight(30)
  566. self.app.ui.splitter_left.addWidget(self.app.ui.snap_toolbar)
  567. self.app.ui.corner_snap_btn.setVisible(True)
  568. self.app.ui.snap_magnet.setVisible(True)
  569. else:
  570. # ## TOOLBAR INSTALLATION # ##
  571. self.app.ui.toolbarfile = QtWidgets.QToolBar('File Toolbar')
  572. self.app.ui.toolbarfile.setObjectName('File_TB')
  573. self.app.ui.addToolBar(self.app.ui.toolbarfile)
  574. self.app.ui.toolbargeo = QtWidgets.QToolBar('Edit Toolbar')
  575. self.app.ui.toolbargeo.setObjectName('Edit_TB')
  576. self.app.ui.addToolBar(self.app.ui.toolbargeo)
  577. self.app.ui.toolbarview = QtWidgets.QToolBar('View Toolbar')
  578. self.app.ui.toolbarview.setObjectName('View_TB')
  579. self.app.ui.addToolBar(self.app.ui.toolbarview)
  580. self.app.ui.toolbarshell = QtWidgets.QToolBar('Shell Toolbar')
  581. self.app.ui.toolbarshell.setObjectName('Shell_TB')
  582. self.app.ui.addToolBar(self.app.ui.toolbarshell)
  583. self.app.ui.toolbartools = QtWidgets.QToolBar('Tools Toolbar')
  584. self.app.ui.toolbartools.setObjectName('Tools_TB')
  585. self.app.ui.addToolBar(self.app.ui.toolbartools)
  586. self.app.ui.exc_edit_toolbar = QtWidgets.QToolBar('Excellon Editor Toolbar')
  587. # self.app.ui.exc_edit_toolbar.setVisible(False)
  588. self.app.ui.exc_edit_toolbar.setObjectName('ExcEditor_TB')
  589. self.app.ui.addToolBar(self.app.ui.exc_edit_toolbar)
  590. self.app.ui.addToolBarBreak()
  591. self.app.ui.geo_edit_toolbar = QtWidgets.QToolBar('Geometry Editor Toolbar')
  592. # self.app.ui.geo_edit_toolbar.setVisible(False)
  593. self.app.ui.geo_edit_toolbar.setObjectName('GeoEditor_TB')
  594. self.app.ui.addToolBar(self.app.ui.geo_edit_toolbar)
  595. self.app.ui.grb_edit_toolbar = QtWidgets.QToolBar('Gerber Editor Toolbar')
  596. # self.app.ui.grb_edit_toolbar.setVisible(False)
  597. self.app.ui.grb_edit_toolbar.setObjectName('GrbEditor_TB')
  598. self.app.ui.addToolBar(self.app.ui.grb_edit_toolbar)
  599. self.app.ui.snap_toolbar = QtWidgets.QToolBar('Grid Toolbar')
  600. self.app.ui.snap_toolbar.setObjectName('Snap_TB')
  601. # self.app.ui.snap_toolbar.setMaximumHeight(30)
  602. self.app.ui.addToolBar(self.app.ui.snap_toolbar)
  603. self.app.ui.corner_snap_btn.setVisible(False)
  604. self.app.ui.snap_magnet.setVisible(False)
  605. if current_layout == 'minimal':
  606. self.app.ui.toolbarview.setVisible(False)
  607. self.app.ui.toolbarshell.setVisible(False)
  608. self.app.ui.snap_toolbar.setVisible(False)
  609. self.app.ui.geo_edit_toolbar.setVisible(False)
  610. self.app.ui.grb_edit_toolbar.setVisible(False)
  611. self.app.ui.exc_edit_toolbar.setVisible(False)
  612. self.app.ui.lock_toolbar(lock=True)
  613. # add all the actions to the toolbars
  614. self.app.ui.populate_toolbars()
  615. # reconnect all the signals to the toolbar actions
  616. self.app.connect_toolbar_signals()
  617. self.app.ui.grid_snap_btn.setChecked(True)
  618. self.app.ui.on_grid_snap_triggered(state=True)
  619. self.app.ui.grid_gap_x_entry.setText(str(self.app.defaults["global_gridx"]))
  620. self.app.ui.grid_gap_y_entry.setText(str(self.app.defaults["global_gridy"]))
  621. self.app.ui.snap_max_dist_entry.setText(str(self.app.defaults["global_snap_max"]))
  622. self.app.ui.grid_gap_link_cb.setChecked(True)