Commits

cuciferus committed 5d05ab1

a disparut fereastra care dadeai aduga/evaluare
acu in search daca nu gaseste automat dai direct adauga

  • Participants
  • Parent commits bf042cd
  • Branches old

Comments (0)

Files changed (3)

File .main.py.swp

Binary file modified.
 import sys 
 #de pus si un scor Framingham
 
-class First(QtGui.QMainWindow):
+
+class Evaluare(QtGui.QMainWindow):
     def __init__(self,parent=None):
-        #tre sa fac o clasa care sa sa ocupe de tranzactiile sqlite: verificat daca exista entry
-        #sa faca prepare and stuff
+        self.cnp=0
+        QtGui.QMainWindow.__init__(self,parent)
+        self.startDB()
+        self.setObjectName('Evaluare')
+        self.setWindowTitle('Evaluare')
+        #desktop=QtGui.QDesktopWidget.availableGeometry()
+        #vedem daca chiar vreau sa mut fereastra cand sa creaza
+        self.centralWidget=QtGui.QWidget(self)
+        cauta=QtGui.QLabel('Cauta pacient')
+        self.cautat=QtGui.QLineEdit()
+        self.adauga=QtGui.QPushButton('Adauga')
+        self.rezultat=QtGui.QListWidget()
+        self.adaugaEvaluare_pre=QtGui.QPushButton('Pacient Predializa')
+        self.adaugaEvaluare_sga=QtGui.QPushButton('Evaluare SGA')
+        self.adaugaEvaluare_adresa=QtGui.QPushButton('Completare adresa Pacient') #TODO later
+        layout=QtGui.QGridLayout()
+        layout.addWidget(cauta)
+        layout.addWidget(self.cautat)
+        layout.addWidget(self.adauga)
+        layout.addWidget(self.rezultat)
+        layout.addWidget(self.adaugaEvaluare_pre)
+        layout.addWidget(self.adaugaEvaluare_sga)
+        layout.addWidget(self.adaugaEvaluare_adresa)
+        self.centralWidget.setLayout(layout)
+        self.setCentralWidget(self.centralWidget)
+        self.connect(self.adauga, QtCore.SIGNAL('clicked()'), self.pacient)
+        self.connect(self.cautat,QtCore.SIGNAL('textChanged(const QString &)'), self.textChangedHandler)
+        #self.connect(self.cautat,QtCore.SIGNAL('returnPressed()'),self.cauta,QtCore.SLOT('click()'))
+        #ma intreb daca linia de sus mai are rost--de vazut
+        self.connect(self.adaugaEvaluare_pre, QtCore.SIGNAL('clicked()'),\
+            lambda:self.adaugaEvaluare_f(self.cnp,"pre"))
+        self.connect(self.adaugaEvaluare_adresa, QtCore.SIGNAL('clicked()'),\
+            lambda:self.adaugaEvaluare_f(self.cnp,"adresa"))
+        self.connect(self.adaugaEvaluare_sga, QtCore.SIGNAL('clicked()'),\
+            lambda:self.adaugaEvaluare_f(self.cnp,"sga"))
+        self.show()
+
+    def pacient(self):
+        self.hide()
+        self.pacient_d=Pacient(self.query,self.cautat.text(),self)
+        self.show()
+
+    def startDB(self):
         self.pacientidb=QtSql.QSqlDatabase.addDatabase("QSQLITE") #TODO: overwrite closeEvent to close database connection
         self.pacientidb.setDatabaseName('data.db') #TODO with pacientidb.close(self?)
         if not self.pacientidb.open():#asta trebe aplicata la fiecare operatiune?
                         QString("Database Error: %1").arg(self.pacientidb.lastError().text()))
             sys.exit(1)
         self.query=QtSql.QSqlQuery()
-        QtGui.QDialog.__init__(self,parent)
-        self.setWindowTitle('principale')
-        self.centralWidget=QtGui.QWidget(self)
 
-        pacient=QtGui.QPushButton('Adauga pacient')
-        evaluare=QtGui.QPushButton('Evaluare pacient')
-        salvare=QtGui.QPushButton('salveaza online baza de date')
-        salvare.setEnabled(False)
-        layout=QtGui.QHBoxLayout()
-        layout.addWidget(pacient)
-        layout.addWidget(salvare)
-        layout.addWidget(evaluare)
-        self.centralWidget.setLayout(layout)
-        self.setCentralWidget(self.centralWidget)
-        self.connect(pacient, QtCore.SIGNAL('clicked()'),self.pacient)
-        self.connect(evaluare, QtCore.SIGNAL('clicked()'), self.evaluare)
-        
-        self.show()
-    def focusChanged(self):
-        print str(QtGui.QApplication.focusWidget().objectName())
-        print QtGui.QApplication.focusWidget().parentWidget().objectName()
-    def evaluare(self):
-        self.hide()
-        self.evaluare_d=Evaluare(self.query,self)
-        self.show()
-    def pacient(self):
-        self.hide()
-        self.pacient_d=Pacient(self.query,self)
-        self.show()
     def closeEvent(self,event):
         try:
             QtSql.QSqlDatabase.close(self.pacientidb) 
         except:
             print 'nu am inchis baza de date'
             print self.pacientidb.lastError().text()
-            event.ignore()
-class Evaluare(QtGui.QDialog):
-    def __init__(self,query,parent=None):
-        #qcompleter, fuzzy search
-        #fuzzy://code.activestate.com/recipes/475148/
-        self.query=query
-        self.cnp=0
-        QtGui.QDialog.__init__(self,parent)
-        self.setObjectName('Evaluare')
-        self.setWindowTitle('Evaluare')
-        cauta=QtGui.QLabel('Cauta pacient')
-        self.cautat=QtGui.QLineEdit()
-        self.cauta=QtGui.QPushButton('Cauta')
-        self.rezultat=QtGui.QListWidget()
-        self.adaugaEvaluare_pre=QtGui.QPushButton('Pacient Predializa')
-        self.adaugaEvaluare_sga=QtGui.QPushButton('Evaluare SGA')
-        self.adaugaEvaluare_adresa=QtGui.QPushButton('Completare adresa Pacient') #TODO later
-        layout=QtGui.QGridLayout()
-        layout.addWidget(cauta)
-        layout.addWidget(self.cautat)
-        layout.addWidget(self.cauta)
-        layout.addWidget(self.rezultat)
-        layout.addWidget(self.adaugaEvaluare_pre)
-        layout.addWidget(self.adaugaEvaluare_sga)
-        layout.addWidget(self.adaugaEvaluare_adresa)
-        self.setLayout(layout)
-        self.connect(self.cauta, QtCore.SIGNAL('clicked()'), self.cauta_f)
-        self.connect(self.cautat,QtCore.SIGNAL('textChanged(const QString &)'), self.textChangedHandler)
-        self.connect(self.cautat,QtCore.SIGNAL('returnPressed()'),self.cauta,QtCore.SLOT('click()'))
-        self.connect(self.adaugaEvaluare_pre, QtCore.SIGNAL('clicked()'),\
-            lambda:self.adaugaEvaluare_f(self.cnp,"pre"))
-        self.connect(self.adaugaEvaluare_adresa, QtCore.SIGNAL('clicked()'),\
-            lambda:self.adaugaEvaluare_f(self.cnp,"adresa"))
-        self.connect(self.adaugaEvaluare_sga, QtCore.SIGNAL('clicked()'),\
-            lambda:self.adaugaEvaluare_f(self.cnp,"sga"))
-        self.exec_()
+            event.ignore() 
+    def focusChanged(self):
+        print str(QtGui.QApplication.focusWidget().objectName())
+        print QtGui.QApplication.focusWidget().parentWidget().objectName()
 
         
     def veziEval(self):
             cnp=continut[0].text().split('\t')[1]
         else:
             a=QtGui.QErrorMessage(self)
-            a.showMessage(QtCore.QString('cauta si tu pa cineva'))
+            a.showMessage(QtCore.QString('selecteazasi tu pa cineva sau adauga\
+            pacient'))
             a.exec_()
+            return
 
         if tip=="pre":
             self.hide()
 
     
 class Pacient(QtGui.QDialog):
-    def __init__(self,query,parent=None):
+    def __init__(self,query,nume=None,parent=None):
         self.query=query
+        self.numeDat=nume
+
         self.query.exec_("create table  if not exists pacienti (nume varchar(15), prenume varchar(25), data_dializa date,data_diabet date, cnp integer primary key) ")
         #QtGui.QApplication.processEvents()
         QtGui.QDialog.__init__(self,parent)
         self.setObjectName('Pacient')
         nume=QtGui.QLabel('Nume')
         self.nume=QtGui.QLineEdit()
+        self.nume.setText(self.numeDat) #self sau fara self?
         prenume=QtGui.QLabel('Prenume')
         self.prenume=QtGui.QLineEdit()
         cnp=QtGui.QLabel('CNP')
     def __init__(self,argv):
         self.argv=argv
         self.qapp=QtGui.QApplication([self.argv])
-        self.first=First()
+        self.first=Evaluare()
         QtCore.QObject.connect(self.qapp, QtCore.SIGNAL("focusChanged(\
         QWidget *, QWidget*)"), self.first.focusChanged)
 
 #de pus si un scor Framingham
 
 class First(QtGui.QMainWindow):
+#acu asta e inutila o mai las sa vaz totusi daca am uitat ceva in ea dar va fi
+#stearsa cu cruzime
     def __init__(self,parent=None):
         #tre sa fac o clasa care sa sa ocupe de tranzactiile sqlite: verificat daca exista entry
         #sa faca prepare and stuff
             print 'nu am inchis baza de date'
             print self.pacientidb.lastError().text()
             event.ignore()
-class Evaluare(QtGui.QDialog):
-    def __init__(self,query,parent=None):
-        #qcompleter, fuzzy search
-        #fuzzy://code.activestate.com/recipes/475148/
-        self.query=query
+
+class Evaluare(QtGui.QMainWindow):
+    def __init__(self,parent=None):
         self.cnp=0
-        QtGui.QDialog.__init__(self,parent)
+        QtGui.QMainWindow.__init__(self,parent)
+        self.startDB()
         self.setObjectName('Evaluare')
         self.setWindowTitle('Evaluare')
+        #desktop=QtGui.QDesktopWidget.availableGeometry()
+        #vedem daca chiar vreau sa mut fereastra cand sa creaza
+        self.centralWidget=QtGui.QWidget(self)
         cauta=QtGui.QLabel('Cauta pacient')
         self.cautat=QtGui.QLineEdit()
-        self.cauta=QtGui.QPushButton('Cauta')
+        self.adauga=QtGui.QPushButton('Adauga')
         self.rezultat=QtGui.QListWidget()
         self.adaugaEvaluare_pre=QtGui.QPushButton('Pacient Predializa')
         self.adaugaEvaluare_sga=QtGui.QPushButton('Evaluare SGA')
         layout=QtGui.QGridLayout()
         layout.addWidget(cauta)
         layout.addWidget(self.cautat)
-        layout.addWidget(self.cauta)
+        layout.addWidget(self.adauga)
         layout.addWidget(self.rezultat)
         layout.addWidget(self.adaugaEvaluare_pre)
         layout.addWidget(self.adaugaEvaluare_sga)
         layout.addWidget(self.adaugaEvaluare_adresa)
-        self.setLayout(layout)
-        self.connect(self.cauta, QtCore.SIGNAL('clicked()'), self.cauta_f)
+        self.centralWidget.setLayout(layout)
+        self.setCentralWidget(self.centralWidget)
+        self.connect(self.adauga, QtCore.SIGNAL('clicked()'), self.pacient)
         self.connect(self.cautat,QtCore.SIGNAL('textChanged(const QString &)'), self.textChangedHandler)
-        self.connect(self.cautat,QtCore.SIGNAL('returnPressed()'),self.cauta,QtCore.SLOT('click()'))
+        #self.connect(self.cautat,QtCore.SIGNAL('returnPressed()'),self.cauta,QtCore.SLOT('click()'))
+        #ma intreb daca linia de sus mai are rost--de vazut
         self.connect(self.adaugaEvaluare_pre, QtCore.SIGNAL('clicked()'),\
             lambda:self.adaugaEvaluare_f(self.cnp,"pre"))
         self.connect(self.adaugaEvaluare_adresa, QtCore.SIGNAL('clicked()'),\
             lambda:self.adaugaEvaluare_f(self.cnp,"adresa"))
         self.connect(self.adaugaEvaluare_sga, QtCore.SIGNAL('clicked()'),\
             lambda:self.adaugaEvaluare_f(self.cnp,"sga"))
