コード例 #1
0
    def cascade(self, r):
        """
        Moves all the windows in a cascade-like fashion.

        Redisplays all tileable windows owned by the desk top in cascaded
        format. The first tileable window in Z-order (the window "in back") is
        zoomed to fill the desk top, and each succeeding window fills a region
        beginning one line lower and one space further to the right than the
        one before. The active window appears "on top" as the smallest window.

        :param r: Rectangle to cascade into
        """
        minSize = Point()
        maxSize = Point()
        self.cascadeNum = 0

        self.forEach(self.doCount, None)
        if self.cascadeNum > 0:
            self.lastView.sizeLimits(minSize, maxSize)
            if ((minSize.x > r.bottomRight.x - r.topLeft.x - self.cascadeNum)
                    or
                (minSize.y > r.bottomRight.y - r.topLeft.y - self.cascadeNum)):
                self.tileError()
            else:
                self.cascadeNum -= 1
                self.lock()
                try:
                    self.forEach(self.doCascade, r)
                finally:
                    self.unlock()
コード例 #2
0
    def __dragWindow(self, event, mode):
        minBounds = Point()
        maxBounds = Point()

        limits = self.owner.owner.getExtent()
        self.owner.sizeLimits(minBounds, maxBounds)
        self.owner.dragView(event, self.owner.dragMode | mode, limits, minBounds, maxBounds)
        self.clearEvent(event)
コード例 #3
0
ファイル: scroller.py プロジェクト: gabbpuy/vindauga
    def __init__(self, bounds, hScrollBar, vScrollBar):
        super().__init__(bounds)
        self._drawLock = 0
        self._drawFlag = False
        self._hScrollBar = hScrollBar
        self._vScrollBar = vScrollBar

        self._limit = Point()
        self.delta = Point()

        self.options |= ofSelectable
        self.eventMask |= evBroadcast
コード例 #4
0
    def zoom(self):
        minSize = Point()
        maxSize = Point()

        self.sizeLimits(minSize, maxSize)

        if self.size != maxSize:
            self.zoomRect = self.getBounds()
            r = Rect(0, 0, maxSize.x, maxSize.y)
            self.locate(r)
        else:
            self.locate(self.zoomRect)
コード例 #5
0
ファイル: scroll_group.py プロジェクト: gabbpuy/vindauga
    def __init__(self, bounds, hScrollBar, vScrollBar):
        super().__init__(bounds)
        self.hScrollBar = hScrollBar
        self.vScrollBar = vScrollBar
        self.background = None
        self.eventMask |= evBroadcast
        self.delta = Point(0, 0)
        self.limit = Point(0, 0)

        self.background = self.initBackground(self.getExtent())
        if self.background:
            self.background.growMode = gfGrowHiX | gfGrowHiY
            self.insert(self.background)
コード例 #6
0
ファイル: editor.py プロジェクト: gabbpuy/vindauga
    def _handleMouseEvent(self, event, selectMode):
        if event.mouse.eventFlags & meDoubleClick:
            selectMode |= smDouble
        done = False
        while not done:
            self.lock()

            if event.what == evMouseAuto:
                mouse = self.makeLocal(event.mouse.where)
                d = Point(self.delta.x, self.delta.y)

                if mouse.x < 0:
                    d.x -= 1
                if mouse.x >= self.size.x:
                    d.x += 1

                if mouse.y < 0:
                    d.y -= 1

                if mouse.y >= self.size.y:
                    d.y += 1

                self.scrollTo(d.x, d.y)

            self.setCurPtr(self.getMousePtr(event.mouse.where), selectMode)
            selectMode |= smExtend
            self.unlock()

            done = (not self.mouseEvent(event, evMouseMove + evMouseAuto))
コード例 #7
0
ファイル: scroll_group.py プロジェクト: gabbpuy/vindauga
    def scrollDraw(self):
        d = Point(0, 0)
        d.x = self.hScrollBar.value if self.hScrollBar else 0
        d.y = self.vScrollBar.value if self.vScrollBar else 0

        if d.x != self.delta.x or d.y != self.delta.y:
            info = self.ScrollInfo()
            info.delta = self.delta - d
            info.ignore = self.background
            self.lock()
            try:
                self.forEach(self.doScroll, info)
                self.delta = d
            finally:
                self.unlock()
            self.drawView()
