Example #1
0
func (mw *MainWindow) openImage() {
	dlg := &walk.FileDialog{}

	dlg.FilePath = mw.prevFilePath
	dlg.Filter = "Image Files (*.emf;*.bmp;*.exif;*.gif;*.jpeg;*.jpg;*.png;*.tiff)|*.emf;*.bmp;*.exif;*.gif;*.jpeg;*.jpg;*.png;*.tiff"
	dlg.Title = "Select an Image"

	if ok, _ := dlg.ShowOpen(mw); !ok {
		return
	}

	mw.prevFilePath = dlg.FilePath

	img, _ := walk.NewImageFromFile(dlg.FilePath)

	var succeeded bool
	defer func() {
		if !succeeded {
			img.Dispose()
		}
	}()

	page, _ := walk.NewTabPage()
	page.SetTitle(path.Base(strings.Replace(dlg.FilePath, "\\", "/", -1)))
	page.SetLayout(walk.NewHBoxLayout())

	defer func() {
		if !succeeded {
			page.Dispose()
		}
	}()

	imageView, _ := walk.NewImageView(page)

	defer func() {
		if !succeeded {
			imageView.Dispose()
		}
	}()

	imageView.SetImage(img)
	mw.tabWidget.Pages().Add(page)
	mw.tabWidget.SetCurrentIndex(mw.tabWidget.Pages().Len() - 1)

	succeeded = true
}
Example #2
0
func (iv ImageView) Create(builder *Builder) error {
	w, err := walk.NewImageView(builder.Parent())
	if err != nil {
		return err
	}

	return builder.InitWidget(iv, w, func() error {
		if err := w.SetImage(iv.Image); err != nil {
			return err
		}

		if iv.AssignTo != nil {
			*iv.AssignTo = w
		}

		return nil
	})
}
Example #3
0
func (iv ImageView) Create(parent walk.Container) error {
	w, err := walk.NewImageView(parent)
	if err != nil {
		return err
	}

	return InitWidget(iv, w, func() error {
		if err := w.SetImage(iv.Image); err != nil {
			return err
		}

		if iv.AssignTo != nil {
			*iv.AssignTo = w
		}

		return nil
	})
}
Example #4
0
File: win.go Project: xausee/touch
func showImage(owner walk.Form, tabWidget *walk.TabWidget) {
	dlgf := new(walk.FileDialog)
	dlgf.FilePath = ""
	dlgf.Filter = "Image Files (*.emf;*.bmp;*.exif;*.gif;*.jpeg;*.jpg;*.png;*.tiff)|*.emf;*.bmp;*.exif;*.gif;*.jpeg;*.jpg;*.png;*.tiff"
	dlgf.Title = "Select an Image"

	if ok, err := dlgf.ShowOpen(owner); err != nil {
		log.Print(err)
	} else if !ok {
		//return nil
	}

	//walk.MsgBox(nil, "文件路径", dlgf.FilePath, walk.MsgBoxOK)

	img, err := walk.NewImageFromFile(dlgf.FilePath)
	if err != nil {
		log.Print(err)
	}

	var succeeded bool
	defer func() {
		if !succeeded {
			img.Dispose()
		}
	}()

	page, err := walk.NewTabPage()
	if err != nil {
		log.Print(err)
	}

	//if page.SetTitle(path.Base(strings.Replace(dlgf.FilePath, "\\", "/", -1))); err != nil {
	//	log.Print(err)
	//}
	page.SetLayout(walk.NewHBoxLayout())

	defer func() {
		if !succeeded {
			page.Dispose()
		}
	}()

	imageView, err := walk.NewImageView(page)
	if err != nil {
		log.Print(err)
	}

	defer func() {
		if !succeeded {
			imageView.Dispose()
		}
	}()
	imageView.SetImage(img)

	if err := tabWidget.Pages().Add(page); err != nil {
		log.Print(err)
	}

	if err := tabWidget.SetCurrentIndex(tabWidget.Pages().Len() - 1); err != nil {
		log.Print(err)
	}

	succeeded = true
}