Beispiel #1
0
    def scroll(self, z):
        if self.isSubMenuNeedScroll():
            self.subMenuOffsetIdx = clamp(0, self.subMenuOffsetIdx + z, len(self.children))
            sw, sh = self.subMenuSize
            dw, dh = self.window.size
            h = 0
            idx = 0
            for c in self.children[: self.subMenuOffsetIdx]:
                h += c.height
                if sh - h < dh:
                    h = sh - dh
                    self.subMenuOffsetIdx = idx
                    break
                idx += 1

            rh = 0  # remain height
            for c in self.children[self.subMenuOffsetIdx :]:
                rh += c.height
                c.dirty = True
                if rh > dh:
                    break

            self.subMenuOffset.Reset(0.3, -h)
            self.dirty = True
            return True
        return hasattr(self, "subMenuExpand") and self.subMenuExpand
Beispiel #2
0
    def scroll(self, z):
        if self.fullSize > self.height:
            self.subMenuOffsetIdx = clamp(0, self.subMenuOffsetIdx + z, len(self.children))
            sw, sh = self.width, self.fullSize
            dw, dh = self.window.size
            h = 0
            idx = 0
            for c in self.children[: self.subMenuOffsetIdx]:
                h += c.height
                if sh - h < dh:
                    h = sh - dh
                    self.subMenuOffsetIdx = idx
                    break
                idx += 1

            rh = 0  # remain height
            for c in self.children[self.subMenuOffsetIdx :]:
                rh += c.height
                c.dirty = True
                if rh > dh:
                    break

            self.onScroll(float(h) / self.fullSize)
            self.dirty = True
            return True
        return True
Beispiel #3
0
    def __getSubMenuPos(self):
        mw, mh = self.subMenuSize

        # calc the expect position
        if self.sysMenuItem:
            pos = 0, self.height
        else:
            # default sub menu is on the right side
            pm = self.popupMenu
            pos = self.width - (pm.subMenuIndent if pm else 0), -(mh - self.height) / 2
            # return (pm.subMenuIndent if pm else 0) - self.subMenuSize[0], 0

            # fix position to prevent outside the window
            dw, dh = self.window.size
            l, t = self.local2global(*pos)
            if l + mw > dw:  # display sub menu on left side
                _l, _t = (pm.subMenuIndent if pm else 0) - mw, pos[1]
                l, t = self.local2global(_l, _t)
            l = max(0, l)
            if mh > dh:
                t = 0
            else:
                t = clamp(0, t, dh - mh)
            pos = self.global2local(l, t)
        return pos
Beispiel #4
0
    def __getSubMenuPos(self):
        mw, mh = self.subMenuSize

        # calc the expect position
        if self.sysMenuItem:
            pos = 0, self.height
        else:
            # default sub menu is on the right side
            pm = self.popupMenu
            pos = self.width - (pm.subMenuIndent
                                if pm else 0), -(mh - self.height) / 2
            #return (pm.subMenuIndent if pm else 0) - self.subMenuSize[0], 0

            # fix position to prevent outside the window
            dw, dh = self.window.size
            l, t = self.local2global(*pos)
            if l + mw > dw:  # display sub menu on left side
                _l, _t = (pm.subMenuIndent if pm else 0) - mw, pos[1]
                l, t = self.local2global(_l, _t)
            l = max(0, l)
            if mh > dh:
                t = 0
            else:
                t = clamp(0, t, dh - mh)
            pos = self.global2local(l, t)
        return pos
Beispiel #5
0
    def scroll(self, z):
        if self.fullSize > self.height:
            self.subMenuOffsetIdx = clamp(0, self.subMenuOffsetIdx + z,
                                          len(self.children))
            sw, sh = self.width, self.fullSize
            dw, dh = self.window.size
            h = 0
            idx = 0
            for c in self.children[:self.subMenuOffsetIdx]:
                h += c.height
                if sh - h < dh:
                    h = sh - dh
                    self.subMenuOffsetIdx = idx
                    break
                idx += 1

            rh = 0  # remain height
            for c in self.children[self.subMenuOffsetIdx:]:
                rh += c.height
                c.dirty = True
                if rh > dh:
                    break

            self.onScroll(float(h) / self.fullSize)
            self.dirty = True
            return True
        return True
