Advertisement
Guest User

Untitled

a guest
Mar 25th, 2019
109
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 10.40 KB | None | 0 0
  1. from appJar import gui
  2. app=gui("Rubrica Contatti (Spataro Palazzi)")
  3. app.setOnTop(stay=True)
  4. app.setResizable(False)
  5. app.setSize(500,400)
  6. app.setBg("lightblue")
  7. l=[]
  8. i=0
  9. cont=0
  10. class Rubrica(object):
  11. def __init__(self,nome,numero,mail,sesso,categoria):
  12. self.nome=nome
  13. self.numero=numero
  14. self.mail=mail
  15. self.sesso=sesso
  16. self.categoria=categoria
  17. def visualizza(self):
  18. app.removeAllWidgets()
  19. app.addLabel("alt","Contatto "+self.nome,0,0)
  20. app.setLabelBg("alt", "yellow")
  21. app.addLabel("nome","Nome: "+self.nome,2,0)
  22. app.addLabel("numero","Numero: "+self.numero,3,0)
  23. app.addLabel("mail","Mail: "+self.mail,4,0)
  24. app.addLabel("sesso","Sesso: "+self.sesso,5,0)
  25. app.addLabel("catego","Categoria: "+self.categoria,6,0)
  26. app.addButton("Elimina",metodi,8,0)
  27. app.addButton("Modifica",metodi,9,0)
  28. app.addNamedButton("<","sss",fai,10,0)
  29. def modifica(self):
  30. global cont
  31. global trov
  32. global i
  33. global l
  34. file=open("rubrica.txt","r")
  35. tempp=file.readlines()
  36. file.close()
  37. coso=tempp
  38. j=0
  39. aa=self.nome+","+self.numero+","+self.mail+","+self.sesso+","+self.categoria+",\n"
  40. for j in range(len(coso)):
  41. if ((aa) == (coso[j])):
  42. trov=j
  43. break
  44. file=open("categorie_amici.txt","r")
  45. cosos=file.readlines()
  46. file.close()
  47. gho=cosos
  48. app.removeAllWidgets()
  49. app.addLabel("A","Modifica Contatto",0,0)
  50. app.setLabelBg("A", "yellow")
  51. app.addLabelEntry("Nome",1,0)
  52. app.setEntry("Nome", self.nome)
  53. app.addLabelEntry("Numero",2,0)
  54. app.setEntry("Numero", self.numero)
  55. app.addLabelEntry("Mail",3,0)
  56. app.setEntry("Mail", self.mail)
  57. app.addLabel("esso","Sesso",4,0)
  58. app.addRadioButton("col", "M")
  59. app.addRadioButton("col", "F")
  60. app.setRadioButton("col", self.sesso)
  61. f=0
  62. lis=[]
  63. for f in range(len(gho)):
  64. bo=gho[f].split(",")
  65. lis.append(bo[0])
  66. app.addLabelOptionBox("Categorie",lis,7,0)
  67. app.addButton("<",fai,9,0)
  68. app.addButton("Conferma",metodi,9,5)
  69. def elimina(self):
  70. global cont
  71. global i
  72. global l
  73. file=open("rubrica.txt","r")
  74. tempp=file.readlines()
  75. file.close()
  76. coso=tempp
  77. if (len(coso))==1:
  78. file=open("rubrica.txt","w")
  79. file.close()
  80. cont=0
  81. l=[]
  82. i=0
  83. fai()
  84. else:
  85. j=0
  86. aa=self.nome+","+self.numero+","+self.mail+","+self.sesso+","+self.categoria+",\n"
  87. for j in range(len(coso)):
  88. if ((aa) == (coso[j])):
  89. tro=j
  90. break
  91. nuovo=open("rubrica.txt","w")
  92. j=0
  93. for j in range(len(coso)):
  94. if j!=(tro):
  95. nuovo.write(coso[j])
  96. nuovo.close()
  97. cont=0
  98. i=0
  99. l=[]
  100. fai()
  101.  
  102. def metodi(puls):
  103. global uy
  104. global l
  105. global trov
  106. global cont
  107. global i
  108. if puls=="Elimina":
  109. l[uy].elimina()
  110. if puls=="Modifica":
  111. l[uy].modifica()
  112. if puls=="Conferma":
  113. file=open("rubrica.txt","r")
  114. tempp=file.readlines()
  115. file.close()
  116. coso=tempp
  117. nuovo=open("rubrica.txt","w")
  118. j=0
  119. for j in range(len(coso)):
  120. if j!=(trov):
  121. nuovo.write(coso[j])
  122. else:
  123. nuovo.write(app.getEntry("Nome")+","+app.getEntry("Numero")+","+app.getEntry("Mail")+","+app.getRadioButton("col")+","+app.getOptionBox("Categorie")+",\n")
  124. nuovo.close()
  125. cont=0
  126. i=0
  127. l=[]
  128. fai()
  129.  
  130. def press3(pp):
  131. global i
  132. global ggg
  133. global uy
  134. global l
  135. global cont
  136. global z
  137. z=0
  138. for z in range(i):
  139. if pp==(str(z)):
  140. uy=z
  141. l[uy].visualizza()
  142. if pp=="Cerca":
  143. if (len(app.getEntry("Cerc")))==0:
  144. fdsg=0
  145. else:
  146. dd=app.getEntry("Cerc")
  147. t=dd.lower()
  148. app.removeAllWidgets()
  149. app.addLabel("B","Rubrica Contatti by Spataro",0,0)
  150. app.setLabelBg("B", "yellow")
  151. app.addEntry("Cerc",1,0)
  152. app.addButton("Cerca",press3,1,1)
  153. app.addButton("x",fai,1,2)
  154. app.setEntry("Cerc", dd)
  155. k=0
  156. u=0
  157. for k in range(i):
  158. if k==0:
  159. u=2
  160. if (t in ((l[k].nome).lower()))==True:
  161. app.addLabel("c"+str(k),l[k].nome,u+2,0)
  162. app.setLabelBg("c"+str(k), "orange")
  163. app.addNamedButton("Visualizza", str(k), press3,u+2,1)
  164. u=u+1
  165. app.addButton("Esci",press,u+2,0)
  166. app.addButton("Svuota Rubrica",press,u+2,1)
  167. app.addButton("+",press,u+2,5)
  168. if pp=="Conferma":
  169. try:
  170. app.removeLabel("Errore")
  171. except:
  172. pass
  173. k=0
  174. sbaglio=0
  175. for k in range(len(ggg)):
  176. yui=ggg[k].split(",")
  177. if(app.getEntry("Codice Categoria")==yui[0]):
  178. sbaglio=1
  179. app.addLabel("Errore","Errore, Codice già esistente",3,0)
  180. break
  181. if sbaglio==0:
  182. if "," in app.getEntry("Codice Categoria"):
  183. sbaglio=1
  184. app.addLabel("Errore","Errore, il codice non può contenere virgole",3,0)
  185. elif len(app.getEntry("Codice Categoria"))>3:
  186. sbaglio=1
  187. app.addLabel("Errore","Errore, codice troppo lungo",3,0)
  188. elif "," in app.getEntry("Descrizione Categoria"):
  189. sbaglio=1
  190. app.addLabel("Errore","Errore, la descrizione non può contenere virgole",3,0)
  191. elif len(app.getEntry("Descrizione Categoria"))<3:
  192. sbaglio=1
  193. app.addLabel("Errore","Errore, descrizione troppo corta",3,0)
  194. else:
  195. truma=app.getEntry("Codice Categoria").upper()
  196. file=open("categorie_amici.txt","a")
  197. file.write(truma+","+app.getEntry("Descrizione Categoria")+",\n")
  198. file.close()
  199. fai()
  200. def fai():
  201. global l
  202. global i
  203. global cont
  204. try:
  205. if cont==0:
  206. file=open("rubrica.txt","r")
  207. leggi=file.readlines()
  208. file.close()
  209. y=0
  210. for y in range(len(leggi)):
  211. temp=leggi[y].split(",")
  212. l.append("p")
  213. l[y]=Rubrica(temp[0],temp[1],temp[2],temp[3],temp[4])
  214. i=i+1
  215. cont=1
  216. except:
  217. pass
  218. app.removeAllWidgets()
  219. app.addLabel("B","Rubrica Contatti by Spataro",0,0)
  220. app.setLabelBg("B", "yellow")
  221. app.addEntry("Cerc",1,0)
  222. app.addButton("Cerca",press3,1,1)
  223. k=0
  224. u=0
  225. #print("I:",i)
  226. for k in range(i):
  227. if k==0:
  228. u=2
  229. #print("K:",k)
  230. app.addLabel("c"+str(k),l[k].nome,u+2,0)
  231. app.setLabelBg("c"+str(k), "orange")
  232. app.addNamedButton("Visualizza", str(k), press3,u+2,1)
  233. u=u+1
  234.  
  235. app.addButton("Aggiungi Categoria",press,u+2,0)
  236. app.addButton("Aggiungi Contatto",press,u+2,1)
  237. app.addButton("Svuota Rubrica",press,u+3,0)
  238. app.addButton("Esci",press,u+3,1)
  239. def press1(p):
  240. global l
  241. global i
  242. if p=="Conferma":
  243. l.append("p")
  244. l[i]=Rubrica(app.getEntry("Nome"),app.getEntry("Numero"),app.getEntry("Mail"),app.getRadioButton("col"),app.getOptionBox("Categorie"))
  245. i=i+1
  246. file=open("rubrica.txt","a")
  247. file.write(app.getEntry("Nome")+","+app.getEntry("Numero")+","+app.getEntry("Mail")+","+app.getRadioButton("col")+","+app.getOptionBox("Categorie")+",\n")
  248. file.close()
  249. fai()
  250. def press(pulsante):
  251. global ggg
  252. global l
  253. global i
  254. global cont
  255. if pulsante=="Aggiungi Categoria":
  256. try:
  257. file=open("categorie_amici.txt","r")
  258. temp=file.readlines()
  259. file.close()
  260. ggg=temp
  261. except:
  262. file=open("categorie_amici.txt","w")
  263. file.write("S,compagno di studio,\nD,compagno di danza,\nG,compagno di giochi,\nC,compagno del cuore,\n")
  264. file.close()
  265. file=open("categorie_amici.txt","r")
  266. temp=file.readlines()
  267. file.close()
  268. ggg=temp
  269. app.removeAllWidgets()
  270. app.addLabel("A","Nuova Categoria",0,0)
  271. app.setLabelBg("A", "lime")
  272. app.addLabelEntry("Codice Categoria",1,0)
  273. app.addLabelEntry("Descrizione Categoria",2,0)
  274. app.addButton("Conferma",press3,4,1)
  275. app.addButton("<",fai,4,0)
  276. if pulsante=="Aggiungi Contatto":
  277. try:
  278. file=open("categorie_amici.txt","r")
  279. except:
  280. file=open("categorie_amici.txt","w")
  281. file.write("S,compagno di studio,\nD,compagno di danza,\nG,compagno di giochi,\nC,compagno del cuore,\n")
  282. file.close()
  283. file=open("categorie_amici.txt","r")
  284. cosos=file.readlines()
  285. file.close()
  286. gho=cosos
  287. app.removeAllWidgets()
  288. app.addLabel("A","Nuovo Contatto",0,0)
  289. app.setLabelBg("A", "orange")
  290. app.addLabelEntry("Nome",1,0)
  291. app.addLabelEntry("Numero",2,0)
  292. app.addLabelEntry("Mail",3,0)
  293. app.addLabel("esso","Sesso",4,0)
  294. app.addRadioButton("col", "M")
  295. app.addRadioButton("col", "F")
  296. f=0
  297. lis=[]
  298. for f in range(len(gho)):
  299. bo=gho[f].split(",")
  300. lis.append(bo[0])
  301. app.addLabelOptionBox("Categorie",lis,7,0)
  302. app.addButton("<",fai,9,0)
  303. app.addButton("Conferma",press1,9,5)
  304. if pulsante=="Esci":
  305. app.stop()
  306. if pulsante=="Svuota Rubrica":
  307. file=open("rubrica.txt","w")
  308. file.close()
  309. cont=0
  310. l=[]
  311. i=0
  312. fai()
  313.  
  314. fileMenus1 = ["Svuota Rubrica","Esci"]
  315. app.addMenuList("File", fileMenus1, press)
  316. fileMenus = ["Aggiungi Contatto", "-", "Aggiungi Categoria"]
  317. app.addMenuList("Aggiungi", fileMenus, press)
  318. fai()
  319. app.go()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement