-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCubeMenu.py
More file actions
117 lines (94 loc) · 3.56 KB
/
CubeMenu.py
File metadata and controls
117 lines (94 loc) · 3.56 KB
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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
# Cube menu for FreeCAD.
# Copyright (C) 2015, 2016 (as part of TabBar) triplus @ FreeCAD
# Copyright (C) 2017, 2018, 2019 (as part of CommandPanel) triplus @ FreeCAD
# Copyright (C) 2020 triplus @ FreeCAD
#
#
# This library is free software; you can redistribute it and/or
# modify it under the terms of the GNU Lesser General Public
# License as published by the Free Software Foundation; either
# version 2.1 of the License, or (at your option) any later version.
#
# This library is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public
# License along with this library; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
"""Cube menu for FreeCAD - API."""
import CubeMenuCommon as cpc
p = cpc.p
def addMenu(menu=None):
"""addMenu({menu})
Command panel API provides ability to preset commands for workbench.
Settings are deleted when FreeCAD exits normally. Following is a two
menus example for Start workbench.
import CommandPanel as cp
workbench = "StartWorkbench"
# workbench = "GlobalPanel" # Global panel
menuDemo = {
"workbench": workbench, # Mandatory
"uuid": "StartDemo", # Mandatory
"name": "Demo",
"commands": [
"Std_ViewFront", # Command name
"CPSeparator", # Separator
"Std_ViewTop",
"Std_ViewRight"]}
domainDemo = cp.addMenu(menuDemo) # Add menuDemo
menuDefault = {
"workbench": workbench,
"uuid": "StartDefault",
"name": "Default",
"default": True, # Set as default menu
"commands": [
"CPGlobalDefault", # Add global defaults
domainDemo]} # Add menuDemo
cp.addMenu(menuDefault)"""
# Workbench
if menu and "workbench" in menu:
wb = menu["workbench"]
if "." in wb or "," in wb:
wb = None
else:
wb = None
# UUID
if wb and "uuid" in menu:
uid = menu["uuid"]
if "." in uid or "," in uid:
uid = None
else:
uid = None
if wb and uid:
domain = ".".join(["CPMenu", "System", wb, uid])
group = cpc.findGroup(domain)
if not group:
group = cpc.newGroup(domain)
if group:
# UUID
group.SetString("uuid", uid)
# Name
if "name" in menu:
group.SetString("name", menu["name"])
# Commands
if "commands" in menu:
temp = []
for cmd in menu["commands"]:
if cmd.startswith("CPMenu") and "," not in cmd:
temp.append(cmd)
elif "." not in cmd and "," not in cmd:
temp.append(cmd)
else:
pass
group.SetString("commands", ",".join(temp))
# Default
if "default" in menu:
base = p.GetGroup("System").GetGroup(wb)
base.SetString("default", domain)
else:
domain = None
else:
domain = None
return domain