Beispiel #6
0
    def scroll(self, z):
        if self.isSubMenuNeedScroll():
            self.subMenuOffsetIdx = clamp(0, self.subMenuOffsetIdx + z,
                                          len(self.children))
            sw, sh = self.subMenuSize
            dw, dh = self.window.size
            h = 0
            idx = 0
            for c in self.children[:self.subMenuOffsetIdx]:
                h += c.height
                if sh - h < dh:
                    h = sh - dh
                    self.subMenuOffsetIdx = idx
                    break
                idx += 1

            rh = 0  # remain height
            for c in self.children[self.subMenuOffsetIdx:]:
                rh += c.height
                c.dirty = True
                if rh > dh:
                    break

            self.subMenuOffset.Reset(0.3, -h)
            self.dirty = True
            return True
        return hasattr(self, 'subMenuExpand') and self.subMenuExpand
Beispiel #7
0
 def moveToFocus(self, anim=True):
     '''
     move focus item to center
     '''
     #prevent invalid offset when list item is less than view
     old_o1 = -self.o1.QueryValue()
     o1 = 0
     if self.cellSize * len(self._items) <= self.viewSize:
         o1 = 0
         if anim:
             self.o1.Reset(self.animTime, 0)
         else:
             self.o1.Assign(0)
     else:
         o1 = (self.cellSize + self.cellMargin) * self.focusIdx - (
             self.viewSize - self.cellSize - self.cellMargin) / 2
         o1 = clamp(0, o1, self._full - self.viewSize)
         if anim:
             self.o1.Reset(self.animTime, -o1)
         else:
             self.o1.Assign(-o1)
     #self.o1 = -o1
     self.__resetDisplayRange(old_o1, o1)
     if self._full:
         self.invoke('Fix Scroll', -self.o1 / self._full)
Beispiel #8
0
 def onSlideMove(self, x, y):
     self.thumbStart = clamp(self.__start,
                             self.__capPos + (y if self.vertical else x),
                             self.__end)
     self._thumbStartAnim.ForceAssign(int(self.thumbStart))
     if self.snap == 0:
         self.__updateValue()
Beispiel #9
0
 def __onScroll(self, x, y):
     if self.vertical:
         offset = float(y) / self.height
     else:
         offset = float(x) / self.width
     self.__offset = clamp(0, self.__capOffset + offset, self.maxOffset)
     self.__onChangeOffset()
     self.__animScroll(self.thumbStart)
Beispiel #10
0
 def onKey(self, key):        
     if self.vertical and (key == 'UP' or key == 'DOWN') or not self.vertical and (key == 'LEFT' or key == 'RIGHT'):
         interval = float(self.valueRange[1] - self.valueRange[0]) / 10
         if key == 'UP' or key == 'LEFT':
             interval = -interval
         self.value = clamp(self.valueRange[0], self.value + interval, self.valueRange[1])
         return True
     return super(Slider, self).onKey(key)
Beispiel #11
0
 def __onScroll(self, x, y):
     if self.vertical:
         offset = float(y) / self.height
     else:
         offset = float(x) / self.width
     self.__offset = clamp(0, self.__capOffset + offset, self.maxOffset)
     self.__onChangeOffset()
     self.__animScroll(self.thumbStart)
Beispiel #12
0
 def __onMouseWheel(self, delta):
     old_o1 = -self.o1.QueryValue()
     #o1 = -self.o1
     new_o1 = old_o1 - delta * (self.cellSize + self.cellMargin)
     new_o1 = clamp(0, new_o1, max(0, self._full - self.viewSize))
     self.o1.Reset(self.animTime, -new_o1)
     self.__resetDisplayRange(old_o1, new_o1)
     if self._full:
         self.invoke('Fix Scroll', -self.o1 / self._full)
