def dragBegin(self, fontb, context, parent): #print('fontBottonDragBegin'## caled before dragCalDataGet) textLay = newTextLayout(self, gtk.FontButton.get_font_name(self)) w, h = textLay.get_pixel_size() pmap = gdk.Pixmap(None, w, h, 24) pmap.draw_layout( pmap.new_gc(), 0, 0, textLay, gdk.Color(0, 0, 0),# foreground gdk.Color(-1, -1, -1),# background ) pbuf = gdk.Pixbuf(gdk.COLORSPACE_RGB, True, 8, w, h) pbuf.get_from_drawable( pmap, parent.get_screen().get_system_colormap(), 0, 0, 0, 0, -1, -1, ) #fontb.drag_source_set_icon_pixbuf(pbuf) context.set_icon_pixbuf(pbuf, -16, -10) return True
def onConfigChange(self, *a, **kw): CustomizableCalObj.onConfigChange(self, *a, **kw) ##### for child in self.get_children(): child.destroy() ### monthLabels = [] mode = calTypes.primary ## box = YearLabelButtonBox(mode) pack(self, box) self.appendItem(box.label) ## pack(self, gtk.VSeparator(), 1, 1) ## box = MonthLabelButtonBox(mode) pack(self, box) self.appendItem(box.label) monthLabels.append(box.label) #### for i, mode in list(enumerate(calTypes.active))[1:]: pack(self, gtk.VSeparator(), 1, 1) label = YearLabel(mode) pack(self, label) self.appendItem(label) ############### label = gtk.Label('') label.set_property('width-request', 5) pack(self, label) ############### label = MonthLabel(mode) pack(self, label) monthLabels.append(label) self.appendItem(label) #### ## updateTextWidth lay = newTextLayout(self) for label in monthLabels: wm = 0 for m in range(12): name = getMonthName(label.mode, m) if ui.boldYmLabel: lay.set_markup('<b>%s</b>'%name) else: lay.set_text(name) ## OR lay.set_markup w = lay.get_pixel_size()[0] if w > wm: wm = w label.set_property('width-request', wm) ##### self.show_all() ##### self.onDateChange()
def trayUpdate(self, gdate=None, checkTrayMode=True): if checkTrayMode and self.trayMode < 1: return if gdate is None: gdate = localtime()[:3] if core.primaryMode==core.DATE_GREG: ddate = gdate else: ddate = core.convert(gdate[0], gdate[1], gdate[2], core.DATE_GREG, core.primaryMode) imagePath = ui.trayImageHoli if ui.todayCell.holiday else ui.trayImage ###################################### ''' import Image, ImageDraw, ImageFont im = Image.open(imagePath) w, h = im.size draw = ImageDraw.Draw(im) text = _(ddate[2]).decode('utf8') font = ImageFont.truetype('/usr/share/fonts/TTF/DejaVuSans.ttf', 15) fw, fh = font.getsize(text) draw.text( ((w-fw)/2, (h-fh)/2), text, font=font, fill=ui.trayTextColor, ) self.sicon.set_from_pixbuf(gdk.pixbuf_new_from_data(im.tostring(), gdk.COLORSPACE_RGB, True, 8, w, h, 4*w)) ''' try: pixbuf = gdk.pixbuf_new_from_file(imagePath) except: pixbuf = gdk.pixbuf_new_from_file(join(pixDir, 'tray-blue.png')) ##pixbuf.scale() #???????????? ###################### PUTTING A TEXT ON A PIXBUF pmap = pixbuf.render_pixmap_and_mask(alpha_threshold=127)[0] ## pixmap is also a drawable textLay = newTextLayout(self, _(ddate[2]), ui.trayFont) w, h = textLay.get_pixel_size() s = ui.traySize if ui.trayY0 == None: y = s/4+int((0.9*s-h)/2) else: y = ui.trayY0 pmap.draw_layout(pmap.new_gc(), (s-w)/2, y, textLay, gdk.Color(*ui.trayTextColor))## , foreground, background) self.trayPix.get_from_drawable(pmap, self.get_screen().get_system_colormap(), 0, 0, 0, 0, s, s) ###################################### self.sicon.set_from_pixbuf(self.trayPix) ###################################### set_tooltip(self.sicon, self.getTrayTooltip()) return True
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 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 dragBegin(self, obj, context): colormap = self.get_screen().get_system_colormap() ############################################# text = '%.2d/%.2d/%.2d' % ui.cell.dates[ui.dragGetMode] textLay = newTextLayout(self, text) w, h = textLay.get_pixel_size() pmap = gdk.Pixmap(None, w, h, 24) #pmap.set_colormap(colormap) gc = pmap.new_gc() gc.set_foreground(rgbToGdkColor(*ui.bgColor)) pmap.draw_rectangle(gc, True, 0, 0, w, h) #gc.set_background(ui.bgColor) ##pmap.set_direction(gtk.DIR_LTR)## FIXME pmap.draw_layout( gc, 0, 0, textLay, rgbToGdkColor(*ui.textColor), rgbToGdkColor( *ui.bgColor ), ## rgbToGdkColor(ui.gdkColorInvert(*ui.textColor)) ) pbuf = gdk.Pixbuf(gdk.COLORSPACE_RGB, True, 8, w, h) pbuf.get_from_drawable( pmap, colormap, 0, 0, 0, 0, -1, -1, ) context.set_icon_pixbuf( pbuf, w / 2, ## y offset -10, ## x offset FIXME - not to be hidden behind mouse cursor ) return True
def dragBegin(self, obj, context): colormap = self.get_screen().get_system_colormap() ############################################# text = '%.2d/%.2d/%.2d'%ui.cell.dates[ui.dragGetMode] textLay = newTextLayout(self, text) w, h = textLay.get_pixel_size() pmap = gdk.Pixmap(None, w, h, 24) #pmap.set_colormap(colormap) gc = pmap.new_gc() gc.set_foreground(rgbToGdkColor(*ui.bgColor)) pmap.draw_rectangle(gc, True, 0, 0, w, h) #gc.set_background(ui.bgColor) ##pmap.set_direction(gtk.DIR_LTR)## FIXME pmap.draw_layout( gc, 0, 0, textLay, rgbToGdkColor(*ui.textColor), rgbToGdkColor(*ui.bgColor),## rgbToGdkColor(ui.gdkColorInvert(*ui.textColor)) ) pbuf = gdk.Pixbuf(gdk.COLORSPACE_RGB, True, 8, w , h) pbuf.get_from_drawable( pmap, colormap, 0, 0, 0, 0, -1, -1, ) context.set_icon_pixbuf( pbuf, w/2,## y offset -10,## x offset FIXME - not to be hidden behind mouse cursor ) return True