示例#1
1
func (mw *MyMainWindow) openImage() error {
	dlg := new(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, err := dlg.ShowOpen(mw); err != nil {
		return err
	} else if !ok {
		return nil
	}

	mw.prevFilePath = dlg.FilePath

	img, err := walk.NewImageFromFile(dlg.FilePath)
	if err != nil {
		return err
	}

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

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

	if page.SetTitle(path.Base(strings.Replace(dlg.FilePath, "\\", "/", -1))); err != nil {
		return err
	}
示例#2
0
文件: toolbutton.go 项目: Archs/walk
func (tb ToolButton) Create(builder *Builder) error {
	w, err := walk.NewToolButton(builder.Parent())
	if err != nil {
		return err
	}

	return builder.InitWidget(tb, w, func() error {
		img := tb.Image
		if s, ok := img.(string); ok {
			var err error
			if img, err = walk.NewImageFromFile(s); err != nil {
				return err
			}
		}
		if img != nil {
			if err := w.SetImage(img.(walk.Image)); err != nil {
				return err
			}
		}

		if tb.OnClicked != nil {
			w.Clicked().Attach(tb.OnClicked)
		}

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

		return nil
	})
}
示例#3
0
文件: builder.go 项目: linhua55/walk
func imageFromFile(filePath string) (walk.Image, error) {
	if image, ok := imagesByFilePath[filePath]; ok {
		return image, nil
	}

	image, err := walk.NewImageFromFile(filePath)
	if err != nil {
		return nil, err
	}

	imagesByFilePath[filePath] = image

	return image, nil
}
示例#4
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
}
示例#5
0
文件: win.go 项目: 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
}