42
42
43
43
44
44
def add_automation_tab (
45
- name , lib_dir , icon_file = None , product = "Project" , template = "Run PyAEDT Toolkit Script" , overwrite = False
45
+ name ,
46
+ lib_dir ,
47
+ icon_file = None ,
48
+ product = "Project" ,
49
+ template = "Run PyAEDT Toolkit Script" ,
50
+ overwrite = False ,
51
+ panel = "Panel_PyAEDT_Toolkits" ,
46
52
):
47
53
"""Add an automation tab in AEDT.
48
54
@@ -61,6 +67,8 @@ def add_automation_tab(
61
67
overwrite : bool, optional
62
68
Whether to overwrite the existing automation tab. The default is ``False``, in
63
69
which case is adding new tabs to the existing ones.
70
+ panel : str, optional
71
+ Panel name. The default is ``"Panel_PyAEDT_Toolkits"``.
64
72
65
73
Returns
66
74
-------
@@ -82,22 +90,22 @@ def add_automation_tab(
82
90
83
91
panels = root .findall ("./panel" )
84
92
if panels :
85
- panel_names = [panel .attrib ["label" ] for panel in panels ]
86
- if "Panel_PyAEDT_Toolkits" in panel_names :
93
+ panel_names = [panel_element .attrib ["label" ] for panel_element in panels ]
94
+ if panel in panel_names :
87
95
# Remove previously existing PyAEDT panel and update with newer one.
88
- panel = [panel for panel in panels if panel .attrib ["label" ] == "Panel_PyAEDT_Toolkits" ][0 ]
96
+ panel_element = [panel_element for panel_element in panels if panel_element .attrib ["label" ] == panel ][0 ]
89
97
else :
90
- panel = ET .SubElement (root , "panel" , label = "Panel_PyAEDT_Toolkits" )
98
+ panel_element = ET .SubElement (root , "panel" , label = panel )
91
99
else :
92
- panel = ET .SubElement (root , "panel" , label = "Panel_PyAEDT_Toolkits" )
100
+ panel_element = ET .SubElement (root , "panel" , label = panel )
93
101
94
- buttons = panel .findall ("./button" )
102
+ buttons = panel_element .findall ("./button" )
95
103
if buttons :
96
104
button_names = [button .attrib ["label" ] for button in buttons ]
97
105
if name in button_names :
98
106
# Remove previously existing PyAEDT panel and update with newer one.
99
107
b = [button for button in buttons if button .attrib ["label" ] == name ][0 ]
100
- panel .remove (b )
108
+ panel_element .remove (b )
101
109
102
110
if not icon_file :
103
111
icon_file = os .path .join (os .path .dirname (pyaedt .workflows .__file__ ), "images" , "large" , "pyansys.png" )
@@ -111,7 +119,7 @@ def add_automation_tab(
111
119
shutil .copy (icon_file , dest_file )
112
120
113
121
ET .SubElement (
114
- panel ,
122
+ panel_element ,
115
123
"button" ,
116
124
label = name ,
117
125
isLarge = "1" ,
@@ -127,7 +135,7 @@ def add_automation_tab(
127
135
return tab_config_file_path
128
136
129
137
130
- def remove_automation_tab (name , lib_dir ):
138
+ def remove_automation_tab (name , lib_dir , panel = "Panel_PyAEDT_Toolkits" ):
131
139
"""Remove automation tab in AEDT.
132
140
133
141
Parameters
@@ -136,6 +144,8 @@ def remove_automation_tab(name, lib_dir):
136
144
Toolkit name.
137
145
lib_dir : str
138
146
Path to the library directory.
147
+ panel : str, optional
148
+ Panel name. The default is ``"Panel_PyAEDT_Toolkits"``.
139
149
140
150
Returns
141
151
-------
@@ -156,22 +166,22 @@ def remove_automation_tab(name, lib_dir):
156
166
157
167
panels = root .findall ("./panel" )
158
168
if panels :
159
- panel_names = [panel .attrib ["label" ] for panel in panels ]
160
- if "Panel_PyAEDT_Toolkits" in panel_names :
169
+ panel_names = [panel_element .attrib ["label" ] for panel_element in panels ]
170
+ if panel in panel_names :
161
171
# Remove previously existing PyAEDT panel and update with newer one.
162
- panel = [panel for panel in panels if panel .attrib ["label" ] == "Panel_PyAEDT_Toolkits" ][0 ]
172
+ panel_element = [panel_element for panel_element in panels if panel .attrib ["label" ] == panel ][0 ]
163
173
else :
164
- panel = ET .SubElement (root , "panel" , label = "Panel_PyAEDT_Toolkits" )
174
+ panel_element = ET .SubElement (root , "panel" , label = panel )
165
175
else :
166
- panel = ET .SubElement (root , "panel" , label = "Panel_PyAEDT_Toolkits" )
176
+ panel_element = ET .SubElement (root , "panel" , label = panel )
167
177
168
- buttons = panel .findall ("./button" )
178
+ buttons = panel_element .findall ("./button" )
169
179
if buttons :
170
180
button_names = [button .attrib ["label" ] for button in buttons ]
171
181
if name in button_names :
172
182
# Remove previously existing PyAEDT panel and update with newer one.
173
183
b = [button for button in buttons if button .attrib ["label" ] == name ][0 ]
174
- panel .remove (b )
184
+ panel_element .remove (b )
175
185
176
186
create_xml_tab (root , tab_config_file_path )
177
187
@@ -193,7 +203,7 @@ def create_xml_tab(root, output_file):
193
203
f .write (xml_str )
194
204
195
205
196
- def remove_xml_tab (toolkit_dir , name ):
206
+ def remove_xml_tab (toolkit_dir , name , panel = "Panel_PyAEDT_Toolkits" ):
197
207
"""Remove a toolkit configuration file."""
198
208
tab_config_file_path = os .path .join (toolkit_dir , "TabConfig.xml" )
199
209
if not os .path .isfile (tab_config_file_path ):
@@ -207,22 +217,22 @@ def remove_xml_tab(toolkit_dir, name):
207
217
208
218
panels = root .findall ("./panel" )
209
219
if panels :
210
- panel_names = [panel .attrib ["label" ] for panel in panels ]
211
- if "Panel_PyAEDT_Toolkits" in panel_names :
220
+ panel_names = [panel_element .attrib ["label" ] for panel_element in panels ]
221
+ if panel in panel_names :
212
222
# Remove previously existing PyAEDT panel and update with newer one.
213
- panel = [panel for panel in panels if panel .attrib ["label" ] == "Panel_PyAEDT_Toolkits" ][0 ]
223
+ panel_element = [panel_element for panel_element in panels if panel_element .attrib ["label" ] == panel ][0 ]
214
224
else :
215
- panel = ET .SubElement (root , "panel" , label = "Panel_PyAEDT_Toolkits" )
225
+ panel_element = ET .SubElement (root , "panel" , label = panel )
216
226
else :
217
- panel = ET .SubElement (root , "panel" , label = "Panel_PyAEDT_Toolkits" )
227
+ panel_element = ET .SubElement (root , "panel" , label = panel )
218
228
219
- buttons = panel .findall ("./button" )
229
+ buttons = panel_element .findall ("./button" )
220
230
if buttons :
221
231
button_names = [button .attrib ["label" ] for button in buttons ]
222
232
if name in button_names :
223
233
# Remove previously existing PyAEDT panel and update with newer one.
224
234
b = [button for button in buttons if button .attrib ["label" ] == name ][0 ]
225
- panel .remove (b )
235
+ panel_element .remove (b )
226
236
227
237
create_xml_tab (root , tab_config_file_path )
228
238
@@ -261,6 +271,7 @@ def add_script_to_menu(
261
271
product = "Project" ,
262
272
copy_to_personal_lib = True ,
263
273
executable_interpreter = None ,
274
+ panel = "Panel_PyAEDT_Toolkits" ,
264
275
):
265
276
"""Add a script to the ribbon menu.
266
277
@@ -289,6 +300,8 @@ def add_script_to_menu(
289
300
Whether to copy the script to Personal Lib or link the original script. Default is ``True``.
290
301
executable_interpreter : str, optional
291
302
Executable python path. The default is the one current interpreter.
303
+ panel : str, optional
304
+ Panel name. The default is ``"Panel_PyAEDT_Toolkits"``.
292
305
293
306
Returns
294
307
-------
@@ -347,7 +360,9 @@ def add_script_to_menu(
347
360
out_file .write (build_file_data )
348
361
349
362
if aedt_version >= "2023.2" :
350
- add_automation_tab (name , toolkit_dir , icon_file = icon_file , product = product , template = file_name_dest )
363
+ add_automation_tab (
364
+ name , toolkit_dir , icon_file = icon_file , product = product , template = file_name_dest , panel = panel
365
+ )
351
366
desktop_object .logger .info ("{} installed" .format (name ))
352
367
return True
353
368
0 commit comments