Thursday, November 4, 2010

variable = not variable

I was going through the book on Qt by Mark Summerfield when I came across this pretty nifty trick that assign True to a variable if its False and vice-versa. I liked it so much that I would like to remember it my whole life so I am posting it here.

variable = not variable

Just test it on your Python interpreter. You would absolutely love it the way I did. Cheers!!!

Thursday, October 28, 2010

Error higlighter.

 This one is for highlighting the error codes in a DNA sequence. It can be used for any string. First an errorIndices method is defined which search for error codes via matching with a list of corrent codes. It then returns the index of the error codes which are then higlighted.

def findErrors(self): 
        errorIndexList = self.errorIndices()

        selectionList = []
               
        for i in errorIndexList:
            selection = QtGui.QTextEdit.ExtraSelection()
            cursor = QtGui.QTextCursor(self.newSeqEdit.document())
            selection.cursor = cursor
            selection.cursor.setPosition(i,QtGui.QTextCursor.MoveAnchor)
            selection.format.setBackground(QtCore.Qt.red)
            selecection.cursor.movePosition(QtGui.QTextCursor.NextCharacter,\
QtGui.QTextCursor.KeepAnchor,1)
            print selection.cursor.selectedText()
            selectionList.append(selection)

        self.newSeqEdit.setExtraSelections(selectionList)