[texworks] New script features (was: Help please with Integer constants and use in messageboxes)
jfkthame at googlemail.com
Mon Apr 26 02:21:22 CEST 2010
On Sun, Apr 25, 2010 at 1:51 PM, Stefan Löffler <st.loeffler at gmail.com>wrote:
> 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.
Could you explain a bit more about your concern here?
> particular, I'd prefer scripts to not use absolute paths as much as
True, in general - although if the script is building the path by starting
from things like its own path, or the path of the document it's working
with, and modifying the file name/extension, etc, then the fact that it's an
absolute path is not important.
> 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).
Yes, that might be nice. Though it raises questions of context: does the new
script execute in its own separate context, or can it be run within the
current script's context (allowing sharing of globals, etc)? I suppose that
could only work if the scripts are in the same language....
> 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)
That's easy, I guess; what do you expect it to be used for?
> 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)
How about also having an application-wide collection of such globals, so
that it's possible for a group of related scripts to share data?
> 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)
Yes; I presume this would allow non-modal script-created windows to do more
interesting things in response to controls. (You can do a few things
already, by connecting signals in the UI widgets to slots within the
application. But that's very limited, as it doesn't allow the script to
intervene and customize things.)
I've been wondering if we should in some way allow scripts to be "attached"
to the windows they create in this situation. But perhaps that's not
necessary. If the script object is deleted/replaced while the connected
widgets are still around, the connections will break, but no real harm
should follow - the user would just have to close and re-instantiate the
window to get it working again.
> 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.
Defines functions for use as hooks, callback slots, whatever....
No need for a magic init() function: the "main program" of the script is
executed on load, and can do whatever setup is desired.
Or maybe we should have both initialize() and terminate() functions; the
latter provides an opportunity for the script library to do last-minute
things before the app shuts down, such as saving its globals to a .ini file,
to be read by initialize() next time it is loaded.
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the texworks