[texworks] SCRIPTING: TW.deleteLate()

Stefan Löffler st.loeffler at gmail.com
Mon Jun 20 17:00:14 CEST 2011


Hi,

On 2011-06-20 14:27, Paul A Norman wrote:
> Just confirming for complete clarity ...
>
> So    TW..deleteLater(showMoreDialogue);
>
> Must be ... ?
>
>  showMoreDialogue.deleteLater();

Yes, exactly.

> Your .odt notes to me late last year (now in Scripting Api) noted to
> leave TW.deleteLater() alone (
> http://twscript.paulanorman.com/docs/html/files/deleteLater.html ), I
> got confused when trying to work out how to get rid of dialogues.

Yes, you _should_ leave TW.deleteLater() alone, as that would kill the
connection between the script and Tw itself. Back then, I told you to
simply ignore it mainly because deleteLater is a method provided
automatically for any QObject and it was nothing Tw specific that was
added to the API. For dialogs, it turns out to be important, but only
for the dialog variables.

> > Just a word of caution: as discussed before, connecting to signals is
> not guaranteed to 
> > be stable ATM.
>
> For me, afaik, no problem with signals ever so far ever since UI
> became available in Scripting.
> Especially using the Qt supplied connection  model style in last email:
>
>    eval("convertImage.finished." + connectAction + "(dialog_finished)");
>
> I haven't tried the other way.

OK. I just wanted to point it out. It may work (in particular for modal
dialogs), but this depends on the way Qt handles things internally. I'm
just not giving any guarantees (not that I could on other matters ;)).

> > and doesn't cover some cases, where dialogs would be created
> on-the-fly based on user input
>
> Ok, created and deleted locally in creating function then?

Yes, that's an option.

> Or when needed to be used in other functions once created, could
> just declare the var global say as a string = "I'm not a dialogue
> yet", not know whether the User initialised it or not as a dialogue,
> and at finalisation test the global var's .toString().indexOf() for
> either the dialogue QDialog className or "I'm not a dialogue yet", if
> appropriate  then run .deleteLater() on it during Script finalisation?

I wouldn't use a string here, more something like null (and then test
=== null (I think that's supported in QtScript?)).
Also, I'm not a real fan of global variables, but that's a matter of
philosophy. Having an object that bundles all dialogs, for example,
would be more OOP style, but in reality it doesn't matter that much IMHO.

> Otherwise if being used in more than one function once the User has
> made it, you'd never know whether and when to deletLater() on it or
> not.  Could also test for initialisation on "I'm not a dialogue
> yet" in any function that wants to use it calling a function to do
> that test which can then create it if necessary?

"Create on demand" sounds like a sensible idea as well.
The interesting question still is if deleteLater() can be called on a
dialog not created.

> >  e.g., dialogs could be kept in TW.globals for later use.
>
> Had tried that when Script UI first came out, and thought it didn't
> work (might have to retry and make sure I got it right). Really like
> the idea!

I naively think that it should work, but I haven't tried it. So maybe
there is a subtle problem somewhere I don't know of.

HTH
Stefan


More information about the texworks mailing list