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 from Koo.Common import Common
00030 from Koo.Common import Shortcuts
00031
00032 from Koo.Fields.TranslationDialog import *
00033 from Koo.Fields.AbstractFieldWidget import *
00034 from PyQt4.QtCore import *
00035 from PyQt4.QtGui import *
00036
00037
00038 class CharFieldWidget(AbstractFieldWidget):
00039 def __init__(self, parent, view, attrs={}):
00040 AbstractFieldWidget.__init__(self, parent, view, attrs)
00041
00042 self.widget = QLineEdit( self )
00043 self.widget.setSizePolicy( QSizePolicy.Preferred, QSizePolicy.Fixed )
00044 if 'size' in attrs:
00045 self.widget.setMaxLength( int( attrs['size'] ) )
00046 if 'password' in attrs:
00047 self.widget.setEchoMode( QLineEdit.Password )
00048
00049
00050
00051
00052 self.setFocusProxy( self.widget )
00053 self.installPopupMenu( self.widget )
00054
00055 layout = QHBoxLayout( self )
00056 layout.setContentsMargins( 0, 0, 0, 0 )
00057 layout.addWidget( self.widget )
00058
00059 if attrs.get('translate', False):
00060 pushTranslate = QToolButton( self )
00061 pushTranslate.setIcon( QIcon( ':/images/locale.png' ) )
00062 pushTranslate.setFocusPolicy( Qt.NoFocus )
00063 layout.addWidget( pushTranslate )
00064 self.connect( pushTranslate, SIGNAL('clicked()'), self.translate )
00065
00066 self.scTranslate = QShortcut( self.widget )
00067 self.scTranslate.setKey( Shortcuts.SearchInField )
00068 self.scTranslate.setContext( Qt.WidgetShortcut )
00069 self.connect( self.scTranslate, SIGNAL('activated()'), self.translate )
00070
00071 self.connect( self.widget, SIGNAL('editingFinished()'), self.store )
00072
00073 def translate(self):
00074 if not self.record.id:
00075 QMessageBox.information( self, _('Translation dialog'), _('You must save the resource before adding translations'))
00076 return
00077 dialog = TranslationDialog( self.record.id, self.record.group.resource, self.attrs['name'], unicode(self.widget.text()), TranslationDialog.LineEdit, self )
00078 if dialog.exec_() == QDialog.Accepted:
00079 self.setText( dialog.result )
00080
00081 def storeValue(self):
00082
00083
00084 if not self.record:
00085 return
00086 self.record.setValue( self.name, unicode(self.widget.text()) or False )
00087
00088 def clear(self):
00089 self.widget.clear()
00090 self.widget.setToolTip('')
00091
00092 def showValue(self):
00093 self.setText( self.record.value(self.name) or '' )
00094
00095 def setText(self, text):
00096 self.widget.setCursorPosition( 0 )
00097 self.widget.setText( text )
00098 self.widget.setToolTip( text )
00099
00100 def setReadOnly(self, value):
00101 AbstractFieldWidget.setReadOnly(self, value)
00102 self.widget.setReadOnly( value )
00103
00104 def colorWidget(self):
00105 return self.widget
00106