Beispiel #13
0
 def onSlideTo(self, x, y, flag):
     self.thumbStart = clamp(self.__start, (y - self.thumb.height / 2) if self.vertical else (x - self.thumb.width / 2), self.__end)
     if self.snap > 0:
         self.__updateValue()
         self.__updateThumbPos()
     else:            
         self._thumbStartAnim.ForceAssign(int(self.thumbStart))
         self.__updateValue()
     self.invoke('Slide To', self.__value)
Beispiel #14
0
 def __onMouseWheel(self, delta):
     old_o1 = -self.o1.QueryValue()
     #o1 = -self.o1
     new_o1 = old_o1 - delta * (self.cellSize + self.cellMargin)
     new_o1 = clamp( 0, new_o1, max(0, self._full - self.viewSize) )
     self.o1.Reset( self.animTime, -new_o1 )
     self.__resetDisplayRange(old_o1, new_o1)
     if self._full:
         self.invoke('Fix Scroll', -self.o1 / self._full)
Beispiel #15
0
 def onSlideTo(self, x, y, flag):
     self.thumbStart = clamp(
         self.__start, (y - self.thumb.height / 2) if self.vertical else
         (x - self.thumb.width / 2), self.__end)
     if self.snap > 0:
         self.__updateValue()
         self.__updateThumbPos()
     else:
         self._thumbStartAnim.ForceAssign(int(self.thumbStart))
         self.__updateValue()
     self.invoke('Slide To', self.__value)
Beispiel #16
0
 def onKey(self, key):
     if self.vertical and (key == 'UP'
                           or key == 'DOWN') or not self.vertical and (
                               key == 'LEFT' or key == 'RIGHT'):
         interval = float(self.valueRange[1] - self.valueRange[0]) / 10
         if key == 'UP' or key == 'LEFT':
             interval = -interval
         self.value = clamp(self.valueRange[0], self.value + interval,
                            self.valueRange[1])
         return True
     return super(Slider, self).onKey(key)
Beispiel #17
0
 def onSize(self):
     self.onCellSize()
     
     # full size (self._full) and view size (self.width)
     self._full = (self.cellSize + self.cellMargin) * len(self._items) + self.cellMargin
     
     #
     old_o1 = -self.o1.QueryValue()
     if self._full > self.viewSize:
         new_o1 = clamp( 0, old_o1, max(self._full - self.viewSize, self.viewSize) )
     else:
         new_o1 = 0
     self.o1.Reset( self.animTime, -new_o1 )
     self.__resetDisplayRange(old_o1, new_o1)
     if self._full:
         self.invoke('Fix Scroll', -self.o1 / self._full)
Beispiel #18
0
    def onSize(self):
        self.onCellSize()

        # full size (self._full) and view size (self.width)
        self._full = (self.cellSize + self.cellMargin) * len(
            self._items) + self.cellMargin

        #
        old_o1 = -self.o1.QueryValue()
        if self._full > self.viewSize:
            new_o1 = clamp(0, old_o1,
                           max(self._full - self.viewSize, self.viewSize))
        else:
            new_o1 = 0
        self.o1.Reset(self.animTime, -new_o1)
        self.__resetDisplayRange(old_o1, new_o1)
        if self._full:
            self.invoke('Fix Scroll', -self.o1 / self._full)
Beispiel #19
0
 def moveToFocus(self, anim = True):
     '''
     move focus item to center
     '''
     #prevent invalid offset when list item is less than view
     old_o1 = -self.o1.QueryValue()
     o1 = 0
     if self.cellSize * len(self._items) <= self.viewSize:
         o1 = 0
         if anim:
             self.o1.Reset( self.animTime, 0 )
         else:
             self.o1.Assign( 0 )
     else:
         o1 = (self.cellSize + self.cellMargin) * self.focusIdx - (self.viewSize-self.cellSize-self.cellMargin) / 2
         o1 = clamp(0, o1, self._full - self.viewSize)
         if anim:
             self.o1.Reset( self.animTime, -o1 )
         else:
             self.o1.Assign( -o1 )
     #self.o1 = -o1
     self.__resetDisplayRange(old_o1, o1)
     if self._full:
         self.invoke('Fix Scroll', -self.o1 / self._full)
Beispiel #20
0
 def __getThumbSize(self):
     if self.vertical:
         size = self.height
     else:
         size = self.width
     return clamp(self.thumbMinSize, self.pageSize * size, size)
