[texworks] SCRIPTING: global __FILE__ now only available when debugger on?

Paul A Norman paul.a.norman at gmail.com
Thu Jan 12 07:43:34 CET 2012


Hi,

These new properties on TW.script  have made  something worthwhile possible
for checking for updates on scripts... in fact "TW.script.date" may even be
worthwhile?

Some draft notes I've added to the API ...

"It is possible to think through ways of including methods people can use
to check for any new Update for your script if you are giving it away, or
it is on an organisations local web server.

"Although direct access is not given to the web, TeXworks does provide a
system command for launching files by address. (There is no guarantee that
a system call to wget or like will work on all systems.)

"Provide an option on your form, or in a drop down box or other for the
User to be able to check for a new version.

"You can call a php script on your local (organisation) or www server
passing variables to it in the html query, and show a page that maintains
an associative array that determines
whether the script has a new version for download or not and
displays an appropriate message to the User.

       var thisFileName =  TW.script.fileName.substr(
                        TW.script.fileName.lastIndexOf("/") +1
                                                  );

var checkFile = "checkFile.php?script=" + thisFileName
                + "&version=" + TW.script.version;

   var whatHappened =  TW.launchFile( // there is a strong security check
on this

                          "http://twscript.paulanorman.info/downloads/"
                          + checkFile
                                     );

      if (whatHappened.status != 0) // call failed
        {
         TW.information("What Happened", whatHappened['message']);
         } //


"Or a more basic approach is to point to a down load page with version
information already shown. This would mean showing the User what the script
name and version number were perhaps as part of any form, drop-down
(getItem) or Information box being presented to them.

var thisOne = TW.getItem(null, "Please Choose",  "This is: " +
TW.script.title
                         +  " version: <b>" + TW.script.version
                         +"</b>  "+ thisFileName

//  Not available        + "<br> Dated : " + TW.script.date
                              + "<br> Please Check for Updates at\n   <span
style='color:navy; text-decoration: underline; cursor:none' title='Choose
Update from Drop Box'>twscript.PaulANorman.info</span>"

                            +"<br><br>Please Choose..."
                            , mainList // mainList is an array
                            , 2
                            , false
                            );

"Then something like...

      var whatHappened =  TW.launchFile("
http://twscript.paulanorman.info/downloads/");

      if (whatHappened.status != 0) // call failed
        {
         TW.information("What Happened", whatHappened['message']);
         } //

Paul

On 12 December 2011 12:44, Paul A Norman <paul.a.norman at gmail.com> wrote:

> Awesome thanks Stefan, I'll write that into the Scripting api.
>
> Actually in one dialogue box I have been making for inserting images
> into .tex docs, I actually have been showing the version number of the
> script in the dialogue so that people would be able to see whether
> they need to upgrade or not - so far I have had to read the script
> itself into memory and search for the string.
>
> So "for the sake of completeness" - the completeness principle proves
> itself again.
>
> Paul
>
> On 12 December 2011 00:01, Stefan Löffler <st.loeffler at gmail.com> wrote:
> > Hi,
> >
> > On 2011-11-20 09:57, Paul A Norman wrote:
> >> Seems any script locating the script's directory through __FILE__ no
> >> longer works when the Debugger is off (eg .ui(s)). I don;t know when
> >> this started but I am reasonably sure I have not had this happen at
> >> all before now. I can not say what version of TW I last successfully
> >> ran __FILE__ with Debugger off I am sorry.
> >>
> >> Is this a new Qt  4.7.3  feature (hmm), or something I should put on
> >> Tw issues?
> >
> > I assume it's a Qt-related thing. In r952, I added a couple of
> > properties to deal with that. The new properties are (as visible in
> > scripts):
> > TW.script.fileName
> > TW.script.title
> > TW.script.description
> > TW.script.author
> > TW.script.version
> >
> > Probably only fileName is of any real interest (as the others are
> > defined exclusively by the script author), but I thought I'd include the
> > rest for the sake of completeness, too.
> >
> > HTH
> > Stefan
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://tug.org/pipermail/texworks/attachments/20120112/494aaf44/attachment.html>


More information about the texworks mailing list