def _win32_get_syntheyes_main_hwnd(self): """ Windows specific method to find the main SynthEyes window handle (HWND) """ if hasattr(self, "_win32_syntheyes_main_hwnd"): return self._win32_syntheyes_main_hwnd self._win32_syntheyes_main_hwnd = None # find SynthEyes process id: se_process_id = self._win32_get_syntheyes_process_id() if se_process_id != None: # get main application window for SynthEyes process: from tk_syntheyes import win_32_api found_hwnds = win_32_api.find_windows(process_id=se_process_id, class_name='SynthEyes', stop_if_found=False) if len(found_hwnds) == 1: self._win32_syntheyes_main_hwnd = found_hwnds[0] return self._win32_syntheyes_main_hwnd
def show_modal(self, title, bundle, widget_class, *args, **kwargs): """ Shows a modal dialog window in a way suitable for this engine. The engine will attempt to integrate it as seamlessly as possible into the host application. This call is blocking until the user closes the dialog. :param title: The title of the window :param bundle: The app, engine or framework object that is associated with this window :param widget_class: The class of the UI to be constructed. This must derive from QWidget. Additional parameters specified will be passed through to the widget_class constructor. :returns: (a standard QT dialog status return code, the created widget_class instance) """ if not self.has_ui: msg = ('Sorry, this environment does not support UI display!' 'Cannot show the requested window "%s".' % title) self.log_error(msg) return from sgtk.platform.qt import QtGui # create the dialog: dialog, widget = self._create_dialog_with_widget(title, bundle, widget_class, *args, **kwargs) # Note - the base engine implementation will try to clean up # dialogs and widgets after they've been closed. However this # can cause a crash in SynthEyes as the system may try to send # an event after the dialog has been deleted. # Keeping track of all dialogs will ensure this doesn't happen self.__qt_dialogs.append(dialog) # make sure the window raised so it doesn't # appear behind the main SynthEyes window dialog.raise_() dialog.activateWindow() status = QtGui.QDialog.Rejected if sys.platform == "win32": from tk_syntheyes import win_32_api saved_state = [] try: # find all syntheyes windows and save enabled state: se_process_id = self._win32_get_syntheyes_process_id() if se_process_id != None: found_hwnds = win_32_api.find_windows( process_id=se_process_id, class_name='SynthEyes', stop_if_found=False) for hwnd in found_hwnds: enabled = win_32_api.IsWindowEnabled(hwnd) saved_state.append((hwnd, enabled)) if enabled: win_32_api.EnableWindow(hwnd, False) # show dialog: status = dialog.exec_() except Exception, e: self.log_error("Error showing modal dialog: %s" % e) finally: