Skip to content
Snippets Groups Projects
Commit 7a34c762 authored by Jan Hönig's avatar Jan Hönig
Browse files

Added advst presentation

Added DebugGui
parent 5514c786
No related merge requests found
import sys
from PyQt5.QtWidgets import QWidget, QApplication, QTreeWidget, QTreeWidgetItem, QHBoxLayout
from pystencils.astnodes import Block, LoopOverCoordinate, KernelFunction
def toDot(expr, graphStyle={}): def toDot(expr, graphStyle={}):
...@@ -27,6 +30,16 @@ def highlightCpp(code): ...@@ -27,6 +30,16 @@ def highlightCpp(code):
return HTML(highlight(code, CppLexer(), HtmlFormatter())) return HTML(highlight(code, CppLexer(), HtmlFormatter()))
def debugGUI(ast):
app = QApplication.instance()
if app is None:
app = QApplication(sys.argv)
else:
print('QApplication instance already exists: %s' % str(app))
ex = DebugTree()
ex.insert_ast(ast)
app.exec_()
# ----------------- Embedding of animations as videos in IPython notebooks --------------------------------------------- # ----------------- Embedding of animations as videos in IPython notebooks ---------------------------------------------
...@@ -155,3 +168,41 @@ def makeSurfacePlotAnimation(runFunction, frames=90, interval=30): ...@@ -155,3 +168,41 @@ def makeSurfacePlotAnimation(runFunction, frames=90, interval=30):
return plot, return plot,
return animation.FuncAnimation(fig, updatefig, interval=interval, frames=frames, blit=False) return animation.FuncAnimation(fig, updatefig, interval=interval, frames=frames, blit=False)
# -------------------- DEBUG GUI ------------------------
class DebugTree(QWidget):
def __init__(self):
super().__init__()
self.initUI()
def initUI(self):
self.tree = QTreeWidget(self)
self.tree.setColumnCount(1)
self.tree.setHeaderLabel('repr')
hbox = QHBoxLayout()
hbox.stretch(1)
hbox.addWidget(self.tree)
self.setWindowTitle('Debug')
self.setLayout(hbox)
self.show()
def insert_ast(self, node, parent=None):
if parent is None:
parent = self.tree
if isinstance(node, Block): # Blocks are represented with the tree structure
item = parent
else:
item = QTreeWidgetItem(parent)
item.setText(0, repr(node))
if node.func in [LoopOverCoordinate, KernelFunction]:
self.tree.expandItem(item)
for child in node.args:
self.insert_ast(child, item)
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment