I'm new into python programming. I'm building an app using python 2.7 and PyQt4. My app is using MariaDB as database server, i have to input some data using a GUI form. That data is displayed on a QTbaleView and i want to make cells editable, and i want to send the modified cell to MariaDB . Basically if the user has entered a wrong value or wants to update the client personal data i want to be able to do it just by double clicking the cell, correct the cell and press return to update it.

I didn't find any example like this, using a .ui file so i can implement it into my code.


This is my main Window:

import sys,os,module,config_read,time,threading,datecs_pr int
from PyQt4 import QtGui, uic ,QtSql,QtCore
import resources



class MyWindow(QtGui.QMainWindow):
def __init__(self):
QtGui.QDialog.__init__(self)
super(MyWindow, self).__init__()
file_path = os.path.abspath("ui/back_office.ui")
uic.loadUi(file_path, self)
self.run_threads()
self.statusBar().showMessage('OptimPos BackOffice. support:admin.unu@protonmail.com')
self.move(QtGui.QApplication.desktop().screen().re ct().center() - self.rect().center())
self.actionIesire.triggered.connect(self.close)
self.actionArticole.triggered.connect(self.run_art icole)
self.command_articole.pressed.connect(self.run_art icole)
self.actionRapoarte_Vanzari.triggered.connect(self .run_raport_vanzari)
self.command_rapoarte.pressed.connect(self.run_rap ort_vanzari)
self.actionLista_Stoc.triggered.connect(self.run_s toc)
self.command_listastoc.pressed.connect(self.run_st oc)
self.actionDespre.triggered.connect(self.run_dialo g_despre)
self.command_parteneri.pressed.connect(self.run_di alog_parteneri)
self.command_receptie.pressed.connect(self.run_rec eptie_marfa)

def run_dialog_parteneri(self):
dialog = module.parteneri.dialog_parteneri()
dialog.exec_()

def run_dialog_despre(self):#despre
dialog = module.despre.despre_dialog()
dialog.exec_()

def run_stoc(self):
dialog = module.lista_stoc.show_lista_stoc()
dialog.exec_()

def run_articole(self):#executa modulul de management articole
dialog = module.articole.gestiune_articole()
dialog.exec_()

def run_raport_vanzari(self):
dialog = module.raport_vanzari.raport_vanzari()
dialog.exec_()

def run_receptie_marfa(self):
dialog = module.receptie.dialog_receptie()
dialog.exec_()

def db_errors(self):#verifica conexiunea bazei de date
if self.db.isOpenError() == True:
lastErrors = self.db.lastError()
time_print = time.strftime("%d/%m/%Y-%H:%M:%S")
file = open("log_db_errors.txt", "a")
file.write(time_print+"---------------------------------->")
file.write(str(lastErrors)+'\n')
file.close()

def db_check_con(self):#afiseaza mesaje de eroare daca nu exista conexiune sql
if self.db.isOpenError() == True:
time_print = time.strftime("%d/%m/%Y-%H:%M:%S")
self.status_main.setText('Eroare comunicatie baza de date. ' + time_print)

def run_db_connection(self):#initializeaza conexiunea qtsql si verifica daca este conectat
user_db = config_read.config_read_user()
pass_db = config_read.config_read_pass()
name_db = config_read.config_read_name()
ip_db = config_read.config_read_ip()
self.db = QtSql.QSqlDatabase.addDatabase("QMYSQL")
self.db.setHostName(ip_db)
self.db.setDatabaseName(name_db)
self.db.setUserName(user_db)
self.db.setPassword(pass_db)
self.db.open()
if self.db.isOpen() == True:
time_print = time.strftime("%d/%m/%Y-%H:%M:%S")
self.statusBar().showMessage('Comunicatie functionala. ' + time_print)
if self.db.isOpenError() == True:
time_print = time.strftime("%d/%m/%Y-%H:%M:%S")
self.statusBar().showMessage('Eroare comunicatie baza de date. ' + time_print)

def run_stocuri(self):#executa lista de stocuri
dialog = module.lista_stoc.show_lista_stoc()
dialog.exec_()

def closeEvent(self,event):#inchide fereastra de vanzare
self.db.close()
self.db = QtSql.QSqlDatabase.removeDatabase("QMYSQL")
self.close()

def run_threads(self):#thread mode pentru anumite functii
t1 = threading.Thread(target=self.run_db_connection())
t1.start()
t1.join()
t2 = threading.Thread(target=self.db_errors())
t2.start()
t2.join()
t12 = threading.Thread(target=self.db_check_con())
t12.start()
t12.join()

if __name__ == '__main__':

