GeneralAPPSetGroupUI.py 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469
  1. from PyQt5 import QtCore, QtWidgets, QtGui
  2. from PyQt5.QtCore import QSettings
  3. from flatcamGUI.GUIElements import FCDoubleSpinner, FCCheckBox, FCComboBox, RadioSet, OptionalInputSection, FCSpinner, \
  4. FCEntry
  5. from flatcamGUI.preferences import settings
  6. from flatcamGUI.preferences.OptionsGroupUI import OptionsGroupUI
  7. class GeneralAPPSetGroupUI(OptionsGroupUI):
  8. def __init__(self, decimals=4, parent=None):
  9. super(GeneralAPPSetGroupUI, self).__init__(self)
  10. self.setTitle(str(_("App Settings")))
  11. self.decimals = decimals
  12. theme_settings = QtCore.QSettings("Open Source", "FlatCAM")
  13. if theme_settings.contains("theme"):
  14. theme = theme_settings.value('theme', type=str)
  15. else:
  16. theme = 'white'
  17. if theme == 'white':
  18. self.resource_loc = 'assets/resources'
  19. else:
  20. self.resource_loc = 'assets/resources'
  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. # GRID Settings
  27. self.grid_label = QtWidgets.QLabel('<b>%s</b>' % _('Grid Settings'))
  28. grid0.addWidget(self.grid_label, 0, 0, 1, 2)
  29. # Grid X Entry
  30. self.gridx_label = QtWidgets.QLabel('%s:' % _('X value'))
  31. self.gridx_label.setToolTip(
  32. _("This is the Grid snap value on X axis.")
  33. )
  34. self.gridx_entry = FCDoubleSpinner()
  35. self.gridx_entry.set_precision(self.decimals)
  36. self.gridx_entry.setSingleStep(0.1)
  37. grid0.addWidget(self.gridx_label, 1, 0)
  38. grid0.addWidget(self.gridx_entry, 1, 1)
  39. # Grid Y Entry
  40. self.gridy_label = QtWidgets.QLabel('%s:' % _('Y value'))
  41. self.gridy_label.setToolTip(
  42. _("This is the Grid snap value on Y axis.")
  43. )
  44. self.gridy_entry = FCDoubleSpinner()
  45. self.gridy_entry.set_precision(self.decimals)
  46. self.gridy_entry.setSingleStep(0.1)
  47. grid0.addWidget(self.gridy_label, 2, 0)
  48. grid0.addWidget(self.gridy_entry, 2, 1)
  49. # Snap Max Entry
  50. self.snap_max_label = QtWidgets.QLabel('%s:' % _('Snap Max'))
  51. self.snap_max_label.setToolTip(_("Max. magnet distance"))
  52. self.snap_max_dist_entry = FCDoubleSpinner()
  53. self.snap_max_dist_entry.set_precision(self.decimals)
  54. self.snap_max_dist_entry.setSingleStep(0.1)
  55. grid0.addWidget(self.snap_max_label, 3, 0)
  56. grid0.addWidget(self.snap_max_dist_entry, 3, 1)
  57. separator_line = QtWidgets.QFrame()
  58. separator_line.setFrameShape(QtWidgets.QFrame.HLine)
  59. separator_line.setFrameShadow(QtWidgets.QFrame.Sunken)
  60. grid0.addWidget(separator_line, 4, 0, 1, 2)
  61. # Workspace
  62. self.workspace_label = QtWidgets.QLabel('<b>%s</b>' % _('Workspace Settings'))
  63. grid0.addWidget(self.workspace_label, 5, 0, 1, 2)
  64. self.workspace_cb = FCCheckBox('%s' % _('Active'))
  65. self.workspace_cb.setToolTip(
  66. _("Draw a delimiting rectangle on canvas.\n"
  67. "The purpose is to illustrate the limits for our work.")
  68. )
  69. grid0.addWidget(self.workspace_cb, 6, 0, 1, 2)
  70. self.workspace_type_lbl = QtWidgets.QLabel('%s:' % _('Size'))
  71. self.workspace_type_lbl.setToolTip(
  72. _("Select the type of rectangle to be used on canvas,\n"
  73. "as valid workspace.")
  74. )
  75. self.wk_cb = FCComboBox()
  76. grid0.addWidget(self.workspace_type_lbl, 7, 0)
  77. grid0.addWidget(self.wk_cb, 7, 1)
  78. self.pagesize = {}
  79. self.pagesize.update(
  80. {
  81. 'A0': (841, 1189),
  82. 'A1': (594, 841),
  83. 'A2': (420, 594),
  84. 'A3': (297, 420),
  85. 'A4': (210, 297),
  86. 'A5': (148, 210),
  87. 'A6': (105, 148),
  88. 'A7': (74, 105),
  89. 'A8': (52, 74),
  90. 'A9': (37, 52),
  91. 'A10': (26, 37),
  92. 'B0': (1000, 1414),
  93. 'B1': (707, 1000),
  94. 'B2': (500, 707),
  95. 'B3': (353, 500),
  96. 'B4': (250, 353),
  97. 'B5': (176, 250),
  98. 'B6': (125, 176),
  99. 'B7': (88, 125),
  100. 'B8': (62, 88),
  101. 'B9': (44, 62),
  102. 'B10': (31, 44),
  103. 'C0': (917, 1297),
  104. 'C1': (648, 917),
  105. 'C2': (458, 648),
  106. 'C3': (324, 458),
  107. 'C4': (229, 324),
  108. 'C5': (162, 229),
  109. 'C6': (114, 162),
  110. 'C7': (81, 114),
  111. 'C8': (57, 81),
  112. 'C9': (40, 57),
  113. 'C10': (28, 40),
  114. # American paper sizes
  115. 'LETTER': (8.5, 11),
  116. 'LEGAL': (8.5, 14),
  117. 'ELEVENSEVENTEEN': (11, 17),
  118. # From https://en.wikipedia.org/wiki/Paper_size
  119. 'JUNIOR_LEGAL': (5, 8),
  120. 'HALF_LETTER': (5.5, 8),
  121. 'GOV_LETTER': (8, 10.5),
  122. 'GOV_LEGAL': (8.5, 13),
  123. 'LEDGER': (17, 11),
  124. }
  125. )
  126. page_size_list = list(self.pagesize.keys())
  127. self.wk_cb.addItems(page_size_list)
  128. # Page orientation
  129. self.wk_orientation_label = QtWidgets.QLabel('%s:' % _("Orientation"))
  130. self.wk_orientation_label.setToolTip(_("Can be:\n"
  131. "- Portrait\n"
  132. "- Landscape"))
  133. self.wk_orientation_radio = RadioSet([{'label': _('Portrait'), 'value': 'p'},
  134. {'label': _('Landscape'), 'value': 'l'},
  135. ], stretch=False)
  136. self.wks = OptionalInputSection(self.workspace_cb,
  137. [
  138. self.workspace_type_lbl,
  139. self.wk_cb,
  140. self.wk_orientation_label,
  141. self.wk_orientation_radio
  142. ])
  143. grid0.addWidget(self.wk_orientation_label, 8, 0)
  144. grid0.addWidget(self.wk_orientation_radio, 8, 1)
  145. separator_line = QtWidgets.QFrame()
  146. separator_line.setFrameShape(QtWidgets.QFrame.HLine)
  147. separator_line.setFrameShadow(QtWidgets.QFrame.Sunken)
  148. grid0.addWidget(separator_line, 9, 0, 1, 2)
  149. # Font Size
  150. self.font_size_label = QtWidgets.QLabel('<b>%s</b>' % _('Font Size'))
  151. grid0.addWidget(self.font_size_label, 10, 0, 1, 2)
  152. # Notebook Font Size
  153. self.notebook_font_size_label = QtWidgets.QLabel('%s:' % _('Notebook'))
  154. self.notebook_font_size_label.setToolTip(
  155. _("This sets the font size for the elements found in the Notebook.\n"
  156. "The notebook is the collapsible area in the left side of the GUI,\n"
  157. "and include the Project, Selected and Tool tabs.")
  158. )
  159. self.notebook_font_size_spinner = FCSpinner()
  160. self.notebook_font_size_spinner.set_range(8, 40)
  161. self.notebook_font_size_spinner.setWrapping(True)
  162. qsettings = QSettings("Open Source", "FlatCAM")
  163. if qsettings.contains("notebook_font_size"):
  164. self.notebook_font_size_spinner.set_value(qsettings.value('notebook_font_size', type=int))
  165. else:
  166. self.notebook_font_size_spinner.set_value(12)
  167. grid0.addWidget(self.notebook_font_size_label, 11, 0)
  168. grid0.addWidget(self.notebook_font_size_spinner, 11, 1)
  169. # Axis Font Size
  170. self.axis_font_size_label = QtWidgets.QLabel('%s:' % _('Axis'))
  171. self.axis_font_size_label.setToolTip(
  172. _("This sets the font size for canvas axis.")
  173. )
  174. self.axis_font_size_spinner = FCSpinner()
  175. self.axis_font_size_spinner.set_range(0, 40)
  176. self.axis_font_size_spinner.setWrapping(True)
  177. qsettings = QSettings("Open Source", "FlatCAM")
  178. if qsettings.contains("axis_font_size"):
  179. self.axis_font_size_spinner.set_value(qsettings.value('axis_font_size', type=int))
  180. else:
  181. self.axis_font_size_spinner.set_value(8)
  182. grid0.addWidget(self.axis_font_size_label, 12, 0)
  183. grid0.addWidget(self.axis_font_size_spinner, 12, 1)
  184. # TextBox Font Size
  185. self.textbox_font_size_label = QtWidgets.QLabel('%s:' % _('Textbox'))
  186. self.textbox_font_size_label.setToolTip(
  187. _("This sets the font size for the Textbox GUI\n"
  188. "elements that are used in FlatCAM.")
  189. )
  190. self.textbox_font_size_spinner = FCSpinner()
  191. self.textbox_font_size_spinner.set_range(8, 40)
  192. self.textbox_font_size_spinner.setWrapping(True)
  193. qsettings = QSettings("Open Source", "FlatCAM")
  194. if qsettings.contains("textbox_font_size"):
  195. self.textbox_font_size_spinner.set_value(settings.value('textbox_font_size', type=int))
  196. else:
  197. self.textbox_font_size_spinner.set_value(10)
  198. grid0.addWidget(self.textbox_font_size_label, 13, 0)
  199. grid0.addWidget(self.textbox_font_size_spinner, 13, 1)
  200. separator_line = QtWidgets.QFrame()
  201. separator_line.setFrameShape(QtWidgets.QFrame.HLine)
  202. separator_line.setFrameShadow(QtWidgets.QFrame.Sunken)
  203. grid0.addWidget(separator_line, 14, 0, 1, 2)
  204. # -----------------------------------------------------------
  205. # -------------- MOUSE SETTINGS -----------------------------
  206. # -----------------------------------------------------------
  207. self.mouse_lbl = QtWidgets.QLabel('<b>%s</b>' % _('Mouse Settings'))
  208. grid0.addWidget(self.mouse_lbl, 21, 0, 1, 2)
  209. # Mouse Cursor Shape
  210. self.cursor_lbl = QtWidgets.QLabel('%s:' % _('Cursor Shape'))
  211. self.cursor_lbl.setToolTip(
  212. _("Choose a mouse cursor shape.\n"
  213. "- Small -> with a customizable size.\n"
  214. "- Big -> Infinite lines")
  215. )
  216. self.cursor_radio = RadioSet([
  217. {"label": _("Small"), "value": "small"},
  218. {"label": _("Big"), "value": "big"}
  219. ], orientation='horizontal', stretch=False)
  220. grid0.addWidget(self.cursor_lbl, 22, 0)
  221. grid0.addWidget(self.cursor_radio, 22, 1)
  222. # Mouse Cursor Size
  223. self.cursor_size_lbl = QtWidgets.QLabel('%s:' % _('Cursor Size'))
  224. self.cursor_size_lbl.setToolTip(
  225. _("Set the size of the mouse cursor, in pixels.")
  226. )
  227. self.cursor_size_entry = FCSpinner()
  228. self.cursor_size_entry.set_range(10, 70)
  229. self.cursor_size_entry.setWrapping(True)
  230. grid0.addWidget(self.cursor_size_lbl, 23, 0)
  231. grid0.addWidget(self.cursor_size_entry, 23, 1)
  232. # Cursor Width
  233. self.cursor_width_lbl = QtWidgets.QLabel('%s:' % _('Cursor Width'))
  234. self.cursor_width_lbl.setToolTip(
  235. _("Set the line width of the mouse cursor, in pixels.")
  236. )
  237. self.cursor_width_entry = FCSpinner()
  238. self.cursor_width_entry.set_range(1, 10)
  239. self.cursor_width_entry.setWrapping(True)
  240. grid0.addWidget(self.cursor_width_lbl, 24, 0)
  241. grid0.addWidget(self.cursor_width_entry, 24, 1)
  242. # Cursor Color Enable
  243. self.mouse_cursor_color_cb = FCCheckBox(label='%s' % _('Cursor Color'))
  244. self.mouse_cursor_color_cb.setToolTip(
  245. _("Check this box to color mouse cursor.")
  246. )
  247. grid0.addWidget(self.mouse_cursor_color_cb, 25, 0, 1, 2)
  248. # Cursor Color
  249. self.mouse_color_label = QtWidgets.QLabel('%s:' % _('Cursor Color'))
  250. self.mouse_color_label.setToolTip(
  251. _("Set the color of the mouse cursor.")
  252. )
  253. self.mouse_cursor_entry = FCEntry()
  254. self.mouse_cursor_button = QtWidgets.QPushButton()
  255. self.mouse_cursor_button.setFixedSize(15, 15)
  256. self.form_box_child_1 = QtWidgets.QHBoxLayout()
  257. self.form_box_child_1.addWidget(self.mouse_cursor_entry)
  258. self.form_box_child_1.addWidget(self.mouse_cursor_button)
  259. self.form_box_child_1.setAlignment(QtCore.Qt.AlignLeft | QtCore.Qt.AlignVCenter)
  260. grid0.addWidget(self.mouse_color_label, 26, 0)
  261. grid0.addLayout(self.form_box_child_1, 26, 1)
  262. self.mois = OptionalInputSection(
  263. self.mouse_cursor_color_cb,
  264. [
  265. self.mouse_color_label,
  266. self.mouse_cursor_entry,
  267. self.mouse_cursor_button
  268. ]
  269. )
  270. # Select mouse pan button
  271. self.panbuttonlabel = QtWidgets.QLabel('%s:' % _('Pan Button'))
  272. self.panbuttonlabel.setToolTip(
  273. _("Select the mouse button to use for panning:\n"
  274. "- MMB --> Middle Mouse Button\n"
  275. "- RMB --> Right Mouse Button")
  276. )
  277. self.pan_button_radio = RadioSet([{'label': _('MMB'), 'value': '3'},
  278. {'label': _('RMB'), 'value': '2'}])
  279. grid0.addWidget(self.panbuttonlabel, 27, 0)
  280. grid0.addWidget(self.pan_button_radio, 27, 1)
  281. # Multiple Selection Modifier Key
  282. self.mselectlabel = QtWidgets.QLabel('%s:' % _('Multiple Selection'))
  283. self.mselectlabel.setToolTip(
  284. _("Select the key used for multiple selection.")
  285. )
  286. self.mselect_radio = RadioSet([{'label': _('CTRL'), 'value': 'Control'},
  287. {'label': _('SHIFT'), 'value': 'Shift'}])
  288. grid0.addWidget(self.mselectlabel, 28, 0)
  289. grid0.addWidget(self.mselect_radio, 28, 1)
  290. separator_line = QtWidgets.QFrame()
  291. separator_line.setFrameShape(QtWidgets.QFrame.HLine)
  292. separator_line.setFrameShadow(QtWidgets.QFrame.Sunken)
  293. grid0.addWidget(separator_line, 29, 0, 1, 2)
  294. # Delete confirmation
  295. self.delete_conf_cb = FCCheckBox(_('Delete object confirmation'))
  296. self.delete_conf_cb.setToolTip(
  297. _("When checked the application will ask for user confirmation\n"
  298. "whenever the Delete object(s) event is triggered, either by\n"
  299. "menu shortcut or key shortcut.")
  300. )
  301. grid0.addWidget(self.delete_conf_cb, 30, 0, 1, 2)
  302. # Open behavior
  303. self.open_style_cb = FCCheckBox('%s' % _('"Open" behavior'))
  304. self.open_style_cb.setToolTip(
  305. _("When checked the path for the last saved file is used when saving files,\n"
  306. "and the path for the last opened file is used when opening files.\n\n"
  307. "When unchecked the path for opening files is the one used last: either the\n"
  308. "path for saving files or the path for opening files.")
  309. )
  310. grid0.addWidget(self.open_style_cb, 31, 0, 1, 2)
  311. # Enable/Disable ToolTips globally
  312. self.toggle_tooltips_cb = FCCheckBox(label=_('Enable ToolTips'))
  313. self.toggle_tooltips_cb.setToolTip(
  314. _("Check this box if you want to have toolTips displayed\n"
  315. "when hovering with mouse over items throughout the App.")
  316. )
  317. grid0.addWidget(self.toggle_tooltips_cb, 32, 0, 1, 2)
  318. # Machinist settings that allow unsafe settings
  319. self.machinist_cb = FCCheckBox(_("Allow Machinist Unsafe Settings"))
  320. self.machinist_cb.setToolTip(
  321. _("If checked, some of the application settings will be allowed\n"
  322. "to have values that are usually unsafe to use.\n"
  323. "Like Z travel negative values or Z Cut positive values.\n"
  324. "It will applied at the next application start.\n"
  325. "<<WARNING>>: Don't change this unless you know what you are doing !!!")
  326. )
  327. grid0.addWidget(self.machinist_cb, 33, 0, 1, 2)
  328. # Bookmarks Limit in the Help Menu
  329. self.bm_limit_spinner = FCSpinner()
  330. self.bm_limit_spinner.set_range(0, 9999)
  331. self.bm_limit_label = QtWidgets.QLabel('%s:' % _('Bookmarks limit'))
  332. self.bm_limit_label.setToolTip(
  333. _("The maximum number of bookmarks that may be installed in the menu.\n"
  334. "The number of bookmarks in the bookmark manager may be greater\n"
  335. "but the menu will hold only so much.")
  336. )
  337. grid0.addWidget(self.bm_limit_label, 34, 0)
  338. grid0.addWidget(self.bm_limit_spinner, 34, 1)
  339. # Activity monitor icon
  340. self.activity_label = QtWidgets.QLabel('%s:' % _("Activity Icon"))
  341. self.activity_label.setToolTip(
  342. _("Select the GIF that show activity when FlatCAM is active.")
  343. )
  344. self.activity_combo = FCComboBox()
  345. self.activity_combo.addItems(['Ball black', 'Ball green', 'Arrow green', 'Eclipse green'])
  346. grid0.addWidget(self.activity_label, 35, 0)
  347. grid0.addWidget(self.activity_combo, 35, 1)
  348. self.layout.addStretch()
  349. self.mouse_cursor_color_cb.stateChanged.connect(self.on_mouse_cursor_color_enable)
  350. self.mouse_cursor_entry.editingFinished.connect(self.on_mouse_cursor_entry)
  351. self.mouse_cursor_button.clicked.connect(self.on_mouse_cursor_button)
  352. def on_mouse_cursor_color_enable(self, val):
  353. if val:
  354. self.app.cursor_color_3D = self.app.defaults["global_cursor_color"]
  355. else:
  356. theme_settings = QtCore.QSettings("Open Source", "FlatCAM")
  357. if theme_settings.contains("theme"):
  358. theme = theme_settings.value('theme', type=str)
  359. else:
  360. theme = 'white'
  361. if theme == 'white':
  362. self.app.cursor_color_3D = 'black'
  363. else:
  364. self.app.cursor_color_3D = 'gray'
  365. def on_mouse_cursor_entry(self):
  366. self.app.defaults['global_cursor_color'] = self.mouse_cursor_entry.get_value()
  367. self.mouse_cursor_button.setStyleSheet("background-color:%s" % str(self.app.defaults['global_cursor_color']))
  368. self.app.cursor_color_3D = self.app.defaults["global_cursor_color"]
  369. def on_mouse_cursor_button(self):
  370. current_color = QtGui.QColor(self.app.defaults['global_cursor_color'])
  371. c_dialog = QtWidgets.QColorDialog()
  372. proj_color = c_dialog.getColor(initial=current_color)
  373. if proj_color.isValid() is False:
  374. return
  375. self.mouse_cursor_button.setStyleSheet("background-color:%s" % str(proj_color.name()))
  376. new_val_sel = str(proj_color.name())
  377. self.mouse_cursor_entry.set_value(new_val_sel)
  378. self.app.defaults['global_cursor_color'] = new_val_sel
  379. self.app.cursor_color_3D = self.app.defaults["global_cursor_color"]