Exemplo n.º 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()
}
Exemplo n.º 2
0
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()
}
Exemplo n.º 3
0
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
}
Exemplo n.º 4
0
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
}
Exemplo n.º 5
0
// 托盘图标
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)
}
Exemplo n.º 6
0
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()
}
Exemplo n.º 7
0
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
}
Exemplo n.º 8
0
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)
	// }
}
Exemplo n.º 9
0
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
}
Exemplo n.º 10
0
Arquivo: action.go Projeto: bonyz/walk
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
}
Exemplo n.º 11
0
Arquivo: action.go Projeto: etel/walk
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
}
Exemplo n.º 12
0
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()
}
Exemplo n.º 13
0
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
}
Exemplo n.º 14
0
func (mw *MyDialog) AddMyNotifyAction() (err error) {
	// We put an exit action into the context menu.
	exitAction := walk.NewAction()
	err = exitAction.SetText("退出程序")
	mw.checkError(err)

	exitAction.Triggered().Attach(func() {
		mw.Dispose()    // 释放主程序
		mw.ni.Dispose() // 右下角图标退出
		walk.App().Exit(1)
	})
	// 增加快捷键
	exitAction.SetShortcut(walk.Shortcut{walk.ModShift, walk.KeyB})
	// 提示信息
	exitAction.SetToolTip("退出程序.")
	err = mw.ni.ContextMenu().Actions().Add(exitAction)
	mw.checkError(err)

	return nil
}
Exemplo n.º 15
0
func (mw *MyWindows) remoteClipboard() 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)
		}
		// 先清空粘贴板
		walk.Clipboard().Clear()
		err = walk.Clipboard().SetText(fmt.Sprintf("http://%s%s", ip, port))
		checkErr(err)
	})
	if err := mw.ni.ContextMenu().Actions().Add(remoteAction); err != nil {
		return err
	}

	return nil

}
Exemplo n.º 16
0
func (mw *MyDialog) init(owner walk.Form) (err error) {
	// 设置最小化
	mw.SetMinimizeBox(true)
	// 禁用最大化
	mw.SetMaximizeBox(false)
	// 设置窗口固定
	mw.SetFixedSize(true)
	// // 设置窗口前置
	// mw.SetWindowPos(true)

	mw.Dialog, err = walk.NewDialog(owner)
	mw.checkError(err)

	succeeded := false
	defer func() {
		if !succeeded {
			mw.Dispose()
		}
	}()

	// 设置主窗体大小
	err = mw.SetClientSize(walk.Size{700, 560})
	mw.checkError(err)

	// 设置主窗体标题
	err = mw.SetTitle("iMan-打包工具   V【" + _VERSION_ + "】")
	mw.checkError(err)

	// 设置
	mw.ui.SettingMenu, _ = walk.NewMenu()
	mw.ui.SettingAction = walk.NewMenuAction(mw.ui.SettingMenu)
	mw.ui.SettingAction.SetText("设置")

	mw.ui.ServerAction = walk.NewAction()
	mw.ui.ServerAction.SetText("服务器")

	mw.ui.SettingMenu.Actions().Add(mw.ui.ServerAction)

	// 帮助
	mw.ui.HelpMenu, _ = walk.NewMenu()
	mw.ui.HelpAction = walk.NewMenuAction(mw.ui.HelpMenu)
	mw.ui.HelpAction.SetText("帮助")

	mw.ui.AboutAction = walk.NewAction()
	mw.ui.AboutAction.SetText("关于")

	mw.ui.HelpMenu.Actions().Add(mw.ui.AboutAction)

	// 菜单配置
	mw.Menu().Actions().Add(mw.ui.SettingAction)
	mw.Menu().Actions().Add(mw.ui.HelpAction)

	// 设置字体和图标
	fountTitle, _ := walk.NewFont("幼圆", 10, walk.FontBold)
	otherFont, _ := walk.NewFont("幼圆", 10, 0)

	// 开始打包
	mw.ui.StartPackingBtn, err = walk.NewPushButton(mw)
	mw.checkError(err)

	mw.ui.StartPackingBtn.SetText("开始打包")

	mw.ui.StartPackingBtn.SetBounds(walk.Rectangle{310, 20, 75, 30})

	// 版本配置
	mw.ui.VersionGb, err = walk.NewGroupBox(mw)
	mw.checkError(err)
	mw.ui.VersionGb.SetTitle("版本配置")
	mw.ui.VersionGb.SetFont(otherFont)

	err = mw.ui.VersionGb.SetBounds(walk.Rectangle{10, 60, 330, 260})
	mw.checkError(err)

	// 版本类型
	mw.ui.VersionTypeLb, err = walk.NewLabel(mw.ui.VersionGb)
	mw.checkError(err)

	mw.ui.VersionTypeLb.SetText("版本类型:")
	mw.ui.VersionTypeLb.SetFont(fountTitle)

	mw.ui.VersionTypeLb.SetBounds(walk.Rectangle{10, 20, 70, 25})

	// 测试版
	mw.ui.VersionTestRadio, err = walk.NewRadioButton(mw.ui.VersionGb)
	mw.checkError(err)

	mw.ui.VersionTestRadio.SetText("测试版")

	mw.ui.VersionTestRadio.SetBounds(walk.Rectangle{110, 20, 60, 25})
	mw.ui.VersionTestRadio.SetChecked(true)

	// 正式版
	mw.ui.VersionOffRadio, err = walk.NewRadioButton(mw.ui.VersionGb)
	mw.checkError(err)
	mw.ui.VersionOffRadio.SetText("正式版")

	mw.ui.VersionOffRadio.SetBounds(walk.Rectangle{180, 20, 70, 25})

	// 主版本号
	mw.ui.MasterVersionLb, err = walk.NewLabel(mw.ui.VersionGb)
	mw.checkError(err)

	mw.ui.MasterVersionLb.SetText("主版本号:")
	mw.ui.MasterVersionLb.SetFont(fountTitle)

	mw.ui.MasterVersionLb.SetBounds(walk.Rectangle{10, 60, 70, 25})

	// 主版本号内容
	mw.ui.MasterVersionLe, err = walk.NewLineEdit(mw.ui.VersionGb)
	mw.checkError(err)

	mw.ui.MasterVersionLe.SetBounds(walk.Rectangle{110, 60, 60, 25})

	// 生成版本号
	mw.ui.PackVersionLb, err = walk.NewLabel(mw.ui.VersionGb)
	mw.checkError(err)

	mw.ui.PackVersionLb.SetText("生成版本:")
	mw.ui.PackVersionLb.SetFont(fountTitle)

	mw.ui.PackVersionLb.SetBounds(walk.Rectangle{10, 100, 70, 25})

	// 生成版本号内容
	mw.ui.PackVersionLe, err = walk.NewLineEdit(mw.ui.VersionGb)
	mw.checkError(err)

	mw.ui.PackVersionLe.SetEnabled(false)

	mw.ui.PackVersionLe.SetBounds(walk.Rectangle{110, 100, 140, 25})

	// PC助手
	mw.ui.PcHelperLb, err = walk.NewLabel(mw.ui.VersionGb)
	mw.checkError(err)

	mw.ui.PcHelperLb.SetText("PC助手:")
	mw.ui.PcHelperLb.SetFont(fountTitle)

	mw.ui.PcHelperLb.SetBounds(walk.Rectangle{10, 140, 70, 25})

	// PC助手上传路径
	mw.ui.PcHelperLe, err = walk.NewLineEdit(mw.ui.VersionGb)
	mw.checkError(err)

	mw.ui.PcHelperLe.SetBounds(walk.Rectangle{110, 140, 150, 25})

	// PC助手上传按钮
	mw.ui.PcUploadBtn, err = walk.NewPushButton(mw.ui.VersionGb)
	mw.checkError(err)

	mw.ui.PcUploadBtn.SetText("上传")
	mw.ui.PcUploadBtn.SetBounds(walk.Rectangle{270, 140, 50, 25})

	// Android助手
	mw.ui.AndroidHelperLb, err = walk.NewLabel(mw.ui.VersionGb)
	mw.checkError(err)

	mw.ui.AndroidHelperLb.SetText("Android助手:")
	mw.ui.AndroidHelperLb.SetFont(fountTitle)

	mw.ui.AndroidHelperLb.SetBounds(walk.Rectangle{10, 180, 100, 25})

	// Android助手上传路径
	mw.ui.AndroidHelperLe, err = walk.NewLineEdit(mw.ui.VersionGb)
	mw.checkError(err)

	mw.ui.AndroidHelperLe.SetBounds(walk.Rectangle{110, 180, 150, 25})

	// Android助手上传按钮
	mw.ui.AndUploadBtn, err = walk.NewPushButton(mw.ui.VersionGb)
	mw.checkError(err)

	mw.ui.AndUploadBtn.SetText("上传")

	mw.ui.AndUploadBtn.SetBounds(walk.Rectangle{270, 180, 50, 25})

	// Web 数据库
	mw.ui.WebSqlLb, err = walk.NewLabel(mw.ui.VersionGb)
	mw.checkError(err)

	mw.ui.WebSqlLb.SetText("Web 数据库:")
	mw.ui.WebSqlLb.SetFont(fountTitle)

	mw.ui.WebSqlLb.SetBounds(walk.Rectangle{10, 220, 90, 25})

	// Web 数据库上传路径
	mw.ui.WebSqlLe, err = walk.NewLineEdit(mw.ui.VersionGb)
	mw.checkError(err)

	mw.ui.WebSqlLe.SetBounds(walk.Rectangle{110, 220, 150, 25})

	// Web 数据库上传按钮
	mw.ui.WebSqlBtn, err = walk.NewPushButton(mw.ui.VersionGb)
	mw.checkError(err)

	mw.ui.WebSqlBtn.SetText("上传")

	mw.ui.WebSqlBtn.SetBounds(walk.Rectangle{270, 220, 50, 25})

	// 打包内容配置
	mw.ui.PackGb, err = walk.NewGroupBox(mw)
	mw.checkError(err)

	mw.ui.PackGb.SetTitle("打包内容配置")
	mw.ui.PackGb.SetFont(otherFont)

	mw.ui.PackGb.SetBounds(walk.Rectangle{355, 60, 335, 260})

	// 全选
	mw.ui.CheckAllLb, err = walk.NewLabel(mw.ui.PackGb)
	mw.checkError(err)

	mw.ui.CheckAllLb.SetText("全选:")
	mw.ui.CheckAllLb.SetFont(fountTitle)

	mw.ui.CheckAllLb.SetBounds(walk.Rectangle{10, 20, 55, 25})

	// 全选框
	mw.ui.CheckAllCb, err = walk.NewCheckBox(mw.ui.PackGb)
	mw.checkError(err)
	mw.ui.CheckAllCb.SetVisible(true)

	mw.ui.CheckAllCb.SetBounds(walk.Rectangle{80, 20, 70, 25})

	// 服务器
	mw.ui.ServerLb, err = walk.NewLabel(mw.ui.PackGb)
	mw.checkError(err)

	mw.ui.ServerLb.SetText("服务器:")
	mw.ui.ServerLb.SetFont(fountTitle)

	mw.ui.ServerLb.SetBounds(walk.Rectangle{10, 50, 55, 25})

	// Java Web复选框
	mw.ui.JavaWebCb, err = walk.NewCheckBox(mw.ui.PackGb)
	mw.checkError(err)

	mw.ui.JavaWebCb.SetText("Java Web")

	mw.ui.JavaWebCb.SetBounds(walk.Rectangle{80, 50, 80, 25})

	// Web 数据库复选框
	mw.ui.WebSqlCb, err = walk.NewCheckBox(mw.ui.PackGb)
	mw.checkError(err)

	mw.ui.WebSqlCb.SetText("Web 数据库")

	mw.ui.WebSqlCb.SetBounds(walk.Rectangle{170, 50, 90, 25})

	// PC助手
	mw.ui.PcHelperCb, err = walk.NewCheckBox(mw.ui.PackGb)
	mw.checkError(err)

	mw.ui.PcHelperCb.SetText("PC助手")

	mw.ui.PcHelperCb.SetBounds(walk.Rectangle{80, 90, 60, 25})

	// Android助手
	mw.ui.AndroidHelperCb, err = walk.NewCheckBox(mw.ui.PackGb)
	mw.checkError(err)

	mw.ui.AndroidHelperCb.SetText("Android助手")

	mw.ui.AndroidHelperCb.SetBounds(walk.Rectangle{170, 90, 90, 25})

	// 控制器
	mw.ui.ControlLb, err = walk.NewLabel(mw.ui.PackGb)
	mw.checkError(err)

	mw.ui.ControlLb.SetText("控制器:")
	mw.ui.ControlLb.SetFont(fountTitle)

	mw.ui.ControlLb.SetBounds(walk.Rectangle{10, 130, 55, 25})

	// Linux knl
	mw.ui.LinuxKnlCb, err = walk.NewCheckBox(mw.ui.PackGb)
	mw.checkError(err)

	mw.ui.LinuxKnlCb.SetText("Linux Knl")

	mw.ui.LinuxKnlCb.SetBounds(walk.Rectangle{80, 130, 80, 25})

	// Linux App
	mw.ui.LinuxAppCb, err = walk.NewCheckBox(mw.ui.PackGb)
	mw.checkError(err)

	mw.ui.LinuxAppCb.SetText("Linux App")

	mw.ui.LinuxAppCb.SetBounds(walk.Rectangle{170, 130, 80, 25})

	// Linux Ruby
	mw.ui.LinuxRubyCb, err = walk.NewCheckBox(mw.ui.PackGb)
	mw.checkError(err)

	mw.ui.LinuxRubyCb.SetText("Linux Ruby")

	mw.ui.LinuxRubyCb.SetBounds(walk.Rectangle{80, 170, 90, 25})

	// 打包日志
	mw.ui.PackLogLb, err = walk.NewLabel(mw)
	mw.checkError(err)

	mw.ui.PackLogLb.SetText("打包日志")
	mw.ui.PackLogLb.SetFont(fountTitle)

	mw.ui.PackLogLb.SetBounds(walk.Rectangle{20, 330, 60, 20})

	// 日志输出
	mw.ui.lv, err = NewLogView(mw)
	mw.checkError(err)

	err = mw.ui.lv.SetBounds(walk.Rectangle{10, 360, 680, 190})
	mw.checkError(err)

	log.SetOutput(mw.ui.lv)

	// img, _ = walk.NewIconFromResourceId(7)
	// mw.ui.browseBtn.SetImage(img)
	// mw.ui.browseBtn.SetImageAboveText(false)
	// mw.ui.browseBtn.SetBackground(bg)

	// reader, _ := os.Open("../../img/folder_add.png")
	// add, _, _ := image.Decode(reader)
	// var img walk.Image
	// img, _ = walk.NewBitmapFromImage(add)

	// mw.ui.browseBtn.SetImage(img)

	// img, _ = walk.NewImageFromFile("../../img/arrow_divide.png")
	// mw.ui.uploadBtn.SetImage(img)

	succeeded = true

	return nil
}
Exemplo n.º 17
0
func runNotify() {
	// 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, err := walk.NewMainWindow()
	if err != nil {
		log.Fatal(err)
	}

	// We load our icon from a file.
	iconPlay, err = walk.NewIconFromFile("play.ico")
	if err != nil {
		log.Fatal(err)
	}

	// We load our icon from a file.
	iconStop, err = walk.NewIconFromFile("stop.ico")
	if err != nil {
		log.Fatal(err)
	}

	// Create the notify icon and make sure we clean it up on exit.
	notifyIcon, err = walk.NewNotifyIcon()
	if err != nil {
		log.Fatal(err)
	}
	defer notifyIcon.Dispose()

	if err := notifyIcon.SetToolTip("Direct Print Server"); err != nil {
		log.Fatal(err)
	}

	// We put an exit action into the context menu.
	startAction = walk.NewAction()
	startAction.Triggered().Attach(func() {
		if stoped {
			start()
		} else {
			stop()
		}
	})
	if err := notifyIcon.ContextMenu().Actions().Add(startAction); err != nil {
		log.Fatal(err)
	}

	// We put an exit action into the context menu.
	exitAction := walk.NewAction()
	if err := exitAction.SetText("E&xit"); err != nil {
		log.Fatal(err)
	}
	exitAction.Triggered().Attach(func() {
		//stop()
		walk.App().Exit(0)
	})
	if err := notifyIcon.ContextMenu().Actions().Add(exitAction); err != nil {
		log.Fatal(err)
	}

	// The notify icon is hidden initially, so we have to make it visible.
	if err := notifyIcon.SetVisible(true); err != nil {
		log.Fatal(err)
	}

	start()
	// Run the message loop.
	mw.Run()
}
Exemplo n.º 18
0
func InterfaceStart(server ZakupkiProxyServer,
	config ServerConfig) (err error) {

	if server == nil {
		panic("InterfaceStart: passed nil server")
	}
	if config == nil {
		panic("InterfaceStart: passed nil config")
	}

	/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
	 *                        INITIALIZATION                       *
	 * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */

	startServer := func() {
		if !server.IsRunning() {
			go func() {
				// start server
				if err := server.Start(); err != nil {
					log.Println("Cannot start server:", err)
				}
			}()
			time.Sleep(_START_SERVER_TIMEOUT)
		}
	}
	stopServer := func() {
		if server.IsRunning() {
			// shutdown server
			if err = server.ShutDown(); err != nil {
				log.Println("Cannot shutdown server", err)
			}
		}
	}
	if _RUN_SERVER_ON_STARTING && !server.IsRunning() {
		startServer()
	}
	defer func() {
		if server.IsRunning() {
			stopServer()
		}
	}()
	defer func() {
		if err = config.Save(); err != nil {
			log.Println("Cannot save configures:", err)
		}
	}()

	/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
	 *                      END INITIALIZATION                     *
	 * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */

	mw, err := walk.NewMainWindow()
	if err != nil {
		return
	}
	defer mw.Dispose()
	ni, err := walk.NewNotifyIcon()
	if err != nil {
		return
	}
	defer ni.Dispose()
	if err = ni.SetVisible(true); err != nil {
		return
	}
	if err = ni.SetToolTip(_PROG_TITLE); err != nil {
		return
	}
	ni.ShowMessage(_PROG_TITLE, _NOTICE_APP_START)
	// create image icon
	if icon, err :=
		walk.NewIconFromFile(_PROG_ICON_FILE_NAME); err != nil {
		log.Println("Cannot load icon from file:", err)
	} else {
		defer icon.Dispose()
		if err = ni.SetIcon(icon); err != nil {
			log.Println("Cannot bind img with notify icon:", err)
		}
	}

	/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
	 *                            ACTIONS                          *
	 * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */

	startServerAction := walk.NewAction()
	err = startServerAction.SetText(_ACTION_TITLE_START_SERVER)
	if err != nil {
		return
	}
	err = startServerAction.SetVisible(!server.IsRunning())
	if err != nil {
		return
	}
	err = ni.ContextMenu().Actions().Add(startServerAction)
	if err != nil {
		return
	}

	stopServerAction := walk.NewAction()
	err = stopServerAction.SetText(_ACTION_TITLE_STOP_SERVER)
	if err != nil {
		return
	}
	err = stopServerAction.SetVisible(server.IsRunning())
	if err != nil {
		return
	}
	err = ni.ContextMenu().Actions().Add(stopServerAction)
	if err != nil {
		return
	}

	filterEnableAction := walk.NewAction()
	err = filterEnableAction.SetText(_ACTION_TITLE_FILTER_ENABLED)
	if err != nil {
		return
	}
	err = filterEnableAction.SetVisible(!config.IsFilterEnabled())
	if err != nil {
		return
	}
	err = ni.ContextMenu().Actions().Add(filterEnableAction)
	if err != nil {
		return
	}

	filterDisabledAction := walk.NewAction()
	err = filterDisabledAction.SetText(_ACTION_TITLE_FILTER_DISABLED)
	if err != nil {
		return
	}
	err = filterDisabledAction.SetVisible(config.IsFilterEnabled())
	if err != nil {
		return
	}
	err = ni.ContextMenu().Actions().Add(filterDisabledAction)
	if err != nil {
		return
	}

	removeCacheAction := walk.NewAction()
	err = removeCacheAction.SetText(_ACTION_TITLE_REMOVE_CACHE)
	if err != nil {
		return
	}
	err = ni.ContextMenu().Actions().Add(removeCacheAction)
	if err != nil {
		return
	}

	err = ni.ContextMenu().Actions().Add(walk.NewSeparatorAction())
	if err != nil {
		return
	}

	openURLGenAction := walk.NewAction()
	err = openURLGenAction.SetText(_ACTION_TITLE_OPEN_URL_GEN)
	if err != nil {
		return
	}
	err = ni.ContextMenu().Actions().Add(openURLGenAction)
	if err != nil {
		return
	}

	openDirAction := walk.NewAction()
	err = openDirAction.SetText(_ACTION_TITLE_OPEN_DIR)
	if err != nil {
		return
	}
	err = ni.ContextMenu().Actions().Add(openDirAction)
	if err != nil {
		return
	}

	openReadMeAction := walk.NewAction()
	err = openReadMeAction.SetText(_ACTION_TITLE_OPEN_README)
	if err != nil {
		return
	}
	err = ni.ContextMenu().Actions().Add(openReadMeAction)
	if err != nil {
		return
	}

	err = ni.ContextMenu().Actions().Add(walk.NewSeparatorAction())
	if err != nil {
		return
	}

	exitAction := walk.NewAction()
	err = exitAction.SetText(_ACTION_TITLE_EXIT)
	if err != nil {
		return
	}
	err = ni.ContextMenu().Actions().Add(exitAction)
	if err != nil {
		return
	}

	/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
	 *                        EVENT HANDLERS                       *
	 * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */

	updateServerButtons := func() {
		if server.IsRunning() {
			if err = startServerAction.SetVisible(false); err != nil {
				log.Println(err)
			}
			if err = stopServerAction.SetVisible(true); err != nil {
				log.Println(err)
			}
		} else {
			if err = stopServerAction.SetVisible(false); err != nil {
				log.Println(err)
			}
			if err = startServerAction.SetVisible(true); err != nil {
				log.Println(err)
			}
		}
	}

	startServerAction.Triggered().Attach(func() {
		if !server.IsRunning() {
			if err = startServerAction.SetEnabled(false); err != nil {
				log.Println(err)
			}
			startServer()
			if server.IsRunning() {
				ni.ShowMessage(_PROG_TITLE, _NOTICE_PROXY_ENABLED)
			}
			if err = startServerAction.SetEnabled(true); err != nil {
				log.Println(err)
			}
		}
		updateServerButtons()
	})

	stopServerAction.Triggered().Attach(func() {
		if server.IsRunning() {
			stopServer()
			ni.ShowMessage(_PROG_TITLE, _NOTICE_PROXY_DISABLED)
		}
		updateServerButtons()
	})

	updateFilterButtons := func() {
		if config.IsFilterEnabled() {
			err = filterEnableAction.SetVisible(false)
			if err != nil {
				log.Println(err)
			}
			err = filterDisabledAction.SetVisible(true)
			if err != nil {
				log.Println(err)
			}
		} else {
			err = filterDisabledAction.SetVisible(false)
			if err != nil {
				log.Println(err)
			}
			err = filterEnableAction.SetVisible(true)
			if err != nil {
				log.Println(err)
			}
		}
	}

	filterEnableAction.Triggered().Attach(func() {
		if !config.IsFilterEnabled() {
			config.SetFilterEnabled(true)
			ni.ShowInfo(_PROG_TITLE, _NOTICE_ENABLED_FILTERS)
		}
		updateFilterButtons()
	})

	filterDisabledAction.Triggered().Attach(func() {
		if config.IsFilterEnabled() {
			config.SetFilterEnabled(false)
			ni.ShowInfo(_PROG_TITLE, _NOTICE_DISABLED_FILTERS)
		}
		updateFilterButtons()
	})

	removeCacheAction.Triggered().Attach(func() {
		if err = server.RemoveCache(); err != nil {
			log.Println("Cannot remove cache:", err)
		} else {
			ni.ShowInfo(_PROG_TITLE, _NOTICE_CACHE_REMOVED)
		}
	})

	openURLGenAction.Triggered().Attach(func() {
		err = exec.Command(_PROG_URL_GENER_FILE_NAME).Start()
		if err != nil {
			log.Println("Cannot open url generator:", err)
		}
	})

	openDirAction.Triggered().Attach(func() {
		err = exec.Command("cmd", "/C", "start", ".").Start()
		if err != nil {
			log.Println("Cannot open program directory:", err)
		} else {
			ni.ShowInfo(_PROG_TITLE, _NOTICE_CONFIGS)
		}
	})

	openReadMeAction.Triggered().Attach(func() {
		err = exec.Command(
			"cmd", "/C", "start", _PROG_DESCRIPTION_FILE_NAME,
		).Start()
		if err != nil {
			log.Println("Cannot open README:", err)
		}
	})

	exitAction.Triggered().Attach(func() {
		walk.App().Exit(0)
	})

	/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
	 *                       END EVENT HANDLERS                    *
	 * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */

	mw.Run()

	return
}
Exemplo n.º 19
0
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()
}
Exemplo n.º 20
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()
}
Exemplo n.º 21
0
func main() {
	xcgui.XWnd_Create(0, 0, 0, 0, "炫彩界面库窗口", 0, xcgui.XC_WINDOW_STYLE_NOTHING)

	// We load our icon from a file.
	icon, err := walk.NewIconFromFile("../../img/x.ico")
	if err != nil {
		log.Fatal(err)
	}

	// Create the notify icon and make sure we clean it up on exit.
	ni, err := walk.NewNotifyIcon()
	if err != nil {
		log.Fatal(err)
	}
	defer ni.Dispose()

	// Set the icon and a tool tip text.
	if err := ni.SetIcon(icon); err != nil {
		log.Fatal(err)
	}
	if err := ni.SetToolTip("托盘"); err != nil {
		log.Fatal(err)
	}

	// 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
		}

		if err := ni.ShowCustom(
			"自定义消息",
			"这是一个带图标的自定义消息."); err != nil {
			log.Fatal(err)
		}
	})

	// 菜单使用walk的,主程序为xcgui.
	exitAction := walk.NewAction()
	if err := exitAction.SetText("退出"); err != nil {
		log.Fatal(err)
	}
	exitAction.Triggered().Attach(func() {
		ni.Dispose()
		walk.App().Exit(0)
		xcgui.XExitXCGUI()
	})

	if err := ni.ContextMenu().Actions().Add(exitAction); err != nil {
		log.Fatal(err)
	}

	// 托盘图标默认为隐藏状态,需设置为显示。
	if err := ni.SetVisible(true); err != nil {
		log.Fatal(err)
	}

	// Now that the icon is visible, we can bring up an info balloon.
	if err := ni.ShowInfo("托盘", "正在运行中."); err != nil {
		log.Fatal(err)
	}

	// Run the message loop.
	xcgui.XRunXCGUI()
}
Exemplo n.º 22
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()
}
Exemplo n.º 23
0
func (mw *MainWindow) initPoseInfo() {
	if modelItem == nil {
		return
	}

	model := modelItem.img
	if model == nil {
		return
	}
	// Get the pose count
	poseCnt := 1
	x := model.Bounds().Min.X
	y := model.Bounds().Min.Y
	w := model.Bounds().Dx()
	h := model.Bounds().Dy()
	for i := 2; i < POSE_CNT_MAX; i++ {
		sh := h / i
		for j := 1; j < i; j++ {
			beginY := sh * j
			// Erase the boundary by 1 pix to handel the neighbor pix
			for z := 1; z < w-1; z++ {
				_, _, _, a := model.At(x+z, y+beginY).RGBA()
				if a != 0 {
					_, _, _, la := model.At(x+z-1, y+beginY).RGBA()
					_, _, _, ra := model.At(x+z+1, y+beginY).RGBA()
					_, _, _, ta := model.At(x+z, y+beginY-1).RGBA()
					_, _, _, da := model.At(x+z, y+beginY+1).RGBA()
					if la != 0 && ra != 0 && ta != 0 && da != 0 {
						fmt.Println("Pose alpha:", x+z, y+beginY, a)
						goto nextPose
					}
				}
			}
		}
		poseCnt = i
		break

	nextPose:
	}

	fmt.Println("Pose count: ", poseCnt)

	// Init the pose list
	imageW = w / int(mw.uiFrameCnt.Value())
	imageH = h / poseCnt

	mw.resetImageList()
	boundary = image.Rect(0, 0, imageW, imageH)
	tmpBound := boundary
	// Read all png images
	for i := 0; i < poseCnt; i++ {
		for j := 0; j < int(mw.uiFrameCnt.Value()); j++ {
			deltaX := imageW * j
			deltaY := imageH * i
			tmpBound = boundary.Add(image.Point{deltaX, deltaY})

			newImg := new(ImageItem)
			newImg.fname = ""
			newImg.img = modelItem.img.SubImage(tmpBound).(ImageExt)
			newImg.bm, _ = walk.NewBitmapFromImage(newImg.img)

			imgList = append(imgList, newImg)
		}
	}

}