-        self.exec_()
+        self.show()
+
+    def pacient(self):
+        self.hide()
+        self.pacient_d=Pacient(self.query,self.cautat.text(),self)
+        self.show()
+
+    def startDB(self):
+        self.pacientidb=QtSql.QSqlDatabase.addDatabase("QSQLITE") #TODO: overwrite closeEvent to close database connection
+        self.pacientidb.setDatabaseName('data.db') #TODO with pacientidb.close(self?)
+        if not self.pacientidb.open():#asta trebe aplicata la fiecare operatiune?
+            QtGui.QMessageBox.warning(None, "Eroare tati", \
+                        QString("Database Error: %1").arg(self.pacientidb.lastError().text()))
+            sys.exit(1)
+        self.query=QtSql.QSqlQuery()
+
+    def closeEvent(self,event):
+        try:
+            QtSql.QSqlDatabase.close(self.pacientidb) 
+            QtSql.QSqlDatabase.removeDatabase('data.db')
+            event.accept()
+        except:
+            print 'nu am inchis baza de date'
+            print self.pacientidb.lastError().text()
+            event.ignore() 
+    def focusChanged(self):
+        print str(QtGui.QApplication.focusWidget().objectName())
+        print QtGui.QApplication.focusWidget().parentWidget().objectName()
 
         
     def veziEval(self):
         a=str(self.cautat.text().toLower())
         if len(a)>=3:
             a='%'+a+'%'
-            print(a)
             self.query.prepare('select * from pacienti where nume like ?')
             self.query.addBindValue(QtCore.QVariant(a))
             self.query.exec_()
-            self.counter=0
             if self.query.next():
                     self.query.exec_()
-                    self.counter+=1
                     nume,prenume, data_diabet,data_dializa,cnp =range(5)
                     while self.query.next():#a,b,c,d is qstring
                         a=self.query.value(nume).toString()
                         self.cnp=self.query.value(cnp).toString()#[0]
                         final=a+' '+b+'\t'+self.cnp #ma rog....
                         self.rezultat.addItem(final)
-            QtGui.QApplication.processEvents()
-            print self.counter
+
     def cauta_f(self):
         self.rezultat.clear()
         try:
             cnp=continut[0].text().split('\t')[1]
         else:
             a=QtGui.QErrorMessage(self)
-            a.showMessage(QtCore.QString('cauta si tu pa cineva'))
+            a.showMessage(QtCore.QString('selecteazasi tu pa cineva sau adauga\
+            pacient'))
             a.exec_()
+            return
 
         if tip=="pre":
             self.hide()
 
     
 class Pacient(QtGui.QDialog):
-    def __init__(self,query,parent=None):
+    def __init__(self,query,nume=None,parent=None):
         self.query=query
+        self.numeDat=nume
+
         self.query.exec_("create table  if not exists pacienti (nume varchar(15), prenume varchar(25), data_dializa date,data_diabet date, cnp integer primary key) ")
         #QtGui.QApplication.processEvents()
         QtGui.QDialog.__init__(self,parent)
         self.setObjectName('Pacient')
         nume=QtGui.QLabel('Nume')
         self.nume=QtGui.QLineEdit()
+        self.nume.setText(self.numeDat) #self sau fara self?
         prenume=QtGui.QLabel('Prenume')
         self.prenume=QtGui.QLineEdit()
         cnp=QtGui.QLabel('CNP')
     def __init__(self,argv):
         self.argv=argv
         self.qapp=QtGui.QApplication([self.argv])
-        self.first=First()
+        self.first=Evaluare()
         QtCore.QObject.connect(self.qapp, QtCore.SIGNAL("focusChanged(\
         QWidget *, QWidget*)"), self.first.focusChanged)