コード例 #8
0
ファイル: editor.py プロジェクト: gabbpuy/vindauga
    def __init__(self, bounds, hScrollBar, vScrollBar, indicator, bufSize):
        super().__init__(bounds)

        self.delta = Point(0, 0)
        self.limit = Point(0, 0)
        self.curPos = Point(0, 0)
        self.hScrollBar = hScrollBar
        self.vScrollBar = vScrollBar
        self.indicator = indicator

        self.bufSize = bufSize
        self.canUndo = True
        self.selecting = False
        self.overwrite = False
        self.autoIndent = False
        self.isValid = False
        self.modified = False

        self.bufLen = 0
        self.gapLen = 0
        self.selStart = 0
        self.selEnd = 0
        self.curPtr = 0
        self.delCount = 0
        self.insCount = 0
        self.updateFlags = 0
        self.drawPtr = 0
        self.drawLine = 0
        self.lockCount = 0
        self.keyState = 0
        self.editorFlags = 0

        self.findStr = ''
        self.replaceStr = ''
        self.clipboard = None
        self.buffer = None

        self.growMode = gfGrowHiX | gfGrowHiY

        self.options |= ofSelectable
        self.eventMask = evMouseDown | evKeyDown | evCommand | evBroadcast

        self.showCursor()
        self.initBuffer()
        self.setBufLen(0)
        self.isValid = True
        self.clipboard = None
コード例 #9
0
ファイル: scroller.py プロジェクト: gabbpuy/vindauga
    def scrollDraw(self):
        """
        Checks to see if `delta` matches the current positions of the scroll
        bars. If not, `delta` is set to the correct value and `drawView()` is called to
        redraw the scroller.
        """
        d = Point()

        if self._hScrollBar:
            d.x = self._hScrollBar.value
        else:
            d.x = 0

        if self._vScrollBar:
            d.y = self._vScrollBar.value
        else:
            d.y = 0

        if d.x != self.delta.x or d.y != self.delta.y:
            self.setCursor(self.cursor.x + self.delta.x - d.x,
                           self.cursor.y + self.delta.y - d.y)
            self.delta = d
            if self._drawLock:
                self._drawFlag = True
            else:
                self.drawView()
コード例 #10
0
    def __handleMenuAction(self, action, autoSelect, e, result):
        if ((action == MenuAction.doSelect or
             (action == MenuAction.doNothing and autoSelect))
                and (self._current and self._current.name)):
            if not self._current.command:
                if e.what & (evMouseDown | evMouseMove):
                    self.putEvent(e)

                r = self.getItemRect(self._current)
                r.topLeft.x += self.origin.x
                r.topLeft.y = self.origin.y + r.bottomRight.y
                r.bottomRight = Point(self.owner.size.x, self.owner.size.y)

                if self.size.y == 1:
                    r.topLeft.x -= 1

                target = self.__topMenu().newSubView(r, self._current.subMenu,
                                                     self)
                result = self.owner.execView(target)
                self.destroy(target)
            elif action == MenuAction.doSelect:
                result = self._current.command
        return result
コード例 #11
0
ファイル: test_Point.py プロジェクト: gabbpuy/vindauga
 def test_sub(self):
     x = Point(1, 1)
     y = Point(2, 2)
     z = y - x
     assert z == x
コード例 #12
0
ファイル: test_Point.py プロジェクト: gabbpuy/vindauga
 def test_add(self):
     x = Point(1, 1)
     y = Point(2, 2)
     z = x + y
     assert z == Point(3, 3)
コード例 #13
0
ファイル: test_Point.py プロジェクト: gabbpuy/vindauga
 def test_Neq_tuple(self):
     x = Point(1, 2)
     assert x != (2, 2)