/*
func (mw *MainWindow) onUiSetFrameCnt() {
	if modelItem == nil {
		return
	}

	// imageW = modelItem.img.Bounds().Dx()
	// imageH = modelItem.img.Bounds().Dy()

	// poseCnt := mw.getPoseCnt()
	playPose = int(mw.uiPlayPose.Value())
	mw.setImageSize()
}*/

func (mw *MainWindow) refreshToolBar(mode int) {
	mw.uiConvirm.SetEnabled(false)
	mw.uiComposeAction.SetEnabled(false)
	mw.uiPoseCnt.SetEnabled(false)

	mw.mode = mode
	mw.uiFrameCnt.SetEnabled(false)
	if mw.mode == MODE_INVALID {
		return
	}

	if mw.mode == MODE_PLAY {
		return
	}
	if mw.mode == MODE_COMPOSE {
		mw.uiFrameCnt.SetEnabled(true)
		mw.uiComposeAction.SetEnabled(true)
	}
}

func (mw *MainWindow) getPoseInfo() (int, int) {
	totalFrame := len(imgList)
	poseCnt := mw.getPoseCnt()

	if poseCnt >= totalFrame {
		return 1, totalFrame
	}
	if totalFrame%poseCnt != 0 {
		return 1, totalFrame
	}
	return poseCnt, totalFrame / poseCnt
}

