func main() { walk.Initialize(walk.InitParams{PanicOnError: true}) defer walk.Shutdown() mw, _ := walk.NewMainWindow() mw.SetTitle("Walk External Widgets Example") mw.SetLayout(walk.NewHBoxLayout()) a, _ := NewMyWidget(mw) a.SetName("a") b, _ := NewMyWidget(mw) b.SetName("b") c, _ := NewMyWidget(mw) c.SetName("c") mpb, _ := NewMyPushButton(mw) mpb.SetText("MyPushButton") mw.SetSize(walk.Size{400, 300}) mw.Show() mw.Run() }
func (hb HBox) Create() (walk.Layout, error) { l := walk.NewHBoxLayout() if err := setLayoutMargins(l, hb.Margins, hb.MarginsZero); err != nil { return nil, err } if err := setLayoutSpacing(l, hb.Spacing, hb.SpacingZero); err != nil { return nil, err } return l, nil }
func (tw TabWidget) Create(parent walk.Container) error { w, err := walk.NewTabWidget(parent) if err != nil { return err } return InitWidget(tw, w, func() error { for i, page := range tw.Pages { wp, err := walk.NewTabPage() if err != nil { return err } if len(tw.PageTitles) > i { if err := wp.SetTitle(tw.PageTitles[i]); err != nil { return err } } if err := w.Pages().Add(wp); err != nil { return err } l := walk.NewHBoxLayout() m := tw.Margins if !tw.MarginsZero && m.isZero() { m = Margins{9, 9, 9, 9} } if err := l.SetMargins(m.toW()); err != nil { return err } if err := wp.SetLayout(l); err != nil { return err } if err := page.Create(wp); err != nil { return err } } if tw.AssignTo != nil { *tw.AssignTo = w } return nil }) }
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 }
func main() { walk.Initialize(walk.InitParams{PanicOnError: true}) defer walk.Shutdown() mainWnd, _ := walk.NewMainWindow() mw := &MainWindow{ MainWindow: mainWnd, fileInfoModel: &FileInfoModel{}, } mw.SetTitle("Walk File Browser Example") mw.SetLayout(walk.NewHBoxLayout()) fileMenu, _ := walk.NewMenu() fileMenuAction, _ := mw.Menu().Actions().AddMenu(fileMenu) fileMenuAction.SetText("&File") exitAction := walk.NewAction() exitAction.SetText("E&xit") exitAction.Triggered().Attach(func() { walk.App().Exit(0) }) fileMenu.Actions().Add(exitAction) helpMenu, _ := walk.NewMenu() helpMenuAction, _ := mw.Menu().Actions().AddMenu(helpMenu) helpMenuAction.SetText("&Help") aboutAction := walk.NewAction() aboutAction.SetText("&About") aboutAction.Triggered().Attach(func() { walk.MsgBox(mw, "About", "Walk File Browser Example", walk.MsgBoxOK|walk.MsgBoxIconInformation) }) helpMenu.Actions().Add(aboutAction) splitter, _ := walk.NewSplitter(mw) mw.treeView, _ = walk.NewTreeView(splitter) mw.treeView.ItemExpanded().Attach(func(item *walk.TreeViewItem) { children := item.Children() if children.Len() == 1 && children.At(0).Text() == "" { mw.populateTreeViewItem(item) } }) mw.treeView.SelectionChanged().Attach(func(old, new *walk.TreeViewItem) { mw.selTvwItem = new mw.showError(mw.fileInfoModel.ResetRows(pathForTreeViewItem(new))) }) drives, _ := walk.DriveNames() mw.treeView.SetSuspended(true) for _, drive := range drives { driveItem := newTreeViewItem(drive[:2]) mw.treeView.Items().Add(driveItem) } mw.treeView.SetSuspended(false) mw.tableView, _ = walk.NewTableView(splitter) mw.tableView.SetModel(mw.fileInfoModel) mw.tableView.SetSingleItemSelection(true) mw.tableView.CurrentIndexChanged().Attach(func() { var url string index := mw.tableView.CurrentIndex() if index > -1 { name := mw.fileInfoModel.items[index].Name url = path.Join(pathForTreeViewItem(mw.selTvwItem), name) } mw.preview.SetURL(url) }) mw.preview, _ = walk.NewWebView(splitter) mw.SetMinMaxSize(walk.Size{600, 400}, walk.Size{}) mw.SetSize(walk.Size{800, 600}) mw.Show() mw.Run() }
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 }