Back to DrPython Help
DrScript
DrScript is vaguely modeled after Script-Fu in The Gimp
(A VERY powerful open source image manipulation program,
used on the images in DrPython).
You can add any python file you want to the DrPython menu
under the heading DrScript (Simply select "Add Script").
To start from scratch, select
"New Script" to add a new script to the menu, then
open it for editing (You will have to select the filename).
You can select "Dynamic DrScript" from the menu
to type in a DrScript right away (without saving it to a file).
Dynamic DrScripts are parsed in the same way as a saved DrScript.
Whether you select "New Script" or "Add Script", you must
select a title for your script. This is what you will see
on the DrScript submenu.
You can also Move Scripts Around on the menu once you have
added them. (Moving Scripts Around Updates and Saves
All of Your Shortcuts.)
When Shortcuts Have been added to the menu, they can
then be seen in the customize shortcuts dialog, and you
can bind keys to your custom scripts.
Now you are ready to script!
It is advisable to make the first line or so read:
#drscript
just as a reminder.
Now let's look at an example DrScript:
Let's say you want to write a script which adds "with ducks" to the
selected
text:
#drscript
DrDocument.SetSelectedText(DrDocument.GetSelectedText()
+ " with ducks!")
First let's look at what this does:
Let's say I select the text:
"The Philosopher shares his epipheny"
I then select "Add With Ducks" from the DrScript submenu.
Viola!
The text now reads:
"The Philosopher shares his epipheny with ducks!"
Back to the program:
DrPython will run the code in the DrScript exactly as if it were
written into the source
of DrPython itself!
The difference is that there are special keywords DrPython recognizes:
You can choose from:
"DrFrame": which gives
access to DrPython internals
(DrFrame)
"DrScript":
a wxObject
attached to DrFrame to hold persistant variables.
"DrFilename": the current
filename (of the active tab if in mdi mode)
"DrDocument": which
gives access
to the Document wxStyledTextControl
"DrPrompt":
which
gives access
to the Prompt wxStyledTextControl
You could choose DrFrame for several reasons. If you want a
dialog,
all you have to do is:
wxTextEntryDialog(DrFrame, "Replace What?:", "Replace All In Selection", "")
In other words, it is perfect for functions that require a wxFrame as
an argument.
You can also access DrPython internals:
Frame.txtDocument.GetTextLength()
Of course, you could also write:
DrDocument.GetTextLength()
Now if you wanted to set a variable in one script, then use it
in
another, you would write:
#drscript
#SetWhoRoars
d = wxTextEntryDialog(DrFrame,
"Who
Roars?", "Determine Who Roars", "")
if (d.ShowModal() == wxID_OK):
DrScript.WhoRoars =
d.GetValue()
#drscript
#AddRoar
if DrScript.VariableExists("WhoRoars"):
DrDocument.SetSelectedText(DrDocument.GetSelectedText() + " roared the
" + DrScript.WhoRoars)
else:
DrDocument.SetSelectedText(DrDocument.GetSelectedText() + " roared the Mouse")
You can also set the Text for either the Prompt or Document.
For example:
#drscript
#AddWithDucks
DrPrompt.SetText(DrDocument.GetSelectedText()
+ " with ducks!")
This code will set the prompt text to the document selection plus the
string "
with ducks!".
Back to DrPython Help