comparison python/codeeditor.py @ 154:81e08e2e7777

Used error icon
author Windel Bouwman
date Sat, 02 Mar 2013 10:19:38 +0100
parents af0d7913677a
children d8c735dc31f9
comparison
equal deleted inserted replaced
153:e05b2b216bfc 154:81e08e2e7777
55 # members: 55 # members:
56 self.isUntitled = True 56 self.isUntitled = True
57 self.filename = None 57 self.filename = None
58 self.setFont(QFont('Courier')) 58 self.setFont(QFont('Courier'))
59 self.lineNumberArea = LineNumberArea(self) 59 self.lineNumberArea = LineNumberArea(self)
60 h = QFontMetrics(self.font()).height()
61 print(h)
62 self.errorPixmap = QPixmap('error.png').scaled(h, h)
63 self.errorList = []
60 64
61 self.blockCountChanged.connect(self.updateLineNumberAreaWidth) 65 self.blockCountChanged.connect(self.updateLineNumberAreaWidth)
62 self.updateRequest.connect(self.updateLineNumberArea) 66 self.updateRequest.connect(self.updateLineNumberArea)
63 67
64 # Syntax highlighter: 68 # Syntax highlighter:
100 #selection.format.setProperty(QTextFormat.FullWidthSelection, True) 104 #selection.format.setProperty(QTextFormat.FullWidthSelection, True)
101 selection.cursor = tc 105 selection.cursor = tc
102 self.setExtraSelections( [ selection ] ) 106 self.setExtraSelections( [ selection ] )
103 def clearErrors(self): 107 def clearErrors(self):
104 self.setExtraSelections( [ ] ) 108 self.setExtraSelections( [ ] )
109 def setErrors(self, el):
110 self.errorList = el
111 self.lineNumberArea.update()
105 112
106 def lineNumberAreaWidth(self): 113 def lineNumberAreaWidth(self):
107 digits = 1 114 digits = 1
108 mx = max(1, self.blockCount()) 115 mx = max(1, self.blockCount())
109 while mx >= 10: 116 while mx >= 10:
110 mx = mx / 10 117 mx = mx / 10
111 digits += 1 118 digits += 1
112 space = 3 + self.fontMetrics().width('8') * digits 119 space = 3 + self.fontMetrics().width('8') * digits + self.errorPixmap.width() + 2
113 return space 120 return space
114 def lineNumberAreaPaintEvent(self, ev): 121 def lineNumberAreaPaintEvent(self, ev):
115 painter = QPainter(self.lineNumberArea) 122 painter = QPainter(self.lineNumberArea)
116 painter.fillRect(ev.rect(), Qt.lightGray) 123 painter.fillRect(ev.rect(), Qt.lightGray)
117 block = self.firstVisibleBlock() 124 block = self.firstVisibleBlock()
121 while block.isValid() and top <= ev.rect().bottom(): 128 while block.isValid() and top <= ev.rect().bottom():
122 if block.isVisible() and bottom >= ev.rect().top(): 129 if block.isVisible() and bottom >= ev.rect().top():
123 num = str(blockNumber + 1) 130 num = str(blockNumber + 1)
124 painter.setPen(Qt.black) 131 painter.setPen(Qt.black)
125 painter.drawText(0, top, self.lineNumberArea.width(), self.fontMetrics().height(), Qt.AlignRight, num) 132 painter.drawText(0, top, self.lineNumberArea.width(), self.fontMetrics().height(), Qt.AlignRight, num)
133 for e in self.errorList:
134 if e.loc.row == blockNumber + 1:
135 painter.drawPixmap(0, top, self.errorPixmap)
136
126 block = block.next() 137 block = block.next()
127 top = bottom 138 top = bottom
128 bottom = top + self.blockBoundingRect(block).height() 139 bottom = top + self.blockBoundingRect(block).height()
129 blockNumber += 1 140 blockNumber += 1
130 def resizeEvent(self, ev): 141 def resizeEvent(self, ev):