GeneralAppPrefGroupUI.py 16 KB

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