[PyCrust] FW: [pythoncard] updated turtle sample with doc strings and shell init
Brought to you by:
pobrien
|
From: Patrick K. O'B. <po...@or...> - 2001-08-09 00:13:19
|
This is good to know for anyone else using PyCrust as a plugin.
---
Patrick K. O'Brien
Orbtech
"I am, therefore I think."
-----Original Message-----
From: Patrick K. O'Brien [mailto:po...@or...]
Sent: Wednesday, August 08, 2001 6:41 PM
To: pyt...@ya...
Subject: RE: [pythoncard] updated turtle sample with doc strings and shell
init
Kevin had asked me to confirm that his example uses the shell run method the
way it was intended and, indeed, he's got it nailed. The only minor
suggestion I had was that if you had a lot of commands to run you could save
yourself a few keystrokes with this variation:
run = self.stack.app.shell.run
run('from wxTurtle import *')
run('dc = TurtleDC(pcapp.getCurrentBackground().panel)')
run('t = Pen(dc)')
You could also store all of those commands in a separate file and then do
shell.runfile('file') which simply iterates through the file calling run()
on each line.
A final variation exists if you don't want the commands echoed to the shell
editor, which is to send a verbose=0 parameter (it defaults to 1, or True)
to the run command like this:
run('from wxTurtle import *', verbose=0)
run('dc = TurtleDC(pcapp.getCurrentBackground().panel)', verbose=0)
run('t = Pen(dc)', verbose=0)
That way when the shell pops up they won't be looking at all these lines of
code that were pushed through behind the scenes. I would think in most cases
the shell user is going to want to see the commands, which is why run
defaults to verbose turned on.
Looking at the example I gave I'm tempted to suggest that "echo" might be a
better parameter name than "verbose". It also seems a bit tedious to have to
include it as a parameter on each call. I'm open to any suggestions.
---
Patrick K. O'Brien
Orbtech
"I am, therefore I think."
-----Original Message-----
From: Kevin Altis [mailto:al...@se...]
Sent: Wednesday, August 08, 2001 5:49 PM
To: Pythoncard
Subject: [pythoncard] updated turtle sample with doc strings and shell init
I updated the aTurtle.py and wxTurtle.py modules of the turtle sample so
that all the methods now have doc strings. This means that if you're using
the shell to control the turtle interactively, when you type the open parens
for a method:
>>> t.fd(
you'll get a calltip telling you what the method does. That should improve
the ease of experimenting with the various turtle commands.
To highlight another benefit of the shell I added a menu item that
auto-initializes the shell, so the user doesn't have to remember the import
commands. The method in test_turtle.py looks like:
def on_menuCommandsShellInit_select(self, menu, event):
if self.stack.app.shell is not None:
shell = self.stack.app.shell
shell.run('from wxTurtle import *')
shell.run('dc = TurtleDC(pcapp.getCurrentBackground().panel)')
shell.run('t = Pen(dc)')
else:
dlg = PythonCardPrototype.dialog.AlertDialog(self,
"The shell isn't
available",
"PythonCard Error")
Given that this is probably the default initialization a user would want, I
wanted to have the shell.run commands in the __init__ of the background, but
we can't do this yet, because we need an 'openBackground' message that
occurs after all initialization is done. Right now, the Background __init__
is done before any of the Shell, Message Watcher, or Property Editor windows
are created.
As always, the changes to the turtle sample will be part of the next
release.
ka
|