1
2
3
4
5
6
7
8
9
10
11
12
13
14
15 """This module contains AutoWidthListCtrl, a wxListCtrl object that
16 automatically adjusts the width of its columns.
17 """
18
19 __id__ = "$Id: autowidthlabelsgrid.py 2980 2009-04-02 00:14:33Z juhas $"
20
21 import wx
22 import wx.grid
23
25 '''wx grid which allows lables auto sizing'''
26
27
28
30
31 devContext = wx.ScreenDC()
32 devContext.SetFont(self.GetLabelFont())
33
34
35 if rows:
36 maxWidth = 0
37 curRow = self.GetNumberRows() - 1
38 while curRow >= 0:
39 curWidth = devContext.GetTextExtent("M%s"%(self.GetRowLabelValue(curRow)))[0]
40 if curWidth > maxWidth:
41 maxWidth = curWidth
42 curRow = curRow - 1
43 self.SetRowLabelSize(maxWidth)
44
45
46 if cols:
47 maxHeight = 0
48 curCol = self.GetNumberCols() - 1
49 while curCol >= 0:
50 (w,h,d,l) = devContext.GetFullTextExtent(self.GetColLabelValue(curCol))
51 curHeight = h + d + l + 4
52 if curHeight > maxHeight:
53 maxHeight = curHeight
54 curCol = curCol - 1
55 self.SetColLabelSize(maxHeight)
56 return
57
58
59