Hi guys!
I'm writing my first small application*. For this I'm using Sqlite as database, Glade as GUI builder and Python as coding.
The application is pretty simple: it's a notebook to store names, surnames, adresses, etc.. I've been able to create a first window to store data in Sqlite and a dialog that comes out if some cell are empty (if you forget to put the name).
Now, I want to display in a treeview or listbox what I have in Sqlite and I have to say I can't find any good documentation for this out there. So, can someone help me??
*Which is a first step into a project I have in mind to store pdf, odf and all type of University/office files.
import sqlite3
import sys
import gobject
try:
import pygtk
pygtk.require("2.0")
except:
pass
try:
import gtk
import gtk.glade
except:
sys.exit(1)
connection = sqlite3.connect('rubrypyth.sqlite')
cursor = connection.cursor()
class guyRP:
def __init__(self):
#Set the Glade file
self.gladefile = "Rubrypyth3.glade"
self.wTree = gtk.glade.XML(self.gladefile,"window1")
self.enNam = self.wTree.get_widget("enNam")
self.enSur = self.wTree.get_widget("enSur")
self.enPho = self.wTree.get_widget("enPho")
self.enCel = self.wTree.get_widget("enCel")
self.enEma = self.wTree.get_widget("enEma")
self.enAdd = self.wTree.get_widget("enAdd")
self.treeview=self.wTree.get_widget("treeview1")
self.treemodel=gtk.TreeStore(gobject.TYPE_STRING,gobject.TYPE_STRING)
self.treeview.set_model(self.treemodel)
#Create our dictionay and connect it
dic = { "on_Ok_clicked" : self.btnOk_clicked,
"on_MainWindow_destroy" : gtk.main_quit }
self.wTree.signal_autoconnect(dic)
def insert_row(model,parent,firstcolumn,secondcolumn):
myiter=model.insert_after(parent,None)
model.set_value(myiter,0,firstcolumn)
model.set_value(myiter,1,secondcolumn)
return myiter
def btnOk_clicked(self, widget):
global getNam,getSur,getPho,getCel,getEma,getAdd
getNam = self.enNam.get_text()
getSur=self.enSur.get_text()
getPho=self.enPho.get_text()
getCel=self.enCel.get_text()
getEma=self.enEma.get_text()
getAdd=self.enAdd.get_text()
btnYes_clicked=0
db().EmptyCell(getNam,getSur,getPho,getCel,getEma,getAdd,btnYes_clicked)
class db():
def EmptyCell(self,getNam,getSur,getPho,getCel,getEma,getAdd,btnYes_clicked):
if btnYes_clicked == 1:
self.insert_sqlite(getNam,getSur,getPho,getCel,getEma,getAdd)
elif getNam=="":
self.DialogBoxEmpty()
return getNam,getSur,getPho,getCel,getEma,getAdd
def EmptyCell2(self,btnYes_clicked):
self.insert_sqlite(getNam,getSur,getPho,getCel,getEma,getAdd)
def insert_sqlite(self,getNam,getSur,getPho,getCel,getEma,getAdd):
connection = sqlite3.connect('rubrypyth.sqlite')
cursor = connection.cursor()
sql = "INSERT INTO Rubric (Name,Surname,Phone,Cell,Email,Address) VALUES ('%s','%s','%s','%s','%s','%s')" % (getNam,getSur,getPho,getCel,getEma,getAdd)
cursor.execute(sql)
data = cursor.fetchall()
print data
connection.commit()
connection.close
def DialogBoxEmpty(self):
windows().dialog1(self)
class windows():
def dialog1(self,widget):
self.gladefile = "Rubrypyth3.glade"
self.wTree = gtk.glade.XML(self.gladefile, "dialog1")
self.dialog1 = self.wTree.get_widget("dialog1")
#Create our dictionay and connect it
dic = { "on_No_clicked" : gtk.main_quit,
"on_Yes_clicked" : self.btnYes_clicked,
"on_MainWindow_destroy" : gtk.main_quit }
self.wTree.signal_autoconnect(dic)
def btnYes_clicked(self,widget):
btnYes_clicked=1
self.dialog1.destroy()
db().EmptyCell(getNam,getSur,getPho,getCel,getEma,getAdd,btnYes_clicked)
return btnYes_clicked
if __name__ == "__main__":
hwg = guyRP()
gtk.main()