app = QtGui.QApplication(sys.argv)
window = MyWindow()
window.show()
# app.exec_()
sys.exit(app.exec_())
This is my parteneri dialog:

import time,os.path, os
from PyQt4 import QtGui, uic,QtSql,QtCore

class dialog_parteneri(QtGui.QDialog):
def __init__(self):
QtGui.QDialog.__init__(self)
file_path = os.path.abspath("ui/parteneri.ui")
uic.loadUi(file_path, self)
self.move(QtGui.QApplication.desktop().screen().re ct().center() - self.rect().center())
self.saveClient_btn.pressed.connect(self.add_parte ners)
self.list_parteners()
self.exitClient_btn.pressed.connect(self.close)
self.clientNou_btn.pressed.connect(self.new_partne r)
self.treeView.doubleClicked.connect(self.select_ro w_parteners)
self.deleteClient_btn.pressed.connect(self.delete_ parteners)

def new_partner(self):
self.nume_firma.setText('')
self.cui_firma.setText('')
self.nrReg_firma.setText('')
self.adresa_firma.setText('')
self.codClient_firma.setText('')
self.telefon_firma.setText('')
self.persoana_firma.setText('')
self.email_firma.setText('')
self.list_parteners()
time_print = time.strftime("%d/%m/%Y-%H:%M:%S")
self.textBrowser.setText('Adaugati un partener nou: =====> ' + time_print)

def select_row_parteners(self):
index = self.treeView.selectionModel().selectedRows()[0]
id_us = self.treeView.model().data(index).toString()
den = unicode(str(id_us))
time_print = time.strftime("%d/%m/%Y-%H:%M:%S")
self.textBrowser.setText('Partener <'+den+'> selectat: =====> ' + time_print)
return den

def delete_parteners(self):
denumire = self.select_row_parteners()
query = QtSql.QSqlQuery()
query.prepare("DELETE FROM parteneri WHERE id ='"+denumire+"';")
query.exec_()
self.list_parteners()
time_print = time.strftime("%d/%m/%Y-%H:%M:%S")
self.textBrowser.setText('Partener eliminat din lista: =====> ' + time_print)

def add_parteners(self):
query = QtSql.QSqlQuery()
numePart = self.nume_firma.displayText()
cuiPart = self.cui_firma.displayText()
nrRegPart = self.nrReg_firma.displayText()
adresaPart = self.adresa_firma.displayText()
codClientPart = self.codClient_firma.displayText()
telPart = self.telefon_firma.displayText()
contactPart = self.persoana_firma.displayText()
emailPart = self.email_firma.displayText()
tvaPart = self.tva_check.isChecked()
if tvaPart == True:
tvaPart1 = '1'
else:
tvaPart1 = '0'
query.prepare("INSERT INTO parteneri (denumire,nr_cui,nr_reg,adresa,cod_client,telefon_ client,pers_contact,email_contact,platitor_tva)"
"VALUES ('"+numePart+"','"+cuiPart+"','"+nrRegPart+"','"+a dresaPart+"','"+codClientPart+"','"+telPart+"','"+ contactPart+"','"+emailPart+"','"+tvaPart1+"');" )
query.exec_()
self.list_parteners()
time_print = time.strftime("%d/%m/%Y-%H:%M:%S")
self.textBrowser.setText('Partener adaugat: =====> ' + time_print)

def list_parteners(self):
self.model = QtSql.QSqlQueryModel()
self.model.setQuery("SELECT id,denumire,nr_cui,nr_reg,adresa,cod_client,telefo n_client,pers_contact,email_contact FROM parteneri;")
self.model.setHeaderData(0, QtCore.Qt.Horizontal, self.tr("Nr.Crt. "))
self.model.setHeaderData(1, QtCore.Qt.Horizontal, self.tr("Partener "))
self.model.setHeaderData(2, QtCore.Qt.Horizontal, self.tr("CUI "))
self.model.setHeaderData(3, QtCore.Qt.Horizontal, self.tr("Nr.Reg. "))
self.model.setHeaderData(4, QtCore.Qt.Horizontal, self.tr("Adresa "))
self.model.setHeaderData(5, QtCore.Qt.Horizontal, self.tr("Cod Client "))
self.model.setHeaderData(6, QtCore.Qt.Horizontal, self.tr("Telefon "))
self.model.setHeaderData(7, QtCore.Qt.Horizontal, self.tr("Persoana Contact"))
self.model.setHeaderData(8, QtCore.Qt.Horizontal, self.tr("Email "))
self.treeView.setModel(self.model)
self.treeView.setSelectionBehavior(QtGui.QAbstract ItemView.SelectRows)
self.treeView.setSelectionMode(QtGui.QAbstractItem View.SingleSelection)
Thank you for your help.