Skip to content

Commit 9e3a1f9

Browse files
Separate installer and project
1 parent 5334c79 commit 9e3a1f9

15 files changed

+89
-55
lines changed

doc/source/Resources/PyAEDTInstallerFromDesktop.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ def run_pyinstaller_from_c_python(oDesktop):
6060
# enable in debu mode
6161
# f.write("import sys\n")
6262
# f.write('sys.path.insert(0, r"c:\\ansysdev\\git\\repos\\pyaedt")\n')
63-
f.write("from pyaedt.workflows.project.pyaedt_installer import add_pyaedt_to_aedt\n")
63+
f.write("from pyaedt.workflows.installer.pyaedt_installer import add_pyaedt_to_aedt\n")
6464
f.write(
6565
'add_pyaedt_to_aedt(aedt_version="{}", student_version={}, new_desktop_session=False)\n'.format(
6666
oDesktop.GetVersion()[:6], is_student_version(oDesktop)))

pyaedt/workflows/customize_automation_tab.py

+41-26
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,13 @@
4242

4343

4444
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",
4652
):
4753
"""Add an automation tab in AEDT.
4854
@@ -61,6 +67,8 @@ def add_automation_tab(
6167
overwrite : bool, optional
6268
Whether to overwrite the existing automation tab. The default is ``False``, in
6369
which case is adding new tabs to the existing ones.
70+
panel : str, optional
71+
Panel name. The default is ``"Panel_PyAEDT_Toolkits"``.
6472
6573
Returns
6674
-------
@@ -82,22 +90,22 @@ def add_automation_tab(
8290

8391
panels = root.findall("./panel")
8492
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:
8795
# 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]
8997
else:
90-
panel = ET.SubElement(root, "panel", label="Panel_PyAEDT_Toolkits")
98+
panel_element = ET.SubElement(root, "panel", label=panel)
9199
else:
92-
panel = ET.SubElement(root, "panel", label="Panel_PyAEDT_Toolkits")
100+
panel_element = ET.SubElement(root, "panel", label=panel)
93101

94-
buttons = panel.findall("./button")
102+
buttons = panel_element.findall("./button")
95103
if buttons:
96104
button_names = [button.attrib["label"] for button in buttons]
97105
if name in button_names:
98106
# Remove previously existing PyAEDT panel and update with newer one.
99107
b = [button for button in buttons if button.attrib["label"] == name][0]
100-
panel.remove(b)
108+
panel_element.remove(b)
101109

102110
if not icon_file:
103111
icon_file = os.path.join(os.path.dirname(pyaedt.workflows.__file__), "images", "large", "pyansys.png")
@@ -111,7 +119,7 @@ def add_automation_tab(
111119
shutil.copy(icon_file, dest_file)
112120

113121
ET.SubElement(
114-
panel,
122+
panel_element,
115123
"button",
116124
label=name,
117125
isLarge="1",
@@ -127,7 +135,7 @@ def add_automation_tab(
127135
return tab_config_file_path
128136

129137

130-
def remove_automation_tab(name, lib_dir):
138+
def remove_automation_tab(name, lib_dir, panel="Panel_PyAEDT_Toolkits"):
131139
"""Remove automation tab in AEDT.
132140
133141
Parameters
@@ -136,6 +144,8 @@ def remove_automation_tab(name, lib_dir):
136144
Toolkit name.
137145
lib_dir : str
138146
Path to the library directory.
147+
panel : str, optional
148+
Panel name. The default is ``"Panel_PyAEDT_Toolkits"``.
139149
140150
Returns
141151
-------
@@ -156,22 +166,22 @@ def remove_automation_tab(name, lib_dir):
156166

157167
panels = root.findall("./panel")
158168
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:
161171
# 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]
163173
else:
164-
panel = ET.SubElement(root, "panel", label="Panel_PyAEDT_Toolkits")
174+
panel_element = ET.SubElement(root, "panel", label=panel)
165175
else:
166-
panel = ET.SubElement(root, "panel", label="Panel_PyAEDT_Toolkits")
176+
panel_element = ET.SubElement(root, "panel", label=panel)
167177

168-
buttons = panel.findall("./button")
178+
buttons = panel_element.findall("./button")
169179
if buttons:
170180
button_names = [button.attrib["label"] for button in buttons]
171181
if name in button_names:
172182
# Remove previously existing PyAEDT panel and update with newer one.
173183
b = [button for button in buttons if button.attrib["label"] == name][0]
174-
panel.remove(b)
184+
panel_element.remove(b)
175185

176186
create_xml_tab(root, tab_config_file_path)
177187

@@ -193,7 +203,7 @@ def create_xml_tab(root, output_file):
193203
f.write(xml_str)
194204

195205

196-
def remove_xml_tab(toolkit_dir, name):
206+
def remove_xml_tab(toolkit_dir, name, panel="Panel_PyAEDT_Toolkits"):
197207
"""Remove a toolkit configuration file."""
198208
tab_config_file_path = os.path.join(toolkit_dir, "TabConfig.xml")
199209
if not os.path.isfile(tab_config_file_path):
@@ -207,22 +217,22 @@ def remove_xml_tab(toolkit_dir, name):
207217

208218
panels = root.findall("./panel")
209219
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:
212222
# 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]
214224
else:
215-
panel = ET.SubElement(root, "panel", label="Panel_PyAEDT_Toolkits")
225+
panel_element = ET.SubElement(root, "panel", label=panel)
216226
else:
217-
panel = ET.SubElement(root, "panel", label="Panel_PyAEDT_Toolkits")
227+
panel_element = ET.SubElement(root, "panel", label=panel)
218228

