Sun, Nov 3, 5:22 PM CST

Renderosity Forums / Poser Python Scripting



Welcome to the Poser Python Scripting Forum

Forum Moderators: Staff

Poser Python Scripting F.A.Q (Last Updated: 2024 Sep 18 2:50 am)

We now have a ProPack Section in the Poser FreeStuff.
Check out the new Poser Python Wish List thread. If you have an idea for a script, jot it down and maybe someone can write it. If you're looking to write a script, check out this thread for useful suggestions.

Also, check out the official Python site for interpreters, sample code, applications, cool links and debuggers. This is THE central site for Python.

You can now attach text files to your posts to pass around scripts. Just attach the script as a txt file like you would a jpg or gif. Since the forum will use a random name for the file in the link, you should give instructions on what the file name should be and where to install it. Its a good idea to usually put that info right in the script file as well.

Checkout the Renderosity MarketPlace - Your source for digital art content!



Subject: wxPython remember dock location


3doutlaw ( ) posted Wed, 26 June 2013 at 10:20 PM · edited Thu, 31 October 2024 at 8:38 AM

For wxPython windows, how do you set it to remember the location of the docked window on the next launch of Poser?  I can get it docking, and I found and understand how to make it non-docking....

What I don't understand is how to get it to remember the dock settings?  When I restart, my script always starts undocked again?

Thanks!


PhilC ( ) posted Thu, 27 June 2013 at 1:58 AM

userDir = os.path.join(poser.PrefsLocation(),"My Script") iniFile = os.path.join(userDir,"MyScript.ini") scene = poser.Scene() man = poser.WxAuiManager() root = man.GetManagedWindow()

class MyClass(wx.ScrolledWindow):

    def __init__(self, parent):
        etc

    def MyFunction(self):
        etc

win = MyClass(root)

def readINIFile(filepath):
    # dock value of one or zero read from ini file

def main():
    readINIFile(iniFile)
    win.MyFunction()

    man.AddPane(win, wx.aui.AuiPaneInfo().
                    Caption("Create Prop").CaptionVisible(True).GripperTop(True).
                    Floatable(True).Resizable(True).DestroyOnClose(True).Dockable(dock).
                    FloatingSize(wx.Size(330, 895)).CloseButton(True).MaxSize(wx.Size(330, 895)).
                    MinSize(wx.Size(330, 250)))

    info = man.GetPane(win)
    info.Show()
    man.Update()

main()

I've used the format above to create a dockable window. The option to dock or not is set by the value read from the ini file on start up. Trouble is that once I docked it, it would always start up docked. I could never again get it to start up un-docked. I've looked for a possible setting in the Poser.ini file but not found one. Not exactly an answer to your problem but may shed some light on it. How are you creating the dockable window for your script?


Fenier ( ) posted Thu, 27 June 2013 at 6:23 AM

You would, on dock, have to set state in a file somewhere.

On script load, you would have to read that file.

When you un-dock it, you must update that file to reflect current state.

 

So three parts:

On Dock - Write to File

On UnDock - Write to File

On Load - Read file


3doutlaw ( ) posted Thu, 27 June 2013 at 12:18 PM

Thanks for the replies, guys! 

I got it docking on startup, but now I realize that I probably have to also read/save the position of the docked pane as well as "if" it is docked or not, so that I can redock it at the same position it was at.


Fenier ( ) posted Thu, 27 June 2013 at 3:42 PM

Correct.

You'd save the exact state to the file, and read that file on startup.

You should have a if clause in there, to if there is no stored position  / state then THIS (whatever this is) should be used.


3doutlaw ( ) posted Thu, 27 June 2013 at 4:31 PM

You don't by any chance have an example do you?  (...not the write/read from file, I get that...its the Read Position and Write Position of the pane) I've been toying with it all day, and using this, but all I've managed to do is mess it up.

In exasperation, I've all but decided to just force it to float, which is not ideal.


Dizzi ( ) posted Fri, 28 June 2013 at 6:08 AM

Have a look at my "MorphScale" script in freestuff. It does load and save its position.

But you cannot force a docked position, easily (and I don't to that). The only way to do that easily is to use the UI dots. They store and restore the whole UI for each room including the wxPython windows.



semidieu ( ) posted Sun, 30 June 2013 at 2:12 PM · edited Sun, 30 June 2013 at 2:15 PM

With Poser 9+, this is working if you use the new 'addons' system.

If you don't use the addons system, I was able to make it work to something similar to what PhilC did.

 

Saving dock info:

  1. Read the pane settings.

  2. Save it in a .ini file.

 

Restoring dock info:

  1. Read the .ini file.

  2. Create the pane with the settings from the .ini file.

 

 

There are some strange things happening... And the position must be adjusted...

When I load a new pange, I'm using a function that read the ini file, the the position (xp, yp), the size (xs, ys), the dock/float status (DOCK), the various docking information (D - Direction, L - layer, P - position and R - row) and the dockable/floatable status.

Getting the docking information:

pane.dock_direction,pane.dock_layer,pane.dock_pos,pane.dock_rowThen to restore the settings, I read the ini file and get the informations:

(xp,yp,xs,ys,DOCK, D, L, P, R, DOCKABLE) =
SWPC_SizeAndPosInstances()

Finally, I'm loading all using this:

if DOCK:<br></br>
  pane.Dock()<br></br>
else:<br></br>
  pane.Float()<br></br>
pane.Dockable(DOCKABLE)<br></br>
pane.Floatable(DOCKABLE)<br></br>
pane.Caption(name).CaptionVisible()<br></br>
pane.Resizable()<br></br>
pane.Direction(D).Layer(L).Position(P-1).Row(R)<br></br>
pane.FloatingSize(wx.Size(xs-16, ys-34))<br></br>
pane.FloatingPosition(wx.Point(xp+8, yp+26))<br></br>
pane.BestSize(wx.Size(100,100))<br></br>
pane.MinSize(wx.Size(100,100))<br></br>
pane.CloseButton(True)<br></br>
pane.MinimizeButton(True)<br></br>
pane.DestroyOnClose(True)

Notice the Position(P-1) which adjust the docking position - don't know why it's necessary but this was working for me.

 

 

Now... this is an old code and certainly might be better :) Last thing, don't forget the addons if you're developing for the latest version of Poser. It's much better and offers other nice uses :)


3doutlaw ( ) posted Sun, 30 June 2013 at 6:47 PM

Dizzi and Basil, I'll give those a look, and a try thanks! 

I looked originally for doco on the addons stuff, but I could not find it?  Is it a seperate PDF I may be missing?


3doutlaw ( ) posted Sun, 30 June 2013 at 10:12 PM

file_495732.txt

Ugh...I worked for a while today with SavePaneInfo and LoadPaneInfo, with awful results.  It would dock only in a single position, and was like in 2 pieces.  A docked piece, and a floating above it piece, that was unselectable.  When I undocked it, it came back together.  It appears to have all of the attributes needed (like Basils listed ones), but I could not get it to work (using Dizzi's example, and a lot of online doco and googling).  Obviously my problem. 

I attached it in case anyone has time to take a look.  I stripped it down to the bare docking and setup stuff, so it is pretty small.  It just loads and has a single file->save command, which create an INI file in c:temp.

You'll have to change it to a .py of course...

(feel free to critique...I am trying to improve)


semidieu ( ) posted Mon, 01 July 2013 at 2:37 PM

I think the biggest problem here is the use of the wxFrame. You should use wxPanel instead.


Privacy Notice

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.