Contenu | Rechercher | Menus

Annonce

Si vous avez des soucis pour rester connecté, déconnectez-vous puis reconnectez-vous depuis ce lien en cochant la case
Me connecter automatiquement lors de mes prochaines visites.

À propos de l'équipe du forum.

#1 Le 11/05/2008, à 18:18

g_barthe

[Résolu] [Python] Pb évènement wxpython

Bonsoir,

J'ai commencé un développement avec python et wxpython et je construis mon interface avec wxglade qui me parait "simple" à prendre en main.

J'ai généré le code de mon interface que voici :

#!/usr/bin/env python
# -*- coding: utf-8 -*-
# generated by wxGlade 0.6.3 on Sun May 11 18:13:21 2008

import wx

# begin wxGlade: extracode
# end wxGlade

class wxNotebook_1(wx.Notebook):
    def __init__(self, *args, **kwds):
        # begin wxGlade: wxNotebook_1.__init__
        kwds["style"] = 0
        wx.Notebook.__init__(self, *args, **kwds)
        self.notebook_1_pane_2 = wx.Panel(self, -1)
        self.notebook_1_pane_1 = wx.Panel(self, -1)
        self.label_1 = wx.StaticText(self.notebook_1_pane_1, -1, u"Température : ")
        self.T_cas_1 = wx.TextCtrl(self.notebook_1_pane_1, -1, "")
        self.label_4 = wx.StaticText(self.notebook_1_pane_1, -1, u"°C")
        self.label_20 = wx.StaticText(self.notebook_1_pane_1, -1, "")
        self.label_13 = wx.StaticText(self.notebook_1_pane_1, -1, "Pvs : ")
        self.pvs_cas_1 = wx.TextCtrl(self.notebook_1_pane_1, -1, "")
        self.label_8 = wx.StaticText(self.notebook_1_pane_1, -1, "Pa")
        self.label_2 = wx.StaticText(self.notebook_1_pane_1, -1, u"Hygrométrie : ")
        self.HR_cas_1 = wx.TextCtrl(self.notebook_1_pane_1, -1, "")
        self.label_5 = wx.StaticText(self.notebook_1_pane_1, -1, "%")
        self.label_21 = wx.StaticText(self.notebook_1_pane_1, -1, "")
        self.label_14 = wx.StaticText(self.notebook_1_pane_1, -1, "Pv : ")
        self.pv_cas_1 = wx.TextCtrl(self.notebook_1_pane_1, -1, "")
        self.label_9 = wx.StaticText(self.notebook_1_pane_1, -1, "Pa")
        self.label_3 = wx.StaticText(self.notebook_1_pane_1, -1, "Pression atm : ")
        self.p_atm_cas_1 = wx.TextCtrl(self.notebook_1_pane_1, -1, "")
        self.label_6 = wx.StaticText(self.notebook_1_pane_1, -1, "Pa")
        self.b_cas_1 = wx.Button(self.notebook_1_pane_1, -1, "Calculer")
        self.label_15 = wx.StaticText(self.notebook_1_pane_1, -1, "enthalpie : ")
        self.h_cas_1 = wx.TextCtrl(self.notebook_1_pane_1, -1, "")
        self.label_10 = wx.StaticText(self.notebook_1_pane_1, -1, "kJ / kg")
        self.label_11_copy_11 = wx.StaticText(self.notebook_1_pane_1, -1, "")
        self.label_11_copy_6 = wx.StaticText(self.notebook_1_pane_1, -1, "")
        self.label_11_copy_5 = wx.StaticText(self.notebook_1_pane_1, -1, "")
        self.label_11_copy = wx.StaticText(self.notebook_1_pane_1, -1, "")
        self.label_16 = wx.StaticText(self.notebook_1_pane_1, -1, "Poids d'eau : ")
        self.r_cas_1 = wx.TextCtrl(self.notebook_1_pane_1, -1, "")
        self.label_19 = wx.StaticText(self.notebook_1_pane_1, -1, "g / kg")
        self.label_11_copy_10 = wx.StaticText(self.notebook_1_pane_1, -1, "")
        self.label_11_copy_7 = wx.StaticText(self.notebook_1_pane_1, -1, "")
        self.label_11_copy_4 = wx.StaticText(self.notebook_1_pane_1, -1, "")
        self.label_11_copy_1 = wx.StaticText(self.notebook_1_pane_1, -1, "")
        self.label_17 = wx.StaticText(self.notebook_1_pane_1, -1, "V : ")
        self.v_cas_1 = wx.TextCtrl(self.notebook_1_pane_1, -1, "")
        self.label_11 = wx.StaticText(self.notebook_1_pane_1, -1, "m3 / kg")
        self.label_11_copy_9 = wx.StaticText(self.notebook_1_pane_1, -1, "")
        self.label_11_copy_8 = wx.StaticText(self.notebook_1_pane_1, -1, "")
        self.label_11_copy_3 = wx.StaticText(self.notebook_1_pane_1, -1, "")
        self.label_11_copy_2 = wx.StaticText(self.notebook_1_pane_1, -1, "")
        self.label_22 = wx.StaticText(self.notebook_1_pane_1, -1, "Ro : ")
        self.ro_cas_1 = wx.TextCtrl(self.notebook_1_pane_1, -1, "")
        self.label_12 = wx.StaticText(self.notebook_1_pane_1, -1, "kg / m3")
        self.label_11_copy_9_copy = wx.StaticText(self.notebook_1_pane_1, -1, "")
        self.label_11_copy_9_copy_1 = wx.StaticText(self.notebook_1_pane_1, -1, "")
        self.label_11_copy_9_copy_2 = wx.StaticText(self.notebook_1_pane_1, -1, "")
        self.label_11_copy_9_copy_3 = wx.StaticText(self.notebook_1_pane_1, -1, "")
        self.label_18 = wx.StaticText(self.notebook_1_pane_1, -1, u"T rosée : ")
        self.tr_cas_1 = wx.TextCtrl(self.notebook_1_pane_1, -1, "")
        self.label_7 = wx.StaticText(self.notebook_1_pane_1, -1, u"°C")
        self.b_cas_2 = wx.Button(self.notebook_1_pane_2, -1, "button_1")
        self.notebook_1_pane_3 = wx.Panel(self, -1)
        self.notebook_1_pane_4 = wx.Panel(self, -1)
        self.notebook_1_pane_5 = wx.Panel(self, -1)
        self.notebook_1_pane_6 = wx.Panel(self, -1)
        self.notebook_1_pane_7 = wx.Panel(self, -1)

        self.__set_properties()
        self.__do_layout()

        self.Bind(wx.EVT_BUTTON, self.calculer_cas_1, self.b_cas_1)
        # end wxGlade

    def __set_properties(self):
        # begin wxGlade: wxNotebook_1.__set_properties
        self.AddPage(self.notebook_1_pane_1, "T / HR")
        self.AddPage(self.notebook_1_pane_2, "T / h")
        self.AddPage(self.notebook_1_pane_3, "T / r")
        self.AddPage(self.notebook_1_pane_4, "HR / r")
        self.AddPage(self.notebook_1_pane_5, "h / r")
        self.AddPage(self.notebook_1_pane_6, "T / v")
        self.AddPage(self.notebook_1_pane_7, u"T / T rosée")
        self.SetMinSize((650,300))
        # end wxGlade

    def __do_layout(self):
        # begin wxGlade: wxNotebook_1.__do_layout
        grid_sizer_2 = wx.GridSizer(7, 7, 0, 0)
        grid_sizer_1 = wx.GridSizer(7, 7, 0, 0)
        grid_sizer_1.Add(self.label_1, 0, 0, 0)
        grid_sizer_1.Add(self.T_cas_1, 0, 0, 0)
        grid_sizer_1.Add(self.label_4, 0, 0, 0)
        grid_sizer_1.Add(self.label_20, 0, 0, 0)
        grid_sizer_1.Add(self.label_13, 0, 0, 0)
        grid_sizer_1.Add(self.pvs_cas_1, 0, 0, 0)
        grid_sizer_1.Add(self.label_8, 0, 0, 0)
        grid_sizer_1.Add(self.label_2, 0, 0, 0)
        grid_sizer_1.Add(self.HR_cas_1, 0, 0, 0)
        grid_sizer_1.Add(self.label_5, 0, 0, 0)
        grid_sizer_1.Add(self.label_21, 0, 0, 0)
        grid_sizer_1.Add(self.label_14, 0, 0, 0)
        grid_sizer_1.Add(self.pv_cas_1, 0, 0, 0)
        grid_sizer_1.Add(self.label_9, 0, 0, 0)
        grid_sizer_1.Add(self.label_3, 0, 0, 0)
        grid_sizer_1.Add(self.p_atm_cas_1, 0, 0, 0)
        grid_sizer_1.Add(self.label_6, 0, 0, 0)
        grid_sizer_1.Add(self.b_cas_1, 0, 0, 0)
        grid_sizer_1.Add(self.label_15, 0, 0, 0)
        grid_sizer_1.Add(self.h_cas_1, 0, 0, 0)
        grid_sizer_1.Add(self.label_10, 0, 0, 0)
        grid_sizer_1.Add(self.label_11_copy_11, 0, 0, 0)
        grid_sizer_1.Add(self.label_11_copy_6, 0, 0, 0)
        grid_sizer_1.Add(self.label_11_copy_5, 0, 0, 0)
        grid_sizer_1.Add(self.label_11_copy, 0, 0, 0)
        grid_sizer_1.Add(self.label_16, 0, 0, 0)
        grid_sizer_1.Add(self.r_cas_1, 0, 0, 0)
        grid_sizer_1.Add(self.label_19, 0, 0, 0)
        grid_sizer_1.Add(self.label_11_copy_10, 0, 0, 0)
        grid_sizer_1.Add(self.label_11_copy_7, 0, 0, 0)
        grid_sizer_1.Add(self.label_11_copy_4, 0, 0, 0)
        grid_sizer_1.Add(self.label_11_copy_1, 0, 0, 0)
        grid_sizer_1.Add(self.label_17, 0, 0, 0)
        grid_sizer_1.Add(self.v_cas_1, 0, 0, 0)
        grid_sizer_1.Add(self.label_11, 0, 0, 0)
        grid_sizer_1.Add(self.label_11_copy_9, 0, 0, 0)
        grid_sizer_1.Add(self.label_11_copy_8, 0, 0, 0)
        grid_sizer_1.Add(self.label_11_copy_3, 0, 0, 0)
        grid_sizer_1.Add(self.label_11_copy_2, 0, 0, 0)
        grid_sizer_1.Add(self.label_22, 0, 0, 0)
        grid_sizer_1.Add(self.ro_cas_1, 0, 0, 0)
        grid_sizer_1.Add(self.label_12, 0, 0, 0)
        grid_sizer_1.Add(self.label_11_copy_9_copy, 0, 0, 0)
        grid_sizer_1.Add(self.label_11_copy_9_copy_1, 0, 0, 0)
        grid_sizer_1.Add(self.label_11_copy_9_copy_2, 0, 0, 0)
        grid_sizer_1.Add(self.label_11_copy_9_copy_3, 0, 0, 0)
        grid_sizer_1.Add(self.label_18, 0, 0, 0)
        grid_sizer_1.Add(self.tr_cas_1, 0, 0, 0)
        grid_sizer_1.Add(self.label_7, 0, 0, 0)
        self.notebook_1_pane_1.SetSizer(grid_sizer_1)
        grid_sizer_2.Add(self.b_cas_2, 0, 0, 0)
        self.notebook_1_pane_2.SetSizer(grid_sizer_2)
        # end wxGlade

    def calculer_cas_1(self, event): # wxGlade: wxNotebook_1.<event_handler>
        print "Event handler `calculer_cas_1' not implemented"
        event.Skip()

# end of class wxNotebook_1

class wxFrame_1(wx.Frame):
    def __init__(self, *args, **kwds):
        # begin wxGlade: wxFrame_1.__init__
        kwds["style"] = wx.DEFAULT_FRAME_STYLE
        wx.Frame.__init__(self, *args, **kwds)
        self.notebook_1 = wxNotebook_1(self, -1)

        self.__set_properties()
        self.__do_layout()
        # end wxGlade

    def __set_properties(self):
        # begin wxGlade: wxFrame_1.__set_properties
        self.SetTitle(u"AstuGeClim - Diagramme psychrométrique")
        # end wxGlade

    def __do_layout(self):
        # begin wxGlade: wxFrame_1.__do_layout
        sizer_1 = wx.BoxSizer(wx.VERTICAL)
        sizer_1.Add(self.notebook_1, 1, wx.EXPAND, 0)
        self.SetSizer(sizer_1)
        sizer_1.Fit(self)
        self.Layout()
        # end wxGlade

# end of class wxFrame_1


if __name__ == "__main__":
    app = wx.PySimpleApp(0)
    wx.InitAllImageHandlers()
    fenetre_dah = wxFrame_1(None, -1, "")
    app.SetTopWindow(fenetre_dah)
    fenetre_dah.Show()
    app.MainLoop()

