[texworks] Scripts: Exploration of TW objects

Stefan Löffler st.loeffler at gmail.com
Mon Nov 8 17:08:57 CET 2010


Am 2010-11-08 11:31, schrieb Paul A Norman:
> There are a couple of functions under TW.target that have an unexpected names.
>  runScript(QObject*)
>  runScript(QObject*,TWScript::ScriptType)
>  runHooks(QString)
> Stefan has already told me that we can not run scripts from scripts so
> I am naturally intrigued by these fellows' names !
> If they don't set anything do I populate them and they return a value
> of some sort?

You continually surprise me ;).
But you're right, of course, these functions are there, although they
probably shouldn't be.
So, runScript does what it says, it runs a script. The QObject* is a
pointer to the script object to run. Right now you shouldn't be able to
get a hold of such an object (other than TW.script, of course), so these
two functions are of little use (as I said, they actually shouldn't be
available, anyway ;)). The reason why it's a QObject* and not a
TWScript* is the internal mechanism of mapping menu items to scripts. On
that matter, it might be possible to run scripts via the menu (i.e., get
a handle to the QAction describing the menu item and call the
triggered() slot). This wouldn't be helpful, though, as I think the
script is run asynchronously. In any case, it's not really advisable at
the moment.

The runHooks() function also shouldn't be there and shouldn't be used.
It is probably functional, however, in the sense that you could say
runHooks("NewFile") to run the NewFile hooks. Note that this is against
the very nature of hooks and must not be done.

> I tried this but running it breaks on  TW.target.runScript(xx);
>  var xx = {};
>  TW.target.runScript(xx);
>  TW.information(null, "xx", xx);
>  var yy = {}; var look;
>  TW.target.runScript(yy,look)
>  TW.information(null, yy, look);

As said above, you'd need to have a TWScript* object, like TW.script
(which would cause an infinite loop, though, and probably run into many
other problems of shared variables in undefined states, etc.).

> This guy is referring to Qt style css type instructions for the current window?
> setStyleSheet(QString)


> And I was looking for guidance on these two please.
>  setSyntaxColoring(int)
>  setSyntaxColoringMode(QString)
> Does that suggest that some aspect of the syntax-patterns.txt file can
> be directly selected?

Yes. Basically, it does the same as if the user clicked on a menu item
in the syntax coloring menu. The int version uses a numeric index (0 is
the first pattern as defined in syntax-patterns.txt, 1 the second, and
so on; -1 corresponds to None, IIRC). The QString version selects a menu
item by name (note that None might be translated).


More information about the texworks mailing list