Пример #1
0
func (widget *Preview) setImage(imageLocation string) {
	if imageLocation != "" {
		pixbuf, e := common.PixbufAtSize(imageLocation, MaxPreviewWidth, MaxPreviewHeight)
		if e == nil {
			widget.previewImage.SetFromPixbuf(pixbuf)
			widget.previewFrame.Show()
		}
	}

	// if isTemp {
	// 	widget.TmpFile = imageLocation
	// }

}
Пример #2
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)
		})
	}()

}