1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59
|
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import sys
from PyQt4 import QtGui, QtCore
class Example(QtGui.QWidget):
def __init__(self):
super(Example, self).__init__()
self.initUI()
def initUI(self):
self.table = QtGui.QTableWidget(1,1, self)
item = QtGui.QTableWidgetItem()
item.setText("")
self.table.setItem(0,0, item)
QtCore.QObject.connect(self.table, QtCore.SIGNAL("cellChanged(int, int)"), self.cellChange)
self.setGeometry(300, 300, 280, 170)
self.show()
def cellChange(self, currentRow, currentColumn):
if self.mon_validateur(self.table.item(currentRow, currentColumn).text()) != False:
return True
self.table.item(currentRow, currentColumn).setText("")
return False
def is_numeric(self, str):
try:
float(str)
except (ValueError, TypeError):
return False
return True
def mon_validateur(self, str):
list_s = str.split(',')
if len(list_s) != 2:
return False
if self.is_numeric(list_s[0]) == False or self.is_numeric(list_s[1]) == False:
return False
return True
def main():
app = QtGui.QApplication(sys.argv)
ex = Example()
sys.exit(app.exec_())
if __name__ == '__main__':
main() |
Partager