Skip to content

Commit

Permalink
FEM: Examples, QTreeView replaced with QTreeWidget
Browse files Browse the repository at this point in the history
Implemented item selection so now selected example is executed
  • Loading branch information
Sudhanshu-Dubey14 committed May 10, 2020
1 parent 2ab23a5 commit 7ec780a
Showing 1 changed file with 15 additions and 18 deletions.
33 changes: 15 additions & 18 deletions src/Mod/Fem/femexamples/examplesgui.py
Expand Up @@ -46,11 +46,7 @@ def init_ui(self):
self.macrotitle_label = QtGui.QLabel("<b>FEM Examples</b>", self)

# init widgets
self.view = QtGui.QTreeView()
self.view.setSelectionBehavior(QtGui.QAbstractItemView.SelectRows)
self.model = QtGui.QStandardItemModel()
self.view.setModel(self.model)
self.view.setUniformRowHeights(True)
self.view = QtGui.QTreeWidget()

path = os.path.dirname(os.path.realpath(__file__))
meshes_path = str(path) + "/meshes"
Expand All @@ -63,23 +59,24 @@ def init_ui(self):
"__pycache__",
]

files = [f for f in files if f not in not_files]
files = [str(f) for f in files if f not in not_files]

all_examples = QtGui.QStandardItem("All")
all_examples = QtGui.QTreeWidgetItem(self.view, ["All"])
for f in files:
example = QtGui.QStandardItem(str(f))
all_examples.appendRow(example)
self.model.appendRow(all_examples)
if f.endswith(".py"):
QtGui.QTreeWidgetItem(all_examples, [f[:-3]])

self.view.addTopLevelItem(all_examples)

meshes_files = [f for f in os.listdir(str(meshes_path))]
meshes_files = [f for f in meshes_files if f not in not_files]
meshes_files = [str(f) for f in meshes_files if f not in not_files]

all_meshes = QtGui.QStandardItem("Meshes")
all_meshes = QtGui.QTreeWidgetItem(self.view, ["Meshes"])
for f in meshes_files:
mesh = QtGui.QStandardItem(str(f))
all_meshes.appendRow(mesh)
self.model.appendRow(all_meshes)
if f.endswith(".py"):
QtGui.QTreeWidgetItem(all_meshes, [f[:-3]])

self.view.addTopLevelItem(all_meshes)
self.view.setHeaderHidden(True)

# Ok buttons:
Expand All @@ -102,10 +99,10 @@ def init_ui(self):

def accept(self):
print("\nExample will be run.")
item = self.view.selectedItems()[0]
example = item.text(0)
# if done this way the Python commands are printed in Python console
FreeCADGui.doCommand(
"from femexamples.constraint_contact_solid_solid import setup"
)
FreeCADGui.doCommand("from femexamples." + str(example) + " import setup")
FreeCADGui.doCommand("setup()")

def reject(self):
Expand Down

0 comments on commit 7ec780a

Please sign in to comment.