On Thu, Dec 13, 2018 at 1:10 PM kiteh <[email protected]> wrote:
> Hi everyone, I have an issue with the use of the `toggled` signal.
> I loaded and created the GUI using .ui or uic module.
>
> Example of my tool's code:
> class MyWindow(QtGui.QWidget):
> def __init__(self):
> ...
> # self.informationVisBtn, `setChecked` and `setCheckable` field is
> checked in the .ui file
> self.informationVisBtn.toggled.connect(self.setInfoVis)
>
> def setInfoVis(self):
> self.toggleVisibility(
> self.informationVisBtn.isChecked()
> )
>
> def toggleVisibility(self, value):
> if value:
> self.uiInformationFrame.show()
> self.informationVisBtn.setText("-")
> else:
> self.uiInformationFrame.hide()
> self.informationVisBtn.setText("+")
>
>
> As I load my tool, I had expected the button text to be '-' but instead it
> shows up as '+', even though the frame is still shown.
>
> I had thought that by using toggled and having it initialized under the
> __init__(), it will reads both setInfoVis() and toggleVisibility()
>
This part is the misconception: "it will read both setInfoVis and
toggleVisibility)
That isn't actually how signals/slots work. The signals don't read from the
slots. The signals trigger the slots. This occurs by Qt being told to emit
a signal and then iterating the registered slots and calling them. No
signal, no slot. Your initial state of your class does not emit and signals
after you have wired up the toggled signal to a slot.
If you did something like this in your constructor, it would fix your
problem:
# class state is initialized from ui file and other custom settings
# ...
self.setInfoVis()
# custom signals
self.informationVisBtn.toggled.connect(self.setInfoVis)
> but when I tried adding in a couple of print statements, it does not seems
> to even go pass the `if` statement unless I clicked on the button, only
> will the print statements within the `if` will be executed, or if I added
> in setInfo() before the `xxx.toggled.connect()...`
>
> Any ideas? Or any way that I can force the toggleVisibility() to be
> executed on started up?
>
See above.
Also I just wanted to point out that it is a bit redundant, at least from
your small example, to have the setInfoVis() which calls
toggleVisibility(value) when the toggled signal from the button emits with
a bool argument and could be wired directly to toggleVisibility
> --
> 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 [email protected].
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/python_inside_maya/dede49fa-6633-4fff-a7b6-ea4d31254098%40googlegroups.com
> <https://groups.google.com/d/msgid/python_inside_maya/dede49fa-6633-4fff-a7b6-ea4d31254098%40googlegroups.com?utm_medium=email&utm_source=footer>
> .
> 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 [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/python_inside_maya/CAPGFgA1j72FeinAkA4mNRA6j8%2B34xJ-ea7%3DpdHajZa7%3D6SjJJg%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.