示例#1
0
    def __Scroll(self, type):
        xViewStart, yViewStart = self.GetViewStart()
        xClientSize, yClientSize = self.GetClientSizeTuple()
        xVirtualSize, yVirtualSize = self.GetGridWindow().GetVirtualSize()
        xScrollPixels, yScrollPixels = self.GetScrollPixelsPerUnit()

        xScrollOld = self.GetScrollPos(wx.HORIZONTAL)
        yScrollOld = self.GetScrollPos(wx.VERTICAL)

        if (xScrollPixels == 0):
            xClientSize = 0
            xVirtualSize = -1
        else:
            xClientSize = xClientSize / xScrollPixels
            xVirtualSize = xVirtualSize / xScrollPixels
        if (yScrollPixels == 0):
            yClientSize = 0
            yVirtualSize = -1
        else:
            yClientSize = yClientSize / yScrollPixels
            yVirtualSize = yVirtualSize / yScrollPixels

        if (type == FGrid.__SCROLL_PAGE_UP):
            yDest = yViewStart - (5 * yClientSize / 6)
            if (yDest == -1):
                self.Scroll(-1, 0)
            else:
                self.Scroll(-1, yDest)
        elif (type == FGrid.__SCROLL_PAGE_DOWN):
            self.Scroll(-1, yViewStart + (5 * yClientSize / 6))
        elif (type == FGrid.__SCROLL_UP):
            self.Scroll(-1, yViewStart - 1)
        elif (type == FGrid.__SCROLL_DOWN):
            self.Scroll(-1, yViewStart + 1)
        elif (type == FGrid.__SCROLL_LEFT):
            self.Scroll(xViewStart - 1, -1)
        elif (type == FGrid.__SCROLL_RIGHT):
            self.Scroll(xViewStart + 1, -1)
        elif (type == FGrid.__SCROLL_ABS_TOP):
            self.Scroll(-1, 0)
        elif (type == FGrid.__SCROLL_ABS_BOTTOM):
            self.Scroll(-1, yVirtualSize - yClientSize)
        elif (type == FGrid.__SCROLL_ABS_LEFT):
            self.Scroll(0, -1)
        elif (type == FGrid.__SCROLL_ABS_RIGHT):
            self.Scroll(xVirtualSize - xClientSize, -1)

        xScrollNew = self.GetScrollPos(wx.HORIZONTAL)
        if (xScrollOld != xScrollNew):
            e = wx.ScrollWinEvent(wx.wxEVT_SCROLLWIN_THUMBTRACK, xScrollNew,
                                  wx.HORIZONTAL)
            e.SetEventObject(self)
            self.GetEventHandler().ProcessEvent(e)

        yScrollNew = self.GetScrollPos(wx.VERTICAL)
        if (yScrollOld != yScrollNew):
            e = wx.ScrollWinEvent(wx.wxEVT_SCROLLWIN_THUMBTRACK, yScrollNew,
                                  wx.VERTICAL)
            e.SetEventObject(self)
            self.GetEventHandler().ProcessEvent(e)
示例#2
0
    def EventMouseWheel(self, event):

        if self._text_ctrl.GetValue() == '' and len(self._dropdown_list) == 0:

            if event.GetWheelRotation() > 0:
                id = ClientCaches.MENU_EVENT_ID_TO_ACTION_CACHE.GetTemporaryId(
                    'select_up')
            else:
                id = ClientCaches.MENU_EVENT_ID_TO_ACTION_CACHE.GetTemporaryId(
                    'select_down')

            new_event = wx.CommandEvent(
                commandType=wx.wxEVT_COMMAND_MENU_SELECTED, winid=id)

            self.ProcessEvent(new_event)

        else:

            if event.CmdDown():

                key_event = wx.KeyEvent(wx.EVT_CHAR_HOOK.typeId)

                if event.GetWheelRotation() > 0:

                    key_event.m_keyCode = wx.WXK_UP

                else:

                    key_event.m_keyCode = wx.WXK_DOWN

                self._dropdown_list.ProcessEvent(key_event)

            else:

                # for some reason, the scrolledwindow list doesn't process scroll events properly when in a popupwindow
                # so let's just tell it to scroll manually

                (start_x, start_y) = self._dropdown_list.GetViewStart()

                if event.GetWheelRotation() > 0:
                    self._dropdown_list.Scroll(-1, start_y - 3)
                else:
                    self._dropdown_list.Scroll(-1, start_y + 3)

                if event.GetWheelRotation() > 0:
                    command_type = wx.wxEVT_SCROLLWIN_LINEUP
                else:
                    command_type = wx.wxEVT_SCROLLWIN_LINEDOWN

                wx.PostEvent(self, wx.ScrollWinEvent(command_type))
