Skip to content

Commit

Permalink
FEM: Examples, file name changed to example name in examplesgui
Browse files Browse the repository at this point in the history
  • Loading branch information
Sudhanshu-Dubey14 committed May 28, 2020
1 parent 04140ad commit 40d62b6
Showing 1 changed file with 12 additions and 9 deletions.
21 changes: 12 additions & 9 deletions src/Mod/Fem/femexamples/examplesgui.py
Expand Up @@ -65,6 +65,7 @@ def init_ui(self):
files = [f[:-3] for f in files if f.endswith(".py")]
files.sort()
files_info = {}
self.files_name = {}
constraints = set()
meshes = set()
solvers = set()
Expand All @@ -76,6 +77,7 @@ def init_ui(self):
if hasattr(module, "get_information"):
info = getattr(module, "get_information")()
files_info[f] = info
self.files_name[info["name"]] = f
meshes.add(info["meshelement"])
equations.add(info["equation"])
materials.add(info["material"])
Expand All @@ -87,8 +89,8 @@ def init_ui(self):
constraints.add(constraint)

all_examples = QtGui.QTreeWidgetItem(self.view, ["All"])
for f in files:
QtGui.QTreeWidgetItem(all_examples, [f])
for example, info in files_info.items():
QtGui.QTreeWidgetItem(all_examples, [info["name"]])

self.view.addTopLevelItem(all_examples)
all_constraints = QtGui.QTreeWidgetItem(self.view, ["Constraints"])
Expand All @@ -97,7 +99,7 @@ def init_ui(self):
for example, info in files_info.items():
file_constraints = info["constraints"]
if constraint in file_constraints:
QtGui.QTreeWidgetItem(constraint_item, [example])
QtGui.QTreeWidgetItem(constraint_item, [info["name"]])

self.view.addTopLevelItem(all_constraints)
all_solvers = QtGui.QTreeWidgetItem(self.view, ["Solvers"])
Expand All @@ -106,7 +108,7 @@ def init_ui(self):
for example, info in files_info.items():
file_solvers = info["solvers"]
if solver in file_solvers:
QtGui.QTreeWidgetItem(solver_item, [example])
QtGui.QTreeWidgetItem(solver_item, [info["name"]])

self.view.addTopLevelItem(all_solvers)

Expand All @@ -115,23 +117,23 @@ def init_ui(self):
mesh_item = QtGui.QTreeWidgetItem(all_meshes, [mesh])
for example, info in files_info.items():
if info["meshelement"] == mesh:
QtGui.QTreeWidgetItem(mesh_item, [example])
QtGui.QTreeWidgetItem(mesh_item, [info["name"]])

self.view.addTopLevelItem(all_meshes)
all_equations = QtGui.QTreeWidgetItem(self.view, ["Equations"])
for equation in equations:
equation_item = QtGui.QTreeWidgetItem(all_equations, [equation])
for example, info in files_info.items():
if info["equation"] == equation:
QtGui.QTreeWidgetItem(equation_item, [example])
QtGui.QTreeWidgetItem(equation_item, [info["name"]])

self.view.addTopLevelItem(all_equations)
all_materials = QtGui.QTreeWidgetItem(self.view, ["materials"])
all_materials = QtGui.QTreeWidgetItem(self.view, ["Materials"])
for material in materials:
material_item = QtGui.QTreeWidgetItem(all_materials, [material])
for example, info in files_info.items():
if info["material"] == material:
QtGui.QTreeWidgetItem(material_item, [example])
QtGui.QTreeWidgetItem(material_item, [info["name"]])

self.view.addTopLevelItem(all_materials)

Expand All @@ -158,7 +160,8 @@ def init_ui(self):
def accept(self):
print("\nExample will be run.")
item = self.view.selectedItems()[0]
example = item.text(0)
name = item.text(0)
example = self.files_name[name]
# if done this way the Python commands are printed in Python console
FreeCADGui.doCommand("from femexamples." + str(example) + " import setup")
FreeCADGui.doCommand("setup()")
Expand Down

0 comments on commit 40d62b6

Please sign in to comment.