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 draw(self, cr): if self.center: w, h = self.layout.get_pixel_size() cr.move_to(self.x - w/2.0, self.y - h/2.0) else: cr.move_to(self.x, self.y) fillColor(cr, self.color) cr.show_layout(self.layout)
def draw(self, cr): if self.center: w, h = self.layout.get_pixel_size() cr.move_to(self.x - w / 2.0, self.y - h / 2.0) else: cr.move_to(self.x, self.y) fillColor(cr, self.color) cr.show_layout(self.layout)
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
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 layout = newTextLayout( self, text=tick.label, font=font, maxSize=(tick.maxLabelWidth, 0), maximizeScale=1.0, 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 drawAll(self, cr): width = self.get_allocation().width height = self.get_allocation().height pixelPerSec = self.pixelPerSec dayPixel = dayLen * pixelPerSec ## pixel maxTickHeight = maxTickHeightRatio * height ##### cr.rectangle(0, 0, width, height) fillColor(cr, bgColor) ##### setColor(cr, holidayBgBolor) for x in self.data['holidays']: cr.rectangle(x, 0, dayPixel, height) cr.fill() ##### for tick in self.data['ticks']: self.drawTick(cr, tick, maxTickHeight) ###### beforeBoxH = maxTickHeight ## FIXME maxBoxH = height - beforeBoxH for box in self.data['boxes']: box.setPixelValues(self.timeStart, pixelPerSec, beforeBoxH, maxBoxH) self.drawBox(cr, box) self.drawBoxEditingHelperLines(cr) ###### Draw Current Time Marker dt = self.currentTime - self.timeStart if 0 <= dt <= self.timeWidth: setColor(cr, currentTimeMarkerColor) cr.rectangle( dt*pixelPerSec - currentTimeMarkerWidth/2.0, 0, currentTimeMarkerWidth, currentTimeMarkerHeightRatio * self.get_allocation().height ) cr.fill() ###### for button in self.buttons: button.draw(cr, width, height)
def drawAll(self, cr): width = self.get_allocation().width height = self.get_allocation().height pixelPerSec = self.pixelPerSec dayPixel = dayLen * pixelPerSec ## pixel maxTickHeight = maxTickHeightRatio * height ##### cr.rectangle(0, 0, width, height) fillColor(cr, bgColor) ##### setColor(cr, holidayBgBolor) for x in self.data['holidays']: cr.rectangle(x, 0, dayPixel, height) cr.fill() ##### for tick in self.data['ticks']: self.drawTick(cr, tick, maxTickHeight) ###### beforeBoxH = maxTickHeight ## FIXME maxBoxH = height - beforeBoxH for box in self.data['boxes']: box.setPixelValues(self.timeStart, pixelPerSec, beforeBoxH, maxBoxH) self.drawBox(cr, box) self.drawBoxEditingHelperLines(cr) ###### Draw Current Time Marker dt = self.currentTime - self.timeStart if 0 <= dt <= self.timeWidth: setColor(cr, currentTimeMarkerColor) cr.rectangle( dt * pixelPerSec - currentTimeMarkerWidth / 2.0, 0, currentTimeMarkerWidth, currentTimeMarkerHeightRatio * self.get_allocation().height) cr.fill() ###### for button in self.buttons: button.draw(cr, width, height)
def drawBox(self, cr, box): d = box.lineW x = box.x w = box.w y = box.y h = box.h ### cr.rectangle(x, y, w, h) if d == 0: fillColor(cr, box.color) else: try: alpha = box.color[3] except IndexError: alpha = 255 try: fillColor(cr, ( box.color[0], box.color[1], box.color[2], int(alpha*boxInnerAlpha), )) except cairo.Error: return ### cr.set_line_width(0) cr.move_to(x, y) cr.line_to(x+w, y) cr.line_to(x+w, y+h) cr.line_to(x, y+h) cr.line_to(x, y) cr.line_to(x+d, y) cr.line_to(x+d, y+h-d) cr.line_to(x+w-d, y+h-d) cr.line_to(x+w-d, y+d) cr.line_to(x+d, y+d) cr.close_path() fillColor(cr, box.color) ######## Draw Move/Resize Border if box.hasBorder: if w > boxMoveBorder*2 and h > boxMoveBorder: b = boxMoveBorder bd = boxMoveLineW #cr.set_line_width(bd) cr.move_to(x+b, y+h) cr.line_to(x+b, y+b) cr.line_to(x+w-b, y+b) cr.line_to(x+w-b, y+h) cr.line_to(x+w-b-bd, y+h) cr.line_to(x+w-b-bd, y+b+bd) cr.line_to(x+b+bd, y+b+bd) cr.line_to(x+b+bd, y+h) cr.close_path() fillColor(cr, box.color) ### bds = 0.7*bd cr.move_to(x, y) cr.line_to(x+bds, y) cr.line_to(x+b+bds, y+b) cr.line_to(x+b, y+b+bds) cr.line_to(x, y+bds) cr.close_path() fillColor(cr, box.color) ## cr.move_to(x+w, y) cr.line_to(x+w-bds, y) cr.line_to(x+w-b-bds, y+b) cr.line_to(x+w-b, y+b+bds) cr.line_to(x+w, y+bds) cr.close_path() fillColor(cr, box.color) else: box.hasBorder = False ######## ## now draw the text ## how to find the best font size based in the box's width and height, and font family? FIXME ## possibly write in many lines? or just in one line and wrap if needed? if box.text: #print box.text textW = 0.9*w textH = 0.9*h textLen = len(toUnicode(box.text)) #print 'textLen=%s'%textLen if rotateBoxLabel == 0: avgCharW = float(textW) / textLen else: avgCharW = float(max(textW, textH)) / textLen #print 'avgCharW=%s'%avgCharW if avgCharW > 3:## FIXME font = list(ui.getFont()) layout = self.create_pango_layout(box.text) ## a pango.Layout object layout.set_font_description(pfontEncode(font)) layoutW, layoutH = layout.get_pixel_size() #print 'orig font size: %s'%font[3] normRatio = min( float(textW)/layoutW, float(textH)/layoutH, ) rotateRatio = min( float(textW)/layoutH, float(textH)/layoutW, ) if rotateBoxLabel != 0 and rotateRatio > normRatio: font[3] *= max(normRatio, rotateRatio) layout.set_font_description(pfontEncode(font)) layoutW, layoutH = layout.get_pixel_size() fillColor(cr, fgColor)## before cr.move_to #print 'x=%s, y=%s, w=%s, h=%s, layoutW=%s, layoutH=%s'%(x,y,w,h,layoutW,layoutH) cr.move_to( x + (w - rotateBoxLabel*layoutH)/2.0, y + (h + rotateBoxLabel*layoutW)/2.0, ) cr.rotate(-rotateBoxLabel*pi/2) cr.show_layout(layout) try: cr.rotate(rotateBoxLabel*pi/2) except: print 'counld not rotate by %s*pi/2 = %s'%(rotateBoxLabel, rotateBoxLabel*pi/2) else: font[3] *= normRatio layout.set_font_description(pfontEncode(font)) layoutW, layoutH = layout.get_pixel_size() fillColor(cr, fgColor)## before cr.move_to cr.move_to( x + (w-layoutW)/2.0, y + (h-layoutH)/2.0, ) cr.show_layout(layout)