當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。