Exemple #1
0
// Load loads an applet or theme in the preview. Handbooker and Appleter can be used.
//
func (widget *Preview) Load(pack Previewer) {
	widget.title.SetMarkup(common.Big(common.Bold(pack.GetTitle())))
	author := pack.GetAuthor()
	if author != "" {
		author = fmt.Sprintf(tran.Slate("by %s"), author)
	}
	widget.author.SetMarkup(common.Small(common.Mono(author)))

	apl, ok := pack.(Appleter)
	if ok {
		widget.stateText.SetMarkup(apl.FormatState())
		widget.size.SetMarkup(common.Small(apl.FormatSize()))

		if icon := apl.IconState(); icon != "" {
			if pixbuf, e := common.PixbufAtSize(icon, 24, 24); !widget.log.Err(e, "Load image pixbuf") {
				widget.stateIcon.SetFromPixbuf(pixbuf)
				widget.stateIcon.Show()
			}
		}
	}

	// widget.RemoveTmpFile()

	widget.previewFrame.Hide() // Hide the preview frame until we have an image.

	// Async calls for description and image. They can have to be downloaded and be slow at it.

	chDesc := make(chan (string))
	go func() { // Go routines to get data.
		chDesc <- pack.GetDescription()
	}()
	go func() {
		imageLocation := pack.GetPreviewFilePath()
		// imageLocation, isTemp := pack.GetPreview(widget.TmpFile) // reuse the same tmp location if needed.

		desc := <-chDesc
		glib.IdleAdd(func() { // glib Idle to show the result.
			widget.description.SetMarkup(desc)
			widget.setImage(imageLocation)
		})
	}()

}
Exemple #2
0
// SetPackage fills the handbook data with a package.
//
func (widget *Handbook) SetPackage(book datatype.Handbooker) {
	title := common.Bold(common.Big(book.GetTitle()))
	if widget.ShowVersion {
		title += " v" + book.GetModuleVersion()
	}
	widget.title.SetMarkup(title)

	author := book.GetAuthor()
	if author != "" {
		author = fmt.Sprintf("by %s", author)
		widget.author.SetMarkup(common.Small(common.Mono(author)))
	}
	widget.author.SetVisible(author != "")

	widget.description.SetMarkup("<span rise='8000'>" + book.GetDescription() + "</span>")

	previewFound := false
	defer func() { widget.previewFrame.SetVisible(previewFound) }()

	file := book.GetPreviewFilePath()
	if file == "" {
		return
	}
	_, w, h := gdk.PixbufGetFileInfo(file)

	var pixbuf *gdk.Pixbuf
	var e error
	if w > PreviewSizeMax || h > PreviewSizeMax {
		pixbuf, e = gdk.PixbufNewFromFileAtScale(file, PreviewSizeMax, PreviewSizeMax, true)
	} else {
		pixbuf, e = gdk.PixbufNewFromFile(file)
	}

	if e == nil && pixbuf != nil {
		previewFound = true
		widget.previewImage.SetFromPixbuf(pixbuf)
	}
}