当前位置: 首页>>代码示例>>Golang>>正文


Golang walk.NewAction函数代码示例

本文整理汇总了Golang中github.com/lxn/walk.NewAction函数的典型用法代码示例。如果您正苦于以下问题:Golang NewAction函数的具体用法?Golang NewAction怎么用?Golang NewAction使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了NewAction函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。

示例1: main

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()
}
开发者ID:CodyGuo,项目名称:Go-Cody,代码行数:34,代码来源:main.go

示例2: main

func main() {
	walk.Initialize(walk.InitParams{PanicOnError: true})
	defer walk.Shutdown()

	mainWnd, _ := walk.NewMainWindow()

	mw := &MainWindow{MainWindow: mainWnd}
	mw.SetLayout(walk.NewVBoxLayout())
	mw.SetTitle("Walk Image Viewer Example")

	mw.tabWidget, _ = walk.NewTabWidget(mw)

	imageList, _ := walk.NewImageList(walk.Size{16, 16}, 0)
	mw.ToolBar().SetImageList(imageList)

	fileMenu, _ := walk.NewMenu()
	fileMenuAction, _ := mw.Menu().Actions().AddMenu(fileMenu)
	fileMenuAction.SetText("&File")

	openBmp, _ := walk.NewBitmapFromFile("../img/open.png")

	openAction := walk.NewAction()
	openAction.SetImage(openBmp)
	openAction.SetText("&Open")
	openAction.Triggered().Attach(func() { mw.openImage() })
	fileMenu.Actions().Add(openAction)
	mw.ToolBar().Actions().Add(openAction)

	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 Image Viewer Example", walk.MsgBoxOK|walk.MsgBoxIconInformation)
	})
	helpMenu.Actions().Add(aboutAction)

	mw.SetMinMaxSize(walk.Size{320, 240}, walk.Size{})
	mw.SetSize(walk.Size{800, 600})
	mw.Show()

	mw.Run()
}
开发者ID:hoperuin,项目名称:walk,代码行数:50,代码来源:imageviewer.go

示例3: switchEngine

func (mw *MyWindows) switchEngine() error {
	menuEngine, _ := walk.NewMenu()
	engine, _ := mw.ni.ContextMenu().Actions().AddMenu(menuEngine)
	engine.SetText("切换视频源")

	engineAction1 := walk.NewAction()
	engineAction1.SetText("资源一")
	engineAction2 := walk.NewAction()
	engineAction2.SetText("资源二")
	engineAction3 := walk.NewAction()
	engineAction3.SetText("资源三")

	engineAction1.SetChecked(true)
	engineAction2.SetChecked(false)
	engineAction3.SetChecked(false)

	engineAction1.Triggered().Attach(func() {
		requestUrl = engine1
		engineAction1.SetChecked(true)
		engineAction2.SetChecked(false)
		engineAction3.SetChecked(false)

		mw.OpenVip()
	})

	engineAction2.Triggered().Attach(func() {
		requestUrl = engine2
		engineAction1.SetChecked(false)
		engineAction2.SetChecked(true)
		engineAction3.SetChecked(false)

		mw.OpenVip()
	})

	engineAction3.Triggered().Attach(func() {
		requestUrl = engine3
		engineAction1.SetChecked(false)
		engineAction2.SetChecked(false)
		engineAction3.SetChecked(true)

		mw.OpenVip()
	})

	menuEngine.Actions().Add(engineAction1)
	menuEngine.Actions().Add(engineAction2)
	menuEngine.Actions().Add(engineAction3)

	return nil
}
开发者ID:CodyGuo,项目名称:Go-Cody,代码行数:49,代码来源:main.go

示例4: createAction

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
}
开发者ID:karlma,项目名称:walk,代码行数:26,代码来源:action.go

示例5: AddMenuAction

func (this *Table) AddMenuAction(text string, cb func()) *Table {
	act := walk.NewAction()
	act.SetText(text)
	act.Triggered().Attach(cb)
	this.ContextMenu().Actions().Add(act)

	return this
}
开发者ID:joy999,项目名称:walkwrap,代码行数:8,代码来源:Table.go

示例6: createAction

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
}
开发者ID:jeffycf,项目名称:walk,代码行数:58,代码来源:action.go

示例7: addNotyfyAction

// 托盘图标
func (mw *MyWindow) addNotyfyAction() {
	var err error
	mw.notifyIcon, err = walk.NewNotifyIcon()
	checkError(err)
	mw.notifyIcon.SetVisible(true)
	exitAction := walk.NewAction()
	exitAction.SetText("退出程序")
	exitAction.Triggered().Attach(func() {
		mw.exit()
	})
	mw.notifyIcon.ContextMenu().Actions().Add(exitAction)
}
开发者ID:CodyGuo,项目名称:Go-Cody,代码行数:13,代码来源:main.go

示例8: RunApp

func (mw *MyWindow) RunApp() {
	mw.model = NewLogModel()
	open := walk.NewAction()
	open.SetText("打开目录")

	if err := (MainWindow{
		AssignTo: &mw.MainWindow,
		Title:    "iMan高级调试日志解密工具 2.2",
		Layout:   VBox{},
		MinSize:  Size{980, 650},
		Children: []Widget{
			TableView{
				AssignTo:            &mw.tv,
				LastColumnStretched: true,
				ToolTipText:         "把日志拖放上来即可解密.",
				Columns: []TableViewColumn{
					{Title: "序号", Width: 45},
					{Title: "文件名", Width: 180},
					{Title: "文件路径", Width: 200},
					{Title: "状态", Width: 70},
					{Title: "备注", Width: 0},
				},
				Model: mw.model,
				OnCurrentIndexChanged: func() {
					mw.row = mw.tv.CurrentIndex()
				},
				ContextMenuItems: []MenuItem{
					ActionRef{&open},
				},
			},
		},
	}.CreateCody()); err != nil {
		log.Fatal(err)
	}

	open.Triggered().Attach(func() {
		if len(mw.model.items) == 0 {
			runCMD("cmd /c start .").Run()
		} else {
			path, _ := os.Getwd()
			runCMD("cmd /c start " + path + "\\logout\\").Run()
		}
	})

	mw.dropFiles()

	icon, _ := walk.NewIconFromResourceId(3)
	mw.SetIcon(icon)

	walk.MsgBox(mw, "提示", "把日志拖放到空白区即可解密!", walk.MsgBoxIconInformation)
	mw.Run()
}
开发者ID:CodyGuo,项目名称:Go-Cody,代码行数:52,代码来源:main.go

示例9: openAction

func (mw *MyWindows) openAction() error {
	openAction := walk.NewAction()
	if err := openAction.SetText("打开VIP"); err != nil {
		return err
	}
	openAction.Triggered().Attach(func() {
		mw.OpenVip()
	})
	if err := mw.ni.ContextMenu().Actions().Add(openAction); err != nil {
		return err
	}

	return nil
}
开发者ID:CodyGuo,项目名称:Go-Cody,代码行数:14,代码来源:main.go

示例10: newNotify

func newNotify() {
	var err error
	context.notifyIcon, err = walk.NewNotifyIcon()
	if err != nil {
		common.Error("Error invoking NewNotifyIcon: %v", err)
	}
	icon, _ := walk.NewIconFromFile("res/lily.ico")
	if err := context.notifyIcon.SetIcon(icon); err != nil {
		common.Error("Error setting notify icon: %v", err)
	}
	if err := context.notifyIcon.SetToolTip("Click for info or use the context menu to exit."); err != nil {
		common.Error("Fail to set tooltip: %v", err)
	}
	f := func() {
		if !context.mw.Visible() {
			context.mw.Show()
		} else {
			context.mw.SwitchToThisWindow()
		}
	}
	go core.Triggered(f)
	context.notifyIcon.MouseUp().Attach(func(x, y int, button walk.MouseButton) {
		if button == walk.LeftButton {
			f()
		}
		// if err := context.notifyIcon.ShowCustom(
		// 	"Walk NotifyIcon Example",
		// 	"There are multiple ShowX methods sporting different icons."); err != nil {
		// 	common.Error("Fail to show custom notify: %v", err)
		// }
	})
	exitAction := walk.NewAction()
	if err := exitAction.SetText("退出"); err != nil {
		common.Error("Error setting exitAction text: %v", err)
	}
	exitAction.Triggered().Attach(func() {
		context.notifyIcon.Dispose()
		// os.Exit(-1)
		walk.App().Exit(0)
	})
	if err := context.notifyIcon.ContextMenu().Actions().Add(exitAction); err != nil {
		common.Error("Error Adding exitAction: %v", err)
	}
	if err := context.notifyIcon.SetVisible(true); err != nil {
		common.Error("Error setting notify visible: %v", err)
	}
	// if err := context.notifyIcon.ShowInfo("Walk NotifyIcon Example", "Click the icon to show again."); err != nil {
	// 	common.Error("Error showing info: %v", err)
	// }
}
开发者ID:tinycedar,项目名称:lily,代码行数:50,代码来源:notify.go

