PySide: initlal button state

56 views
Skip to first unread message

kevco...@gmail.com

unread,
Sep 14, 2014, 12:10:50 PM9/14/14
to python_in...@googlegroups.com
Hey everybody,

I'm somewhat new to QT, & pyside, not to mention coding in general. I've been working on a tool window for myself, and have hit a snag - I'm hoping someone can point me in the right direction.

There's a few checkable QPushButtons in my dialog that turn on/off some settings in the move, select, or rotate tool.

It's working great. However, I'd like the button check states to assume the state of the tool option when the window is created.

so for instance, If "Symmetry" is turned ON in the Move tool, then when my tool window is created - my button for "Symmetry" is checked.

Thanks!
Kev

Marcus Ottosson

unread,
Sep 14, 2014, 1:15:28 PM9/14/14
to python_in...@googlegroups.com

One way of doing this is to check the state of the Symmetry when you first create the button, and use that value to set your buttons state.

button = QPushButton('Symmetry')

if symmetry_is_on():
    button.setChecked(True)

Where “symmetry_is_on()” is a function you’ve made to check the state of the symmetry.



--
You received this message because you are subscribed to the Google Groups "Python Programming for Autodesk Maya" group.
To unsubscribe from this group and stop receiving emails from it, send an email to python_inside_m...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/dd6324cf-9045-42f4-8b51-f30a8959cf5a%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.



--
Marcus Ottosson
konstr...@gmail.com

kevco...@gmail.com

unread,
Sep 15, 2014, 12:03:54 PM9/15/14
to python_in...@googlegroups.com, kevco...@gmail.com
ah yes. That works great. so simple!

I guess my next logical question would be if there is a way to have those settings in the tool, update the checkbox in my toolwindow.

So if my toolwindow has already been created, and a setting/option within the move tool is changed, it updates the checkbox in my tool window to reflect the new value?

Thanks!

Marcus Ottosson

unread,
Sep 15, 2014, 1:02:24 PM9/15/14
to python_in...@googlegroups.com, kevin cortez
That's a bit more tricky, unfortunately. :)

One method of doing that might be to start a scriptJob and have that monitor an attribute for changes. You could pass a reference to your window into whatever function responds to that change, and use that to toggle your checkbox.

--
You received this message because you are subscribed to the Google Groups "Python Programming for Autodesk Maya" group.
To unsubscribe from this group and stop receiving emails from it, send an email to python_inside_m...@googlegroups.com.

For more options, visit https://groups.google.com/d/optout.



--
Marcus Ottosson
konstr...@gmail.com

damon shelton

unread,
Sep 15, 2014, 1:23:36 PM9/15/14
to python_in...@googlegroups.com, kevin cortez
there is a ToolChanged scriptJob event.
I would suggest creating the scriptjob on window creation. the scriptJob could then emit a qsignal that the tool can connect to to update your UI. and you can kill the scriptJob on ui closeEvent.

kevco...@gmail.com

unread,
Sep 15, 2014, 1:34:09 PM9/15/14
to python_in...@googlegroups.com, kevco...@gmail.com
That sounds exactly like what I need. I wonder if it's really necessary though. Is that 2-way link between built in tools, and user toolwindows common?

This really isn't anything fancy. It just provides quicker access to commonly used tool settings like tweak, soft selection, symmetry, etc, etc.

Thanks!
Kev

damon shelton

unread,
Sep 15, 2014, 1:42:31 PM9/15/14
to python_in...@googlegroups.com, kevin cortez
yes, very common when you need your gui to update based on things that happen in maya. The most common is probably selectionChanged.

--
You received this message because you are subscribed to the Google Groups "Python Programming for Autodesk Maya" group.
To unsubscribe from this group and stop receiving emails from it, send an email to python_inside_m...@googlegroups.com.

kevco...@gmail.com

unread,
Sep 15, 2014, 2:00:31 PM9/15/14
to python_in...@googlegroups.com, kevco...@gmail.com
will I see any performance hit while they're running, or are they fairly gentle?

sorry - this is all new to me ;)

Kev

damon shelton

unread,
Sep 15, 2014, 2:06:47 PM9/15/14
to python_in...@googlegroups.com, kevin cortez
These should be fine. The thing to look out for is what you are actually doing each time the event triggers your code. sometimes triggers can happen faster than you like and you can then use a qtimer to limit the minimum amount of time before a function can actually run again once it is triggered.

scriptJob sends event which triggers your qtimer.start which executes your function. **tip: QTimer should be singleShot=True


Kev

--
You received this message because you are subscribed to the Google Groups "Python Programming for Autodesk Maya" group.
To unsubscribe from this group and stop receiving emails from it, send an email to python_inside_m...@googlegroups.com.

kevco...@gmail.com

unread,
Sep 15, 2014, 2:14:42 PM9/15/14
to python_in...@googlegroups.com, kevco...@gmail.com
ah okay, this helps me a bunch. Thank you.

I'll have to play around with this a bit. I'm sure I'll have some more questions.

Kev

Justin Israel

unread,
Sep 15, 2014, 3:17:51 PM9/15/14
to python_in...@googlegroups.com


On 16/09/2014 6:06 AM, "damon shelton" <damond...@gmail.com> wrote:
>
> These should be fine. The thing to look out for is what you are actually doing each time the event triggers your code. sometimes triggers can happen faster than you like and you can then use a qtimer to limit the minimum amount of time before a function can actually run again once it is triggered.
>
> scriptJob sends event which triggers your qtimer.start which executes your function. **tip: QTimer should be singleShot=True
>

I use this trick often, to delay the response of actions until they stop. Like when someone is typing in a text field and I don't want to trigger expensive refreshes on every character they type. So their typing only calls start() on a single shot qtimer. When they finally stop typing, the timer stops getting reset and triggers.

There is one other variation of this approach that I use as well. If the action that triggers the timer happens often, then there are circumstances where the previous approach may not be the behaviour you want. You may not want your trigger to be reset indefinitely until the source action stops, but rather to have the action fire immediately, but ignore future triggers for a "cool down" period. The variation is to let the source action directly trigger your function, but to use isActive() on the single shot qtimer to see if it is already running, and if so, you bail. Otherwise you do your work and start the timer. Subsequent triggers again will bail while that timer is active. Just don't connect the timer trigger to anything.

> On Mon, Sep 15, 2014 at 11:00 AM, <kevco...@gmail.com> wrote:
>>
>> will I see any performance hit while they're running, or are they fairly gentle?
>>
>> sorry - this is all new to me ;)
>>
>> Kev
>>
>> --
>> You received this message because you are subscribed to the Google Groups "Python Programming for Autodesk Maya" group.
>> To unsubscribe from this group and stop receiving emails from it, send an email to python_inside_m...@googlegroups.com.
>> To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/5d021b7a-2ddd-4885-a667-c18f4bbc9327%40googlegroups.com.
>> For more options, visit https://groups.google.com/d/optout.
>
>
> --
> You received this message because you are subscribed to the Google Groups "Python Programming for Autodesk Maya" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to python_inside_m...@googlegroups.com.

> To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/CAM9RXoK%2BWG08rF%2BrL9GZEi_3kVtm4CF56Vi9gEw%3DnQnNgS7LDQ%40mail.gmail.com.

Reply all
Reply to author
Forward
0 new messages