示例#1
0
 def update_display():
     yield fetcher
     try:
         tasks.check(fetcher)
         # Try to insert new icon into the cache
         # If it fails, we'll be left with None in the cached_icon so
         # we don't try again.
         iconpath = self.config.iface_cache.get_icon_path(
             iface)
         if iconpath:
             self.cached_icon[iface.uri] = load_icon(
                 iconpath, ICON_SIZE, ICON_SIZE)
             self.build_tree()
         else:
             warn("Failed to download icon for '%s'", iface)
     except download.DownloadAborted as ex:
         info("Icon download aborted: %s", ex)
         # Don't report further; the user knows they cancelled
     except download.DownloadError as ex:
         warn("Icon download failed: %s", ex)
         # Not worth showing a dialog box for this
     except Exception as ex:
         import traceback
         traceback.print_exc()
         self.config.handler.report_error(ex)
示例#2
0
	def populate_model(self):
		m = self.model
		m.clear()

		for uri in self.app_list.get_apps():
			itr = m.append()
			m[itr][AppListBox.URI] = uri

			try:
				iface = self.iface_cache.get_interface(uri)
				feed = self.iface_cache.get_feed(uri)
				if feed:
					name = feed.get_name()
					summary = feed.summary or _('No information available')
					summary = summary[:1].capitalize() + summary[1:]
				else:
					name = iface.get_name()
					summary = _('No information available')
				# (GTK3 returns an extra boolean at the start)
				icon_width, icon_height = gtk.icon_size_lookup(gtk.ICON_SIZE_DIALOG)[-2:]
				pixbuf = icon.load_icon(self.iface_cache.get_icon_path(iface), icon_width, icon_height)
			except model.InvalidInterface as ex:
				name = uri
				summary = unicode(ex)
				pixbuf = None

			m[itr][AppListBox.NAME] = name
			if pixbuf is None:
				pixbuf = self.window.render_icon(gtk.STOCK_EXECUTE, gtk.ICON_SIZE_DIALOG)
			m[itr][AppListBox.ICON] = pixbuf

			m[itr][AppListBox.MARKUP] = '<b>%s</b>\n<i>%s</i>' % (_pango_escape(name), _pango_escape(summary))
示例#3
0
    def populate_model(self):
        m = self.model
        m.clear()

        for uri in self.app_list.get_apps():
            itr = m.append()
            m[itr][AppListBox.URI] = uri

            try:
                iface = self.iface_cache.get_interface(uri)
                name = iface.get_name()
                summary = iface.summary or _('No information available')
                summary = summary[:1].capitalize() + summary[1:]
                icon_width, icon_height = gtk.icon_size_lookup(
                    gtk.ICON_SIZE_DIALOG)
                pixbuf = icon.load_icon(self.iface_cache.get_icon_path(iface),
                                        icon_width, icon_height)
            except model.InvalidInterface as ex:
                name = uri
                summary = unicode(ex)
                pixbuf = None

            m[itr][AppListBox.NAME] = name
            if pixbuf is None:
                pixbuf = self.window.render_icon(gtk.STOCK_EXECUTE,
                                                 gtk.ICON_SIZE_DIALOG)
            m[itr][AppListBox.ICON] = pixbuf

            m[itr][AppListBox.MARKUP] = '<b>%s</b>\n<i>%s</i>' % (
                _pango_escape(name), _pango_escape(summary))
示例#4
0
文件: addbox.py 项目: afb/0install
		def update_details_page():
			blocker = slave.invoke_master(['get-feed-metadata', uri.get_text()])
			yield blocker
			tasks.check(blocker)
			feed = blocker.result

			about.set_text('%s - %s' % (feed['name'], feed['summary']))
			icon_path = feed['icon-path']
			from zeroinstall.gtkui import icon
			icon_pixbuf = icon.load_icon(icon_path)
			if icon_pixbuf:
				icon_widget.set_from_pixbuf(icon_pixbuf)

			feed_category = feed['category']
			if feed_category:
				i = 0
				for row in categories:
					if row.lower() == feed_category.lower():
						category.set_active(i)
						break
					i += 1
			self.window.set_response_sensitive(_RESPONSE_PREV, True)

			nb.next_page()
			dialog_next.set_property('visible', False)
			dialog_ok.set_property('visible', True)
			dialog_ok.grab_focus()
	def populate_model(self):
		model = self.model
		model.clear()

		default_icon = self.window.render_icon(gtk.STOCK_EXECUTE, gtk.ICON_SIZE_DIALOG)

		for uri in self.app_list.get_apps():
			itr = model.append()
			model[itr][AppListBox.URI] = uri

			iface = self.iface_cache.get_interface(uri)
			name = iface.get_name()
			summary = iface.summary or _('No information available')
			summary = summary[:1].capitalize() + summary[1:]

			model[itr][AppListBox.NAME] = name
			pixbuf = icon.load_icon(self.iface_cache.get_icon_path(iface))
			if not pixbuf:
				pixbuf = default_icon
			else:
				# Cap icon size, some icons are really high resolution
				pixbuf = self.cap_pixbuf_dimensions(pixbuf, default_icon.get_width())
			model[itr][AppListBox.ICON] = pixbuf

			model[itr][AppListBox.MARKUP] = '<b>%s</b>\n<i>%s</i>' % (_pango_escape(name), _pango_escape(summary))
