[texworks] New script features (was: Help please with Integer constants and use in messageboxes)

Stefan Löffler st.loeffler at gmail.com
Sun Apr 25 14:51:33 CEST 2010


Hi,

Am 2010-04-25 11:24, schrieb Jonathan Kew:
> It's pretty neat that this works; however, I think we should expose a readFile() method to directly read the text of a file, rather than going through the "open document, get text, close document" sequence. That's pretty inefficient, and could become a significant overhead if you were loading a number of script libraries.
>   

I tend to disagree (partly). A general purpose readFile() is something
that may come in handy some times, but also can do a lot of harm. In
particular, I'd prefer scripts to not use absolute paths as much as
possible. In any case, it would probably be nice to have a runScript()
function that does what one would expect of it (i.e., as Paul suggested,
run a script identified by some name/label, rather than a TWScript
object we currently have no way of obtaining a handle to).

To make a long story short, here's a list of things I'd like to see in
scripting (and for the most of them I even have an idea of how to code
them ;)):
1) Give scripts a way to obtain a handle to their TWScript obj (the
pointer is in TWScriptAPI already, anyway)

2) Provide a per-script list/hash of "globals", i.e. of QVariant
objects; this would give us the possibility to pass data between
successive invocations of the same script (need to think about data
lifetime here; possibly need to find a way to clone objects)

3) Add the possibility to call functions defined in a script from C++

4) Make it possible to connect C++ signals to script slots (it should
already be working for QtScript; for the others we need some tricks -
possibly create a dummy QtScript object to connect to which passes on
the signals to the real script)

5) Introduce a new script type ("multi", "mixed", ... ideas welcome)
that defines only functions. There is one special function (e.g. init())
that gets called when the TWScript object is created. Its purpose is to
register menu items, toolbar items, hooks, ... (whatever comes to mind).
Each of them gets connected to a function provided by the script.

Then, I think, we'd have moved several huge steps further towards even
greater scripting capabilities in Tw.

-Stefan

PS: I just wanted to lay out these plans as several features that were
requested would come naturally if these plans are realized. And also so
people can comment on the ideas, the feasibility, etc.


More information about the texworks mailing list