For future reference, and for those interested in trying this with the 
win32 api. This is using pywin32 and pyqt5, the same thing applies using 
pyqt4 and ctypes.


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 event(self, event):
        if isinstance(event, QEnterEvent):
            self.show()
        return super(Window, self).event(event)

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"
    # widget = sip.wrapinstance(HWND, QWidget)
    # print widget
    win32gui.ShowWindow(HWND, win32con.SW_RESTORE)
else:
    print "No existing Window found"
    new_window()




On Sunday, 5 January 2014 22:28:57 UTC, Marcus Ottosson wrote:
>
> 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/0ec423b3-461b-4b9a-96c3-ddc479941c62%40googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

Reply via email to