<div dir="ltr"><div class="gmail_quote"><div dir="ltr">Good afternoon,<div><br></div><div>Following is my code to validate an account code, and add dashes at certain intervals. An example account code is 140-100-1000-6610-543. The code takes the regex: \d{3}-\d{3}-\d{4}-\d{4}-\d{3] and allows the user to type in numbers, and where there is a dash in the regex, it places the dash for the user. Or rather, it should. On our production server (('Qt version:', '4.8.1'), ('SIP version:', '4.13.2'), ('PyQt version:', '4.9.1')) it does work. Our dev server is upgraded to ('Qt version:', '4.8.6'), ('SIP version:', '4.15.5'), ('PyQt version:', '4.10.4') and it doesn't work there.</div><div><br></div><div>On each server, I type in 140. On the production (older version), the line edit value changes to 140-. On the newer version development server, it does not add the dash.</div><div><br></div><div>Please let me know if you see my issue, and let me know if this is a PyQT issue, or a QT issue.</div><div><br></div><div>Thanks in advance!</div><div>Kerri</div><div><br></div><div>CODE:</div><div><br></div><div><div>#!/usr/bin/env python</div><div># vim:set ts=4:set ff=unix</div><div>import sys</div><div>from PyQt4 import QtGui, QtCore</div><div><br></div><div>DEBUG = True</div><div><br></div><div>class acValidator(QtGui.QRegExpValidator):</div><div><br></div><div> def __init__(self, regexp, widget):</div><div> QtGui.QRegExpValidator.__init__(self, regexp, widget)</div><div> self.widget = widget</div><div><br></div><div> def validate(self, text, pos):</div><div> '''function to decide if this account code is valid'''</div><div> valid, _npos = QtGui.QRegExpValidator.validate(self, text, pos)</div><div><br></div><div> if valid != QtGui.QValidator.Acceptable:</div><div> self.fixup(text)</div><div> print 'acWidget.validate result of fixup', text</div><div><br></div><div> # move position to the end, if fixup just added a dash</div><div> # to the end</div><div> newstr = self.widget.text()</div><div> newpos = len(str(newstr))</div><div> if pos + 1 == newpos and newstr[pos:newpos] == '-':</div><div> pos = newpos</div><div><br></div><div> # return the valid variable, and the current position</div><div> return (valid, pos)</div><div><br></div><div> def fixup(self, text):</div><div> '''place dashes, if we can'''</div><div> # pylint: disable=no-member</div><div> if DEBUG:</div><div> print 'acWidget.py fixup'</div><div> reParts = self.regExp().pattern().split('-')</div><div> if DEBUG:</div><div> print list(reParts)</div><div> newreg = ''</div><div> for i in range(len(reParts)):</div><div> newreg += reParts[i]</div><div> if DEBUG:</div><div> print i, reParts[i]</div><div><br></div><div> nr = QtCore.QRegExp(newreg)</div><div> # pylint: disable=no-member</div><div> if nr.exactMatch(text) and not self.regExp().exactMatch(text):</div><div> if DEBUG:</div><div> print 'adding dash'</div><div> text += '-'</div><div> return</div><div><br></div><div> newreg += '-'</div><div><br></div><div> def isValid(self):</div><div> '''return a true or false for the validity based on whether the</div><div> widget is a lineEdit or a comboBox (acCB). true only if the</div><div> validator returns QtGui.QValidator.Acceptable</div><div> '''</div><div> valid, _npos = QtGui.QRegExpValidator.validate(self,</div><div> self.widget.text(),</div><div> self.widget.cursorPosition())</div><div> if valid == QtGui.QValidator.Acceptable:</div><div> return True</div><div><br></div><div> return False</div><div><br></div><div><br></div><div>class acWidget(QtGui.QLineEdit):</div><div><br></div><div> def __init__(self, parent=None):</div><div> QtGui.QLineEdit.__init__(self, parent)</div><div><br></div><div> self.regex = r'\d{3}-\d{3}-\d{4}-\d{4}-\d{3}'</div><div> self.setMinimumWidth(200)</div><div> self.setValidator(acValidator(QtCore.QRegExp(self.regex),</div><div> self))</div><div><br></div><div>if __name__ == '__main__':</div><div><br></div><div> app = QtGui.QApplication(sys.argv)</div><div> form = QtGui.QDialog()</div><div> layout = QtGui.QVBoxLayout(form)</div><div> a = acWidget(form)</div><div> layout.addWidget(a)</div><div> form.setLayout(layout)</div><div> form.setMinimumWidth(400)</div><div> form.setMinimumHeight(200)</div><div> form.show()</div><div> app.exec_()</div></div><span class="HOEnZb"><font color="#888888"><div><br></div><div><div><br></div><div><br></div><div><span style="color:rgb(34,34,34)">-- </span><br></div></div></font></span></div></div><div class="gmail_signature"><div dir="ltr">.·:*¨¨*:·. .·:*¨¨*:·. .·:*¨¨*:·.<br>Yuma Educational Computer Consortium<br>Compass Development Team<br>Kerri Reno<br><a href="mailto:kreno@yumaed.org" target="_blank">kreno@yumaed.org</a> (928) 502-4240<br>.·:*¨¨*:·. .·:*¨¨*:·. .·:*¨¨*:·.<br>I'm so busy I don't know if I found a rope or lost a horse!</div></div>
</div>