def _draw_badge(self, context, size, sensitive, widget): theme = gtk.icon_theme_get_default() badge_info = theme.lookup_icon(self.badge_name, int(size), 0) if badge_info: badge_file_name = badge_info.get_filename() if badge_file_name.endswith('.svg'): handle = self._loader.load(badge_file_name, {}, self.cache) dimensions = handle.get_dimension_data() icon_width = int(dimensions[0]) icon_height = int(dimensions[1]) pixbuf = handle.get_pixbuf() else: pixbuf = gtk.gdk.pixbuf_new_from_file(badge_file_name) icon_width = pixbuf.get_width() icon_height = pixbuf.get_height() context.scale(float(size) / icon_width, float(size) / icon_height) if not sensitive: pixbuf = self._get_insensitive_pixbuf(pixbuf, widget) surface = hippo.cairo_surface_from_gdk_pixbuf(pixbuf) context.set_source_surface(surface, 0, 0) context.paint()
def get(self, url, cb, errcb, format='surface'): if self._cache.has_key(url): # TODO expire pixbuf = self._cache[url] cb(url, format == 'surface' and hippo.cairo_surface_from_gdk_pixbuf(pixbuf) or pixbuf) return cbdata = (cb, errcb, format) if self._loads.has_key(url): self._loads[url].append(cbdata) else: self._loads[url] = [cbdata] self.__logger.debug("adding url='%s' to pending loads (%d outstanding)" % (url, len(self._loads.keys()))) self._fetcher.refetch(url, self._do_load, self._do_load_error)
def _do_load(self, url, data): try: loader = gtk.gdk.PixbufLoader() # the write and close can both throw loader.write(data) loader.close() pixbuf = loader.get_pixbuf() self.__logger.debug("invoking callback for %s url='%s'" % (self, url)) self._cache[url] = pixbuf for cb, errcb, fmt in self._loads[url]: cb(url, fmt == 'surface' and hippo.cairo_surface_from_gdk_pixbuf(pixbuf) or pixbuf) except: for cb, errcb, fmt in self._loads[url]: errcb(url, sys.exc_info()) del self._loads[url]
def _do_load(self, url, data): try: # Why doesn't gdk-pixbuf have a sensible _new_from_memory_stream ? (tmpfd, tmpf_name) = tempfile.mkstemp() tmpf = os.fdopen(tmpfd, 'w') tmpf.write(data) tmpf.close() pixbuf = gtk.gdk.pixbuf_new_from_file(tmpf_name) os.unlink(tmpf_name) surface = hippo.cairo_surface_from_gdk_pixbuf(pixbuf) logging.debug("invoking callback for %s url='%s'" % (self, url)) self._cache[url] = surface for cb, errcb in self._loads[url]: cb(url, surface) except: for cb, errcb in self._loads[url]: errcb(url, sys.exc_info()) del self._loads[url]
def __app_display_sync(self): if not self.__app: return self.__box.set_child_visible(self.__subtitle, not self.__description_mode) self.__box.set_child_visible(self.__description, self.__description_mode) self.__photo.set_clickable(self.__app.is_installed()) self.__box.set_clickable(self.__app.is_installed()) self.__title.set_property("text", self.__app.get_name()) self.__subtitle.set_property("text", self.__app.get_generic_name() or self.__app.get_tooltip() or self.__app.get_comment()) self.__description.set_property("text", self.__app.get_description()) if self.__app.get_mugshot_app(): self.__photo.set_url(self.__app.get_mugshot_app().get_icon_url()) else: pixbuf = self.__app.get_local_pixbuf() if pixbuf: self.__photo.set_property("image", hippo.cairo_surface_from_gdk_pixbuf(pixbuf))
def __app_display_sync(self): if not self.__app: return self.__box.set_child_visible(self.__subtitle, not self.__description_mode) self.__box.set_child_visible(self.__description, self.__description_mode) self.__title.set_property("text", self.__app.get_name()) if self.__app.is_installed() or self.__app_location == AppLocation.DESCRIPTION_HEADER: self.__subtitle.set_property("text", self.__app.get_generic_name() or self.__app.get_tooltip() or self.__app.get_comment()) ## for now, install won't work if not connected elif self.__app_location == AppLocation.STOCK and globals.get_data_model().ready and globals.get_data_model().global_resource.online: self.__subtitle.set_property('text', "(Click to Install)") else: self.__subtitle.set_property('text', "(Not Installed)") self.__description.set_property("text", self.__app.get_description()) if self.__app.get_icon_url(): self.__photo.set_url(self.__app.get_icon_url()) else: pixbuf = self.__app.get_local_pixbuf() if pixbuf: self.__photo.set_property("image", hippo.cairo_surface_from_gdk_pixbuf(pixbuf))
def get_surface(self, sensitive=True, widget=None): cache_key = self._get_cache_key(sensitive) if cache_key in self._surface_cache: return self._surface_cache[cache_key] icon_info = self._get_icon_info() if icon_info.file_name is None: return None is_svg = icon_info.file_name.endswith('.svg') if is_svg: handle = self._load_svg(icon_info.file_name) dimensions = handle.get_dimension_data() icon_width = int(dimensions[0]) icon_height = int(dimensions[1]) else: pixbuf = gtk.gdk.pixbuf_new_from_file(icon_info.file_name) icon_width = pixbuf.get_width() icon_height = pixbuf.get_height() badge_info = self._get_badge_info(icon_info, icon_width, icon_height) padding = badge_info.icon_padding width, height = self._get_size(icon_width, icon_height, padding) if self.background_color is None: surface = cairo.ImageSurface(cairo.FORMAT_ARGB32, int(width), int(height)) context = cairo.Context(surface) else: surface = cairo.ImageSurface(cairo.FORMAT_RGB24, int(width), int(height)) context = cairo.Context(surface) context = gtk.gdk.CairoContext(context) context.set_source_color(self.background_color) context.paint() context.scale(float(width) / (icon_width + padding * 2), float(height) / (icon_height + padding * 2)) context.save() context.translate(padding, padding) if is_svg: if sensitive: handle.render_cairo(context) else: pixbuf = handle.get_pixbuf() pixbuf = self._get_insensitive_pixbuf(pixbuf, widget) pixbuf_surface = hippo.cairo_surface_from_gdk_pixbuf(pixbuf) context.set_source_surface(pixbuf_surface, 0, 0) context.paint() else: if not sensitive: pixbuf = self._get_insensitive_pixbuf(pixbuf, widget) pixbuf_surface = hippo.cairo_surface_from_gdk_pixbuf(pixbuf) context.set_source_surface(pixbuf_surface, 0, 0) context.paint() if self.badge_name: context.restore() context.translate(badge_info.attach_x, badge_info.attach_y) self._draw_badge(context, badge_info.size, sensitive, widget) self._surface_cache[cache_key] = surface return surface
_pixbufcache = {} def load_image_hook(img_name): try: pixbuf = _pixbufcache[img_name] except KeyError, e: pixbuf = None if not pixbuf: if img_name.find(os.sep) >= 0: pixbuf = gtk.gdk.pixbuf_new_from_file(img_name) _logger.debug("loaded from file '%s': %s" % (img_name,pixbuf)) else: theme = gtk.icon_theme_get_default() pixbuf = theme.load_icon(img_name, 60, gtk.ICON_LOOKUP_USE_BUILTIN) _logger.debug("loaded from icon theme '%s': %s" % (img_name,pixbuf)) _pixbufcache[img_name] = pixbuf return hippo.cairo_surface_from_gdk_pixbuf(pixbuf) def on_name_lost(*args): name = str(args[0]) logging.debug("Lost bus name " + name) if name == BUS_NAME_STR: gtk.main_quit() def usage(): print "%s [--debug] [--debug-modules=mod1,mod2...] [--info] [--no-autolaunch] [--stockdirs=dir1:dir2:...] [--help]" % (sys.argv[0]) def main(): try: opts, args = getopt.getopt(sys.argv[1:], "hds", ["help", "debug", "na", "no-autolaunch", "info", "replace", "stockdirs=", "debug-modules=", "server=", "dogfood"]) except getopt.GetoptError: usage()
def __init__( self, ca ): self.__class__.activityId = ca._activity_id thumbPhotoSvgPath = os.path.join(self.__class__.gfxPath, 'object-photo.svg') thumbPhotoSvgFile = open(thumbPhotoSvgPath, 'r') self.__class__.thumbPhotoSvgData = thumbPhotoSvgFile.read() self.__class__.thumbPhotoSvg = utils.loadSvg(self.__class__.thumbPhotoSvgData, Instance.colorStroke.hex, Instance.colorFill.hex) thumbPhotoSvgFile.close() thumbVideoSvgPath = os.path.join(self.__class__.gfxPath, 'object-video.svg') thumbVideoSvgFile = open(thumbVideoSvgPath, 'r') self.__class__.thumbVideoSvgData = thumbVideoSvgFile.read() self.__class__.thumbVideoSvg = utils.loadSvg(self.__class__.thumbVideoSvgData, Instance.colorStroke.hex, Instance.colorFill.hex) thumbVideoSvgFile.close() thumbAudioSvgPath = os.path.join(self.__class__.gfxPath, 'object-audio.svg') thumbAudioSvgFile = open(thumbAudioSvgPath, 'r') self.__class__.thumbAudioSvgData = thumbAudioSvgFile.read() self.__class__.thumbAudioSvg = utils.loadSvg(self.__class__.thumbAudioSvgData, Instance.colorStroke.hex, Instance.colorFill.hex) thumbAudioSvgFile.close() maxEnlargeSvgPath = os.path.join(self.__class__.gfxPath, 'max-enlarge.svg') maxEnlargeSvgFile = open(maxEnlargeSvgPath, 'r') maxEnlargeSvgData = maxEnlargeSvgFile.read() self.__class__.maxEnlargeSvg = utils.loadSvg(maxEnlargeSvgData, None, None ) maxEnlargeSvgFile.close() maxReduceSvgPath = os.path.join(self.__class__.gfxPath, 'max-reduce.svg') maxReduceSvgFile = open(maxReduceSvgPath, 'r') maxReduceSvgData = maxReduceSvgFile.read() self.__class__.maxReduceSvg = utils.loadSvg(maxReduceSvgData, None, None ) maxReduceSvgFile.close() infoOnSvgPath = os.path.join(self.__class__.gfxPath, 'corner-info.svg') infoOnSvgFile = open(infoOnSvgPath, 'r') infoOnSvgData = infoOnSvgFile.read() self.__class__.infoOnSvg = utils.loadSvg(infoOnSvgData, None, None ) infoOnSvgFile.close() xoGuySvgPath = os.path.join(self.__class__.gfxPath, 'xo-guy.svg') xoGuySvgFile = open(xoGuySvgPath, 'r') self.__class__.xoGuySvgData = xoGuySvgFile.read() xoGuySvgFile.close() recFile = os.path.join(self.__class__.gfxPath, 'media-record.png') recPixbuf = gtk.gdk.pixbuf_new_from_file(recFile) self.__class__.recImg = gtk.Image() self.__class__.recImg.set_from_pixbuf( recPixbuf ) recRedFile = os.path.join(self.__class__.gfxPath, 'media-record-red.png') recRedPixbuf = gtk.gdk.pixbuf_new_from_file(recRedFile) self.__class__.recRedImg = gtk.Image() self.__class__.recRedImg.set_from_pixbuf( recRedPixbuf ) recCircleFile = os.path.join(self.__class__.gfxPath, 'media-circle.png') recCirclePixbuf = gtk.gdk.pixbuf_new_from_file(recCircleFile) self.__class__.recCircleCairo = hippo.cairo_surface_from_gdk_pixbuf(recCirclePixbuf) recInsFile = os.path.join(self.__class__.gfxPath, 'media-insensitive.png') recInsPixbuf = gtk.gdk.pixbuf_new_from_file(recInsFile) self.__class__.recInsensitiveImg = gtk.Image() self.__class__.recInsensitiveImg.set_from_pixbuf( recInsPixbuf ) fullInsFile = os.path.join(self.__class__.gfxPath, 'full-insensitive.png') fullInsPixbuf = gtk.gdk.pixbuf_new_from_file(fullInsFile) self.__class__.fullInsensitiveImg = gtk.Image() self.__class__.fullInsensitiveImg.set_from_pixbuf( fullInsPixbuf ) recPlayFile = os.path.join(self.__class__.gfxPath, 'media-play.png') recPlayPixbuf = gtk.gdk.pixbuf_new_from_file(recPlayFile) self.__class__.recPlayImg = gtk.Image() self.__class__.recPlayImg.set_from_pixbuf( recPlayPixbuf ) recPauseFile = os.path.join(self.__class__.gfxPath, 'media-pause.png') recPausePixbuf = gtk.gdk.pixbuf_new_from_file(recPauseFile) self.__class__.recPauseImg = gtk.Image() self.__class__.recPauseImg.set_from_pixbuf( recPausePixbuf ) self._ts = self.__class__.TIMERS longestTime = self._ts[len(self._ts)-1] for i in range (0, longestTime): self.createCountdownPng( i )