-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathStylesheetRefresh.FCMacro
38 lines (34 loc) · 1.58 KB
/
StylesheetRefresh.FCMacro
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
__Name__ = 'Stylesheet Refresh'
__Comment__ = 'Refreshes the stylesheet - very useful when creating a theme and wanting to apply newly saved changes'
__Author__ = 'Axeia'
__Version__ = '3'
__Date__ = '2023-06-16'
__License__ = 'CC0-1.0'
__Web__ = ''
__Wiki__ = ''
__Icon__ = 'https://svgur.com/i/vLj.svg'
__Help__ = ''
__Status__ = ''
__Requires__ = 'FreeCAD >= v0.20'
__Communication__ = 'https://forum.freecad.org/memberlist.php?mode=viewprofile&u=54199'
__Files__ = ''
# svg source can be found over here: https://www.svgviewer.dev/s/uVkJa2ZE
import FreeCAD
import os
from PySide2 import QtGui
stylesheetFileName = FreeCAD.ParamGet(
"User parameter:BaseApp/Preferences/MainWindow"
).GetString('StyleSheet')
stylesheetsRelativePath = ['Gui', 'Stylesheets', stylesheetFileName]
mainWindowInstance = QtGui.QGuiApplication.instance()
stylesheetUserFilePath = os.path.join(FreeCAD.getUserAppDataDir(), *stylesheetsRelativePath)
stylesheetMainFilePath = os.path.join(FreeCAD.getResourceDir(), *stylesheetsRelativePath)
currentStyleSheetPath = ''
if os.path.exists(stylesheetUserFilePath):
currentStyleSheetPath = stylesheetUserFilePath
else:
currentStyleSheetPath = stylesheetMainFilePath
with open(currentStyleSheetPath, 'r', encoding='utf-8') as f:
stylesheetContent = f.read()
mainWindowInstance.setStyleSheet(stylesheetContent)
FreeCAD.Console.PrintMessage(f"Reloaded {stylesheetFileName} from: {currentStyleSheetPath}\n")