pyxPOP "beta testing"

Post Reply
User avatar
rray
Moderator
Posts: 1774
Joined: 26 Sep 2009, 15:51
Location: Bonn, Germany
Contact:

pyxPOP "beta testing"

Post by rray » 02 Sep 2010, 00:04

Hello once more 8-x

I've been working today on this "beta" python version of XPOP. I'd be particularly interested if it works on linux (I mean it uses the win32gui module but maybe mainwin supports it)

Once installed, it can be used from JScript and VBS, too.

Usage Examples:

Python Example:

Code: Select all

def handler(n):
    Application.LogMessage(str(n))

p = Application.XPOP()

submenu =  p.AppendSubMenu( p.mainmenu, "HelloX" )
ok = p.AppendMenu( submenu, "HelloY", "Application.NewScene()" )

submenu2 =  p.AppendSubMenu( submenu , "HelloZ" )
ok = p.AppendSeparator( submenu2 )
ok = p.AppendMenu( submenu2 ,"bottom", "handler(2)" )

exec(p.Track())
VBS Example:

Code: Select all

set p = XPOP()

subm =  p.AppendSubMenu( p.mainmenu, "HelloX" )
ok   = p.AppendMenu( subm, "HelloY", "NewScene()" )

subn =     p.AppendSubMenu( Cdbl(subm), "HelloZ" )
ok   = p.AppendSeparator( subn )
ok   = p.AppendMenu( subn,"bottom", "handler(2)" )

ExecuteGlobal p.Track

sub handler(i)
    logmessage(i)
end sub
JS Example:

Code: Select all

var p = XPOP();

sub =  p.AppendSubMenu( p.mainmenu, "HelloX");
            p.AppendMenu( sub, "HelloY", "NewScene();");
sub2 =  p.AppendSubMenu( sub, "HelloZ");
                p.AppendMenu( sub2,"bottom", "handler(2)");

eval(  p.Track() );

function handler(i)
{
    logmessage(i);
}
Thanks for reporting xD

PS I've been wondering if the old 1-long-string syntax will be still useful or if I should discard it.
Attachments
pyXPOP.zip
zipped xsiaddon
(2.61 KiB) Downloaded 166 times
softimage resources section updated Jan 5th 2024

User avatar
Hirazi Blue
Administrator
Posts: 5107
Joined: 04 Jun 2009, 12:15

Re: pyxPOP "beta testing"

Post by Hirazi Blue » 02 Sep 2010, 10:40

Something specific you would like to see tested
(other than if it works in Linux, which I sadly cannot test)
or do you need mere confirmation of the general "yes, it works" kind?
Anyhow, I'll try to look into it later today...
;)
Stay safe, sane & healthy!

User avatar
rray
Moderator
Posts: 1774
Joined: 26 Sep 2009, 15:51
Location: Bonn, Germany
Contact:

Re: pyxPOP "beta testing"

Post by rray » 02 Sep 2010, 11:34

Thanks for having a look Hirazi - I'm just probing the communiy to see if someone sees any pitfalls with the new method that I've been missing.
Or suggestions on how to extend it, I'm looking into adding a title for the menu as well as possibly icons

~o)

btw here's the sourcecode.. could be useful if someone's interested in doing windows programming in xsi. It should also be a nice starting point for doing things like custom drawn radial menus etc.

Code: Select all

import win32com.client, win32com.server
from win32com.client import constants
import win32gui, win32con, win32api

class xpop:
    _public_methods_ = ['Track', 'AppendMenu', 'AppendSeparator', 'AppendSubMenu']
    _public_attrs_ = ['mainmenu']
 
    def __init__(self):   
        self.mainmenu = win32gui.CreatePopupMenu()    
        self.itemhandlers = ['']
        self.idcount = 0
        self.pickedmenuid = 0
        
    def CreateInvisibleWindow(self):
        self.wc = win32gui.WNDCLASS()
        self.wc.lpszClassName = 'win32gui_invisiblewindow_class'
        self.wc.lpfnWndProc= { win32con.WM_COMMAND:self.OnCommand }
        self.class_atom=win32gui.RegisterClass(self.wc)       
        self.hwnd = win32gui.CreateWindow(self.wc.lpszClassName, "Invisible message receiving window", win32con.WS_CAPTION|win32con.WS_SYSMENU, 20, 20, 50, 50, 0, 0, 0, None)
            
    def Track(self):
        self.CreateInvisibleWindow()
        pos = win32gui.GetCursorPos()
        win32gui.TrackPopupMenu(self.mainmenu, win32con.TPM_LEFTALIGN, pos[0], pos[1], 0, self.hwnd, None)
        win32gui.PumpWaitingMessages()
        win32gui.DestroyWindow(self.hwnd)
        win32gui.UnregisterClass(self.wc.lpszClassName, None)
        return self.itemhandlers[self.pickedmenuid]
        
    def AppendSubMenu(self, parent, string):
        hSubMenu = win32gui.CreatePopupMenu()
        win32gui.AppendMenu( parent, win32con.MF_STRING|win32con.MF_POPUP, hSubMenu, string)
        return hSubMenu;
        
    def AppendMenu(self, parent, string, handler):        
        self.idcount = self.idcount + 1
        self.itemhandlers.append(handler)
        return win32gui.AppendMenu( parent, win32con.MF_STRING, 1024 + self.idcount, string)
         
    def AppendSeparator(self, parent):
        return win32gui.AppendMenu( parent, win32con.MF_SEPARATOR, 0, '')
        
    def OnCommand(self, hwnd, msg, wparam, lparam):
        self.pickedmenuid = wparam - 1024

