From 7a34c76286b7c1aba9ee4638279bdfcf11ce1130 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20H=C3=B6nig?= <jan.hoenig@fau.de> Date: Fri, 22 Dec 2017 16:27:55 +0100 Subject: [PATCH] Added advst presentation Added DebugGui --- display_utils.py | 51 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 51 insertions(+) diff --git a/display_utils.py b/display_utils.py index 785fcd5d7..11e5b426b 100644 --- a/display_utils.py +++ b/display_utils.py @@ -1,3 +1,6 @@ +import sys +from PyQt5.QtWidgets import QWidget, QApplication, QTreeWidget, QTreeWidgetItem, QHBoxLayout +from pystencils.astnodes import Block, LoopOverCoordinate, KernelFunction def toDot(expr, graphStyle={}): @@ -27,6 +30,16 @@ def highlightCpp(code): 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 --------------------------------------------- @@ -155,3 +168,41 @@ def makeSurfacePlotAnimation(runFunction, frames=90, interval=30): return plot, 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) + -- GitLab