Mercurial > lcfOS
diff python/codeedit.py @ 256:225f444019b1
Added build and flash menu option
author | Windel Bouwman |
---|---|
date | Sun, 04 Aug 2013 18:32:04 +0200 |
parents | f5fba5b554d7 |
children | 046017431c6a |
line wrap: on
line diff
--- a/python/codeedit.py Sun Aug 04 15:10:10 2013 +0200 +++ b/python/codeedit.py Sun Aug 04 18:32:04 2013 +0200 @@ -36,24 +36,24 @@ self.t.start() def updateCursor(self): - self.blinkcursor = not self.blinkcursor - self.update() - #self.update(self.cursorX, self.cursorY, self.charWidth, self.charHeight) + self.blinkcursor = not self.blinkcursor + self.update() + #self.update(self.cursorX, self.cursorY, self.charWidth, self.charHeight) def setSource(self, src): - self.src = src - self.adjust() + self.src = src + self.adjust() def getSource(self): - return self.src + return self.src def setErrors(self, el): - self.errorlist = el - self.update() + self.errorlist = el + self.update() def setCursorPosition(self, c): - self.cursorPosition = clipVal(c, 0, len(self.src)) - self.update() + self.cursorPosition = clipVal(c, 0, len(self.src)) + self.update() CursorPosition = property(lambda self: self.cursorPosition, setCursorPosition) @@ -95,42 +95,51 @@ def showRow(self, r): self.scrollArea.ensureVisible(self.xposTXT, r * self.charHeight, 4, self.charHeight) + # Annotations: def addAnnotation(self, row, col, ln, msg): pass + # Text modification: def getChar(self, pos): pass + def insertText(self, txt): - self.setSource(self.src[0:self.CursorPosition] + txt + self.src[self.CursorPosition:]) - self.CursorPosition += len(txt) - self.textChanged.emit() + self.setSource(self.src[0:self.CursorPosition] + txt + self.src[self.CursorPosition:]) + self.CursorPosition += len(txt) + self.textChanged.emit() + def deleteChar(self): - self.setSource(self.src[0:self.CursorPosition] + self.src[self.CursorPosition+1:]) - self.textChanged.emit() + self.setSource(self.src[0:self.CursorPosition] + self.src[self.CursorPosition+1:]) + self.textChanged.emit() + def GotoNextChar(self): - if self.src[self.CursorPosition] != '\n': - self.CursorPosition += 1 + if self.src[self.CursorPosition] != '\n': + self.CursorPosition += 1 + def GotoPrevChar(self): - if self.src[self.CursorPosition - 1] != '\n': - self.CursorPosition -= 1 + if self.src[self.CursorPosition - 1] != '\n': + self.CursorPosition -= 1 + def GotoNextLine(self): - curLine = self.CurrentLine - c = self.CursorCol - 1 # go to zero based - self.CursorPosition += len(curLine) - c + 1 # line break char! - curLine = self.CurrentLine - if len(curLine) < c: - self.CursorPosition += len(curLine) - else: - self.CursorPosition += c - self.showRow(self.CursorRow) + curLine = self.CurrentLine + c = self.CursorCol - 1 # go to zero based + self.CursorPosition += len(curLine) - c + 1 # line break char! + curLine = self.CurrentLine + if len(curLine) < c: + self.CursorPosition += len(curLine) + else: + self.CursorPosition += c + self.showRow(self.CursorRow) + def GotoPrevLine(self): - c = self.CursorCol - 1 # go to zero based - self.CursorPosition -= c + 1 # line break char! - curLine = self.CurrentLine - if len(curLine) > c: - self.CursorPosition -= len(curLine) - c - self.showRow(self.CursorRow) + c = self.CursorCol - 1 # go to zero based + self.CursorPosition -= c + 1 # line break char! + curLine = self.CurrentLine + if len(curLine) > c: + self.CursorPosition -= len(curLine) - c + self.showRow(self.CursorRow) + def paintEvent(self, event): # Helper variables: er = event.rect() @@ -209,25 +218,26 @@ self.update() def mousePressEvent(self, event): - pos = event.pos() - if pos.x() > self.xposTXT and pos.x(): - c = round((pos.x() - self.xposTXT) / self.charWidth) - r = int(pos.y() / self.charHeight) + 1 - self.setRowCol(r, c) + pos = event.pos() + if pos.x() > self.xposTXT and pos.x(): + c = round((pos.x() - self.xposTXT) / self.charWidth) + r = int(pos.y() / self.charHeight) + 1 + self.setRowCol(r, c) + super().mousePressEvent(event) def adjust(self): - metrics = self.fontMetrics() - self.charHeight = metrics.height() - self.charWidth = metrics.width('x') - self.charDescent = metrics.descent() - self.xposERR = GAP - self.xposLNA = self.xposERR + GAP + self.errorPixmap.width() - self.xposTXT = self.xposLNA + 4 * self.charWidth + GAP - self.xposEnd = self.xposTXT + self.charWidth * 80 - self.setMinimumWidth(self.xposEnd) - txt = self.src.split('\n') - self.setMinimumHeight(self.charHeight * len(txt)) - self.update() + metrics = self.fontMetrics() + self.charHeight = metrics.height() + self.charWidth = metrics.width('x') + self.charDescent = metrics.descent() + self.xposERR = GAP + self.xposLNA = self.xposERR + GAP + self.errorPixmap.width() + self.xposTXT = self.xposLNA + 4 * self.charWidth + GAP + self.xposEnd = self.xposTXT + self.charWidth * 80 + self.setMinimumWidth(self.xposEnd) + txt = self.src.split('\n') + self.setMinimumHeight(self.charHeight * len(txt)) + self.update() class CodeEdit(QScrollArea): def __init__(self): @@ -248,6 +258,7 @@ def setFocus(self): self.ic.setFocus() + super().setFocus() def setFileName(self, fn): self.filename = fn