This might very well be a too specific question for this group and is 
outside of Maya, and I suspect Justin you are more on the Linux side of 
Python, and its more than reasonable to assume the problem is not unique to 
Qt, but I figure asking couldn't hurt.

In Maya, I would fetch a handle to the child window by traversing the 
existing handles of the parent window and finally run .show(), but how does 
this work on top-level windows?

So I'm hiding a PyQt main window and showing it using the pywin32 library 
with its method win32gui.ShowWindow
win32gui.ShowWindow(hsnd, win32con.SW_SHOW)

Which I presume is the equivalent of the ctypes (for those who would rather 
use it over pywin32)
ctypes.windll.user32.ShowWindow(hsnd, win32con.SW_SHOW)

The window shows up, but I suspect the event loop is still on hold as there 
is no interacting with the window, its a complete zombie.

How would I return control to the QApplication event loop (if that indeed 
is the problem) after showing it via the Win32 API?

Here is some sample code (you need 
pywin32<http://sourceforge.net/projects/pywin32/> installed 
and you need to be on Windows). Minimize and re-run the code to have the 
window pop back up. Uncomment closeEvent to make it hide when you try and 
close it. Re-running the code this time will bring up a static window with 
no ability to interact.

import win32gui, win32con
 
from PyQt5.QtWidgets import *
from PyQt5.QtCore import *
from PyQt5.QtGui import *

class Window(QWidget):
    def __init__(self, parent=None):
        super(Window, self).__init__(parent)
        self.setWindowTitle('Test Window')
        self.resize(300, 200)

        QPushButton('Test Button', self)

    # def closeEvent(self, event):
    #     self.hide()
    #     event.ignore()


def new_window():
    import sys
    app = QApplication(sys.argv)
    win = Window()
    win.show()
    sys.exit(app.exec_())


HWND = None
def foreach_window(hwnd, lParam):
    if 'Test Window' == win32gui.GetWindowText(hwnd):
        global HWND
        HWND = hwnd
    return True


win32gui.EnumWindows(foreach_window, 0)


if HWND:
    print "Restoring existing Window"
    win32gui.ShowWindow(HWND, win32con.SW_RESTORE)
else:
    print "No existing Window found"
    new_window()





-- 
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/f094bfcc-a222-4173-b1f0-62b2780ef7db%40googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

Reply via email to