File: selection.py

package info (click to toggle)
wxpython3.0 3.0.2.0%2Bdfsg-4
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 482,760 kB
  • ctags: 518,293
  • sloc: cpp: 2,127,226; python: 294,045; makefile: 51,942; ansic: 19,033; sh: 3,013; xml: 1,629; perl: 17
file content (44 lines) | stat: -rw-r--r-- 1,307 bytes parent folder | download | duplicates (10)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# 12/14/2003 - Jeff Grimmett (grimmtooth@softhome.net)
#
# o 2.5 compatability update.
#

def RestOfLine(sx, width, data, bool):
    if len(data) == 0 and sx == 0:
        return [('', bool)]
    if sx >= len(data):
        return []
    return [(data[sx:sx+width], bool)]

def Selection(SelectBegin,SelectEnd, sx, width, line, data):
    if SelectEnd is None or SelectBegin is None:
        return RestOfLine(sx, width, data, False)
    (bRow, bCol) = SelectBegin
    (eRow, eCol) = SelectEnd
    if (eRow < bRow):
        (bRow, bCol) = SelectEnd
        (eRow, eCol) = SelectBegin
    if (line < bRow or eRow < line):
        return RestOfLine(sx, width, data, False)
    if (bRow < line and line < eRow):
        return RestOfLine(sx, width, data, True)
    if (bRow == eRow) and (eCol < bCol):
        (bCol, eCol) = (eCol, bCol)
    # selection either starts or ends on this line
    end = min(sx+width, len(data))
    if (bRow < line):
        bCol = 0
    if (line < eRow):
        eCol = end
    pieces = []
    if (sx < bCol):
        if bCol <= end:
            pieces += [(data[sx:bCol], False)]
        else:
            return [(data[sx:end], False)]
    pieces += [(data[max(bCol,sx):min(eCol,end)], True)]
    if (eCol < end):
        pieces += [(data[eCol:end], False)]
    return pieces