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 PyQt4.QtCore import * 00031 from PyQt4.QtGui import * 00032 00033 ## @brief AbstractFieldWidget is the base class for all search widgets in Koo. 00034 # In order to create a new search widget, that is: a widget that appears in a 00035 # auto-generated search form you need to inherit from this class and implement some 00036 # of it's functions. 00037 class AbstractSearchWidget(QWidget): 00038 ## @brief Creates a new AbstractSearchWidget and receives the following parameters 00039 # 00040 # Note that a class that inherits AbstractSearchWidget should set self.focusWidget 00041 # which by default equals 'self'. 00042 # 00043 # name: The name of the field 00044 # parent: The QWidget parent of this QWidget 00045 # attributes: Holds some extra attributes 00046 # 00047 def __init__(self, name, parent, attrs={}): 00048 QWidget.__init__(self, parent) 00049 self._value = None 00050 self.name = name 00051 self.model = attrs.get('model', None) 00052 self.attrs = attrs 00053 self.focusWidget = self 00054 00055 def eventFilter( self, target, event ): 00056 if event.type() == QEvent.KeyPress and event.key() == Qt.Key_Down: 00057 self.emit( SIGNAL('keyDownPressed()') ) 00058 return True 00059 return False 00060 00061 ## @brief Sets the focus to the widget 00062 def setFocus(self): 00063 self.focusWidget.setFocus() 00064 00065 ## @brief Clears the value of the widget 00066 # New widgets should override this function. 00067 def clear(self): 00068 pass 00069 00070 ## @brief Returns a domain-like list for the current value in the widget. 00071 # New widgets should override this function. 00072 def value(self): 00073 return [] 00074 00075 ## @brief Sets the given value in the search field. 00076 # New widgets should override this function. 00077 def setValue(self, value): 00078 pass 00079