Ejemplo n.º 1
0
func NewElangGui() (this *ElangGui, err error) {
	this = &ElangGui{Data: &ElangGuiData{"我学会了新的姿势", "厘侥氏阻仟议徊米", Mode1}}
	var db *walk.DataBinder
	update := func() {
		src := this.mSrc.Text()
		switch this.Data.Mode {
		case Mode1:
			src = zhconv.EncodeString(src)
			src = elang.EncodeString(src)
			src = zhconv.EncodeString(src)
		case Mode2:
			src = zhconv.DecodeString(src)
			src = elang.DecodeString(src)
			src = zhconv.EncodeString(src)
		}
		this.mTar.SetText(src)
	}
	wmodel := MainWindow{
		AssignTo: &this.mw,
		Title:    "鹅语",
		MinSize:  Size{512, 450},
		Layout:   VBox{},
		DataBinder: DataBinder{
			AssignTo:   &db,
			DataSource: this.Data,
		},
		Children: []Widget{
			TextEdit{
				Text:     Bind("Src"),
				AssignTo: &this.mSrc,
			},
			RadioButtonGroupBox{
				Title:      "模式",
				AssignTo:   &this.mMode,
				Layout:     HBox{},
				DataMember: "Mode",
				Buttons: []RadioButton{
					{Text: "模式一", Value: Mode1, OnClicked: update},
					{Text: "模式二", Value: Mode2, OnClicked: update},
				},
			},
			TextEdit{
				Text:     Bind("Dst"),
				AssignTo: &this.mTar,
			},
		},
	}
	if err = wmodel.Create(); err != nil {
		walk.MsgBox(nil, "错误", "创建窗口失败", walk.MsgBoxOK|walk.MsgBoxIconError)
		return
	}
	if icon, err2 := walk.NewIconFromResource("ICON_MAIN"); err2 == nil {
		this.mw.SetIcon(icon)
	}
	this.mSrc.TextChanged().Attach(update)
	db.SetAutoSubmit(true)
	return
}
Ejemplo n.º 2
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()
}
Ejemplo n.º 3
0
func setWindow() {
	// 绑定log输出界面
	lv, err := NewLogView(mw)
	if err != nil {
		panic(err)
	}
	LogicApp.SetLog(lv)
	log.SetOutput(lv)
	// 设置左上角图标
	if icon, err := walk.NewIconFromResource("ICON"); err == nil {
		mw.SetIcon(icon)
	}
}
Ejemplo n.º 4
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()
}
Ejemplo n.º 5
0
func serverWindow() {
	mw.Close()

	if err := (MainWindow{
		AssignTo: &mw,
		DataBinder: DataBinder{
			AssignTo:       &db,
			DataSource:     Input,
			ErrorPresenter: ErrorPresenterRef{&ep},
		},
		Title:   config.APP_NAME + "                                                          【 运行模式 -> 服务器 】",
		MinSize: Size{1100, 700},
		Layout:  VBox{ /*MarginsZero: true*/ },
		Children: []Widget{

			Composite{
				AssignTo: &setting,
				Layout:   Grid{Columns: 2},
				Children: []Widget{
					// 任务列表
					TableView{
						ColumnSpan:            1,
						MinSize:               Size{550, 350},
						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{
						ColumnSpan: 1,
						MinSize:    Size{550, 0},
						Children: []Widget{

							VSplitter{
								Children: []Widget{
									Label{
										Text: "自定义输入:(多任务之间以 | 隔开,选填)",
									},
									LineEdit{
										Text: Bind("Keywords"),
									},
								},
							},

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

							VSplitter{
								Children: []Widget{
									Label{
										Text: "采集页数:(选填)",
									},
									NumberEdit{
										Value:    Bind("MaxPage"),
										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: 1,
								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,
					},

					PushButton{
						MinSize:   Size{90, 0},
						Text:      serverBtnTxt(),
						AssignTo:  &toggleRunBtn,
						OnClicked: serverStart,
					},
				},
			},
		},
	}.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)
	}

	// 开启报告
	reporter.Log.Run()

	// 运行pholcus核心
	PholcusRun()

	// 运行窗体程序
	mw.Run()
}
Ejemplo n.º 6
0
func runmodeWindow() {
	if err := (MainWindow{
		AssignTo: &mw,
		DataBinder: DataBinder{
			AssignTo:       &db,
			DataSource:     Input,
			ErrorPresenter: ErrorPresenterRef{&ep},
		},
		Title:   config.APP_NAME,
		MinSize: Size{450, 350},
		Layout:  VBox{ /*MarginsZero: true*/ },
		Children: []Widget{

			RadioButtonGroupBox{
				AssignTo: &mode,
				Title:    "*运行模式",
				Layout:   HBox{},
				MinSize:  Size{0, 70},

				DataMember: "RunMode",
				Buttons: []RadioButton{
					{Text: GuiOpt.RunMode[0].Key, Value: GuiOpt.RunMode[0].Int},
					{Text: GuiOpt.RunMode[1].Key, Value: GuiOpt.RunMode[1].Int},
					{Text: GuiOpt.RunMode[2].Key, Value: GuiOpt.RunMode[2].Int},
				},
			},

			VSplitter{
				AssignTo: &host,
				MaxSize:  Size{0, 120},
				Children: []Widget{
					VSplitter{
						Children: []Widget{
							Label{
								Text: "分布式端口:(单机模式不填)",
							},
							NumberEdit{
								Value:    Bind("Port"),
								Suffix:   "",
								Decimals: 0,
							},
						},
					},

					VSplitter{
						Children: []Widget{
							Label{
								Text: "主节点 URL:(客户端模式必填)",
							},
							LineEdit{
								Text: Bind("Master"),
							},
						},
					},
				},
			},

			PushButton{
				Text:     "确认开始",
				MinSize:  Size{0, 30},
				AssignTo: &runStopBtn,
				OnClicked: func() {
					if err := db.Submit(); err != nil {
						log.Println(err)
						return
					}

					switch Input.RunMode {
					case status.OFFLINE:
						offlineWindow()

					case status.SERVER:
						serverWindow()

					case status.CLIENT:
						clientWindow()
					}

				},
			},
		},
	}.Create()); err != nil {
		log.Fatal(err)
	}

	if icon, err := walk.NewIconFromResource("ICON"); err == nil {
		mw.SetIcon(icon)
	}
	// 运行窗体程序
	mw.Run()
}
Ejemplo n.º 7
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())
				},
			},