IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

wxPython Discussion :

WxPython Frame


Sujet :

wxPython

Vue hybride

Message précédent Message précédent   Message suivant Message suivant
  1. #1
    Invité
    Invité(e)
    Par défaut WxPython Frame
    Bonjour à tous,

    Je suis plus que débutant et mon défi est de créer une application de gestion de magasin informatique.

    Je veux faire très simple un menu avec une barre d'outils et le tout dans UNE seule fenêtre.

    Est ce possible ?

    Voici mon code :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    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
    204
    205
    206
    207
    208
    209
    210
    211
    212
    213
    214
    215
    216
    217
    218
    219
    220
    221
    222
    223
    224
    225
    226
    227
    228
    229
    230
    231
    232
    233
    234
    235
    236
    237
    238
    239
    240
    241
    242
    243
    244
    245
    246
    247
    248
    249
    250
    251
    252
    253
    254
    255
    256
    257
    258
    259
    260
    261
    262
    263
    264
     
    #!/usr/bin/python
    # -*- coding: iso-8859-15 -*-
    import wx
    import os
     
    ID_CONNEXION=100
    ID_PRINTER=101
    #ID_EXIT=210
    ID_ASELL=102
    ID_MSELL=103
    ID_DSELL=104
    ID_APRODUCT=105
    ID_MPRODUCT=106
    ID_DPRODUCT=107
    ID_LPRODUCT=508
    ID_ACLIENT=108
    ID_MCLIENT=109
    ID_DCLIENT=110
    ID_LCLIENT=511
    ID_BARRE=111
    ID_CALCULATRICE=112
    ID_HELP=113
    ID_ABOUT=114
     
    #ID_PLUS=200
    #ID_MOINS=201
    ID_STOCK=202
    ID_FACTURE=203
     
    ID_BOUTON_OK=300
     
    class Principale(wx.Frame):
     
        def __init__(self, titre):
     
    	wx.Frame.__init__(self, None, -1, title = titre, size = (1000, 800))
     
    	#Item Menu Files
    	menuFiles = wx.Menu()
    	menuFiles.Append(ID_CONNEXION, "&Connexion", "Données de connexion DB")
    	menuFiles.AppendSeparator()
    	menuFiles.Append(ID_PRINTER, "Printing\tCTRL+p", "Imprimante par défaut")
    	menuFiles.AppendSeparator()
    	menuFiles.Append(wx.ID_EXIT, "&Exit\tCTRL+q", "Quitter l'application")
     
    	#Item Menu Sell
    	menuSell = wx.Menu()
    	menuSell.Append(ID_ASELL, "New sell", "Nouvelle vente")
    	menuSell.Append(ID_MSELL, "Modify sell", "Modifier une vente")
    	menuSell.Append(ID_DSELL, "Delete sell", "Supprimer une vente")
     
    	#Item Menu Product
    	menuProduct = wx.Menu(style = wx.MENU_TEAROFF)
    	menuProduct.Append(ID_APRODUCT, "New product","Nouveau produit")
     
     
    	#Item Menu Customer
    	menuCustomer = wx.Menu(style = wx.MENU_TEAROFF)
    	menuCustomer.Append(ID_ACLIENT, "New Client", "Nouveau client")
    	menuCustomer.Append(ID_MCLIENT, "Modify client", "Modifier un client")
    	menuCustomer.Append(ID_DCLIENT, "Delete client", "Supprimer un client")
     
    	#Item Menu Tools
    	menuTools = wx.Menu(style = wx.MENU_TEAROFF)
    	menuTools.Append(ID_BARRE,"&Barre d'etat", "Afficher ou non la barre d'état",kind=wx.ITEM_CHECK)
    	menuTools.Append(ID_CALCULATRICE, "&Calculatrice", "Ouvrir la calculatrice")
     
    	#Item Menu About
    	menuAbout = wx.Menu(style = wx.MENU_TEAROFF)
    	menuAbout.Append(ID_HELP, "&Help", "Please Help Me!")
    	menuAbout.Append(ID_ABOUT, "&About...", "Shop  : what is that ?")
     
    	#Item Title Barre Menu
    	menuBarre = wx.MenuBar()
    	menuBarre.Append(menuFiles, "&Files")
    	menuBarre.Append(menuSell, "&Sell")
    	menuBarre.Append(menuProduct, "&Products")
    	menuBarre.Append(menuCustomer, "&Clients")
    	menuBarre.Append(menuTools, "&Tools")
    	menuBarre.Append(menuAbout, "Help")
    	self.SetMenuBar(menuBarre)
     
    	#Barre de Statut
    	self.barre = wx.StatusBar(self, -1)
    	self.barre.SetFieldsCount(2)
    	self.barre.SetStatusWidths([-1, -1])
    	self.SetStatusBar(self.barre)
     
    	#Item Barre d'outils
    	outils = wx.ToolBar(self, -1, style = wx.TB_HORIZONTAL | wx.NO_BORDER)
    	outils.AddSimpleTool(ID_CONNEXION, 
    			    wx.Bitmap("connection.png", wx.BITMAP_TYPE_PNG),
    			    shortHelpString = "Connexion",
    			    longHelpString = "Vérifier les données de connexions")
     
    	outils.AddSimpleTool(ID_STOCK,
    			    wx.Bitmap("stock.png", wx.BITMAP_TYPE_PNG),
    			    shortHelpString = "Stock",
    			    longHelpString = "Voir les articles en stock")
     
    	outils.AddSimpleTool(ID_ASELL,
    			    wx.Bitmap("vente.png", wx.BITMAP_TYPE_PNG),
    			    shortHelpString = "Vente", 
    			    longHelpString = "Nouvelle vente")
     
    	outils.AddSimpleTool(ID_LPRODUCT,
    			    wx.Bitmap("Products.png", wx.BITMAP_TYPE_PNG),
    			    shortHelpString = "Products",
    			    longHelpString = "Gérer les produits")
     
    	outils.AddSimpleTool(ID_LCLIENT,
                                wx.Bitmap("client.png", wx.BITMAP_TYPE_PNG),
                                shortHelpString = "Customer",
                                longHelpString = "Gérer les clients")
     
    	outils.AddSimpleTool(ID_FACTURE,
                                wx.Bitmap("facture.png", wx.BITMAP_TYPE_PNG),
                                shortHelpString = "Facture",
                                longHelpString = "Voir une facture")
     
    	outils.AddSimpleTool(ID_CALCULATRICE,
                                wx.Bitmap("Calculatrice.png", wx.BITMAP_TYPE_PNG),
                                shortHelpString = "Calculatrice",
                                longHelpString = "Lancer la calculatrice")
     
    	outils.AddSimpleTool(wx.ID_EXIT,
    			    wx.Bitmap("Exit.png", wx.BITMAP_TYPE_PNG),
    			    shortHelpString = "Quitter",
    			    longHelpString = "Quitter l'application")
     
    	outils.Realize()
    	self.SetToolBar(outils)
     
     
    #	wx.EVT_MENU(self, wx.ID_OPEN, self.OnOpen)
    #	wx.EVT_MENU(self, wx.ID_CLOSE, self.OnClose)
    #	wx.EVT_MENU(self, wx.ID_UNDO, self.Retour)
    #	wx.EVT_MENU(self, ID_PLUS, self.Plus)
    #	wx.EVT_MENU(self, ID_MOINS, self.Moins)
    	wx.EVT_MENU(self, ID_APRODUCT, self.aproduct)
    	wx.EVT_MENU(self, ID_ACLIENT, self.acustomer)
    	wx.EVT_MENU(self, ID_CALCULATRICE, self.Calculatrice)
    	wx.EVT_MENU(self, wx.ID_EXIT, self.OnExit)
    	wx.EVT_MENU(self, ID_ABOUT, self.About)
    	wx.EVT_MENU(self, ID_LPRODUCT, self.lproduct)
     
        #Définition des différentes fonctions
        def aproduct(self,evt):
    	self.Clear(True)
            wx.StaticText(self, -1, 'Numéro de l\'article		:', (10, 20))
            wx.StaticText(self, -1, 'Manufacturier				:', (10, 60))
            wx.StaticText(self, -1, 'Modèle					:', (10, 100))
            wx.StaticText(self, -1, 'Prix HTVA				:', (10, 140))
            wx.StaticText(self, -1, 'Taux TVA					:', (10, 180))
            wx.StaticText(self, -1, 'Montant TVA				:', (10, 220))
            wx.StaticText(self, -1, 'Prix TVAC				:', (10, 260))
            wx.StaticText(self, -1, 'Prix promotion			:', (10, 300))
            wx.StaticText(self, -1, 'Nombre de produit en stock	:', (10, 340))
            wx.StaticText(self, -1, 'Stock minimum			:', (10, 380))
            wx.StaticText(self, -1, 'Description				:', (10, 420))
     
    	self.txt_barre_code = wx.TextCtrl(self, -1, '',  (230, 15), (120, -1))
     
    	self.txt_manufacturier= wx.TextCtrl(self, -1, '',  (230, 55), (320, -1))
     
    	self.txtmodele= wx.TextCtrl(self, -1, '',  (230, 95), (320, -1))
     
    	self.txt_prix_htva= wx.TextCtrl(self, -1, '',  (230, 135), (320, -1))
     
    	self.txt_taux_tva= wx.TextCtrl(self, -1, '',  (230, 175), (320, -1))
     
    	self.txt_tva= wx.TextCtrl(self, -1, '',  (230, 215), (320, -1))
     
    	self.txt_tva= wx.TextCtrl(self, -1, '',  (230, 255), (320, -1))
     
    	self.txt_prix_promo= wx.TextCtrl(self, -1, '',  (230, 295), (320, -1))
     
    	self.txt_qtite_stock= wx.TextCtrl(self, -1, '',  (230, 335), (320, -1))
     
    	self.txt_qtite_min= wx.TextCtrl(self, -1, '',  (230, 375), (320, -1))
     
    	self.txt_description= wx.TextCtrl(self, -1, '',  (230, 415), (320, -1))
    	btn_retour = wx.Button(self, ID_BOUTON_OK, 'Retour', (230,465), size=(100, 30))
     
    	self.Refresh(True)
    	self.Update()
     
     
        def lproduct(self,evt):
            wx.StaticText(self, -1, 'Numéro d\'article	:', (10, 20)) 
    	self.txt_barre_code = wx.TextCtrl(self, -1, '',  (180, 15), (120, -1))
     
     
     
     
        def acustomer(self,evt):
    	self.Close()
            wx.StaticText(self, -1, 'Numéro de client		:', (10, 20))
            wx.StaticText(self, -1, 'Nom				:', (10, 60))
            wx.StaticText(self, -1, 'Prénom				:', (10, 100))
            wx.StaticText(self, -1, 'Adresse				:', (10, 140))
            wx.StaticText(self, -1, 'Code postal			:', (10, 180))
            wx.StaticText(self, -1, 'Ville				:', (10, 220))
            wx.StaticText(self, -1, 'Pays				:', (10, 260))
            wx.StaticText(self, -1, 'Numéro de Téléphone	:', (10, 300))
            wx.StaticText(self, -1, 'Numéro de Fax		:', (10, 340))
            wx.StaticText(self, -1, 'E-mail				:', (10, 380))
            wx.StaticText(self, -1, 'Numéro de TVA		:', (10, 420))
     
    	self.txt_num_client = wx.TextCtrl(self, -1, '',  (230, 15), (120, -1))
     
    	self.txt_nom = wx.TextCtrl(self, -1, '',  (230, 55), (320, -1))
     
    	self.txt_prenom = wx.TextCtrl(self, -1, '',  (230, 95), (320, -1))
     
    	self.txt_adresse = wx.TextCtrl(self, -1, '',  (230, 135), (320, -1))
     
    	self.txt_code_postal = wx.TextCtrl(self, -1, '',  (230, 175), (320, -1))
     
    	self.txt_ville = wx.TextCtrl(self, -1, '',  (230, 215), (320, -1))
     
    	self.txt_pays = wx.TextCtrl(self, -1, '',  (230, 255), (320, -1))
     
    	self.txt_num_tel = wx.TextCtrl(self, -1, '',  (230, 295), (320, -1))
     
    	self.txt_num_fax = wx.TextCtrl(self, -1, '',  (230, 335), (320, -1))
     
    	self.txt_email = wx.TextCtrl(self, -1, '',  (230, 375), (320, -1))
     
    	self.txt_num_tva = wx.TextCtrl(self, -1, '',  (230, 415), (320, -1))
    	btn_retour = wx.Button(self, ID_BOUTON_OK, 'Retour', (230,465), size=(100, 30))
     
        def Calculatrice(self,evt):
    	os.system("gcalctool")
     
        def About(self,evt):
            dlg = wx.MessageDialog(self, "\nGes v.1.0\n\n"
     
                    "Programme écrit en Python / Tkinter / SQL \n"
     
                    "et distribué sous licence GNU GPL.\n\n"
                    "\nCe programme permet de gérer le magasin\n", "- Ges -")
            dlg.ShowModal()
            dlg.Destroy()
     
     
        def OnExit(self,evt):
    	self.Destroy()
     
     
    class MonApp(wx.App):
        def OnInit(self):
    	fen = Principale(" - SHOP  - ")
    	fen.Show(True)
    	self.SetTopWindow(fen)
    	return True
     
    ###############################################################################
    # Debut du programme
    ###############################################################################
     
    app = MonApp()
    app.MainLoop()
    Ma question est pourquoi quand je clique sur la barre outils (produit) puis sur le menu Add product --> Comment effacer l'ancien formulaire par le nouveau...
    ???
    Desolé si c'est évident... Merci de votre aide
    Dernière modification par Invité ; 05/08/2009 à 11h08.

  2. #2
    Membre Expert Avatar de pacificator
    Profil pro
    Inscrit en
    Août 2006
    Messages
    1 074
    Détails du profil
    Informations personnelles :
    Âge : 45
    Localisation : France

    Informations forums :
    Inscription : Août 2006
    Messages : 1 074
    Par défaut
    Bonjour,

    tu devrais placer tes differentes vues dans des wx.Panel différents, tu pourras alors les interchanger au besoin:
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    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
    #!/usr/bin/python
    #-*- coding: iso-8859-15 -*-
    import wx
    import os
     
     
    class Principale(wx.Frame):
     
        def __init__(self, titre):
            wx.Frame.__init__(self, None, -1, title = titre, size = (1000, 800))
            self.colors= [("rouge", wx.RED), ("bleu", wx.BLUE), ("vert", wx.GREEN)]
            self.CreatePanels()
            self.CreateMenu()
            self.DoBinding()
     
        def CreatePanels(self):
            self.panels = []
            for n,c in self.colors:
                panel = wx.Panel(self, -1)
                panel.SetBackgroundColour(c)
                panel.Show(False)
                panel.SetSize(self.GetSize())
                self.panels.append(panel)
            self.panels[0].Show(True)
     
        def CreateMenu(self):
            menu = wx.Menu()
            for i,(n,c) in enumerate(self.colors):
                menu.Append(1000+i, n)
            menuBar = wx.MenuBar()
            menuBar.Append(menu, "Couleurs")
            self.SetMenuBar(menuBar)
     
        def DoBinding(self):
            for i in range(len(self.colors)):
                wx.EVT_MENU(self, 1000+i, self.OnEventMenuChangePanel)
     
        def OnEventMenuChangePanel(self, evt):
            i = evt.GetId()-1000
            if not i in range(len(self.colors)):
                evt.Skip()
                return False
            for panel in self.panels:
                panel.Show(False)
            self.panels[i].Show(True)
            evt.Skip()
     
     
    class MonApp(wx.App):
     
        def OnInit(self):
        fen = Principale(" - SHOP  - ")
        fen.Show(True)
        self.SetTopWindow(fen)
        return True
     
    if __name__ == '__main__':
        app = MonApp()
        app.MainLoop()

  3. #3
    Invité
    Invité(e)
    Par défaut
    En fait, j'ai trouvé ceci

    self.DestroyChildren()

    Ca fait ce que je veux aussi

    Mais je vais tester ta solution qui me semble mieux Encore merci

+ Répondre à la discussion
Cette discussion est résolue.

Discussions similaires

  1. Réponses: 1
    Dernier message: 05/10/2009, 22h13
  2. [wxPython] : iconized frame (fenetre reduite)
    Par pyNox dans le forum wxPython
    Réponses: 1
    Dernier message: 18/03/2006, 21h07
  3. [wxpython] creer deux panel dans une frame
    Par hysah dans le forum wxPython
    Réponses: 3
    Dernier message: 27/12/2005, 18h21
  4. [wxPython][wxFrame]Comment fermer proprement une frame ?
    Par Screameur dans le forum wxPython
    Réponses: 4
    Dernier message: 12/05/2005, 19h49
  5. [wxpython][wx.frame] mettre une image sur un bouton
    Par Kyti dans le forum wxPython
    Réponses: 7
    Dernier message: 02/05/2005, 12h13

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo