func (mw *MyMainWindow) showDialogAction_Triggered() { dlg := new(MyDialog) var acceptPB *walk.PushButton var le1, le2 *walk.LineEdit widgets := []Widget{ Label{Row: 0, Column: 0, Text: "A LineEdit:"}, LineEdit{Row: 0, Column: 1, AssignTo: &le1, OnTextChanged: func() { le2.SetText(le1.Text()) }}, ToolButton{Row: 0, Column: 2, Text: "..."}, Label{Row: 1, Column: 0, Text: "Another LineEdit:"}, LineEdit{Row: 1, Column: 1, AssignTo: &le2}, Label{Row: 2, Column: 0, Text: "A ComboBox:"}, ComboBox{Row: 2, Column: 1}, VSpacer{Row: 3, Column: 0, Size: 10}, Label{Row: 4, Column: 0, ColumnSpan: 2, Text: "A TextEdit:"}, TextEdit{Row: 5, Column: 0, ColumnSpan: 2}, } dd := &DialogDecl{ Title: "My Dialog", Owner: mw, Dialog: &dlg.Dialog, AcceptPB: &acceptPB, Widgets: widgets, MinSize: Size{400, 300}, } if err := dd.Create(); err != nil { log.Fatal(err) } acceptPB.Clicked().Attach(func() { dlg.Accept() }) dlg.Run() }
func main() { var aTE, bTE, cTE, dTE *walk.LineEdit var outTE *walk.TextEdit var mw *walk.MainWindow defer func() { if e := recover(); e != nil { walk.MsgBox(mw, "Error", fmt.Sprintf("%v", e), walk.MsgBoxIconInformation) } }() MainWindow{ AssignTo: &mw, Title: "24 Game", MinSize: Size{600, 400}, Layout: VBox{}, Children: []Widget{ Composite{ Layout: HBox{}, Children: []Widget{ Label{Text: "a"}, LineEdit{AssignTo: &aTE}, Label{Text: "b"}, LineEdit{AssignTo: &bTE}, Label{Text: "c"}, LineEdit{AssignTo: &cTE}, Label{Text: "d"}, LineEdit{AssignTo: &dTE}, PushButton{ Text: "Go", OnClicked: func() { rand.Seed(time.Now().Unix()) aTE.SetText(fmt.Sprint(rand.Intn(13) + 1)) bTE.SetText(fmt.Sprint(rand.Intn(13) + 1)) cTE.SetText(fmt.Sprint(rand.Intn(13) + 1)) dTE.SetText(fmt.Sprint(rand.Intn(13) + 1)) }, }, }, }, TextEdit{AssignTo: &outTE, ReadOnly: true}, PushButton{ Text: "Compute", OnClicked: func() { a, err := strconv.ParseInt(aTE.Text(), 10, 64) b, err := strconv.ParseInt(bTE.Text(), 10, 64) c, err := strconv.ParseInt(cTE.Text(), 10, 64) d, err := strconv.ParseInt(dTE.Text(), 10, 64) if err != nil { walk.MsgBox(mw, "Error", err.Error(), walk.MsgBoxIconInformation) } outTE.SetText("") for solution := range findSolution(a, b, c, d) { outTE.AppendText(fmt.Sprintf("%s = 24\r\n", solution)) } if outTE.Text() == "" { outTE.SetText("No solution.") } }, }, }, }.Run() }
/** *添加版本的方法 */ func CreateVersion_Triggered(owner walk.Form, model *xorm.VersionModel) { var dlg *walk.Dialog var db *walk.DataBinder var dph *walk.LineEdit var ep walk.ErrorPresenter var version = new(xorm.Version) var acceptPB, cancelPB *walk.PushButton var dialog = Dialog{} dialog.AssignTo = &dlg dialog.Title = "创建版本" dialog.DataBinder = DataBinder{ AssignTo: &db, DataSource: version, ErrorPresenter: ErrorPresenterRef{&ep}, } dialog.MinSize = Size{300, 200} dialog.Layout = VBox{} dialog.DefaultButton = &acceptPB dialog.CancelButton = &cancelPB dirPath := LineEdit{ AssignTo: &dph, Text: Bind("Path"), ReadOnly: true, } childrens := []Widget{ Composite{ Layout: Grid{Columns: 5}, Children: []Widget{ Label{ Text: "工程:", MinSize: Size{42, 0}, }, ComboBox{ MinSize: Size{108, 0}, Value: Bind("ProjectName", SelRequired{}), BindingMember: "Key", DisplayMember: "Name", Model: xorm.FindAllProjDataCombox(), }, dirPath, PushButton{ Text: "选择版本", OnClicked: func() { filDlg := new(walk.FileDialog) filDlg.ShowBrowseFolder(owner) dph.SetText(filDlg.FilePath) }, }, }, }, Composite{ Layout: Grid{Columns: 2}, Children: []Widget{ Label{ Text: "名称:", }, LineEdit{ Text: Bind("Name"), MaxLength: 10, }, Label{ Text: "创建者:", }, LineEdit{ Text: Bind("CreateUser"), MaxLength: 10, }, Label{ Text: "描述:", }, TextEdit{ Text: Bind("Desc"), MinSize: Size{300, 50}, }, LineErrorPresenter{ AssignTo: &ep, ColumnSpan: 2, }, }, }, Composite{ Layout: HBox{}, Children: []Widget{ HSpacer{}, PushButton{ AssignTo: &acceptPB, Text: "保存", OnClicked: func() { if err := db.Submit(); err != nil { log.Print(err) return } xorm.SaveVersionByParam(version.Name, version.CreateUser, version.Desc) model.ResetRows() dlg.Accept() }, }, PushButton{ AssignTo: &cancelPB, Text: "取消", OnClicked: func() { dlg.Cancel() }, }, }, }, } dialog.Children = childrens dialog.Run(owner) }