|
Trouver une ressource
Vous ne trouvez pas de réponse à votre problème ? Alors posez la question dans le forum. Souvenez-vous qu'il n'y a jamais de question bête, mais rester dans l'ignorance parce que l'on n'ose pas poser une question, ça c'est une erreur !
MON REPERTOIRE
Information sur la source
Description
Salut Encore pour mon initiation à wxpython j'ai réalisé cette aplli. Envoyer moi assez de commentaires.Merci
Source
- # -*- coding: cp1252 -*-
-
- #----------------------------------------------------------------------------
- # Name: MyAdresseBook.py
- #
- #
- # Author: Kouakou021988
- #
- # Created:
- # Licence: GNU
- #----------------------------------------------------------------------------
-
- import os
- import gadfly
- import sys
- import wx
- import wx.lib.mixins.listctrl as listmix
- import sha
- import shutil
- from wx.lib.wordwrap import wordwrap
- import SimplePDF_Generateur
-
-
- ID_CONNECT=100
- ID_DECONNECT=101
- ID_NEW=102
- ID_PROPOS=103
- ID_HELP=104
- ID_SEARCH=105
- ID_ENR=106
- ID_IMP=107
- ID_SUPP=108
- ID_SELF=109
-
- passe=0
- refresh=0
- user=""
- cur=""
- connection_ok=0
- apercu=0
- photo=""
- photo_ok=0
- recherche_ok=0
-
-
- def takeId(fich):
- t=open(fich,'r')
- i=t.read()
- t.close()
- return i
-
- def setId(fich,num):
- t=open(fich,'w')
- t.write(num)
- t.close()
- return 1
-
- def codage(txt):
- p=sha.new(txt)
- return p.hexdigest()
-
- def copie(num,path):
- ch,name=os.path.split(path)
- new=ch+"\%s.jpg"%num
- os.rename(path,new)
- shutil.copy2(new,"c:\\MyAddressBook\MyPhoto")
- os.rename(new,path)
- new="c:\\MyAddressBook\MyPhoto\%s.jpg"%num
- return new
-
- def verif(name):
- global cur
- req="select * from UTILISATEUR where user='%s'"%name
- cur.execute(req)
- r=cur.fetchall()
- if len(r): return 1
- else: return 0
-
- class Modif_contact(wx.Frame):
- def __init__(self,info):
- wx.Frame.__init__(self,None,title="::.MyAdressBook.::Modifier un contact",size=(300,250),style=wx.DEFAULT_FRAME_STYLE^(wx.RESIZE_BORDER
- |wx.MAXIMIZE_BOX
- |wx.MINIMIZE_BOX))
- frameicon = wx.Icon("./côte d'ivoire.ico", wx.BITMAP_TYPE_ICO)
- self.SetIcon(frameicon)
- self.panel = wx.Panel(self, -1)
- self.info=info
- self.builder()
-
- def builder(self):
- wx.StaticText(self.panel,-1,"Nom*: ",style=wx.ALIGN_LEFT,pos=(15,15))
- self.nom=wx.TextCtrl(self.panel,-1,self.info[1], size=(150,-1),pos=(100,10))
- wx.StaticText(self.panel,-1,"Prenoms*: ",style=wx.ALIGN_LEFT,pos=(15,50))
- self.prenom=wx.TextCtrl(self.panel,-1,self.info[2],size=(150,-1),pos=(100,45))
- wx.StaticText(self.panel,-1,"Contact I: ",style=wx.ALIGN_LEFT,pos=(15,85))
- self.contact1=wx.TextCtrl(self.panel,-1,self.info[3],size=(150,-1),pos=(100,80))
- wx.StaticText(self.panel,-1,"Contact II: ",style=wx.ALIGN_LEFT,pos=(15,120))
- self.contact2=wx.TextCtrl(self.panel,-1,self.info[4],size=(150,-1),pos=(100,115))
- wx.StaticText(self.panel,-1,"Email: ",style=wx.ALIGN_LEFT,pos=(15,155))
- self.email=wx.TextCtrl(self.panel,-1,self.info[5],size=(150,-1),pos=(100,150))
- b_Ok=wx.Button(self.panel,-1,"OK",pos=(60,180),size=(80,25))
- b_Annuler=wx.Button(self.panel,-1,"Annuler",pos=(150,180),size=(100,25))
- self.Bind(wx.EVT_BUTTON,self.close,b_Annuler)
- self.Bind(wx.EVT_BUTTON,self.modif_contact,b_Ok)
- self.Bind(wx.EVT_CLOSE,self.close)
-
- def modif_contact(self,event):
- global user,cur,refresh,connection_ok
- if self.nom.GetValue().strip()=="" or self.prenom.GetValue().strip()=="":
- dlg=wx.MessageDialog(self, "Veuillez remplir les champs marqués par '*'.Merci",
- caption="::.MyAdressBook.::Modifier un contact",style=wx.OK|wx.ICON_ERROR,pos=wx.DefaultPosition)
- result=dlg.ShowModal()
- dlg.Destroy()
- else:
- i=self.info[0]
- req="""update contact set nom='%s',prenoms='%s',contact1='%s',contact2='%s',email='%s' where id='%s' and user='%s'"""%(self.nom.GetValue().strip().capitalize(),self.prenom.GetValue().strip().capitalize(),
- self.contact1.GetValue().strip(),self.contact2.GetValue().strip(),self.email.GetValue().strip(),i, user)
-
- rep=self.verification([self.nom.GetValue().strip().capitalize(),self.prenom.GetValue().strip().capitalize(),user,self.contact1.GetValue().strip(),self.contact2.GetValue().strip(),self.email.GetValue().strip()])
- if rep:
- dlg=wx.MessageDialog(self, "Ce Contact existe déja.Merci",
- caption="::.MyAdressBook.::Modifier un contact",style=wx.OK|wx.ICON_ERROR,pos=wx.DefaultPosition)
- result=dlg.ShowModal()
- dlg.Destroy()
- else:
- cur.execute(req)
- refresh=1
- connection_ok=1
- self.close(None)
-
- def verification(self,l):
- global cur
- req="select id from contact where nom='%s' and prenoms='%s'and user='%s'and contact1='%s'and contact2='%s'and email='%s'"%(l[0],l[1],l[2],l[3],l[4],l[5])
- cur.execute(req)
- r=cur.fetchall()
- if len(r): return 1
- else: return 0
-
- def close(self,event):
- self.MakeModal(False)
- self.Destroy()
-
- class Apercu(wx.Frame):
- def __init__(self,info):
- wx.Frame.__init__(self,None,-1,title="::.MyAdressBook.::Kouakou021988-Apercu",
- size=(400,250),style=wx.DEFAULT_FRAME_STYLE ^ (wx.RESIZE_BORDER|wx.MAXIMIZE_BOX|wx.MINIMIZE_BOX))
- frameicon = wx.Icon("./côte d'ivoire.ico", wx.BITMAP_TYPE_ICO)
- self.SetIcon(frameicon)
- self.CenterOnParent(wx.BOTH)
- self.SetBackgroundColour("black")
- self.panel=wx.Panel(self,-1,size=self.GetClientSize())
- self.sizer = wx.FlexGridSizer(rows=0, cols=2, hgap=1, vgap=1)
- self.build()
- self.info=info
- self.note()
-
- def build(self):
- self.panelA=wx.Panel(self.panel,-1)
- self.panelA.SetBackgroundColour("black")
- self.sizer.Add(self.panelA, 0, 0)
- lui=self.FindWindowById(self.panelA.GetId())
- lui.SetMinSize((280,250))
- self.panelB=wx.Panel(self.panel,-1)
- self.panelB.SetBackgroundColour("black")
- self.sizer.Add(self.panelB, 0, 1)
- tof=self.FindWindowById(self.panelB.GetId())
- tof.SetMinSize((120,100))
- self.SetSizer(self.sizer)
-
- def note(self):
- font = wx.Font(10, wx.ROMAN,wx.ITALIC, wx.NORMAL)
- nom=wx.StaticText(self.panelA,-1,"Nom: ",style=wx.ALIGN_LEFT,pos=(15,15))
- prenoms=wx.StaticText(self.panelA,-1,"Prenoms: ",style=wx.ALIGN_LEFT,pos=(15,45))
- contact1=wx.StaticText(self.panelA,-1,"Contact I: ",style=wx.ALIGN_LEFT,pos=(15,75))
- contact2=wx.StaticText(self.panelA,-1,"Contact II: ",style=wx.ALIGN_LEFT,pos=(15,110))
- email=wx.StaticText(self.panelA,-1,"Email: ",style=wx.ALIGN_LEFT,pos=(15,145))
- sexe=wx.StaticText(self.panelA,-1,"Sexe: ",style=wx.ALIGN_LEFT,pos=(15,180))
- for i in [nom,prenoms,contact1,contact2,email,sexe]:
- i.SetFont(font)
- i.SetForegroundColour('white')
- self.remplir()
-
- def remplir(self):
- global cur
- req="select photo_path,sexe from contact where id='%s'"%self.info[0]
- cur.execute(req)
- rep=cur.fetchall()[0]
- sexe=rep[1]
- photo_path=rep[0]
- font = wx.Font(12, wx.ROMAN, wx.NORMAL,wx.NORMAL)
- nom=wx.StaticText(self.panelA,-1,self.info[1],style=wx.ALIGN_LEFT,pos=(105,15))
- prenoms=wx.StaticText(self.panelA,-1,self.info[2],style=wx.ALIGN_LEFT,pos=(105,45))
- contact1=wx.StaticText(self.panelA,-1,self.info[3],style=wx.ALIGN_LEFT,pos=(105,75))
- contact2=wx.StaticText(self.panelA,-1,self.info[4],style=wx.ALIGN_LEFT,pos=(105,110))
- email=wx.StaticText(self.panelA,-1,self.info[5],style=wx.ALIGN_LEFT,pos=(105,145))
- sexe=wx.StaticText(self.panelA,-1,sexe,style=wx.ALIGN_LEFT,pos=(105,180))
- for i in [nom,prenoms,contact1,contact2,email,sexe]:
- i.SetFont(font)
- i.SetForegroundColour('white')
- self.photo(photo_path)
-
- def photo(self,path):
- if os.path.exists(path):
- jpg = wx.Image(path, wx.BITMAP_TYPE_ANY)
- tof=jpg.Scale(120,100)
- wx.StaticBitmap(self.panelB, -1, wx.BitmapFromImage(tof))
- self.panelB.Refresh()
-
- class DataBase:
- def __init__(self):
- i=self.existence()
- if i: self.creation()
-
- def existence(self):
- for i in ["c:\\MyAddressBook","c:\\MyAddressBook\MyAddressBook.gfd","c:\\MyAddressBook\UTILISATEUR.grl",
- "c:\\MyAddressBook\CONTACT.grl","c:\\MyAddressBook\MyPhoto"]:
- if not os.path.exists(i):
- return 1
-
- def creation(self):
- self.destructeur()
- os.mkdir("c:\\MyAddressBook")
- os.mkdir("c:\\MyAddressBook\MyPhoto")
- base=gadfly.gadfly()
- base.startup("MyAddressBook","c:\\MyAddressBook")
- cur=base.cursor()
- cur.execute("create table Utilisateur (user varchar,password varchar)")
- cur.execute("create table Contact (id varchar,nom varchar,prenoms varchar,contact1 varchar,contact2 varchar,\
- email varchar,sexe varchar,photo_path varchar,user varchar)")
- base.commit()
- cur.close()
- base.close()
-
- def destructeur(self):
- if sys.platform=="win32":
- s="c:\\MyAddressBook"
- cmd="rmdir %s /S/Q"%s
- a=os.popen(cmd)
- else:
- import glob
- d=glob.glob("c:\\MyAddressBook\*.*")
- for i in d:
- os.unlink(i)
- d=glob.glob("c:\\MyAddressBook\MyPhoto\*.*")
- for i in d:
- os.unlink(i)
- os.rmdir("c:\\MyAddressBook\MyPhoto")
- os.rmdir("c:\\MyAddressBook")
-
- def dbConnection(self):
- global cur
- self.base=gadfly.gadfly("MyAddressBook","c:\\MyAddressBook")
- cur=self.base.cursor()
- self.id_saisie()
-
- def id_saisie(self):
- global cur
- path=open("c:\\MyAddressBook\id.txt",'w')
- cur.execute("select id from CONTACT")
- r=cur.fetchall()
- if len(r)==0:
- path.write(str(1))
- path.close()
- else:
- path.write(str(int(max(r)[0])+1))
- path.close()
-
- def enr(self):
- self.base.commit()
-
- def fermer(self):
- global cur
- cur.close()
- self.base.close()
-
-
- class Recherche(wx.Frame):
- def __init__(self):
- wx.Frame.__init__(self,None,title="::.MyAdressBook.::Rechercher un contact",size=(350,150),style=wx.DEFAULT_FRAME_STYLE^(wx.RESIZE_BORDER
- |wx.MAXIMIZE_BOX
- |wx.MINIMIZE_BOX))
- frameicon = wx.Icon("./côte d'ivoire.ico", wx.BITMAP_TYPE_ICO)
- self.SetIcon(frameicon)
- self.panel = wx.Panel(self, -1)
- self.option=""
- self.builder()
-
- def builder(self):
- wx.StaticText(self.panel,-1,"Recherche: ",style=wx.ALIGN_LEFT,pos=(15,15))
- self.recherche=wx.TextCtrl(self.panel,-1,"", size=(200,-1),pos=(100,10))
- nom= wx.RadioButton(self.panel, -1, " Nom", style =0,pos=(15,50))
- prenoms= wx.RadioButton(self.panel, -1, " Prenoms ",pos=(65,50))
- contact1 = wx.RadioButton(self.panel, -1, " Contact I ",pos=(135,50))
- contact2 = wx.RadioButton(self.panel, -1, " Contact II " ,pos=(205,50))
- email = wx.RadioButton(self.panel, -1, " Email ",pos=(280,50))
- b_Ok=wx.Button(self.panel,-1,"OK",pos=(80,80),size=(80,25))
- b_Annuler=wx.Button(self.panel,-1,"Annuler",pos=(170,80),size=(100,25))
- for eachRadio in [nom,prenoms,contact1,contact2,email]:
- self.Bind(wx.EVT_RADIOBUTTON, self.myOption, eachRadio)
- self.Bind(wx.EVT_BUTTON,self.close,b_Annuler)
- self.Bind(wx.EVT_BUTTON,self.new_recherche,b_Ok)
- self.Bind(wx.EVT_CLOSE,self.close)
-
- def myOption(self,event):
- button=event.GetEventObject()
- self.option=button.GetLabel()
-
- def new_recherche(self,event):
- global cur,user,recherche_ok,connection_ok
- dico={" Nom":"nom"," Prenoms ":"prenoms"," Contact I ":"contact1"," Contact II ":"contact2"," Email ":"email"}
- if not self.option:
- dlg=wx.MessageDialog(self, "Veuillez utiliser une option.Merci",
- caption="::.MyAdressBook.::Rechercher un contact",style=wx.OK|wx.ICON_ERROR,pos=wx.DefaultPosition)
- result=dlg.ShowModal()
- dlg.Destroy()
- else:
- option=dico[self.option]
- req="select id from contact where %s='%s' and user='%s'"%(option,self.recherche.GetValue().strip().capitalize(),user)
- cur.execute(req)
- recherche_ok=1
- self.close(None)
-
- def close(self,event):
- self.MakeModal(False)
- self.Destroy()
-
- class New_contact(wx.Frame):
- def __init__(self):
- wx.Frame.__init__(self,None,title="::.MyAdressBook.::Enregistrer un contact",size=(300,320),style=wx.DEFAULT_FRAME_STYLE^(wx.RESIZE_BORDER
- |wx.MAXIMIZE_BOX
- |wx.MINIMIZE_BOX))
- frameicon = wx.Icon("./côte d'ivoire.ico", wx.BITMAP_TYPE_ICO)
- self.SetIcon(frameicon)
- self.panel = wx.Panel(self, -1)
- self.builder()
- self.sexe=""
-
-
- def builder(self):
- wx.StaticText(self.panel,-1,"Nom*: ",style=wx.ALIGN_LEFT,pos=(15,15))
- self.nom=wx.TextCtrl(self.panel,-1,"", size=(150,-1),pos=(100,10))
- wx.StaticText(self.panel,-1,"Prenoms*: ",style=wx.ALIGN_LEFT,pos=(15,50))
- self.prenom=wx.TextCtrl(self.panel,-1,"",size=(150,-1),pos=(100,45))
- wx.StaticText(self.panel,-1,"Contact I: ",style=wx.ALIGN_LEFT,pos=(15,85))
- self.contact1=wx.TextCtrl(self.panel,-1,"",size=(150,-1),pos=(100,80))
- wx.StaticText(self.panel,-1,"Contact II: ",style=wx.ALIGN_LEFT,pos=(15,120))
- self.contact2=wx.TextCtrl(self.panel,-1,"",size=(150,-1),pos=(100,115))
- wx.StaticText(self.panel,-1,"Email: ",style=wx.ALIGN_LEFT,pos=(15,155))
- self.email=wx.TextCtrl(self.panel,-1,"",size=(150,-1),pos=(100,150))
- wx.StaticText(self.panel,-1,"Photo: ",style=wx.ALIGN_LEFT,pos=(15,190))
- self.photo_path=wx.TextCtrl(self.panel,-1,"",size=(150,-1),pos=(100,185))
- b_photo=wx.Button(self.panel,-1,"...",pos=(250,183),size=(25,25))
- wx.StaticText(self.panel,-1,"Sexe*: ",style=wx.ALIGN_LEFT,pos=(15,220))
- radio_f=wx.RadioButton(self.panel,-1,"Feminin",style=0,pos=(100,220))
- radio_m=wx.RadioButton(self.panel,-1,"Masculin",pos=(180,220))
- b_Ok=wx.Button(self.panel,-1,"OK",pos=(60,250),size=(80,25))
- b_Annuler=wx.Button(self.panel,-1,"Annuler",pos=(150,250),size=(100,25))
- self.Bind(wx.EVT_BUTTON,self.path_photo,b_photo)
- self.Bind(wx.EVT_BUTTON,self.close,b_Annuler)
- self.Bind(wx.EVT_BUTTON,self.new_contact,b_Ok)
- self.Bind(wx.EVT_CLOSE,self.close)
- for eachRadio in [radio_f, radio_m]:
- self.Bind(wx.EVT_RADIOBUTTON, self.sexeChoix, eachRadio)
-
- def path_photo(self,event):
- wildcard = "Ma Photo (*.jpg)|*.jpg|"
- dialog = wx.FileDialog(None, "Photo", os.getcwd(),"", wildcard, wx.OPEN)
- if dialog.ShowModal() == wx.ID_OK:
- self.photo_path.SetValue(dialog.GetPath())
- else:
- self.photo_path=""
- dialog.Destroy()
- self.SetFocus()
-
- def sexeChoix(self,event):
- button=event.GetEventObject()
- self.sexe=button.GetLabel()
-
- def new_contact(self,event):
- global user,cur,refresh,connection_ok
- if self.sexe=="" or self.nom.GetValue().strip()=="" or self.prenom.GetValue().strip()=="":
- dlg=wx.MessageDialog(self, "Veuillez remplir les champs marqués par '*'.Merci",
- caption="::.MyAdressBook.::Enregistrer un contact",style=wx.OK|wx.ICON_ERROR,pos=wx.DefaultPosition)
- result=dlg.ShowModal()
- dlg.Destroy()
- else:
- i=takeId("c:\\MyAddressBook\id.txt")
- if self.photo_path.GetValue()!="":
- mytof=copie(i,self.photo_path.GetValue().strip())
- else: mytof=""
- req="""insert into contact(id,nom,prenoms,contact1,contact2,email,sexe,photo_path,user)values\
- ('%s','%s','%s','%s','%s','%s','%s','%s','%s')"""%(i, self.nom.GetValue().strip().capitalize(),self.prenom.GetValue().strip().capitalize(),
- self.contact1.GetValue().strip(),self.contact2.GetValue().strip(),
- self.email.GetValue().strip(),self.sexe,mytof,
- user)
- rep=self.verification([self.nom.GetValue().strip().capitalize(),self.prenom.GetValue().strip().capitalize(),self.sexe,user])
- if rep:
- dlg=wx.MessageDialog(self, "Ce Contact existe déja.Merci",
- caption="::.MyAdressBook.::Enregistrer un contact",style=wx.OK|wx.ICON_ERROR,pos=wx.DefaultPosition)
- result=dlg.ShowModal()
- dlg.Destroy()
- else:
- cur.execute(req)
- setId("c:\\MyAddressBook\id.txt",str(int(i)+1))
- refresh=1
- connection_ok=1
- self.close(None)
-
- def verification(self,l):
- global cur,user
- req="select id from contact where nom='%s' and prenoms='%s' and sexe='%s' and user='%s'"%(l[0],l[1],l[2],l[3])
- cur.execute(req)
- r=cur.fetchall()
- if len(r): return 1
- else: return 0
-
- def close(self,event):
- self.MakeModal(False)
- self.Destroy()
-
- class New_user(wx.Frame):
- def __init__(self):
- wx.Frame.__init__(self,None,title="::.MyAdressBook.::Nouvel Utilisateur",size=(300,200),style=wx.DEFAULT_FRAME_STYLE^(wx.RESIZE_BORDER
- |wx.MAXIMIZE_BOX
- |wx.MINIMIZE_BOX))
- frameicon = wx.Icon("./côte d'ivoire.ico", wx.BITMAP_TYPE_ICO)
- self.SetIcon(frameicon)
- self.panel = wx.Panel(self, -1)
- self.builder()
-
- def builder(self):
- wx.StaticText(self.panel,-1,"Utilisateur: ",style=wx.ALIGN_LEFT,pos=(15,15))
- self.user=wx.TextCtrl(self.panel,-1,"", size=(150,-1),pos=(140,10))
- wx.StaticText(self.panel,-1,"Mot de passe: ",style=wx.ALIGN_LEFT,pos=(15,50))
- self.passwd1=wx.TextCtrl(self.panel,-1,"",size=(150,-1),pos=(140,45),style=wx.TE_PASSWORD)
- wx.StaticText(self.panel,-1,"Repeter le mot de passe: ",style=wx.ALIGN_LEFT,pos=(15,85))
- self.passwd2=wx.TextCtrl(self.panel,-1,"",size=(150,-1),pos=(140,80),style=wx.TE_PASSWORD)
- b_Ok=wx.Button(self.panel,-1,"OK",pos=(60,130),size=(80,25))
- b_Annuler=wx.Button(self.panel,-1,"Annuler",pos=(150,130),size=(100,25))
- self.Bind(wx.EVT_BUTTON,self.close,b_Annuler)
- self.Bind(wx.EVT_BUTTON,self.new_connection,b_Ok)
- self.Bind(wx.EVT_CLOSE,self.close)
-
- def new_connection(self,event):
- global cur,refresh
- user=self.user.GetValue()
- pass1=self.passwd1.GetValue()
- pass2=self.passwd2.GetValue()
- if pass1==pass2 and not verif(user) and len(pass1)>5:
- req="insert into UTILISATEUR(user,password) values ('%s','%s')"%(user,codage(str(pass1)))
- cur.execute(req)
- refresh=1
- self.close(None)
- else:
- dlg=wx.MessageDialog(self, "Verifier si vous avez entrer le même mot de passe dans les différents champs.\n"+
- "Si le problème persiste changer de login et vérifier si la taille de votre passe est >=6.Merci",
- caption="::.MyAdressBook.::Nouvel Utilisateur",style=wx.OK|wx.ICON_ERROR,pos=wx.DefaultPosition)
- result=dlg.ShowModal()
- dlg.Destroy()
- self.user.Clear()
- self.passwd1.Clear()
- self.passwd2.Clear()
-
- def close(self,event):
- self.MakeModal(False)
- self.Destroy()
-
- class Connection(wx.Frame):
- def __init__(self):
- wx.Frame.__init__(self,None,title="::.MyAdressBook.::Connection",size=(300,150),style=wx.DEFAULT_FRAME_STYLE^(wx.RESIZE_BORDER
- |wx.MAXIMIZE_BOX
- |wx.MINIMIZE_BOX))
- frameicon = wx.Icon("./côte d'ivoire.ico", wx.BITMAP_TYPE_ICO)
- self.SetIcon(frameicon)
- self.panel = wx.Panel(self, -1)
- self.builder()
-
- def builder(self):
- wx.StaticText(self.panel,-1,"Login: ",style=wx.ALIGN_LEFT,pos=(15,15))
- self.user=wx.TextCtrl(self.panel,-1,"", size=(150,-1),pos=(100,10))
- wx.StaticText(self.panel,-1,"Mot de passe:",style=wx.ALIGN_LEFT,pos=(15,50))
- self.passwd=wx.TextCtrl(self.panel,-1,"",size=(150,-1),pos=(100,45),style=wx.TE_PASSWORD)
- b_Ok=wx.Button(self.panel,-1,"OK",pos=(60,80),size=(80,25))
- b_Annuler=wx.Button(self.panel,-1,"Annuler",pos=(150,80),size=(100,25))
- self.Bind(wx.EVT_BUTTON,self.close,b_Annuler)
- self.Bind(wx.EVT_BUTTON,self.connection,b_Ok)
- self.Bind(wx.EVT_CLOSE,self.close)
-
- def connection(self,event):
- global cur,user,connection_ok
- error=0
- u=self.user.GetValue()
- req="""select password from UTILISATEUR where user='%s'"""%u
- cur.execute(req)
- r=cur.fetchall()
- if len(r)==1:
- passwd=r[0]
- if codage(str(self.passwd.GetValue()))==passwd[0]:
- connection_ok=1
- user=u
- self.close(None)
- else: error=1
- else: error=1
- if error:
- dlg=wx.MessageDialog(self, "Votre login ou votre mot de passe est incorrect",
- caption="::.MyAdressBook.::Connection",style=wx.OK|wx.ICON_ERROR,pos=wx.DefaultPosition)
- result=dlg.ShowModal()
- dlg.Destroy()
- self.user.Clear()
- self.passwd.Clear()
- self.user.SetFocus()
-
- def close(self,event):
- self.MakeModal(False)
- self.Destroy()
-
- class AdressListCtrl(wx.ListCtrl, listmix.ListCtrlAutoWidthMixin):
- def __init__(self, parent, ID, pos=wx.DefaultPosition,
- size=wx.DefaultSize, style=0):
- wx.ListCtrl.__init__(self, parent, ID, pos, size, style)
- listmix.ListCtrlAutoWidthMixin.__init__(self)
-
- class ContenuPanel(wx.Panel,listmix.ColumnSorterMixin):
- def __init__(self, parent, log):
- wx.Panel.__init__(self, parent, -1,style=wx.WANTS_CHARS)
- self.log = log
- tID = wx.NewId()
- sizer = wx.BoxSizer(wx.VERTICAL)
-
- self.list=AdressListCtrl(self, tID,style=wx.LC_REPORT | wx.BORDER_SUNKEN
- | wx.LC_SORT_ASCENDING
- | wx.LC_VRULES| wx.LC_HRULES)
- sizer.Add(self.list, 1, wx.EXPAND)
- self.remplissage()
- listmix.ColumnSorterMixin.__init__(self,7)
- self.SetSizer(sizer)
- self.SetAutoLayout(True)
- self.Bind(wx.EVT_LIST_COL_BEGIN_DRAG, self.bloqueColonne, self.list)
- self.list.Bind(wx.EVT_LIST_ITEM_RIGHT_CLICK, self.onClickDroit)
- self.list.Bind(wx.EVT_LIST_ITEM_ACTIVATED, self.double)
- self.Bind(wx.EVT_LIST_ITEM_SELECTED, self.photo, self.list)
- #self.Bind(wx.EVT_ClICK_DOWN,self.photo)
-
- def remplissage(self):
- self.list.InsertColumn(0, "Id")
- self.list.SetColumnWidth(0,0) #Cache de la colonne "id"
- self.list.InsertColumn(1, "photo_path")
- self.list.SetColumnWidth(1,0)
- self.list.InsertColumn(2, "Nom")
- self.list.InsertColumn(3, "Prenoms")
- self.list.SetColumnWidth(3,110)
- self.list.InsertColumn(4, "Contact I (Fixe)")
- self.list.SetColumnWidth(4,100)
- self.list.InsertColumn(5, "Contact II (Cel)")
- self.list.SetColumnWidth(5,100)
- self.list.InsertColumn(6, "Email")
- self.list.SetColumnWidth(6,160)
-
- def GetListCtrl(self):
- return self.list
-
- def bloqueColonne(self, event): #bloque le redimensionnement de la colonne "id" et "phot_path"
- if event.GetColumn() == 0 or event.GetColumn() == 1:
- event.Veto()
-
- def remplir(self,c):
- n=0
- self.itemDataMap=self.gotoDict(c)
- for i in c:
- index = self.list.InsertStringItem(sys.maxint, i[0])
- self.list.SetStringItem(index, 1, i[1])
- self.list.SetStringItem(index, 2, i[2])
- self.list.SetStringItem(index, 3, i[3])
- self.list.SetStringItem(index, 4, i[4])
- self.list.SetStringItem(index, 5, i[5])
- self.list.SetStringItem(index, 6, i[6])
- self.color(n,i[7])
- self.list.SetItemData(index,n)
- n+=1
- #self.SortListItems(2, True) #force un tri à partir de la 2ème colonne
-
- def gotoDict(self,c):
- self.dico={}
- n=0
- for i in c:
- self.dico[n]=(i[0],i[1],i[2],i[3],i[4],i[5],i[6])
- n+=1
- return self.dico
-
- def color(self,u,s):
- item = self.list.GetItem(u)
- if s.upper()=="Masculin".upper():
- item.SetTextColour("blue")
- else: item.SetTextColour("orange")
- self.list.SetItem(item)
-
- def effacer(self):
- self.list.DeleteAllItems()
-
- def getColumnText(self, index, col):
- item = self.list.GetItem(index, col)
- return item.GetText()
-
- def onClickDroit(self, event):
- self.p=event.m_itemIndex #index de la selection
- if not hasattr(self, "popupID1"):
- self.popupID1 = wx.NewId()
- self.popupID2 = wx.NewId()
- self.popupID3 = wx.NewId()
- self.popupID4 = wx.NewId()
-
- self.Bind(wx.EVT_MENU, self.apercu, id=self.popupID1)
- self.Bind(wx.EVT_MENU, self.modification, id=self.popupID2)
- self.Bind(wx.EVT_MENU, self.supp, id=self.popupID4)
- self.Bind(wx.EVT_MENU, self.imp, id=self.popupID3)
-
- menu = wx.Menu()
- menu.Append(self.popupID1, "Aperçu")
- menu.Append(self.popupID2, "Modifier le Contact")
- menu.Append(self.popupID3, "Imprimer Contact")
- menu.Append(self.popupID4, "Supprimer Contact")
- self.PopupMenu(menu)
- menu.Destroy()
-
- def appel(self,i):
- num=self.getColumnText(i, 0)
- nom= self.getColumnText(i, 2)
- prenoms= self.getColumnText(i, 3)
- contact1= self.getColumnText(i, 4)
- contact2=self.getColumnText(i, 5)
- email=self.getColumnText(i, 6)
- tof_path= self.getColumnText(i, 1)
- return [num,nom,prenoms,contact1,contact2,email,tof_path]
-
- def apercu(self,event):
- i=self.appel(self.p)
- fram=Apercu(i)
- fram.CenterOnParent(wx.BOTH)
- fram.Show(True)
-
- def modification(self,event):
- i=self.appel(self.p)
- fram=Modif_contact(i)
- fram.CenterOnParent(wx.BOTH)
- fram.Show(True)
-
- def supp(self,event):
- global cur,user,refresh,connection_ok
- i=self.appel(self.p)
- dlg=wx.MessageDialog(self, "Confirmer la Suppression de ce Contact",
- caption="::.MyAdressBook.::Supprimer ce Contact",style=wx.OK|wx.CANCEL|wx.ICON_QUESTION,pos=wx.DefaultPosition)
- if dlg.ShowModal()==wx.ID_OK:
- req="delete from contact where user='%s' and id='%s'"%(user,i[0])
- cur.execute(req)
- refresh=1
- connection_ok=1
-
- def imp(self,event):
- global user,cur
- i=self.appel(self.p)[0]
- req="select nom,prenoms,contact1,contact2,email,photo_path from contact where user='%s' and id='%s' "%(user,i)
- cur.execute(req)
- rep=cur.fetchall()
- rep.sort()
- pdf=SimplePDF_Generateur.GenPDF_ONE()
- pdf.entete(user)
- pdf.contact(rep)
- pdf.pied()
- name=pdf.generate()
- os.system(name)
-
- def photo(self,event):
- global photo,photo_ok
- self.p=event.m_itemIndex
- lot=self.appel(self.p)
- if len(lot[6])==0:
- photo=""
- else:
- photo=lot[6]
- photo_ok=1
- event.Skip()
-
-
- def double(self,event):
- p=event.m_itemIndex
- i=self.appel(p)
- fram=Apercu(i)
- fram.CenterOnParent(wx.BOTH)
- fram.Show(True)
-
- def marqueur(self,i):
- global connection_ok,passe
- for u in i:
- for s in self.dico.keys():
- if u ==self.dico[s][0]:
- self.list.SetItemState(s, wx.LIST_STATE_SELECTED, wx.LIST_STATE_SELECTED)
- #passe=1
-
-
- class Book(wx.Frame):
- def __init__(self):
- wx.Frame.__init__(self,None,-1,title="::.MyAdressBook.::Kouakou021988",
- size=(800,400),style=wx.DEFAULT_FRAME_STYLE^ (wx.RESIZE_BORDER|wx.MAXIMIZE_BOX))
- frameicon = wx.Icon("./côte d'ivoire.ico", wx.BITMAP_TYPE_ICO)
- self.SetIcon(frameicon)
- self.CenterOnParent(wx.BOTH)
- self.SetBackgroundColour("black")
- self.panel=wx.Panel(self,-1,size=self.GetClientSize())
- self.framesizer=wx.BoxSizer(wx.VERTICAL)
- self.sizer = wx.FlexGridSizer(rows=1, cols=2, hgap=1, vgap=1)
- self.build()
- self.base=DataBase()
- self.base.dbConnection()
- self.onTimer(None)
- self.timer = wx.Timer(self)
- self.timer.Start(1000)
- self.Bind(wx.EVT_TIMER, self.onTimer)
- self.Bind(wx.EVT_CLOSE,self.fermer)
-
- def build(self):
- self.menu_barre()
- self.A_list=ContenuPanel(self.panel,None)
- self.sizer.Add(self.A_list, 0, 0)
- self.panelA=wx.Panel(self.panel,-1,style=wx.BORDER_DOUBLE )
- self.panelA.SetBackgroundColour("white")
- self.sizer.Add(self.panelA, 0, 0)
- tof=self.FindWindowById(self.panelA.GetId())
- lui=self.FindWindowById(self.A_list.GetId())
- lui.SetMinSize((600,325))
- tof.SetMinSize((200,325))
- self.panel.SetSizer(self.sizer)
- self.framesizer.Add(self.panel,1)
- self.SetSizer(self.framesizer)
- self.affiche("IvoryCoast.gif",1)#---->Problème non resolu
-
- def menu_barre(self):
- self.menuFichier=wx.Menu()
- self.menuFichier.Append(ID_NEW,"Nouvel Utilisateur")
- self.menuFichier.Append(ID_CONNECT, "Connection")
- self.menuFichier.Append(ID_DECONNECT, "Deconnection")
- self.menuFichier.Append(ID_ENR, "Enregistrer un contact")
- self.menuFichier.Append(ID_IMP, "Imprimer vos contacts")
- self.menuFichier.Append(ID_SUPP, "Supprimer vos contacts")
- self.menuFichier.Append(ID_SELF, "Supprimer mon compte")
- self.menuFichier.Append(ID_SEARCH, "Recherche")
- self.menuFichier.AppendSeparator()
- self.menuFichier.Append(wx.ID_CLOSE, "Quitter")
- self.verrou([101,105,106])
- menuAide=wx.Menu()
- menuAide.Append(ID_HELP, "Aide")
- menuAide.Append(ID_PROPOS, "A Propos")
- menuBarre=wx.MenuBar()
- menuBarre.Append(self.menuFichier,"Fichier")
- menuBarre.Append(menuAide,"?")
- self.SetMenuBar(menuBarre)
- self.barre=wx.StatusBar(self,-1)
- self.barre.SetFieldsCount(3)
- self.barre.SetStatusWidths([-1,-1,-1])
- self.SetStatusBar(self.barre)
- wx.EVT_MENU(self,wx.ID_CLOSE,self.fermer)
- wx.EVT_MENU(self,ID_CONNECT,self.connection)
- wx.EVT_MENU(self,ID_HELP,self.aide)
- wx.EVT_MENU(self,ID_PROPOS,self.a_propos)
- wx.EVT_MENU(self,ID_NEW,self.user_new)
- wx.EVT_MENU(self,ID_DECONNECT,self.deconnection)
- wx.EVT_MENU(self,ID_SEARCH,self.recherche)
- wx.EVT_MENU(self,ID_ENR,self.enregistrement)
- wx.EVT_MENU(self,ID_IMP,self.impressionContact)
- wx.EVT_MENU(self,ID_SUPP,self.suppContact)
- wx.EVT_MENU(self,ID_SELF,self.suppProfil)
-
- def onTimer(self,event):
- global connection_ok,refresh,user,photo,photo_ok,cur,recherche_ok,passe
- if connection_ok:
- self.active([101,105,106,107,108,109])
- self.verrou([100])
- titre="::.MyAdressBook.::Kouakou021988-Bienvenue %s"%user.capitalize()
- self.SetTitle(titre)
- if connection_ok!=2:
- self.A_list.effacer()
- self.sesame()
- self.Refresh()
- connection_ok=2
-
- if not connection_ok:
- self.SetTitle("::.MyAdressBook.::Kouakou021988")
- self.verrou([101,105,106,107,108,109])
- self.active([100])
- self.A_list.effacer()
-
- if refresh:
- self.base.enr()
- refresh=0
-
- if photo_ok:
- photo_ok=0
- self.p.Destroy()
- del self.p
- if photo=="":
- self.affiche("IvoryCoast.gif")
- else:
- self.affiche(photo)
- photo=""
-
- if recherche_ok:
- rep=[]
- r=cur.fetchall()
- if r:
- for i in r:
- rep.append(i[0])
- self.A_list.effacer()
- self.sesame()
- self.Refresh()
- self.A_list.marqueur(rep)
- recherche_ok=0
- else:
- recherche_ok=0
- dlg=wx.MessageDialog(self, "Aucun resultat.Merci",
- caption="::.MyAdressBook.::Rechercher un contact",style=wx.OK|wx.ICON_ERROR,pos=wx.DefaultPosition)
- result=dlg.ShowModal()
- dlg.Destroy()
- #############################################################################################################################
- def affiche(self,path,n=0):
- if n==0:
- jpg = wx.Image(path, wx.BITMAP_TYPE_ANY)
- tof=jpg.Scale(150,175)
- self.p=wx.StaticBitmap(self.panelA, -1, wx.BitmapFromImage(tof),pos=(20,50))
- self.panelA.Refresh()
-
- else: #Situation de mon problème(si c'est correct alors expliquez moi pourquoi c'est comme ça
- jpg = wx.Image(path, wx.BITMAP_TYPE_ANY)
- tof=jpg.Scale(150,200)
- self.p=wx.StaticBitmap(self.panelA, -1, wx.BitmapFromImage(tof),pos=(625,50))
- self.panelA.Refresh()
- ###############################################################################################################################
- def shutdown(self):
- self.timer.Stop()
- del self.timer
-
- def sesame(self):
- global user,cur
- req="select id,photo_path,nom,prenoms,contact1,contact2,email,sexe from contact where user='%s'"%user
- cur.execute(req)
- rep=cur.fetchall()
- self.A_list.remplir(rep)
- self.barre.SetStatusText(user+" est connecté(e)",1)
- self.barre.SetStatusText("Choix=Connection",2)
-
- def verrou(self,i):
- for o in i:
- self.menuFichier.Enable(o,False)
-
- def active(self,i):
- for o in i:
- self.menuFichier.Enable(o,True)
-
- def fermer(self,event):
- self.barre.SetStatusText("Cliquer pour sortir de l'application",0)
- self.barre.SetStatusText("Choix=Fermer",2)
- self.base.fermer()
- del self.base
- os.unlink("<
|