Beispiel #1
4
func main() {
	var tool *walk.Action
	var menutool *walk.Menu

	var mw *walk.MainWindow

	mw.SetMaximizeBox(false)
	mw.SetFixedSize(true)

	mw, _ = walk.NewMainWindowCody()
	mw.SetTitle("测试")
	mw.SetSize(walk.Size{300, 200})

	menutool, _ = walk.NewMenu()
	tool = walk.NewMenuAction(menutool)
	tool.SetText("文件")
	open := walk.NewAction()
	open.SetText("打开")
	exit := walk.NewAction()
	exit.SetText("退出")

	menutool.Actions().Add(open)
	menutool.Actions().Add(exit)

	men2, _ := walk.NewMenu()
	too2 := walk.NewMenuAction(men2)
	too2.SetText("工具")

	mw.Menu().Actions().Add(tool)
	mw.Menu().Actions().Add(too2)

	mw.Show()
	mw.Run()
}
Beispiel #2
0
func (s Separator) createAction(menu *walk.Menu) (*walk.Action, error) {
	action := walk.NewAction()

	if err := action.SetText("-"); err != nil {
		return nil, err
	}

	if menu != nil {
		if err := menu.Actions().Add(action); err != nil {
			return nil, err
		}
	}

	return action, nil
}
Beispiel #3
0
func (a Action) createAction(menu *walk.Menu) (*walk.Action, error) {
	action := walk.NewAction()

	if _, err := a.initAction(action); err != nil {
		return nil, err
	}

	if menu != nil {
		if err := menu.Actions().Add(action); err != nil {
			return nil, err
		}
	}

	return action, nil
}
Beispiel #4
0
func (m Menu) createAction(menu *walk.Menu) (*walk.Action, error) {
	if menu == nil {
		var err error
		if menu, err = walk.NewMenu(); err != nil {
			return nil, err
		}
	}

	subMenu, err := walk.NewMenu()
	if err != nil {
		return nil, err
	}

	action, err := menu.Actions().AddMenu(subMenu)
	if err != nil {
		return nil, err
	}

	if err := action.SetText(m.Text); err != nil {
		return nil, err
	}
	if err := action.SetImage(m.Image); err != nil {
		return nil, err
	}

	for _, item := range m.Items {
		if _, err := item.createAction(subMenu); err != nil {
			return nil, err
		}
	}

	if m.AssignActionTo != nil {
		*m.AssignActionTo = action
	}
	if m.AssignTo != nil {
		*m.AssignTo = subMenu
	}

	return action, nil
}
Beispiel #5
0
func (m Menu) createAction(builder *Builder, menu *walk.Menu) (*walk.Action, error) {
	subMenu, err := walk.NewMenu()
	if err != nil {
		return nil, err
	}

	var action *walk.Action
	if menu == nil {
		action = walk.NewMenuAction(subMenu)
	} else if action, err = menu.Actions().AddMenu(subMenu); err != nil {
		return nil, err
	}

	if err := action.SetText(m.Text); err != nil {
		return nil, err
	}
	if err := setActionImage(action, m.Image); err != nil {
		return nil, err
	}

	for _, item := range m.Items {
		if _, err := item.createAction(builder, subMenu); err != nil {
			return nil, err
		}
	}

	if m.OnTriggered != nil {
		action.Triggered().Attach(m.OnTriggered)
	}

	if m.AssignActionTo != nil {
		*m.AssignActionTo = action
	}
	if m.AssignTo != nil {
		*m.AssignTo = subMenu
	}

	return action, nil
}
Beispiel #6
0
func main() {
	walk.SetTranslationFunc(tr)

	var err error
	if trDict, err = polyglot.NewDict("../../l10n", "en"); err != nil {
		log.Fatal(err)
	}

	mw := new(MyMainWindow)

	var openAction *walk.Action
	var recentMenu *walk.Menu

	menuActions, err := CreateActions(
		Menu{
			Text: "&File",
			Items: []MenuItem{
				Action{
					AssignTo:    &openAction,
					Text:        "&Open",
					Image:       "../img/open.png",
					OnTriggered: func() { mw.openAction_Triggered() },
				},
				Menu{
					AssignTo: &recentMenu,
					Text:     "Recent",
				},
				Separator{},
				Action{
					Text:        "E&xit",
					OnTriggered: func() { walk.App().Exit(0) },
				},
			},
		})
	if err != nil {
		log.Fatal(err)
	}

	openRecent1Action := walk.NewAction()
	openRecent1Action.SetText("Blah")
	recentMenu.Actions().Add(openRecent1Action)

	openRecent2Action := walk.NewAction()
	openRecent2Action.SetText("Yadda")
	recentMenu.Actions().Add(openRecent2Action)

	openRecent3Action := walk.NewAction()
	openRecent3Action.SetText("Oink")
	recentMenu.Actions().Add(openRecent3Action)

	toolBarActions, err := CreateActions(
		ActionRef{openAction},
		Separator{},
		Action{Text: "Show Dialog", OnTriggered: func() { mw.showDialogAction_Triggered() }})
	if err != nil {
		log.Fatal(err)
	}

	if err := (MainWindow{
		AssignTo:       &mw.MainWindow,
		Title:          "Walk Declarative Example",
		MenuActions:    menuActions,
		ToolBarActions: toolBarActions,
		MinSize:        Size{600, 400},
		Size:           Size{1024, 768},
		Layout:         HBox{MarginsZero: true},
		Children: []Widget{
			TabWidget{
				ContentMarginsZero: true,
				Pages: []TabPage{
					//					TabPage{Title: "golang.org/doc/", Content: WebView{URL: "http://golang.org/doc/"}},
					//					TabPage{Title: "golang.org/ref/", Content: WebView{URL: "http://golang.org/ref/"}},
					//					TabPage{Title: "golang.org/pkg/", Content: WebView{URL: "http://golang.org/pkg/"}},
					TabPage{
						Title:  "Composite Stuff",
						Layout: Grid{},
						Children: []Widget{
							TextEdit{Row: 0, Column: 0, RowSpan: 4},
							PushButton{Row: 0, Column: 1, Text: "Foo"},
							PushButton{Row: 1, Column: 1, Text: "Bar"},
							PushButton{Row: 2, Column: 1, Text: "Baz"},
							VSpacer{Row: 3, Column: 1},
						},
					},
				},
			},
		},
	}.Create()); err != nil {
		log.Fatal(err)
	}

	mw.Run()
}
Beispiel #7
0
func main() {
	walk.Initialize(walk.InitParams{})
	defer walk.Shutdown()

	mw := new(MyMainWindow)

	openImage, err := walk.NewBitmapFromFile("../img/open.png")
	if err != nil {
		log.Fatal(err)
	}

	var openAction *walk.Action
	var recentMenu *walk.Menu

	menuActions, err := CreateActions(
		Menu{
			Text: "&File",
			Items: []MenuItem{
				Action{
					AssignTo:    &openAction,
					Text:        "&Open",
					Image:       openImage,
					OnTriggered: func() { mw.openAction_Triggered() },
				},
				Menu{
					AssignTo: &recentMenu,
					Text:     "Recent",
				},
				Action{},
				Action{
					Text:        "E&xit",
					OnTriggered: func() { walk.App().Exit(0) },
				},
			},
		})
	if err != nil {
		log.Fatal(err)
	}

	openRecent1Action := walk.NewAction()
	openRecent1Action.SetText("Blah")
	recentMenu.Actions().Add(openRecent1Action)

	openRecent2Action := walk.NewAction()
	openRecent2Action.SetText("Yadda")
	recentMenu.Actions().Add(openRecent2Action)

	openRecent3Action := walk.NewAction()
	openRecent3Action.SetText("Oink")
	recentMenu.Actions().Add(openRecent3Action)

	toolBarActions, err := CreateActions(
		ActionRef{openAction},
		Action{Text: "Show Dialog", OnTriggered: func() { mw.showDialogAction_Triggered() }})
	if err != nil {
		log.Fatal(err)
	}

	if err := (MainWindow{
		AssignTo:       &mw.MainWindow,
		Title:          "FTPS cycle finder",
		MenuActions:    menuActions,
		ToolBarActions: toolBarActions,
		MinSize:        Size{600, 400},
		Size:           Size{800, 600},
		Layout:         HBox{Margins: Margins{6, 6, 6, 6}},
		Children: []Widget{
			ToolBar{Orientation: Vertical, Actions: toolBarActions},
			Composite{
				Layout: VBox{MarginsZero: true},
				Children: []Widget{
					Composite{
						Layout: HBox{MarginsZero: true},
						Children: []Widget{
							Label{Text: "File"},
							LineEdit{ContextMenuActions: []*walk.Action{openAction}},
							ToolButton{Text: "..."},
						},
					},
					Composite{
						Layout: HBox{MarginsZero: true},
						Children: []Widget{
							PushButton{Text: "Check"},
							PushButton{Text: "Check and Fix"},
							PushButton{Text: "Clear"},
							HSpacer{},
							Label{Text: "Parameter"},
							LineEdit{MaxLength: 10},
						},
					},
					Composite{
						Layout: HBox{MarginsZero: true},
						Children: []Widget{
							LineEdit{Text: "Ready.", ReadOnly: true},
							ProgressBar{StretchFactor: 10},
						},
					},
					TextEdit{ReadOnly: true},
				},
			},
		},
	}.Create(nil)); err != nil {
		log.Fatal(err)
	}

	mw.Show()
	mw.Run()
}
Beispiel #8
0
func main() {
	MustRegisterCondition("isSpecialMode", isSpecialMode)

	mw := new(MyMainWindow)

	var openAction, showAboutBoxAction *walk.Action
	var recentMenu *walk.Menu
	var toggleSpecialModePB *walk.PushButton

	if err := (MainWindow{
		AssignTo: &mw.MainWindow,
		Title:    "Walk Actions Example",
		MenuItems: []MenuItem{
			Menu{
				Text: "&File",
				Items: []MenuItem{
					Action{
						AssignTo:    &openAction,
						Text:        "&Open",
						Image:       "../img/open.png",
						Enabled:     Bind("enabledCB.Checked"),
						Visible:     Bind("openVisibleCB.Checked"),
						Shortcut:    Shortcut{walk.ModControl, walk.KeyO},
						OnTriggered: mw.openAction_Triggered,
					},
					Menu{
						AssignTo: &recentMenu,
						Text:     "Recent",
					},
					Separator{},
					Action{
						Text:        "E&xit",
						OnTriggered: func() { mw.Close() },
					},
				},
			},
			Menu{
				Text: "&Help",
				Items: []MenuItem{
					Action{
						AssignTo:    &showAboutBoxAction,
						Text:        "About",
						OnTriggered: mw.showAboutBoxAction_Triggered,
					},
				},
			},
		},
		ToolBarItems: []MenuItem{
			ActionRef{&openAction},
			Menu{
				Text:  "New A",
				Image: "../img/document-new.png",
				Items: []MenuItem{
					Action{
						Text:        "A",
						OnTriggered: mw.newAction_Triggered,
					},
					Action{
						Text:        "B",
						OnTriggered: mw.newAction_Triggered,
					},
					Action{
						Text:        "C",
						OnTriggered: mw.newAction_Triggered,
					},
				},
				OnTriggered: mw.newAction_Triggered,
			},
			Separator{},
			Menu{
				Text:  "View",
				Image: "../img/document-properties.png",
				Items: []MenuItem{
					Action{
						Text:        "X",
						OnTriggered: mw.changeViewAction_Triggered,
					},
					Action{
						Text:        "Y",
						OnTriggered: mw.changeViewAction_Triggered,
					},
					Action{
						Text:        "Z",
						OnTriggered: mw.changeViewAction_Triggered,
					},
				},
			},
			Separator{},
			Action{
				Text:        "Special",
				Image:       "../img/system-shutdown.png",
				Enabled:     Bind("isSpecialMode && enabledCB.Checked"),
				OnTriggered: mw.specialAction_Triggered,
			},
		},
		ContextMenuItems: []MenuItem{
			ActionRef{&showAboutBoxAction},
		},
		MinSize: Size{300, 200},
		Layout:  VBox{},
		Children: []Widget{
			CheckBox{
				Name:    "enabledCB",
				Text:    "Open / Special Enabled",
				Checked: true,
			},
			CheckBox{
				Name:    "openVisibleCB",
				Text:    "Open Visible",
				Checked: true,
			},
			PushButton{
				AssignTo: &toggleSpecialModePB,
				Text:     "Enable Special Mode",
				OnClicked: func() {
					isSpecialMode.SetSatisfied(!isSpecialMode.Satisfied())

					if isSpecialMode.Satisfied() {
						toggleSpecialModePB.SetText("Disable Special Mode")
					} else {
						toggleSpecialModePB.SetText("Enable Special Mode")
					}
				},
			},
		},
	}.Create()); err != nil {
		log.Fatal(err)
	}

	addRecentFileActions := func(texts ...string) {
		for _, text := range texts {
			a := walk.NewAction()
			a.SetText(text)
			a.Triggered().Attach(mw.openAction_Triggered)
			recentMenu.Actions().Add(a)
		}
	}

	addRecentFileActions("Foo", "Bar", "Baz")

	mw.Run()
}
Beispiel #9
0
func main() {
	walk.Initialize(walk.InitParams{})
	defer walk.Shutdown()

	mw := new(MyMainWindow)

	var openAction *walk.Action
	var recentMenu *walk.Menu

	menuActions, err := CreateActions(
		Menu{
			Text: "&File",
			Items: []MenuItem{
				Action{
					AssignTo:    &openAction,
					Text:        "&Open",
					Image:       "../img/open.png",
					OnTriggered: func() { mw.openAction_Triggered() },
				},
				Menu{
					AssignTo: &recentMenu,
					Text:     "Recent",
				},
				Separator{},
				Action{
					Text:        "E&xit",
					OnTriggered: func() { walk.App().Exit(0) },
				},
			},
		})
	if err != nil {
		log.Fatal(err)
	}

	openRecent1Action := walk.NewAction()
	openRecent1Action.SetText("Blah")
	recentMenu.Actions().Add(openRecent1Action)

	openRecent2Action := walk.NewAction()
	openRecent2Action.SetText("Yadda")
	recentMenu.Actions().Add(openRecent2Action)

	openRecent3Action := walk.NewAction()
	openRecent3Action.SetText("Oink")
	recentMenu.Actions().Add(openRecent3Action)

	toolBarActions, err := CreateActions(
		ActionRef{openAction},
		Separator{},
		Action{Text: "Show Dialog", OnTriggered: func() { mw.showDialogAction_Triggered() }})
	if err != nil {
		log.Fatal(err)
	}

	if err := (MainWindow{
		AssignTo:       &mw.MainWindow,
		Title:          "Walk Declarative Example",
		MenuActions:    menuActions,
		ToolBarActions: toolBarActions,
		MinSize:        Size{600, 400},
		Size:           Size{1024, 768},
		Layout:         HBox{MarginsZero: true},
		Children: []Widget{
			TabWidget{
				MarginsZero: true,
				PageTitles:  []string{"golang.org/doc/", "golang.org/ref/", "golang.org/pkg/"},
				Pages: []Widget{
					WebView{URL: "http://golang.org/doc/"},
					WebView{URL: "http://golang.org/ref/"},
					WebView{URL: "http://golang.org/pkg/"},
				},
			},
		},
	}.Create()); err != nil {
		log.Fatal(err)
	}

	mw.Show()
	mw.Run()
}
Beispiel #10
-1
func (m Menu) createAction(builder *Builder, menu *walk.Menu) (*walk.Action, error) {
	subMenu, err := walk.NewMenu()
	if err != nil {
		return nil, err
	}

	action, err := menu.Actions().AddMenu(subMenu)
	if err != nil {
		return nil, err
	}

	if err := action.SetText(m.Text); err != nil {
		return nil, err
	}
	if err := setActionImage(action, m.Image); err != nil {
		return nil, err
	}

	for _, item := range m.Items {
		if _, err := item.createAction(builder, subMenu); err != nil {
			return nil, err
		}
	}

	if m.AssignActionTo != nil {
		*m.AssignActionTo = action
	}
	if m.AssignTo != nil {
		*m.AssignTo = subMenu
	}

	return action, nil
}
Beispiel #11
-1
func (a Action) createAction(menu *walk.Menu) (*walk.Action, error) {
	action := walk.NewAction()

	if err := action.SetText(a.Text); err != nil {
		return nil, err
	}
	if err := setActionImage(action, a.Image); err != nil {
		return nil, err
	}

	if a.OnTriggered != nil {
		action.Triggered().Attach(a.OnTriggered)
	}

	if menu != nil {
		if err := menu.Actions().Add(action); err != nil {
			return nil, err
		}
	}

	if a.AssignTo != nil {
		*a.AssignTo = action
	}

	return action, nil
}
Beispiel #12
-1
func (a Action) createAction(builder *Builder, menu *walk.Menu) (*walk.Action, error) {
	action := walk.NewAction()

	if err := action.SetText(a.Text); err != nil {
		return nil, err
	}
	if err := setActionImage(action, a.Image); err != nil {
		return nil, err
	}

	if a.Enabled != nil {
		if b, ok := a.Enabled.(bool); ok {
			if err := action.SetEnabled(b); err != nil {
				return nil, err
			}
		} else if s := builder.conditionOrProperty(a.Enabled); s != nil {
			if c, ok := s.(walk.Condition); ok {
				action.SetEnabledCondition(c)
			} else {
				return nil, fmt.Errorf("value of invalid type bound to Action.Enabled: %T", s)
			}
		}
	}
	if a.Visible != nil {
		if b, ok := a.Visible.(bool); ok {
			if err := action.SetVisible(b); err != nil {
				return nil, err
			}
		} else if s := builder.conditionOrProperty(a.Visible); s != nil {
			if c, ok := s.(walk.Condition); ok {
				action.SetVisibleCondition(c)
			} else {
				return nil, fmt.Errorf("value of invalid type bound to Action.Visible: %T", s)
			}
		}
	}

	s := a.Shortcut
	if err := action.SetShortcut(walk.Shortcut{s.Modifiers, s.Key}); err != nil {
		return nil, err
	}

	if a.OnTriggered != nil {
		action.Triggered().Attach(a.OnTriggered)
	}

	if menu != nil {
		if err := menu.Actions().Add(action); err != nil {
			return nil, err
		}
	}

	if a.AssignTo != nil {
		*a.AssignTo = action
	}

	return action, nil
}
Beispiel #13
-1
func (ar ActionRef) createAction(builder *Builder, menu *walk.Menu) (*walk.Action, error) {
	if menu != nil {
		if err := menu.Actions().Add(*ar.Action); err != nil {
			return nil, err
		}
	}

	return *ar.Action, nil
}
Beispiel #14
-1
func (s Separator) createAction(builder *Builder, menu *walk.Menu) (*walk.Action, error) {
	action := walk.NewSeparatorAction()

	if menu != nil {
		if err := menu.Actions().Add(action); err != nil {
			return nil, err
		}
	}

	return action, nil
}