From 094b48e2125c36ed161c2130a7e5be24e440b20e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9rome=20Launay?= Date: Sat, 12 Dec 2015 03:30:07 +0100 Subject: [PATCH] [mod] nettoyage du code --- app_gestion/MesCigares.py | 705 ++++++++++++++++++++----------- app_gestion/bdd/main.db | Bin 15360 -> 15360 bytes app_gestion/conf/mescigares.conf | 2 +- 3 files changed, 468 insertions(+), 239 deletions(-) diff --git a/app_gestion/MesCigares.py b/app_gestion/MesCigares.py index bd4bdc9..32ad06f 100755 --- a/app_gestion/MesCigares.py +++ b/app_gestion/MesCigares.py @@ -1,17 +1,19 @@ #!/usr/bin/env python # -*- coding: utf-8 -*- -import sys +# pylint: disable=line-too-long + import os -import sqlite3 +import sys import locale import ntpath +import sqlite3 import configparser import gi gi.require_version('Gtk', '3.0') try: from gi.repository import Gtk as gtk, GdkPixbuf -except Exception: +except ImportError: print("GTK (PyGI) n'est pas installé") sys.exit(1) @@ -34,8 +36,9 @@ class MesCigares(object): self.aboutdialog.run() self.aboutdialog.hide() - # Mise à jour de la quantité en fonction du cigare choisi dans la liste déroulante - def on_cbchoixcigqte_changed(self, object, data=None): + # Mise à jour de la quantité en fonction du cigare choisi dans la liste + # déroulante + def on_cbchoixcigqte_changed(self, objt, data=None): item = self.cbchoixcigqte.get_active() # Si aucune séléction, pas besoin de traitement. @@ -46,7 +49,9 @@ class MesCigares(object): idc = model[item] cursor = db.cursor() - qte = cursor.execute("Select quantite from stocks where id_cigare = '{0}'".format(idc[0])).fetchone()[0] + qte = cursor.execute("Select quantite from stocks " + + "where id_cigare = '{0}'" + .format(idc[0])).fetchone()[0] cursor.close() self.scaleqte.set_value(int(qte)) @@ -57,12 +62,18 @@ class MesCigares(object): self.table.clear() cursor = db.cursor() - cursor.execute('Select c.designation, m.libelle, mo.module,m.provenance, s.quantite,c.id from cigares c inner join modules mo on mo.id = c.module inner join marques m on m.id = c.marque inner join stocks s on s.id_cigare = c.id') + cursor.execute('Select c.designation, m.libelle, ' + + 'mo.module,m.provenance,s.quantite,' + + 'c.id from cigares c inner join modules mo on ' + + 'mo.id = c.module inner join marques m on m.id = ' + + 'c.marque inner join stocks s on s.id_cigare = c.id') rs = cursor.fetchall() - cursor.execute("select avg(d.note), max(d.note),id_cigare from degustation d group by id_cigare") + cursor.execute("select avg(d.note), max(d.note),id_cigare " + + "from degustation d group by id_cigare") rs2 = cursor.fetchall() - # top = 5 premier items de la liste par meilleure note [2] pour la note seulement + # top = 5 premier items de la liste par meilleure note [2] pour la note + # seulement top = sorted(rs2, reverse=True)[0:5] print(top) # top5 = juste les id @@ -70,16 +81,19 @@ class MesCigares(object): for i in top: top5.append(i[2]) - cursor.execute("select min(prix),id_cigare from achats group by id_cigare") + cursor.execute("select min(prix),id_cigare from achats " + + "group by id_cigare") rs3 = cursor.fetchall() - cursor.execute("select commentaires, id_cigare from degustation group by id_cigare") + cursor.execute("select commentaires, id_cigare from degustation " + + "group by id_cigare") rs4 = cursor.fetchall() for item in rs: - iter = self.table.append() - # Si le nombre de cigares est = 0 on affiche la ligne en rouge clair - if (item[4] == 0): + itr = self.table.append() + # Si le nombre de cigares est = 0 on affiche la ligne en rouge + # clair + if item[4] == 0: color = '#F3B9B9' # rouge clair else: color = '#FFFFFF' # blanc @@ -90,32 +104,37 @@ class MesCigares(object): except Exception: index = 9 # Et on affecte la couleur (dégradé de vert) - if(index == 0): + if index == 0: topcolor = '#8FFF80' - if(index == 1): + if index == 1: topcolor = '#A4FF97' - if(index == 2): + if index == 2: topcolor = '#BFFFB7' - if(index == 3): + if index == 3: topcolor = '#CDFFC7' - if(index == 4): + if index == 4: topcolor = '#DBFFD7' - if(index == 9): + if index == 9: topcolor = color - self.table.set(iter, 0, item[0], 1, item[1], 2, item[2].title(), 3, item[3].title(), 4, item[4], 5, item[5], 11, color, 12, topcolor) - # Il n'y a pas de outer join en sqlite du coup je suis obligé d'alimenter les notes à part + self.table.set(itr, 0, item[0], 1, item[1], 2, item[2].title(), 3, + item[3].title(), 4, item[4], 5, item[5], 11, + color, 12, topcolor) + # Il n'y a pas de outer join en sqlite du coup je suis obligé + # d'alimenter les notes à part for item2 in rs2: itr = self.table.get_iter_first() - while (itr is not None): - # itr, 5 = id de la table cigare (colonne 4 invisible), item2[2] = id_cigare table degustation + while itr is not None: + # itr, 5 = id de la table cigare (colonne 4 invisible), + # item2[2] = id_cigare table degustation if self.table.get_value(itr, 5) == item2[2]: self.table.set(itr, 6, item2[1], 7, item2[0]) itr = self.table.iter_next(itr) for item3 in rs3: itr = self.table.get_iter_first() - while (itr is not None): - # itr, 5 = id de la table cigare (colonne 4 invisible), item3[1] = id_cigare table achats + while itr is not None: + # itr, 5 = id de la table cigare (colonne 4 invisible), + # item3[1] = id_cigare table achats if self.table.get_value(itr, 5) == item3[1]: # .2f pour 2 decimales it = '%.2f' % item3[0] @@ -123,8 +142,9 @@ class MesCigares(object): itr = self.table.iter_next(itr) for item4 in rs4: itr = self.table.get_iter_first() - while (itr is not None): - # itr, 4 = id de la table cigare (colonne 4 invisible), item4[1] = id_cigare table achats + while itr is not None: + # itr, 4 = id de la table cigare (colonne 4 invisible), + # item4[1] = id_cigare table achats if self.table.get_value(itr, 5) == item4[1]: self.table.set(itr, 9, item4[0]) itr = self.table.iter_next(itr) @@ -133,12 +153,13 @@ class MesCigares(object): nbcigares = 0 montant = 0 itr = self.table.get_iter_first() - while (itr is not None): + while itr is not None: nbcigares += int(self.table.get_value(itr, 4)) if self.table.get_value(itr, 8) is not None: - montant += float(self.table.get_value(itr, 10)) * int(self.table.get_value(itr, 4)) + montant += float(self.table.get_value(itr, 10)) * \ + int(self.table.get_value(itr, 4)) itr = self.table.iter_next(itr) - montant = '%.2f' % montant + montant = str('%.2f' % montant) # On calcule le prix total montant_total = 0 @@ -147,20 +168,30 @@ class MesCigares(object): for item in rs: montant_total += (item[0] * item[1]) - montant_total = '%.2f' % montant_total + montant_total = str('%.2f' % montant_total) cursor.close() # On affiche le nombre de résultats trouvés sur la barre de statut if nbcigares == 0: self.statusbar.push(self.context_id, "Aucun cigare dans la base") else: - self.statusbar.push(self.context_id, str(nbcigares) + " cigares dans la base pour un montant de " + str(montant) + "€ - (" + str(montant_total) + "€ depuis le début)") + self.statusbar.push( + self.context_id, + str(nbcigares) + + " cigares dans la base pour un montant de " + + str(montant) + + "€ - (" + + str(montant_total) + + "€ depuis le début)") - # Permet l'affichage de la photo du cigare séléctionné dans la zone rétractable + # Permet l'affichage de la photo du cigare séléctionné dans la zone + # rétractable def affiche_preview(self): cursor = db.cursor() - photo = cursor.execute("select photo from photos where id_cigare = '{0}'".format(self.treeview_selection[5])) + photo = cursor.execute( + "select photo from photos where id_cigare = '{0}'".format( + self.treeview_selection[5])) try: photo = cursor.fetchone()[0] @@ -168,7 +199,7 @@ class MesCigares(object): photo = None cursor.close() # Si aucune photo n'existe pour ce cigare - if(photo is None): + if photo is None: photo = __CONFDIR__ + "/images/no_photo.jpg" self.image_preview.set_from_file(photo) else: @@ -176,16 +207,22 @@ class MesCigares(object): pixbuf = GdkPixbuf.Pixbuf().new_from_file(photo) # Si l'image est plus grande que la fenêtre on re-dimensionne new_size = self.window.get_size()[0] - 20 - if(pixbuf.get_width() > new_size): + if pixbuf.get_width() > new_size: w, h = pixbuf.get_width(), pixbuf.get_height() - pixbuf = pixbuf.scale_simple(new_size, new_size * h / w, GdkPixbuf.InterpType.HYPER) - # Si la largeur de l'image est plus petite que la hauteur on fait pivoter - if(pixbuf.get_width() < pixbuf.get_height()): + pixbuf = pixbuf.scale_simple( + new_size, new_size * h / w, GdkPixbuf.InterpType.HYPER) + # Si la largeur de l'image est plus petite que la hauteur on + # fait pivoter + if pixbuf.get_width() < pixbuf.get_height(): pixbuf = pixbuf.rotate_simple(270) - # Si la hauteur est dépasse la moitié de la fenêtre principale, on re-dimensionne - if(pixbuf.get_height() > self.window.get_size()[1] / 2): + # Si la hauteur est dépasse la moitié de la fenêtre principale, + # on re-dimensionne + if pixbuf.get_height() > self.window.get_size()[1] / 2: w, h = pixbuf.get_width(), pixbuf.get_height() - pixbuf = pixbuf.scale_simple((w * self.window.get_size()[1] / 2) / h, self.window.get_size()[1] / 2, GdkPixbuf.InterpType.HYPER) + pixbuf = pixbuf.scale_simple( + (w * self.window.get_size()[1] / 2) / h, + self.window.get_size()[1] / 2, + GdkPixbuf.InterpType.HYPER) self.image_preview.set_from_pixbuf(pixbuf) else: # Si la photo n'existe plus ou a été renommée @@ -193,10 +230,12 @@ class MesCigares(object): self.image_preview.set_from_file(photo) self.imgpath = photo - # Si la fenêtre principale change de taille on re-dimensionne le preview aussi + # Si la fenêtre principale change de taille on re-dimensionne le preview + # aussi def on_window_main_check_resize(self, widget): # print(self.window.get_size()[1],self.window_last_h) - if ((abs(self.window_last_h - self.window.get_size()[1]) > 40) | (abs(self.window_last_w - self.window.get_size()[0]) > 5)): + if abs(self.window_last_h - self.window.get_size()[1] > 40) | \ + abs(self.window_last_w - self.window.get_size()[0]) > 5: self.window_last_h = self.window.get_size()[1] self.window_last_w = self.window.get_size()[0] @@ -205,32 +244,39 @@ class MesCigares(object): pixbuf = GdkPixbuf.Pixbuf().new_from_file(self.imgpath) # Si l'image est plus grande que la fenêtre on re-dimensionne new_size = self.window.get_size()[0] - 20 - if(pixbuf.get_width() > new_size): + if pixbuf.get_width() > new_size: w, h = pixbuf.get_width(), pixbuf.get_height() - pixbuf = pixbuf.scale_simple(new_size, new_size * h / w, GdkPixbuf.InterpType.HYPER) - # Si la largeur de l'image est plus petite que la hauteur on fait pivoter - if(pixbuf.get_width() < pixbuf.get_height()): + pixbuf = pixbuf.scale_simple( + new_size, new_size * h / w, GdkPixbuf.InterpType.HYPER) + # Si la largeur de l'image est plus petite que la hauteur on fait + # pivoter + if pixbuf.get_width() < pixbuf.get_height(): pixbuf = pixbuf.rotate_simple(270) - # Si la hauteur est dépasse la moitié de la fenêtre principale, on re-dimensionne - if(pixbuf.get_height() > self.window.get_size()[1] / 2): + # Si la hauteur est dépasse la moitié de la fenêtre principale, on + # re-dimensionne + if pixbuf.get_height() > self.window.get_size()[1] / 2: w, h = pixbuf.get_width(), pixbuf.get_height() - pixbuf = pixbuf.scale_simple((w * self.window.get_size()[1] / 2) / h, self.window.get_size()[1] / 2, GdkPixbuf.InterpType.HYPER) + pixbuf = pixbuf.scale_simple( + (w * self.window.get_size()[1] / 2) / h, + self.window.get_size()[1] / 2, + GdkPixbuf.InterpType.HYPER) self.image_preview.set_from_pixbuf(pixbuf) - # Dès qu'une ligne est séléctionnée sur la treeview on enregistre les valeurs + # Dès qu'une ligne est séléctionnée sur la treeview on enregistre les + # valeurs def on_treeview_cigares_row_activated(self, widget): selection = self.tree.get_selection() - (model, iter) = selection.get_selected() - if iter is not None: + (model, itr) = selection.get_selected() + if itr is not None: self.treeview_selection.clear() - self.treeview_selection.append(model.get_value(iter, 0)) - self.treeview_selection.append(model.get_value(iter, 1)) - self.treeview_selection.append(model.get_value(iter, 2)) - self.treeview_selection.append(model.get_value(iter, 3)) - self.treeview_selection.append(model.get_value(iter, 4)) - self.treeview_selection.append(model.get_value(iter, 5)) - self.treeview_selection.append(model.get_value(iter, 6)) - self.treeview_selection.append(model.get_value(iter, 7)) + self.treeview_selection.append(model.get_value(itr, 0)) + self.treeview_selection.append(model.get_value(itr, 1)) + self.treeview_selection.append(model.get_value(itr, 2)) + self.treeview_selection.append(model.get_value(itr, 3)) + self.treeview_selection.append(model.get_value(itr, 4)) + self.treeview_selection.append(model.get_value(itr, 5)) + self.treeview_selection.append(model.get_value(itr, 6)) + self.treeview_selection.append(model.get_value(itr, 7)) # for i in range(0,6): # print(model.get_value(iter, i)) # print("\n") @@ -239,11 +285,11 @@ class MesCigares(object): def get_libelle_quantite(self): selection = self.tree.get_selection() - (model, iter) = selection.get_selected() - if iter is not None: - lib = model.get_value(iter, 0) - qtee = model.get_value(iter, 5) - return(lib, qtee) + (model, itr) = selection.get_selected() + if itr is not None: + lib = model.get_value(itr, 0) + qtee = model.get_value(itr, 5) + return lib, qtee # Changer de base de données def on_bdd_change_activate(self, widget): @@ -266,7 +312,9 @@ class MesCigares(object): db.close() db = sqlite3.connect(self.filechooser_bdd.get_filename()) # On met à jour le titre de la fenêtre - self.window.set_title("MesCigares - base : {0}".format(ntpath.basename(self.filechooser_bdd.get_filename().replace('.db', '')))) + self.window.set_title("MesCigares - base : {0}".format( + ntpath.basename(self.filechooser_bdd.get_filename().replace( + '.db', '')))) self.loadtreeview() self.filechooser_bdd.hide() @@ -288,21 +336,27 @@ class MesCigares(object): # Modifier/Supprimer une note de degustation def on_modsupp_degustation_activate(self, widget): - # On commence par vider la liststore_date_modif_degustation (2ème utilisation) + # On commence par vider la liststore_date_modif_degustation (2ème + # utilisation) if len(self.liststore_date_modif_degustation) != 0: self.liststore_date_modif_degustation.clear() cursor = db.cursor() # On regarde récupère le commentaire - cursor.execute("select date, q1, q2, q3, q4, q5, q6, q7, q8, q9, q10, q11, q12, q13, id, commentaires from degustation where id_cigare = '{0}'".format(self.treeview_selection[5])) + cursor.execute("select date, q1, q2, q3, q4, q5, q6, q7, q8, q9, q10," + + "q11, q12, q13, id, commentaires from degustation " + + "where id_cigare = " + + "'{0}'".format(self.treeview_selection[5])) rs = cursor.fetchall() # si nb = 0 on insère sinon on update la table photos db.commit() cursor.close() - if(len(rs) == 0): - # Afficher un message d'infos pour alerter qu'il faut d'abord faire une dégustation - self.msgdialog.format_secondary_text("Il n'y a aucune dégustation pour ce cigare") + if len(rs) == 0: + # Afficher un message d'infos pour alerter qu'il faut d'abord faire + # une dégustation + self.msgdialog.format_secondary_text( + "Il n'y a aucune dégustation pour ce cigare") self.msgdialog.run() self.msgdialog.hide() return @@ -324,8 +378,11 @@ class MesCigares(object): q13 = item[13] idcomm = item[14] commentaire = item[15] - iter = self.liststore_date_modif_degustation.append() - self.liststore_date_modif_degustation.set(iter, 0, date, 1, q1, 2, q2, 3, q3, 4, q4, 5, q5, 6, q6, 7, q7, 8, q8, 9, q9, 10, q10, 11, q11, 12, q12, 13, q13, 14, idcomm, 15, commentaire) + itr = self.liststore_date_modif_degustation.append() + self.liststore_date_modif_degustation.set( + itr, 0, date, 1, q1, 2, q2, 3, q3, 4, q4, 5, q5, 6, + q6, 7, q7, 8, q8, 9, q9, 10, q10, 11, q11, 12, q12, + 13, q13, 14, idcomm, 15, commentaire) # On affiche la fenêtre de modification du commentaire self.window_modif_degustation.run() @@ -333,7 +390,8 @@ class MesCigares(object): # On recharge la treeview self.loadtreeview() - # Changement sur la liste déroulante de choix de la note de dégustation à modifier/supprimer + # Changement sur la liste déroulante de choix de la note de dégustation à + # modifier/supprimer def on_cbchoix_date_modif_degustation_changed(self, widget): index = self.cbchoix_date_modif_degustation.get_active() q = list() @@ -384,23 +442,24 @@ class MesCigares(object): # Calcul de la note globale pour modification d'une note de dégustation def on_scaleqm_change_value(self, scale, enum, new_value): # On récupère les notes - q1 = int(self.scaleq1m.get_value()) - q2 = int(self.scaleq2m.get_value()) - q3 = int(self.scaleq3m.get_value()) - q4 = int(self.scaleq4m.get_value()) - q5 = int(self.scaleq5m.get_value()) - q6 = int(self.scaleq6m.get_value()) - q7 = int(self.scaleq7m.get_value()) - q8 = int(self.scaleq8m.get_value()) - q9 = int(self.scaleq9m.get_value()) - q10 = int(self.scaleq10m.get_value()) - q11 = int(self.scaleq11m.get_value()) - q12 = int(self.scaleq12m.get_value()) - q13 = int(self.scaleq13m.get_value()) - note = q1 + q2 + q3 + q4 + q5 + q6 + q7 + q8 + q9 + q10 + q11 + q12 + q13 + note = [] + note.append(int(self.scaleq1m.get_value())) + note.append(int(self.scaleq2m.get_value())) + note.append(int(self.scaleq3m.get_value())) + note.append(int(self.scaleq4m.get_value())) + note.append(int(self.scaleq5m.get_value())) + note.append(int(self.scaleq6m.get_value())) + note.append(int(self.scaleq7m.get_value())) + note.append(int(self.scaleq8m.get_value())) + note.append(int(self.scaleq9m.get_value())) + note.append(int(self.scaleq10m.get_value())) + note.append(int(self.scaleq11m.get_value())) + note.append(int(self.scaleq12m.get_value())) + note.append(int(self.scaleq13m.get_value())) + # On affiche la note / 100 temporaire - self.lbl_note_totale.set_text("Nouvelle note: {0}/100".format(note)) + self.lbl_note_totale.set_text("Nouvelle note: {0}/100".format(sum(note))) # Validation de la modification d'une dégustation def on_btvalid_degustation_clicked(self, widget): @@ -410,35 +469,51 @@ class MesCigares(object): start = textbuffer.get_start_iter() end = textbuffer.get_end_iter() # On récupère le commentaire et on échape les quote pour l'insert SQL - commentaire = textbuffer.get_text(start, end, include_hidden_chars=False).replace("'", "''") + commentaire = textbuffer.get_text( + start, end, include_hidden_chars=False).replace("'", "''") # On récupère les notes - q1 = int(self.scaleq1m.get_value()) - q2 = int(self.scaleq2m.get_value()) - q3 = int(self.scaleq3m.get_value()) - q4 = int(self.scaleq4m.get_value()) - q5 = int(self.scaleq5m.get_value()) - q6 = int(self.scaleq6m.get_value()) - q7 = int(self.scaleq7m.get_value()) - q8 = int(self.scaleq8m.get_value()) - q9 = int(self.scaleq9m.get_value()) - q10 = int(self.scaleq10m.get_value()) - q11 = int(self.scaleq11m.get_value()) - q12 = int(self.scaleq12m.get_value()) - q13 = int(self.scaleq13m.get_value()) + note = [] + note.append(int(self.scaleq1m.get_value())) + note.append(int(self.scaleq2m.get_value())) + note.append(int(self.scaleq3m.get_value())) + note.append(int(self.scaleq4m.get_value())) + note.append(int(self.scaleq5m.get_value())) + note.append(int(self.scaleq6m.get_value())) + note.append(int(self.scaleq7m.get_value())) + note.append(int(self.scaleq8m.get_value())) + note.append(int(self.scaleq9m.get_value())) + note.append(int(self.scaleq10m.get_value())) + note.append(int(self.scaleq11m.get_value())) + note.append(int(self.scaleq12m.get_value())) + note.append(int(self.scaleq13m.get_value())) - note = q1 + q2 + q3 + q4 + q5 + q6 + q7 + q8 + q9 + q10 + q11 + q12 + q13 # Le commentaire et l'id idcomm = self.liststore_date_modif_degustation[index][14] id_cigare = self.treeview_selection[5] # On met à jour la base de données cursor = db.cursor() - sql = "update degustation set commentaires = '{0}', q1 = '{1}', q2 = '{2}', q3 = '{3}', q4 = '{4}', q5 = '{5}', q7 = '{7}', q8 = '{8}', q9 = '{9}', q10 = '{10}', q11 = '{11}', q12 = '{12}', q13 = '{13}', note = '{14}' where id_cigare = '{15}' and id = '{16}'".format(commentaire, q1, q2, q3, q4, q5, q6, q7, q8, q9, q10, q11, q12, q13, note, id_cigare, idcomm) + + req = ("update degustation set commentaires ='{0}',q1='{1}'," + + "q2='{2}',q3='{3}',q4 ='{4}',q5='{5}',q7='{7}'" + + ",q8='{8}',q9='{9}',q10='{10}',q11='{11}',q12=" + + "'{12}',q13='{13}',note='{14}' where id_cigare='{15}' " + + "and id='{16}'") + + sql = (req.format(commentaire, note[0], note[1], note[2], + note[3], note[4], note[5], note[6], + note[7], note[8], note[9], note[10], + note[11], note[12], sum(note), + id_cigare, idcomm)) cursor.execute(sql) db.commit() cursor.close() # Afficher un message d'infos pour confirmer - self.msgdialog.format_secondary_text("Modification de la dégustation pour {0}.\nNouvelle note: {1}".format(self.treeview_selection[1], note)) + self.msgdialog.format_secondary_text( + "Modification de la dégustation pour " + + "{0}.\nNouvelle note: {1}".format( + self.treeview_selection[1],sum(note))) + self.msgdialog.run() self.msgdialog.hide() @@ -459,12 +534,19 @@ class MesCigares(object): cursor = db.cursor() # On regarde s'il y a déjà une photo pour le cigare séléctionné - nb = cursor.execute("select count(*) from photos where id_cigare = '{0}'".format(self.treeview_selection[5])).fetchone()[0] + req = ("select count(*) from photos where id_cigare ='{0}'" + .format(self.treeview_selection[5])) + nb = cursor.execute(req).fetchone()[0] # si nb = 0 on insère sinon on update la table photos - if (nb == 0): - cursor.execute("insert into photos (id_cigare, photo) values('{0}','{1}')".format(self.treeview_selection[5], path)) + if nb == 0: + cursor.execute("insert into photos " + + "(id_cigare, photo) " + + "values('{0}','{1}')".format( + self.treeview_selection[5], path)) else: - cursor.execute("update photos set photo = '{0}' where id_cigare='{1}'".format(path, self.treeview_selection[5])) + cursor.execute( + "update photos set photo = '{0}' where id_cigare='{1}'".format( + path, self.treeview_selection[5])) db.commit() cursor.close() @@ -491,7 +573,8 @@ class MesCigares(object): if col == 4: try: self.table.set_value(iter, col, int(new_text)) - self.update_db("id", new_text, tuple(self.treeview_selection)[5]) + self.update_db("id", new_text, tuple( + self.treeview_selection)[5]) except ValueError: # Si la quantité saisie n'est pas un entier pass else: @@ -502,15 +585,17 @@ class MesCigares(object): def update_db(self, operation, new_text, indice): cursor = db.cursor() # update cigares.designation - if (operation == 'nom'): - sql = "update cigares set designation = '{0}' where id = '{1}'".format(new_text.replace("'", "''"), str(indice)) + if operation == 'nom': + sql = "update cigares set designation = '{0}' where id = '{1}'".format( + new_text.replace("'", "''"), str(indice)) # print(sql) cursor.execute(sql) db.commit() # update quantité dans table stock - if (operation == 'id'): - sql = "update stocks set quantite = '{0}' where id_cigare='{1}'".format(new_text, str(indice)) + if operation == 'id': + sql = "update stocks set quantite = '{0}' where id_cigare='{1}'".format( + new_text, str(indice)) # print(sql) cursor.execute(sql) db.commit() @@ -528,19 +613,27 @@ class MesCigares(object): self.tablemodules.clear() cursor = db.cursor() - cursor.execute('Select id, libelle, provenance from marques order by lower(libelle)') + cursor.execute( + 'Select id, libelle, provenance from marques order by lower(libelle)') rs = cursor.fetchall() # On alimente la combobox des marques for item in rs: iter = self.tablemarques.append() - self.tablemarques.set(iter, 0, item[0], 1, item[1].title(), 2, item[2].title()) + self.tablemarques.set(iter, 0, item[0], 1, + item[1].title(), 2, item[2].title()) - cursor.execute('Select id, module, longueur, diametre, calibre from modules order by lower(module)') + cursor.execute( + 'Select id, module, longueur, diametre, calibre from modules order by lower(module)') rs = cursor.fetchall() # Et celle des modules for item in rs: - iter = self.tablemodules.append() - self.tablemodules.set(iter, 0, item[0], 1, item[1].title(), 2, item[2], 3, item[3], 4, item[4]) + itr = self.tablemodules.append() + self.tablemodules.set(itr, + 0, item[0], + 1, item[1].title(), + 2, item[2], + 3, item[3], + 4, item[4]) cursor.close() self.dialog_add_cigare.run() @@ -562,7 +655,9 @@ class MesCigares(object): longueur = self.tablemodules[index][2] diametre = self.tablemodules[index][3] calibre = self.tablemodules[index][4] - self.lbl_module.set_text("{0} mm, diamètre {1}, calibre(cepo) {2}".format(longueur, diametre, calibre)) + self.lbl_module.set_text( + "{0} mm, diamètre {1}, calibre(cepo) {2}".format( + longueur, diametre, calibre)) except IndexError: self.lbl_module.set_text("") @@ -590,8 +685,12 @@ class MesCigares(object): maxid = cursor.fetchone()[0] + 1 except TypeError: maxid = 1 - cursor.execute("insert into stocks (id_cigare, quantite) values ('{0}','{1}')".format(int(maxid), 0)) - cursor.execute("insert into cigares (designation, marque, module) values ('{0}','{1}', '{2}')".format(str(self.entry_nom_cigare.get_text()), int(itemmarque[0]), int(itemmodel[0]))) + cursor.execute("insert into stocks (id_cigare, quantite) " + + "values ('{0}','{1}')".format(int(maxid), 0)) + cursor.execute("insert into cigares (designation, marque, module) " + + "values ('{0}','{1}','{2}')".format( + str(self.entry_nom_cigare.get_text()), + int(itemmarque[0]), int(itemmodel[0]))) db.commit() cursor.close() @@ -612,7 +711,8 @@ class MesCigares(object): self.tablechoixcig.clear() cursor = db.cursor() - cursor.execute('Select c.id, c.designation from cigares c order by c.designation asc') + cursor.execute('Select c.id, c.designation from cigares c ' + + 'order by c.designation asc') rs = cursor.fetchall() for item in rs: iter = self.tablechoixcig.append() @@ -635,24 +735,27 @@ class MesCigares(object): id_cigare = itemchoixcig[0] # On vérifie les saisies - if(index == -1): # Aucun cigare choisi - self.msgdialog.format_secondary_text("Vous devez d'abord choisir un cigare dans la liste") + if index == -1: # Aucun cigare choisi + self.msgdialog.format_secondary_text( + "Vous devez d'abord choisir un cigare dans la liste") self.msgdialog.run() self.msgdialog.hide() return # Mauvais prix unité - if(self.notebook_achats.get_current_page() == 0 and not is_number(self.entry_prix_achats.get_text())): - self.msgdialog.format_secondary_text("Saisie erronée pour le prix du cigare.") + if self.notebook_achats.get_current_page() == 0 and not is_number(self.entry_prix_achats.get_text()): + self.msgdialog.format_secondary_text( + "Saisie erronée pour le prix du cigare.") self.msgdialog.run() self.msgdialog.hide() return # Mauvais prix boite - if(self.notebook_achats.get_current_page() == 1 and not is_number(self.entry_prix_boite.get_text())): - self.msgdialog.format_secondary_text("Saisie erronée pour le prix de la boite.") + if self.notebook_achats.get_current_page() == 1 and not is_number(self.entry_prix_boite.get_text()): + self.msgdialog.format_secondary_text( + "Saisie erronée pour le prix de la boite.") self.msgdialog.run() self.msgdialog.hide() return - if(self.notebook_achats.get_current_page() == 0): # Choix à l'unité + if self.notebook_achats.get_current_page() == 0: # Choix à l'unité qte_achat = int(self.scale_qte_achats.get_value()) prix_achat = self.entry_prix_achats.get_text().replace(",", ".") prix_achat = '%.2f' % float(prix_achat) @@ -668,7 +771,7 @@ class MesCigares(object): # On formate la date (ajout d'un 0 si besoin) j = str(self.calendar_date_achats.get_date()[2]) - if(len(str(self.calendar_date_achats.get_date()[1] + 1)) == 1): + if len(str(self.calendar_date_achats.get_date()[1] + 1)) == 1: m = "0" + str(self.calendar_date_achats.get_date()[1] + 1) else: m = str(self.calendar_date_achats.get_date()[1] + 1) @@ -678,17 +781,27 @@ class MesCigares(object): # Insert des achats en base de données cursor = db.cursor() - cursor.execute("insert into achats (id_cigare, date, prix, quantite, code_boite) values ('{0}','{1}','{2}','{3}', '{4}')".format(id_cigare, date_achat, prix_achat, qte_achat, code_boite)) + cursor.execute( + "insert into achats (id_cigare, date, prix, quantite, " + + "code_boite) values ('{0}','{1}','{2}','{3}', '{4}')".format( + id_cigare, + date_achat, + prix_achat, + qte_achat, + code_boite)) # ajout dans le stock - cursor.execute("update stocks set quantite = quantite + {1} where id = {0}".format(id_cigare, qte_achat)) + cursor.execute("update stocks set quantite = " + + "quantite + {1} where id = {0}" + .format(id_cigare, qte_achat)) db.commit() cursor.close() # Afficher un message d'infos pour confirmer - self.msgdialog.format_secondary_text("Achats ajoutés avec succés pour {0}".format(itemchoixcig[1])) - self.msgdialog.run() - self.msgdialog.hide() + #self.msgdialog.format_secondary_text("Achats ajoutés avec succés " + + #"pour {0}".format(itemchoixcig[1])) + #self.msgdialog.run() + #self.msgdialog.hide() # On recharge la liste des cigares self.loadtreeview() @@ -697,11 +810,13 @@ class MesCigares(object): # Affiche du prix d'un cigare pour les achats par boite def on_scale_typeboite_change_value(self, scale, enum, new_value): - if(is_number(self.entry_prix_boite.get_text())): - prix_unite = float(self.entry_prix_boite.get_text()) / int(self.scale_typeboite.get_value()) + if is_number(self.entry_prix_boite.get_text()): + prix_unite = float(self.entry_prix_boite.get_text()) / \ + int(self.scale_typeboite.get_value()) prix_unite = '%.2f' % prix_unite # on met à jour le label - self.lbl_prix_unite_boite.set_text(" Soit {0}€ le cigare".format(prix_unite)) + self.lbl_prix_unite_boite.set_text( + " Soit {0}€ le cigare".format(prix_unite)) def on_entry_prix_boite_changed(self, widget): self.on_scale_typeboite_change_value(None, None, None) @@ -719,13 +834,15 @@ class MesCigares(object): # Insert de la nouvelle marque en base de données cursor = db.cursor() - cursor.execute("insert into marques (libelle, provenance) values ('{0}','{1}')".format(e_marque, e_provenance)) + cursor.execute("insert into marques (libelle, provenance) " + + "values ('{0}','{1}')".format(e_marque, e_provenance)) db.commit() cursor.close() # Afficher un message d'infos pour confirmer - self.msgdialog.format_secondary_text("Marque {0} ajoutée.".format(e_marque)) + self.msgdialog.format_secondary_text( + "Marque {0} ajoutée.".format(e_marque)) self.msgdialog.run() self.msgdialog.hide() @@ -736,7 +853,8 @@ class MesCigares(object): self.tablechoixcig.clear() cursor = db.cursor() - cursor.execute('Select c.id, c.designation from cigares c order by c.designation asc') + cursor.execute( + 'Select c.id, c.designation from cigares c order by c.designation asc') rs = cursor.fetchall() for item in rs: iter = self.tablechoixcig.append() @@ -753,11 +871,17 @@ class MesCigares(object): idc = model[item] cursor = db.cursor() - cursor.execute("Update stocks set quantite = '{0}' where id_cigare = '{1}'".format(int(self.scaleqte.get_value()), idc[0])) + cursor.execute( + "Update stocks set quantite='{0}' where id_cigare='{1}'".format( + int(self.scaleqte.get_value()), idc[0])) + db.commit() cursor.close() # affichage message maj ok pour qte - self.msgdialog.format_secondary_text("Quantité mise à jour pour {0}.\nVous avez maintenant {1} exemplaire(s)".format(idc[1], int(self.scaleqte.get_value()))) + self.msgdialog.format_secondary_text( + "Quantité mise à jour pour " + + "{0}.\nVous avez maintenant {1} exemplaire(s)" + .format(idc[1], int(self.scaleqte.get_value()))) self.msgdialog.run() self.msgdialog.hide() # On recharge la treeview principale @@ -769,7 +893,10 @@ class MesCigares(object): self.tablechoixcigare.clear() cursor = db.cursor() - cursor.execute('Select c.id, c.designation from cigares c where c.id not in (select s.id_cigare from stocks s where s.quantite = 0) order by c.designation asc') + cursor.execute( + 'Select c.id, c.designation from cigares c where c.id not in ' + + '(select s.id_cigare from stocks s where s.quantite = 0) ' + + 'order by c.designation asc') rs = cursor.fetchall() for item in rs: iter = self.tablechoixcigare.append() @@ -784,7 +911,7 @@ class MesCigares(object): # On formate la date (ajout d'un 0 si besoin) j = str(self.DegustationDate.get_date()[2]) - if(len(str(self.DegustationDate.get_date()[1] + 1)) == 1): + if len(str(self.DegustationDate.get_date()[1] + 1)) == 1: m = "0" + str(self.DegustationDate.get_date()[1] + 1) else: m = str(self.DegustationDate.get_date()[1] + 1) @@ -797,22 +924,51 @@ class MesCigares(object): start = textbuffer.get_start_iter() end = textbuffer.get_end_iter() # On récupère le commentaire et on échape les quote pour l'insert SQL - textlines = textbuffer.get_text(start, end, include_hidden_chars=False).replace("'", "''") + textlines = textbuffer.get_text( + start, end, include_hidden_chars=False).replace("'", "''") index = self.cbchoixcigare.get_active() itemchoixcig = self.tablechoixcigare[index] - note = int(self.scaleq1.get_value()) + int(self.scaleq2.get_value()) + int(self.scaleq3.get_value()) + int(self.scaleq4.get_value()) + int(self.scaleq5.get_value()) + int(self.scaleq6.get_value()) + int(self.scaleq7.get_value()) + int(self.scaleq8.get_value()) + int(self.scaleq9.get_value()) + int(self.scaleq10.get_value()) + int(self.scaleq11.get_value()) + int(self.scaleq12.get_value()) + int(self.scaleq13.get_value()) + note = int(self.scaleq1.get_value()) + int(self.scaleq2.get_value()) \ + + int(self.scaleq3.get_value()) + int(self.scaleq4.get_value()) \ + + int(self.scaleq5.get_value()) + int(self.scaleq6.get_value()) \ + + int(self.scaleq7.get_value()) + int(self.scaleq8.get_value()) \ + + int(self.scaleq9.get_value()) + int(self.scaleq10.get_value()) \ + + int(self.scaleq11.get_value()) + int(self.scaleq12.get_value()) \ + + int(self.scaleq13.get_value()) cursor = db.cursor() - cursor.execute("insert into degustation (id_cigare,date,commentaires,q1,q2,q3,q4,q5,q6,q7,q8,q9,q10,q11,q12,q13,note) values ('{0}','{1}','{2}','{3}','{4}','{5}','{6}','{7}','{8}','{9}','{10}','{11}','{12}','{13}','{14}','{15}','{16}')".format(itemchoixcig[0], DateDegustation, textlines, int(self.scaleq1.get_value()), int(self.scaleq2.get_value()), int(self.scaleq3.get_value()), int(self.scaleq4.get_value()), int(self.scaleq5.get_value()), int(self.scaleq6.get_value()), int(self.scaleq7.get_value()), int(self.scaleq8.get_value()), int(self.scaleq9.get_value()), int(self.scaleq10.get_value()), int(self.scaleq11.get_value()), int(self.scaleq12.get_value()), int(self.scaleq13.get_value()), note)) + req = ("insert into degustation (id_cigare,date,commentaires," + + "q1,q2,q3,q4,q5,q6,q7,q8,q9,q10,q11,q12,q13,note) " + + "values ('{0}','{1}','{2}','{3}','{4}','{5}','{6}'" + + ",'{7}','{8}','{9}','{10}','{11}','{12}','{13}'," + + "'{14}','{15}','{16}')") + cursor.execute(req.format(itemchoixcig[0], DateDegustation, textlines, + int(self.scaleq1.get_value()), + int(self.scaleq2.get_value()), + int(self.scaleq3.get_value()), + int(self.scaleq4.get_value()), + int(self.scaleq5.get_value()), + int(self.scaleq6.get_value()), + int(self.scaleq7.get_value()), + int(self.scaleq8.get_value()), + int(self.scaleq9.get_value()), + int(self.scaleq10.get_value()), + int(self.scaleq11.get_value()), + int(self.scaleq12.get_value()), + int(self.scaleq13.get_value()), note)) # - 1 sur le stock - cursor.execute("update stocks set quantite = quantite - 1 where id = {0}".format(itemchoixcig[0])) + cursor.execute("update stocks set quantite = quantite - 1 " + + "where id = {0}".format(itemchoixcig[0])) db.commit() cursor.close() - # TODO ajouter une checkbox sur le formulaire pour choisir si retirer 1 du stock ou non - self.msgdialog.format_secondary_text("Note de dégustation ajoutée avec succès pour : {0}.\n1 cigare retiré du stock.".format(itemchoixcig[1])) + # TODO(jlaunay) ajouter une checkbox sur le formulaire pour choisir si retirer 1 + # du stock ou non + self.msgdialog.format_secondary_text( + "Note de dégustation ajoutée avec succès pour : " + + "{0}.\n1 cigare retiré du stock.".format(itemchoixcig[1])) self.msgdialog.run() self.msgdialog.hide() @@ -826,14 +982,17 @@ class MesCigares(object): self.liststore_wishes.clear() cursor = db.cursor() - cursor.execute('select nom, provenance,raison,source,id from tester order by id') + cursor.execute( + 'select nom, provenance,raison,source,id from tester order by id') rs = cursor.fetchall() for item in rs: iter = self.liststore_wishes.append() - self.liststore_wishes.set(iter, 0, item[0], 1, item[1], 2, item[2], 3, item[3], 4, item[4]) + self.liststore_wishes.set(iter, 0, item[0], 1, item[1], + 2, item[2], 3, item[3], 4, item[4]) cursor.close() - self.window_wishes.resize(self.window.get_size()[0], self.window.get_size()[1]) + self.window_wishes.resize(self.window.get_size()[0], + self.window.get_size()[1]) self.window_wishes.show() @@ -866,11 +1025,16 @@ class MesCigares(object): start = textbuffer.get_start_iter() end = textbuffer.get_end_iter() # On récupère le commentaire et on échape les quote pour l'insert SQL - textlines = textbuffer.get_text(start, end, include_hidden_chars=False).replace("'", "''") + textlines = textbuffer.get_text( + start, end, include_hidden_chars=False).replace("'", "''") # On ajoute en base de données cursor = db.cursor() - sql = "insert into tester (nom, provenance, source, raison) values ('{0}','{1}','{2}','{3}')".format(self.entry_test_nom.get_text(), self.entry_test_origine.get_text(), self.entry_test_source.get_text(), textlines) + sql = ("insert into tester (nom, provenance, source, raison) " + + "values ('{0}','{1}','{2}','{3}')" + .format(self.entry_test_nom.get_text(), + self.entry_test_origine.get_text(), + self.entry_test_source.get_text(), textlines)) cursor.execute(sql) db.commit() cursor.close() @@ -890,14 +1054,16 @@ class MesCigares(object): self.treeview_wishes.set_cursor(path, col, 0) # On affiche le popup self.popup_test.show_all() - self.popup_test.popup(None, None, None, None, event.button, event.time) + self.popup_test.popup(None, None, None, None, + event.button, event.time) - # Ouvrir l'url dans le navigateur au clic droit sur une ligne de la treeview des cigares à tester + # Ouvrir l'url dans le navigateur au clic droit sur une ligne de la + # treeview des cigares à tester def on_gtk_copier_test_activate(self, widget): try: import webbrowser from urllib.parse import urlparse - except Exception: + except ImportError: print('webbrowser not available') return False @@ -937,14 +1103,20 @@ class MesCigares(object): (model, iter) = selection.get_selected() if iter is not None: cursor = db.cursor() - sql = "delete from tester where nom = '{0}' and provenance = '{1}' and raison = '{2}' and source = '{3}'".format(model.get_value(iter, 0), model.get_value(iter, 1), model.get_value(iter, 2), model.get_value(iter, 3)) + sql = ("delete from tester where nom = '{0}' and provenance = " + + "'{1}' and raison = '{2}' and source = '{3}'" + .format(model.get_value(iter, 0), + model.get_value(iter, 1), + model.get_value(iter, 2), + model.get_value(iter, 3))) cursor.execute(sql) db.commit() cursor.close() # Afficher un message d'infos pour alerter que c'est bien supprimé - self.msgdialog.format_secondary_text("Cigare à tester correctement supprimé") + self.msgdialog.format_secondary_text( + "Cigare à tester correctement supprimé") self.msgdialog.run() self.msgdialog.hide() @@ -984,9 +1156,12 @@ class MesCigares(object): self.dialog_add_module = self.builder.get_object("dialog_add_module") # Modification/Suppression d'une note de dégustation - self.window_modif_degustation = self.builder.get_object("window_modif_degustation") - self.liststore_date_modif_degustation = self.builder.get_object("liststore_date_modif_degustation") - self.cbchoix_date_modif_degustation = self.builder.get_object("cbchoix_date_modif_degustation") + self.window_modif_degustation = self.builder.get_object( + "window_modif_degustation") + self.liststore_date_modif_degustation = self.builder.get_object( + "liststore_date_modif_degustation") + self.cbchoix_date_modif_degustation = self.builder.get_object( + "cbchoix_date_modif_degustation") self.scaleq1m = self.builder.get_object("scaleq1m") self.scaleq2m = self.builder.get_object("scaleq2m") self.scaleq3m = self.builder.get_object("scaleq3m") @@ -1001,11 +1176,13 @@ class MesCigares(object): self.scaleq12m = self.builder.get_object("scaleq12m") self.scaleq13m = self.builder.get_object("scaleq13m") self.lbl_note_totale = self.builder.get_object("lbl_note_totale") - self.txtview_commentaire_modif = self.builder.get_object("txtview_commentaire_modif") + self.txtview_commentaire_modif = self.builder.get_object( + "txtview_commentaire_modif") self.cbmarques = self.builder.get_object("cbmarques") self.cbchoixcigare = self.builder.get_object("cbchoixcigare") - self.tablechoixcigare = self.builder.get_object("liststore_cigares_a_noter") + self.tablechoixcigare = self.builder.get_object( + "liststore_cigares_a_noter") self.scaleq1 = self.builder.get_object("scaleq1") self.scaleq2 = self.builder.get_object("scaleq2") self.scaleq3 = self.builder.get_object("scaleq3") @@ -1024,7 +1201,8 @@ class MesCigares(object): self.tablemodules = self.builder.get_object("liststore_modules") self.entry_nom_cigare = self.builder.get_object("entry_nom_cigare") self.window_degustation = self.builder.get_object("window_degustation") - self.txtview_commentaire = self.builder.get_object("txtview_commentaire") + self.txtview_commentaire = self.builder.get_object( + "txtview_commentaire") self.popup = self.builder.get_object("popup") self.popup_test = self.builder.get_object("popup_test") self.filechooser_image = self.builder.get_object("filechooser_image") @@ -1035,7 +1213,8 @@ class MesCigares(object): self.entry_provenance = self.builder.get_object("entry_provenance") # Fenêtre des cigares à tester - self.txtview_test_raison = self.builder.get_object("txtview_test_raison") + self.txtview_test_raison = self.builder.get_object( + "txtview_test_raison") self.entry_test_nom = self.builder.get_object("entry_test_nom") self.entry_test_source = self.builder.get_object("entry_test_source") self.entry_test_origine = self.builder.get_object("entry_test_origine") @@ -1045,7 +1224,8 @@ class MesCigares(object): self.msgdialog = self.builder.get_object("msgdialog") - self.tablechoixcig = self.builder.get_object("listestore_liste_cigares") + self.tablechoixcig = self.builder.get_object( + "listestore_liste_cigares") self.cbchoixcigqte = self.builder.get_object("cbchoixcigqte") self.lblqte = self.builder.get_object("lblqte") self.dialog_stocks = self.builder.get_object("dialog_stocks") @@ -1060,8 +1240,10 @@ class MesCigares(object): # Fenêtre de gestion des achats self.dialog_achats = self.builder.get_object("dialog_achats") - # Combo pour la liste des cigares (achats) - utilise aussi listestore_choix_cigare_qte - self.cb_liste_cigares_achats = self.builder.get_object("cb_liste_cigares_achats") + # Combo pour la liste des cigares (achats) - utilise aussi + # listestore_choix_cigare_qte + self.cb_liste_cigares_achats = self.builder.get_object( + "cb_liste_cigares_achats") # Scale pour la quantité achetée self.scale_qte_achats = self.builder.get_object("scale_qte_achats") # Entry pour le prix d'achat @@ -1071,10 +1253,12 @@ class MesCigares(object): self.scale_typeboite = self.builder.get_object("scale_typeboite") self.entry_prix_boite = self.builder.get_object("entry_prix_boite") self.entry_code_boite = self.builder.get_object("entry_code_boite") - self.lbl_prix_unite_boite = self.builder.get_object("lbl_prix_unite_boite") + self.lbl_prix_unite_boite = self.builder.get_object( + "lbl_prix_unite_boite") # Calendar pour la date d'achat - self.calendar_date_achats = self.builder.get_object("calendar_date_achats") + self.calendar_date_achats = self.builder.get_object( + "calendar_date_achats") # Fenêtre pour la liste des cigares à tester self.window_wishes = self.builder.get_object("window_wishes") # Fenêtre d'ajout d'un cigare à tester @@ -1114,7 +1298,8 @@ class MesCigares(object): self.editable_cell_nom.connect('edited', self.cell_edited_callback, 0) self.editable_cell_nom.set_property('editable', True) - self.col_nom = gtk.TreeViewColumn('Nom', self.editable_cell_nom, text=0, background=11) + self.col_nom = gtk.TreeViewColumn( + 'Nom', self.editable_cell_nom, text=0, background=11) self.col_nom.set_sort_column_id(0) self.tree.append_column(self.col_nom) @@ -1124,44 +1309,54 @@ class MesCigares(object): self.no_editable_cell.set_property('editable', False) - self.col_marque = gtk.TreeViewColumn('Marque', self.no_editable_cell, text=1, background=11) + self.col_marque = gtk.TreeViewColumn( + 'Marque', self.no_editable_cell, text=1, background=11) self.col_marque.set_sort_column_id(1) self.tree.append_column(self.col_marque) - self.col_module = gtk.TreeViewColumn('Module', self.no_editable_cell, text=2, background=11) + self.col_module = gtk.TreeViewColumn( + 'Module', self.no_editable_cell, text=2, background=11) self.col_module.set_sort_column_id(2) self.tree.append_column(self.col_module) - self.col_provenance = gtk.TreeViewColumn('Terroir', self.no_editable_cell, text=3, background=11) + self.col_provenance = gtk.TreeViewColumn( + 'Terroir', self.no_editable_cell, text=3, background=11) self.col_provenance.set_sort_column_id(3) self.tree.append_column(self.col_provenance) self.editable_cell_qte.connect('edited', self.cell_edited_callback, 4) self.editable_cell_qte.set_property('editable', True) - self.col_qte = gtk.TreeViewColumn('Quantité', self.editable_cell_qte, text=4, background=11) + self.col_qte = gtk.TreeViewColumn( + 'Quantité', self.editable_cell_qte, text=4, background=11) self.col_qte.set_sort_column_id(4) self.tree.append_column(self.col_qte) # colonne invisible pour l'id_cigare self.invisible_cell.set_property('visible', False) - self.col_id = gtk.TreeViewColumn('id', self.invisible_cell, text=5, background=11) + self.col_id = gtk.TreeViewColumn( + 'id', self.invisible_cell, text=5, background=11) self.col_id.set_sort_column_id(5) - self.col_best_note = gtk.TreeViewColumn('Meilleure note', self.no_editable_cell, text=6, background=11) + self.col_best_note = gtk.TreeViewColumn( + 'Meilleure note', self.no_editable_cell, text=6, background=11) self.col_best_note.set_sort_column_id(6) self.tree.append_column(self.col_best_note) - self.col_mid_note = gtk.TreeViewColumn('Note moyenne', self.no_editable_cell, text=7, background=12) + self.col_mid_note = gtk.TreeViewColumn( + 'Note moyenne', self.no_editable_cell, text=7, background=12) self.col_mid_note.set_sort_column_id(7) self.tree.append_column(self.col_mid_note) - self.col_prix = gtk.TreeViewColumn('Prix', self.no_editable_cell, text=8, background=11) - # On utilise l'id de la col_tri (id = 10) qui contient le prix en float pour le tri + self.col_prix = gtk.TreeViewColumn( + 'Prix', self.no_editable_cell, text=8, background=11) + # On utilise l'id de la col_tri (id = 10) qui contient le prix en float + # pour le tri self.col_prix.set_sort_column_id(10) self.tree.append_column(self.col_prix) # colonne invisible pour le commentaire de dégustation - self.col_comment = gtk.TreeViewColumn('commentaire', self.invisible_cell, text=9) + self.col_comment = gtk.TreeViewColumn( + 'commentaire', self.invisible_cell, text=9) self.col_comment.set_sort_column_id(9) # On défini cette colonne comme colonne d'infobulle self.tree.set_tooltip_column(9) @@ -1170,29 +1365,35 @@ class MesCigares(object): self.col_tri = gtk.TreeViewColumn('tri', self.invisible_cell, text=10) # colonne invisible pour la couleur d'une ligne - self.col_couleur = gtk.TreeViewColumn('couleur', self.invisible_cell, text=11) + self.col_couleur = gtk.TreeViewColumn( + 'couleur', self.invisible_cell, text=11) # colonne invisible pour la couleur du top 5 - self.col_couleurtop5 = gtk.TreeViewColumn('couleurtop5', self.invisible_cell, text=12) + self.col_couleurtop5 = gtk.TreeViewColumn( + 'couleurtop5', self.invisible_cell, text=12) # Utiliser gtkspellcheck dans la txtview des commentaires # http://koehlma.github.io/projects/pygtkspellcheck.html try: from gtkspellcheck import SpellChecker - SpellChecker(self.txtview_commentaire, locale.getdefaultlocale()[0]) - SpellChecker(self.txtview_commentaire_modif, locale.getdefaultlocale()[0]) - SpellChecker(self.txtview_test_raison, locale.getdefaultlocale()[0]) + SpellChecker(self.txtview_commentaire, + locale.getdefaultlocale()[0]) + SpellChecker(self.txtview_commentaire_modif, + locale.getdefaultlocale()[0]) + SpellChecker(self.txtview_test_raison, + locale.getdefaultlocale()[0]) except Exception: - print("gtkspellcheck n'est pas installé") + print("gtkspellcheck n'est pas installé " + + "http://koehlma.github.io/projects/" + + "pygtkspellcheck.html") pass self.window.show_all() # On charge la liste des cigares self.loadtreeview() + # Vérifier qu'il s'agit d'un nombre - - def is_number(s): try: float(s) @@ -1204,29 +1405,36 @@ def is_number(s): def createdb(new_bdd): db = sqlite3.connect(new_bdd) cursor = db.cursor() - sql = 'create table achats' + \ - '(id INTEGER PRIMARY KEY, id_cigare INTEGER, date TEXT, code_boite TEXT, prix FLOAT, quantite INTEGER)' + sql = ('create table achats(id INTEGER PRIMARY KEY, id_cigare ' + 'INTEGER, date TEXT, code_boite TEXT, prix FLOAT, ' + 'quantite INTEGER)') cursor.execute(sql) - sql = 'create table cigares' + \ - '(id INTEGER PRIMARY KEY, designation TEXT, marque INTEGER, module INTEGER)' + sql = ('create table cigares(id INTEGER PRIMARY KEY, designation ' + 'TEXT, marque INTEGER, module INTEGER)') cursor.execute(sql) - sql = 'create table degustation' + \ - '(id INTEGER PRIMARY KEY, id_cigare INTEGER, date TEXT, note NUMERIC, commentaires TEXT, q1 INTEGER, q2 INTEGER, q3 INTEGER, q4 INTEGER, q5 INTEGER, q6 INTEGER, q7 INTEGER, q8 INTEGER, q9 INTEGER, q10 INTEGER, q11 INTEGER, q12 INTEGER, q13 INTEGER)' + sql = ('create table degustation' + '(id INTEGER PRIMARY KEY, id_cigare INTEGER, date TEXT, ' + 'note NUMERIC, commentaires TEXT, q1 INTEGER, q2 INTEGER, ' + 'q3 INTEGER, q4 INTEGER, q5 INTEGER, q6 INTEGER, q7 INTEGER, ' + 'q8 INTEGER, q9 INTEGER, q10 INTEGER, q11 INTEGER, q12 INTEGER, ' + 'q13 INTEGER)') cursor.execute(sql) - sql = 'create table marques' + \ - '(id INTEGER PRIMARY KEY, libelle TEXT, provenance TEXT)' + sql = ('create table marques' + '(id INTEGER PRIMARY KEY, libelle TEXT, provenance TEXT)') cursor.execute(sql) - sql = 'create table modules' + \ - '(id INTEGER PRIMARY KEY, module TEXT, calibre TEXT, diametre TEXT, longueur TEXT)' + sql = ('create table modules' + '(id INTEGER PRIMARY KEY, module TEXT, calibre TEXT, ' + 'diametre TEXT, longueur TEXT)') cursor.execute(sql) - sql = 'create table photos' + \ - '(id INTEGER PRIMARY KEY, id_cigare INTEGER, photo TEXT)' + sql = ('create table photos' + '(id INTEGER PRIMARY KEY, id_cigare INTEGER, photo TEXT)') cursor.execute(sql) - sql = 'create table stocks' + \ - '(id INTEGER PRIMARY KEY, id_cigare INTEGER, quantite INTEGER)' + sql = ('create table stocks' + '(id INTEGER PRIMARY KEY, id_cigare INTEGER, quantite INTEGER)') cursor.execute(sql) - sql = 'create table tester' + \ - '(id INTEGER PRIMARY KEY, nom TEXT, provenance TEXT, raison TEXT, source TEXT)' + sql = ('create table tester' + '(id INTEGER PRIMARY KEY, nom TEXT, provenance TEXT, ' + 'raison TEXT, source TEXT)') cursor.execute(sql) # INSERT à mettre dans un fichier à part @@ -1234,7 +1442,8 @@ def createdb(new_bdd): cursor.execute(sql) sql = "INSERT INTO modules VALUES(2, 'Carolina', '26', '10.32', '121')" cursor.execute(sql) - sql = "INSERT INTO modules VALUES(3, 'Panetela Larga', '28', '11.11', '175')" + sql = ("INSERT INTO modules VALUES(3, 'Panetela Larga', '28', " + "'11.11', '175')") cursor.execute(sql) sql = "INSERT INTO modules VALUES(4, 'Chico', '29', '11.51', '106')" cursor.execute(sql) @@ -1266,17 +1475,20 @@ def createdb(new_bdd): cursor.execute(sql) sql = "INSERT INTO modules VALUES(18, 'Veguerito', '36', '14.29', '127')" cursor.execute(sql) - sql = "INSERT INTO modules VALUES(19, 'Delicado Extra', '36', '14.29', '185')" + sql = ("INSERT INTO modules VALUES(19, 'Delicado Extra', " + "'36', '14.29', '185')") cursor.execute(sql) sql = "INSERT INTO modules VALUES(20, 'Trabuco', '38', '15.08', '110')" cursor.execute(sql) - sql = "INSERT INTO modules VALUES(21, 'Laguito N ° 2', '38', '15.08', '152')" + sql = ("INSERT INTO modules VALUES(21, 'Laguito N ° 2', '38', " + "'15.08', '152')") cursor.execute(sql) sql = "INSERT INTO modules VALUES(22, 'Parejo', '38', '15.08', '166')" cursor.execute(sql) sql = "INSERT INTO modules VALUES(23, 'Delicado', '38', '15.08', '192')" cursor.execute(sql) - sql = "INSERT INTO modules VALUES(24, 'Laguito N ° 1', '38', '15.08', '192')" + sql = ("INSERT INTO modules VALUES(24, 'Laguito N ° 1', '38', " + "'15.08', '192')") cursor.execute(sql) sql = "INSERT INTO modules VALUES(25, 'Belvedere', '39', '15.48', '125')" cursor.execute(sql) @@ -1296,13 +1508,15 @@ def createdb(new_bdd): cursor.execute(sql) sql = "INSERT INTO modules VALUES(33, 'Crema', '40', '15.87', '140')" cursor.execute(sql) - sql = "INSERT INTO modules VALUES(34, 'Laguito No.1', '40', '15.87', '192')" + sql = ("INSERT INTO modules VALUES(34, 'Laguito No.1', '40', '15.87', " + "'192')") cursor.execute(sql) sql = "INSERT INTO modules VALUES(35, 'Minuto', '42', '16.67', '110')" cursor.execute(sql) sql = "INSERT INTO modules VALUES(36, 'Mareva', '42', '16.67', '129')" cursor.execute(sql) - sql = "INSERT INTO modules VALUES(37, 'Petit Corona', '42', '16.67', '127')" + sql = ("INSERT INTO modules VALUES(37, 'Petit Corona', '42', '16.67', " + "'127')") cursor.execute(sql) sql = "INSERT INTO modules VALUES(38, 'Eminente', '42', '16.67', '132')" cursor.execute(sql) @@ -1312,7 +1526,8 @@ def createdb(new_bdd): cursor.execute(sql) sql = "INSERT INTO modules VALUES(41, 'Corona', '42', '16.67', '140')" cursor.execute(sql) - sql = "INSERT INTO modules VALUES(42, 'Corona Grande', '42', '16.67', '155')" + sql = ("INSERT INTO modules VALUES(42, 'Corona Grande', '42', " + "'16.67', '155')") cursor.execute(sql) sql = "INSERT INTO modules VALUES(43, 'Cervante', '42', '16.67', '165')" cursor.execute(sql) @@ -1324,19 +1539,23 @@ def createdb(new_bdd): cursor.execute(sql) sql = "INSERT INTO modules VALUES(47, 'Francisco', '44', '17.46', '143')" cursor.execute(sql) - sql = "INSERT INTO modules VALUES(48, 'Corona Gorda', '46', '18.26', '143')" + sql = ("INSERT INTO modules VALUES(48, 'Corona Gorda', '46', " + "'18.26', '143')") cursor.execute(sql) sql = "INSERT INTO modules VALUES(49, 'Taco', '47', '18.65', '158')" cursor.execute(sql) - sql = "INSERT INTO modules VALUES(50, 'Julieta / Churchill', '47', '18.65', '178')" + sql = ("INSERT INTO modules VALUES(50, 'Julieta / Churchill', " + "'47', '18.65', '178')") cursor.execute(sql) sql = "INSERT INTO modules VALUES(51, 'Gran Corona', '47', '18.65', '235')" cursor.execute(sql) - sql = "INSERT INTO modules VALUES(52, 'Hermoso N ° 4', '49', '19.05', '127')" + sql = ("INSERT INTO modules VALUES(52, 'Hermoso N ° 4', '49', " + "'19.05', '127')") cursor.execute(sql) sql = "INSERT INTO modules VALUES(53, 'Paco', '49', '19.45', '180')" cursor.execute(sql) - sql = "INSERT INTO modules VALUES(54, 'Double corona', '49', '19.45', '194')" + sql = ("INSERT INTO modules VALUES(54, 'Double corona', '49', " + "'19.45', '194')") cursor.execute(sql) sql = "INSERT INTO modules VALUES(55, 'Robusto', '50', '19.84', '127')" cursor.execute(sql) @@ -1344,11 +1563,14 @@ def createdb(new_bdd): cursor.execute(sql) sql = "INSERT INTO modules VALUES(57, 'Campana', '52', '20.64', '140')" cursor.execute(sql) - sql = "INSERT INTO modules VALUES(58, 'Panetelas Extra', '37', '13.49', '127')" + sql = ("INSERT INTO modules VALUES(58, 'Panetelas Extra', '37', " + "'13.49', '127')") cursor.execute(sql) - sql = "INSERT INTO modules VALUES(59, 'Oficios (Corona)', '43', '17.07', '135')" + sql = ("INSERT INTO modules VALUES(59, 'Oficios (Corona)', '43', " + "'17.07', '135')") cursor.execute(sql) - sql = "INSERT INTO modules VALUES(60, 'Majestic (Petit Corona)', '39', '15.87', '140')" + sql = ("INSERT INTO modules VALUES(60, 'Majestic (Petit Corona)', " + "'39', '15.87', '140')") cursor.execute(sql) sql = "INSERT INTO modules VALUES(61, 'Figurados', '60', '20+', '150+')" cursor.execute(sql) @@ -1360,7 +1582,8 @@ def createdb(new_bdd): cursor.execute(sql) sql = "INSERT INTO modules VALUES(65, 'Indéfini', '0', '0', '0')" cursor.execute(sql) - sql = "INSERT INTO modules VALUES(66, 'Très petit corona', '40', '15.88', '102')" + sql = ("INSERT INTO modules VALUES(66, 'Très petit corona', '40', " + "'15.88', '102')") cursor.execute(sql) sql = "INSERT INTO modules VALUES(67, 'Toro', '52', '20.8', '152')" cursor.execute(sql) @@ -1436,9 +1659,11 @@ def createdb(new_bdd): cursor.execute(sql) sql = "INSERT INTO marques VALUES(34, 'Villa Zamorano', 'Honduras')" cursor.execute(sql) - sql = "INSERT INTO marques VALUES(35, 'Flor de Rafaël Gonzáles Márquez', 'cuba')" + sql = ("INSERT INTO marques VALUES(35, " + "'Flor de Rafaël Gonzáles Márquez', 'cuba')") cursor.execute(sql) - sql = "INSERT INTO marques VALUES(36, 'Macanudo', 'République Dominicaine')" + sql = ("INSERT INTO marques VALUES(36, 'Macanudo', " + "'République Dominicaine')") cursor.execute(sql) sql = "INSERT INTO marques VALUES(37, 'Pléiades', 'Nicaragua')" cursor.execute(sql) @@ -1446,7 +1671,8 @@ def createdb(new_bdd): cursor.execute(sql) sql = "INSERT INTO marques VALUES(39, 'Davidoff', 'cuba')" cursor.execute(sql) - sql = "INSERT INTO marques VALUES(40, 'Avo Uvezian', 'République Dominicaine')" + sql = ("INSERT INTO marques VALUES(40, 'Avo Uvezian', " + "'République Dominicaine')") cursor.execute(sql) sql = "INSERT INTO marques VALUES(41, 'Don Pepin Garcia', 'Nicaragua')" cursor.execute(sql) @@ -1461,26 +1687,26 @@ def createdb(new_bdd): def checkconfig(): """Récupérer la configuration ou la créer""" # Fichier de configuration - #configfile = os.path.expanduser("~/.config/cltwit.conf") + # configfile = os.path.expanduser("~/.config/cltwit.conf") # On ouvre le fichier de conf config = configparser.RawConfigParser() try: config.read(__CONFIGFILE__) if config.has_option('MesCigares', 'bdd'): bdd = config.get('MesCigares', 'bdd') - except: + except Exception: pass if not os.path.exists(bdd): createdb(bdd) # Si aucune conf - if not(config.has_option('MesCigares', 'bdd')): + if not config.has_option('MesCigares', 'bdd'): bdd = __CONFDIR__ + "/bdd/main.db" # écrire le fichier de conf avec les informations par defaut try: cfgfile = open(__CONFIGFILE__, 'w') - if not(config.has_section('MesCigares')): + if not config.has_section('MesCigares'): config.add_section('MesCigares') config.set('MesCigares', 'bdd', bdd) config.write(cfgfile) @@ -1489,7 +1715,7 @@ def checkconfig(): finally: cfgfile.close createdb(bdd) - return(bdd) + return bdd def setconfig(new_bdd): @@ -1497,7 +1723,7 @@ def setconfig(new_bdd): config = configparser.RawConfigParser() try: cfgfile = open(__CONFIGFILE__, 'w') - if not(config.has_section('MesCigares')): + if not config.has_section('MesCigares'): config.add_section('MesCigares') config.set('MesCigares', 'bdd', new_bdd) config.write(cfgfile) @@ -1506,9 +1732,12 @@ def setconfig(new_bdd): finally: cfgfile.close + if __name__ == "__main__": dbconf = checkconfig() db = sqlite3.connect(dbconf) main = MesCigares() - main.window.set_title("MesCigares - base : {0}".format(ntpath.basename(dbconf)).replace('.db', '')) + main.window.set_title( + "MesCigares - base : {0}".format(ntpath.basename(dbconf)) + .replace('.db', '')) gtk.main() diff --git a/app_gestion/bdd/main.db b/app_gestion/bdd/main.db index f2efd4f591c4a4d994883f58f6d1a36b3dfb1f52..60ce5ac88dee5dc6d075b1ad9277f3ab08d96dcb 100644 GIT binary patch delta 640 zcmb7?!Al!K6vp41w`($yXwprZt|?k$NrE6|qfv7x1dGRlLg}ec&`r~dU@t;s7~&$H zTU`p`O$$Ykf*}_V`3GuGJ>_4h)gC-3h?mZYwmEpv4`$xs`_0G4V^*pw)lW%Gu0MWm zCSmC4cir8hhd~MhfJyT}$Ml_c=_Ae4i@NuUY6E5fcz<62o#L>QAI|5Tf_tM^{;)LcRWHl(kBDyw-a#b7DVX8nD{|*L_>5R7$x$O$?kovQQ)8 z_VA97?u&E=bVk1#QR9e`98HKKE-zU{Z5k8-YEqR(DYETREoE3L1;drZ)A-i(gn~3ovMZZp@fMBaLiu)96SWtq&VAWQ;o>e0`os- YdXW43nQ1?lDf{2jtNv8_-A*?47ahHuTL1t6 delta 139 zcmV;60CfL=cz}428vzNC976>O04?Gvv1FP90to}M7z6~P1Q-Of1Q`4SvJeCevji9d z1PILl0nGwX0?V<1zX1w?009RV85seATa$JlT$AG;9h31Md$YV9H31L}000050m=XZ tMFOn@Fawpd5F|AMlb9!HlNBd}ldvXblSL*P0SJ>|CQy