Ejemplo n.º 1
0
    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:
            self.log_error("Sorry, this environment does not support UI display! Cannot show "
                           "the requested window '%s'." % title)
            return        
        
        from tank.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 Photoshop 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 Photoshop window
        FlexRequest.ActivatePython()
        dialog.raise_()
        dialog.activateWindow()

        status = QtGui.QDialog.Rejected
        if sys.platform == "win32":
            from tk_photoshop import win_32_api

            saved_state = []
            try:
                # find all photoshop windows and save enabled state:
                ps_process_id = self._win32_get_photoshop_process_id()
                if ps_process_id != None:
                    found_hwnds = win_32_api.find_windows(process_id=ps_process_id, 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:
Ejemplo n.º 2
0
    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:
            self.log_error("Sorry, this environment does not support UI display! Cannot show "
                           "the requested window '%s'." % title)
            return        
        
        from tank.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 Photoshop 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 Photoshop window
        FlexRequest.ActivatePython()
        dialog.raise_()
        dialog.activateWindow()

        status = QtGui.QDialog.Rejected
        if sys.platform == "win32":
            from tk_photoshop import win_32_api

            saved_state = []
            try:
                # find all photoshop windows and save enabled state:
                ps_process_id = self._win32_get_photoshop_process_id()
                if ps_process_id != None:
                    found_hwnds = win_32_api.find_windows(process_id=ps_process_id, 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:
Ejemplo n.º 3
0
    def _win32_get_photoshop_main_hwnd(self):
        """
        Windows specific method to find the main Photoshop window
        handle (HWND)
        """
        if hasattr(self, "_win32_photoshop_main_hwnd"):
            return self._win32_photoshop_main_hwnd
        self._win32_photoshop_main_hwnd = None

        # find photoshop process id:
        ps_process_id = self._win32_get_photoshop_process_id()

        if ps_process_id != None:
            # get main application window for photoshop process:
            from tk_photoshop import win_32_api
            found_hwnds = win_32_api.find_windows(process_id=ps_process_id, class_name="Photoshop", stop_if_found=False)
            if len(found_hwnds) == 1:
                self._win32_photoshop_main_hwnd = found_hwnds[0]

        return self._win32_photoshop_main_hwnd
Ejemplo n.º 4
0
    def _win32_get_photoshop_main_hwnd(self):
        """
        Windows specific method to find the main Photoshop window
        handle (HWND)
        """
        if hasattr(self, "_win32_photoshop_main_hwnd"):
            return self._win32_photoshop_main_hwnd
        self._win32_photoshop_main_hwnd = None

        # find photoshop process id:
        ps_process_id = self._win32_get_photoshop_process_id()

        if ps_process_id != None:
            # get main application window for photoshop process:
            from tk_photoshop import win_32_api
            found_hwnds = win_32_api.find_windows(process_id=ps_process_id, class_name="Photoshop", stop_if_found=False)
            if len(found_hwnds) == 1:
                self._win32_photoshop_main_hwnd = found_hwnds[0]

        return self._win32_photoshop_main_hwnd