def XSILoadPlugin( in_reg ):
    in_reg.Author = "Reinhard Claus"
    in_reg.Name = "pyXPOPPlugin"
    in_reg.Major = 1
    in_reg.Minor = 0
    in_reg.RegisterCommand("XPOP","XPOP")
    return 1
    
def XPOP_Execute(  ):
    return win32com.server.util.wrap( xpop() )

def XPOP_Init( in_ctxt ):
    oCmd = in_ctxt.Source
    oCmd.ReturnValue = 1
    return 1
 
def XSIUnloadPlugin( in_reg ):
    strPluginName = in_reg.Name
    return 1
softimage resources section updated Jan 5th 2024

User avatar
Hirazi Blue
Administrator
Posts: 5107
Joined: 04 Jun 2009, 12:15

Re: pyxPOP "beta testing"

Post by Hirazi Blue » 02 Sep 2010, 21:07

Okay, I finally got around to test this & it seems to work. Must dig a bit deeper, before I can say anything more, but at the moment I really haven't got the time. Sorry.
It seems that while creating a custom command the handler function in your example needs to live outside of the execute callback otherwise strange things happen.

How is this "different" for the user from the "xPopMenu" for Python by Patrick Boucher?
Stay safe, sane & healthy!

User avatar
rray
Moderator
Posts: 1774
Joined: 26 Sep 2009, 15:51
Location: Bonn, Germany
Contact:

Re: pyxPOP "beta testing"

Post by rray » 02 Sep 2010, 22:06

Thank you, Hirazi for your time. No obligations here ;) :D
Hm I'm having a slow day, I didn't understand what you meant be living outside the execute callback. Does it mean that it can not be implemented inside the plugin code? Or just not as a functions-inside-the-execute-function?

There's no difference really to Patrick Boucher's extension except that it's just simpler implementation because it doesn't use the original XPOP, and that it (hopefully) runs on linux. Also it is extendable (also hopefully).
softimage resources section updated Jan 5th 2024

User avatar
Hirazi Blue
Administrator
Posts: 5107
Joined: 04 Jun 2009, 12:15

Re: pyxPOP "beta testing"

Post by Hirazi Blue » 02 Sep 2010, 22:12

just not as a functions-inside-the-execute-function
And this is obviously me having a bad day, because you cannot do this period AFAIK. :-
But it took way too much time before I noticed,
after simply copy/pasting your example into a custom command
and wondering what the error message was trying to tell me. :ymblushing:
That's why I mentioned it!

A little more documentation would have been nice, though...
I looked at the original xPop site and felt naturally something was missing (=Python :D )
Stay safe, sane & healthy!

User avatar
rray
Moderator
Posts: 1774
Joined: 26 Sep 2009, 15:51
Location: Bonn, Germany
Contact:

Re: pyxPOP "beta testing"

Post by rray » 02 Sep 2010, 22:32

Ah that's good to hear no 2nd file has to be used. It's usually not possible to make functions in a function, only as inline functions, something like (JScript)

set_timeout(6minutes, function() { alert("you egg is ready to consume"); })

I'll create some docs for the finished Xpop 2.0, and also try to make a little download library of ready-to-use popups.

Python is neat, with Softimage there seems to be a collection of addititonal libraries distributed (like the win32gui I used). Just beginning to explore these.
softimage resources section updated Jan 5th 2024

User avatar
Hirazi Blue
Administrator
Posts: 5107
Joined: 04 Jun 2009, 12:15

Re: pyxPOP "beta testing"

Post by Hirazi Blue » 03 Sep 2010, 10:05

Forgot to mention this yesterday (and I'm not sure if this is xPop-related or a mere Softimage quirk), but your example code creates an entry to open a new scene. This prompts you with the normal "want to save? yes | no | cancel" dialog. When you however press "cancel" this throws an error.
Again, not sure if this standard Softimage behavior (as I have never started a new scene from scripting before), but I wanted to mention it nonetheless...
;)
Stay safe, sane & healthy!

User avatar
rray
Moderator
Posts: 1774
Joined: 26 Sep 2009, 15:51
Location: Bonn, Germany
Contact:

Re: pyxPOP "beta testing"

Post by rray » 03 Sep 2010, 15:49

This looks like a bug with python, even if you type Application.NewScene() in the command line you get that
Doing some custom draw tests right now after having spent too much time in the sun X(
softimage resources section updated Jan 5th 2024

User avatar
rray
Moderator
Posts: 1774
Joined: 26 Sep 2009, 15:51
Location: Bonn, Germany
Contact:

Re: pyxPOP "beta testing"

Post by rray » 06 Sep 2010, 00:16

Ok rc1 :- some custom drawing code finished ~o)

Image

New features:
* icon support (For now only a fixed set of icons. They are installed with the xsiaddon)
* "section headers" with custom background color (these can't be selected)
* possible to set a vertical offset for the whole menu, so the mouse cursor is on a specified menu item when it's activated
* example popup menu commands in python, VBS and js
* accelerator keys work now
* greyed out menu items
* (checkboxes can be created with the "Ok" icon .. but the logic has to be done manually)

Here's a list of the icons, add a menu item with icon like this (JS)

Code: Select all

item = p.AddItem( sub2, "Pepsi Light", "handler(2)");
p.SetIcon( item, "Flag" ); 
The JS example command demonstrates some menu logic like radio buttons/toggle checkboxes/enable menu item. VBS and python example only show basic menu

Image
(from Axialis Studios)

download here
softimage resources section updated Jan 5th 2024

Post Reply

Who is online

Users browsing this forum: No registered users and 29 guests