219-
buttons = panel.findall("./button")
229+
buttons = panel_element.findall("./button")
220230
if buttons:
221231
button_names = [button.attrib["label"] for button in buttons]
222232
if name in button_names:
223233
# Remove previously existing PyAEDT panel and update with newer one.
224234
b = [button for button in buttons if button.attrib["label"] == name][0]
225-
panel.remove(b)
235+
panel_element.remove(b)
226236

227237
create_xml_tab(root, tab_config_file_path)
228238

@@ -261,6 +271,7 @@ def add_script_to_menu(
261271
product="Project",
262272
copy_to_personal_lib=True,
263273
executable_interpreter=None,
274+
panel="Panel_PyAEDT_Toolkits",
264275
):
265276
"""Add a script to the ribbon menu.
266277
@@ -289,6 +300,8 @@ def add_script_to_menu(
289300
Whether to copy the script to Personal Lib or link the original script. Default is ``True``.
290301
executable_interpreter : str, optional
291302
Executable python path. The default is the one current interpreter.
303+
panel : str, optional
304+
Panel name. The default is ``"Panel_PyAEDT_Toolkits"``.
292305
293306
Returns
294307
-------
@@ -347,7 +360,9 @@ def add_script_to_menu(
347360
out_file.write(build_file_data)
348361

349362
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+
)
351366
desktop_object.logger.info("{} installed".format(name))
352367
return True
353368

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# Copyright (C) 2023 - 2024 ANSYS, Inc. and/or its affiliates.
2+
# SPDX-License-Identifier: MIT
3+
#
4+
#
5+
# Permission is hereby granted, free of charge, to any person obtaining a copy
6+
# of this software and associated documentation files (the "Software"), to deal
7+
# in the Software without restriction, including without limitation the rights
8+
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
# copies of the Software, and to permit persons to whom the Software is
10+
# furnished to do so, subject to the following conditions:
11+
#
12+
# The above copyright notice and this permission notice shall be included in all
13+
# copies or substantial portions of the Software.
14+
#
15+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
# SOFTWARE.

pyaedt/workflows/project/pyaedt_installer.py renamed to pyaedt/workflows/installer/pyaedt_installer.py

+1
Original file line numberDiff line numberDiff line change
@@ -120,4 +120,5 @@ def __add_pyaedt_tabs(desktop_object):
120120
product="Project",
121121
copy_to_personal_lib=True,
122122
executable_interpreter=None,
123+
panel="Panel_PyAEDT_Installer",
123124
)

pyaedt/workflows/project/toolkit_manager.py renamed to pyaedt/workflows/installer/toolkit_manager.py

+2-5
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
from pyaedt.workflows.customize_automation_tab import add_script_to_menu
3434
from pyaedt.workflows.customize_automation_tab import available_toolkits
3535
from pyaedt.workflows.customize_automation_tab import remove_script_from_menu
36-
import pyaedt.workflows.project
36+
import pyaedt.workflows.installer
3737

3838
env_vars = ["PYAEDT_SCRIPT_VERSION", "PYAEDT_SCRIPT_PORT", "PYAEDT_STUDENT_VERSION"]
3939
if all(var in os.environ for var in env_vars):
@@ -60,9 +60,6 @@
6060
def create_toolkit_page(frame, window_name, internal_toolkits):
6161
"""Create page to display toolkit on."""
6262
# Available toolkits
63-
if window_name == "Project":
64-
# Remove PyAEDT installer toolkits from the list
65-
internal_toolkits = internal_toolkits[:-4]
6663
toolkits = ["Custom"] + internal_toolkits
6764

6865
max_length = max(len(item) for item in toolkits) + 1
@@ -270,7 +267,7 @@ def button_is_clicked(
270267
root.title("AEDT Toolkit Manager")
271268

272269
# Load the logo for the main window
273-
icon_path = os.path.join(os.path.dirname(pyaedt.workflows.project.__file__), "images", "large", "logo.png")
270+
icon_path = os.path.join(os.path.dirname(pyaedt.workflows.installer.__file__), "images", "large", "logo.png")
274271
im = PIL.Image.open(icon_path)
275272
photo = PIL.ImageTk.PhotoImage(im)
276273

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
[Console]
2+
name = "PyAEDT Console"
3+
script = "console_setup.py"
4+
icon = "console.png"
5+
template = "PyAEDT_Console"
6+
7+
[Jupyter]
8+
name = "Jupyter Notebook"
9+
script = "jupyter_template.ipynb"
10+
icon = "jupyter.png"
11+
template = "Jupyter"
12+
13+
[Run_Script]
14+
name = "Run PyAEDT Script"
15+
script = ""
16+
icon = "run_script.png"
17+
template = "Run_PyAEDT_Script"
18+
19+
[ToolkitManager]
20+
name = "Toolkit Manager"
21+
script = "toolkit_manager.py"
22+
icon = "toolkit_manager.png"
23+
template = "Run_Toolkit_Manager"
Original file line numberDiff line numberDiff line change
@@ -1,23 +0,0 @@
1-
[Console]
2-
name = "PyAEDT Console"
3-
script = "console_setup.py"
4-
icon = "console.png"
5-
template = "PyAEDT_Console"
6-
7-
[Jupyter]
8-
name = "Jupyter Notebook"
9-
script = "jupyter_template.ipynb"
10-
icon = "jupyter.png"
11-
template = "Jupyter"
12-
13-
[Run_Script]
14-
name = "Run PyAEDT Script"
15-
script = ""
16-
icon = "run_script.png"
17-
template = "Run_PyAEDT_Script"
18-
19-
[ToolkitManager]
20-
name = "Toolkit Manager"
21-
script = "toolkit_manager.py"
22-
icon = "toolkit_manager.png"
23-
template = "Run_Toolkit_Manager"

0 commit comments

Comments
 (0)