00001 ############################################################################## 00002 # 00003 # Copyright (c) 2004 TINY SPRL. (http://tiny.be) All Rights Reserved. 00004 # Fabien Pinckaers <fp@tiny.Be> 00005 # Copyright (c) 2007-2008 Albert Cervera i Areny <albert@nan-tic.com> 00006 # 00007 # WARNING: This program as such is intended to be used by professional 00008 # programmers who take the whole responsability of assessing all potential 00009 # consequences resulting from its eventual inadequacies and bugs 00010 # End users who are looking for a ready-to-use solution with commercial 00011 # garantees and support are strongly adviced to contract a Free Software 00012 # Service Company 00013 # 00014 # This program is Free Software; you can redistribute it and/or 00015 # modify it under the terms of the GNU General Public License 00016 # as published by the Free Software Foundation; either version 2 00017 # of the License, or (at your option) any later version. 00018 # 00019 # This program is distributed in the hope that it will be useful, 00020 # but WITHOUT ANY WARRANTY; without even the implied warranty of 00021 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00022 # GNU General Public License for more details. 00023 # 00024 # You should have received a copy of the GNU General Public License 00025 # along with this program; if not, write to the Free Software 00026 # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 00027 # 00028 ############################################################################## 00029 00030 from Koo.Common import Common 00031 00032 from Koo.Search.AbstractSearchWidget import * 00033 from PyQt4.QtGui import * 00034 from PyQt4.QtCore import * 00035 00036 class BooleanSearchWidget(AbstractSearchWidget): 00037 def __init__(self, name, parent, attrs={}): 00038 AbstractSearchWidget.__init__(self, name, parent, attrs) 00039 self.uiCombo = QComboBox( self ) 00040 self.uiCombo.setEditable( False ) 00041 self.uiCombo.addItem( '', QVariant() ) 00042 self.uiCombo.addItem( _('Yes'), QVariant( True ) ) 00043 self.uiCombo.addItem( _('No'), QVariant( False ) ) 00044 layout = QVBoxLayout( self ) 00045 layout.addWidget( self.uiCombo ) 00046 layout.setSpacing( 0 ) 00047 layout.setContentsMargins( 0, 0, 0, 0 ) 00048 self.focusWidget = self.uiCombo 00049 00050 def value(self): 00051 value = self.uiCombo.itemData( self.uiCombo.currentIndex() ) 00052 if value.type() == QVariant.Bool: 00053 return [(self.name,'=',int(value.toBool()))] 00054 return [] 00055 00056 def clear(self): 00057 self.uiCombo.setCurrentIndex( self.uiCombo.findText('') ) 00058 00059 def setValue(self, value): 00060 self.uiCombo.setCurrentIndex( self.uiCombo.findData( QVariant(value) ) )