def drawTick(self, cr, tick, maxTickHeight): tickH = tick.height tickW = tick.width tickH = min(tickH, maxTickHeight) ### tickX = tick.pos - tickW / 2.0 tickY = 1 cr.rectangle(tickX, tickY, tickW, tickH) try: fillColor(cr, tick.color) except: print "error in fill, x=%.2f, y=%.2f, w=%.2f, h=%.2f" % (tickX, tickY, tickW, tickH) ### font = (fontFamily, False, False, tick.fontSize) layout = newLimitedWidthTextLayout( self, tick.label, tick.maxLabelWidth, font=font, truncate=truncateTickLabel ) ## FIXME if layout: # layout.set_auto_dir(0)## FIXME # print 'layout.get_auto_dir() = %s'%layout.get_auto_dir() layoutW, layoutH = layout.get_pixel_size() layoutX = tick.pos - layoutW / 2.0 layoutY = tickH * labelYRatio try: cr.move_to(layoutX, layoutY) except: print "error in move_to, x=%.2f, y=%.2f" % (layoutX, layoutY) else: cr.show_layout(layout) ## with the same tick.color
def onExposeEvent(self, widget=None, event=None): t0 = time.time() w = self.allocation.width h = self.allocation.height cr = self.window.cairo_create() cr.rectangle(0, 0, w, h) fillColor(cr, ui.bgColor) setColor(cr, ui.wcalTextColor) status = getCurrentWeekStatus() rowH = (h-self.topMargin)/7 widthList = [] expandIndex = [] for (i, item) in enumerate(self.rowItems): widthList.append(item.width + self.widthSpacing) if item.expand: expandIndex.append(i) extraWidth = float(w - sum(widthList)) / len(expandIndex) for i in expandIndex: widthList[i] += extraWidth del expandIndex for (i, row) in enumerate(status): y = self.topMargin + i*rowH cr.rectangle(0, 0, w, h) #fillColor(cr, bgColor) if rtl: x = w else: x = 0 for (j, item) in enumerate(self.rowItems): itemW = widthList[j] text = item.getText(row).decode('utf8') if text: layout = newLimitedWidthTextLayout(self, text, itemW) if layout: layoutW, layoutH = layout.get_pixel_size() layoutX = x + item.textAlign * (itemW-layoutW) if rtl: layoutX -= itemW cr.move_to(layoutX, y+(rowH - layoutH)/2) if row.holiday and item.holidayColorize: setColor(cr, ui.holidayColor) else: setColor(cr, ui.wcalTextColor) cr.show_layout(layout) x = x - rtlSgn() * itemW for button in self.buttons: button.draw(cr, w, h) #print time.time()-t0 return False