| 12
 3
 4
 5
 6
 7
 8
 9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
 100
 101
 102
 103
 104
 105
 106
 107
 108
 109
 110
 111
 112
 113
 114
 115
 116
 117
 118
 119
 120
 121
 122
 123
 124
 125
 126
 127
 128
 129
 130
 131
 132
 133
 134
 135
 136
 137
 138
 139
 140
 141
 142
 143
 144
 145
 146
 147
 148
 149
 150
 151
 152
 153
 154
 155
 156
 157
 158
 159
 160
 161
 162
 163
 164
 165
 166
 167
 168
 169
 170
 171
 172
 173
 174
 175
 176
 177
 178
 179
 180
 181
 182
 183
 184
 185
 186
 187
 188
 189
 190
 191
 192
 193
 194
 195
 196
 197
 198
 199
 200
 201
 202
 203
 
 | #!/usr/bin/env python3
# -*- coding: utf-8 -*-
 
import datetime
from tkinter import *
 
# exemple avec la classe Ticket
 
def today ():
    return str(datetime.date.today())
# end def
 
class Ticket:
    def __init__ (self, **kw):
        # init membres de la classe
        self.identifiant = id(self)
        self.commande_client = kw.get("commande_client")
        self.date_impression = kw.get("date_impression") or today()
        self.offres_speciales = kw.get("offres_speciales")
        self.mentions_legales = kw.get("mentions_legales")
        # ...etc...
    # end def
# end class Ticket
 
class TicketView:
    DEFAULT_TEMPLATE = """\
Ticket no. : {id_ticket}
Commande no. : {id_commande}
Client : {id_client}    date : {date_impression}
 
{liste_produits}
 
{offres_speciales}
 
{mentions_legales}
"""
    def __init__ (self, **kw):
        # init membres de la classe
        self.ticket = kw.get("ticket")
        self.template = kw.get("template") or self.DEFAULT_TEMPLATE
    # end def
 
    def get_output (self):
        """
            ici, on fournit le résultat à afficher sous forme d'une
            chaîne de caractères qui pourra être remaniée par
            l'objet spécialisé affichage spécifique à l'application
            en cours;
        """
        # c'est du brut de décoffrage - il faut peaufiner bien sûr
        fields = dict(
            id_ticket=self.identifiant,
            id_commande=self.ticket.commande_client.identifiant,
            id_client=self.ticket.commande_client.client.identifiant,
            date_impression=self.ticket.date_impression,
            liste_produits=self.ticket.get_facture(formatter=str),
            offres_speciales=self.ticket.offres_speciales,
            mentions_legales=self.ticket.mentions_legales,
        )
        return str(self.template).format(**fields)
    # end def
# end class TicketView
 
class CommandeClient:
    def __init__ (self, **kw):
        # init membres de la classe
        self.identifiant = id(self)
        self.client = kw.get("client")
        self.date_commande = kw.get("date_commande") or today()
        self.liste_produits = list()
        # ...etc...
    # end def
# end class CommandeClient
 
class Client:
    def __init__ (self, **kw):
        # init membres de la classe
        self.identifiant = id(self)
        self.nom = kw.get("nom")
        self.prenom = kw.get("prenom")
        self.adresse = kw.get("adresse")
        self.code_postal = kw.get("code_postal")
        self.ville = kw.get("ville")
        # ...etc...
    # end def
# end class Client
 
class Application (Tk):
    def __init__ (self, **kw):
        # super class inits first /!\
        Tk.__init__(self)
        # maintenant, on peut instancier les principaux objets
        self.init_widgets(**kw)
    # end def
 
    def init_widgets (self, **kw):
        "on instancie les composants du logiciel ici"
        # un peu de bazar
        self.title("Exemple ticket de caisse")
        self.resizable(width=False, height=False)
        # ouvrir une connexion BDD
        # récupérer liste produits à vendre
        # etc
        pass
        # objets affichage
        self.view_produits = Canvas(
            self, bg="sky blue", width=200, height=300
        )
        self.view_commande = Canvas(
            self, bg="pale goldenrod", width=200, height=300
        )
        self.bouton_ajouter = Button(
            self, text="Ajouter >>", command=None,
        )
        self.bouton_enlever = Button(
            self, text="<< Enlever", command=None,
        )
        self.bouton_valider = Button(
            self, text="Valider\ncommande", command=None,
        )
        self.bouton_annuler = Button(
            self, text="Annuler\ncommande", command=None,
        )
        self.bouton_quitter = Button(
            self, text="Quitter\nl'application", command=self.quit,
        )
        # layout inits
        Label(
            self,
            text="Produits disponibles:"
        ).grid(row=0, column=0, padx=5, pady=5)
        self.view_produits.grid(
            row=1,
            column=0,
            rowspan=6,
            sticky=NW+SE,
            padx=5,
            pady=5,
        )
        Label(
            self,
            text="Commande client:"
        ).grid(row=0, column=2, padx=5, pady=5)
        self.view_commande.grid(
            row=1,
            column=2,
            rowspan=6,
            sticky=NS,
            padx=5,
            pady=5,
        )
        self.bouton_ajouter.grid(row=3, column=1, sticky=EW)
        self.bouton_enlever.grid(row=5, column=1, sticky=EW)
        self.bouton_annuler.grid(row=10, column=0, padx=5, pady=5)
        self.bouton_valider.grid(row=10, column=1, padx=5)
        self.bouton_quitter.grid(row=10, column=2, sticky=E, padx=5)
        self.rowconfigure(2, weight=1)
        self.rowconfigure(6, weight=1)
    # end def
 
    def run (self, **kw):
        "on lance l'application ici"
        # première étape du programme
        self.nouvelle_commande(**kw)
        # on lance la boucle principale Tkinter
        self.mainloop()
    # end def
 
    def nouvelle_commande (self, **kw):
        "on crée une nouvelle commande pour un nouveau client"
        # inits - exemples bidons
        self.client = Client(
            nom="Cavère",
            prenom="Nicole",
            adresse="Rue de la Grotte",
        )
        self.commande_client = CommandeClient(client=self.client)
        # saisie nouvelle commande
        self.saisir_commande()
    # end def
 
    def saisir_commande (self):
        "on gère ici la saisie / modification d'une commande"
        # RAZ affichages
        self.view_produits.delete(ALL)
        self.view_commande.delete(ALL)
        # on re-remplit la liste des produits disponibles
        self.remplir_liste_produits()
        # ...etc...
        pass
    # end def
 
    def remplir_liste_produits (self):
        "...etc...etc..."
        pass
    # end def
# end class Application
 
# module appelé en tant que script à exécuter ?
if __name__ == "__main__":
    # on lance l'application
    Application().run()
# end if | 
Partager