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 :

Comment utiliser plusieurs panels ?


Sujet :

wxPython

  1. #1
    Membre du Club
    Profil pro
    Inscrit en
    Novembre 2010
    Messages
    8
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Novembre 2010
    Messages : 8
    Par défaut Comment utiliser plusieurs panels ?
    Bonjour,

    je suis en train d'essayer de comprendre comment gérer au mieux plusieurs panels au sein d'une même wx.Frame. J'ai fais un bout de code afin d'afficher 2 panels mais le résultat et assez étrange...

    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
     
    #!/usr/bin/env python
    #-*- coding: ISO-8859-1 -*-
     
    import wx
     
    class myApp(wx.Frame):
        #__init__:begin
        def __init__(self, parent, id, title):
            wx.Frame.__init__(self, parent, id, title)
     
            self.panel1 = wx.Panel(self, -1)
            self.panel2 = wx.Panel(self, -1)
     
            hbox = wx.BoxSizer(wx.HORIZONTAL)
            vbox1 = wx.BoxSizer(wx.VERTICAL)
            vbox2 = wx.BoxSizer(wx.VERTICAL)
     
            Text1 = wx.StaticText(self.panel1, -1, "coucou panel 1")
            ListBox = wx.ListBox(self.panel1, -1, choices=['1','2'])
     
            Text2 = wx.StaticText(self.panel2, -1, "coucou panel 2")
            Btn = wx.Button(self.panel2, -1, "coucou")
     
     
            vbox1.Add(Text1, 0)
            vbox1.Add(ListBox, 0)
     
            vbox2.Add(Text2, 0)
            vbox2.Add(Btn, 0)
     
            hbox.Add(vbox1, 1)
            hbox.Add(vbox2, 1)
     
            hbox.Add(self.panel1, 0)
            hbox.Add(self.panel2, 0)
     
            self.SetSizer(hbox)
            self.SetMinSize(self.GetMinSize())
            self.Fit()
     
            self.Centre()
            self.Show(True)
     
    app = wx.App()
    myApp(None, -1, 'myApp title')
    app.MainLoop()
    En attaché, le résultat obtenu... qui ne ressemble pas à grand chose !

    Qu'ai je loupé ?

    Merci de votre aide !
    Images attachées Images attachées  

  2. #2
    Membre expérimenté
    Profil pro
    Inscrit en
    Décembre 2007
    Messages
    222
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Décembre 2007
    Messages : 222
    Par défaut
    Bonjour,
    Il y a plusieurs erreurs dans ton code.
    Tout d'abord il faut associer les sizers des panels avec SetSizer et il ne faut pas ajouter ces sizers au sizer principal:

    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
     
    #!/usr/bin/env python
    #-*- coding: ISO-8859-1 -*-
     
    import wx
     
    class myApp(wx.Frame):
        #__init__:begin
        def __init__(self, parent, id, title):
            wx.Frame.__init__(self, parent, id, title)
     
            self.panel1 = wx.Panel(self, -1)
            self.panel2 = wx.Panel(self, -1)
     
            hbox = wx.BoxSizer(wx.HORIZONTAL)
            vbox1 = wx.BoxSizer(wx.VERTICAL)
            vbox2 = wx.BoxSizer(wx.VERTICAL)
     
            Text1 = wx.StaticText(self.panel1, -1, "coucou panel 1")
            ListBox = wx.ListBox(self.panel1, -1, choices=['1','2'])
     
            Text2 = wx.StaticText(self.panel2, -1, "coucou panel 2")
            Btn = wx.Button(self.panel2, -1, "coucou")
     
            self.panel1.SetSizer(vbox1)
            self.panel2.SetSizer(vbox2)
     
            vbox1.Add(Text1, 0)
            vbox1.Add(ListBox, 0)
     
            vbox2.Add(Text2, 0)
            vbox2.Add(Btn, 0)
     
            hbox.Add(self.panel1, 0)
            hbox.Add(self.panel2, 0)
     
            self.SetSizer(hbox)
     
            self.Fit()
     
            self.Centre()
            self.Show(True)
     
    app = wx.App()
    myApp(None, -1, 'myApp title')
    app.MainLoop()
    Pour se genre de rendu les panels ne sont pas indispensable, tu peux t'en sortir uniquement avec des sizers:
    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
     
    #!/usr/bin/env python
    #-*- coding: ISO-8859-1 -*-
     
    import wx
     
    class myApp(wx.Frame):
        #__init__:begin
        def __init__(self, parent, id, title):
            wx.Frame.__init__(self, parent, id, title)
     
            hbox = wx.BoxSizer(wx.HORIZONTAL)
            vbox1 = wx.BoxSizer(wx.VERTICAL)
            vbox2 = wx.BoxSizer(wx.VERTICAL)
     
            Text1 = wx.StaticText(self, -1, "coucou panel 1")
            ListBox = wx.ListBox(self, -1, choices=['1','2'])
     
            Text2 = wx.StaticText(self, -1, "coucou panel 2")
            Btn = wx.Button(self, -1, "coucou")
     
            vbox1.Add(Text1, 0)
            vbox1.Add(ListBox, 0)
     
            vbox2.Add(Text2, 0)
            vbox2.Add(Btn, 0)
     
            hbox.Add(vbox1, 0)
            hbox.Add(vbox2, 0)
     
            self.SetSizer(hbox)
     
            self.Fit()
     
            self.Centre()
            self.Show(True)
     
    app = wx.App()
    myApp(None, -1, 'myApp title')
    app.MainLoop()
    J'ai l'impression que tu as fais un mixte de ces deux codes.

  3. #3
    Membre du Club
    Profil pro
    Inscrit en
    Novembre 2010
    Messages
    8
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Novembre 2010
    Messages : 8
    Par défaut
    Merci beaucoup pour ta réponse. Effectivement je pourrais utiliser uniquement des sizers pour obtenir ce genre de rendu mais je cherche à mettre à jour une image qui serait affichée sur la même Frame après avoir sélectionné une entrée dans une ListBox. Je pensais qu'en utilisant plusieurs panel, on pourrait mettre à jour la valeur de wx.Image... j'ai eu beau chercher quelques exemples, malheureusement sans succès... Si quelqu'un a un exemple de script fonctionnel, je suis preneur ! :-)

  4. #4
    Membre expérimenté
    Profil pro
    Inscrit en
    Décembre 2007
    Messages
    222
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Décembre 2007
    Messages : 222
    Par défaut
    wx.Image est utile pour le traitement d'une image, ça ne sert pas à afficher une image dans la frame.
    Ce que cherche est plutôt un wx.StaticBitmap.
    Ensuite il n'y a pas de rapport entre le faite d'utiliser des panels et l'affichage (et la mise à jour) d'un wx.StaticBitmap (ou de n'importe quelle contrôle). Tu peux très bien les afficher dans des sizers.
    Voici un petit exemple vite fait, qui permet de changer une image en la sélectionnant dans une listbox. Bien sûr tu dois modifier image1.jpg, image2.jpg... par le nom des images présentes dans ton dossier:

    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
     
    #!/usr/bin/env python
    #-*- coding: ISO-8859-1 -*-
     
    import wx
     
    class myApp(wx.Frame):
        def __init__(self, parent, id, title):
            wx.Frame.__init__(self, parent, id, title)
     
            hbox = wx.BoxSizer(wx.HORIZONTAL)
            vbox1 = wx.BoxSizer(wx.VERTICAL)
            vbox2 = wx.BoxSizer(wx.VERTICAL)
     
            listImg = (("image1", "image1.jpg"), ("image2", "image2.jpg"), 
                ("image3", "image3.jpg"), ("image4", "image4.jpg"))
     
            text1 = wx.StaticText(self, -1, "liste des images:")
            listBox = wx.ListBox(self, -1, size=(200, 300))
     
            listBox.Bind(wx.EVT_LISTBOX, self.onImgChange)
     
     
            text2 = wx.StaticText(self, -1, "Mon image sélectionnée:")
            self.staticBitmap = wx.StaticBitmap(self, -1)
     
            vbox1.Add(text1, 0, wx.ALIGN_CENTER)
            vbox1.Add(listBox, 0, wx.ALIGN_CENTER)
     
            vbox2.Add(text2, 0, wx.ALIGN_CENTER)
            vbox2.Add(self.staticBitmap, 0, wx.ALIGN_CENTER)
     
            hbox.Add(vbox1, 0, wx.RIGHT, 30)
            hbox.Add(vbox2, 0)
     
            self.SetSizer(hbox)
     
            for imgName, imgPath in listImg:
                i = listBox.Append(imgName)
                listBox.SetClientData(i, imgPath)
     
            self.Fit()
            self.Centre()
            self.Show(True)
     
        def onImgChange(self, e):
            bmp = wx.Bitmap(e.GetClientData())
            self.staticBitmap.SetBitmap(bmp)
            self.Fit()
     
    app = wx.App()
    myApp(None, -1, 'myApp title')
    app.MainLoop()
    Si le nombre de photos n'est pas trop important tu peux les précharger au démarrage:

    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
     
    #!/usr/bin/env python
    #-*- coding: ISO-8859-1 -*-
     
    import wx
     
    class myApp(wx.Frame):
        def __init__(self, parent, id, title):
            wx.Frame.__init__(self, parent, id, title)
     
            hbox = wx.BoxSizer(wx.HORIZONTAL)
            vbox1 = wx.BoxSizer(wx.VERTICAL)
            vbox2 = wx.BoxSizer(wx.VERTICAL)
     
            listImg = (("image1", wx.Bitmap("image1.jpg")), ("image2", wx.Bitmap("image2.jpg")), 
                ("image3", wx.Bitmap("image3.jpg")), ("image4", wx.Bitmap("image4.jpg")))
     
            text1 = wx.StaticText(self, -1, "liste des images:")
            listBox = wx.ListBox(self, -1, size=(200, 300))
     
            listBox.Bind(wx.EVT_LISTBOX, self.onImgChange)
     
     
            text2 = wx.StaticText(self, -1, "Mon image sélectionnée:")
            self.staticBitmap = wx.StaticBitmap(self, -1)
     
            vbox1.Add(text1, 0, wx.ALIGN_CENTER)
            vbox1.Add(listBox, 0, wx.ALIGN_CENTER)
     
            vbox2.Add(text2, 0, wx.ALIGN_CENTER)
            vbox2.Add(self.staticBitmap, 0, wx.ALIGN_CENTER)
     
            hbox.Add(vbox1, 0, wx.RIGHT, 30)
            hbox.Add(vbox2, 0)
     
            self.SetSizer(hbox)
     
            for imgName, bmp in listImg:
                i = listBox.Append(imgName)
                listBox.SetClientData(i, bmp)
     
            self.Fit()
            self.Centre()
            self.Show(True)
     
        def onImgChange(self, e):
            self.staticBitmap.SetBitmap(e.GetClientData())
            self.Fit()

  5. #5
    Membre du Club
    Profil pro
    Inscrit en
    Novembre 2010
    Messages
    8
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Novembre 2010
    Messages : 8
    Par défaut
    mille merci pour ton aide ! Ca marche parfaitement et effectivement, je n'etais pas du tout dans la bonne direction...

    J'ai juste eu à modifier la fonction onImgChange en ajoutant self.Refresh() afin que les images ne se superposent pas à la sélection.

    Encore merci ! :

Discussions similaires

  1. Comment utiliser plusieurs boutons submit dans un seul formulaire ?
    Par Alexandrebox dans le forum Général JavaScript
    Réponses: 2
    Dernier message: 04/06/2009, 19h27
  2. Comment utiliser plusieurs ResourceBundle avec struts-menu ?
    Par m.ben.hamida dans le forum Struts 1
    Réponses: 5
    Dernier message: 18/02/2008, 12h14
  3. [C#][Mysql]Comment utiliser plusieurs dataset sur la même connexion
    Par Invité dans le forum Accès aux données
    Réponses: 3
    Dernier message: 05/12/2006, 09h30
  4. Réponses: 5
    Dernier message: 24/08/2006, 15h00
  5. TPanel OnMouseEnter... comment selectionner plusieurs panel
    Par seb8810 dans le forum Composants VCL
    Réponses: 7
    Dernier message: 02/02/2006, 16h02

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