def _OKToAlterUI(self):

        if not QP.isValid(self): return

        main_gui = self.parentWidget()

        # test both because when user uses a shortcut to send gui to a diff monitor, we can't chase it
        # this may need a better test for virtual display dismissal
        not_on_hidden_or_virtual_display = ClientGUIFunctions.MouseIsOnMyDisplay(
            main_gui) or ClientGUIFunctions.MouseIsOnMyDisplay(self)

        main_gui_up = not main_gui.isMinimized()

        return not_on_hidden_or_virtual_display and main_gui_up
    def _DoDebugHide(self):

        if not QP.isValid(self): return

        parent = self.parentWidget()

        possibly_on_hidden_virtual_desktop = not ClientGUIFunctions.MouseIsOnMyDisplay(
            parent)

        going_to_bug_out_at_hide_or_show = possibly_on_hidden_virtual_desktop

        new_options = HG.client_controller.new_options

        if new_options.GetBoolean('hide_message_manager_on_gui_iconise'
                                  ) and not self._DisplayingError():

            if parent.isMinimized():

                self.hide()

                return

        current_focus_tlw = QW.QApplication.activeWindow()

        main_gui_is_active = current_focus_tlw in (self, parent)

        if new_options.GetBoolean('hide_message_manager_on_gui_deactive'
                                  ) and not self._DisplayingError():

            if not main_gui_is_active:

                if not going_to_bug_out_at_hide_or_show:

                    self.hide()
    def _OKToAlterUI( self ):

        if not QP.isValid( self ): return
        
        main_gui = self.parentWidget()
        
        gui_is_hidden = not main_gui.isVisible()
        
        if gui_is_hidden:
            
            return False
            
        
        if HG.client_controller.new_options.GetBoolean( 'freeze_message_manager_when_mouse_on_other_monitor' ):
            
            # test both because when user uses a shortcut to send gui to a diff monitor, we can't chase it
            # this may need a better test for virtual display dismissal
            # this is also a proxy for hidden/virtual displays, which is really what it is going on about
            on_my_monitor = ClientGUIFunctions.MouseIsOnMyDisplay( main_gui ) or ClientGUIFunctions.MouseIsOnMyDisplay( self )
            
            if not on_my_monitor:
                
                return False
                
            
        
        if HG.client_controller.new_options.GetBoolean( 'freeze_message_manager_when_main_gui_minimised' ):
            
            main_gui_up = not main_gui.isMinimized()
            
            if not main_gui_up:
                
                return False
                
            
        
        return True
    def _SizeAndPositionAndShow(self):

        try:

            gui_frame = self.parentWidget()

            possibly_on_hidden_virtual_desktop = not ClientGUIFunctions.MouseIsOnMyDisplay(
                gui_frame)

            gui_is_hidden = not gui_frame.isVisible()

            going_to_bug_out_at_hide_or_show = possibly_on_hidden_virtual_desktop or gui_is_hidden

            current_focus_tlw = QW.QApplication.activeWindow()

            self_is_active = current_focus_tlw == self

            main_gui_or_child_window_is_active = ClientGUIFunctions.TLWOrChildIsActive(
                gui_frame)

            num_messages_displayed = self._message_vbox.count()

            there_is_stuff_to_display = num_messages_displayed > 0

            if there_is_stuff_to_display:

                parent_size = gui_frame.size()

                my_size = self.size()

                my_x = (parent_size.width() - my_size.width()) - 20
                my_y = (parent_size.height() - my_size.height()) - 25

                if gui_frame.isVisible():

                    my_position = ClientGUIFunctions.ClientToScreen(
                        gui_frame, QC.QPoint(my_x, my_y))

                    if my_position != self.pos():

                        self.move(my_position)

                # Unhiding tends to raise the main gui tlw in some window managers, which is annoying if a media viewer window has focus
                show_is_not_annoying = main_gui_or_child_window_is_active or self._DisplayingError(
                )

                ok_to_show = show_is_not_annoying and not going_to_bug_out_at_hide_or_show

                if ok_to_show:

                    self.show()

            else:

                if not going_to_bug_out_at_hide_or_show:

                    self.hide()

        except:

            text = 'The popup message manager experienced a fatal error and will now stop working! Please restart the client as soon as possible! If this keeps happening, please email the details and your client.log to the hydrus developer.'

            HydrusData.Print(text)

            HydrusData.Print(traceback.format_exc())

            QW.QMessageBox.critical(gui_frame, 'Error', text)

            self._update_job.Cancel()

            self.CleanBeforeDestroy()

            self.deleteLater()