Bien le bonjour à tous

Voilà plus de huit six mois que j'avais laissé tomber mon projet, mais maintenant, j'ai pluss de temps alors je m'y remets.
Mais me voilà de nouveau confronté à un ***** de problème. Je m'arrache les cheveux dessus depuis un bon nombre d'heures, j'ai essayé tout ce que je trouvais, etc ... J'y suis allé au débogueur,mais rien n'y fait ...

C'est pourquoi je solicite votre aidé précieuse :p

J'ai un sizer dans lequel je place un MyStaticText (classe dérivée d'une wx.Window qui me permet de rendre transparent le Background, de cette facon je peux écrire du texte sans avoir le cadre d'une wx.StaticText, voir http://www.developpez.net/forums/d67...sparent-panel/) et un wx.Button

Quand j'appuie sur mon bouton, je change le Label de mon MyStaticText et donc j'augmente (ou diminue sa taille). Le probleme est que, après ce redimensionnement, mon widget n'est plus centré !! J'ai utilisé un sizer.Layout(), mais ca ne donne aucun résultat !

Voici mon programme simplifié :

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
import wx
 
class MyStaticText(wx.Window):
    def __init__(self, parent, label):
        wx.Window.__init__(self,parent,-1)
        self.parent=parent
        self.label=label
        self.police=wx.Font(12,wx.FONTFAMILY_DEFAULT,wx.FONTSTYLE_NORMAL,wx.FONTWEIGHT_NORMAL)
        self.police.SetNativeFontInfoFromString(u'0;-16;0;0;0;400;0;0;0;0;3;2;1;66;Lucida Handwriting')
## Remplacez la police ci-dessus par 'Georgia' si vous n'avez pas le Lucida Handwriting
        width,height=self.GetFullTextExtent(label,font=self.police)[0:2]
        self.SetSize((width,height))
        self.SetBackgroundStyle(wx.BG_STYLE_CUSTOM)
 
        self.Bind(wx.EVT_PAINT, self.OnPaint)
 
    def OnPaint(self,evt):
        x,y=self.GetPositionTuple()
        dc=wx.PaintDC(self)
        l,h=dc.GetFullTextExtent(self.label,font=self.police)[0:2]
        self.SetSize((l,h))
        dc=wx.PaintDC(self)
        dc2=wx.BufferedPaintDC(self.parent)
        dc.Blit(0,0,l,h,dc2,x,y)
        dc.SetTextBackground(wx.NullColour)
        dc.SetTextForeground(wx.BLACK)
        dc.SetFont(self.police)
        dc.DrawText(self.label,0,0)
 
    def SetLabel(self,label):
        self.Refresh(True)
        self.label=label
        width,height=self.GetFullTextExtent(label,font=self.police)[0:2]
        self.SetSize((width,height))
 
class MyFrame(wx.Frame):
 
    def __init__(self, *args, **kwargs):
 
        wx.Frame.__init__(self, *args, **kwargs)
 
        self.panel = wx.Panel(self)
 
        self.btn = wx.Button(self.panel, -1, "Click me!!!")
        self.stt = MyStaticText(self.panel, "Salut")
 
        self.szr = wx.GridBagSizer(5, 5)
        self.szr.Add(self.stt, (0, 0), flag=wx.ALIGN_CENTRE_VERTICAL|wx.ALIGN_CENTRE_HORIZONTAL)
        self.szr.AddGrowableCol(0)
        self.szr.AddGrowableRow(0)
        self.szr.Add(self.btn, (1, 0), flag=wx.ALIGN_CENTRE)
 
        self.panel.SetSizer(self.szr)
        self.btn.Bind(wx.EVT_BUTTON,self.button)
        self.panel.Bind(wx.EVT_PAINT,self.OnPaint)
 
    def button(self,evt):
        self.stt.SetLabel("Saluuuuuuuuuuuuuuuuuut")
        self.szr.Layout()
 
    def OnPaint(self,evt):
        size=self.panel.GetRect()
        dc=wx.BufferedPaintDC(self.panel)
        dc.GradientFillLinear(size,wx.BLUE,wx.SystemSettings.GetColour(wx.SYS_COLOUR_MENU),wx.NORTH)
        evt.Skip()
 
if __name__ == "__main__":
 
    app = wx.PySimpleApp(redirect=False)
    fr = MyFrame(None, -1, "Test bouton")
    fr.Show(True)
    app.MainLoop()
J'espere que vous pourrez m'aider !
Merci beaucoup !

Lotendan