func (mw *MainWindow) composeImg(fullname string) {
	poseCnt, frame := mw.getPoseInfo()
	if frame == 0 {
		return
	}

	sw := boundary.Dx()
	sh := boundary.Dy() + yBoundAdd

	//var rgba bool
	_newBound := image.Rect(0, 0, sw*frame, sh*poseCnt)
	// No need to check the source image type.
	var result draw.Image
	firstImg := imgList[0].img
	switch firstImg.(type) {
	case *image.RGBA:
		result = image.NewRGBA(_newBound)
	case *image.RGBA64:
		result = image.NewRGBA64(_newBound)
	case *image.NRGBA:
		result = image.NewNRGBA(_newBound)
	case *image.NRGBA64:
		result = image.NewNRGBA64(_newBound)
	default:
		fmt.Println("image type: ", reflect.TypeOf(firstImg))
		println("Unsupported image type")
		return
	}
	// Compress to RGBA32, Stride
	// result := image.NewRGBA(_newBound)
	// result.Stride = result.Bounds().Dx()

	singleBound := image.Rect(0, 0, sw, sh)
	for i, _img := range imgList {
		_subImg := _img.img.SubImage(boundary)
		col := i % frame
		row := i / frame
		drawBound := singleBound.Add(image.Point{sw * col, sh * row})
		draw.Draw(result, drawBound, _subImg, _subImg.Bounds().Min, draw.Src)
	}
	// Modify stride
	// fmt.Println("Stride ", result.Stride)

	f, err := os.OpenFile(fullname, os.O_RDWR|os.O_CREATE, os.ModePerm)
	if err != nil {
		panic(err)
		return
	}
	defer f.Close()

	f.Truncate(0)
	// buf := bufio.NewWriterSize(f, 1024 * 1000)
	buf := bufio.NewWriter(f)
	png.Encode(buf, result)
}

