source: branches/mbutscher/work/WikidPadHelp/data/InlinePythonEval.wiki @ 195

Last change on this file since 195 was 192, checked in by mbutscher, 10 years ago

branches/mbutscher/work:
2.0beta03

  • Option to reverse search order for scripts (global imports first)
  • Wiki-bound option to create wiki page files with ASCII-only names (does not apply to Compact Sqlite DB backend). This should also fix a problem with Windows binary installer and WikidPad help wiki on non-western Windows versions.
  • Wiki-bound option to handle missing or externally inserted page files gracefully (does not apply to Compact Sqlite DB backend)
  • New insertion "iconimage" to insert an icon into an HTML page.
  • Preview shows link target in the status bar when hovering with mouse over it like browsers do
  • Menu item "Select All" in "Edit" menu (for completeness)
  • Bug fixed: Some errors weren't recorded in error log
  • Bug fixed: stdDialog of doc page presenter did not return a value (needed for some plugins)
  • Bug fixed: Tree scrolled to wrong initial position on startup
  • Bug fixed: Windows: Spell check addon did not work due to wrong DLL find mechanism
  • Bug fixed: LossyWikiCloseDeniedException? wasn't caught and polluted error log
  • Bug fixed: Search and replace dialog for page cleared "Search" text field when "Find next" was pressed
  • Bug fixed: Wiki-wide search dialog did not focus search text field when initially shown
  • Bug fixed: Pollution of error log if moving mouse over incremental search field
File size: 3.5 KB
Line 
1++ Inline Python Eval
2
3
4+++ Security concerns
5WikidPad allows to evaluate and execute arbitrary Python scripts.
6Because this is a potential security risk, script execution is
7disabled by default.
8
9To enable it, open the "Options" dialog, chapter "Other", item
10"Script security". In the drop-down field you can enter the level
11of security you want:
12
13    * No scripts: Script execution is completely disabled. This is
14      the default.
15    * No import_scripts: Scripts on the currently open page can be
16      executed and expressions evaluated. Importing scripts from
17      other pages with the import_scripts property doesn't work (see
18      below how to do this).
19    * No global.import_scripts: Property "import_scripts" works,
20      but "global.import_scripts" does not
21    * Allow everything
22
23
24When pressing Ctrl-1 to Ctrl-6 WikidPad searches for a script normally in the following order:
25
26    * Current page
27    * Pages imported by current page with attribute "import_scripts"
28    * Page imported somewhere with attribute "global.import_scripts"
29
30The latter two are only searched if security settings allow it.
31The order can be reversed by checking option "Reverse script search order (global imports first)" on options page "Security".
32
33
34
35
36
37The following examples work therefore only with an appropriately relaxed security setting.
38
39
40+++ Evaluating expressions
41You can evaluate Python expressions directly in the editor by
42highlighting the expression and pressing CTRL-E. Example:
43
44Highlight the calculation below, and type CTRL-E.
45
461+2+3
47 
48 
49+++ Executing scripts on the same page
50You can also execute blocks of code within a document.  Blocks of code
51are defined within <% %> blocks. For example:
52
53<%
54editor.GotoPos(editor.GetLength())
55editor.AddText('\nhello ')
56%>
57
58To execute the code above, type Ctrl-E. Ctrl-E actually will execute all
59of the scripts on a page, including script imports.
60
61You can assign up to 6 functions on a page to a Ctrl-# key. For example:
62
63function 1: <% 1: editor.AddText(lib.now()) %>
64function 2: <% 2: lib.addDate(editor) %>
65
66Type Ctrl-1 to execute function 1. Enter Ctrl-2 to execute function 2.
67This will execute at most one script. If a script with this number is
68found on the page, it is executed, if not, the local script imports
69with import_scripts are searched. If no appropriate script is found
70there either, the page mentioned in global.import_scripts is searched.
71As already said, this happens only with the right security settings.
72
73You can define your own functions for evaluation by copying
74evalLibrary.py into a directory in the wikidPad install directory
75called "user_extensions". This file will not be touched when upgrading
76wikidPad.
77
78file:///C|/Program%20Files/WikidPad/extensions/EvalLibrary.py
79file:///C|/Program%20Files/WikidPad/user_extensions/EvalLibrary.py
80
81
82+++ Script Imports
83
84You can import scripts from another page using the following attribute.
85
86[import_scripts: GlobalScriptLibrary]
87
88Type "Ctrl-4" to see the output from script 4 on the page
89GlobalScriptLibrary.
90
91You can also use \[global.import_scripts: ...] property to define a single page which will be seen as if it was imported by every page of the wiki.
92
93
94+++ Editor Control Functions
95
96See http://www.yellowbrain.com/stc/index.html for a list of the functions
97available to the "editor" control.
98
99
100+++ Another Example
101
102Highlight the line below and press CTRL-3
103
104c:\this path\will be encoded.txt
105
106<% 3: lib.encodeSelection(editor) %>
Note: See TracBrowser for help on using the repository browser.