Python PySide Qt Dialog Strangeness

   2105   1   1
User Avatar
Member
16 posts
Joined: Sept. 2012
Offline
Hi

I was looking at the Font Dialog http://www.sidefx.com/docs/houdini14.0/hom/cookbook/qt/ [sidefx.com], which works fine out of the box. Copied and pasted into a shelf script and great it works.
However when I've put the class FontDialog() from the script in an external file ‘foo.py’ and imported the file/class. Leaving the instantiation of FontDialog in the shelf script.

import foo
reload(foo)

dialog = fooFontDialog()
dialog.show()
dialog.activateWindow()

Basically the dialog just flashes on screen momentarily. Seems a bit odd, must be to do with scope as mentioned in the notes on the example page, because the problem can be worked around using the global keyword technique mentioned in the example.

I tried to find a different approach, other than using the global technique, because remember the example works when the class is also in the shelf script and not in an external file. So why is that?

This is where things get strange!!!

Take a step back to the simple shelf script above -
  • import
    instantiate()
    show
    activateWindow
    Now before or after the instantiation step of our object put in an empty class or function, either of them, doesn't matter, and don't call the function or instantiate the class. Wola it works, the dialog stays in memory and therefore visible.

    def Foo():
    print ‘bar’

    class Bar():
    def __init__(self):
    print ‘foo’

    Does leave me wondering, am I missing something about how python works or is this a bug / feature.

    I'd be interested to hear some thoughts

    cheers Nick
User Avatar
Member
16 posts
Joined: Sept. 2012
Offline
Hi

I found the solution to problem, having to define a function or class construct in order for the Widget to stay in memory.

When subclassing the QDialog I wasn't passing a parent to it's constructor function, in this case the QApplication.instance().activeWindow().

Still strange that having either of those constructs got it working
  • Quick Links