コード例 #14
0
ファイル: test_Point.py プロジェクト: gabbpuy/vindauga
 def test_Neq(self):
     x = Point(1, 2)
     y = Point(2, 2)
     assert x != y
コード例 #15
0
ファイル: test_Point.py プロジェクト: gabbpuy/vindauga
 def test_constructor(self):
     x = Point()
     y = Point(1, 1)
コード例 #16
0
from vindauga.constants.grow_flags import gfGrowAll, gfGrowRel
from vindauga.constants.event_codes import evCommand, evKeyDown, evBroadcast
from vindauga.constants.keys import kbTab, kbShiftTab
from vindauga.constants.option_flags import ofSelectable, ofTopSelect, ofPostProcess
from vindauga.constants.state_flags import sfShadow, sfActive, sfSelected, sfModal
from vindauga.types.command_set import CommandSet
from vindauga.types.group import Group
from vindauga.types.palette import Palette
from vindauga.types.point import Point
from vindauga.types.rect import Rect
from vindauga.types.view import View
from .frame import Frame
from .scroll_bar import ScrollBar

logger = logging.getLogger('vindauga.widgets.window')
minWinSize = Point(16, 6)


class Window(Group):
    """
    A `Window` object is a specialized group that typically owns a `Frame`
    object, an interior `Scroller` object, and one or two `ScrollBar` objects.
    These attached subviews provide the "visibility" to the `Window` object.
    """

    name = 'Window'
    cpBlueWindow = '\x08\x09\x0A\x0B\x0C\x0D\x0E\x0F'
    cpCyanWindow = '\x10\x11\x12\x13\x14\x15\x16\x17'
    cpGrayWindow = '\x18\x19\x1A\x1B\x1C\x1D\x1E\x1F'

    def __init__(self, bounds, title, windowNumber):
コード例 #17
0
 def __init__(self, bounds):
     super().__init__(bounds)
     self._location = Point()
     self._modified = False
     self.growMode = gfGrowLoY | gfGrowHiY
コード例 #18
0
ファイル: test_Point.py プロジェクト: gabbpuy/vindauga
 def test_iadd(self):
     x = Point(1, 1)
     x += Point(2, 2)
     assert x == Point(3, 3)
コード例 #19
0
ファイル: test_Point.py プロジェクト: gabbpuy/vindauga
 def test_isub(self):
     x = Point(2, 2)
     x -= Point(1, 1)
     assert x == Point(1, 1)
コード例 #20
0
    def handleEvent(self, event):
        """
        First calls `super().handleEvent()`, and then handles events
        specific to a `Window` as follows:

        * The following `evCommand` events are handled if the `flags`
          data member permits that operation:
          * `cmResize` (move or resize the window using the `dragView()`
            member function);
          * `cmClose` (close the window by creating a `cmCancel` event);
          * `cmZoom` (zoom the window using the `zoom()` member function).
        * `evKeyDown` events with a keyCode value of `kbTab` or `kbShiftTab`
          are handled by selecting the next or previous selectable subview (if
          any).
        * An `evBroadcast` event with a command value of `cmSelectWindowNum`
          is handled by selecting the window if the `event.infoPtr' data
          member is equal to `number` data member.

        :param event: Event to be handled
        """
        super().handleEvent(event)

        if event.what == evCommand:
            emc = event.message.command

            if emc == cmResize:
                if self.flags & (wfMove | wfGrow):
                    minBounds = Point()
                    maxBounds = Point()
                    limits = self.owner.getExtent()
                    self.sizeLimits(minBounds, maxBounds)
                    self.dragView(
                        event,
                        self.dragMode | (self.flags & (wfMove | wfGrow)),
                        limits, minBounds, maxBounds)
                    self.clearEvent(event)
            if emc == cmClose:
                if self.flags & wfClose and event.message.infoPtr in {
                        None, self
                }:
                    self.clearEvent(event)
                    if not self.state & sfModal:
                        self.close()
                    else:
                        event.what = evCommand
                        event.message.command = cmCancel
                        self.putEvent(event)
                        self.clearEvent(event)
            if emc == cmZoom:
                if self.flags & wfZoom and event.message.infoPtr in {
                        None, self
                }:
                    self.zoom()
                    self.clearEvent(event)
        elif event.what == evKeyDown:
            kc = event.keyDown.keyCode
            if kc == kbTab:
                self.focusNext(False)
                self.clearEvent(event)
            elif kc == kbShiftTab:
                # TODO: Modern terminals send \e[Z for shift tab
                self.focusNext(True)
                self.clearEvent(event)
        elif (event.what == evBroadcast
              and event.message.command == cmSelectWindowNum
              and event.message.infoPtr == self.number
              and (self.options & ofSelectable)):
            self.select()
            self.clearEvent(event)
