00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030 from Koo.Search.AbstractSearchWidget import *
00031 from PyQt4.QtGui import *
00032 from PyQt4.QtCore import *
00033
00034 class SelectionSearchWidget(AbstractSearchWidget):
00035 def __init__(self, name, parent, attrs={}):
00036 AbstractSearchWidget.__init__(self, name, parent, attrs)
00037 self.uiCombo = QComboBox( self )
00038 self.uiCombo.setEditable( False )
00039
00040 self.layout = QHBoxLayout( self )
00041 self.layout.addWidget( self.uiCombo )
00042 self.layout.setSpacing( 0 )
00043 self.layout.setContentsMargins( 0, 0, 0, 0 )
00044
00045 self.fill( attrs.get('selection',[] ) )
00046 self.focusWidget = self.uiCombo
00047
00048 def fill(self, selection):
00049
00050 self.uiCombo.addItem( '' )
00051 for (id,name) in selection:
00052 self.uiCombo.addItem( name, QVariant(id) )
00053
00054 def value( self ):
00055 value = self.uiCombo.itemData( self.uiCombo.currentIndex() )
00056 if value.isValid():
00057 return [(self.name,'=',unicode( value.toString() ) )]
00058 else:
00059 return []
00060
00061 def setValue(self, value):
00062 if not value:
00063 self.uiCombo.setCurrentIndex( self.uiCombo.findText('') )
00064 else:
00065 self.uiCombo.setCurrentIndex( self.uiCombo.findData( QVariant(value) ) )
00066
00067 def clear(self):
00068 self.setValue( False )
00069