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

	var mw *walk.MainWindow

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

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

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

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

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

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

	mw.Show()
	mw.Run()
}
Beispiel #2
0
// Spawns a window containing a webview pointed at the given URL, and waits for
// it to be closed. If the webview cannot be opened, returns an error
// immediately.
func WebviewWindow(serverURL string) (e error) {
	var mainWindow *walk.MainWindow
	var webView *walk.WebView

	log.Print("Starting to create webview window")
	if err := (declarative.MainWindow{
		AssignTo: &mainWindow,
		Title:    "WebCmd Webview",
		MinSize:  declarative.Size{600, 400},
		Size:     declarative.Size{800, 600},
		Visible:  true,
		Layout:   declarative.HBox{},
		Children: []declarative.Widget{
			declarative.WebView{
				AssignTo: &webView,
			},
		},
	}.Create()); err != nil {
		log.Println("Error while creating window. Usually happens when " +
			"compiled without -ldflags=\"-Hwindowsgui\" or a manifest. " +
			"see make.bat to compile with window support on windows.")
		return errors.New("Unable to create webview window")
	}
	log.Print("Create complete, initializing webView with URL ", serverURL)
	webView.SetURL(serverURL)

	mainWindow.Run()
	log.Print("Webview closed.")
	return nil
}
Beispiel #3
0
func main() {
	var mw *walk.MainWindow

	if err := (MainWindow{
		AssignTo: &mw,
		Title:    "Walk LogView Example",
		MinSize:  Size{320, 240},
		Size:     Size{400, 600},
		Layout:   VBox{MarginsZero: true},
	}.Create()); err != nil {
		log.Fatal(err)
	}

	lv, err := NewLogView(mw)
	if err != nil {
		log.Fatal(err)
	}

	lv.PostAppendText("XXX")
	log.SetOutput(lv)

	go func() {
		for i := 0; i < 10000; i++ {
			time.Sleep(100 * time.Millisecond)
			log.Println("Text" + "\r\n")
		}
	}()

	mw.Run()
}
Beispiel #4
0
func main() {
	var mw *walk.MainWindow

	if err := (MainWindow{
		AssignTo: &mw,
		Title:    "Walk External Widgets Example",
		Size:     Size{400, 300},
		Layout:   HBox{},
	}).Create(); err != nil {
		log.Fatal(err)
	}

	for _, name := range []string{"a", "b", "c"} {
		if w, err := NewMyWidget(mw); err != nil {
			log.Fatal(err)
		} else {
			w.SetName(name)
		}
	}

	mpb, err := NewMyPushButton(mw)
	if err != nil {
		log.Fatal(err)
	}
	mpb.SetText("MyPushButton")

	mw.Run()
}
Beispiel #5
0
func main() {
	var mw *walk.MainWindow
	var windowIcon *walk.Icon
	counter := 0

	if _, err := (MainWindow{
		AssignTo: &mw,
		Title:    "Walk Image Icon Example",
		Layout:   HBox{},
		Children: []Widget{
			HSpacer{},
			PushButton{
				Text: "Push me",
				OnClicked: func() {
					ic, err := walk.NewIconFromImage(makeDigitImage(counter))
					if err != nil {
						return
					}
					counter++
					mw.SetIcon(ic)
					if windowIcon != nil {
						windowIcon.Dispose()
					}
					windowIcon = ic
				},
			},
			HSpacer{},
		},
	}.Run()); err != nil {
		log.Fatal(err)
	}
}
Beispiel #6
0
func main() {
	var mw *walk.MainWindow
	var c1 *walk.Composite
	var c2 *walk.Composite

	bmp, err := walk.NewBitmapFromFile("../../img/plus.png")
	if err != nil {
		panic(err)
	}
	defer bmp.Dispose()

	MainWindow{
		AssignTo: &mw,
		Title:    "Background Example",
		Layout:   VBox{MarginsZero: true},
		MinSize:  Size{300, 400},
		Children: []Widget{
			Composite{
				AssignTo: &c1,
				Layout:   VBox{},
				Children: []Widget{
					TextEdit{},
				},
			},
			Composite{
				AssignTo: &c2,
				Layout:   VBox{},
				Children: []Widget{
					TextEdit{},
				},
			},
			ImageView{
				Image: bmp,
			},
		},
	}.Create()

	scb, err := walk.NewSolidColorBrush(walk.RGB(255, 0, 0))
	if err != nil {
		panic(err)
	}
	defer scb.Dispose()

	c1.SetBackground(scb)

	bmb, err := walk.NewBitmapBrush(bmp)
	if err != nil {
		panic(err)
	}
	defer bmb.Dispose()

	c2.SetBackground(bmb)

	mw.Show()
	mw.Run()
}
Beispiel #7
0
// Main entry and GUI construction
func main() {
	LANG = queryRegLayoutId(LANG_ID)
	var (
		mw            *walk.MainWindow
		currentLayout = getKeyboardLayout() // Get current system layout.
		layoutPresent = checkLanguage()     // Check if installed language is present and can be loaded.
		triggered     = true
		infoText      string
		ldtMain       *walk.LineEdit
		btnMain       *walk.PushButton
	)

	if layoutPresent {
		infoText = INFO_TEXT
	} else {
		infoText = "The layout does not seem to be present on your system. Please install it first."
	}

	MainWindow{
		AssignTo: &mw,
		Title:    "kasahorow " + LANG_STRING + " Writer",
		MaxSize:  Size{600, 200},
		MinSize:  Size{600, 200},
		Layout:   VBox{},
		Children: []Widget{
			MultilineLabel{Text: infoText},
			LineEdit{AssignTo: &ldtMain},
			PushButton{
				AssignTo: &btnMain,
				Enabled:  layoutPresent,
				Text:     "Switch back to default layout.",
				OnClicked: func() {
					if triggered {
						triggered = false
						activateKeyboardLayout(currentLayout, KFL_SETFORPROCESS)
						btnMain.SetText("Switch to " + LANG_STRING + ".")
					} else {
						triggered = true
						loadLanguage()
						btnMain.SetText("Switch back to default layout.")
					}
				},
			},
		},
	}.Create()

	if layoutPresent {
		mw.Synchronize(loadLanguage) // Load new layout in main GUI thread.
	}

	ic, _ := walk.NewIconFromResource("kasahorow")
	mw.SetIcon(ic)
	mw.Run()
}
Beispiel #8
0
func Run() {
	var mw *walk.MainWindow
	var db *walk.DataBinder
	var ep walk.ErrorPresenter
	var spiderMenu = NewSpiderMenu(spider.Menu)

	if err := (MainWindow{
		AssignTo: &mw,
		DataBinder: DataBinder{
			AssignTo:       &db,
			DataSource:     Input,
			ErrorPresenter: ErrorPresenterRef{&ep},
		},
		Title:   config.APP_NAME,
		MinSize: Size{1100, 700},
		Layout:  VBox{},
		Children: []Widget{
			// 任务列表
			HSplitter{
				Children: []Widget{
					TableView{
						MinSize:               Size{550, 400},
						AlternatingRowBGColor: walk.RGB(255, 255, 224),
						CheckBoxes:            true,
						ColumnsOrderable:      true,
						Columns: []TableViewColumn{
							{Title: "#", Width: 45},
							{Title: "任务", Width: 110 /*, Format: "%.2f", Alignment: AlignFar*/},
							{Title: "描述", Width: 370},
						},
						Model: spiderMenu,
					},
					// 关键词
					VSplitter{
						MinSize: Size{550, 400},

						Children: []Widget{
							VSplitter{
								Children: []Widget{
									Label{
										Text: "关键词:(多任务之间以 | 隔开,选填)",
									},
									LineEdit{
										Text: Bind("Keywords"),
									},
								},
							},

							VSplitter{
								Children: []Widget{
									Label{
										Text: "采集页数:(选填)",
									},
									NumberEdit{
										Value:    Bind("MaxPage"),
										Suffix:   "",
										Decimals: 0,
									},
								},
							},

							VSplitter{
								Children: []Widget{
									Label{
										Text: "*并发协程:(1~99999)",
									},
									NumberEdit{
										Value:    Bind("ThreadNum", Range{1, 99999}),
										Suffix:   "",
										Decimals: 0,
									},
								},
							},

							VSplitter{
								Children: []Widget{
									Label{
										Text: "*分批输出大小:(1~5,000,000 条数据)",
									},
									NumberEdit{
										Value:    Bind("DockerCap", Range{1, 5000000}),
										Suffix:   "",
										Decimals: 0,
									},
								},
							},

							VSplitter{
								Children: []Widget{
									Label{
										Text: "*间隔基准:",
									},
									ComboBox{
										Value:         Bind("BaseSleeptime", SelRequired{}),
										BindingMember: "Uint",
										DisplayMember: "Key",
										Model:         GUIOpt.SleepTime,
									},
								},
							},

							VSplitter{
								Children: []Widget{
									Label{
										Text: "*随机延迟:",
									},
									ComboBox{
										Value:         Bind("RandomSleepPeriod", SelRequired{}),
										BindingMember: "Uint",
										DisplayMember: "Key",
										Model:         GUIOpt.SleepTime,
									},
								},
							},

							RadioButtonGroupBox{
								ColumnSpan: 2,
								Title:      "*输出方式",
								Layout:     HBox{},
								DataMember: "OutType",
								Buttons: []RadioButton{
									{Text: GUIOpt.OutType[0].Key, Value: GUIOpt.OutType[0].String},
									{Text: GUIOpt.OutType[1].Key, Value: GUIOpt.OutType[1].String},
									{Text: GUIOpt.OutType[2].Key, Value: GUIOpt.OutType[2].String},
								},
							},
						},
					},
				},
			},

			Composite{
				Layout: HBox{},
				Children: []Widget{

					// 必填项错误检查
					LineErrorPresenter{
						AssignTo:   &ep,
						ColumnSpan: 2,
					},

					PushButton{
						Text:     "开始抓取",
						AssignTo: &toggleSpecialModePB,
						OnClicked: func() {
							if toggleSpecialModePB.Text() == "取消" {
								toggleSpecialModePB.SetEnabled(false)
								toggleSpecialModePB.SetText("取消中…")
								Stop()
							} else {
								if err := db.Submit(); err != nil {
									log.Print(err)
									return
								}
								Input.Spiders = spiderMenu.GetChecked()
								if len(Input.Spiders) == 0 {
									return
								}
								toggleSpecialModePB.SetText("取消")
								Start()
							}
						},
					},
				},
			},
		},
	}.Create()); err != nil {
		log.Fatal(err)
	}

	// 绑定log输出界面
	lv, err := NewLogView(mw)
	if err != nil {
		log.Fatal(err)
	}
	log.SetOutput(lv)

	if icon, err := walk.NewIconFromResource("ICON"); err == nil {
		mw.SetIcon(icon)
	}

	// 运行窗体程序
	mw.Run()
}
Beispiel #9
0
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()
}
Beispiel #10
0
func main() {
	var mainWindow *walk.MainWindow
	var treeView *walk.TreeView
	var tableView *walk.TableView
	var webView *walk.WebView

	treeModel, err := NewDirectoryTreeModel()
	if err != nil {
		log.Fatal(err)
	}
	tableModel := NewFileInfoModel()

	if err := (MainWindow{
		AssignTo: &mainWindow,
		Title:    "Walk File Browser Example",
		MinSize:  Size{600, 400},
		Size:     Size{800, 600},
		Layout:   HBox{},
		Children: []Widget{
			HSplitter{
				Children: []Widget{
					TreeView{
						AssignTo: &treeView,
						Model:    treeModel,
						OnCurrentItemChanged: func() {
							dir := treeView.CurrentItem().(*Directory)
							if err := tableModel.SetDirPath(dir.Path()); err != nil {
								walk.MsgBox(
									mainWindow,
									"Error",
									err.Error(),
									walk.MsgBoxOK|walk.MsgBoxIconError)
							}
						},
					},
					TableView{
						AssignTo: &tableView,
						Columns: []TableViewColumn{
							TableViewColumn{
								Title:      "Name",
								DataMember: "Name",
								Width:      200,
							},
							TableViewColumn{
								Title:      "Size",
								DataMember: "Size",
								Format:     "%d",
								Alignment:  AlignFar,
								Width:      80,
							},
							TableViewColumn{
								Title:      "Modified",
								DataMember: "Modified",
								Format:     "2006-01-02 15:04:05",
								Width:      120,
							},
						},
						Model: tableModel,
						OnCurrentIndexChanged: func() {
							var url string
							if index := tableView.CurrentIndex(); index > -1 {
								name := tableModel.items[index].Name
								dir := treeView.CurrentItem().(*Directory)
								url = filepath.Join(dir.Path(), name)
							}

							webView.SetURL(url)
						},
					},
					WebView{
						AssignTo: &webView,
					},
				},
			},
		},
	}.Create()); err != nil {
		log.Fatal(err)
	}

	mainWindow.Run()
}
Beispiel #11
0
func main() {
	font := Font{
		Family:    "Times New Roman",
		PointSize: 13,
		Bold:      true,
	}
	usr, _ := user.Current()
	usrModel := env.NewModel(0)
	sysModel := env.NewModel(1)
	var usrTableView, sysTableView *walk.TableView
	var mw *walk.MainWindow
	MainWindow{
		Title:    "Enviroment Variable",
		Size:     Size{600, 700},
		Layout:   VBox{},
		AssignTo: &mw,
		Font:     font,
		Children: []Widget{
			VSplitter{
				Children: []Widget{
					GroupBox{
						Title:  "User variables for " + usr.Username,
						Font:   font,
						Layout: VBox{},
						Children: []Widget{
							TableView{
								AssignTo:              &usrTableView,
								AlternatingRowBGColor: walk.RGB(255, 255, 224),
								ColumnsOrderable:      true,
								Columns: []TableViewColumn{
									{Title: "name", Width: 200},
									{Title: "value"},
								},
								LastColumnStretched: true,
								Model:               usrModel,
								OnItemActivated: func() {
									index := usrTableView.CurrentIndex()
									if index != -1 {
										EditVariable(mw, usrModel, usrModel.GetVariable(index).Name, usrModel.GetVariable(index).Value)
									}
								},
							},
							Composite{
								Layout: HBox{},
								Children: []Widget{
									HSpacer{},
									PushButton{
										Text: "New...",
										OnClicked: func() {
											NewVariable(mw, usrModel)
										},
									},
									PushButton{
										Text: "Edit...",
										OnClicked: func() {
											index := usrTableView.CurrentIndex()
											if index != -1 {
												EditVariable(mw, usrModel, usrModel.GetVariable(index).Name, usrModel.GetVariable(index).Value)
											}
										},
									},
									PushButton{
										Text: "Delete",
										OnClicked: func() {
											index := usrTableView.CurrentIndex()
											if index != -1 {
												DeleteVariable(mw, usrModel, usrModel.GetVariable(index).Name)
											}
										},
									},
								},
							},
						},
					},
					GroupBox{
						Title:  "System variables",
						Font:   font,
						Layout: VBox{},
						Children: []Widget{
							TableView{
								AssignTo:              &sysTableView,
								AlternatingRowBGColor: walk.RGB(255, 255, 224),
								ColumnsOrderable:      true,
								Columns: []TableViewColumn{
									{Title: "Variable", Width: 200},
									{Title: "Value"},
								},
								LastColumnStretched: true,
								Model:               sysModel,
								OnItemActivated: func() {
									index := sysTableView.CurrentIndex()
									if index != -1 {
										EditVariable(mw, sysModel, sysModel.GetVariable(index).Name, sysModel.GetVariable(index).Value)
									}
								},
							},
							Composite{
								Layout: HBox{},
								Children: []Widget{
									HSpacer{},
									PushButton{
										Text: "New...",
										OnClicked: func() {
											NewVariable(mw, sysModel)
										},
									},
									PushButton{
										Text: "Edit...",
										OnClicked: func() {
											index := sysTableView.CurrentIndex()
											if index != -1 {
												EditVariable(mw, sysModel, sysModel.GetVariable(index).Name, sysModel.GetVariable(index).Value)
											}
										},
									},
									PushButton{
										Text: "Delete",
										OnClicked: func() {
											index := sysTableView.CurrentIndex()
											if index != -1 {
												DeleteVariable(mw, sysModel, sysModel.GetVariable(index).Name)
											}
										},
									},
								},
							},
						},
					},
				},
			},
			Composite{
				Layout: HBox{},
				Children: []Widget{
					HSpacer{},
					PushButton{
						Text: "OK",
						OnClicked: func() {
							if ApplyEnv(mw, usrModel, sysModel) {
								mw.Close()
							}
						},
					},
					PushButton{
						Text: "Cancel",
						OnClicked: func() {
							mw.Close()
						},
					},
				},
			},
		},
	}.Run()

}
Beispiel #12
0
func main() {
	var le, le2 *walk.LineEdit
	var lb1, lb2 *walk.Label
	var ck1 *walk.CheckBox
	var mw *walk.MainWindow

	copytext, _ := walk.Clipboard().Text()

	updateIcon := func() {
		mainIcon, err := walk.NewIconFromResource("101")
		if err != nil {
			// do some work
		}
		mw.SetIcon(mainIcon)
	}

	if err := (MainWindow{
		AssignTo: &mw,
		Title:    "模板下载器",
		MinSize:  Size{400, 100},
		Layout:   VBox{},
		Children: []Widget{
			CheckBox{
				AssignTo: &ck1,
				Name:     "cksnap",
				Text:     "带截图抓取",
				Checked:  false,
			},
			Label{
				AssignTo: &lb1,
				Text:     "网址",
			},
			LineEdit{
				AssignTo: &le,
				Text:     copytext,
			},
			Label{
				AssignTo: &lb2,
				Text:     "保存目录",
			},
			LineEdit{
				AssignTo: &le2,
				Text:     `D:\APMServ5.2.6\www\htdocs\down\tpls\`,
			},
			PushButton{
				Text: "开始抓取",
				OnClicked: func() {
					fmt.Println(ck1.Checked())
					if ck1.Checked() {
						command := flag.String("cmd", "phantomjs", "Set the command.")
						patharr := strings.Split(le2.Text(), "\\")

						args := flag.String("args", "rasterize.js "+le.Text()+" "+le2.Text()+"\\"+patharr[len(patharr)-1]+".png", "Set the args. (separated by spaces)")
						var argArray []string
						if *args != "" {
							argArray = strings.Split(*args, " ")
						} else {
							argArray = make([]string, 0)
						}

						flag.Parse()
						cmd := exec.Command(*command, argArray...)

						buf, err := cmd.Output()
						if err != nil {
							fmt.Fprintf(os.Stderr, "The command failed to perform: %s (Command: %s, Arguments: %s)", err, *command, *args)
							return
						}
						fmt.Fprintf(os.Stdout, "Result: %s", buf)

					}
					getTemplate(le.Text(), le2.Text())
				},
			},