-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathexport_report_config.py
53 lines (38 loc) · 1.49 KB
/
export_report_config.py
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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
import FreeCAD
import FreeCADGui
from report_utils.resource_utils import iconPath
from report_utils.selection_utils import findSelectedReportConfig
from report_utils import qtutils
class ExportReportConfigCommand:
toolbarName = 'Reporting_Tools'
commandName = 'Export_Report'
def GetResources(self):
return {'MenuText': "Export Report",
'ToolTip': "Exports the configuration stored inside the Report object to a JSON file",
'Pixmap': iconPath('ExportConfig.svg')
}
def Activated(self):
reportConfig = findSelectedReportConfig()
if reportConfig is None:
qtutils.showInfo(
"No Report selected", "Select exactly one Report object to export its content")
return
selectedFile = qtutils.userSelectedFile(
'Export Location', qtutils.JSON_FILES, False)
if selectedFile is None:
return
fileObject = open(selectedFile, 'w')
reportConfig.exportJson(fileObject)
def IsActive(self):
"""If there is no active document we can't do anything."""
return not FreeCAD.ActiveDocument is None
if __name__ == "__main__":
command = ExportReportConfigCommand()
if command.IsActive():
command.Activated()
else:
qtutils.showInfo("No open Document", "There is no open document")
else:
import reporting_toolbars
reporting_toolbars.toolbarManager.registerCommand(
ExportReportConfigCommand())