func setIcon(ui *walk.Action, fname string) {
	fpath := "./img/" + fname
	_, err := os.Stat(fpath)
	if err != nil {
		fmt.Println(err)
		return
	}
	img, _ := walk.NewBitmapFromFile(fpath)
	ui.SetImage(img)
}

func (mw *MainWindow) initMenu() {
	fileMenu, _ := walk.NewMenu()
	fileMenuAction, _ := mw.Menu().Actions().AddMenu(fileMenu)
	fileMenuAction.SetText("&File")

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

	openAction := walk.NewAction()
	setIcon(openAction, "open.png")
	openAction.SetText("&Open")
	openAction.Triggered().Attach(func() { go mw.openImage(MODE_COMPOSE) })
	fileMenu.Actions().Add(openAction)
	mw.ToolBar().Actions().Add(openAction)

	///
	// Load
	loadAction := walk.NewAction()
	setIcon(loadAction, "load.png")
	loadAction.SetText("&Load")
	loadAction.Triggered().Attach(func() { mw.openImage(MODE_PLAY) })
	fileMenu.Actions().Add(loadAction)
	mw.ToolBar().Actions().Add(loadAction)

	helpMenu, _ := walk.NewMenu()
	helpMenuAction, _ := mw.Menu().Actions().AddMenu(helpMenu)
	helpMenuAction.SetText("&Help")

	aboutAction := walk.NewAction()
	helpMenu.Actions().Add(aboutAction)
	aboutAction.SetText("&About")
	aboutAction.Triggered().Attach(func() {
		walk.MsgBox(mw, "About", "Image composer V0.1\nAuthor:heml",
			walk.MsgBoxOK|walk.MsgBoxIconInformation)
	})

	// Image operations
	// Save
	mw.uiComposeAction = walk.NewAction()
	setIcon(mw.uiComposeAction, "save.png")
	mw.uiComposeAction.SetText("&Save")
	mw.uiComposeAction.Triggered().Attach(func() { mw.saveImage() })
	fileMenu.Actions().Add(mw.uiComposeAction)
	mw.ToolBar().Actions().Add(mw.uiComposeAction)

	// Exit
	exitAction := walk.NewAction()
	exitAction.SetText("E&xit")
	exitAction.Triggered().Attach(func() { walk.App().Exit(0) })
	fileMenu.Actions().Add(exitAction)
}

