def TIMEREventCheckIfShouldShow(self, event):

        try:

            new_options = HG.client_controller.GetNewOptions()

            if new_options.GetBoolean('always_show_hover_windows'):

                self._SizeAndPosition()

                self.Show()

                return

            if self._hide_until is not None:

                if HydrusData.TimeHasPassed(self._hide_until):

                    self._hide_until = None

                else:

                    return

            if self._current_media is None or not self.GetParent().IsShown(
            ):  # Can't ClientToScreen if not shown, like in init

                self.Hide()

            else:

                (mouse_x, mouse_y) = wx.GetMousePosition()

                (my_width, my_height) = self.GetSize()

                (should_resize, (my_ideal_width, my_ideal_height),
                 (my_ideal_x, my_ideal_y)) = self._GetIdealSizeAndPosition()

                if my_ideal_width == -1:

                    my_ideal_width = max(my_width, 50)

                if my_ideal_height == -1:

                    my_ideal_height = max(my_height, 50)

                (my_x, my_y) = self.GetPosition()

                in_ideal_x = my_ideal_x <= mouse_x and mouse_x <= my_ideal_x + my_ideal_width
                in_ideal_y = my_ideal_y <= mouse_y and mouse_y <= my_ideal_y + my_ideal_height

                in_actual_x = my_x <= mouse_x and mouse_x <= my_x + my_width
                in_actual_y = my_y <= mouse_y and mouse_y <= my_y + my_height

                # we test both ideal and actual here because setposition is not always honoured by the OS
                # for instance, in Linux on a fullscreen view, the top taskbar is hidden, but when hover window is shown, it takes focus and causes taskbar to reappear
                # the reappearance shuffles the screen coordinates down a bit so the hover sits +20px y despite wanting to be lined up with the underlying fullscreen viewer
                # wew lad

                in_position = (in_ideal_x or in_actual_x) and (in_ideal_y
                                                               or in_actual_y)

                menu_open = HG.client_controller.MenuIsOpen()

                dialog_open = False

                tlps = wx.GetTopLevelWindows()

                for tlp in tlps:

                    if isinstance(tlp, wx.Dialog):

                        dialog_open = True

                mime = self._current_media.GetMime()

                mouse_is_over_interactable_media = mime == HC.APPLICATION_FLASH and self.GetParent(
                ).MouseIsOverMedia()

                mouse_is_near_animation_bar = self.GetParent(
                ).MouseIsNearAnimationBar()

                mouse_is_over_something_important = mouse_is_over_interactable_media or mouse_is_near_animation_bar

                focus_is_good = ClientGUICommon.TLPHasFocus(
                    self) or ClientGUICommon.TLPHasFocus(self.GetParent())

                ready_to_show = in_position and not mouse_is_over_something_important and focus_is_good and not dialog_open and not menu_open
                ready_to_hide = not menu_open and (not in_position
                                                   or dialog_open
                                                   or not focus_is_good)

                if ready_to_show:

                    self._SizeAndPosition()

                    self.Show()

                elif ready_to_hide:

                    self.Hide()

        except wx.PyDeadObjectError:

            self._timer_check_show.Stop()

        except:

            self._timer_check_show.Stop()

            raise
Exemple #2
0
    def TIMERUIUpdate(self):

        new_options = HG.client_controller.new_options

        if new_options.GetBoolean('always_show_hover_windows'):

            self._SizeAndPosition()

            self.Show()

            return

        if self._hide_until is not None:

            if HydrusData.TimeHasPassed(self._hide_until):

                self._hide_until = None

            else:

                return

        if self._current_media is None or not self.GetParent().IsShown(
        ):  # Can't ClientToScreen if not shown, like in init

            if self.IsShown():

                if HG.hover_window_report_mode:

                    HydrusData.ShowText(
                        repr(self) +
                        ' - hiding because nothing to show or parent hidden.')

                self.Hide()

        else:

            (mouse_x, mouse_y) = wx.GetMousePosition()

            (my_width, my_height) = self.GetSize()

            (should_resize, (my_ideal_width, my_ideal_height),
             (my_ideal_x, my_ideal_y)) = self._GetIdealSizeAndPosition()

            if my_ideal_width == -1:

                my_ideal_width = max(my_width, 50)

            if my_ideal_height == -1:

                my_ideal_height = max(my_height, 50)

            (my_x, my_y) = self.GetPosition()

            in_ideal_x = my_ideal_x <= mouse_x and mouse_x <= my_ideal_x + my_ideal_width
            in_ideal_y = my_ideal_y <= mouse_y and mouse_y <= my_ideal_y + my_ideal_height

            in_actual_x = my_x <= mouse_x and mouse_x <= my_x + my_width
            in_actual_y = my_y <= mouse_y and mouse_y <= my_y + my_height

            # we test both ideal and actual here because setposition is not always honoured by the OS
            # for instance, in Linux on a fullscreen view, the top taskbar is hidden, but when hover window is shown, it takes focus and causes taskbar to reappear
            # the reappearance shuffles the screen coordinates down a bit so the hover sits +20px y despite wanting to be lined up with the underlying fullscreen viewer
            # wew lad

            in_position = (in_ideal_x or in_actual_x) and (in_ideal_y
                                                           or in_actual_y)

            menu_open = HG.client_controller.MenuIsOpen()

            dialog_open = False

            tlps = wx.GetTopLevelWindows()

            for tlp in tlps:

                if isinstance(tlp, wx.Dialog):

                    dialog_open = True

            mime = self._current_media.GetMime()

            mouse_is_over_interactable_media = mime == HC.APPLICATION_FLASH and self.GetParent(
            ).MouseIsOverMedia()

            mouse_is_near_animation_bar = self.GetParent(
            ).MouseIsNearAnimationBar()

            mouse_is_over_something_important = mouse_is_over_interactable_media or mouse_is_near_animation_bar

            focus_is_good = ClientGUICommon.TLPHasFocus(
                self) or ClientGUICommon.TLPHasFocus(self.GetParent())

            ready_to_show = in_position and not mouse_is_over_something_important and focus_is_good and not dialog_open and not menu_open
            ready_to_hide = not menu_open and (not in_position or dialog_open
                                               or not focus_is_good)

            def get_logic_report_string():

                tuples = []

                tuples.append(('in position: ', in_position))
                tuples.append(('menu open: ', menu_open))
                tuples.append(('dialog open: ', dialog_open))
                tuples.append(('mouse over interactable media: ',
                               mouse_is_over_interactable_media))
                tuples.append(('mouse near animation bar: ',
                               mouse_is_near_animation_bar))
                tuples.append(('focus is good: ', focus_is_good))

                message = os.linesep * 2 + os.linesep.join(
                    (a + str(b) for (a, b) in tuples)) + os.linesep

                return message

            if ready_to_show:

                self._SizeAndPosition()

                if not self.IsShown():

                    if HG.hover_window_report_mode:

                        HydrusData.ShowText(
                            repr(self) + ' - showing.' +
                            get_logic_report_string())

                    self.Show()

            elif ready_to_hide:

                if self.IsShown():

                    if HG.hover_window_report_mode:

                        HydrusData.ShowText(
                            repr(self) + ' - hiding.' +
                            get_logic_report_string())

                    self.Hide()