本文整理汇总了Python中viewer.Viewer.get_terminal_tree方法的典型用法代码示例。如果您正苦于以下问题:Python Viewer.get_terminal_tree方法的具体用法?Python Viewer.get_terminal_tree怎么用?Python Viewer.get_terminal_tree使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类viewer.Viewer
的用法示例。
在下文中一共展示了Viewer.get_terminal_tree方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: ParseView
# 需要导入模块: from viewer import Viewer [as 别名]
# 或者: from viewer.Viewer import get_terminal_tree [as 别名]
class ParseView(QtGui.QMainWindow):
def __init__(self, window):
QtGui.QMainWindow.__init__(self)
self.ui = Ui_ParseTree()
self.ui.setupUi(self)
self.connect(self.ui.cb_fit_ast, SIGNAL("clicked()"), self.refresh)
self.connect(self.ui.cb_toggle_ast, SIGNAL("clicked()"), self.refresh)
self.connect(self.ui.cb_toggle_ws, SIGNAL("clicked()"), self.refresh)
self.connect(self.ui.bt_show_sel_ast, SIGNAL("clicked()"), self.showAstSelection)
self.connect(self.ui.rb_view_parsetree, SIGNAL("clicked()"), self.refresh)
self.connect(self.ui.rb_view_linetree, SIGNAL("clicked()"), self.refresh)
self.connect(self.ui.rb_view_ast, SIGNAL("clicked()"), self.refresh)
self.viewer = Viewer("pydot")
self.ui.graphicsView.setRenderHints(QPainter.Antialiasing | QPainter.SmoothPixmapTransform | QPainter.TextAntialiasing)
self.ui.graphicsView.wheelEvent = self.gvWheelEvent
self.zoom = 1.0
self.window = window
def refresh(self):
editor = self.window.getEditor()
whitespaces = self.ui.cb_toggle_ws.isChecked()
if self.ui.cb_toggle_ast.isChecked():
if self.ui.rb_view_parsetree.isChecked():
self.viewer.get_tree_image(editor.tm.main_lbox, [], whitespaces)
elif self.ui.rb_view_linetree.isChecked():
self.viewer.get_terminal_tree(editor.tm.main_lbox)
elif self.ui.rb_view_ast.isChecked():
self.viewer.get_tree_image(editor.tm.main_lbox, [], whitespaces, ast=True)
self.showImage(self.ui.graphicsView, self.viewer.image)
def showImage(self, graphicsview, imagefile):
scene = QGraphicsScene()
item = QGraphicsPixmapItem(QPixmap(imagefile))
scene.addItem(item);
graphicsview.setScene(scene)
graphicsview.resetMatrix()
if self.ui.cb_fit_ast.isChecked():
self.fitInView(graphicsview)
def gvWheelEvent(self, event):
if event.modifiers() == Qt.ControlModifier:
transform = self.ui.graphicsView.transform()
if event.delta() > 0:
self.zoom /= 0.9
else:
self.zoom *= 0.9
transform.reset()
transform.scale(self.zoom, self.zoom)
self.ui.graphicsView.setTransform(transform)
else:
QGraphicsView.wheelEvent(self.ui.graphicsView, event)
event.ignore()
def fitInView(self, graphicsview):
graphicsview.fitInView(graphicsview.sceneRect(), Qt.KeepAspectRatio)
def showAstSelection(self):
editor = self.window.getEditor()
whitespaces = self.ui.cb_toggle_ws.isChecked()
nodes, _, _ = editor.tm.get_nodes_from_selection()
if len(nodes) == 0:
return
start = nodes[0]
end = nodes[-1]
ast = editor.tm.get_mainparser().previous_version
parent = ast.find_common_parent(start, end)
for node in nodes:
p = node.get_parent()
if p and p is not parent:
nodes.append(p)
nodes.append(parent)
if parent:
self.viewer.get_tree_image(parent, [start, end], whitespaces, nodes)
self.showImage(self.ui.graphicsView, self.viewer.image)