def processKeyDown(self, evt): if not self.editable: return Widget.processKeyDown(self, evt) # process keys if evt.key == pygame.K_BACKSPACE: self.wrapDeleteSelection(self._processBackspace, evt, deleteOnly=True) elif evt.key == pygame.K_DELETE: self.wrapDeleteSelection(self._processDelete, evt, deleteOnly=True) elif evt.key == pygame.K_ESCAPE: self.app.setFocus(None) elif evt.key == pygame.K_LEFT: self.wrapSelect(self._processLeft, evt) elif evt.key == pygame.K_RIGHT: self.wrapSelect(self._processRight, evt) elif evt.key == pygame.K_UP: self.wrapSelect(self._processUp, evt) elif evt.key == pygame.K_DOWN: self.wrapSelect(self._processDown, evt) elif evt.key == pygame.K_TAB: pass elif evt.key == pygame.K_HOME: self.wrapSelect(self._processHome, evt) elif evt.key == pygame.K_END: self.wrapSelect(self._processEnd, evt) elif evt.key == pygame.K_RETURN: self.wrapDeleteSelection(self._processReturn, evt) elif hasattr(evt, 'unicode') and evt.unicode: self.wrapDeleteSelection(self._processUnicode, evt) elif evt.key in MAPPING: self.wrapDeleteSelection(self._processNumKeyboard, evt) return Widget.processKeyDown(self, Const.NoEvent)
def processKeyDown(self, evt): if evt.key == K_BACKSPACE: if self.cursorPos > 0: self.text = '%s%s' % (self.text[:self.cursorPos - 1], self.text[self.cursorPos:]) self.cursorPos -= 1 elif evt.key == K_DELETE: if self.cursorPos < len(self.text): self.text = '%s%s' % (self.text[:self.cursorPos], self.text[self.cursorPos + 1:]) elif evt.key == K_RETURN or evt.key == K_KP_ENTER: self.app.setFocus(None) elif evt.key == K_ESCAPE: self.app.setFocus(None) elif evt.key == K_HOME: self.cursorPos = 0 elif evt.key == K_END: self.cursorPos = len(self.text) elif evt.key == K_LEFT: if self.cursorPos > 0: self.cursorPos -= 1 elif evt.key == K_RIGHT: if self.cursorPos < len(self.text): self.cursorPos += 1 elif evt.key == K_TAB: pass elif (evt.key == K_v and evt.mod & KMOD_CTRL) or (evt.key == K_INSERT and evt.mod & KMOD_SHIFT): clipboardLines = clipboard.read() clipboardText = ''.join(clipboardLines).replace('\t', ' ') if self.text: self.text = u'%s%s%s' % (self.text[:self.cursorPos], clipboardText, self.text[self.cursorPos:]) else: self.text = clipboardText self.cursorPos += len(clipboardText) elif hasattr(evt, 'unicode') and evt.unicode: if os.name == "nt": # TODO this is ugly windows only hack char = unicode(chr(ord(evt.unicode)), 'cp1250') else: char = evt.unicode if self.text: self.text = u'%s%c%s' % (self.text[:self.cursorPos], char, self.text[self.cursorPos:]) else: self.text = char self.cursorPos += 1 elif mapping.has_key(evt.key): self.text = u'%s%c%s' % (self.text[:self.cursorPos], mapping[evt.key], self.text[self.cursorPos:]) self.cursorPos += 1 if (self.reportValueChanged): self.processAction("onValueChanged") return Widget.processKeyDown(self, NoEvent)
def processKeyDown(self, evt): if evt.key == K_BACKSPACE: if self.cursorPos > 0: self.text = '%s%s' % (self.text[:self.cursorPos - 1], self.text[self.cursorPos:]) self.cursorPos -= 1 elif evt.key == K_DELETE: if self.cursorPos < len(self.text): self.text = '%s%s' % (self.text[:self.cursorPos], self.text[self.cursorPos + 1:]) elif evt.key == K_RETURN or evt.key == K_KP_ENTER: self.app.setFocus(None) elif evt.key == K_ESCAPE: self.app.setFocus(None) elif evt.key == K_HOME: self.cursorPos = 0 elif evt.key == K_END: self.cursorPos = len(self.text) elif evt.key == K_LEFT: if self.cursorPos > 0: self.cursorPos -= 1 elif evt.key == K_RIGHT: if self.cursorPos < len(self.text): self.cursorPos += 1 elif evt.key == K_TAB: pass elif (evt.key == K_v and evt.mod & KMOD_CTRL) or (evt.key == K_INSERT and evt.mod & KMOD_SHIFT): clipboardLines = clipboard.read() clipboardText = ''.join(clipboardLines).replace('\t', ' ') if self.text: self.text = u'%s%s%s' % ( self.text[:self.cursorPos], clipboardText, self.text[self.cursorPos:] ) else: self.text = clipboardText self.cursorPos += len(clipboardText) elif hasattr(evt, 'unicode') and evt.unicode: if os.name == "nt": # TODO this is ugly windows only hack char = unicode(chr(ord(evt.unicode)), 'cp1250') else: char = evt.unicode if self.text: self.text = u'%s%c%s' % ( self.text[:self.cursorPos], char, self.text[self.cursorPos:] ) else: self.text = char self.cursorPos += 1 elif mapping.has_key(evt.key): self.text = u'%s%c%s' % ( self.text[:self.cursorPos], mapping[evt.key], self.text[self.cursorPos:] ) self.cursorPos += 1 if (self.reportValueChanged): self.processAction("onValueChanged") return Widget.processKeyDown(self, NoEvent)
def processKeyDown(self, evt): try: # this is done to translate keypad codes to normal ones as # we don't have any special meaning for these evt.key = mapping[evt.key] except KeyError: pass if evt.key == pygame.K_BACKSPACE: if self.cursorPos > 0: self.text = '%s%s' % (self.text[:self.cursorPos - 1], self.text[self.cursorPos:]) self.cursorPos -= 1 elif evt.key == pygame.K_DELETE: if self.cursorPos < len(self.text): self.text = '%s%s' % (self.text[:self.cursorPos], self.text[self.cursorPos + 1:]) elif evt.key == pygame.K_RETURN: self.app.setFocus(None) elif evt.key == pygame.K_ESCAPE: self.app.setFocus(None) elif evt.key == pygame.K_HOME: self.cursorPos = 0 elif evt.key == pygame.K_END: self.cursorPos = len(self.text) elif evt.key == pygame.K_LEFT: if self.cursorPos > 0: self.cursorPos -= 1 elif evt.key == pygame.K_RIGHT: if self.cursorPos < len(self.text): self.cursorPos += 1 elif evt.key == pygame.K_TAB: pass elif hasattr(evt, 'unicode') and evt.unicode: # TODO this is ugly windows only hack needed for Win 9x and XP # char = unicode(chr(ord(evt.unicode)), 'cp1250') char = evt.unicode if self.text: self.text = u'%s%c%s' % ( self.text[:self.cursorPos], char, self.text[self.cursorPos:] ) else: self.text = char self.cursorPos += 1 if (self.reportValueChanged): self.processAction("onValueChanged") return Widget.processKeyDown(self, Const.NoEvent)
def processKeyDown(self, evt): if evt.key == K_BACKSPACE: if self.cursorPos > 0: self.text = '%s%s' % (self.text[:self.cursorPos - 1], self.text[self.cursorPos:]) self.cursorPos -= 1 elif evt.key == K_DELETE: if self.cursorPos < len(self.text): self.text = '%s%s' % (self.text[:self.cursorPos], self.text[self.cursorPos + 1:]) elif evt.key == K_RETURN: self.app.setFocus(None) elif evt.key == K_ESCAPE: self.app.setFocus(None) elif evt.key == K_HOME: self.cursorPos = 0 elif evt.key == K_END: self.cursorPos = len(self.text) elif evt.key == K_LEFT: if self.cursorPos > 0: self.cursorPos -= 1 elif evt.key == K_RIGHT: if self.cursorPos < len(self.text): self.cursorPos += 1 elif evt.key == K_TAB: pass elif hasattr(evt, 'unicode') and evt.unicode: # TODO this is ugly windows only hack needed for Win 9x and XP # char = unicode(chr(ord(evt.unicode)), 'cp1250') char = evt.unicode if self.text: self.text = u'%s%c%s' % ( self.text[:self.cursorPos], char, self.text[self.cursorPos:] ) else: self.text = char self.cursorPos += 1 elif mapping.has_key(evt.key): self.text = u'%s%c%s' % ( self.text[:self.cursorPos], mapping[evt.key], self.text[self.cursorPos:] ) self.cursorPos += 1 if (self.reportValueChanged): self.processAction("onValueChanged") return Widget.processKeyDown(self, NoEvent)
def processKeyDown(self, evt): if not self.editable: return Widget.processKeyDown(self, evt) # process keys if evt.key == pygame.K_BACKSPACE: if self.selStart != None: self.deleteSelection() elif self.cursorColumn > 0: self.text[self.cursorRow] = u'%s%s' % (self.text[self.cursorRow][:self.cursorColumn - 1], self.text[self.cursorRow][self.cursorColumn:]) self.cursorColumn -= 1 else: if self.cursorRow > 0: self.cursorColumn = len(self.text[self.cursorRow - 1]) self.text[self.cursorRow - 1] = u'%s%s' % (self.text[self.cursorRow - 1], self.text[self.cursorRow]) del self.text[self.cursorRow] self.cursorRow -= 1 elif evt.key == pygame.K_DELETE: if self.selStart != None: self.deleteSelection() elif self.cursorColumn < len(self.text[self.cursorRow]): self.text[self.cursorRow] = u'%s%s' % (self.text[self.cursorRow][:self.cursorColumn], self.text[self.cursorRow][self.cursorColumn + 1:]) elif self.cursorRow < len(self.text) - 1: self.text[self.cursorRow] = u'%s%s' % (self.text[self.cursorRow], self.text[self.cursorRow + 1]) del self.text[self.cursorRow + 1] elif evt.key == pygame.K_ESCAPE: self.app.setFocus(None) elif evt.key == pygame.K_LEFT: if evt.mod & pygame.KMOD_SHIFT: if self.selStart == None: self.selStart = (self.cursorRow,self.cursorColumn) if evt.mod & pygame.KMOD_CTRL: # move one word left # take words on line words = splitter(self.text[self.cursorRow]) if len(words) == 0: #move to previous line if self.cursorRow > 0: self.cursorRow -= 1 words2 = splitter(self.text[self.cursorRow]) if len(words2) > 0: #move cursor to begining of last word self.cursorColumn = words2[-1][1] else: #no words on line, so move cursor to the end of line self.cursorColumn = len(self.text[self.cursorRow]) else: #we are on first line, so move cursor to begining of line self.cursorColumn = 0 idxs = getIdxFromColumn(words, self.cursorColumn) if idxs != (-1, -1): if idxs[0] == -1: #cursor is before first word, jump to beginig of last word on previous line if self.cursorRow > 0: self.cursorRow -= 1 words2 = splitter(self.text[self.cursorRow]) if len(words2) > 0: #move cursor to begining of last word self.cursorColumn = words2[-1][1] else: #no words on line, so move cursor to the end of line self.cursorColumn = len(self.text[self.cursorRow]) else: #we are on first line, so move cursor to begining of line self.cursorColumn = 0 elif idxs[0] == idxs[1]: #we are inside word, so move cursor to begining of word self.cursorColumn = words[idxs[0]][1] elif idxs[1] == -1: #cursor is after last word, we must jump to begining of last word self.cursorColumn = words[idxs[0]][1] else: #cursor is between words, we must jump to begining of left word self.cursorColumn = words[idxs[0]][1] elif self.cursorColumn > 0: self.cursorColumn -= 1 elif self.cursorRow > 0: self.cursorRow -= 1 self.cursorColumn = len(self.text[self.cursorRow]) if evt.mod & pygame.KMOD_SHIFT: self.selEnd = (self.cursorRow,self.cursorColumn) if self.selStart == self.selEnd: self.selStart = self.selEnd = None else: self.selStart = self.selEnd = None elif evt.key == pygame.K_RIGHT: if evt.mod & pygame.KMOD_SHIFT: if self.selStart == None: self.selStart = (self.cursorRow,self.cursorColumn) if evt.mod & pygame.KMOD_CTRL: # move one word right # take words on line words = splitter(self.text[self.cursorRow]) if len(words) == 0: #move to next line if self.cursorRow < len(self.text) - 1: self.cursorRow += 1 words2 = splitter(self.text[self.cursorRow]) if len(words2) > 0: self.cursorColumn = words2[0][1] else: #on next line are only separators (or is empty), so move to column 0 self.cursorColumn = 0 else: #we are on last line, so move cursor to end of line self.cursorColumn = len(self.text[self.cursorRow]) idxs = getIdxFromColumn(words, self.cursorColumn) if idxs != (-1, -1): if idxs[0] == idxs[1] or self.cursorColumn == words[idxs[1]][1]: #cursor is inside of word or is on begining of word, so move on begining of next word if idxs[1] + 1 < len(words): #there is next word on line self.cursorColumn = words[idxs[1] + 1][1] else: #we must jump to begining first word on next line if self.cursorRow < len(self.text) - 1: self.cursorRow += 1 words2 = splitter(self.text[self.cursorRow]) if len(words2) > 0: self.cursorColumn = words2[0][1] else: #on next line are only separators (or is empty), so move to column 0 self.cursorColumn = 0 else: #we are on last line, so move cursor to end of line self.cursorColumn = len(self.text[self.cursorRow]) elif idxs[0] == -1: #cursor is before first word, jump to beginig of fist word self.cursorColumn = words[idxs[1]][1] elif idxs[1] == -1: #cursor is after last word, we must jump to begining first word on next line if self.cursorRow < len(self.text) - 1: self.cursorRow += 1 words2 = splitter(self.text[self.cursorRow]) if len(words2) > 0: self.cursorColumn = words2[0][1] else: #on next line are only separators (or is empty), so move to column 0 self.cursorColumn = 0 else: #we are on last line, so move cursor to end of line self.cursorColumn = len(self.text[self.cursorRow]) else: #cursor is between words self.cursorColumn = words[idxs[1]][1] elif self.cursorColumn < len(self.text[self.cursorRow]): self.cursorColumn += 1 elif self.cursorRow < len(self.text): # move to the next row if self.cursorRow < len(self.text) - 1: self.cursorRow += 1 self.cursorColumn = 0 if evt.mod & pygame.KMOD_SHIFT: self.selEnd = (self.cursorRow,self.cursorColumn) if self.selStart == self.selEnd: self.selStart = self.selEnd = None else: self.selStart = self.selEnd = None elif evt.key == pygame.K_UP: if evt.mod & pygame.KMOD_SHIFT: if self.selStart == None: self.selStart = (self.cursorRow,self.cursorColumn) if self.cursorRow > 0: self.cursorRow -= 1 self.cursorColumn = min(self.cursorColumn, len(self.text[self.cursorRow])) if self.cursorRow - self.offsetRow < 0: self.vertScrollbar.onButton1(self, "", "") if evt.mod & pygame.KMOD_SHIFT: self.selEnd = (self.cursorRow,self.cursorColumn) if self.selStart == self.selEnd: self.selStart = self.selEnd = None else: self.selStart = self.selEnd = None elif evt.key == pygame.K_DOWN: if evt.mod & pygame.KMOD_SHIFT: if self.selStart == None: self.selStart = (self.cursorRow,self.cursorColumn) if self.cursorRow < len(self.text) - 1: self.cursorRow += 1 self.cursorColumn = min(self.cursorColumn, len(self.text[self.cursorRow])) if self.cursorRow - self.offsetRow >= self.theme.getTextDrawLines(self): self.vertScrollbar.onButton2(self, "", "") if evt.mod & pygame.KMOD_SHIFT: self.selEnd = (self.cursorRow,self.cursorColumn) if self.selStart == self.selEnd: self.selStart = self.selEnd = None else: self.selStart = self.selEnd = None elif evt.key == pygame.K_TAB: pass elif evt.key == pygame.K_END: if evt.mod & pygame.KMOD_SHIFT: if self.selEnd != None: self.selEnd = (self.selEnd[0], len(self.text[self.cursorRow])) else: self.selStart = (self.cursorRow, self.cursorColumn) self.selEnd = (self.cursorRow, len(self.text[self.cursorRow])) else: self.selStart = self.selEnd = None self.cursorColumn = len(self.text[self.cursorRow]) elif evt.key == pygame.K_HOME: if evt.mod & pygame.KMOD_SHIFT: if self.selStart != None: self.selStart = (self.selStart[0], 0) else: self.selStart = (self.cursorRow, 0) self.selEnd = (self.cursorRow, self.cursorColumn) else: self.selStart = self.selEnd = None self.cursorColumn = 0 elif evt.key == pygame.K_RETURN: text1 = self.text[self.cursorRow][self.cursorColumn:] text2 = self.text[self.cursorRow][:self.cursorColumn] self.text[self.cursorRow] = text1 self.text.insert(self.cursorRow, text2) self.cursorRow += 1 self.cursorColumn = 0 #self.vertScrollbar.slider.max = len(self.text) elif hasattr(evt, 'unicode') and evt.unicode: if self.selStart != None: self.deleteSelection() # TODO this is ugly windows only hack needed for Win 9x and XP # char = unicode(chr(ord(evt.unicode)), 'cp1250') char = evt.unicode self.text[self.cursorRow] = u'%s%c%s' % ( self.text[self.cursorRow][:self.cursorColumn], char, self.text[self.cursorRow][self.cursorColumn:] ) self.cursorColumn += 1 elif mapping.has_key(evt.key): if self.selStart != None: self.deleteSelection() self.text[self.cursorRow] = u'%s%c%s' % ( self.text[self.cursorRow][:self.cursorColumn], mapping[evt.key], self.text[self.cursorRow][self.cursorColumn:] ) self.cursorColumn += 1 return Widget.processKeyDown(self, Const.NoEvent)
def processKeyDown(self, evt): if not self.editable: return Widget.processKeyDown(self, evt) # process keys if evt.key == K_BACKSPACE: if self.cursorColumn > 0: self.text[self.cursorRow] = u'%s%s' % (self.text[self.cursorRow][:self.cursorColumn - 1], self.text[self.cursorRow][self.cursorColumn:]) self.cursorColumn -= 1 else: if self.cursorRow > 0: self.cursorColumn = len(self.text[self.cursorRow -1]) self.text[self.cursorRow - 1] = u'%s%s' % (self.text[self.cursorRow - 1], self.text[self.cursorRow]) del self.text[self.cursorRow] self.cursorRow -= 1 elif evt.key == K_DELETE: if self.cursorColumn < len(self.text[self.cursorRow]): self.text[self.cursorRow] = u'%s%s' % (self.text[self.cursorRow][:self.cursorColumn], self.text[self.cursorRow][self.cursorColumn + 1:]) elif self.cursorRow < len(self.text) - 1: self.text[self.cursorRow] = u'%s%s' % (self.text[self.cursorRow], self.text[self.cursorRow + 1]) del self.text[self.cursorRow + 1] elif evt.key == K_RETURN: text1 = self.text[self.cursorRow][self.cursorColumn:] text2 = self.text[self.cursorRow][:self.cursorColumn] self.text[self.cursorRow] = text1 self.text.insert(self.cursorRow, text2) self.cursorRow += 1 self.cursorColumn = 0 elif evt.key == K_ESCAPE: self.app.setFocus(None) elif evt.key == K_LEFT: if evt.mod & KMOD_CTRL: # move one word left # take words on line words = splitter(self.text[self.cursorRow]) if len(words) == 0: #move to previous line if self.cursorRow > 0: self.cursorRow -= 1 words2 = splitter(self.text[self.cursorRow]) if len(words2) > 0: #move cursor to begining of last word self.cursorColumn = words2[-1][1] else: #no words on line, so move cursor to the end of line self.cursorColumn = len(self.text[self.cursorRow]) else: #we are on first line, so move cursor to begining of line self.cursorColumn = 0 idxs = getIdxFromColumn(words, self.cursorColumn) if idxs != (-1, -1): if idxs[0] == -1: #cursor is before first word, jump to beginig of last word on previous line if self.cursorRow > 0: self.cursorRow -= 1 words2 = splitter(self.text[self.cursorRow]) if len(words2) > 0: #move cursor to begining of last word self.cursorColumn = words2[-1][1] else: #no words on line, so move cursor to the end of line self.cursorColumn = len(self.text[self.cursorRow]) else: #we are on first line, so move cursor to begining of line self.cursorColumn = 0 elif idxs[0] == idxs[1]: #we are inside word, so move cursor to begining of word self.cursorColumn = words[idxs[0]][1] elif idxs[1] == -1: #cursor is after last word, we must jump to begining of last word self.cursorColumn = words[idxs[0]][1] else: #cursor is between words, we must jump to begining of left word self.cursorColumn = words[idxs[0]][1] elif self.cursorColumn > 0: self.cursorColumn -= 1 elif self.cursorRow > 0: self.cursorRow -= 1 self.cursorColumn = len(self.text[self.cursorRow]) elif evt.key == K_RIGHT: if evt.mod & KMOD_CTRL: # move one word right # take words on line words = splitter(self.text[self.cursorRow]) if len(words) == 0: #move to next line if self.cursorRow < len(self.text) - 1: self.cursorRow += 1 words2 = splitter(self.text[self.cursorRow]) if len(words2) > 0: self.cursorColumn = words2[0][1] else: #on next line are only separators (or is empty), so move to column 0 self.cursorColumn = 0 else: #we are on last line, so move cursor to end of line self.cursorColumn = len(self.text[self.cursorRow]) idxs = getIdxFromColumn(words, self.cursorColumn) if idxs != (-1, -1): if idxs[0] == idxs[1] or self.cursorColumn == words[idxs[1]][1]: #cursor is inside of word or is on begining of word, so move on begining of next word if idxs[1] + 1 < len(words): #there is next word on line self.cursorColumn = words[idxs[1] + 1][1] else: #we must jump to begining first word on next line if self.cursorRow < len(self.text) - 1: self.cursorRow += 1 words2 = splitter(self.text[self.cursorRow]) if len(words2) > 0: self.cursorColumn = words2[0][1] else: #on next line are only separators (or is empty), so move to column 0 self.cursorColumn = 0 else: #we are on last line, so move cursor to end of line self.cursorColumn = len(self.text[self.cursorRow]) elif idxs[0] == -1: #cursor is before first word, jump to beginig of fist word self.cursorColumn = words[idxs[1]][1] elif idxs[1] == -1: #cursor is after last word, we must jump to begining first word on next line if self.cursorRow < len(self.text) - 1: self.cursorRow += 1 words2 = splitter(self.text[self.cursorRow]) if len(words2) > 0: self.cursorColumn = words2[0][1] else: #on next line are only separators (or is empty), so move to column 0 self.cursorColumn = 0 else: #we are on last line, so move cursor to end of line self.cursorColumn = len(self.text[self.cursorRow]) else: #cursor is between words self.cursorColumn = words[idxs[1]][1] elif self.cursorColumn < len(self.text[self.cursorRow]): self.cursorColumn += 1 elif self.cursorRow < len(self.text): # move to the next row if self.cursorRow < len(self.text) - 1: self.cursorRow += 1 self.cursorColumn = 0 elif evt.key == K_UP: if self.cursorRow > 0: self.cursorRow -= 1 self.cursorColumn = min(self.cursorColumn, len(self.text[self.cursorRow])) elif evt.key == K_DOWN: if self.cursorRow < len(self.text) - 1: self.cursorRow += 1 self.cursorColumn = min(self.cursorColumn, len(self.text[self.cursorRow])) elif evt.key == K_TAB: pass elif evt.key == K_END: self.cursorColumn = len(self.text[self.cursorRow]) elif evt.key == K_HOME: self.cursorColumn = 0 elif evt.unicode: # TODO this is ugly windows only hack char = unicode(chr(ord(evt.unicode)), 'cp1250') self.text[self.cursorRow] = u'%s%s%s' % ( self.text[self.cursorRow][:self.cursorColumn], char, self.text[self.cursorRow][self.cursorColumn:] ) self.cursorColumn += 1 elif mapping.has_key(evt.key): self.text[self.cursorRow] = u'%s%s%s' % ( self.text[self.cursorRow][:self.cursorColumn], mapping[evt.key], self.text[self.cursorRow][self.cursorColumn:] ) self.cursorColumn += 1 return Widget.processKeyDown(self, NoEvent)
def processKeyDown(self, evt): if not self.editable: return Widget.processKeyDown(self, evt) # process keys if evt.key == K_BACKSPACE: if self.selStart != None: self.deleteSelection() elif self.cursorColumn > 0: self.text[self.cursorRow] = u'%s%s' % ( self.text[self.cursorRow][:self.cursorColumn - 1], self.text[self.cursorRow][self.cursorColumn:]) self.cursorColumn -= 1 else: if self.cursorRow > 0: self.cursorColumn = len(self.text[self.cursorRow - 1]) self.text[self.cursorRow - 1] = u'%s%s' % (self.text[self.cursorRow - 1], self.text[self.cursorRow]) del self.text[self.cursorRow] self.cursorRow -= 1 elif evt.key == K_DELETE: if self.selStart != None: self.deleteSelection() elif self.cursorColumn < len(self.text[self.cursorRow]): self.text[self.cursorRow] = u'%s%s' % ( self.text[self.cursorRow][:self.cursorColumn], self.text[self.cursorRow][self.cursorColumn + 1:]) elif self.cursorRow < len(self.text) - 1: self.text[self.cursorRow] = u'%s%s' % ( self.text[self.cursorRow], self.text[self.cursorRow + 1]) del self.text[self.cursorRow + 1] elif evt.key == K_ESCAPE: self.app.setFocus(None) elif evt.key == K_LEFT: if evt.mod & KMOD_SHIFT: if self.selStart == None: self.selStart = (self.cursorRow, self.cursorColumn) if evt.mod & KMOD_CTRL: # move one word left # take words on line words = splitter(self.text[self.cursorRow]) if len(words) == 0: #move to previous line if self.cursorRow > 0: self.cursorRow -= 1 words2 = splitter(self.text[self.cursorRow]) if len(words2) > 0: #move cursor to begining of last word self.cursorColumn = words2[-1][1] else: #no words on line, so move cursor to the end of line self.cursorColumn = len(self.text[self.cursorRow]) else: #we are on first line, so move cursor to begining of line self.cursorColumn = 0 idxs = getIdxFromColumn(words, self.cursorColumn) if idxs != (-1, -1): if idxs[0] == -1: #cursor is before first word, jump to beginig of last word on previous line if self.cursorRow > 0: self.cursorRow -= 1 words2 = splitter(self.text[self.cursorRow]) if len(words2) > 0: #move cursor to begining of last word self.cursorColumn = words2[-1][1] else: #no words on line, so move cursor to the end of line self.cursorColumn = len( self.text[self.cursorRow]) else: #we are on first line, so move cursor to begining of line self.cursorColumn = 0 elif idxs[0] == idxs[1]: #we are inside word, so move cursor to begining of word self.cursorColumn = words[idxs[0]][1] elif idxs[1] == -1: #cursor is after last word, we must jump to begining of last word self.cursorColumn = words[idxs[0]][1] else: #cursor is between words, we must jump to begining of left word self.cursorColumn = words[idxs[0]][1] elif self.cursorColumn > 0: self.cursorColumn -= 1 elif self.cursorRow > 0: self.cursorRow -= 1 self.cursorColumn = len(self.text[self.cursorRow]) if evt.mod & KMOD_SHIFT: self.selEnd = (self.cursorRow, self.cursorColumn) if self.selStart == self.selEnd: self.selStart = self.selEnd = None else: self.selStart = self.selEnd = None elif evt.key == K_RIGHT: if evt.mod & KMOD_SHIFT: if self.selStart == None: self.selStart = (self.cursorRow, self.cursorColumn) if evt.mod & KMOD_CTRL: # move one word right # take words on line words = splitter(self.text[self.cursorRow]) if len(words) == 0: #move to next line if self.cursorRow < len(self.text) - 1: self.cursorRow += 1 words2 = splitter(self.text[self.cursorRow]) if len(words2) > 0: self.cursorColumn = words2[0][1] else: #on next line are only separators (or is empty), so move to column 0 self.cursorColumn = 0 else: #we are on last line, so move cursor to end of line self.cursorColumn = len(self.text[self.cursorRow]) idxs = getIdxFromColumn(words, self.cursorColumn) if idxs != (-1, -1): if idxs[0] == idxs[1] or self.cursorColumn == words[ idxs[1]][1]: #cursor is inside of word or is on begining of word, so move on begining of next word if idxs[1] + 1 < len(words): #there is next word on line self.cursorColumn = words[idxs[1] + 1][1] else: #we must jump to begining first word on next line if self.cursorRow < len(self.text) - 1: self.cursorRow += 1 words2 = splitter(self.text[self.cursorRow]) if len(words2) > 0: self.cursorColumn = words2[0][1] else: #on next line are only separators (or is empty), so move to column 0 self.cursorColumn = 0 else: #we are on last line, so move cursor to end of line self.cursorColumn = len( self.text[self.cursorRow]) elif idxs[0] == -1: #cursor is before first word, jump to beginig of fist word self.cursorColumn = words[idxs[1]][1] elif idxs[1] == -1: #cursor is after last word, we must jump to begining first word on next line if self.cursorRow < len(self.text) - 1: self.cursorRow += 1 words2 = splitter(self.text[self.cursorRow]) if len(words2) > 0: self.cursorColumn = words2[0][1] else: #on next line are only separators (or is empty), so move to column 0 self.cursorColumn = 0 else: #we are on last line, so move cursor to end of line self.cursorColumn = len(self.text[self.cursorRow]) else: #cursor is between words self.cursorColumn = words[idxs[1]][1] elif self.cursorColumn < len(self.text[self.cursorRow]): self.cursorColumn += 1 elif self.cursorRow < len(self.text): # move to the next row if self.cursorRow < len(self.text) - 1: self.cursorRow += 1 self.cursorColumn = 0 if evt.mod & KMOD_SHIFT: self.selEnd = (self.cursorRow, self.cursorColumn) if self.selStart == self.selEnd: self.selStart = self.selEnd = None else: self.selStart = self.selEnd = None elif evt.key == K_UP: if evt.mod & KMOD_SHIFT: if self.selStart == None: self.selStart = (self.cursorRow, self.cursorColumn) if self.cursorRow > 0: self.cursorRow -= 1 self.cursorColumn = min(self.cursorColumn, len(self.text[self.cursorRow])) if self.cursorRow - self.offsetRow < 0: self.vertScrollbar.onButton1(self, "", "") if evt.mod & KMOD_SHIFT: self.selEnd = (self.cursorRow, self.cursorColumn) if self.selStart == self.selEnd: self.selStart = self.selEnd = None else: self.selStart = self.selEnd = None elif evt.key == K_DOWN: if evt.mod & KMOD_SHIFT: if self.selStart == None: self.selStart = (self.cursorRow, self.cursorColumn) if self.cursorRow < len(self.text) - 1: self.cursorRow += 1 self.cursorColumn = min(self.cursorColumn, len(self.text[self.cursorRow])) if self.cursorRow - self.offsetRow >= self.theme.getTextDrawLines( self): self.vertScrollbar.onButton2(self, "", "") if evt.mod & KMOD_SHIFT: self.selEnd = (self.cursorRow, self.cursorColumn) if self.selStart == self.selEnd: self.selStart = self.selEnd = None else: self.selStart = self.selEnd = None elif evt.key == K_TAB: pass elif evt.key == K_END: if evt.mod & KMOD_SHIFT: if self.selEnd != None: self.selEnd = (self.selEnd[0], len(self.text[self.cursorRow])) else: self.selStart = (self.cursorRow, self.cursorColumn) self.selEnd = (self.cursorRow, len(self.text[self.cursorRow])) else: self.selStart = self.selEnd = None self.cursorColumn = len(self.text[self.cursorRow]) elif evt.key == K_HOME: if evt.mod & KMOD_SHIFT: if self.selStart != None: self.selStart = (self.selStart[0], 0) else: self.selStart = (self.cursorRow, 0) self.selEnd = (self.cursorRow, self.cursorColumn) else: self.selStart = self.selEnd = None self.cursorColumn = 0 elif evt.key == K_RETURN: text1 = self.text[self.cursorRow][self.cursorColumn:] text2 = self.text[self.cursorRow][:self.cursorColumn] self.text[self.cursorRow] = text1 self.text.insert(self.cursorRow, text2) self.cursorRow += 1 self.cursorColumn = 0 #self.vertScrollbar.slider.max = len(self.text) elif hasattr(evt, 'unicode') and evt.unicode: if self.selStart != None: self.deleteSelection() # TODO this is ugly windows only hack char = unicode(chr(ord(evt.unicode)), 'cp1250') self.text[self.cursorRow] = u'%s%c%s' % ( self.text[self.cursorRow][:self.cursorColumn], char, self.text[self.cursorRow][self.cursorColumn:]) self.cursorColumn += 1 elif mapping.has_key(evt.key): if self.selStart != None: self.deleteSelection() self.text[self.cursorRow] = u'%s%c%s' % ( self.text[self.cursorRow][:self.cursorColumn], mapping[evt.key], self.text[self.cursorRow][self.cursorColumn:]) self.cursorColumn += 1 return Widget.processKeyDown(self, NoEvent)