Ejemplo n.º 1
0
    def getRect(bounds, menu):
        w = 10
        h = 2
        r = Rect(bounds.topLeft.x, bounds.topLeft.y, bounds.bottomRight.x,
                 bounds.bottomRight.y)

        if menu:
            for p in menu.items:
                h += 1
                if not p.name:
                    continue
                nameLen = nameLength(p.name) + 6
                if not p.command:
                    nameLen += 3
                elif p.param:
                    nameLen += (nameLength(p.param) + 2)
                w = max(nameLen, w)

            if (r.topLeft.x + w) < r.bottomRight.x:
                r.bottomRight.x = r.topLeft.x + w
            else:
                r.topLeft.x = r.bottomRight.x - w

            if (r.topLeft.y + h) < r.bottomRight.y:
                r.bottomRight.y = r.topLeft.y + h
            else:
                r.topLeft.y = r.bottomRight.y - h
        return r
Ejemplo n.º 2
0
 def __itemMouseIsIn(self, mouse):
     if mouse.y != 0:
         return None
     i = 0
     for item in self._items:
         if item.text:
             k = i + nameLength(item.text) + 2
             if i <= mouse.x < k:
                 return item
             i = k
     return None
Ejemplo n.º 3
0
    def __init__(self, wildCard, title, inputLabel, options, histId):
        super().__init__(Rect(15, 1, 64, 20), title)

        self.directory = ''
        self.options |= ofCentered
        self.wildCard = wildCard
        self.filename = FileInputLine(Rect(3, 3, 31, 4), 79)
        self.filename.setData(self.wildCard)
        self.insert(self.filename)

        self.insert(Label(Rect(2, 2, 3 + nameLength(inputLabel), 3), inputLabel, self.filename))
        self.insert(History(Rect(31, 3, 34, 4), self.filename, histId))

        sb = ScrollBar(Rect(3, 14, 34, 15))
        self.insert(sb)
        self.fileList = FileList(Rect(3, 6, 34, 14), sb)
        self.insert(self.fileList)
        self.insert(Label(Rect(2, 5, 8, 6), self.filesText, self.fileList))

        opt = bfDefault
        r = Rect(35, 3, 46, 5)

        if options & fdOpenButton:
            self.insert(Button(r, self.openText, cmFileOpen, opt))
            opt = bfNormal
            r.topLeft.y += 3
            r.bottomRight.x += 3

        if options & fdOKButton:
            self.insert(Button(r, self.okText, cmFileOpen, opt))
            opt = bfNormal
            r.topLeft.y += 3
            r.bottomRight.y += 3

        if options & fdReplaceButton:
            self.insert(Button(r, self.replaceText, cmFileReplace, opt))
            r.topLeft.y += 3
            r.bottomRight.y += 3

        if options & fdClearButton:
            self.insert(Button(r, self.clearText, cmFileClear, opt))
            r.topLeft.y += 3
            r.bottomRight.y += 3

        self.insert(FileInfoPane(Rect(1, 16, 48, 18)))

        self.selectNext(False)
        if not (options & fdNoLoadDir):
            self._readCurrentDirectory()
Ejemplo n.º 4
0
    def __column(self, item):
        if item < self.size.y:
            return 0
        width = 0
        col = -6
        cellLength = 0
        for i in range(item + 1):
            if i % self.size.y == 0:
                col += width + 6
                width = 0

            if i < len(self._strings):
                cellLength = nameLength(self._strings[i])

            if cellLength > width:
                width = cellLength
        return col
Ejemplo n.º 5
0
    def getItemRect(self, item):
        """
        Returns the rectangle occupied by the given menu item. It can be used
        with `mouseInView()` to determine if a mouse click has occurred on
        a given menu selection.

        :param item: Menu item to find
        :return: `Rect` of the `Menu` item
        """
        r = Rect(1, 0, 1, 1)
        for p in self.menu.items:
            r.topLeft.x = r.bottomRight.x
            if p.name:
                r.bottomRight.x += (nameLength(p.name) + 2)
            if p is item:
                return r
        return r
Ejemplo n.º 6
0
    def __drawSelect(self, selected):
        b = DrawBuffer()
        cNormal = self.getColor(0x0301)
        cSelect = self.getColor(0x0604)
        cNormDisabled = self.getColor(0x0202)
        cSelDisabled = self.getColor(0x0505)

        b.moveChar(0, ' ', cNormal, self.size.x)
        i = 0

        textItems = (item for item in self._items if item.text)
        for item in textItems:
            textLen = nameLength(item.text)
            if i + textLen < self.size.x:
                if self.commandEnabled(item.command):
                    if item is selected:
                        color = cSelect
                    else:
                        color = cNormal
                else:
                    if item is selected:
                        color = cSelDisabled
                    else:
                        color = cNormDisabled

                b.moveChar(i, ' ', color, 1)
                b.moveCStr(i + 1, item.text, color)
                b.moveChar(i + textLen + 1, ' ', color, 1)
            i += textLen + 2

        if i < self.size.x - 2:
            hintBuf = self.hint(self.helpCtx)
            if hintBuf:
                b.moveStr(i, self.hintSeparator, cNormal)
                i += len(self.hintSeparator)
                if len(hintBuf) + i > self.size.x:
                    hintBuf = hintBuf[:self.size.x - i]

                b.moveStr(i, hintBuf, cNormal)
                i += len(hintBuf)

        self.writeLine(0, 0, self.size.x, 1, b)
Ejemplo n.º 7
0
    def __drawTitle(self, b, s, i, cButton, down):
        if self._flags & bfLeftJust:
            titlePosition = 0
        else:
            titlePosition = (s - nameLength(self.title)) // 2

            if titlePosition < 0:
                titlePosition = 1

        b.moveCStr(i + titlePosition, self.title, cButton)

        if self.showMarkers and not down:
            if self.state & sfSelected:
                scOff = 0
            elif self._amDefault:
                scOff = 2
            else:
                scOff = 4

            b.putChar(0, SPECIAL_CHARS[scOff])
            b.putChar(s, SPECIAL_CHARS[scOff + 1])
Ejemplo n.º 8
0
    def draw(self):
        """
        Draws the menu bar with the default palette. The `MenuItem.name`
        and `MenuItem.disabled` data members of each `MenuItem`
        object in the menu linked list are read to give the menu legends in
        the correct colors.

        The current (selected) item is highlighted.
        """
        b = DrawBuffer()
        cNormal = self.getColor(0x0301)
        b.moveChar(0, ' ', cNormal, self.size.x)
        if self.menu and self.menu.items:
            x = 1
            items = (item for item in self.menu.items if item.name)
            for p in items:
                nameLen = nameLength(p.name)
                if x + nameLen < self.size.x:
                    color = self._chooseColor(p)
                    b.moveChar(x, ' ', color, 1)
                    b.moveCStr(x + 1, p.name, color)
                    b.moveChar(x + nameLen + 1, ' ', color, 1)
                x += (nameLen + 2)
        self.writeBuf(0, 0, self.size.x, 1, b)