示例#6
0
	def get_icon(self, iface):
		"""Get an icon for this interface. If the icon is in the cache, use that.
		If not, start a download. If we already started a download (successful or
		not) do nothing. Returns None if no icon is currently available."""
		try:
			# Try the in-memory cache
			return self.cached_icon[iface.uri]
		except KeyError:
			# Try the on-disk cache
			iconpath = self.config.iface_cache.get_icon_path(iface)

			if iconpath:
				icon = load_icon(iconpath, ICON_SIZE, ICON_SIZE)
				# (if icon is None, cache the fact that we can't load it)
				self.cached_icon[iface.uri] = icon
			else:
				icon = None

			# Download a new icon if we don't have one, or if the
			# user did a 'Refresh'
			if iconpath is None or self.update_icons:
				if self.config.network_use == model.network_offline:
					fetcher = None
				else:
					fetcher = self.config.fetcher.download_icon(iface)
				if fetcher:
					if iface.uri not in self.cached_icon:
						self.cached_icon[iface.uri] = None	# Only try once

					@tasks.async
					def update_display():
						yield fetcher
						try:
							tasks.check(fetcher)
							# Try to insert new icon into the cache
							# If it fails, we'll be left with None in the cached_icon so
							# we don't try again.
							iconpath = self.config.iface_cache.get_icon_path(iface)
							if iconpath:
								self.cached_icon[iface.uri] = load_icon(iconpath, ICON_SIZE, ICON_SIZE)
								self.build_tree()
							else:
								warn("Failed to download icon for '%s'", iface)
						except Exception as ex:
							import traceback
							traceback.print_exc()
							self.config.handler.report_error(ex)
					update_display()
				# elif fetcher is None: don't store anything in cached_icon

			# Note: if no icon is available for downloading,
			# more attempts are made later.
			# It can happen that no icon is yet available because
			# the interface was not downloaded yet, in which case
			# it's desireable to try again once the interface is available
			return icon

		return None
示例#7
0
					def update_display():
						yield fetcher
						try:
							tasks.check(fetcher)
							# Try to insert new icon into the cache
							# If it fails, we'll be left with None in the cached_icon so
							# we don't try again.
							iconpath = self.policy.config.iface_cache.get_icon_path(iface)
							if iconpath:
								self.cached_icon[iface.uri] = load_icon(iconpath, ICON_SIZE, ICON_SIZE)
								self.build_tree()
							else:
								warn("Failed to download icon for '%s'", iface)
						except Exception as ex:
							import traceback
							traceback.print_exc()
							self.policy.handler.report_error(ex)
示例#8
0
					def update_display():
						yield fetcher
						try:
							tasks.check(fetcher)
							# Try to insert new icon into the cache
							# If it fails, we'll be left with None in the cached_icon so
							# we don't try again.
							iconpath = self.config.iface_cache.get_icon_path(iface)
							if iconpath:
								self.cached_icon[iface.uri] = load_icon(iconpath, ICON_SIZE, ICON_SIZE)
								self.build_tree()
							else:
								warn("Failed to download icon for '%s'", iface)
						except Exception as ex:
							import traceback
							traceback.print_exc()
							self.config.handler.report_error(ex)
示例#9
0
		def update_details_page():
			iface = iface_cache.get_interface(model.canonical_iface_uri(uri.get_text()))
			about.set_text('%s - %s' % (iface.get_name(), iface.summary))
			icon_path = iface_cache.get_icon_path(iface)
			from zeroinstall.gtkui import icon
			icon_pixbuf = icon.load_icon(icon_path)
			if icon_pixbuf:
				icon_widget.set_from_pixbuf(icon_pixbuf)

			feed_category = None
			for meta in iface.get_metadata(XMLNS_IFACE, 'category'):
				feed_category = meta.content
				break
			if feed_category:
				i = 0
				for row in categories:
					if row.lower() == feed_category.lower():
						category.set_active(i)
						break
					i += 1
			self.window.set_response_sensitive(_RESPONSE_PREV, True)
示例#10
0
		def update_details_page():
			iface = iface_cache.get_interface(model.canonical_iface_uri(uri.get_text()))
			about.set_text('%s - %s' % (iface.get_name(), iface.summary))
			icon_path = iface_cache.get_icon_path(iface)
			from zeroinstall.gtkui import icon
			icon_pixbuf = icon.load_icon(icon_path)
			if icon_pixbuf:
				icon_widget.set_from_pixbuf(icon_pixbuf)

			feed_category = None
			for meta in iface.get_metadata(XMLNS_IFACE, 'category'):
				feed_category = meta.content
				break
			if feed_category:
				i = 0
				for row in category.get_model():
					if row[0].lower() == feed_category.lower():
						category.set_active(i)
						break
					i += 1
			self.window.set_response_sensitive(_RESPONSE_PREV, True)
示例#11
0
					def update_display():
						yield fetcher
						try:
							tasks.check(fetcher)
							# Try to insert new icon into the cache
							# If it fails, we'll be left with None in the cached_icon so
							# we don't try again.
							iconpath = self.config.iface_cache.get_icon_path(iface)
							if iconpath:
								self.cached_icon[iface.uri] = load_icon(iconpath, ICON_SIZE, ICON_SIZE)
								self.build_tree()
							else:
								warn("Failed to download icon for '%s'", iface)
						except download.DownloadAborted as ex:
							info("Icon download aborted: %s", ex)
							# Don't report further; the user knows they cancelled
						except download.DownloadError as ex:
							warn("Icon download failed: %s", ex)
							# Not worth showing a dialog box for this
						except Exception as ex:
							import traceback
							traceback.print_exc()
							self.config.handler.report_error(ex)