Package diffpy :: Package pdfgui :: Package gui :: Package wxExtensions :: Module autowidthlabelsgrid
[hide private]
[frames] | no frames]

Source Code for Module diffpy.pdfgui.gui.wxExtensions.autowidthlabelsgrid

 1  ############################################################################## 
 2  # 
 3  # wxExtensions      by DANSE Diffraction group 
 4  #                   Simon J. L. Billinge 
 5  #                   (c) 2006 trustees of the Michigan State University. 
 6  #                   All rights reserved. 
 7  # 
 8  # File coded by:    Dmitriy Bryndin 
 9  # 
10  # See AUTHORS.txt for a list of people who contributed. 
11  # See LICENSE.txt for license information. 
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   
24 -class AutoWidthLabelsGrid(wx.grid.Grid):
25 '''wx grid which allows lables auto sizing''' 26 # def __init__(self, parent, state, size): 27 # wx.grid.Grid.__init__(self, parent, state, size) 28
29 - def AutosizeLabels(self,rows=True,cols=False):
30 # Common setup. 31 devContext = wx.ScreenDC() 32 devContext.SetFont(self.GetLabelFont()) 33 34 # First do row labels. 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 # Then column labels. 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 # End of class AutoWidthLabelsGrid 59