From ce63537a5bd1b7a4b47f613694b0902a5d1a0b76 Mon Sep 17 00:00:00 2001 From: Martin Bauer <martin.bauer@fau.de> Date: Thu, 11 Jan 2018 09:47:46 +0100 Subject: [PATCH] Moved Qt Stuff into separate file --- display_utils.py | 49 ------------------------------------------------ qtgui.py | 48 +++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 48 insertions(+), 49 deletions(-) create mode 100644 qtgui.py diff --git a/display_utils.py b/display_utils.py index f8cfc7de2..ef49d8107 100644 --- a/display_utils.py +++ b/display_utils.py @@ -1,7 +1,3 @@ -import sys -from PyQt5.QtWidgets import QWidget, QApplication, QTreeWidget, QTreeWidgetItem, QHBoxLayout -from pystencils.astnodes import Block, LoopOverCoordinate, KernelFunction - def toDot(expr, graphStyle={}): """Show a sympy or pystencils AST as dot graph""" @@ -48,15 +44,6 @@ def showCode(ast): return CodeDisplay(ast) -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 --------------------------------------------- @@ -188,39 +175,3 @@ def makeSurfacePlotAnimation(runFunction, frames=90, interval=30): 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) - diff --git a/qtgui.py b/qtgui.py new file mode 100644 index 000000000..451c2b40d --- /dev/null +++ b/qtgui.py @@ -0,0 +1,48 @@ +import sys +from PyQt5.QtWidgets import QWidget, QApplication, QTreeWidget, QTreeWidgetItem, QHBoxLayout +from pystencils.astnodes import Block, LoopOverCoordinate, KernelFunction + + +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_() + + +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