Forum Moderators: Staff
Poser Python Scripting F.A.Q (Last Updated: 2024 Sep 18 2:50 am)
Tromnek: OK, I'm bringing my scale and pet duck over to see how much you weigh. I think this code proves that ... you're a witch! ;) So to try this out, do both scripts need this hijacked mainloop, or is it one 'regular' mainloop and one newtered one? And how many scripts have you tried to run simultaneously with this framework? Thanks...duckmango
It works best if this code loads first. Then run as many scripts as you want. Close and reopen them in any order. You can even close this code before others and things will work fine closeing what ever you like in any order, but don't run any new ones. There are some combinations that will make it 'crash', I need to enumerate them in the doc text.
The main thing to watch out for are foreign scripts where the main function performs some kind of cleanup after it's regular 'mainloop()'. This is because the hijacked mainloop() returns immediately. So scripts should do all their cleanup in their class, not in main.
There are also the standard issues of global() pollution.
This can have some disasterous effects when scripts are running at the same time.
fixed the premature newted mainloop(). in 'def ChangeToNewtMiscMainLoop(self, n=0)' after the print statement add self.master.wait_window( self ) that should keep us in the newterd mainloop until the foreign script destroy()s itself. Just like expected. I also got rid of the self.master.lift(),(duh!), in my Update method. I also cancel the self.master.after(...) when my apps cleanup code. With this done. You can quit your app before other running 'newtered' scripts and everybody stays happy (I think).
Oops, self.master.wait_window(self) doesn't help. I guess the newterd scripts will have to be able to handle an immediate return from their mainloop(). Sorry, I thought it was working because all the GUI stuff seemed to be working. Also, I noticed an oddity with Tkinter stuff that relies on 'variable changes', like Radiobutton's 'variable=foo, value=bar'. I had to change my stuff and add a 'command=' to those things.
Follow up: In P5, the textvariable setting in the Label widget stops displaying after running the hijack script. Tkinter snippet: self.myMessage = StringVar() self.myMessage.set("How do you know she's a ...") Label(parent, textvariable=self.myMessage).grid(row=0) This bug appears only in P5. It's OK in PP, as well as in standalone python.
Looks like I'm going to have to newter Tkinter.Tk() also. Maybe add to
def ChangeToNewt():
<br></br> Tkinter.IGotBetterTk = Tkinter.Tk<br></br> def ChangeToNewtTk():<br></br> return Tkinter.Toplevel()<br></br><br></br> Tkinter.Tk = ChangeToNewtTk<br></br>
and add to def IGotBetter():
<br></br> Tkinter.Tk = IGotBetterTk<br></br>
But now the script that does this must run before any other scripts. Like a 'Protecter of the Realm' script.
KingArthur = NewtMainLoop( Tkinter.Tk() )
It will also need to schedule time for poser.ProcessSomeEvents(),
KingArthur.Update()
It seems to work, but I spoke too soon before. I'll test some more when I get a chance thursday.
NewtTk().mainloop()
or your app can create a separate 'Sir Bedevere' along with itself by;
root = NewtTk().Tk()<br></br>(snip...)<br></br>root.mainloop()
or your app can keep 'Sir Bedevere' all to itself by;
root = NewtTk().Tk(newtoplevel=0)<br></br>(snip...)<br></br>root.mainloop()
Let me know if there are any problems with this approach (or any suggestions).
duckmango, I renamed a bunch of symbols from earlier versions you saw, hope it isn't too confusing.
I had to hijack Tkinter.Misc.quit() also. I added some tracking of newtered (hijacked) scripts so that confirmation of closing can warn a user that other scripts will also close.
I'm releasing the code under the GNU 'Lesser' public license so that this class can be used in commercial scripts.
If I don't hear any complaints or problems within the next week or two, I'll release a non-beta version 1.15 back to this thread.
Duckmango, thanks for the help.
Now I can get back to my 'poser remote procedure call daemon' which is what started all of this stuff.
This site uses cookies to deliver the best experience. Our own cookies make user accounts and other features possible. Third-party cookies are used to display relevant ads and to analyze how Renderosity is used. By using our site, you acknowledge that you have read and understood our Terms of Service, including our Cookie Policy and our Privacy Policy.
I did some more work on this. It turns out that the real curlprit is Tkinter.mainloop(). I found some stuff on this topic and the best approach for my purpose is to hijack Tkinter's event loop. Here's what I currently have;
Let me know what you folks think.