Debian Codegraph @

src/doc/Script.html

raw symbols SCIP
1 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
2
3 <html>
4 <head>
5 <title>Script - QTerm Documents</title>
6 <link rel="stylesheet" type="text/css" href="doc.css"/>
7 </head>
8 <body>
9
10 <div class="Documentation">
11 <div class="Heading">
12 Script
13 </div>
14 </div>
15
16 <div class="toc">
17 <p><strong>Contents</strong></p>
18 <ul>
19 <li><a href="#Introduction">Introduction</a></li>
20 <li><a href="#How_to_Use">How to Use</a></li>
21 <li><a href="#How_to_Debug">How to Debug</a></li>
22 <li><a href="#How_to_Write_a_Script">How to Write a
23 Script</a></li>
24 <li><a href="#How_to_Write_a_System_Script">How to Write
25 a System Script</a></li>
26 </ul>
27 </div>
28 <a name="Introduction" id="Introduction"></a><h3> Introduction</span></h3>
29 <p>Starting from the version 0.5.6, QTerm supports scripts with QtScript. With
30 the greatest and latest script support in QTerm, you can:</p>
31 <ul>
32 <li> Do boring and repeating operation automatically.</li>
33 <li> Change the default behavior of QTerm with system scripts.</li>
34 <li> Try new functions with script (In order to do this you might want to have Qt bindings for QtScript installed, they can be downloaded from <a href="http://labs.trolltech.com/page/Projects/QtScript/Generator" class="external free" title="http://labs.trolltech.com/page/Projects/QtScript/Generator" rel="nofollow">http://labs.trolltech.com/page/Projects/QtScript/Generator</a>)</li>
35 </ul>
36
37 <a name="How_to_Use" id="How_to_Use"></a><h3> How to Use</h3>
38 <p>You can run simple scripts using Script-&gt;Run, for example, save the following
39 code</p>
40 <pre>for (var i = 0; i &lt; 10; i++)
41 QTerm.sendString("q");
42 </pre>
43 <p>to a script file, run it in QTerm will send 10 q's to the server.</p>
44 <p>To use the system control script. Open the address book, in the very end of
45 the General tab. First enable the Load Control Script checkbox, then choose
46 your system script.</p>
47
48 <a name="How_to_Debug" id="How_to_Debug"></a><h3> How to Debug</h3>
49 <p>If you want to develop serious/complicate scripts for QTerm, it is very
50 helpful to have QScriptEngineDebugger enable. This feature is introduced in Qt
51 4.5, make sure your qt is new enough. Then you can run cmake with
52 -DQTERM_ENABLE_SCRIPT_DEBUGGER=ON, for example:</p>
53 <pre>cmake .. -DQTERM_ENABLE_SCRIPT_DEBUGGER=ON</pre>
54 <p>Then do the usual make, make install to install QTerm
55 </p><p>After you enable the debugger. It will pop up every time the script engine
56 catches a exception. You can also call the debugger any time by Script-&gt;Debug.</p>
57
58 <a name="How_to_Write_a_Script" id="How_to_Write_a_Script"></a><h3> How to Write a Script</h3>
59 <p>Here is a list of functions you can call in the scripts, they are all in the
60 "QTerm" object, so for example if you want to call "version()" you should call
61 "QTerm.version()" instead.</p>
62 <p>QString version()</p>
63 <pre> Return the version of QTerm.</pre>
64 <p>int caretX()</p>
65 <p>int caretY()</p>
66 <pre> Return the x or y coordinate of the current position of caret.</pre>
67 <p>int columns()</p>
68 <p>int rows()</p>
69 <pre> Return the number of columns or rows of the current window.</pre>
70 <p>int charX(int x, int y)</p>
71 <p>int charY(int x, int y)</p>
72 <pre> Given the graphical coordinate in the current window, convert it to the
73 text coordinate.
74 </pre>
75 <p>int posX()</p>
76 <p>int posY()</p>
77 <pre> Return the x or y coordinate of the mouse.</pre>
78 <p>QString getUrl()</p>
79 <p>QString getIP()</p>
80 <pre> Return the URL or IP address under the mouse pointer, if no url is
81 detected an empty string will be returned.
82 </pre>
83 <p>bool isConnected()</p>
84 <pre> Check if the current window is conneced to a BBS server.</pre>
85 <p>void reconnect()</p>
86 <pre> Reconnect to the BBS server, do nothing if the current window is already
87 connected.
88 </pre>
89 <p>void disconnect()</p>
90 <pre> Disconnect from the current BBS server.</pre>
91 <p>void buzz()</p>
92 <pre> Shake QTerm.</pre>
93 <p>void sendString(const QString &amp; string)</p>
94 <pre> Send string to the BBS server.</pre>
95 <p>void sendParsedString(const QString &amp; string)</p>
96 <pre> Send parsed string to the BBS server. you can use '^M' to represent the
97 return key for example.
98 </pre>
99 <p>void osdMessage(const QString &amp; message, int icon = 1, int duration = 0)
100 </p>
101 <pre> Show message in the osd, icon = 0, 1, 2, 3 means No/Info/Warning/Error
102 icon. Duration is in the unit of ms, 0 means forever.
103 </pre>
104 <p>void showMessage(const QString &amp; message, int duration = -1)
105 </p>
106 <pre> Show message in the notification area or system tray. duration is not
107 really useful for now.
108 </pre>
109 <p>void cancelZmodem()
110 </p>
111 <pre> Cancel the current zmodem transfer.
112 </pre>
113 <p>void setZmodemFileList(const QStringList &amp; fileList)
114 </p>
115 <pre> Set the list of files you want to upload with zmodem. call it before your
116 start zmodem to avoid the file selection dialog.
117 </pre>
118 <p>QScriptValue getLine(int line)
119 </p>
120 <pre> Get the object represent the 'line' line text.
121 </pre>
122 <p>QScriptValue window()
123 </p>
124 <pre> Return the current window object.
125 </pre>
126 <p>bool addPopupMenu(QString id, QString menuTitle, QString icon = "QTerm")
127 </p>
128 <pre> Add a menu item to the popup menu, you can access to the new action with
129 QTerm.id property if the method succeed. menuTitle is the text displayed
130 in the menu. currently icon parameter has no effect. Return true if
131 succeed, otherwise it will return false.
132 </pre>
133 <p>bool addUrlMenu(QString id, QString menuTitle, QString icon = "QTerm")
134 </p>
135 <pre> Add a menu item to the url popup menu, you can access to the new action
136 with QTerm.id property if the method succeed. menuTitle is the text
137 displayed in the menu. currently icon parameter has no effect. Return true
138 if succeed, otherwise it will return false.
139 </pre>
140 <p>void addPopupSeparator()
141 </p><p>void addUrlSeparator()
142 </p>
143 <pre> Add separators to the popup/url menu so they will look nicer.
144 </pre>
145 <p>void loadScript(const QString &amp; filename)
146 </p>
147 <pre> Load external javascript files, QTerm will search the file under the
148 "scripts" directory under the local path (e.g.SHOME/.qterm) first and then
149 search the global path (e.g. /usr/share)
150 </pre>
151 <p>void globalPath()
152 </p>
153 <pre> Return the global data path, for example, if you installed QTerm to /usr,
154 then it will return /usr/share.
155 </pre>
156 <p>void localPath()
157 </p>
158 <pre> Return the local data path, $HOME/.qterm under Linux.
159 </pre>
160 <p>QString getSelectedText(bool rect = false, bool color = false, const QString &amp; escape = "")
161 </p>
162 <pre> Return the current selected region. rect should always be false currently.
163 color indicate if you want the copy the attribute of the text, escape is
164 only useful when color is true, indicate how you want to represent the
165 escape sequence.
166 </pre>
167 <p>void openUrl(const QString &amp; url)
168 </p>
169 <pre> Open the url using the http browser specified in QTerm.
170 </pre>
171 <p>void loadExtension(const QString &amp; extension)
172 </p>
173 <pre> Load extension, if you want to use the classes in Qt bindings, you
174 need to load them first.
175 </pre>
176 <a name="How_to_Write_a_System_Script" id="How_to_Write_a_System_Script"></a><h3> <span class="mw-headline">How to Write a System Script</span></h3>
177 <p>In order to change the behavior of QTerm. You can reimplement the following
178 functions in the system script, again all the functions are members of 'QTerm'
179 object, for example init() should be understand as QTerm.init():
180 </p><p>There is a property which is important for this usage: QTerm.accepted. It
181 should be set to true if you do not want the native QTerm code to handle the
182 event any further, otherwise it should set to false.
183 </p><p>init()
184 </p>
185 <pre> This function is called every time the system script is loaded. You can
186 show messages or initiate some variables here.
187 </pre>
188 <p>setCursorType(x,y)
189 </p>
190 <pre> Determine what kind of mouse cursor should be shown in the current
191 context, if mouse release events is not handle by the script this function
192 also determine how the mouse release will be handled.
193 </pre>
194 <p>setPageState()
195 </p>
196 <pre> Determine the current state of the BBS page, useful for further determine
197 the mouse behavior
198 </pre>
199 <p>isLineClickable(x,y)
200 </p>
201 <pre> Determine if the current line under mouse cursor is clickable, x and y is
202 the mouse text coordinate.
203 </pre>
204 <p>getClickableString(x,y)
205 </p>
206 <pre> Determine if the string under mouse cursor is clickable, x and y is the
207 mouse text coordinate, the string should be returned and will be
208 highlighted by QTerm.
209 </pre>
210 <p>onMouseEvent(type, button, buttons, modifiers, pt_x, pt_y)
211 </p>
212 <pre> Handle the mouse event, type, button, buttons, modifiers follow the
213 definition in QMouseEvent, pt_x and pt_y is the graphical coordinate of the
214 mouse pointer.
215 </pre>
216 <p>onKeyPressEvent(key, modifiers, text)
217 </p>
218 <pre> Handle the key press event, the definition of the arguments again follows
219 QKeyEvent.
220 </pre>
221 <p>onWheelEvent(delta, buttons, modifiers, orientation, pt_x, pt_y)
222 </p>
223 <pre> Handle the mouse wheel event, the definition of delta, button, modifiers,
224 and orientation follow QWheelEvent. pt_x and pt_y is the graphical
225 coordinate of the mouse pointer.
226 </pre>
227 <p>onNewData()
228 </p>
229 <pre> The function will be called every time QTerm gets new data, you can
230 manipulate the received data a little bit.
231 </pre>
232 <p>antiIdle()
233 </p>
234 <pre> Determine how the anti idle event should be handled.
235 </pre>
236 <p>autoReply()
237 </p>
238 <pre> Determine how to reply the incoming message. Useful for those who want to
239 write BBS robots.
240 </pre>
241 <p>checkUrl()
242 </p>
243 <pre> Determine if there is a URL under the mouse pointer, return the URL if
244 found, otherwise return a empty string.
245 </pre>
246 <p>checkIP()
247 </p>
248 <pre> Determine if there is a IP address under the mouse pointer, return the URL
249 if found, otherwise return a empty string.
250 </pre>
251 <p>onTelnetState(int state)
252 </p>
253 <pre> Handle telnet events
254 </pre>
255 <p>onZmodemState(int type, int value, const QString&amp; msg)
256 </p>
257 <pre> Handle zmodem events
258 </pre>
259 <p>endOfArticle()
260 </p>
261 <pre> Implement this to check the end of articles for downloading articles
262 </pre>
263 <p>There is also a signal: scriptEvent(const QString&amp; type) which can be used by
264 the script to emit and handle signals
265 </p>
266
267 </body>
268 </html>