GeneralAppPrefGroupUI.py 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401
  1. import sys
  2. from PyQt5 import QtWidgets
  3. from PyQt5.QtCore import QSettings
  4. from appGUI.GUIElements import RadioSet, FCSpinner, FCCheckBox, FCComboBox, FCButton, OptionalInputSection, \
  5. FCDoubleSpinner
  6. from appGUI.preferences.OptionsGroupUI import OptionsGroupUI
  7. import gettext
  8. import appTranslation as fcTranslate
  9. import builtins
  10. fcTranslate.apply_language('strings')
  11. if '_' not in builtins.__dict__:
  12. _ = gettext.gettext
  13. settings = QSettings("Open Source", "FlatCAM")
  14. if settings.contains("machinist"):
  15. machinist_setting = settings.value('machinist', type=int)
  16. else:
  17. machinist_setting = 0
  18. class GeneralAppPrefGroupUI(OptionsGroupUI):
  19. def __init__(self, decimals=4, parent=None):
  20. super(GeneralAppPrefGroupUI, self).__init__(self, parent=parent)
  21. self.setTitle(_("App Preferences"))
  22. self.decimals = decimals
  23. # Create a form layout for the Application general settings
  24. grid0 = QtWidgets.QGridLayout()
  25. self.layout.addLayout(grid0)
  26. grid0.setColumnStretch(0, 0)
  27. grid0.setColumnStretch(1, 1)
  28. # Units for FlatCAM
  29. self.unitslabel = QtWidgets.QLabel('<span style="color:red;"><b>%s:</b></span>' % _('Units'))
  30. self.unitslabel.setToolTip(_("The default value for FlatCAM units.\n"
  31. "Whatever is selected here is set every time\n"
  32. "FlatCAM is started."))
  33. self.units_radio = RadioSet([{'label': _('MM'), 'value': 'MM'},
  34. {'label': _('IN'), 'value': 'IN'}])
  35. grid0.addWidget(self.unitslabel, 0, 0)
  36. grid0.addWidget(self.units_radio, 0, 1)
  37. # Precision Metric
  38. self.precision_metric_label = QtWidgets.QLabel('%s:' % _('Precision MM'))
  39. self.precision_metric_label.setToolTip(
  40. _("The number of decimals used throughout the application\n"
  41. "when the set units are in METRIC system.\n"
  42. "Any change here require an application restart.")
  43. )
  44. self.precision_metric_entry = FCSpinner()
  45. self.precision_metric_entry.set_range(2, 16)
  46. self.precision_metric_entry.setWrapping(True)
  47. grid0.addWidget(self.precision_metric_label, 1, 0)
  48. grid0.addWidget(self.precision_metric_entry, 1, 1)
  49. # Precision Inch
  50. self.precision_inch_label = QtWidgets.QLabel('%s:' % _('Precision INCH'))
  51. self.precision_inch_label.setToolTip(
  52. _("The number of decimals used throughout the application\n"
  53. "when the set units are in INCH system.\n"
  54. "Any change here require an application restart.")
  55. )
  56. self.precision_inch_entry = FCSpinner()
  57. self.precision_inch_entry.set_range(2, 16)
  58. self.precision_inch_entry.setWrapping(True)
  59. grid0.addWidget(self.precision_inch_label, 2, 0)
  60. grid0.addWidget(self.precision_inch_entry, 2, 1)
  61. # Graphic Engine for FlatCAM
  62. self.ge_label = QtWidgets.QLabel('<b>%s:</b>' % _('Graphic Engine'))
  63. self.ge_label.setToolTip(_("Choose what graphic engine to use in FlatCAM.\n"
  64. "Legacy(2D) -> reduced functionality, slow performance but enhanced compatibility.\n"
  65. "OpenGL(3D) -> full functionality, high performance\n"
  66. "Some graphic cards are too old and do not work in OpenGL(3D) mode, like:\n"
  67. "Intel HD3000 or older. In this case the plot area will be black therefore\n"
  68. "use the Legacy(2D) mode."))
  69. self.ge_radio = RadioSet([{'label': _('Legacy(2D)'), 'value': '2D'},
  70. {'label': _('OpenGL(3D)'), 'value': '3D'}],
  71. orientation='vertical')
  72. grid0.addWidget(self.ge_label, 3, 0)
  73. grid0.addWidget(self.ge_radio, 3, 1)
  74. separator_line = QtWidgets.QFrame()
  75. separator_line.setFrameShape(QtWidgets.QFrame.HLine)
  76. separator_line.setFrameShadow(QtWidgets.QFrame.Sunken)
  77. grid0.addWidget(separator_line, 4, 0, 1, 2)
  78. # Application Level for FlatCAM
  79. self.app_level_label = QtWidgets.QLabel('<span style="color:red;"><b>%s:</b></span>' % _('APP. LEVEL'))
  80. self.app_level_label.setToolTip(_("Choose the default level of usage for FlatCAM.\n"
  81. "BASIC level -> reduced functionality, best for beginner's.\n"
  82. "ADVANCED level -> full functionality.\n\n"
  83. "The choice here will influence the parameters in\n"
  84. "the Selected Tab for all kinds of FlatCAM objects."))
  85. self.app_level_radio = RadioSet([{'label': _('Basic'), 'value': 'b'},
  86. {'label': _('Advanced'), 'value': 'a'}])
  87. grid0.addWidget(self.app_level_label, 5, 0)
  88. grid0.addWidget(self.app_level_radio, 5, 1)
  89. # Portability for FlatCAM
  90. self.portability_cb = FCCheckBox('%s' % _('Portable app'))
  91. self.portability_cb.setToolTip(_("Choose if the application should run as portable.\n\n"
  92. "If Checked the application will run portable,\n"
  93. "which means that the preferences files will be saved\n"
  94. "in the application folder, in the lib\\config subfolder."))
  95. grid0.addWidget(self.portability_cb, 6, 0, 1, 2)
  96. separator_line = QtWidgets.QFrame()
  97. separator_line.setFrameShape(QtWidgets.QFrame.HLine)
  98. separator_line.setFrameShadow(QtWidgets.QFrame.Sunken)
  99. grid0.addWidget(separator_line, 7, 0, 1, 2)
  100. # Languages for FlatCAM
  101. self.languagelabel = QtWidgets.QLabel('<b>%s</b>' % _('Languages'))
  102. self.languagelabel.setToolTip(_("Set the language used throughout FlatCAM."))
  103. self.language_cb = FCComboBox()
  104. grid0.addWidget(self.languagelabel, 8, 0, 1, 2)
  105. grid0.addWidget(self.language_cb, 9, 0, 1, 2)
  106. self.language_apply_btn = FCButton(_("Apply Language"))
  107. self.language_apply_btn.setToolTip(_("Set the language used throughout FlatCAM.\n"
  108. "The app will restart after click."))
  109. grid0.addWidget(self.language_apply_btn, 15, 0, 1, 2)
  110. separator_line = QtWidgets.QFrame()
  111. separator_line.setFrameShape(QtWidgets.QFrame.HLine)
  112. separator_line.setFrameShadow(QtWidgets.QFrame.Sunken)
  113. grid0.addWidget(separator_line, 16, 0, 1, 2)
  114. # -----------------------------------------------------------
  115. # ----------- APPLICATION STARTUP SETTINGS ------------------
  116. # -----------------------------------------------------------
  117. self.startup_label = QtWidgets.QLabel('<b>%s</b>' % _('Startup Settings'))
  118. grid0.addWidget(self.startup_label, 17, 0, 1, 2)
  119. # Splash Screen
  120. self.splash_cb = FCCheckBox('%s' % _('Splash Screen'))
  121. self.splash_cb.setToolTip(
  122. _("Enable display of the splash screen at application startup.")
  123. )
  124. qsettings = QSettings("Open Source", "FlatCAM")
  125. if qsettings.value("splash_screen"):
  126. self.splash_cb.set_value(True)
  127. else:
  128. self.splash_cb.set_value(False)
  129. grid0.addWidget(self.splash_cb, 18, 0, 1, 2)
  130. # Sys Tray Icon
  131. self.systray_cb = FCCheckBox('%s' % _('Sys Tray Icon'))
  132. self.systray_cb.setToolTip(
  133. _("Enable display of FlatCAM icon in Sys Tray.")
  134. )
  135. grid0.addWidget(self.systray_cb, 19, 0, 1, 2)
  136. # Shell StartUp CB
  137. self.shell_startup_cb = FCCheckBox(label='%s' % _('Show Shell'))
  138. self.shell_startup_cb.setToolTip(
  139. _("Check this box if you want the shell to\n"
  140. "start automatically at startup.")
  141. )
  142. grid0.addWidget(self.shell_startup_cb, 20, 0, 1, 2)
  143. # Project at StartUp CB
  144. self.project_startup_cb = FCCheckBox(label='%s' % _('Show Project'))
  145. self.project_startup_cb.setToolTip(
  146. _("Check this box if you want the project/selected/tool tab area to\n"
  147. "to be shown automatically at startup.")
  148. )
  149. grid0.addWidget(self.project_startup_cb, 21, 0, 1, 2)
  150. # Version Check CB
  151. self.version_check_cb = FCCheckBox(label='%s' % _('Version Check'))
  152. self.version_check_cb.setToolTip(
  153. _("Check this box if you want to check\n"
  154. "for a new version automatically at startup.")
  155. )
  156. grid0.addWidget(self.version_check_cb, 22, 0, 1, 2)
  157. # Send Stats CB
  158. self.send_stats_cb = FCCheckBox(label='%s' % _('Send Statistics'))
  159. self.send_stats_cb.setToolTip(
  160. _("Check this box if you agree to send anonymous\n"
  161. "stats automatically at startup, to help improve FlatCAM.")
  162. )
  163. grid0.addWidget(self.send_stats_cb, 23, 0, 1, 2)
  164. self.ois_version_check = OptionalInputSection(self.version_check_cb, [self.send_stats_cb])
  165. separator_line = QtWidgets.QFrame()
  166. separator_line.setFrameShape(QtWidgets.QFrame.HLine)
  167. separator_line.setFrameShadow(QtWidgets.QFrame.Sunken)
  168. grid0.addWidget(separator_line, 24, 0, 1, 2)
  169. # Worker Numbers
  170. self.worker_number_label = QtWidgets.QLabel('%s:' % _('Workers number'))
  171. self.worker_number_label.setToolTip(
  172. _("The number of Qthreads made available to the App.\n"
  173. "A bigger number may finish the jobs more quickly but\n"
  174. "depending on your computer speed, may make the App\n"
  175. "unresponsive. Can have a value between 2 and 16.\n"
  176. "Default value is 2.\n"
  177. "After change, it will be applied at next App start.")
  178. )
  179. self.worker_number_sb = FCSpinner()
  180. self.worker_number_sb.set_range(2, 16)
  181. grid0.addWidget(self.worker_number_label, 25, 0)
  182. grid0.addWidget(self.worker_number_sb, 25, 1)
  183. # Geometric tolerance
  184. tol_label = QtWidgets.QLabel('%s:' % _("Geo Tolerance"))
  185. tol_label.setToolTip(_(
  186. "This value can counter the effect of the Circle Steps\n"
  187. "parameter. Default value is 0.005.\n"
  188. "A lower value will increase the detail both in image\n"
  189. "and in Gcode for the circles, with a higher cost in\n"
  190. "performance. Higher value will provide more\n"
  191. "performance at the expense of level of detail."
  192. ))
  193. self.tol_entry = FCDoubleSpinner()
  194. self.tol_entry.setSingleStep(0.001)
  195. self.tol_entry.set_precision(6)
  196. grid0.addWidget(tol_label, 26, 0)
  197. grid0.addWidget(self.tol_entry, 26, 1)
  198. separator_line = QtWidgets.QFrame()
  199. separator_line.setFrameShape(QtWidgets.QFrame.HLine)
  200. separator_line.setFrameShadow(QtWidgets.QFrame.Sunken)
  201. grid0.addWidget(separator_line, 27, 0, 1, 2)
  202. # Save Settings
  203. self.save_label = QtWidgets.QLabel('<b>%s</b>' % _("Save Settings"))
  204. grid0.addWidget(self.save_label, 28, 0, 1, 2)
  205. # Save compressed project CB
  206. self.save_type_cb = FCCheckBox(_('Save Compressed Project'))
  207. self.save_type_cb.setToolTip(
  208. _("Whether to save a compressed or uncompressed project.\n"
  209. "When checked it will save a compressed FlatCAM project.")
  210. )
  211. grid0.addWidget(self.save_type_cb, 29, 0, 1, 2)
  212. # Project LZMA Comppression Level
  213. self.compress_spinner = FCSpinner()
  214. self.compress_spinner.set_range(0, 9)
  215. self.compress_label = QtWidgets.QLabel('%s:' % _('Compression'))
  216. self.compress_label.setToolTip(
  217. _("The level of compression used when saving\n"
  218. "a FlatCAM project. Higher value means better compression\n"
  219. "but require more RAM usage and more processing time.")
  220. )
  221. grid0.addWidget(self.compress_label, 30, 0)
  222. grid0.addWidget(self.compress_spinner, 30, 1)
  223. self.proj_ois = OptionalInputSection(self.save_type_cb, [self.compress_label, self.compress_spinner], True)
  224. # Auto save CB
  225. self.autosave_cb = FCCheckBox(_('Enable Auto Save'))
  226. self.autosave_cb.setToolTip(
  227. _("Check to enable the autosave feature.\n"
  228. "When enabled, the application will try to save a project\n"
  229. "at the set interval.")
  230. )
  231. grid0.addWidget(self.autosave_cb, 31, 0, 1, 2)
  232. # Auto Save Timeout Interval
  233. self.autosave_entry = FCSpinner()
  234. self.autosave_entry.set_range(0, 9999999)
  235. self.autosave_label = QtWidgets.QLabel('%s:' % _('Interval'))
  236. self.autosave_label.setToolTip(
  237. _("Time interval for autosaving. In milliseconds.\n"
  238. "The application will try to save periodically but only\n"
  239. "if the project was saved manually at least once.\n"
  240. "While active, some operations may block this feature.")
  241. )
  242. grid0.addWidget(self.autosave_label, 32, 0)
  243. grid0.addWidget(self.autosave_entry, 32, 1)
  244. # self.as_ois = OptionalInputSection(self.autosave_cb, [self.autosave_label, self.autosave_entry], True)
  245. separator_line = QtWidgets.QFrame()
  246. separator_line.setFrameShape(QtWidgets.QFrame.HLine)
  247. separator_line.setFrameShadow(QtWidgets.QFrame.Sunken)
  248. grid0.addWidget(separator_line, 33, 0, 1, 2)
  249. self.pdf_param_label = QtWidgets.QLabel('<B>%s:</b>' % _("Text to PDF parameters"))
  250. self.pdf_param_label.setToolTip(
  251. _("Used when saving text in Code Editor or in FlatCAM Document objects.")
  252. )
  253. grid0.addWidget(self.pdf_param_label, 34, 0, 1, 2)
  254. # Top Margin value
  255. self.tmargin_entry = FCDoubleSpinner()
  256. self.tmargin_entry.set_precision(self.decimals)
  257. self.tmargin_entry.set_range(0.0000, 9999.9999)
  258. self.tmargin_label = QtWidgets.QLabel('%s:' % _("Top Margin"))
  259. self.tmargin_label.setToolTip(
  260. _("Distance between text body and the top of the PDF file.")
  261. )
  262. grid0.addWidget(self.tmargin_label, 35, 0)
  263. grid0.addWidget(self.tmargin_entry, 35, 1)
  264. # Bottom Margin value
  265. self.bmargin_entry = FCDoubleSpinner()
  266. self.bmargin_entry.set_precision(self.decimals)
  267. self.bmargin_entry.set_range(0.0000, 9999.9999)
  268. self.bmargin_label = QtWidgets.QLabel('%s:' % _("Bottom Margin"))
  269. self.bmargin_label.setToolTip(
  270. _("Distance between text body and the bottom of the PDF file.")
  271. )
  272. grid0.addWidget(self.bmargin_label, 36, 0)
  273. grid0.addWidget(self.bmargin_entry, 36, 1)
  274. # Left Margin value
  275. self.lmargin_entry = FCDoubleSpinner()
  276. self.lmargin_entry.set_precision(self.decimals)
  277. self.lmargin_entry.set_range(0.0000, 9999.9999)
  278. self.lmargin_label = QtWidgets.QLabel('%s:' % _("Left Margin"))
  279. self.lmargin_label.setToolTip(
  280. _("Distance between text body and the left of the PDF file.")
  281. )
  282. grid0.addWidget(self.lmargin_label, 37, 0)
  283. grid0.addWidget(self.lmargin_entry, 37, 1)
  284. # Right Margin value
  285. self.rmargin_entry = FCDoubleSpinner()
  286. self.rmargin_entry.set_precision(self.decimals)
  287. self.rmargin_entry.set_range(0.0000, 9999.9999)
  288. self.rmargin_label = QtWidgets.QLabel('%s:' % _("Right Margin"))
  289. self.rmargin_label.setToolTip(
  290. _("Distance between text body and the right of the PDF file.")
  291. )
  292. grid0.addWidget(self.rmargin_label, 38, 0)
  293. grid0.addWidget(self.rmargin_entry, 38, 1)
  294. self.layout.addStretch()
  295. if sys.platform != 'win32':
  296. self.portability_cb.hide()
  297. # splash screen button signal
  298. self.splash_cb.stateChanged.connect(self.on_splash_changed)
  299. # Monitor the checkbox from the Application Defaults Tab and show the TCL shell or not depending on it's value
  300. self.shell_startup_cb.clicked.connect(self.on_toggle_shell_from_settings)
  301. self.language_apply_btn.clicked.connect(lambda: fcTranslate.on_language_apply_click(app=self.app, restart=True))
  302. def on_toggle_shell_from_settings(self, state):
  303. """
  304. Toggle shell ui: if is visible close it, if it is closed then open it
  305. :return: None
  306. """
  307. if state is True:
  308. if not self.app.ui.shell_dock.isVisible():
  309. self.app.ui.shell_dock.show()
  310. else:
  311. if self.app.ui.shell_dock.isVisible():
  312. self.app.ui.shell_dock.hide()
  313. @staticmethod
  314. def on_splash_changed(state):
  315. qsettings = QSettings("Open Source", "FlatCAM")
  316. qsettings.setValue('splash_screen', 1) if state else qsettings.setValue('splash_screen', 0)
  317. # This will write the setting to the platform specific storage.
  318. del qsettings