Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from appJar import gui
- app=gui("Rubrica Contatti (Spataro Palazzi)")
- app.setOnTop(stay=True)
- app.setResizable(False)
- app.setSize(500,400)
- app.setBg("lightblue")
- l=[]
- i=0
- cont=0
- class Rubrica(object):
- def __init__(self,nome,numero,mail,sesso,categoria):
- self.nome=nome
- self.numero=numero
- self.mail=mail
- self.sesso=sesso
- self.categoria=categoria
- def visualizza(self):
- app.removeAllWidgets()
- app.addLabel("alt","Contatto "+self.nome,0,0)
- app.setLabelBg("alt", "yellow")
- app.addLabel("nome","Nome: "+self.nome,2,0)
- app.addLabel("numero","Numero: "+self.numero,3,0)
- app.addLabel("mail","Mail: "+self.mail,4,0)
- app.addLabel("sesso","Sesso: "+self.sesso,5,0)
- app.addLabel("catego","Categoria: "+self.categoria,6,0)
- app.addButton("Elimina",metodi,8,0)
- app.addButton("Modifica",metodi,9,0)
- app.addNamedButton("<","sss",fai,10,0)
- def modifica(self):
- global cont
- global trov
- global i
- global l
- file=open("rubrica.txt","r")
- tempp=file.readlines()
- file.close()
- coso=tempp
- j=0
- aa=self.nome+","+self.numero+","+self.mail+","+self.sesso+","+self.categoria+",\n"
- for j in range(len(coso)):
- if ((aa) == (coso[j])):
- trov=j
- break
- file=open("categorie_amici.txt","r")
- cosos=file.readlines()
- file.close()
- gho=cosos
- app.removeAllWidgets()
- app.addLabel("A","Modifica Contatto",0,0)
- app.setLabelBg("A", "yellow")
- app.addLabelEntry("Nome",1,0)
- app.setEntry("Nome", self.nome)
- app.addLabelEntry("Numero",2,0)
- app.setEntry("Numero", self.numero)
- app.addLabelEntry("Mail",3,0)
- app.setEntry("Mail", self.mail)
- app.addLabel("esso","Sesso",4,0)
- app.addRadioButton("col", "M")
- app.addRadioButton("col", "F")
- app.setRadioButton("col", self.sesso)
- f=0
- lis=[]
- for f in range(len(gho)):
- bo=gho[f].split(",")
- lis.append(bo[0])
- app.addLabelOptionBox("Categorie",lis,7,0)
- app.addButton("<",fai,9,0)
- app.addButton("Conferma",metodi,9,5)
- def elimina(self):
- global cont
- global i
- global l
- file=open("rubrica.txt","r")
- tempp=file.readlines()
- file.close()
- coso=tempp
- if (len(coso))==1:
- file=open("rubrica.txt","w")
- file.close()
- cont=0
- l=[]
- i=0
- fai()
- else:
- j=0
- aa=self.nome+","+self.numero+","+self.mail+","+self.sesso+","+self.categoria+",\n"
- for j in range(len(coso)):
- if ((aa) == (coso[j])):
- tro=j
- break
- nuovo=open("rubrica.txt","w")
- j=0
- for j in range(len(coso)):
- if j!=(tro):
- nuovo.write(coso[j])
- nuovo.close()
- cont=0
- i=0
- l=[]
- fai()
- def metodi(puls):
- global uy
- global l
- global trov
- global cont
- global i
- if puls=="Elimina":
- l[uy].elimina()
- if puls=="Modifica":
- l[uy].modifica()
- if puls=="Conferma":
- file=open("rubrica.txt","r")
- tempp=file.readlines()
- file.close()
- coso=tempp
- nuovo=open("rubrica.txt","w")
- j=0
- for j in range(len(coso)):
- if j!=(trov):
- nuovo.write(coso[j])
- else:
- nuovo.write(app.getEntry("Nome")+","+app.getEntry("Numero")+","+app.getEntry("Mail")+","+app.getRadioButton("col")+","+app.getOptionBox("Categorie")+",\n")
- nuovo.close()
- cont=0
- i=0
- l=[]
- fai()
- def press3(pp):
- global i
- global ggg
- global uy
- global l
- global cont
- global z
- z=0
- for z in range(i):
- if pp==(str(z)):
- uy=z
- l[uy].visualizza()
- if pp=="Cerca":
- if (len(app.getEntry("Cerc")))==0:
- fdsg=0
- else:
- dd=app.getEntry("Cerc")
- t=dd.lower()
- app.removeAllWidgets()
- app.addLabel("B","Rubrica Contatti by Spataro",0,0)
- app.setLabelBg("B", "yellow")
- app.addEntry("Cerc",1,0)
- app.addButton("Cerca",press3,1,1)
- app.addButton("x",fai,1,2)
- app.setEntry("Cerc", dd)
- k=0
- u=0
- for k in range(i):
- if k==0:
- u=2
- if (t in ((l[k].nome).lower()))==True:
- app.addLabel("c"+str(k),l[k].nome,u+2,0)
- app.setLabelBg("c"+str(k), "orange")
- app.addNamedButton("Visualizza", str(k), press3,u+2,1)
- u=u+1
- app.addButton("Esci",press,u+2,0)
- app.addButton("Svuota Rubrica",press,u+2,1)
- app.addButton("+",press,u+2,5)
- if pp=="Conferma":
- try:
- app.removeLabel("Errore")
- except:
- pass
- k=0
- sbaglio=0
- for k in range(len(ggg)):
- yui=ggg[k].split(",")
- if(app.getEntry("Codice Categoria")==yui[0]):
- sbaglio=1
- app.addLabel("Errore","Errore, Codice già esistente",3,0)
- break
- if sbaglio==0:
- if "," in app.getEntry("Codice Categoria"):
- sbaglio=1
- app.addLabel("Errore","Errore, il codice non può contenere virgole",3,0)
- elif len(app.getEntry("Codice Categoria"))>3:
- sbaglio=1
- app.addLabel("Errore","Errore, codice troppo lungo",3,0)
- elif "," in app.getEntry("Descrizione Categoria"):
- sbaglio=1
- app.addLabel("Errore","Errore, la descrizione non può contenere virgole",3,0)
- elif len(app.getEntry("Descrizione Categoria"))<3:
- sbaglio=1
- app.addLabel("Errore","Errore, descrizione troppo corta",3,0)
- else:
- truma=app.getEntry("Codice Categoria").upper()
- file=open("categorie_amici.txt","a")
- file.write(truma+","+app.getEntry("Descrizione Categoria")+",\n")
- file.close()
- fai()
- def fai():
- global l
- global i
- global cont
- try:
- if cont==0:
- file=open("rubrica.txt","r")
- leggi=file.readlines()
- file.close()
- y=0
- for y in range(len(leggi)):
- temp=leggi[y].split(",")
- l.append("p")
- l[y]=Rubrica(temp[0],temp[1],temp[2],temp[3],temp[4])
- i=i+1
- cont=1
- except:
- pass
- app.removeAllWidgets()
- app.addLabel("B","Rubrica Contatti by Spataro",0,0)
- app.setLabelBg("B", "yellow")
- app.addEntry("Cerc",1,0)
- app.addButton("Cerca",press3,1,1)
- k=0
- u=0
- #print("I:",i)
- for k in range(i):
- if k==0:
- u=2
- #print("K:",k)
- app.addLabel("c"+str(k),l[k].nome,u+2,0)
- app.setLabelBg("c"+str(k), "orange")
- app.addNamedButton("Visualizza", str(k), press3,u+2,1)
- u=u+1
- app.addButton("Aggiungi Categoria",press,u+2,0)
- app.addButton("Aggiungi Contatto",press,u+2,1)
- app.addButton("Svuota Rubrica",press,u+3,0)
- app.addButton("Esci",press,u+3,1)
- def press1(p):
- global l
- global i
- if p=="Conferma":
- l.append("p")
- l[i]=Rubrica(app.getEntry("Nome"),app.getEntry("Numero"),app.getEntry("Mail"),app.getRadioButton("col"),app.getOptionBox("Categorie"))
- i=i+1
- file=open("rubrica.txt","a")
- file.write(app.getEntry("Nome")+","+app.getEntry("Numero")+","+app.getEntry("Mail")+","+app.getRadioButton("col")+","+app.getOptionBox("Categorie")+",\n")
- file.close()
- fai()
- def press(pulsante):
- global ggg
- global l
- global i
- global cont
- if pulsante=="Aggiungi Categoria":
- try:
- file=open("categorie_amici.txt","r")
- temp=file.readlines()
- file.close()
- ggg=temp
- except:
- file=open("categorie_amici.txt","w")
- file.write("S,compagno di studio,\nD,compagno di danza,\nG,compagno di giochi,\nC,compagno del cuore,\n")
- file.close()
- file=open("categorie_amici.txt","r")
- temp=file.readlines()
- file.close()
- ggg=temp
- app.removeAllWidgets()
- app.addLabel("A","Nuova Categoria",0,0)
- app.setLabelBg("A", "lime")
- app.addLabelEntry("Codice Categoria",1,0)
- app.addLabelEntry("Descrizione Categoria",2,0)
- app.addButton("Conferma",press3,4,1)
- app.addButton("<",fai,4,0)
- if pulsante=="Aggiungi Contatto":
- try:
- file=open("categorie_amici.txt","r")
- except:
- file=open("categorie_amici.txt","w")
- file.write("S,compagno di studio,\nD,compagno di danza,\nG,compagno di giochi,\nC,compagno del cuore,\n")
- file.close()
- file=open("categorie_amici.txt","r")
- cosos=file.readlines()
- file.close()
- gho=cosos
- app.removeAllWidgets()
- app.addLabel("A","Nuovo Contatto",0,0)
- app.setLabelBg("A", "orange")
- app.addLabelEntry("Nome",1,0)
- app.addLabelEntry("Numero",2,0)
- app.addLabelEntry("Mail",3,0)
- app.addLabel("esso","Sesso",4,0)
- app.addRadioButton("col", "M")
- app.addRadioButton("col", "F")
- f=0
- lis=[]
- for f in range(len(gho)):
- bo=gho[f].split(",")
- lis.append(bo[0])
- app.addLabelOptionBox("Categorie",lis,7,0)
- app.addButton("<",fai,9,0)
- app.addButton("Conferma",press1,9,5)
- if pulsante=="Esci":
- app.stop()
- if pulsante=="Svuota Rubrica":
- file=open("rubrica.txt","w")
- file.close()
- cont=0
- l=[]
- i=0
- fai()
- fileMenus1 = ["Svuota Rubrica","Esci"]
- app.addMenuList("File", fileMenus1, press)
- fileMenus = ["Aggiungi Contatto", "-", "Aggiungi Categoria"]
- app.addMenuList("Aggiungi", fileMenus, press)
- fai()
- app.go()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement