Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

pathButtonGrp / folderButtonGrp creates two instances #425

Open
mwspace opened this issue Apr 2, 2020 · 0 comments
Open

pathButtonGrp / folderButtonGrp creates two instances #425

mwspace opened this issue Apr 2, 2020 · 0 comments

Comments

@mwspace
Copy link

mwspace commented Apr 2, 2020

pathButtonGrp and folderButtonGrp will create two instances when a parent is specified, although the second instance in the UI is non-functional. textFieldGrp doesn't have the same problem.

def make_window():

    win = pm.window()
    fl = pm.frameLayout()
    layout = pm.formLayout(parent=fl)    
    fbg = pm.pathButtonGrp(parent=layout)

    layout.redistribute()
    for x in layout.getChildren():
        print x
    return win
    
import pymel.core as pm
w = make_window()
w.show()

Printed output:

window6|frameLayout53|formLayout122|textFieldButtonGrp15
window6|frameLayout53|formLayout122|window6_frameLayout53_formLayout122_textFieldButtonGrp15

When the parent isn't specified, only one is created...

window7|frameLayout54|formLayout123|textFieldButtonGrp16

As far as my primitive understanding goes, the problem is in pymel.core.uitypes.PyUI.__new__(), which creates the extra, non-functional instance despite receiving create=False.

I've worked around for myself it by pushing parent=None into kwargs before the super but I'm not smart enough to know what damage I might be doing...

class PathButtonGrp(TextFieldButtonGrp):
    PROMPT_FUNCTION = 'promptForPath'

    def __new__(cls, name=None, create=False, *args, **kwargs):

        if create:
            import windows

            kwargs.pop('bl', None)
            kwargs['buttonLabel'] = 'Browse'
            kwargs.pop('bc', None)
            kwargs.pop('buttonCommand', None)

            name = cmds.textFieldButtonGrp(name, *args, **kwargs)

            promptFunction = getattr(windows, cls.PROMPT_FUNCTION)

            def setPathCB(name):
                f = promptFunction()
                if f:
                    cmds.textFieldButtonGrp(name, e=1, text=f, forceChangeCommand=True)

            import windows
            cb = windows.Callback(setPathCB, name)
            cmds.textFieldButtonGrp(name, e=1, buttonCommand=cb)

        kwargs['parent']=None #Hack with unknown consequences
        return super(PathButtonGrp, cls).__new__(cls, name, create=False, *args, **kwargs)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant