MCPcopy Create free account
hub / github.com/Image-Py/imagepy / MegaFontRenderer

Class MegaFontRenderer

imagepy/ui/tablewindow.py:112–180  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

110
111
112class MegaFontRenderer(Grid.GridCellRenderer):
113 def __init__(self, tps):
114 Grid.GridCellRenderer.__init__(self)
115 n_back = wx.SystemSettings.GetColour( wx.SYS_COLOUR_WINDOW )
116 l_back = wx.SystemSettings.GetColour( wx.SYS_COLOUR_HIGHLIGHT )
117 n_text = wx.SystemSettings.GetColour( wx.SYS_COLOUR_WINDOWTEXT )
118 l_text = wx.SystemSettings.GetColour( wx.SYS_COLOUR_HIGHLIGHTTEXT )
119 self.colors = [(n_back, n_text), (l_back, l_text)]
120 #line = wx.Color((255,0,0))
121 self.selectedBrush = wx.Brush("blue", wx.BRUSHSTYLE_SOLID)
122 self.normalBrush = wx.Brush(wx.WHITE, wx.BRUSHSTYLE_SOLID)
123 self.font = wx.Font(10, wx.FONTFAMILY_DEFAULT, wx.FONTSTYLE_NORMAL, wx.FONTWEIGHT_NORMAL, 0, "ARIAL")
124 self.tps = tps
125
126 def Draw(self, grid, attr, dc, rect, row, col, isSelected):
127 dc.SetClippingRegion(rect)
128 cn = self.tps.data.columns[col]
129 rd, tc, lc, ln = self.tps.get_props()[cn]
130 bcolor, tcolor = self.colors[isSelected]
131 if isSelected:tc = tcolor
132
133 # clear the background
134 dc.SetBackgroundMode(wx.SOLID)
135
136 dc.SetBrush(wx.Brush(bcolor, wx.BRUSHSTYLE_SOLID))
137 dc.SetPen(wx.Pen(bcolor, 1, wx.PENSTYLE_SOLID))
138 dc.DrawRectangle(rect)
139
140 isnum = np.issubdtype(self.tps.data[cn].dtype, np.number)
141 if ln!='Line':
142 if isnum:
143 text = str(round(self.tps.data.iat[row, col], rd))
144 else: text = str(self.tps.data.iat[row, col])
145 dc.SetBackgroundMode(wx.SOLID)
146
147 # change the text background based on whether the grid is selected
148 dc.SetBrush(wx.Brush(wx.Colour(tc), wx.BRUSHSTYLE_SOLID))
149 dc.SetTextBackground(bcolor)
150
151
152 dc.SetTextForeground(wx.Colour(tc))
153 dc.SetFont(self.font)
154 dc.DrawText(text, rect.x+1, rect.y+1)
155
156
157 width, height = dc.GetTextExtent(text)
158 if width > rect.width-2:
159 width, height = dc.GetTextExtent("...")
160 x = rect.x+1 + rect.width-2 - width
161 dc.DrawRectangle(x, rect.y+1, width+1, height)
162 dc.DrawText("...", x, rect.y+1)
163
164 if isnum and ln!='Text':
165 data = self.tps.data
166 cn = data.columns[col]
167 rn = data.index[row]
168 minv, maxv = self.tps.range[cn]
169 dc.SetPen(wx.Pen(wx.Colour(lc), 1, wx.PENSTYLE_SOLID))

Callers 1

_updateColAttrsMethod · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected