A partir de l'exemple que l'on peut trouver dans la démo (PopupControl.py), j'ai essayé de l'intégrer dans un gridbagsizer (avec d'autre widgets) mais popupcontrol prend alors une hauteur trop grande que je n'arrive pas à régler => je voudrais qu'il est la taille standard d'un textctrl.
Voyez-vous un moyen d'arriver à mes fins ?

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
import wx
import wx.grid
import wx.calendar
import wx.lib.popupctl
 
class TTest(wx.Frame):
    def __init__(
            self, parent, ID, pos=wx.DefaultPosition, style=wx.DEFAULT_FRAME_STYLE,
            size=(800,600), name='Test',color=wx.RED):
        wx.Frame.__init__(self, parent, -1, "Test ", size=size )
        self.pRight = wx.Panel(self, -1)
        self.bshMain = wx.BoxSizer(wx.HORIZONTAL)
 
	self.bsvRight = wx.BoxSizer(wx.VERTICAL)
 
        self.sbFilter = wx.StaticBox(self.pRight, -1, "Filtre")
        self.sbsFilter = wx.StaticBoxSizer(self.sbFilter, wx.VERTICAL)
        self.gbsFilter = wx.GridBagSizer( 4, 2)
 
        self.gcFilter = []
        self.rbNoneFilter = wx.RadioButton( self.pRight, -1, "Pas de filtre ", style = wx.RB_GROUP )
        self.rbNameFilter = wx.RadioButton( self.pRight, -1, "Filtre sur le nom")
        self.rbDateFilter = wx.RadioButton( self.pRight, -1, "Filtre sur la date" )
        self.tcNameFilter = wx.TextCtrl( self.pRight, -1, "" )
        self.pcDateFilter = wx.lib.popupctl.PopupControl( self.pRight, -1, pos = (30,30), size=(100,22))        
        self.win = wx.Window(self.pRight,-1, pos = (0,0), style = 0)
        self.cDateFilter = wx.calendar.CalendarCtrl(self.win, -1, pos = (0,0))        
        bz = self.cDateFilter.GetBestSize()
        self.win.SetSize(bz)        
        self.pcDateFilter.SetPopupContent(self.win)
 
        self.cbDateFilter = wx.CheckBox(self.pRight, -1, "A partir de")
        self.gcFilter.append((self.rbNoneFilter, None ))
        self.gcFilter.append((self.rbNameFilter, self.tcNameFilter))
        self.gcFilter.append((self.rbDateFilter, self.pcDateFilter))
        self.gcFilter.append((None, self.cbDateFilter))
 
        i = 0
        for radio, text in self.gcFilter:
            if radio != None: self.gbsFilter.Add( radio, (i,0), (1,1))##, wx.ALIGN_LEFT )
            if text != None: self.gbsFilter.Add( text, (i,1), (1,1))##, wx.ALIGN_LEFT )
            i += 1
 
        self.sbsFilter.Add(self.gbsFilter, 0)##,  wx.ALIGN_CENTRE|wx.ALL, 5 )
        self.bsvRight.Add(self.sbsFilter, 0)##, wx.EXPAND|wx.ALL)        
        self.pRight.SetSizer( self.bsvRight )
 
        self.bshMain.Add(self.pRight, 1, wx.EXPAND)
        self.SetSizer(self.bshMain)
        self.Bind(wx.EVT_CLOSE, self.OnCloseWindow)
        self.cDateFilter.Bind(wx.calendar.EVT_CALENDAR_DAY, self.OnCalSelected)
    def OnCalSelected(self,evt):
        self.pcDateFilter.PopDown()
        date = self.cDateFilter.GetDate()
 
        # Format the date that was selected for the text part of the control
        self.pcDateFilter.SetValue('%02d/%02d/%04d' % (date.GetDay(),
                                                       date.GetMonth()+1,
                                                       date.GetYear()))
        evt.Skip()
 
    # Method overridden from PopupControl
    # This method is called just before the popup is displayed
    # Use this method to format any controls in the popup
    def FormatContent(self):
        # I parse the value in the text part to resemble the correct date in
        # the calendar control
        txtValue = self.pcDateFilter.GetValue()
        dmy = txtValue.split('/')
        didSet = False
 
        if len(dmy) == 3:
            date = self.cDateFilter.GetDate()
            d = int(dmy[0])
            m = int(dmy[1]) - 1
            y = int(dmy[2])
 
            if d > 0 and d < 31:
                if m >= 0 and m < 12:
                    if y > 1000:
                        self.cDateFilter.SetDate(wx.DateTimeFromDMY(d,m,y))
                        didSet = True
 
        if not didSet:
            self.cDateFilter.SetDate(wx.DateTime_Today())
 
 
 
    def OnCloseWindow(self, event):
        self.Destroy()
 
 
def go():
    app = wx.PySimpleApp()
    a = TTest(None, -1)
    a.Show()
    app.MainLoop()
 
go()