Je souhaite gérer les clics de mes boutons pour calculer des éléments. Le clic du bouton du cas_1 me parait bon mais lorsque je clic sur le bouton il ne se passe rien. Pourtant le print me parait ok. Si je désactive le skip rien ne change.

Alors je voudrais bien un petit coup de main afin de résoudre ce problème qui je pense est enfantin pour un habitué.

Merci à tous.

Dernière modification par g_barthe (Le 11/05/2008, à 23:26)


Mon forum perso sur le génie climatique http://le-genie-climatique.positifforum.com/
Le forum des travaux manuels : http://pausebroderie.fr/

Hors ligne

#2 Le 11/05/2008, à 23:04

g_barthe

Re : [Résolu] [Python] Pb évènement wxpython

J'ai essayé avec un code plus simple juste une frame et un bouton et ça marche.

Donc là je pense que le problème vient des objets parents de mon bouton.

Je crois que wxglade gère pas çca comme il faut ou alors j'ai pas mis les bonnes options.

Affaire à suivre. A voir si un pro passe dans le coin

[edit]Alors finalement la nuit porte conseil. J'ai repris un nouveau projet depuis le départ en positionnant la frame, le notebook, le sizer, un bouton une zone de texte et ca à l'air de fonctionner. J'arrive à récupérer la valeur de la zone de texte après clic sur mon bouton. J'avais du changer une option ou un nom de classe dans wxglade qui a du lui faire perdre la tête.
Je continuerais dans la journée je pense. Mais la ca semble résolu. Je reste perplexe.
[/edit]

Dernière modification par g_barthe (Le 11/05/2008, à 23:26)


Mon forum perso sur le génie climatique http://le-genie-climatique.positifforum.com/
Le forum des travaux manuels : http://pausebroderie.fr/

Hors ligne