GeneralAppSettingsGroupUI.py 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302
  1. from PyQt5 import QtCore
  2. from PyQt5.QtCore import QSettings
  3. from AppGUI.GUIElements import OptionalInputSection
  4. from AppGUI.preferences import settings
  5. from AppGUI.preferences.OptionUI import *
  6. from AppGUI.preferences.OptionsGroupUI import OptionsGroupUI2
  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. class GeneralAppSettingsGroupUI(OptionsGroupUI2):
  14. def __init__(self, decimals=4, **kwargs):
  15. self.decimals = decimals
  16. self.pagesize = {}
  17. self.pagesize.update(
  18. {
  19. 'A0': (841, 1189),
  20. 'A1': (594, 841),
  21. 'A2': (420, 594),
  22. 'A3': (297, 420),
  23. 'A4': (210, 297),
  24. 'A5': (148, 210),
  25. 'A6': (105, 148),
  26. 'A7': (74, 105),
  27. 'A8': (52, 74),
  28. 'A9': (37, 52),
  29. 'A10': (26, 37),
  30. 'B0': (1000, 1414),
  31. 'B1': (707, 1000),
  32. 'B2': (500, 707),
  33. 'B3': (353, 500),
  34. 'B4': (250, 353),
  35. 'B5': (176, 250),
  36. 'B6': (125, 176),
  37. 'B7': (88, 125),
  38. 'B8': (62, 88),
  39. 'B9': (44, 62),
  40. 'B10': (31, 44),
  41. 'C0': (917, 1297),
  42. 'C1': (648, 917),
  43. 'C2': (458, 648),
  44. 'C3': (324, 458),
  45. 'C4': (229, 324),
  46. 'C5': (162, 229),
  47. 'C6': (114, 162),
  48. 'C7': (81, 114),
  49. 'C8': (57, 81),
  50. 'C9': (40, 57),
  51. 'C10': (28, 40),
  52. # American paper sizes
  53. 'LETTER': (8.5, 11),
  54. 'LEGAL': (8.5, 14),
  55. 'ELEVENSEVENTEEN': (11, 17),
  56. # From https://en.wikipedia.org/wiki/Paper_size
  57. 'JUNIOR_LEGAL': (5, 8),
  58. 'HALF_LETTER': (5.5, 8),
  59. 'GOV_LETTER': (8, 10.5),
  60. 'GOV_LEGAL': (8.5, 13),
  61. 'LEDGER': (17, 11),
  62. }
  63. )
  64. super().__init__(**kwargs)
  65. self.setTitle(str(_("App Settings")))
  66. qsettings = QSettings("Open Source", "FlatCAM")
  67. self.notebook_font_size_field = self.option_dict()["notebook_font_size"].get_field()
  68. if qsettings.contains("notebook_font_size"):
  69. self.notebook_font_size_field.set_value(qsettings.value('notebook_font_size', type=int))
  70. else:
  71. self.notebook_font_size_field.set_value(12)
  72. self.axis_font_size_field = self.option_dict()["axis_font_size"].get_field()
  73. if qsettings.contains("axis_font_size"):
  74. self.axis_font_size_field.set_value(qsettings.value('axis_font_size', type=int))
  75. else:
  76. self.axis_font_size_field.set_value(8)
  77. self.textbox_font_size_field = self.option_dict()["textbox_font_size"].get_field()
  78. if qsettings.contains("textbox_font_size"):
  79. self.textbox_font_size_field.set_value(settings.value('textbox_font_size', type=int))
  80. else:
  81. self.textbox_font_size_field.set_value(10)
  82. self.workspace_enabled_field = self.option_dict()["global_workspace"].get_field()
  83. self.workspace_type_field = self.option_dict()["global_workspaceT"].get_field()
  84. self.workspace_type_label = self.option_dict()["global_workspaceT"].label_widget
  85. self.workspace_orientation_field = self.option_dict()["global_workspace_orientation"].get_field()
  86. self.workspace_orientation_label = self.option_dict()["global_workspace_orientation"].label_widget
  87. self.wks = OptionalInputSection(self.workspace_enabled_field, [self.workspace_type_label, self.workspace_type_field, self.workspace_orientation_label, self.workspace_orientation_field])
  88. self.mouse_cursor_color_enabled_field = self.option_dict()["global_cursor_color_enabled"].get_field()
  89. self.mouse_cursor_color_field = self.option_dict()["global_cursor_color"].get_field()
  90. self.mouse_cursor_color_label = self.option_dict()["global_cursor_color"].label_widget
  91. self.mois = OptionalInputSection(self.mouse_cursor_color_enabled_field, [self.mouse_cursor_color_label, self.mouse_cursor_color_field])
  92. self.mouse_cursor_color_enabled_field.stateChanged.connect(self.on_mouse_cursor_color_enable)
  93. self.mouse_cursor_color_field.entry.editingFinished.connect(self.on_mouse_cursor_entry)
  94. def build_options(self) -> [OptionUI]:
  95. return [
  96. HeadingOptionUI(label_text="Grid Settings", label_tooltip=None),
  97. DoubleSpinnerOptionUI(
  98. option="global_gridx",
  99. label_text="X value",
  100. label_tooltip="This is the Grid snap value on X axis.",
  101. step=0.1,
  102. decimals=self.decimals
  103. ),
  104. DoubleSpinnerOptionUI(
  105. option="global_gridy",
  106. label_text='Y value',
  107. label_tooltip="This is the Grid snap value on Y axis.",
  108. step=0.1,
  109. decimals=self.decimals
  110. ),
  111. DoubleSpinnerOptionUI(
  112. option="global_snap_max",
  113. label_text="Snap Max",
  114. label_tooltip="Max. magnet distance",
  115. step=0.1,
  116. decimals=self.decimals
  117. ),
  118. SeparatorOptionUI(),
  119. HeadingOptionUI(label_text="Workspace Settings", label_tooltip=None),
  120. CheckboxOptionUI(
  121. option="global_workspace",
  122. label_text="Active",
  123. label_tooltip="Draw a delimiting rectangle on canvas.\n"
  124. "The purpose is to illustrate the limits for our work."
  125. ),
  126. ComboboxOptionUI(
  127. option="global_workspaceT",
  128. label_text="Size",
  129. label_tooltip="Select the type of rectangle to be used on canvas,\nas valid workspace.",
  130. choices=list(self.pagesize.keys())
  131. ),
  132. RadioSetOptionUI(
  133. option="global_workspace_orientation",
  134. label_text="Orientation",
  135. label_tooltip="Can be:\n- Portrait\n- Landscape",
  136. choices=[
  137. {'label': _('Portrait'), 'value': 'p'},
  138. {'label': _('Landscape'), 'value': 'l'},
  139. ]
  140. ),
  141. # FIXME enabling OptionalInputSection ??
  142. SeparatorOptionUI(),
  143. HeadingOptionUI(label_text="Font Size", label_tooltip=None),
  144. SpinnerOptionUI(
  145. option="notebook_font_size",
  146. label_text="Notebook",
  147. label_tooltip="This sets the font size for the elements found in the Notebook.\n"
  148. "The notebook is the collapsible area in the left side of the GUI,\n"
  149. "and include the Project, Selected and Tool tabs.",
  150. min_value=8, max_value=40, step=1
  151. ),
  152. SpinnerOptionUI(
  153. option="axis_font_size",
  154. label_text="Axis",
  155. label_tooltip="This sets the font size for canvas axis.",
  156. min_value=8, max_value=40, step=1
  157. ),
  158. SpinnerOptionUI(
  159. option="textbox_font_size",
  160. label_text="Textbox",
  161. label_tooltip="This sets the font size for the Textbox GUI\n"
  162. "elements that are used in the application.",
  163. min_value=8, max_value=40, step=1
  164. ),
  165. SeparatorOptionUI(),
  166. HeadingOptionUI(label_text="Mouse Settings", label_tooltip=None),
  167. RadioSetOptionUI(
  168. option="global_cursor_type",
  169. label_text="Cursor Shape",
  170. label_tooltip="Choose a mouse cursor shape.\n"
  171. "- Small -> with a customizable size.\n"
  172. "- Big -> Infinite lines",
  173. choices=[
  174. {"label": _("Small"), "value": "small"},
  175. {"label": _("Big"), "value": "big"}
  176. ]
  177. ),
  178. SpinnerOptionUI(
  179. option="global_cursor_size",
  180. label_text="Cursor Size",
  181. label_tooltip="Set the size of the mouse cursor, in pixels.",
  182. min_value=10, max_value=70, step=1
  183. ),
  184. SpinnerOptionUI(
  185. option="global_cursor_width",
  186. label_text="Cursor Width",
  187. label_tooltip="Set the line width of the mouse cursor, in pixels.",
  188. min_value=1, max_value=10, step=1
  189. ),
  190. CheckboxOptionUI(
  191. option="global_cursor_color_enabled",
  192. label_text="Cursor Color",
  193. label_tooltip="Check this box to color mouse cursor."
  194. ),
  195. ColorOptionUI(
  196. option="global_cursor_color",
  197. label_text="Cursor Color",
  198. label_tooltip="Set the color of the mouse cursor."
  199. ),
  200. # FIXME enabling of cursor color
  201. RadioSetOptionUI(
  202. option="global_pan_button",
  203. label_text="Pan Button",
  204. label_tooltip="Select the mouse button to use for panning:\n"
  205. "- MMB --> Middle Mouse Button\n"
  206. "- RMB --> Right Mouse Button",
  207. choices=[{'label': _('MMB'), 'value': '3'},
  208. {'label': _('RMB'), 'value': '2'}]
  209. ),
  210. RadioSetOptionUI(
  211. option="global_mselect_key",
  212. label_text="Multiple Selection",
  213. label_tooltip="Select the key used for multiple selection.",
  214. choices=[{'label': _('CTRL'), 'value': 'Control'},
  215. {'label': _('SHIFT'), 'value': 'Shift'}]
  216. ),
  217. SeparatorOptionUI(),
  218. CheckboxOptionUI(
  219. option="global_delete_confirmation",
  220. label_text="Delete object confirmation",
  221. label_tooltip="When checked the application will ask for user confirmation\n"
  222. "whenever the Delete object(s) event is triggered, either by\n"
  223. "menu shortcut or key shortcut."
  224. ),
  225. CheckboxOptionUI(
  226. option="global_open_style",
  227. label_text='"Open" behavior',
  228. label_tooltip="When checked the path for the last saved file is used when saving files,\n"
  229. "and the path for the last opened file is used when opening files.\n\n"
  230. "When unchecked the path for opening files is the one used last: either the\n"
  231. "path for saving files or the path for opening files."
  232. ),
  233. CheckboxOptionUI(
  234. option="global_toggle_tooltips",
  235. label_text="Enable ToolTips",
  236. label_tooltip="Check this box if you want to have toolTips displayed\n"
  237. "when hovering with mouse over items throughout the App."
  238. ),
  239. CheckboxOptionUI(
  240. option="global_machinist_setting",
  241. label_text="Allow Machinist Unsafe Settings",
  242. label_tooltip="If checked, some of the application settings will be allowed\n"
  243. "to have values that are usually unsafe to use.\n"
  244. "Like Z travel negative values or Z Cut positive values.\n"
  245. "It will applied at the next application start.\n"
  246. "<<WARNING>>: Don't change this unless you know what you are doing !!!"
  247. ),
  248. SpinnerOptionUI(
  249. option="global_bookmarks_limit",
  250. label_text="Bookmarks limit",
  251. label_tooltip="The maximum number of bookmarks that may be installed in the menu.\n"
  252. "The number of bookmarks in the bookmark manager may be greater\n"
  253. "but the menu will hold only so much.",
  254. min_value=0, max_value=9999, step=1
  255. ),
  256. ComboboxOptionUI(
  257. option="global_activity_icon",
  258. label_text="Activity Icon",
  259. label_tooltip="Select the GIF that show activity when FlatCAM is active.",
  260. choices=['Ball black', 'Ball green', 'Arrow green', 'Eclipse green']
  261. )
  262. ]
  263. def on_mouse_cursor_color_enable(self, val):
  264. if val:
  265. self.app.cursor_color_3D = self.app.defaults["global_cursor_color"]
  266. else:
  267. theme_settings = QtCore.QSettings("Open Source", "FlatCAM")
  268. if theme_settings.contains("theme"):
  269. theme = theme_settings.value('theme', type=str)
  270. else:
  271. theme = 'white'
  272. if theme == 'white':
  273. self.app.cursor_color_3D = 'black'
  274. else:
  275. self.app.cursor_color_3D = 'gray'
  276. def on_mouse_cursor_entry(self):
  277. self.app.defaults['global_cursor_color'] = self.mouse_cursor_color_field.get_value()
  278. self.app.cursor_color_3D = self.app.defaults["global_cursor_color"]