コード例 #21
0
ファイル: test_Rect.py プロジェクト: gabbpuy/vindauga
 def test_contains(self):
     r = Rect(0, 0, 4, 4)
     p = Point(1, 2)
     assert p in r
コード例 #22
0
    def draw(self):
        """
        Draws the frame with color attributes and icons appropriate to the
        current state flags: active, inactive, being dragged. Adds zoom, close
        and resize icons depending on the owner window's flags. Adds the title,
        if any, from the owning window's title data member.

        Active windows are drawn with a double-lined frame and any icons;
        inactive windows are drawn with a single-lined frame and no icons.
        """
        f = 0
        drawable = DrawBuffer()
        if self.state & sfDragging:
            cFrame = 0x0505
            cTitle = 0x0005
        elif not (self.state & sfActive):
            cFrame = 0x0101
            cTitle = 0x0002
        else:
            cFrame = 0x0503
            cTitle = 0x0004
            f = 9

        cFrame = self.getColor(cFrame)
        cTitle = self.getColor(cTitle)

        width = self.size.x
        lineLength = width - 10

        if self.owner.flags & (wfClose | wfZoom):
            lineLength -= 6

        self.__frameLine(drawable, 0, f, cFrame & 0xFF)

        if self.owner.number != wnNoNumber and self.owner.number < 10:
            lineLength -= 4
            if self.owner.flags & wfZoom:
                i = 7
            else:
                i = 3
            drawable.putChar(width - i, chr(self.owner.number + ord('0')))

        if self.owner:
            title = self.owner.getTitle(lineLength)
            if title:
                lineLength = min(len(title), width - 10)  # min(nameLength(title), width - 10)
                lineLength = max(lineLength, 0)
                i = (width - lineLength) >> 1
                drawable.putChar(i - 1, ' ')
                drawable.moveBuf(i, title, cTitle, lineLength)
                drawable.putChar(i + lineLength, ' ')

        if self.state & sfActive:
            if self.owner.flags & wfClose:
                drawable.moveCStr(2, self.closeIcon, cFrame)
            if self.owner.flags & wfZoom:
                minSize = Point()
                maxSize = Point()
                self.owner.sizeLimits(minSize, maxSize)
                if self.owner.size == maxSize:
                    drawable.moveCStr(width - 5, self.unZoomIcon, cFrame)
                else:
                    drawable.moveCStr(width - 5, self.zoomIcon, cFrame)

        self.writeLine(0, 0, self.size.x, 1, drawable)

        for i in range(1, self.size.y - 1):
            self.__frameLine(drawable, i, f + 3, cFrame)
            self.writeLine(0, i, self.size.x, 1, drawable)

        self.__frameLine(drawable, self.size.y - 1, f + 6, cFrame)

        if self.state & sfActive:
            if self.owner.flags & wfGrow:
                drawable.moveCStr(width - 2, self.dragIcon, cFrame)

        self.writeLine(0, self.size.y - 1, self.size.x, 1, drawable)
コード例 #23
0
ファイル: test_Point.py プロジェクト: gabbpuy/vindauga
 def test_Eq(self):
     x = Point(1, 1)
     y = Point(1, 1)
     assert x == y
コード例 #24
0
ファイル: test_Point.py プロジェクト: gabbpuy/vindauga
 def test_Eq_tuple(self):
     x = Point(1, 1)
     assert x == (1, 1)