Skip to content

Commit

Permalink
a little doc update
Browse files Browse the repository at this point in the history
  • Loading branch information
chick committed Apr 16, 2014
1 parent 4d6dc8a commit d2927dc
Show file tree
Hide file tree
Showing 7 changed files with 31 additions and 22 deletions.
18 changes: 11 additions & 7 deletions README.rst
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
astviewer
=========
AstToolBox
==========

Python Abstract Syntax Tree Tool built on PySide
It can show a GUI tree representation of an AST. Any tree or node can be
used to produce a new tree by the application of ast.NodeTransformer
The AstToolBox allows a developer to start from a python source file and
see how a series of ast.NodeTransformers change it, and how a CodeGenerator
will render the AST at any given point.

Files and transforms can be reloaded at any time which facilitates development.
If a tree does not look right after some transformation, the transform can be
edited and reloaded and reapplied.

This tool was derived from `AstViewer <https://github.com/titusjan/astviewer>`_

Expand All @@ -13,7 +17,7 @@ Usage:
======
* Command line example:

%> pyastviewer myprog.py
%> ast_tool_box myprog.py

* Examples to use from within Python:

Expand All @@ -35,5 +39,5 @@ Installation:

2. Run the installer:

%> sudo python setup.py install
%> python setup.py install

1 change: 1 addition & 0 deletions ast_tool_box
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ logger = logging.getLogger(__name__)
def main():
""" Main program to test stand alone
"""
sys.argv[0] = "AstToolBox"
app = QtGui.QApplication(sys.argv) # to allow for Qt command line arguments
remaining_argv = app.arguments()

Expand Down
23 changes: 11 additions & 12 deletions ast_viewer/ast_tool_box.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@

DEBUGGING = False

PROGRAM_NAME = 'AST Toolkit'
PROGRAM_NAME = 'AstToolBox'
PROGRAM_VERSION = '1.0.0'
ABOUT_MESSAGE = u"""
%(prog)s version %(version)s
Expand Down Expand Up @@ -48,7 +48,9 @@ def get_qapplication_instance():
"""
app = QtGui.QApplication.instance()
if app is None:
app = QtGui.QApplication(sys.argv)
# sys.argv[0] = PROGRAM_NAME
print("here I am")
app = QtGui.QApplication(sys.argv[1:])
app.setStyle(QtGui.QMacStyle)
QtGui.QApplication.setStyle(QtGui.QMacStyle())
check_class(app, QtGui.QApplication)
Expand Down Expand Up @@ -186,10 +188,6 @@ def _setup_menu(self):
#file_menu.addAction("C&lose", self.close_window, "Ctrl+W")
file_menu.addAction("E&xit", AstToolBox.quit_application, "Ctrl+Q")

if DEBUGGING is True:
file_menu.addSeparator()
file_menu.addAction("&Test", self.my_test, "Ctrl+T")

view_menu = self.menuBar().addMenu("&View")

self.auto_expand_ast = QtGui.QAction("Expand AST trees on create", self, checkable=True, checked=True)
Expand All @@ -206,24 +204,25 @@ def new_file(self):
""" Clears the widgets """
self.ast_tree.make_tree_from()


def open_file(self, file_name=None):
""" Opens a new file. Show the open file dialog if file_name is None.
"""
if not file_name:
file_name = self._get_file_name_from_dialog()

self._update_widgets(file_name)

self.code_presenter.new_file(file_name)

def _get_file_name_from_dialog(self):
""" Opens a file dialog and returns the file name selected by the user
"""
file_name, _ = QtGui.QFileDialog.getOpenFileName(self, "Open File",
'', "Python Files (*.py);;All Files (*)")
file_name, _ = QtGui.QFileDialog.getOpenFileName(
self,
"Open File",
'',
"Python Files (*.py);;All Files (*)"
)
return file_name


def _update_widgets(self, file_name):
""" Reads source from a file and updates the tree and editor widgets..
"""
Expand Down
7 changes: 6 additions & 1 deletion ast_viewer/controllers/code_presenter.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,17 @@ def __init__(self, tree_transform_controller=None):

self.code_pane = CodePane(code_presenter=self)

def new_file(self, file_name):
self.clear()
self.new_item_from_file(file_name)

def set_transform_presenter(self, transform_presenter):
assert isinstance(transform_presenter, transform_controllers.TransformPresenter)
self.transform_presenter = transform_presenter

def clear(self):
self.code_items = []
while len(self.code_items) > 0:
self.delete_last_item()
self.code_pane.clear()

def delete_last(self):
Expand Down
2 changes: 1 addition & 1 deletion ast_viewer/views/code_views/code_pane.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ def expand_all_asts(self):
pass

def clear(self):
for index in range(self.code_splitter.count()-1, 0, -1):
for index in range(self.code_splitter.count()-1, -1, -1):
self.tab_bar.removeTab(index)
self.code_splitter.widget(index).deleteLater()

Expand Down
2 changes: 1 addition & 1 deletion ast_viewer/views/transform_views/transform_pane.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ def load(self):
self,
caption="Select a file containing Node Transformers",
dir=self.last_used_directory,
# filter="Python Files (*.py);;All Files (*);;"
filter="Python Files (*.py);;All Files (*);;"
)
if file_name:
settings = QtCore.QSettings()
Expand Down
Binary file modified screen_shot.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit d2927dc

Please sign in to comment.