示例#3
0
    def EventMouseWheel(self, event):

        if self._text_ctrl.GetValue() == '' and len(self._dropdown_list) == 0:

            if event.GetWheelRotation() > 0:

                new_event = SelectUpEvent(-1)

            else:

                new_event = SelectDownEvent(-1)

            wx.PostEvent(self.GetEventHandler(), new_event)

        else:

            if event.CmdDown():

                if event.GetWheelRotation() > 0:

                    self._dropdown_list.MoveSelectionUp()

                else:

                    self._dropdown_list.MoveSelectionDown()

            else:

                # for some reason, the scrolledwindow list doesn't process scroll events properly when in a popupwindow
                # so let's just tell it to scroll manually

                (start_x, start_y) = self._dropdown_list.GetViewStart()

                if event.GetWheelRotation() > 0:
                    self._dropdown_list.Scroll(-1, start_y - 3)
                else:
                    self._dropdown_list.Scroll(-1, start_y + 3)

                if event.GetWheelRotation() > 0:
                    command_type = wx.wxEVT_SCROLLWIN_LINEUP
                else:
                    command_type = wx.wxEVT_SCROLLWIN_LINEDOWN

                wx.PostEvent(self._dropdown_list.GetEventHandler(),
                             wx.ScrollWinEvent(command_type))
示例#4
0
    def scrollXY(self, scrollPosX, scrollPosY):
        """
        Set scroll bars according to given pixel positions
        """

        # Bad hack: First scroll to position to avoid a visible jump
        #   if scrolling works, then update display,
        #   then scroll again because it may have failed the first time

        self.SetScrollPos(wx.HORIZONTAL, scrollPosX, False)
        screvt = wx.ScrollWinEvent(wx.wxEVT_SCROLLWIN_THUMBTRACK, scrollPosX,
                                   wx.HORIZONTAL)
        self.ProcessEvent(screvt)
        screvt = wx.ScrollWinEvent(wx.wxEVT_SCROLLWIN_THUMBRELEASE, scrollPosX,
                                   wx.HORIZONTAL)
        self.ProcessEvent(screvt)

        self.SetScrollPos(wx.VERTICAL, scrollPosY, True)
        screvt = wx.ScrollWinEvent(wx.wxEVT_SCROLLWIN_THUMBTRACK, scrollPosY,
                                   wx.VERTICAL)
        self.ProcessEvent(screvt)
        screvt = wx.ScrollWinEvent(wx.wxEVT_SCROLLWIN_THUMBRELEASE, scrollPosY,
                                   wx.VERTICAL)
        self.ProcessEvent(screvt)

        self.Update()

        self.SetScrollPos(wx.HORIZONTAL, scrollPosX, False)
        screvt = wx.ScrollWinEvent(wx.wxEVT_SCROLLWIN_THUMBTRACK, scrollPosX,
                                   wx.HORIZONTAL)
        self.ProcessEvent(screvt)
        screvt = wx.ScrollWinEvent(wx.wxEVT_SCROLLWIN_THUMBRELEASE, scrollPosX,
                                   wx.HORIZONTAL)
        self.ProcessEvent(screvt)

        self.SetScrollPos(wx.VERTICAL, scrollPosY, True)
        screvt = wx.ScrollWinEvent(wx.wxEVT_SCROLLWIN_THUMBTRACK, scrollPosY,
                                   wx.VERTICAL)
        self.ProcessEvent(screvt)
        screvt = wx.ScrollWinEvent(wx.wxEVT_SCROLLWIN_THUMBRELEASE, scrollPosY,
                                   wx.VERTICAL)
        self.ProcessEvent(screvt)
示例#5
0
 def test_ScrollWinEvent_ctor(self):
     evt = wx.ScrollWinEvent()