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() }
func setWindow() { // 绑定log输出界面 lv, err := NewLogView(mw) if err != nil { panic(err) } app.LogicApp.SetLog(lv) log.SetOutput(lv) // 设置左上角图标 if icon, err := walk.NewIconFromResourceId(3); err == nil { mw.SetIcon(icon) } }
func (mw *MyDialog) SetMyNotify() (err error) { // 托盘图标 icon, _ := walk.NewIconFromResourceId(3) mw.ni, err = walk.NewNotifyIcon() mw.checkError(err) mw.SetIcon(icon) // Set the icon and a tool tip text. err = mw.ni.SetIcon(icon) mw.checkError(err) return nil }
func NewMainWindow() *MyWindows { mw := new(MyWindows) mw.MainWindow, _ = walk.NewMainWindow() mw.ni, err = walk.NewNotifyIcon() checkErr(err) icon, _ := walk.NewIconFromResourceId(3) mw.setVipIcon(icon) mw.addAction() mw.ni.SetVisible(true) return mw }
func (mw *MyDialog) setMyNotify() (err error) { // 托盘图标 // icon, _ := walk.NewIconFromFile("../../img/main.ico") icon, _ := walk.NewIconFromResourceId(3) mw.ni, err = walk.NewNotifyIcon() mw.checkError(err) mw.SetIcon(icon) // Set the icon and a tool tip text. err = mw.ni.SetIcon(icon) mw.checkError(err) mw.ni.SetToolTip("测试程序") // The notify icon is hidden initially, so we have to make it visible. err = mw.ni.SetVisible(false) mw.checkError(err) return nil }
func runmodeWindow() { if err := (MainWindow{ AssignTo: &mw, DataBinder: DataBinder{ AssignTo: &db, DataSource: Input, ErrorPresenter: ErrorPresenterRef{&ep}, }, Title: config.FULL_NAME, MinSize: Size{450, 350}, Layout: VBox{ /*MarginsZero: true*/ }, Children: []Widget{ RadioButtonGroupBox{ AssignTo: &mode, Title: "*运行模式", Layout: HBox{}, MinSize: Size{0, 70}, DataMember: "Mode", Buttons: []RadioButton{ {Text: GuiOpt.Mode[0].Key, Value: GuiOpt.Mode[0].Int}, {Text: GuiOpt.Mode[1].Key, Value: GuiOpt.Mode[1].Int}, {Text: GuiOpt.Mode[2].Key, Value: GuiOpt.Mode[2].Int}, }, }, VSplitter{ AssignTo: &host, MaxSize: Size{0, 120}, Children: []Widget{ Label{ Text: "分布式端口:(单机模式不填)", }, NumberEdit{ Value: Bind("Port"), Suffix: "", Decimals: 0, }, Label{ Text: "主节点 URL:(客户端模式必填)", }, LineEdit{ Text: Bind("Master"), }, }, }, PushButton{ Text: "确认开始", MinSize: Size{0, 30}, AssignTo: &runStopBtn, OnClicked: func() { if err := db.Submit(); err != nil { logs.Log.Error("%v", err) return } switch Input.Mode { case status.OFFLINE: offlineWindow() case status.SERVER: serverWindow() case status.CLIENT: clientWindow() } }, }, }, }.Create()); err != nil { panic(err) } if icon, err := walk.NewIconFromResourceId(3); err == nil { mw.SetIcon(icon) } // 运行窗体程序 mw.Run() }
func main() { fout, _ := os.Create("dialer.log") defer fout.Close() bo := bufio.NewWriter(fout) defer bo.Flush() util.INFO.SetOutput(bo) util.ERROR.SetOutput(bo) bin, err := ioutil.ReadFile("config.json") if err == nil { json.Unmarshal(bin, config) } else { util.ERROR.Log(err) err = nil } var usr, pwd *walk.LineEdit var raddr, rusr, rpwd *walk.LineEdit var lb, rb *walk.PushButton var mode *walk.ComboBox var mw *walk.MainWindow var db *walk.DataBinder var laddr, lusr, lpwd *walk.Splitter go func() { for mw == nil { runtime.Gosched() } ic, err := walk.NewIconFromResourceId(6) if err == nil { // func onLoad() { db.SetAutoSubmit(true) mw.SetIcon(ic) switch config.RouterType { case "hiwifi": laddr.SetVisible(true) lusr.SetVisible(false) lpwd.SetVisible(true) case "openwrt": laddr.SetVisible(true) lusr.SetVisible(true) lpwd.SetVisible(true) case "asus": laddr.SetVisible(true) lusr.SetVisible(true) lpwd.SetVisible(true) default: laddr.SetVisible(false) lusr.SetVisible(false) lpwd.SetVisible(false) } mw.SetSize(walk.Size{0, 0}) // } } }() MainWindow{ AssignTo: &mw, Title: TITLE, MinSize: Size{340, 0}, Layout: VBox{}, DataBinder: DataBinder{ AssignTo: &db, DataSource: config, }, Children: []Widget{ HSplitter{ Children: []Widget{ Label{Text: "用户名", MaxSize: Size{60, 20}}, LineEdit{Text: Bind("Username"), AssignTo: &usr, MaxSize: Size{0, 20}}, }, MaxSize: Size{0, 20}, }, HSplitter{ Children: []Widget{ Label{Text: "密码", MaxSize: Size{60, 20}}, LineEdit{Text: Bind("Password"), AssignTo: &pwd, MaxSize: Size{0, 20}, PasswordMode: true, OnMouseDown: func(x, y int, button walk.MouseButton) { pwd.SetPasswordMode(false) }, OnMouseUp: func(x, y int, button walk.MouseButton) { pwd.SetPasswordMode(true) }, }, }, MaxSize: Size{0, 20}, }, HSplitter{ Children: []Widget{ Label{Text: "模式", MaxSize: Size{60, 20}}, ComboBox{AssignTo: &mode, Editable: true, Value: Bind("RouterType"), Model: []string{"local", "10.0.x.x(手动填写)", "openwrt", "hiwifi", "asus"}, MaxSize: Size{0, 20}, OnCurrentIndexChanged: func() { switch mode.CurrentIndex() { case 2: //"openwrt": laddr.SetVisible(true) lusr.SetVisible(true) lpwd.SetVisible(true) case 3: //"hiwifi": config.RouterAddr = "192.168.199.1" laddr.SetVisible(true) lusr.SetVisible(false) lpwd.SetVisible(true) case 4: //"asus": laddr.SetVisible(true) lusr.SetVisible(true) lpwd.SetVisible(true) default: laddr.SetVisible(false) lusr.SetVisible(false) lpwd.SetVisible(false) } mw.SetSize(walk.Size{0, 0}) }, }, }, MaxSize: Size{0, 20}, }, HSplitter{ AssignTo: &laddr, Children: []Widget{ Label{Text: "路由地址", MaxSize: Size{60, 20}}, LineEdit{Text: Bind("RouterAddr"), AssignTo: &raddr, MaxSize: Size{0, 20}}, }, MaxSize: Size{0, 20}, }, HSplitter{ AssignTo: &lusr, Children: []Widget{ Label{Text: "路由用户名", MaxSize: Size{60, 20}}, LineEdit{Text: Bind("RouterUser"), AssignTo: &rusr, MaxSize: Size{0, 20}}, }, MaxSize: Size{0, 20}, }, HSplitter{ AssignTo: &lpwd, Children: []Widget{ Label{Text: "路由密码", MaxSize: Size{60, 20}}, LineEdit{Text: Bind("RouterPwd"), AssignTo: &rpwd, MaxSize: Size{0, 20}, PasswordMode: true, OnMouseDown: func(x, y int, button walk.MouseButton) { rpwd.SetPasswordMode(false) }, OnMouseUp: func(x, y int, button walk.MouseButton) { rpwd.SetPasswordMode(true) }, }, }, MaxSize: Size{0, 20}, }, HSplitter{ Children: []Widget{ PushButton{ AssignTo: &lb, Text: "开始连接", OnClicked: func() { if mode.Text() == "10.0.x.x(手动填写)" { walk.MsgBox(mw, "请填写IP", "手动填写需要自己获取IP 你可在路由器中自己查找 本地拨号请用local", walk.MsgBoxOK) return } lb.SetText("连接中...") lb.SetEnabled(false) rb.SetEnabled(false) go func() { d := netdialer.NewDialer(usr.Text(), pwd.Text()) d.UserIP = selectMode(mode.Text()) if d.UserIP == "" { walk.MsgBox(mw, "连接失败", "请检查设置", walk.MsgBoxOK) d = nil return } d.ConnectDirect() mw.SetTitle(TITLE + " [" + d.UserIP + "]") d = nil lb.SetEnabled(true) rb.SetEnabled(true) lb.SetText("开始连接") if err == nil { walk.MsgBox(mw, "连接成功", "感谢使用", walk.MsgBoxOK) util.INFO.Log("连接成功: 感谢使用") } else { walk.MsgBox(mw, "连接失败", err.Error(), walk.MsgBoxOK) util.INFO.Log("连接失败: ", err.Error()) } }() }, }, PushButton{ AssignTo: &rb, Text: "断开连接", OnClicked: func() { if mode.Text() == "10.0.x.x(手动填写)" { walk.MsgBox(mw, "请填写IP", "手动填写需要自己获取IP 你可在路由器中自己查找", walk.MsgBoxOK) return } rb.SetText("断开中...") lb.SetEnabled(false) rb.SetEnabled(false) go func() { d := netdialer.NewDialer(usr.Text(), pwd.Text()) d.UserIP = selectMode(mode.Text()) if d.UserIP == "" { walk.MsgBox(mw, "连接失败", "请检查设置", walk.MsgBoxOK) util.INFO.Log("连接失败: 请检查设置") d = nil return } err := d.DisconnectDirect() mw.SetTitle(TITLE + " [" + d.UserIP + "]") d = nil lb.SetEnabled(true) rb.SetEnabled(true) rb.SetText("断开连接") if err == nil { walk.MsgBox(mw, "断开成功", "感谢使用", walk.MsgBoxOK) util.INFO.Log("断开成功: 感谢使用") } else { walk.MsgBox(mw, "断开失败", err.Error(), walk.MsgBoxOK) util.INFO.Log("断开失败: ", err.Error()) } }() }, }, }, MaxSize: Size{0, 20}, }, }, }.Run() saveConfig(config) bo.Flush() }
func (dlg *DlgServer) init(owner walk.Form) (err error) { dlg.Dialog, err = walk.NewDialogWithFixedSize(owner) dlg.checkError(err) // 读取配置文件 ConfSer.Read() succeeded := false defer func() { if !succeeded { dlg.Dispose() } }() // 设置主窗体大小 err = dlg.SetClientSize(walk.Size{250, 180}) dlg.checkError(err) // 设置窗体标题 err = dlg.SetTitle("服务器设置") dlg.checkError(err) // 设置字体和图标 fountTitle, _ := walk.NewFont("幼圆", 10, walk.FontBold) fountOther, _ := walk.NewFont("幼圆", 10, 0) // IP标题 dlg.ui.IpLb, err = walk.NewLabel(dlg) dlg.ui.IpLb.SetText("IP:") dlg.ui.IpLb.SetFont(fountTitle) dlg.ui.IpLb.SetBounds(walk.Rectangle{30, 20, 60, 20}) // IP编辑框 dlg.ui.IpLe, err = walk.NewLineEdit(dlg) dlg.ui.IpLe.SetBounds(walk.Rectangle{100, 20, 120, 20}) dlg.ui.IpLe.SetFont(fountOther) dlg.ui.IpLe.SetText(ConfSer.Ip) dlg.ui.IpLe.SetMaxLength(15) // 用户名标题 dlg.ui.UserLb, err = walk.NewLabel(dlg) dlg.ui.UserLb.SetText("用户名:") dlg.ui.UserLb.SetFont(fountTitle) dlg.ui.UserLb.SetBounds(walk.Rectangle{30, 60, 60, 20}) // 用户名编辑框 dlg.ui.UserLe, err = walk.NewLineEdit(dlg) dlg.ui.UserLe.SetBounds(walk.Rectangle{100, 60, 120, 20}) dlg.ui.UserLe.SetFont(fountOther) dlg.ui.UserLe.SetText(ConfSer.User) // 密码标题 dlg.ui.PasswdLb, err = walk.NewLabel(dlg) dlg.ui.PasswdLb.SetText("密码:") dlg.ui.PasswdLb.SetFont(fountTitle) dlg.ui.PasswdLb.SetBounds(walk.Rectangle{30, 100, 60, 20}) // 密码编辑框 dlg.ui.PasswdLe, err = walk.NewLineEdit(dlg) dlg.ui.PasswdLe.SetBounds(walk.Rectangle{100, 100, 120, 20}) dlg.ui.PasswdLe.SetPasswordMode(true) dlg.ui.PasswdLe.SetText(ConfSer.Passwd) // 确定 dlg.ui.AcceptPB, err = walk.NewPushButton(dlg) dlg.ui.AcceptPB.SetText("确定") dlg.ui.AcceptPB.SetBounds(walk.Rectangle{150, 140, 70, 25}) // 设置图标 icon, _ := walk.NewIconFromResourceId(3) dlg.SetIcon(icon) succeeded = true return nil }
// 设置程序图标 func (mw *MyWindow) setIcon(value int) { icon, err := walk.NewIconFromResourceId(uintptr(value)) checkError(err) mw.SetIcon(icon) mw.notifyIcon.SetIcon(icon) }