<s> """<STR_LIT>""" <EOL> from __future__ import division <EOL> from PyQt4 import QtCore , QtGui <EOL> from vistrails . core import debug <EOL> class QModuleAnnotation ( QtGui . QDialog ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , module , controller , parent = None ) : <EOL> """<STR_LIT>""" <EOL> QtGui . QDialog . __init__ ( self , parent ) <EOL> self . module = module <EOL> self . controller = controller <EOL> self . setModal ( True ) <EOL> self . setWindowTitle ( '<STR_LIT>' ) <EOL> self . setLayout ( QtGui . QVBoxLayout ( ) ) <EOL> self . layout ( ) . setMargin ( <NUM_LIT:0> ) <EOL> self . layout ( ) . setSpacing ( <NUM_LIT:0> ) <EOL> self . scrollArea = QtGui . QScrollArea ( self ) <EOL> self . layout ( ) . addWidget ( self . scrollArea ) <EOL> self . scrollArea . setFrameStyle ( QtGui . QFrame . NoFrame ) <EOL> self . annotationTable = QModuleAnnotationTable ( self . module , <EOL> self . controller , <EOL> self ) <EOL> self . scrollArea . setWidget ( self . annotationTable ) <EOL> self . scrollArea . setWidgetResizable ( True ) <EOL> self . buttonLayout = QtGui . QHBoxLayout ( ) <EOL> self . buttonLayout . setMargin ( <NUM_LIT:5> ) <EOL> self . closeButton = QtGui . QPushButton ( '<STR_LIT>' , self ) <EOL> self . closeButton . setFixedWidth ( <NUM_LIT:100> ) <EOL> self . buttonLayout . addWidget ( self . closeButton ) <EOL> self . closeButton . setShortcut ( '<STR_LIT>' ) <EOL> self . layout ( ) . addLayout ( self . buttonLayout ) <EOL> self . connect ( self . closeButton , QtCore . SIGNAL ( '<STR_LIT>' ) , self . close ) <EOL> class QModuleAnnotationTable ( QtGui . QTableWidget ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , module = None , controller = None , parent = None ) : <EOL> """<STR_LIT>""" <EOL> QtGui . QTableWidget . __init__ ( self , <NUM_LIT:1> , <NUM_LIT:2> , parent ) <EOL> self . read_only = False <EOL> self . setHorizontalHeaderLabels ( [ '<STR_LIT>' , '<STR_LIT>' ] ) <EOL> self . horizontalHeader ( ) . setResizeMode ( QtGui . QHeaderView . Interactive ) <EOL> self . horizontalHeader ( ) . setMovable ( False ) <EOL> self . horizontalHeader ( ) . setStretchLastSection ( True ) <EOL> self . setSortingEnabled ( True ) <EOL> self . setSelectionBehavior ( QtGui . QAbstractItemView . SelectRows ) <EOL> self . verticalHeader ( ) . hide ( ) <EOL> self . delegate = QKeyValueDelegate ( self ) <EOL> self . setItemDelegate ( self . delegate ) <EOL> self . module = module <EOL> self . controller = controller <EOL> self . updateLocked = False <EOL> self . updateModule ( ) <EOL> def set_controller ( self , controller ) : <EOL> self . controller = controller <EOL> def setReadOnly ( self , read_only ) : <EOL> if read_only != self . read_only : <EOL> self . read_only = read_only <EOL> self . setEnabled ( not read_only and self . module is not None ) <EOL> def updateModule ( self , module = None ) : <EOL> """<STR_LIT>""" <EOL> self . module = module <EOL> self . setSortingEnabled ( False ) <EOL> if self . updateLocked : return <EOL> self . clearContents ( ) <EOL> self . setRowCount ( <NUM_LIT:0> ) <EOL> if self . module : <EOL> self . setRowCount ( len ( self . module . annotations ) + <NUM_LIT:1> ) <EOL> curRow = <NUM_LIT:0> <EOL> for annotation in self . module . annotations : <EOL> if annotation . key == '<STR_LIT>' : <EOL> self . setRowCount ( len ( self . module . annotations ) ) <EOL> else : <EOL> self . setItem ( curRow , <NUM_LIT:0> , QtGui . QTableWidgetItem ( annotation . key ) ) <EOL> item = QtGui . QTableWidgetItem ( annotation . value ) <EOL> self . setItem ( curRow , <NUM_LIT:1> , item ) <EOL> curRow += <NUM_LIT:1> <EOL> self . setEnabled ( not self . read_only ) <EOL> else : <EOL> self . setRowCount ( <NUM_LIT:1> ) <EOL> self . setEnabled ( False ) <EOL> self . setItem ( self . rowCount ( ) - <NUM_LIT:1> , <NUM_LIT:0> , QtGui . QTableWidgetItem ( '<STR_LIT>' ) ) <EOL> self . setItem ( self . rowCount ( ) - <NUM_LIT:1> , <NUM_LIT:1> , QtGui . QTableWidgetItem ( '<STR_LIT>' ) ) <EOL> self . setSortingEnabled ( True ) <EOL> def makeItemBold ( self , index ) : <EOL> """<STR_LIT>""" <EOL> oldFont = QtGui . QFont ( self . model ( ) . data ( index , QtCore . Qt . FontRole ) ) <EOL> oldFont . setBold ( True ) <EOL> oldFont . setPointSize ( <NUM_LIT:20> ) <EOL> self . model ( ) . setData ( index , oldFont , QtCore . Qt . FontRole ) <EOL> def lockUpdate ( self ) : <EOL> """<STR_LIT>""" <EOL> self . updateLocked = True <EOL> def unlockUpdate ( self ) : <EOL> """<STR_LIT>""" <EOL> self . updateLocked = False <EOL> def addRow ( self ) : <EOL> """<STR_LIT>""" <EOL> self . setSortingEnabled ( False ) <EOL> self . resizeRowsToContents ( ) <EOL> self . insertRow ( self . rowCount ( ) ) <EOL> self . setItem ( self . rowCount ( ) - <NUM_LIT:1> , <NUM_LIT:0> , <EOL> QtGui . QTableWidgetItem ( '<STR_LIT>' ) ) <EOL> self . setItem ( self . rowCount ( ) - <NUM_LIT:1> , <NUM_LIT:1> , <EOL> QtGui . QTableWidgetItem ( '<STR_LIT>' ) ) <EOL> self . setSortingEnabled ( False ) <EOL> def editNextAvailableCell ( self ) : <EOL> item = self . item ( self . rowCount ( ) - <NUM_LIT:1> , <NUM_LIT:0> ) <EOL> self . editItem ( item ) <EOL> class QKeyValueDelegate ( QtGui . QItemDelegate ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , table ) : <EOL> """<STR_LIT>""" <EOL> self . table = table <EOL> QtGui . QItemDelegate . __init__ ( self , None ) <EOL> def setEditorData ( self , editor , index ) : <EOL> """<STR_LIT>""" <EOL> text = index . data ( QtCore . Qt . DisplayRole ) <EOL> editor . setText ( text ) <EOL> def setModelData ( self , editor , model , index ) : <EOL> """<STR_LIT>""" <EOL> text = str ( editor . text ( ) ) <EOL> row = index . row ( ) <EOL> col = index . column ( ) <EOL> keyItem = self . table . item ( row , <NUM_LIT:0> ) <EOL> if keyItem : <EOL> key = str ( keyItem . text ( ) ) <EOL> else : <EOL> key = '<STR_LIT>' <EOL> valueItem = self . table . item ( row , <NUM_LIT:1> ) <EOL> if valueItem : <EOL> value = str ( valueItem . text ( ) ) <EOL> else : <EOL> value = '<STR_LIT>' <EOL> if col == <NUM_LIT:0> : <EOL> if text == '<STR_LIT>' and row < self . table . rowCount ( ) - <NUM_LIT:1> : <EOL> self . table . removeRow ( row ) <EOL> if self . table . controller and self . table . module : <EOL> self . table . lockUpdate ( ) <EOL> self . table . controller . delete_annotation ( key , <EOL> self . table . module . id ) <EOL> self . table . unlockUpdate ( ) <EOL> return <EOL> if text != '<STR_LIT>' and text != key : <EOL> if ( self . table . module and <EOL> self . table . module . has_annotation_with_key ( text ) ) : <EOL> if text == '<STR_LIT>' : <EOL> QtGui . QMessageBox . information ( None , <EOL> "<STR_LIT>" , <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' ) <EOL> else : <EOL> QtGui . QMessageBox . information ( None , <EOL> "<STR_LIT>" , <EOL> text + '<STR_LIT>' <EOL> '<STR_LIT>' ) <EOL> return <EOL> if col == <NUM_LIT:1> and key == '<STR_LIT>' : <EOL> QtGui . QMessageBox . information ( None , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" ) <EOL> return <EOL> if col == <NUM_LIT:0> and key == '<STR_LIT>' and text != '<STR_LIT>' and value != '<STR_LIT>' : <EOL> self . table . addRow ( ) <EOL> if col == <NUM_LIT:1> : <EOL> if text != value : <EOL> if self . table . controller and self . table . module : <EOL> self . table . lockUpdate ( ) <EOL> self . table . controller . add_annotation ( ( key , text ) , <EOL> self . table . module . id ) <EOL> self . table . unlockUpdate ( ) <EOL> if row == self . table . rowCount ( ) - <NUM_LIT:1> : <EOL> self . table . addRow ( ) <EOL> elif text != '<STR_LIT>' and self . table . controller and self . table . module : <EOL> moduleId = self . table . module . id <EOL> self . table . lockUpdate ( ) <EOL> self . table . controller . previousModuleIds = [ moduleId ] <EOL> if key != text and key != '<STR_LIT>' : <EOL> self . table . controller . delete_annotation ( key , moduleId ) <EOL> self . table . controller . add_annotation ( ( text , value ) , <EOL> moduleId ) <EOL> self . table . unlockUpdate ( ) <EOL> model . setData ( index , text ) </s>
