Trees | Indices | Help |
|
---|
|
1 import PySide 2 import re, sys, traceback, os 3 import rlcompleter 4 from StringIO import StringIO 5 6 #Syntax highlighting colour definitions 7 kwdsFgColour = PySide.QtGui.QColor(122, 136, 53) 8 stringLiteralsFgColourDQ = PySide.QtGui.QColor(226, 138, 138) 9 stringLiteralsFgColourSQ = PySide.QtGui.QColor(110, 160, 121) 10 commentsFgColour = PySide.QtGui.QColor(188, 179, 84) 11 blinkTypesColour = PySide.QtGui.QColor(25, 25, 80) 12 blinkFuncsColour = PySide.QtGui.QColor(3, 185, 191) 13 14 15 #Need to add in the proper methods here17 18 #Signal that will be emitted when the user has changed the text 19 userChangedEvent = PySide.QtCore.Signal() 2052722 super(ScriptInputArea, self).__init__(parent) 23 24 #Setup vars 25 self._output = output 26 self._editor = editor 27 self._errorLine = 0 28 self._showErrorHighlight = True 29 self._completer = None 30 self._currentCompletion = None 31 self._completerShowing = False 32 self._showLineNumbers = True 33 34 self.setStyleSheet("background-color: rgb(81, 81, 81);") 35 36 #Setup completer 37 self._completer = PySide.QtGui.QCompleter(self) 38 self._completer.setWidget(self) 39 self._completer.setCompletionMode(PySide.QtGui.QCompleter.UnfilteredPopupCompletion) 40 self._completer.setCaseSensitivity(PySide.QtCore.Qt.CaseSensitive) 41 self._completer.setModel(PySide.QtGui.QStringListModel()) 42 43 #Setup line numbers 44 self._lineNumberArea = LineNumberArea(self, parent=self) 45 46 #Add highlighter 47 self._highlighterInput = InputHighlighter(self.document(), parent=self) 48 49 #Setup connections 50 self.cursorPositionChanged.connect(self.highlightCurrentLine) 51 self._completer.activated.connect(self.insertCompletion) 52 self._completer.highlighted.connect(self.completerHighlightChanged) 53 self.blockCountChanged.connect(self.updateLineNumberAreaWidth) 54 self.updateRequest.connect(self.updateLineNumberArea) 55 56 self.updateLineNumberAreaWidth() 57 self._lineNumberArea.setVisible( self._showLineNumbers )58 5961 62 if not self._showLineNumbers : 63 return 0 64 65 digits = 1 66 maxNum = max(1, self.blockCount()) 67 while (maxNum >= 10) : 68 maxNum /= 10 69 digits += 1 70 71 space = 5 + self.fontMetrics().width('9') * digits 72 return space73 7476 self.setViewportMargins(self.lineNumberAreaWidth(), 0, 0, 0)77 7880 if (dy) : 81 self._lineNumberArea.scroll(0, dy) 82 else : 83 self._lineNumberArea.update(0, rect.y(), self._lineNumberArea.width(), rect.height()) 84 85 if (rect.contains(self.viewport().rect())) : 86 self.updateLineNumberAreaWidth()87 8890 PySide.QtGui.QPlainTextEdit.resizeEvent(self, event) 91 92 cr = self.contentsRect() 93 self._lineNumberArea.setGeometry(PySide.QtCore.QRect(cr.left(), cr.top(), self.lineNumberAreaWidth(), cr.height()))9496 97 painter = PySide.QtGui.QPainter(self._lineNumberArea) 98 painter.fillRect(event.rect(), self.palette().base()) 99 100 block = self.firstVisibleBlock() 101 blockNumber = block.blockNumber() 102 top = int( self.blockBoundingGeometry(block).translated(self.contentOffset()).top() ) 103 bottom = top + int( self.blockBoundingRect(block).height() ) 104 currentLine = self.document().findBlock(self.textCursor().position()).blockNumber() 105 106 font = painter.font() 107 pen = painter.pen() 108 painter.setPen( self.palette().color(PySide.QtGui.QPalette.Text) ) 109 110 while (block.isValid() and top <= event.rect().bottom()) : 111 112 if (block.isVisible() and bottom >= event.rect().top()) : 113 114 if ( blockNumber == currentLine ) : 115 painter.setPen(PySide.QtGui.QColor(255, 255, 255)) 116 font.setBold(True) 117 painter.setFont(font) 118 119 elif ( blockNumber == int(self._errorLine) - 1 ) : 120 painter.setPen(PySide.QtGui.QColor(127, 0, 0)) 121 font.setBold(True) 122 painter.setFont(font) 123 124 else : 125 painter.setPen(PySide.QtGui.QColor(35, 35, 35)) 126 font.setBold(False) 127 painter.setFont(font) 128 129 number = "%s" % str(blockNumber + 1) 130 painter.drawText(0, top, self._lineNumberArea.width(), self.fontMetrics().height(), PySide.QtCore.Qt.AlignRight, number) 131 132 #Move to the next block 133 block = block.next() 134 top = bottom 135 bottom = top + int(self.blockBoundingRect(block).height()) 136 blockNumber += 1137 138140 141 extraSelections = [] 142 143 if (self._showErrorHighlight and not self.isReadOnly()) : 144 selection = PySide.QtGui.QTextEdit.ExtraSelection() 145 146 lineColor = PySide.QtGui.QColor(255, 255, 255, 40) 147 148 selection.format.setBackground(lineColor) 149 selection.format.setProperty(PySide.QtGui.QTextFormat.FullWidthSelection, True) 150 selection.cursor = self.textCursor() 151 selection.cursor.clearSelection() 152 153 extraSelections.append(selection) 154 155 self.setExtraSelections(extraSelections) 156 self._errorLine = 0157 158160 161 extraSelections = [] 162 163 if (self._showErrorHighlight and not self.isReadOnly()) : 164 if (self._errorLine != 0) : 165 selection = PySide.QtGui.QTextEdit.ExtraSelection() 166 167 selection.format.setBackground(PySide.QtGui.QColor(255, 0, 0, 40)) 168 selection.format.setProperty(PySide.QtGui.QTextFormat.OutlinePen, PySide.QtGui.QPen(PySide.QtGui.QColor(127, 0, 0, 0))) 169 selection.format.setProperty(PySide.QtGui.QTextFormat.FullWidthSelection, True) 170 171 pos = self.document().findBlockByLineNumber(int(self._errorLine)-1).position() 172 cursor = self.textCursor() 173 cursor.setPosition(pos) 174 175 selection.cursor = cursor 176 selection.cursor.clearSelection() 177 extraSelections.append(selection) 178 179 self.setExtraSelections(extraSelections)180182 183 lScriptEditorMod = ((event.modifiers() and (PySide.QtCore.Qt.ControlModifier or PySide.QtCore.Qt.AltModifier)) == PySide.QtCore.Qt.ControlModifier) 184 lScriptEditorShift = ((event.modifiers() and (PySide.QtCore.Qt.ShiftModifier)) != 0) 185 lKey = event.key() 186 187 #TODO Query Completer Showing 188 self._completerShowing = self._completer.popup().isVisible() 189 190 if not self._completerShowing : 191 if (lScriptEditorMod and (lKey == PySide.QtCore.Qt.Key_Return or lKey == PySide.QtCore.Qt.Key_Enter)) : 192 if (self._editor) : 193 self._editor.runScript() 194 return 195 #elif lScriptEditorMod and lScriptEditorShift and lKey == PySide.QtCore.Qt.Key_BraceLeft : 196 # self.decreaseIndentationSelected() 197 # return 198 #elif lScriptEditorMod and lScriptEditorShift and lKey == PySide.QtCore.Qt.Key_BraceRight : 199 # self.increaseIndentationSelected() 200 # return 201 elif lScriptEditorMod and lKey == PySide.QtCore.Qt.Key_Slash : 202 self.commentSelected() 203 return 204 elif lScriptEditorMod and lKey == PySide.QtCore.Qt.Key_Backspace : 205 self._editor.clearOutput() 206 return 207 elif lKey == PySide.QtCore.Qt.Key_Tab or (lScriptEditorMod and lKey == PySide.QtCore.Qt.Key_Space) : 208 #Ok. 209 #If you have a selection you should indent 210 #ElIf line is blank it should always pass through the key event 211 #Else get the last 212 tc = self.textCursor() 213 if tc.hasSelection() : 214 print "Indenting" 215 self.increaseIndentationSelected() 216 else : 217 #Show completion 218 colNum = tc.columnNumber() 219 posNum = tc.position() 220 inputText = self.toPlainText() 221 inputTextToCursor = self.toPlainText()[0:posNum] 222 inputTextSplit = inputText.splitlines() 223 inputTextToCursorSplit = inputTextToCursor.splitlines() 224 runningLength = 0 225 currentLine = None 226 227 for line in inputTextToCursorSplit : 228 length = len(line) 229 runningLength += length 230 if runningLength >= posNum : 231 currentLine = line 232 break 233 runningLength += 1 234 235 if currentLine : 236 237 if len(currentLine.strip()) == 0 : 238 PySide.QtGui.QPlainTextEdit.keyPressEvent(self, event) 239 return 240 241 token = currentLine.split(" ")[-1] 242 if "(" in token : 243 token = token.split("(")[-1] 244 245 if len(token)>0: 246 self.completeTokenUnderCursor(token) 247 else : 248 PySide.QtGui.QPlainTextEdit.keyPressEvent(self, event) 249 else : 250 PySide.QtGui.QPlainTextEdit.keyPressEvent(self, event) 251 252 #print mid(tc.position() - tc.columnNumber(), tc.columnNumber()) 253 254 else : 255 PySide.QtGui.QPlainTextEdit.keyPressEvent(self, event) 256 return 257 else : 258 tc = self.textCursor() 259 if lKey == PySide.QtCore.Qt.Key_Return or lKey == PySide.QtCore.Qt.Key_Enter : 260 self.insertCompletion(self._currentCompletion) 261 self._currentCompletion = "" 262 self._completer.popup().hide() 263 self._completerShowing = False 264 elif lKey == PySide.QtCore.Qt.Key_Right or lKey == PySide.QtCore.Qt.Key_Escape: 265 self._completer.popup().hide() 266 self._completerShowing = False 267 elif lKey == PySide.QtCore.Qt.Key_Tab or (lScriptEditorMod and lKey == PySide.QtCore.Qt.Key_Space) : 268 self._currentCompletion = "" 269 self._completer.popup().hide() 270 else : 271 PySide.QtGui.QPlainTextEdit.keyPressEvent(self, event) 272 #Edit completion model 273 colNum = tc.columnNumber() 274 posNum = tc.position() 275 inputText = self.toPlainText() 276 inputTextSplit = inputText.splitlines() 277 runningLength = 0 278 currentLine = None 279 for line in inputTextSplit : 280 length = len(line) 281 runningLength += length 282 if runningLength >= posNum : 283 currentLine = line 284 break 285 runningLength += 1 286 if currentLine : 287 token = currentLine.split(" ")[-1] 288 if "(" in token : 289 token = token.split("(")[-1] 290 self.completeTokenUnderCursor(token) 291 #PySide.QtGui.QPlainTextEdit.keyPressEvent(self, event) 292 return293 297 298 299 305307 308 return 309 310 tc = self.textCursor(); 311 if tc.hasSelection() : 312 313 tc.beginEditBlock() 314 self.ExtendSelectionToCompleteLines(tc) 315 start = tc.selectionStart() 316 end = tc.selectionEnd() 317 tc.setPosition(start) 318 319 320 if self.document().characterAt(start) == '#' : 321 322 #Comment 323 print "Uncommenting" 324 # prevPosition = end 325 # while tc.position() != prevPosition : 326 # tc.insertText("#"); 327 # prevPosition = tc.position() 328 # tc.movePosition(PySide.QtGui.QTextCursor.NextBlock, PySide.QtGui.QTextCursorMoveAnchor) 329 330 else : 331 332 #Uncomment 333 print "Commenting"334 # prevPosition = end 335 # while tc.position() != prevPosition : 336 # if self.document().characterAt(tc.position()) == '#' : 337 # tc.deleteChar() 338 # prevPosition = tc.position() 339 # tc.movePosition(PySide.QtGui.QTextCursor.NextBlock, PySide.QtGui.QTextCursor.MoveAnchor) 340 341 #self.select(start, tc.position()) 342 #tc.endEditBlock() 343 #self.ensureCursorVisible() 344346 347 lPos = tc.position() 348 lAnchor = tc.anchor() 349 tc.setPosition(tc.anchor()); 350 351 if (lPos >= lAnchor) : 352 print "Moving to start of line" 353 #Position was after the anchor. Move to the start of the line, 354 tc.movePosition(PySide.QtGui.QTextCursor.StartOfLine) 355 tc.setPosition(lPos, PySide.QtGui.QTextCursor.KeepAnchor) 356 #Don't extend if the position was at the beginning of a new line 357 lSelected = tc.selectedText() 358 if lSelected != "" and lSelected[-2:-1] != "\n" : 359 tc.movePosition(PySide.QtGui.QTextCursor.EndOfLine, PySide.QtGui.QTextCursor.KeepAnchor) 360 361 else : 362 print "Moving to end of line" 363 #Position was before the anchor. Move to the end of the line, 364 #then select to the start of the line where the position was. 365 #Don't select to the end of the current line if the anchor was at the beginning 366 tc.movePosition(PySide.QtGui.QTextCursor.PreviousCharacter,PySide.QtGui.QTextCursor.KeepAnchor) 367 lSelected = tc.selectedText() 368 tc.movePosition(PySide.QtGui.QTextCursor.NextCharacter) 369 if lSelected != "" and lSelected[-2:-1] != "\n" : 370 tc.movePosition(PySide.QtGui.QTextCursor.EndOfLine) 371 tc.setPosition(lPos, PySide.QtGui.QTextCursor.KeepAnchor) 372 tc.movePosition(PySide.QtGui.QTextCursor.StartOfLine, PySide.QtGui.QTextCursor.KeepAnchor)373 374376 377 print "Need to fix indenting" 378 379 return 380 381 tc = self.textCursor() 382 if tc.hasSelection() : 383 start = tc.selectionStart() 384 self.ExtendSelectionToCompleteLines(tc) 385 selected = tc.selectedText() 386 387 self.insertIndent(tc) 388 389 #replace paragraph things here 390 paraReplace = "\n" + ("\t") 391 indentedParas = selected.replace('\n', paraReplace) 392 393 textSplit = selected.splitlines() 394 indentedText = paraReplace.join(textSplit) 395 396 tc.beginEditBlock() 397 tc.removeSelectedText() 398 tc.insertText(indentedText) 399 tc.endEditBlock() 400 401 print "Need to fix selection after indenting" 402 403 self.setTextCursor(tc) 404 405 406 407 end = tc.selectionEnd() 408 409 tc.setPosition(start) 410 tc.setPosition(end, PySide.QtGui.QTextCursor.KeepAnchor) 411 412 413 414 self.ensureCursorVisible()415417 print "Need to fix unindenting" 418 return 419 420 tc = self.textCursor() 421 if (tc.hasSelection()) : 422 start = tc.selectionStart() 423 self.ExtendSelectionToCompleteLines(tc) 424 return 425 selected = tc.selectedText() 426 427 #Get rid of indents 428 textSplit = selected.splitlines() 429 unsplitLines = [] 430 unindentedText = selected 431 432 for line in textSplit : 433 print type(line) 434 unsplitLines.append(line.replace('\t', '', 1)) 435 436 unindentedText = "\n".join(unsplitLines) 437 438 tc.beginEditBlock() 439 tc.removeSelectedText() 440 tc.insertText(unindentedText) 441 tc.endEditBlock() 442 end = tc.selectionEnd() 443 444 tc.setPosition(start) 445 tc.setPosition(end, PySide.QtGui.QTextCursor.KeepAnchor) 446 447 #tc.select(start, tc.position()) 448 449 self.setTextCursor(tc) 450 451 self.ensureCursorVisible()452454 comp = rlcompleter.Completer() 455 completions = [] 456 completion = 1 457 for x in range(0, 1000): 458 completion = comp.complete(token, x) 459 if completion is not None: 460 completions.append(completion) 461 else : 462 break 463 return completions464466 467 #Clean token 468 token = token.lstrip().rstrip() 469 470 completionList = self.completionsForToken(token) 471 if len(completionList) == 0 : 472 return 473 474 #Set model for _completer to completion list 475 self._completer.model().setStringList(completionList) 476 477 #Set the prefix 478 self._completer.setCompletionPrefix(token) 479 480 #Check if we need to make it visible 481 if self._completer.popup().isVisible() : 482 rect = self.cursorRect(); 483 rect.setWidth(self._completer.popup().sizeHintForColumn(0) + self._completer.popup().verticalScrollBar().sizeHint().width()) 484 self._completer.complete(rect) 485 return 486 487 #Make it visible 488 if len(completionList) == 1 : 489 self.insertCompletion(completionList[0]); 490 else : 491 rect = self.cursorRect(); 492 rect.setWidth(self._completer.popup().sizeHintForColumn(0) + self._completer.popup().verticalScrollBar().sizeHint().width()) 493 self._completer.complete(rect) 494 495 return496498 if completion : 499 completionNoToken = completion[len(self._completer.completionPrefix()):] 500 lCursor = self.textCursor() 501 lCursor.insertText(completionNoToken) 502 return503 506 507 # void ScriptInputArea::insertCompletion(const QString& completion) 508 # { 509 # QString suffix = completion; 510 # suffix.remove(0, _completer->completionPrefix().length()); 511 # QTextCursor lCursor = textCursor(); 512 # lCursor.insertText(suffix); 513 # } 514 516 finalLine = None 517 for line in tracebackStr.split('\n') : 518 if 'File "<string>", line' in line : 519 finalLine = line 520 if finalLine == None : 521 return 0 522 try : 523 errorLine = finalLine.split(',')[1].split(' ')[2] 524 return errorLine 525 except : 526 return 0529 _selection = False; 530 self.highlightCurrentLine() 531 532 #Get text 533 text = self.toPlainText() 534 535 #Check if we've got some text selected. If so, replace text with selected text 536 tc = self.textCursor() 537 if tc.hasSelection() : 538 _selection = True 539 rawtext = tc.selectedText() 540 rawSplit = rawtext.splitlines() 541 rawJoined = '\n'.join(rawSplit) 542 text = rawJoined.lstrip().rstrip() 543 544 #Fix syntax error if last line is a comment with no new line 545 if not text.endswith('\n') : 546 text = text + '\n' 547 548 #JERRY has a lock here 549 550 #Compile 551 result = None 552 compileSuccess = False 553 runError = False 554 555 try : 556 compiled = compile(text, '<string>', 'exec') 557 compileSuccess = True 558 except Exception,e: 559 result = traceback.format_exc() 560 runError = True 561 compileSuccess = False 562 563 oldStdOut = sys.stdout 564 if compileSuccess : 565 #Override stdout to capture exec results 566 buffer = StringIO() 567 sys.stdout = buffer 568 try : 569 exec(compiled, globals()) 570 except Exception,e: 571 runError = True 572 result = traceback.format_exc() 573 else : 574 result = buffer.getvalue() 575 sys.stdout = oldStdOut 576 #print "STDOUT Restored" 577 578 #Update output 579 self._output.updateOutput( text ) 580 self._output.updateOutput( "\n# Result: \n" ) 581 self._output.updateOutput( result ) 582 self._output.updateOutput( "\n" ) 583 584 if runError : 585 #print "There was an error" 586 #print "result is %s " % result 587 self._errorLine = self.getErrorLineFromTraceback(result) 588 self.highlightErrorLine()589 590 #Need to add in the proper methods here749593 594 super(InputHighlighter, self).__init__(parent) 595 596 self.setDocument(doc) 597 598 self._rules = [] 599 self._keywords = PySide.QtGui.QTextCharFormat() 600 self._strings = PySide.QtGui.QTextCharFormat() 601 self._stringSingleQuotes = PySide.QtGui.QTextCharFormat() 602 self._comment = PySide.QtGui.QTextCharFormat() 603 self._blinkFuncs = PySide.QtGui.QTextCharFormat() 604 self._blinkTypes = PySide.QtGui.QTextCharFormat() 605 606 self._keywords.setForeground(kwdsFgColour) 607 self._keywords.setFontWeight(PySide.QtGui.QFont.Bold) 608 609 #Construct rules for C++ keywords 610 #keywordPatterns = ["\\bchar\\b" , "\\bclass\\b" , "\\bconst\\b" 611 # , "\\bdouble\\b" , "\\benum\\b" , "\\bexplicit\\b" 612 # , "\\bfriend\\b" , "\\binline\\b" , "\\bint\\b" 613 # , "\\blong\\b" , "\\bnamespace\\b" , "\\boperator\\b" 614 # , "\\bprivate\\b" , "\\bprotected\\b" , "\\bpublic\\b" 615 # , "\\bshort\\b" , "\\bsignals\\b" , "\\bsigned\\b" 616 # , "\\bslots\\b" , "\\bstatic\\b" , "\\bstruct\\b" 617 # , "\\btemplate\\b" , "\\btypedef\\b" , "\\btypename\\b" 618 # , "\\bunion\\b" , "\\bunsigned\\b" , "\\bvirtual\\b" 619 # , "\\bvoid\\b" , "\\bvolatile\\b"] 620 #Construct rules for RIP++ keywords 621 keywordPatterns = ["\\bchar\\b" , 622 "\\bclass\\b" , 623 "\\bconst\\b" , 624 "\\bdouble\\b" , 625 "\\benum\\b" , 626 "\\bexplicit\\b" , 627 "\\bfriend\\b" , 628 "\\binline\\b" , 629 "\\bint\\b" , 630 "\\blong\\b" , 631 "\\bnamespace\\b" , 632 "\\boperator\\b" , 633 "\\bprivate\\b" , 634 "\\bprotected\\b" , 635 "\\bpublic\\b" , 636 "\\bshort\\b" , 637 "\\bsigned\\b" , 638 "\\bstatic\\b" , 639 "\\bstruct\\b" , 640 "\\btemplate\\b" , 641 "\\btypedef\\b" , 642 "\\btypename\\b" , 643 "\\bunion\\b" , 644 "\\bunsigned\\b" , 645 "\\bvirtual\\b" , 646 "\\bvoid\\b" , 647 "\\bvolatile\\b", 648 "\\blocal\\b", 649 "\\bparam\\b", 650 "\\bkernel\\b", 651 ] 652 653 for pattern in keywordPatterns: 654 rule = {} 655 rule['pattern'] = pattern 656 rule['format'] = self._keywords 657 self._rules.append(rule) 658 659 #Blink funcs 660 self._blinkFuncs.setForeground(blinkFuncsColour) 661 #self._blinkFuncs.setFontWeight(PySide.QtGui.QFont.Bold) 662 blinkFuncPatterns = ["\\bdefine\\b" , 663 "\\bdefineParam\\b" , 664 "\\bprocess\\b" , 665 "\\binit\\b" , 666 "\\bsetRange\\b" , 667 "\\bsetAxis\\b" , 668 "\\bmedian\\b" , 669 "\\bbilinear\\b" , 670 ] 671 for pattern in blinkFuncPatterns: 672 rule = {} 673 rule['pattern'] = pattern 674 rule['format'] = self._blinkFuncs 675 self._rules.append(rule) 676 677 #Blink types 678 self._blinkTypes.setForeground(blinkTypesColour) 679 #self._blinkTypes.setFontWeight(PySide.QtGui.QFont.Bold) 680 blinkTypesPatterns = ["\\bImage\\b" , 681 "\\beRead\\b" , 682 "\\beWrite\\b" , 683 "\\beEdgeClamped\\b" , 684 "\\beEdgeConstant\\b" , 685 "\\beEdgeNull\\b" , 686 "\\beAccessPoint\\b" , 687 "\\beAccessRanged1D\\b" , 688 "\\beAccessRanged2D\\b" , 689 "\\beAccessRandom\\b" , 690 "\\beComponentWise\\b" , 691 "\\bePixelWise\\b" , 692 "\\bImageComputationKernel\\b" , 693 "\\bint\\b" , 694 "\\bint2\\b" , 695 "\\bint3\\b" , 696 "\\bint4\\b" , 697 "\\bfloat\\b" , 698 "\\bfloat2\\b" , 699 "\\bfloat3\\b" , 700 "\\bfloat4\\b" , 701 "\\bfloat3x3\\b" , 702 "\\bfloat4x4\\b" , 703 "\\bbool\\b" , 704 ] 705 for pattern in blinkTypesPatterns: 706 rule = {} 707 rule['pattern'] = pattern 708 rule['format'] = self._blinkTypes 709 self._rules.append(rule) 710 711 #String Literals 712 self._strings.setForeground(stringLiteralsFgColourDQ) 713 rule = {} 714 rule['pattern'] = "\"([^\"\\\\]|\\\\.)*\"" 715 rule['format'] = self._strings 716 self._rules.append(rule) 717 718 #String single quotes 719 self._stringSingleQuotes.setForeground(stringLiteralsFgColourSQ) 720 rule = {} 721 rule['pattern'] = "'([^'\\\\]|\\\\.)*'" 722 rule['format'] = self._stringSingleQuotes 723 self._rules.append(rule) 724 725 #Comments 726 self._comment.setForeground(commentsFgColour) 727 rule = {} 728 rule['pattern'] = "//[^\n]*" 729 rule['format'] = self._comment 730 self._rules.append(rule)731 732 733735 736 text = str(text) 737 738 for rule in self._rules : 739 expression = rule['pattern'] 740 741 if len(text) > 0 : 742 results = re.finditer(expression, text) 743 744 #Loop through all results 745 for result in results : 746 index = result.start() 747 length = result.end() - result.start() 748 self.setFormat(index, length, rule['format'])764752 super(LineNumberArea, self).__init__(parent) 753 754 self._scriptInputWidget = scriptInputWidget 755 #self.setStyleSheet("QWidget { background-color: blue; }"); 756 self.setStyleSheet("text-align: center;")757759 return PySide.QtCore.QSize(self._scriptInputWidget.lineNumberAreaWidth(), 0)760
Trees | Indices | Help |
|
---|
Generated by Epydoc 3.0.1 on Mon Dec 2 22:44:05 2013 | http://epydoc.sourceforge.net |