theodox / mGui

Python module for cleaner maya GUI layout syntax
MIT License
123 stars 23 forks source link

Fix tools #79

Closed theodox closed 7 years ago

theodox commented 7 years ago

77

bob-white commented 7 years ago

Do we want to update gui.py to import from editors and panels now that they're part of core?

theodox commented 7 years ago

Yeah I think we should. We should also bang on the panels and editors a bit more, I don't actually use that stuff much so apart from verifying that it works formally i'm not sure I haven't missed something

theodox commented 7 years ago

@bob-white take a look at this one when you get a chance.

I put a recursive version of wrap into mGui.gui so you can do a one-liner to get an mGui-ified version of an existing gui.

very simple example:

cmds_window = cmds.window( menuBar=1 )
cmds.columnLayout()

def test(*_, **__):
    print "button clicked"
cmds.button(c = test)
cmds.rowLayout(nc=2)
cmds.checkBox()
cmds.textField()
cmds.setParent("..")
cmds.setParent("..")
cmds.menu( label='Position' )
cmds.radioMenuItemCollection()
cmds.menuItem( label='Top', radioButton=False )
cmds.menuItem( label='Middle', radioButton=False )
cmds.menuItem( label='Bottom', radioButton=True )
cmds.menu( label='Number' )
cmds.radioMenuItemCollection()
cmds.menuItem( label='One', radioButton=True )
cmds.menuItem( label='Two', radioButton=False )
cmds.menuItem( label='Three', radioButton=False )
cmds.showWindow()

# -------------------------

from mGui.gui import *
w = wrap(cmds_window)
root = w.find(ColumnLayout)[0]
button = root.find(Button)[0]
button.label = 'set by mGui'
for item in root.recurse():
    if isinstance(item, CheckBox):
        item.value = True         
    if isinstance(item, TextField):
        item.text = "hello world"
theodox commented 7 years ago

@bob-white I merged in your submenu branch to this. Do you have a good test case I can steal to see it in action?

bob-white commented 7 years ago
from mGui import gui

with gui.Window(menuBar=True) as win:
    with gui.Menu(label='TestMenu') as m:
        for v in ('One', 'Two', 'Three'):
            gui.MenuItem(label=v)
        gui.MenuDivider()
        gui.MenuItem(label='Four')
        gui.CheckBoxMenuItem(label='Check')

        with gui.SubMenu(label='sub') as sm:
            for v in ('One', 'Two', 'Three'):
                gui.MenuItem(label=v)
        gui.MenuDivider()        
        with gui.SubMenu(label='Radio') as sm:
            with gui.RadioMenuItemCollection():
                for v in ('One', 'Two', 'Three'):
                    gui.RadioMenuItem(label=v)
            gui.MenuDivider()
            for v in ('One', 'Two', 'Three'):
                gui.MenuItem(label=v)

win.show()

Haven't tested it with menu loader at all, but this should show each part working properly.

bob-white commented 7 years ago

With this merged here, you want me to close out the other PR?

theodox commented 7 years ago

OK, Added a few things needed to make menus work like GUI items (including nested dot-access). menu_loader supports submenus properly too. Take it for a spin and let me know if it looks good!

theodox commented 7 years ago

I'll merge this into main tomorrow just in case something comes up, then I'll check it against the tools at work to see if anything crops up before we call it a release

theodox commented 7 years ago

So I'm seeing that something in this branch is breaking existing menus. The visible symptom is that optionBox menu items fail if they also include the after key. And edit menus don't seem to work more than once; i had two different EditMenus that both touched the main mesh edit menu, but under fix_tools the second one comes in as a submenu

bob-white commented 7 years ago

Yeah, because they both have cmds.menu set as their CMD attribute, so when we're processing the _type_mappings SubMenu is probably coming up second and overwriting the mapping.

Same thing happens with Window and BindingWindow, and while I haven't checked it, I would guess that ActiveOptionMenu is doing the same thing to OptionMenu

~~A possible fix is to check if the key already exists and skip it. That way subclasses don't overwrite. Though we'd need to change gui._collect_mapping to create the mapping itself, instead of working as a generator.~~ Nope, that creates a really odd result. Or I need to double check what the hell I'm doing.

theodox commented 7 years ago

yeah, I'm skipping repeat instances. That makes the menu work again, but the insert-after functionality is broken now. I'll keep poking tonight

bob-white commented 7 years ago

insertAfter was working for me in a simple test. Haven't tried it with the menu loader though.

from mGui import gui, forms

with gui.Window(menuBar=True) as win:
    with forms.VerticalForm():
        for i in xrange(5):
            gui.Button()
    with gui.Menu(label='stuff') as m:
        test = gui.MenuItem(label='Option')
        gui.MenuDivider()
        gui.MenuItem(optionBox=True, insertAfter=test)

win.show()
theodox commented 7 years ago

OK, had to re-add item_array and then make sure gui.wrap uses it correctly. This looks a lot better

theodox commented 7 years ago

# AttributeError: file C:\ul\tools\python\ulMaya\ulMaya\external\mGui\mGui\qt\_properties.py line 36: 'QTextField' object has no attribute 'modal'

it looks like we explicitly check for modal in a lot of places. shouldn't it be a top-level attribute only for windows? we could add a recurse-up 'get top parent' down int the base classes and not have to maintain those flags ...

theodox commented 7 years ago

All the issues I can find are resolved now - anything on your end?

bob-white commented 7 years ago

Bumped into a few issues when running through the examples. Mostly around the shelf_loader, and the primary culprit was PopupMenus

theodox commented 7 years ago

Think we're ready to go?

On Sun, Jul 23, 2017 at 5:03 PM, bob-white notifications@github.com wrote:

Bumped into a few issues when running through the examples. Mostly around the shelf_loader, and the primary culprit was PopupMenus

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/theodox/mGui/pull/79#issuecomment-317292030, or mute the thread https://github.com/notifications/unsubscribe-auth/AD3mGOVC3qsi2y43Up-_acedAnUmeaviks5sQ99CgaJpZM4NXmoC .