[texworks] newbie texworks scripting questions
Stefan Löffler
st.loeffler at gmail.com
Sun Jul 3 12:33:57 CEST 2011
Hi,
a few (off-topic) remarks and clarifications.
On 2011-07-02 01:25, Paul A Norman wrote:
> Python freeze.
>
> Depending on platform/permission issues you can call any ting your
> system will execute form a Tw Script system() call, and optionally
> wait for a return code and or a returned string from your executable.
>
> Your questions raises the issues of which of the TW File functions
> return TW.target objects (like window.document in browsers).
> Some do not. I have not had cause to work with them all as yet. The
> C++ code is available on
> http://code.google.com/p/texworks/source/browse/trunk to troll
> through, or you can experiment testing for TW.target.text to see if
> you get the contents of the editor window that you expect.
>
> There is an application object present called TW.app which loosely
> corresponds to the browser window object.
>
> And TW.target which as mentioned loosely corresponds to the
> window.document object.
>
> TW.target represents the current document, whether focussed by the
> User or in Script, and has a function TW.target.typeset() (document
> would need a saved name on disk first though!)
>
> Of course you could process/save your text in/from script memory to
> disk named as you wish, and then uses TW.system() to execute the
> necessary pdflatex etc TeX utilities directly, you would have to be
> confident of the results as this would not use any of the Tw console
> responses to errors .
>
> TW.app has these calls
>
> TW.app.newFile();
> http://twscript.paulanorman.com/docs/html/files/newFile.html
> Creates a new file and sets the focus in the editor. Returns a
> TW.target object ??
No, it returns nothing. This (and most of the other methods you mention
below) are exactly the ones called when you click on the corresponding
toolbar icons (or menu items). There's no point in return anything, as
there's no place to return it to.
As an aside: all these TW.app event-handling methods are essentially to
accommodate the Mac, where you can have a global menu even without any
windows open.
> TW.app.open();
> http://twscript.paulanorman.com/docs/html/files/open.html
> Presents the open file dialogue.
> >From that point scripting looses 'contact' with the function.
> Does not receive a file filter nor a suggested file name, but will not
> allow the dialogue "Ok" button to be enabled unless the User chooses
> an actual file.
> Upon success, opens the chosen file in a new editor window, (returns
> no value — for neither success nor failure).
> That editor window does not become the new TW.target.
Yes. TW.target never changes (it is the context in which the script is
run; a script cannot be transferred to a different context once it was
started).
[There is one minor exception to this if you have an empty, unmodified
file to begin with. In this case, TW.target doesn't change either, but
because no new window is opened it will probably enable you to access
the opened document (though I haven't tested this yet).]
> Moved to top level for security reasons:
> TW.openFileFromScript(QString,int,bool)
It's TW.app.openFileFromScript(QString,TW,int,bool).
> The TW.target object has some similar calls, but there has been little
> discussion/information here about those yet (and some may be
> obsolete?) ...
As above, these are the entry points for the corresponding menu items
(this time for the current window). Internally, they usually relay the
call to the TW.app methods. They were not originally intended to be
called from scripts, but can be nevertheless (only they are not designed
to take or return scripting-specific data).
HTH
Stefan
More information about the texworks
mailing list