Forum Moderators: Staff
Poser Python Scripting F.A.Q (Last Updated: 2024 Dec 02 3:16 pm)
I tried Bushi's trick once, with similar results. It clearly needs debugging but I'm not the one to do it! Bushi seems to have disappeared from these forums a couple of months ago. One place to start, maybe: "Attribute error" generally means that the function is being attached to the wrong kind of class. But in this case after() is defined in the TKinter documents as belonging to any kind of Widget, including a Frame; and "master" is a Frame. So the problem must be something else.
My python page
My ShareCG freebies
This version seems to work fine, except that it sometimes, almost randomly, generates a C exception when moving the TK window, and this seems to be only when calling "scene.ProcessSomeEvents(1)". Perhaps I'm wrong using "root." in the Update function? or maybe the 10ms interval needs to be much larger? This does seem to work REALLY well! I need to experiment more I guess. (This is based on Bushi's example of "poser friendly script".) ############################################ from Tkinter import * import poser scene = poser.Scene() class App: ~def init(self, master): ~~frame = Frame(master) ~~frame.grid() ~def Update(self): ~~scene.ProcessSomeEvents(1) ~~root.lift() ~~root.after(10, self.Update) root = Tk() app = App(root) app.Update() root.mainloop() ############################################
Yup, you've done it. This works! I think 10 ms is probably a little fast, though. I set it up with 300 ms, and inserted some move-the-ball code so I could see the action, and it behaved faultlessly.
My python page
My ShareCG freebies
Yes it seems to works good, however you need to call "scene.ProcessSomeEvents()" to keep the TK window on top AND work in the main Poser window at the same time. Unfortunatly, this sometimes randomly generates a "C Exception" when you try to move the TK window. I wish I could figure a way around this. I could just make the TK window open at 0 x 0, but you still might want to move it at some point. So for now, I have "scene.ProcessSomeEvents()" commented out, and the TK window stays on top just fine. By the way, I did get Bushi's example to work by adding the line "self.master = master" inside of " def init(self, master):". Thanks Ockham!
Ok, the generated exception seems to be related to the time before looping the "Update" function. On my machine, if I set the ms in the line; root.after(250, self.Update) to less than 250, a exception will be generated if I try to reposition the TK window. If I set it for higher than 250, no problem. Again, this is only when using; scene.ProcessSomeEvents() to let Poser run along with the script. ProcessSomeEvents takes an argument as to how many poser events to process before it returns, but it seems to work the same with, or without a number specified. Could it be that when the loop time is short, ProcessSomeEvents is called again before it is finished? But that dosen't seem right! I wonder, if there is some way to use "after_idle()" to wait untill all events are processed, before calling "Update" again instead of using a ms setting? I have tried, but I am not sure I fully understand how after_idle works. Any ideas?
Back in the days of pure DOS, a program could count on having the processor's undivided attention, and it was possible to get something done in 10 milliseconds. Now, even with processors 1000 times faster, Windows uses up so much of the computer's resources that 250 ms is a dangerously short time. When you consider that TKinter is running on top of TCL, which is running on top of Python, which is running on top of Poser, which is running on top of Windows, which is running on top of BIOS, it's not surprising to have overlapping events.
My python page
My ShareCG freebies
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.
Using Bushi's example of writing poser friendly script, I would like to keep the dialog ontop the poser window. I understand his example script below runs the function "Repeater" every 250 ms and calls "lift()". This keeps the window ontop by lifting it every 250 ms. However, I get "AttributeError: master" on the line; self.master.after(250, self.Repeater) Why is this? How can I fix it? ####################################### from Tkinter import * import poser scene = poser.Scene() class App: ~def init(self, master): ~~~frame = Frame(master) ~~~frame.grid() ~def Repeater(self): ~~~try: ~~~~self.master.lift() ~~~except: ~~~~pass ~~~scene.DrawAll() ~~~scene.ProcessSomeEvents() ~~~self.master.after(250, self.Repeater) root = Tk() app = App(root) app.Repeater() root.mainloop() ####################################### Thanks! Josiah