func (mw *MainWindow) initCanvas() {
	for i := 0; i < POSE_CNT_MAX; i++ {
		iv, _ := selfWidget.NewMyImageView(mw)
		mw.imageView[i] = iv
	}
}
func (mw *MainWindow) initOtherBars() {
	sp, _ := walk.NewSplitter(mw)
	sp.SetSize(walk.Size{400, 20})

	lab, _ := walk.NewLabel(sp)
	lab.SetSize(walk.Size{16, 30})
	// lab.SetText("Pose")

	// others
	mw.uiFrameCnt, _ = walk.NewNumberEdit(sp)
	//mw.uiFrameCnt.SetSize(walk.Size{42, TB_H})
	mw.uiFrameCnt.SetRange(1, 100)
	mw.uiFrameCnt.SetDecimals(0)
	mw.uiFrameCnt.SetValue(8)
	mw.uiFrameCnt.SetEnabled(false)
	mw.uiFrameCnt.SetToolTipText(ttPlayPose)

	mw.uiPoseCnt, _ = walk.NewNumberEdit(sp)
	//mw.uiPoseCnt.SetSize(walk.Size{42, TB_H})
	mw.uiPoseCnt.SetRange(1, 100)
	mw.uiPoseCnt.SetValue(1)
	mw.uiPoseCnt.SetDecimals(0)
	mw.uiPoseCnt.SetToolTipText(ttPosCnt)

	mw.uiAddBoundY, _ = walk.NewNumberEdit(sp)
	mw.uiAddBoundY.SetRange(1, 1000)
	mw.uiAddBoundY.SetValue(0)
	mw.uiAddBoundY.SetDecimals(0)
	mw.uiAddBoundY.ValueChanged().Attach(func() {
		yBoundAdd = int(mw.uiAddBoundY.Value())
		if yBoundAdd < -imageH {
			yBoundAdd = -imageH
		}
		if yBoundAdd > (imageH - boundary.Max.Y) {
			yBoundAdd = imageH - boundary.Max.Y
		}
		mw.uiAddBoundY.SetValue(float64(yBoundAdd))
		mw.setImageSize()
	})

	mw.uiConvirm, _ = walk.NewPushButton(sp)
	mw.uiConvirm.SetText("OK")
	mw.uiConvirm.Clicked().Attach(func() {
		// Get some fresh data.
		// mw.onUiSetFrameCnt()
	})

	walk.InitWidget(sp, mw, FREEZEIZE_CLASS,
		winapi.CCS_NORESIZE,
		winapi.WS_EX_TOOLWINDOW|winapi.WS_EX_WINDOWEDGE)
}

