def loadConfig(self): try: pp.printGreen("Loading config file for client " + self.name + " ...") self.config = configparser.ConfigParser() self.config.read('./Config/' + self.name + ".dat") section = "1" for section in self.config.sections(): print("[" + section + "]") if section != "info": for key in self.config[section]: print(" " + key + ":" + str(self.config[section][key])) aNewFacture = Facture.Facture (section,self.name,\ str(self.config[section]["editionDate"]),\ str(self.config[section]["dueDate"]),\ self.config[section]["amount"],\ self.config[section]["paid"]) self.factureList.append(aNewFacture) self.factureList.sort(key=lambda fac: fac.editionDate) self.lastFactureId = int(section) pp.printGreen("Done") except: pp.printError("Unable to open config file for " + self.name) pp.printError(traceback.format_exc())
def callbackGen(self, event): theClient = event.widget.master.nametowidget( ".placeHolder.maListe").get(ACTIVE) print("Generating the doc ") event.widget.master.config(cursor="watch") try: aWritter = FactureWritter(self.clientList[theClient]) gentime = aWritter.printFacture() except Exception as e: pp.printError("I have fail") pp.printError(e) pp.printError(traceback.format_exc()) messagebox.showerror("Erreur", str(e)) event.widget.master.config(cursor="arrow") return for aFac in self.clientList[theClient].factureList: print(aFac.toString()) pp.printGreen("Generating the doc : OK!") event.widget.master.config(cursor="arrow") messagebox.showinfo( "Info", "Facture créé avec succés (en " + str(gentime) + ")") self.clientList[theClient].toConfig(True)
def loadConfigFile(): pp.printGreen("Loading config file ...") config = configparser.ConfigParser(defaults=None, dict_type=collections.OrderedDict, allow_no_value=True) config.read('Config\\config.dat') for section in config.sections(): print("[" + section + "]") for key in config[section]: print(" " + key + ":" + str(config[section][key])) pp.printGreen("Done") return config
def refreshFactureDetails(self, event): pp.printGreen("Refresh facture details") if event: self.activeFacture = event.widget.get(ACTIVE) theList = self.master.nametowidget(".placeHolder.maListeFacDetails") for aFact in self.clientList[self.activeClient].factureList: if str(aFact.numberId + "-" + aFact.editionDate) == self.activeFacture: theList.delete(0, END) theList.insert(END, aFact.numberId) theList.insert(END, aFact.editionDate) theList.insert(END, aFact.dueDate) theList.insert(END, aFact.amount) if aFact.isPaid: theList.insert(END, "V") else: theList.insert(END, "X") break
def saveBeforeDestroy(): global configFile global clientList try: os.remove("./Config/config.old") except: print("No old config file to rm") try: os.rename("./Config/config.dat", "./Config/config.old") except: print("No config file to backup") with open('./Config/config.dat', 'w') as configfile: configFile.write(configfile) pp.printGreen("Config file save") for client in clientList: print("Saving Client " + client) clientList[client].toConfig(True) pp.printGreen("Clients file save") toplevel.destroy()
def callbackGen(self, event): isError = False pp.printGreen("Generating the doc ") event.widget.master.config(cursor="watch") numberOfClient = len(self.clientListVar) self.progresBar.grid() for aClient in self.clientListVar: self.progressGen.set(self.progressGen.get() + 1) if self.clientListVar[aClient].get(): try: pp.printGreen(" " + aClient) aWritter = FactureWritter(self.clientList[aClient]) gentime = aWritter.printFacture() except Exception as e: pp.printError("I have fail") pp.printError(e) pp.printError(traceback.format_exc()) messagebox.showerror("Erreur", str(e)) event.widget.master.config(cursor="arrow") self.progressGen.set(self.progressGen.get() + 1) isError = True continue self.clientList[aClient].toConfig(True) self.progressGen.set(self.progressGen.get() + 1) else: self.progressGen.set(self.progressGen.get() + 1) event.widget.master.config(cursor="arrow") if isError: pp.printWarning(" Erreur durant la génération") messagebox.showerror( "Warning", "Probléme durant laa génération des factures") else: messagebox.showinfo("Info", "Facture créé avec success") self.progresBar.grid_remove()
def drawScreen(self): # Toolbar rowIndex = 1 photo1 = PhotoImage(file="Ressources/30143-xsara54-Parametres.gif") nP1 = photo1.subsample(4, 4) w1 = Label(self.master, image=nP1, text="Générer facture", compound="top") w1.bind("<Button-1>", self.callbackGen) w1.photo = photo1 w1.grid(row=rowIndex, padx=20) rowIndex = rowIndex + 1 photo2 = PhotoImage(file="Ressources/tickAction.gif") nP2 = photo2.subsample(4, 4) w2 = Label(self.master, image=nP2, text="(dé)selectioner tous", compound="top") w2.bind("<Button-1>", self.switchAll) w2.photo = photo2 w2.grid(row=rowIndex, padx=20) #Avoid photo to be destroy by garbage collector self.listPhoto.append(nP1) self.listPhoto.append(nP2) aFakeLabel = Label(self.master, text="W" + str(1)) myFont = tkFont.Font(font=aFakeLabel['font']) myFont.config(weight=tkFont.BOLD) placeHolder = Frame(self.master, name="placeHolder", bd=1, relief=SUNKEN, bg="white") placeHolder.grid(row=1, column=1, rowspan=5, columnspan=5, sticky=N) titleClientList = Label(placeHolder, name="titleClientList", text="Liste des clients", anchor=S, padx=50, pady=0, font=myFont).grid(row=1, column=1) titleTickBox = Label(placeHolder, name="titleTickBox", text="Generation des factures", anchor=S, padx=50, pady=0, font=myFont).grid(row=1, column=2) rowIndex = 1 for ix in self.clientList: pp.printGreen(ix) self.clientListVar[ix] = IntVar(0) label = Label(placeHolder, name="client_" + str(ix), text=self.clientList[ix].name).grid(row=rowIndex + 1, column=1) c = Checkbutton(placeHolder, name="clientCheckbox_" + str(ix), text="", variable=self.clientListVar[ix]) c.select() self.listCheckBox.append(c) c.grid(row=rowIndex + 1, column=2) rowIndex = rowIndex + 1 self.progresBar = ttk.Progressbar(orient=HORIZONTAL, length=150, mode='determinate', variable=self.progressGen, maximum=self.maxProgress.get()) self.progressGen.set(0) self.progresBar.grid(row=rowIndex + 1, column=1) self.progresBar.grid_remove()
def nextMonth(self,event) : pp.printGreen("Next") dayInCurrentMonth=calendar.monthrange(self.calendarDate.year, self.calendarDate.month)[1] + 1 shiftDays=dayInCurrentMonth-self.calendarDate.day self.calendarDate = self.calendarDate + timedelta(shiftDays+1) self.drawCalendar(event.widget.master)
def previousMonth(self,event) : pp.printGreen("Previous") self.calendarDate = self.calendarDate - timedelta(days=self.calendarDate.day+1) self.calendarDate = self.calendarDate -timedelta(days=self.calendarDate.day-1 ) self.drawCalendar(event.widget.master)
def showGenerationScreen(event): pp.printGreen("Drawing Generation screen") global clientList screen = GenerationScreen(event.widget.master.master, configFile, clientList) screen.drawScreen()
def showClientScreen(event): pp.printGreen("Drawing Client") global clientList screen = ClientSCreen(event.widget.master.master, configFile, clientList) screen.drawScreen()
def showCalendarSCreen(event): pp.printGreen("Drawing calendar") global clientList screen = CalendarScreen(event.widget.master.master, configFile, clientList) screen.drawScreen()