[Bf-taskforce25] [Fwd: Re: Python/RNA high priority TODO's.]

Brecht Van Lommel brecht at blender.org
Tue Sep 15 13:17:25 CEST 2009


Hi Michel, Campbell,

On Tue, 2009-09-15 at 10:15 +0200, Michel.Anders at inter.nl.net wrote:
> >
> > import bpy.ui
> > menu = bpy.ui.getMenu('MENU.ADD') # get a reference to the instance of the
> > ADD menu
> >
> > class mymenuitem(bpy.ui.menuitem):
> >    def __init__ .......
> >    def __poll__ .......
> >    ......
> >
> > menu.addItem(mymenuitem())

On Tue, 2009-09-15 at 03:41 -0700, Campbell Barton wrote:
> If we go the OO way you suggest this can be done entirely in python
> using the existing C api internally.
> to me its important that it stays python only otherwise we end up with
> a lot of c/api code which is hard to manage.
> IMHO using the C/register system us overkill too since it would make
> an StructRNA class for every menu item which would clog up bpy.types.*
>
> But there's been no input on this from anyone else.
> any opinions on weather we should have a way that any python defined
> menu can be extended by other scripts?

I agree that something like this could just as well be implemented in
python. It would be good to update the UI on changes, mainly for python
scripters who are making changes while Blender is running, but that's
just a matter of sending a notifier, should not be a problem to add. I
guess we should define a common base class for menus then, which has
some extra python code to make menus extensible?

Further, I don't think a poll() function is necessary for menu items.
Just call a function and it can do an if() test, like other menu items?
But this is not common within menus anyway, and operators already do
poll for graying out.

One thing I'm not sure about is if we should allow items to be added not
only at the end, but also in between. It would be possible to have
something like this, which I think would be needed for proper grouping,
but it also makes the "API" bigger.

def draw(self, context):
    layout = self.layout

    layout.itemO("tfm.translate")
    layout.itemO("tfm.resize")
    layout.itemO("tfm.rotate")
    self.extra_items("transform")

    layout.itemS()

    layout.itemO("node.group_edit")
    layout.itemO("node.group_ungroup")
    layout.itemO("node.group_make")
    self.extra_items("group")

and then:

def draw_shear(panel, context):
    panel.layout.itemO("tfm.shear")

NODE_MT_node.add_item(draw_shear, part="transform")

for simple tools, one line is also enough:

NODE_MT_node.add_item(lambda p, c: p.layout.itemO("tfm.shear"),
part="transform")


Brecht.


More information about the Bf-taskforce25 mailing list