From 4623c47137d2b389179eda305512d8ffb91270f6 Mon Sep 17 00:00:00 2001 From: chrys87 Date: Mon, 19 Dec 2016 16:04:21 +0100 Subject: [PATCH] Update wrapWord.py --- play zone/wrapWord.py | 45 ++++++++++++++++++++++++++++++++++--------- 1 file changed, 36 insertions(+), 9 deletions(-) diff --git a/play zone/wrapWord.py b/play zone/wrapWord.py index 556c0fd2..8b3a4247 100755 --- a/play zone/wrapWord.py +++ b/play zone/wrapWord.py @@ -32,7 +32,8 @@ def getPrevWord(currX,currY, currText): lineBreak = True else: x -= 1 - x, y, currWord, endOfScreen, lineBreak = getCurrentWord(x,y,currText) + lineBreakCurrWord = lineBreak or lineBreakCurrWord + x, y, currWord, endOfScreen, lineBreak = getCurrentWord(x,y,currText) lineBreak = lineBreak or lineBreakCurrWord return x, y, currWord, endOfScreen, lineBreak @@ -74,29 +75,54 @@ def getCurrentWord(currX,currY, currText): for d in string.whitespace: delimiterPos = currWord.find(d) if delimiterPos != -1: - currWord = currWord[:delimiterPos] + currWord = currWord[:delimiterPos] + return x, y, currWord, endOfScreen, lineBreak return currX, currY, '', False, False def getNextWord(currX,currY, currText): - lineBreak = False + lineBreak = False endOfScreen = False if currText == '': return -1, -1, '', endOfScreen, lineBreak if currText.strip(string.punctuation +"ยง " + string.whitespace) == '': - return currX, currY, '', endOfScreen, lineBreak - x, y, currWord, endOfScreen, lineBreak = getCurrentWord(currX,currY,currText) - if endOfScreen: - return x, y, currWord, endOfScreen, lineBreak + return currX, currY, '', endOfScreen, lineBreak + x = currX + y = currY + currWord = '' wrappedLines = currText.split('\n') currLine = wrappedLines[y] Found = False while(not Found): - currWord = 'next' + if not Found: + if x + 1 > len( currLine ) - 1: + if y + 1 > len( wrappedLines ) - 1: + lineBreak = False + endOfScreen = True + return currX, currY, '', endOfScreen, lineBreak + else: + y += 1 + currLine = wrappedLines[y] + x = 0 + lineBreak = True + else: + x += 1 + if not currLine[x] in string.whitespace: + if x == 0: + Found = True + else: + if currLine[x - 1] in string.whitespace: + Found = True + if Found: + currWord = currLine[x:] + for d in string.whitespace: + delimiterPos = currWord.find(d) + if delimiterPos != -1: + currWord = currWord[:delimiterPos] return x, y, currWord, endOfScreen, lineBreak return currX, currY, '', False, False - + data = """das ist ein test lol das ist ein test l @@ -113,3 +139,4 @@ x = 3 y = 0 x, y, currWord, endOfScreen, lineBreak = getCurrentWord(x,y,data) print(x,y,currWord) +