示例11: createAction

func (s Separator) createAction(builder *Builder, 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
}
开发者ID:bonyz,项目名称:walk,代码行数:15,代码来源:action.go

示例12: exitAction

func (mw *MyWindows) exitAction() error {
	exitAction := walk.NewAction()
	if err := exitAction.SetText("退出VIP"); err != nil {
		return err
	}
	exitAction.Triggered().Attach(func() {
		mw.ni.Dispose()
		walk.App().Exit(0)
	})
	if err := mw.ni.ContextMenu().Actions().Add(exitAction); err != nil {
		return err
	}

	return nil
}
开发者ID:CodyGuo,项目名称:Go-Cody,代码行数:15,代码来源:main.go

示例13: createAction

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
}
开发者ID:etel,项目名称:walk,代码行数:15,代码来源:action.go

示例14: main

func main() {
	// Initialize walk and specify that we want errors to be panics.
	walk.Initialize(walk.InitParams{PanicOnError: true})
	defer walk.Shutdown()

	// We need either a walk.MainWindow or a walk.Dialog for their message loop.
	// We will not make it visible in this example, though.
	mw, _ := walk.NewMainWindow()

	// We load our icon from a file.
	icon, _ := walk.NewIconFromFile("../img/x.ico")

	// Create the notify icon and make sure we clean it up on exit.
	ni, _ := walk.NewNotifyIcon()
	defer ni.Dispose()

	// Set the icon and a tool tip text.
	ni.SetIcon(icon)
	ni.SetToolTip("Click for info or use the context menu to exit.")

	// When the left mouse button is pressed, bring up our balloon.
	ni.MouseDown().Attach(func(x, y int, button walk.MouseButton) {
		if button != walk.LeftButton {
			return
		}

		ni.ShowCustom(
			"Walk NotifyIcon Example",
			"There are multiple ShowX methods sporting different icons.")
	})

	// We put an exit action into the context menu.
	exitAction := walk.NewAction()
	exitAction.SetText("E&xit")
	exitAction.Triggered().Attach(func() { walk.App().Exit(0) })
	ni.ContextMenu().Actions().Add(exitAction)

	// The notify icon is hidden initially, so we have to make it visible.
	ni.SetVisible(true)

	// Now that the icon is visible, we can bring up an info balloon.
	ni.ShowInfo("Walk NotifyIcon Example", "Click the icon to show again.")

	// Run the message loop.
	mw.Run()
}
开发者ID:etel,项目名称:walk,代码行数:46,代码来源:notifyicon.go

示例15: remoteAction

func (mw *MyWindows) remoteAction() error {
	remoteAction := walk.NewAction()
	if err := remoteAction.SetText("远程访问"); err != nil {
		return err
	}
	remoteAction.Triggered().Attach(func() {
		ip, err := getIP()
		if err != nil {
			log.Fatal(err)
		}
		mw.showMsg("远程访问", fmt.Sprintf("其他电脑在浏览器地址中输入 http://%s%s 进行访问。", ip, port))
	})
	if err := mw.ni.ContextMenu().Actions().Add(remoteAction); err != nil {
		return err
	}

	return nil
}
开发者ID:CodyGuo,项目名称:Go-Cody,代码行数:18,代码来源:main.go


注:本文中的github.com/lxn/walk.NewAction函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。