1
2
3
4
5
6
7
8
9
10
11
12 """
13 A TipWindow class that can properly handle tab(\t) characters.
14 Limitation: This class does not do text wrapping!
15 """
16
17 import wx
18
19 space_count=4
20 TEXT_MARGIN_X=3
21 TEXT_MARGIN_Y=3
22 parentclass=wx.TipWindow
24 - def __init__(self, parent, text, maxwidth=100, rectbound=None):
25 global TEXT_MARGIN_X
26 super(TipWindow, self).__init__(parent, text, maxwidth, rectbound)
27 _children_wins=self.GetChildren()
28 if len(_children_wins)!=1:
29
30 return
31 self._view=_children_wins[0]
32 self._text=text
33 self._max_w=maxwidth
34 self._line_h=0
35 self._col_x=[TEXT_MARGIN_X]
36 self.adjust()
37 wx.EVT_PAINT(self._view, self.OnPaintView)
38
40
41 global space_count
42 if self._text.find('\t')==-1:
43
44 return
45 _dc=wx.ClientDC(self._view)
46 _dc.SetFont(self._view.GetFont())
47 for _line in self._text.split('\n'):
48 _cnt=0
49 for _col in _line.split('\t'):
50 _cnt+=1
51 if _cnt>=len(self._col_x):
52 self._col_x.append(0)
53 _w, _h=_dc.GetTextExtent(_col)
54 self._col_x[_cnt]=max(_w, self._col_x[_cnt])
55 self._line_h=max(self._line_h, _h)
56 _space_w=_dc.GetTextExtent(' '*space_count)[0]
57 for _cnt in range(1, len(self._col_x)):
58 self._col_x[_cnt]+=self._col_x[_cnt-1]+_space_w
59 _w, _h=self.GetClientSizeTuple()
60 _w=min(self._col_x[-1]-_space_w+self._col_x[0], self._max_w)
61 self.SetClientSizeWH(_w, _h)
62 self._view.SetDimensions(0, 0, _w, _h)
63
65 global TEXT_MARGIN_Y
66 _dc=wx.PaintDC(self._view)
67
68 _background=self._view.GetBackgroundColour()
69 _foreground=self._view.GetForegroundColour()
70 _dc.SetBrush(wx.Brush(_background, wx.SOLID))
71 _dc.SetPen(wx.Pen(_foreground, 1, wx.SOLID))
72 _dc.DrawRectangle(0, 0, *self._view.GetClientSizeTuple())
73
74 _dc.SetTextBackground(_background)
75 _dc.SetTextForeground(_foreground)
76 _dc.SetFont(self._view.GetFont())
77 _y=TEXT_MARGIN_Y
78 for _line in self._text.split('\n'):
79 for _idx, _col in enumerate(_line.split('\t')):
80 _dc.DrawText(_col, self._col_x[_idx], _y)
81 _y+=self._line_h
82