Skip to content

Conversation

@mottosso
Copy link
Owner

@mottosso mottosso commented Nov 6, 2020

Namely:

  1. Errors are now thrown when you e.g. Enum(fields=["A", "B"]) because fields isn't an argument that exists. Still wondering whether we should just use regular function arguments here, would probably help IDEs highlight available arguments etc.
  2. Enum can now be reset properly.

Still not a fan of this, why **kwargs? What was past-Marcus thinking?
@davidlatwe
Copy link
Collaborator

Opps, version num fallback to 0.5.5, should bump back to 0.5.7 or 0.5.6. :P

@mottosso
Copy link
Owner Author

mottosso commented Nov 6, 2020

Nice catch, thanks

@mottosso
Copy link
Owner Author

mottosso commented Nov 6, 2020

Hope we didn't lose any other changes? :O

kwargs["default"] = kwargs.pop("default", None)
kwargs["items"] = kwargs.get("items", [])
kwargs["items"] = kwargs.get("items", ["Default"])
kwargs["default"] = kwargs.pop("default", kwargs["items"][0])
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TypeError raised if kwargs["items"] is a generator :/

TypeError: 'generator' object is not subscriptable

But shouldn't make it to list here as well, the current use case is to run the generator on create.
🤔

Copy link
Collaborator

@davidlatwe davidlatwe Nov 6, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, change to kwargs.pop("default", 0) should work ? since looks like Enum is now all index-based ?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can confirm changing the line

kwargs["default"] = kwargs.pop("default", kwargs["items"][0])

into

kwargs["default"] = kwargs.pop("default", 0)

works. :D

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice, this should work nicely with it also being able to take an integer. Because otherwise, we would have needed to fetch the first string-item from that "items" list.

@davidlatwe
Copy link
Collaborator

Integer is broken as well XD

> Integer("foo", min=1)
TypeError: Integer() got an unexpected keyword argument 'min' #

@mottosso
Copy link
Owner Author

mottosso commented Nov 6, 2020

I'll throw in restyling here as well.

image

@mottosso
Copy link
Owner Author

mottosso commented Nov 6, 2020

For clarity, left-hand side is native Maya and right-hand side is qargparse.

class Options(QtWidgets.QMainWindow):
    def __init__(self, title, parent=None):
        super(Options, self).__init__(parent)
        self.setWindowTitle(title)
        self.setAttribute(QtCore.Qt.WA_DeleteOnClose)
        self.setMinimumWidth(px(550))
        self.setMinimumHeight(px(370))

        buttons = [
            QtWidgets.QPushButton("Create Rigid"),
            QtWidgets.QPushButton("Apply"),
            QtWidgets.QPushButton("Close"),
        ]

        central = QtWidgets.QWidget()
        # central = QtWidgets.QGroupBox()
        header = self.menuBar()
        # body = QtWidgets.QWidget()
        footer = QtWidgets.QWidget()

        edit = header.addMenu("&Edit")
        hlp = header.addMenu("&Help")

        edit.addAction("Save Settings")
        edit.addAction("Reset Settings")
        hlp.addAction("Help on Create Rigid Options")

        layout = QtWidgets.QHBoxLayout(footer)
        layout.setContentsMargins(0, 0, 0, 0)
        layout.addWidget(buttons[0])
        layout.addWidget(buttons[1])
        layout.addWidget(buttons[2])

        args = [
            qargparse.Enum("Bind to", items=["Joint Hierarchy", "Selected Joints", "Object Hierarchy"]),
            qargparse.Enum("Bind method", items=["Closest Distance", "Closest in hierarchy", "Geodesic voxel"]),
            qargparse.Enum("Skinning method", items=["Classic linear", "Dual quaternion"]),
            qargparse.Enum("Normalize weights", items=["Interactive", "Post"]),
            qargparse.Enum("Weight distribution", items=["Distance", "Neighbors"]),
            qargparse.Boolean("Allow multiple bind poses", default=True),
            qargparse.Integer("Max influences", default=5, min=1, max=30),
            qargparse.Boolean("Maintain max influences", default=True),
            qargparse.Boolean("Remove unused influences", default=True),
            qargparse.Boolean("Colorize skeleton", default=True),
            qargparse.Boolean("Include hidden selections on creation", default=False),
            qargparse.Float("Falloff", min=0.0, max=1.0, default=0.2),
            qargparse.Enum("Resolution", items=["1024", "512", "256"], default="256"),
            qargparse.Boolean("Validate voxel state", default=True),
        ]

        parser = qargparse.QArgumentParser(args)

        layout = QtWidgets.QVBoxLayout(central)
        layout.addWidget(parser)
        layout.addWidget(footer)

        self.setCentralWidget(central)

opt = Options("Bind Skin Options")
opt.show()

I was going to collapse the comboboxes, like they are in Maya. But now I'm not so sure. In bulk like this, it looks quite nice. I do want those sliders though, they are handy.

@davidlatwe
Copy link
Collaborator

In bulk like this, it looks quite nice.

Like things all aligned together as well

@mottosso
Copy link
Owner Author

mottosso commented Nov 7, 2020

Added a separate examples file.

$ python examples.py

image

There's some issue with PySide2 under Maya 2018, the blurry one is at 1.0x scale, the others at 1.5x scale, where 2018 should minimize the width but isn't. Isn't respecting the QSizePolicy it seems like. Not sure what that's about. :/

Either way, I made it an option to either fill or not fill the enum boxes, can't make up my mind and expect others will want the choice.

QArgumentParser(style={"comboboxFillWidth": True})

I also thought more about whether to include the : with or without spaces etc. but think that the user could simply add that to their own labels if they want that, which also gives them the power to control how much spacing etc.

qargparse.Enum("No spacing")
qargparse.Enum("Spacing: ")
qargparse.Enum("Special spacing  :  ")
# etc..

Now it'll act on mouse-down instead of up, as up only took effect if you pressed and released whilst holding the cursor on that little square (hard with a pen)
@mottosso
Copy link
Owner Author

mottosso commented Nov 7, 2020

Added some nice sliders, and fixed the issue with number boxes not working with decimal numbers.

@mottosso
Copy link
Owner Author

mottosso commented Nov 7, 2020

You can now add an icon="/path/to/file.png" on the UI, for some extra flare.

For example.

There's also a separation made between default and "initial" value, the default being what you reset to when pressing the reset button, initial being the initial value put into the argument on launch. You would use that to e.g. store initial values on disk, whilst keeping the reset button and the original default value intact.

Boolean("alive", default=True, initial=False)

For cleanup and automatic disconnect of signal connections to arguments
@davidlatwe
Copy link
Collaborator

You can now add an icon="/path/to/file.png" on the UI, for some extra flare.

Awesome !

There's also a separation made between default and "initial" value

Does that means this mottosso/allzpark#49 can be resolved as well ?

@mottosso
Copy link
Owner Author

mottosso commented Nov 8, 2020

Oo, yes, yes it would.

@mottosso
Copy link
Owner Author

mottosso commented Nov 9, 2020

This works well for me so far, think it's ready to merge.

@mottosso mottosso merged commit eaa3753 into master Nov 9, 2020
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

Successfully merging this pull request may close these issues.

3 participants