Right, I completely forgot a use case. I'm looking to bring up an existing application if one exists when the application is being run twice, such as a launcher type application. If the launcher is already up, I'd like to restore it, rather than create a new instance.
There might be a better way? On 5 January 2014 23:03, Justin Israel <[email protected]> wrote: > Maybe something to do with widget events not being generated (stab in the > dark) when you go through the window system instead of qt? > Out of curiosity, what is the use case for controlling the windows this > way? > > > On Mon, Jan 6, 2014 at 11:28 AM, Marcus Ottosson > <[email protected]>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/f094bfcc-a222-4173-b1f0-62b2780ef7db%40googlegroups.com >> . >> For more options, visit https://groups.google.com/groups/opt_out. >> > > -- > 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/CAPGFgA03e3NL3KrWOfhPV0EPkbw8q5_LDO6qoJnE5JJEOzceLg%40mail.gmail.com > . > > For more options, visit https://groups.google.com/groups/opt_out. > -- *Marcus Ottosson* [email protected] -- 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/CAFRtmOCBy1bmH1vJrGbP%3DHRK1YpH9V_6g0UeqtiTA75_u0Hh-A%40mail.gmail.com. For more options, visit https://groups.google.com/groups/opt_out.
