def drawGrid(self, dc):
"""Draw the grid characters and highlights.
Args:
dc: wx.DC drawing context. Calling the methods of dc will
modify the drawing accordingly.
"""
##dc.SetFont(self.gridFont) # setting the font for the text
# figuring out what is the y-offset for the grid of symbols
yOffset = self.winHeight*32/340.0
if len(self.copyText) == 0:
yOffset = self.winHeight * 14/340.0
# figuring out the distances between each symbol horizontaly and vertically
dx = (self.winWidth+0.0)/(self.nCols+1)
dy = (self.winHeight-yOffset)/(self.nRows+1)
for i in xrange(self.nRows):
for j in xrange(self.nCols):
# select the color and font for the next symbol
mark = self.marked[i,j]
if mark == grid.normal:
dc.SetTextForeground(self.gridColor)
elif mark == grid.highlighted:
dc.SetTextForeground(self.highlightColor)
self.gridFont.SetWeight(wx.FONTWEIGHT_BOLD)
elif mark == grid.unhighlighted:
dc.SetTextForeground(self.unhighlightColor)
elif mark == grid.selected:
dc.SetTextForeground(self.selectColor)
self.gridFont.SetWeight(wx.FONTWEIGHT_BOLD)
else:
raise Exception('Invalid mark value %d.' % mark)
dc.SetFont(self.gridFont)
# get extents of symbol
text = self.grid[i,j]
textWidth, textHeight = dc.GetTextExtent(text)
# draw next symbol
#dc.DrawText(self.grid[i,j], (j+0.7)*dx, (i+0.7)*dy+yOffset)
dc.DrawText(self.grid[i,j],
(j+1.0)*dx-textWidth/2.0,
(i+1.0)*dy+yOffset-textHeight/2.0)
self.gridFont.SetWeight(wx.FONTWEIGHT_NORMAL)
评论列表
文章目录