Beispiel #21
0
 def onSlideMove(self, x, y):
     self.thumbStart = clamp(self.__start, self.__capPos + (y if self.vertical else x), self.__end)
     self._thumbStartAnim.ForceAssign(int(self.thumbStart))
     if self.snap == 0:
         self.__updateValue()
Beispiel #22
0
 def __getThumbSize(self):
     if self.vertical:
         size = self.height
     else:
         size = self.width
     return clamp(self.thumbMinSize, self.pageSize * size, size)
Beispiel #23
0
 def fixScroll(self, value):
     self.__offset = clamp(0, value, self.maxOffset)
     self.__animScroll(self.thumbStart)
Beispiel #24
0
 def onScroll(self, offset):        
     view = self.height if self.orientation == 'Vertical' else self.width
     full = self.fullSize
     if full > view:
         offset = clamp(0, offset, float(full - view) / full)
         self.scrollOffset.Reset(0.3, full * offset)
Beispiel #25
0
 def __fixScroll(self):
     offset = clamp(0, self.__offset, self.maxOffset)
     if offset != self.__offset:
         self.__offset = offset
         self.__onChangeOffset()
         self.__animScroll(self.thumbStart)
Beispiel #26
0
 def onSizeMove(self, x, y):
     self.width = clamp(self.minSize[0], self.__capWidth + x, self.parent.width)
     self.height = clamp(self.minSize[1], self.__capHeight + y, self.parent.height)
Beispiel #27
0
 def onPageDown(self):
     self.__offset = clamp(0, self.__offset + self.pageSize, self.maxOffset)
     self.__onChangeOffset()
     self.__animScroll(self.thumbStart)
Beispiel #28
0
 def onScroll(self, offset):
     view = self.height if self.orientation == 'Vertical' else self.width
     full = self.fullSize
     if full > view:
         offset = clamp(0, offset, float(full - view) / full)
         self.scrollOffset.Reset(0.3, full * offset)
Beispiel #29
0
 def fixScroll(self, value):
     self.__offset = clamp(0, value, self.maxOffset)
     self.__animScroll(self.thumbStart)
Beispiel #30
0
 def onPageDown(self):
     self.__offset = clamp(0, self.__offset + self.pageSize, self.maxOffset)
     self.__onChangeOffset()
     self.__animScroll(self.thumbStart)
Beispiel #31
0
 def relayout(self, *argv):
     super(PopupMenu, self).relayout(*argv)
     window = self.window
     if window:
         self.xy = clamp(0, self.left, window.width - self.width), clamp(
             0, self.top, window.height - self.height)
Beispiel #32
0
 def relayout(self, *argv):
     super(PopupMenu, self).relayout(*argv)
     window = self.window
     if window:
         self.xy = clamp(0, self.left, window.width - self.width), clamp(0, self.top, window.height - self.height)
Beispiel #33
0
 def setScroll(self, value):
     self.__offset = clamp(0, value, self.maxOffset)
     self.__onChangeOffset()
     self.__animScroll(self.thumbStart)
Beispiel #34
0
 def setScroll(self, value):
     self.__offset = clamp(0, value, self.maxOffset)
     self.__onChangeOffset()
     self.__animScroll(self.thumbStart)
Beispiel #35
0
 def __focus(self, idx):
     self.focusIdx = clamp(0, idx, len(self._items)-1 )
     self.moveToFocus()
Beispiel #36
0
 def __focus(self, idx):
     self.focusIdx = clamp(0, idx, len(self._items) - 1)
     self.moveToFocus()
Beispiel #37
0
 def onSizeMove(self, x, y):
     self.width = clamp(self.minSize[0], self.__capWidth + x,
                        self.parent.width)
     self.height = clamp(self.minSize[1], self.__capHeight + y,
                         self.parent.height)
Beispiel #38
0
 def __fixScroll(self):
     offset = clamp(0, self.__offset, self.maxOffset)
     if offset != self.__offset:
         self.__offset = offset
         self.__onChangeOffset()
         self.__animScroll(self.thumbStart)