func newMainWindow() {
	walk.SetPanicOnError(true)
	mainWnd, _ := walk.NewMainWindow()

	mw := &MainWindow{MainWindow: mainWnd}
	mw.viewGrid = walk.NewGridLayout()
	mw.SetLayout(mw.viewGrid)
	mw.viewGrid.SetRowStretchFactor(GRID_CNT, 2)
	mw.viewGrid.SetColumnStretchFactor(GRID_CNT, 2)
	mw.viewGrid.SetMargins(walk.Margins{6, 28, 2, 6})

	mw.SetTitle("Image composer")

	mw.initMenu()
	mw.initOtherBars()
	mw.initCanvas()

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

	mw.refreshToolBar(MODE_INVALID)
	mw.Show()
	mw.Run()
}

func init() {
	walk.MustRegisterWindowClass(FREEZEIZE_CLASS)
	runtime.GOMAXPROCS(2)

	screenW = int(winapi.GetSystemMetrics(winapi.SM_CXSCREEN))
	screenH = int(winapi.GetSystemMetrics(winapi.SM_CYSCREEN))
}

func main() {
	newMainWindow()
}
Exemplo n.º 24
0
func (mw *MyWindow) init() (err error) {
	// 设置最小化
	mw.SetMinimizeBox(true)
	// 禁用最大化
	mw.SetMaximizeBox(false)
	// 设置窗口固定
	mw.SetFixedSize(true)
	// // 设置窗口前置
	// mw.SetWindowPos(true)

	mw.MainWindow, err = walk.NewMainWindow()
	mw.checkError(err)

	succeeded := false
	defer func() {
		if !succeeded {
			mw.Dispose()
		}
	}()

	// 设置主窗体大小
	err = mw.SetClientSize(walk.Size{700, 560})
	mw.checkError(err)

	// 设置主窗体标题
	err = mw.SetTitle("iMan-打包工具   V【" + _VERSION_ + "】")
	mw.checkError(err)

	// 设置
	mw.ui.SettingMenu, _ = walk.NewMenu()
	mw.ui.SettingAction = walk.NewMenuAction(mw.ui.SettingMenu)
	mw.ui.SettingAction.SetText("设置")

	mw.ui.ServerAction = walk.NewAction()
	mw.ui.ServerAction.SetText("服务器")

	mw.ui.SettingMenu.Actions().Add(mw.ui.ServerAction)

	// 帮助
	mw.ui.HelpMenu, _ = walk.NewMenu()
	mw.ui.HelpAction = walk.NewMenuAction(mw.ui.HelpMenu)
	mw.ui.HelpAction.SetText("帮助")

	mw.ui.AboutAction = walk.NewAction()
	mw.ui.AboutAction.SetText("关于")

	mw.ui.HelpMenu.Actions().Add(mw.ui.AboutAction)

	// 菜单配置
	mw.Menu().Actions().Add(mw.ui.SettingAction)
	mw.Menu().Actions().Add(mw.ui.HelpAction)

	// 设置字体和图标
	fountTitle, _ := walk.NewFont("幼圆", 10, walk.FontBold)
	otherFont, _ := walk.NewFont("幼圆", 10, 0)

	// 编译服务器IP
	mw.ui.BuildServerLb, err = walk.NewLabel(mw)
	mw.checkError(err)

	mw.ui.BuildServerLb.SetText("编译服务器IP: " + ConfSer.Ip)
	mw.ui.BuildServerLb.SetFont(otherFont)

	mw.ui.BuildServerLb.SetBounds(walk.Rectangle{480, 10, 220, 20})

	// 开始打包
	mw.ui.StartPackingBtn, err = walk.NewPushButton(mw)
	mw.checkError(err)

	mw.ui.StartPackingBtn.SetText("开始打包")

	mw.ui.StartPackingBtn.SetBounds(walk.Rectangle{310, 20, 75, 30})

	// 版本配置
	mw.ui.VersionGb, err = walk.NewGroupBox(mw)
	mw.checkError(err)
	mw.ui.VersionGb.SetTitle("版本配置")
	mw.ui.VersionGb.SetFont(otherFont)

	err = mw.ui.VersionGb.SetBounds(walk.Rectangle{10, 60, 330, 260})
	mw.checkError(err)

	// 版本类型
	mw.ui.VersionTypeLb, err = walk.NewLabel(mw.ui.VersionGb)
	mw.checkError(err)

	mw.ui.VersionTypeLb.SetText("版本类型:")
	mw.ui.VersionTypeLb.SetFont(fountTitle)

	mw.ui.VersionTypeLb.SetBounds(walk.Rectangle{10, 20, 70, 25})

	// 测试版
	mw.ui.VersionTestRadio, err = walk.NewRadioButton(mw.ui.VersionGb)
	mw.checkError(err)

	mw.ui.VersionTestRadio.SetText("测试版")

	mw.ui.VersionTestRadio.SetBounds(walk.Rectangle{110, 20, 60, 25})
	mw.ui.VersionTestRadio.SetChecked(true)

	// 正式版
	mw.ui.VersionOffRadio, err = walk.NewRadioButton(mw.ui.VersionGb)
	mw.checkError(err)
	mw.ui.VersionOffRadio.SetText("正式版")

	mw.ui.VersionOffRadio.SetBounds(walk.Rectangle{180, 20, 70, 25})

	// 主版本号
	mw.ui.MasterVersionLb, err = walk.NewLabel(mw.ui.VersionGb)
	mw.checkError(err)

	mw.ui.MasterVersionLb.SetText("主版本号:")
	mw.ui.MasterVersionLb.SetFont(fountTitle)

	mw.ui.MasterVersionLb.SetBounds(walk.Rectangle{10, 60, 70, 25})

	// 主版本号内容
	mw.ui.MasterVersionLe, err = walk.NewLineEdit(mw.ui.VersionGb)
	mw.checkError(err)

	mw.ui.MasterVersionLe.SetBounds(walk.Rectangle{110, 60, 60, 25})

	// 生成版本号
	mw.ui.PackVersionLb, err = walk.NewLabel(mw.ui.VersionGb)
	mw.checkError(err)

	mw.ui.PackVersionLb.SetText("生成版本:")
	mw.ui.PackVersionLb.SetFont(fountTitle)

	mw.ui.PackVersionLb.SetBounds(walk.Rectangle{10, 100, 70, 25})

	// 生成版本号内容
	mw.ui.PackVersionLe, err = walk.NewLineEdit(mw.ui.VersionGb)
	mw.checkError(err)

	mw.ui.PackVersionLe.SetEnabled(false)

	mw.ui.PackVersionLe.SetBounds(walk.Rectangle{110, 100, 140, 25})

	// PC助手
	mw.ui.PcHelperLb, err = walk.NewLabel(mw.ui.VersionGb)
	mw.checkError(err)

	mw.ui.PcHelperLb.SetText("PC助手:")
	mw.ui.PcHelperLb.SetFont(fountTitle)

	mw.ui.PcHelperLb.SetBounds(walk.Rectangle{10, 140, 70, 25})

	// PC助手上传路径
	mw.ui.PcHelperLe, err = walk.NewLineEdit(mw.ui.VersionGb)
	mw.checkError(err)

	mw.ui.PcHelperLe.SetBounds(walk.Rectangle{110, 140, 150, 25})

	// PC助手上传按钮
	mw.ui.PcUploadBtn, err = walk.NewPushButton(mw.ui.VersionGb)
	mw.checkError(err)

	mw.ui.PcUploadBtn.SetText("上传")
	mw.ui.PcUploadBtn.SetBounds(walk.Rectangle{270, 140, 50, 25})

	// Android助手
	mw.ui.AndroidHelperLb, err = walk.NewLabel(mw.ui.VersionGb)
	mw.checkError(err)

	mw.ui.AndroidHelperLb.SetText("Android助手:")
	mw.ui.AndroidHelperLb.SetFont(fountTitle)

	mw.ui.AndroidHelperLb.SetBounds(walk.Rectangle{10, 180, 100, 25})

	// Android助手上传路径
	mw.ui.AndroidHelperLe, err = walk.NewLineEdit(mw.ui.VersionGb)
	mw.checkError(err)

	mw.ui.AndroidHelperLe.SetBounds(walk.Rectangle{110, 180, 150, 25})

	// Android助手上传按钮
	mw.ui.AndUploadBtn, err = walk.NewPushButton(mw.ui.VersionGb)
	mw.checkError(err)

	mw.ui.AndUploadBtn.SetText("上传")

	mw.ui.AndUploadBtn.SetBounds(walk.Rectangle{270, 180, 50, 25})

	// Web 数据库
	mw.ui.WebSqlLb, err = walk.NewLabel(mw.ui.VersionGb)
	mw.checkError(err)

	mw.ui.WebSqlLb.SetText("Web 数据库:")
	mw.ui.WebSqlLb.SetFont(fountTitle)

	mw.ui.WebSqlLb.SetBounds(walk.Rectangle{10, 220, 90, 25})

	// Web 数据库上传路径
	mw.ui.WebSqlLe, err = walk.NewLineEdit(mw.ui.VersionGb)
	mw.checkError(err)

	mw.ui.WebSqlLe.SetBounds(walk.Rectangle{110, 220, 150, 25})

	// Web 数据库上传按钮
	mw.ui.WebSqlBtn, err = walk.NewPushButton(mw.ui.VersionGb)
	mw.checkError(err)

	mw.ui.WebSqlBtn.SetText("上传")

	mw.ui.WebSqlBtn.SetBounds(walk.Rectangle{270, 220, 50, 25})

	// 打包内容配置
	mw.ui.PackGb, err = walk.NewGroupBox(mw)
	mw.checkError(err)

	mw.ui.PackGb.SetTitle("打包内容配置")
	mw.ui.PackGb.SetFont(otherFont)

	mw.ui.PackGb.SetBounds(walk.Rectangle{355, 60, 335, 260})

	// 全选
	mw.ui.CheckAllLb, err = walk.NewLabel(mw.ui.PackGb)
	mw.checkError(err)

	mw.ui.CheckAllLb.SetText("全选:")
	mw.ui.CheckAllLb.SetFont(fountTitle)

	mw.ui.CheckAllLb.SetBounds(walk.Rectangle{10, 20, 55, 25})

	// 全选框
	mw.ui.CheckAllCb, err = walk.NewCheckBox(mw.ui.PackGb)
	mw.checkError(err)
	mw.ui.CheckAllCb.SetVisible(true)

	mw.ui.CheckAllCb.SetBounds(walk.Rectangle{80, 20, 70, 25})

	// 服务器
	mw.ui.ServerLb, err = walk.NewLabel(mw.ui.PackGb)
	mw.checkError(err)

	mw.ui.ServerLb.SetText("服务器:")
	mw.ui.ServerLb.SetFont(fountTitle)

	mw.ui.ServerLb.SetBounds(walk.Rectangle{10, 50, 55, 25})

	// Java Web复选框
	mw.ui.JavaWebCb, err = walk.NewCheckBox(mw.ui.PackGb)
	mw.checkError(err)

	mw.ui.JavaWebCb.SetText("Java Web")

	mw.ui.JavaWebCb.SetBounds(walk.Rectangle{80, 50, 80, 25})

	// Web 数据库复选框
	mw.ui.WebSqlCb, err = walk.NewCheckBox(mw.ui.PackGb)
	mw.checkError(err)

	mw.ui.WebSqlCb.SetText("Web 数据库")

	mw.ui.WebSqlCb.SetBounds(walk.Rectangle{170, 50, 90, 25})

	// PC助手
	mw.ui.PcHelperCb, err = walk.NewCheckBox(mw.ui.PackGb)
	mw.checkError(err)

	mw.ui.PcHelperCb.SetText("PC助手")

	mw.ui.PcHelperCb.SetBounds(walk.Rectangle{80, 90, 60, 25})

	// Android助手
	mw.ui.AndroidHelperCb, err = walk.NewCheckBox(mw.ui.PackGb)
	mw.checkError(err)

	mw.ui.AndroidHelperCb.SetText("Android助手")

	mw.ui.AndroidHelperCb.SetBounds(walk.Rectangle{170, 90, 90, 25})

	// 控制器
	mw.ui.ControlLb, err = walk.NewLabel(mw.ui.PackGb)
	mw.checkError(err)

	mw.ui.ControlLb.SetText("控制器:")
	mw.ui.ControlLb.SetFont(fountTitle)

	mw.ui.ControlLb.SetBounds(walk.Rectangle{10, 130, 55, 25})

	// Linux knl
	mw.ui.LinuxKnlCb, err = walk.NewCheckBox(mw.ui.PackGb)
	mw.checkError(err)

	mw.ui.LinuxKnlCb.SetText("Linux Knl")

	mw.ui.LinuxKnlCb.SetBounds(walk.Rectangle{80, 130, 80, 25})

	// Linux App
	mw.ui.LinuxAppCb, err = walk.NewCheckBox(mw.ui.PackGb)
	mw.checkError(err)

	mw.ui.LinuxAppCb.SetText("Linux App")

	mw.ui.LinuxAppCb.SetBounds(walk.Rectangle{170, 130, 80, 25})

	// Linux Ruby
	mw.ui.LinuxRubyCb, err = walk.NewCheckBox(mw.ui.PackGb)
	mw.checkError(err)

	mw.ui.LinuxRubyCb.SetText("Linux Ruby")

	mw.ui.LinuxRubyCb.SetBounds(walk.Rectangle{80, 170, 90, 25})

	// 打包日志 TabWidget
	mw.ui.PackTabWidget, err = walk.NewTabWidget(mw)
	mw.checkError(err)
	mw.ui.PackTabWidget.SetBounds(walk.Rectangle{10, 330, 680, 200})

	// 打包日志 TabPage
	mw.ui.PackTabPage, err = walk.NewTabPage()
	mw.ui.PackTabPage.SetTitle("打包日志")

	// 历史版本记录 TabPage
	mw.ui.VersionPage, err = walk.NewTabPage()
	mw.ui.VersionPage.SetTitle("历史版本记录")

	// TabPage 添加到 TabWidget
	mw.ui.PackTabWidget.Pages().Add(mw.ui.PackTabPage)
	mw.ui.PackTabWidget.Pages().Add(mw.ui.VersionPage)

	// 打包日志 输出记录
	mw.ui.lv, err = NewLogView(mw.ui.PackTabPage)
	mw.checkError(err)
	err = mw.ui.lv.SetBounds(walk.Rectangle{-1, -1, 680, 180})
	mw.checkError(err)

	log.SetOutput(mw.ui.lv)

	// 历史版本记录 TableView
	mw.ui.VersionTableView, err = walk.NewTableView(mw.ui.VersionPage)
	mw.checkError(err)

	mw.ui.VersionTableView.SetBounds(walk.Rectangle{-1, -1, 680, 180})

	// 历史版本记录 - 序号
	mw.ui.VersionTabVieConIndex = walk.NewTableViewColumn()
	mw.ui.VersionTabVieConIndex.SetTitle("序号")
	mw.ui.VersionTabVieConIndex.SetWidth(50)

	// 历史版本记录 - 版本
	mw.ui.VersionTabVieConVer = walk.NewTableViewColumn()
	mw.ui.VersionTabVieConVer.SetTitle("版本")
	mw.ui.VersionTabVieConVer.SetWidth(100)

	// 历史版本记录 - 打包内容
	mw.ui.VersionTabVieConPack = walk.NewTableViewColumn()
	mw.ui.VersionTabVieConPack.SetTitle("打包内容")
	mw.ui.VersionTabVieConPack.SetWidth(120)

	// 历史版本记录 - 是否打Tag
	mw.ui.VersionTabVieConTag = walk.NewTableViewColumn()
	mw.ui.VersionTabVieConTag.SetTitle("Tag")
	mw.ui.VersionTabVieConTag.SetWidth(120)

	// 历史版本记录 - Tag 路径
	mw.ui.VersionTabVieConTagPath = walk.NewTableViewColumn()
	mw.ui.VersionTabVieConTagPath.SetTitle("Tag路径")
	mw.ui.VersionTabVieConTagPath.SetWidth(150)

	// 历史版本记录 - 打包时间
	mw.ui.VersionTabVieConTime = walk.NewTableViewColumn()
	mw.ui.VersionTabVieConTime.SetTitle("打包时间")
	mw.ui.VersionTabVieConTime.SetWidth(100)

	// TableViewColumn 添加到 TableView
	mw.ui.VersionTableView.Columns().Add(mw.ui.VersionTabVieConIndex)
	mw.ui.VersionTableView.Columns().Add(mw.ui.VersionTabVieConVer)
	mw.ui.VersionTableView.Columns().Add(mw.ui.VersionTabVieConPack)
	mw.ui.VersionTableView.Columns().Add(mw.ui.VersionTabVieConTag)
	mw.ui.VersionTableView.Columns().Add(mw.ui.VersionTabVieConTagPath)
	mw.ui.VersionTableView.Columns().Add(mw.ui.VersionTabVieConTime)

	// 历史版本记录数据
	mw.ui.VersionTableView.SetCheckBoxes(true)
	mw.ui.VersionTableView.SetModel(ConfVerModel)

	succeeded = true

	return nil
}
Exemplo n.º 25
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()
}
Exemplo n.º 26
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()
}
Exemplo n.º 27
-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
}
Exemplo n.º 28
-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
}