Exemple #1
1
func main() {
	var mw *walk.MainWindow
	var outTE *walk.TextEdit

	animal := new(Animal)

	if _, err := (MainWindow{
		AssignTo: &mw,
		Title:    "Walk Data Binding Example",
		MinSize:  Size{300, 200},
		Layout:   VBox{},
		Children: []Widget{
			PushButton{
				Text: "Edit Animal",
				OnClicked: func() {
					if cmd, err := RunAnimalDialog(mw, animal); err != nil {
						log.Print(err)
					} else if cmd == walk.DlgCmdOK {
						outTE.SetText(fmt.Sprintf("%+v", animal))
					}
				},
			},
			Label{
				Text: "animal:",
			},
			TextEdit{
				AssignTo: &outTE,
				ReadOnly: true,
				Text:     fmt.Sprintf("%+v", animal),
			},
		},
	}.Run()); err != nil {
		log.Fatal(err)
	}
}
Exemple #2
1
func main() {
	var outTE *walk.TextEdit
	mw := new(MyMainWindow)
	MainWindow{
		Title:    "简易加密文件",
		AssignTo: &mw.MainWindow,
		MinSize:  Size{300, 140},
		Layout:   VBox{},
		Children: []Widget{
			HSplitter{
				Children: []Widget{
					TextEdit{AssignTo: &outTE, ReadOnly: true},
				},
			},
			PushButton{
				Text: "选择文件求反",
				OnClicked: func() {
					dlg := new(walk.FileDialog)
					dlg.Title = "选择文件"
					if ok, err := dlg.ShowOpen(mw); err != nil {
						outTE.SetText(err.Error())
					} else if !ok {
						outTE.SetText("未选择文件")
					} else {
						fileName := dlg.FilePath
						file, err := os.Open(fileName)
						defer file.Close()
						if err != nil {
							outTE.SetText("未找到待处理文件")
						}
						//读取文件内容
						plain, _ := ioutil.ReadAll(file)
						//求反
						for i, b := range plain {
							plain[i] = ^b
						}
						//写入文件
						if fileName[len(fileName)-1:] != "+" {
							fileName += "+"
						} else {
							fileName = fileName[:len(fileName)-1]
						}
						err = ioutil.WriteFile(fileName, plain, 0777)
						if err != nil {
							outTE.SetText(dlg.FilePath + " 保存转换后文件失败!")
						} else {
							outTE.SetText(dlg.FilePath + " 文件已转换!")
						}
					}
				},
			},
		},
	}.Run()
}
Exemple #3
0
func main() {
	var te *walk.TextEdit

	if _, err := (MainWindow{
		Title:   "Walk Clipboard Example",
		MinSize: Size{300, 200},
		Layout:  VBox{},
		Children: []Widget{
			PushButton{
				Text: "Copy",
				OnClicked: func() {
					if err := walk.Clipboard().SetText(te.Text()); err != nil {
						log.Print("Copy: ", err)
					}
				},
			},
			PushButton{
				Text: "Paste",
				OnClicked: func() {
					if text, err := walk.Clipboard().Text(); err != nil {
						log.Print("Paste: ", err)
					} else {
						te.SetText(text)
					}
				},
			},
			TextEdit{
				AssignTo: &te,
			},
		},
	}).Run(); err != nil {
		log.Fatal(err)
	}
}
Exemple #4
0
func openstomp(host, dest, port string, logTextEdit *walk.TextEdit, closeMessage chan int) {
	stomputils.JmsHost = host
	stomputils.JmsDest = dest
	stomputils.JmsPort = port

	handleMessage := func(body []byte) {
		//fmt.Println(string(body))
		logTextEdit.SetText(logTextEdit.Text() + string(body))
	}

	stomputils.Handle(handleMessage, closeMessage)
}
Exemple #5
0
func main() {
	var textEdit *walk.TextEdit
	MainWindow{
		Title:   "Walk DropFiles Example",
		MinSize: Size{320, 240},
		Layout:  VBox{},
		OnDropFiles: func(files []string) {
			textEdit.SetText(strings.Join(files, "\r\n"))
		},
		Children: []Widget{
			TextEdit{
				AssignTo: &textEdit,
				ReadOnly: true,
				Text:     "Drop files here, from windows explorer...",
			},
		},
	}.Run()
}
Exemple #6
0
func main() {
	var (
		msgbox  *walk.TextEdit
		inputUN *walk.LineEdit //input username
		inputPW *walk.LineEdit //input password
		myPB    *walk.PushButton
	)

	MainWindow{

		Title:   "soramail",
		MinSize: Size{640, 480},
		Layout:  VBox{},
		Children: []Widget{
			TextEdit{
				AssignTo: &msgbox,
				Text:     "Hello, World",
				ReadOnly: true,
			},
			HSplitter{
				MaxSize: Size{640, 20},
				Children: []Widget{
					LineEdit{
						AssignTo: &inputUN,
						Text:     "username",
					},
					LineEdit{
						AssignTo: &inputPW,
						Text:     "password",
					},
					PushButton{
						AssignTo: &myPB,
						Text:     "Push",
						OnClicked: func() {
							msgbox.AppendText("\r\nHello," + inputUN.Text() + ".\r\nYour password is " + inputPW.Text())
						},
					},
				},
			},
		},
	}.Run()
}
func main() {
	var inTE, outTE *walk.TextEdit

	MainWindow{
		Title:   "PHP Interpreter",
		MinSize: Size{600, 400},
		Layout:  VBox{},
		Children: []Widget{
			Label{
				Text: "Escriba codigo PHP sin etiquetas de <?php apertura y cierre ?>",
			},
			HSplitter{
				Children: []Widget{
					TextEdit{AssignTo: &inTE},
					TextEdit{AssignTo: &outTE, ReadOnly: true},
				},
			},
			PushButton{
				Text: "Let the magic happen!",
				OnClicked: func() {

					input := strings.Replace(inTE.Text(), "\n", " ", -1)
					out, err := exec.Command("php", "-r", input).Output()

					if err != nil {
						log.Println(err)
					}

					outTE.SetText(string(out))
				},
			},
		},
	}.Run()
}
Exemple #8
0
func main() {
	var (
		te *walk.TextEdit
		le *walk.LineEdit
	)

	MainWindow{
		Title:   _WIN_TITLE,
		MinSize: Size{300, 400},
		Layout:  VBox{},
		Children: []Widget{
			Label{
				Text: _WIN_LABEL_HOST,
			},
			LineEdit{
				AssignTo: &le,
				Text:     GetHttpHost(),
			},
			Label{
				Text: _WIN_LABEL_LINK,
			},
			TextEdit{
				AssignTo: &te,
			},
			Composite{
				Layout: HBox{},
				Children: []Widget{
					PushButton{
						Text: _WIN_GEN_BUTTON,
						OnClicked: func() {
							URL, err := url.Parse(te.Text())
							if err != nil {
								return
							}

							genURL := generateURL(URL, le.Text())
							if genURL != nil {
								te.SetText(genURL.String())
							}
						},
					},
					PushButton{
						Text: _WIN_COPY_BUTTON,
						OnClicked: func() {
							walk.Clipboard().SetText(te.Text())
						},
					},
				},
			},
		},
	}.Run()
}
Exemple #9
0
func main() {
	LoadData()
	chEnd = make(chan bool)
	var emails, body, msgbox *walk.TextEdit
	var user, password, host, subject *walk.LineEdit
	var startBtn *walk.PushButton
	MainWindow{
		Title:   "邮件群发器 By 一曲忧伤",
		MinSize: Size{800, 600},
		Layout:  HBox{},
		Children: []Widget{
			TextEdit{AssignTo: &emails, Text: SJ.Send, ToolTipText: "待发送邮件列表,每行一个"},
			VSplitter{
				Children: []Widget{
					LineEdit{AssignTo: &user, Text: SJ.Name, CueBanner: "请输入邮箱用户名"},
					LineEdit{AssignTo: &password, Text: SJ.Pwd, PasswordMode: true, CueBanner: "请输入邮箱登录密码"},
					LineEdit{AssignTo: &host, Text: SJ.Host, CueBanner: "SMTP服务器:端口"},
					LineEdit{AssignTo: &subject, Text: SJ.Subject, CueBanner: "请输入邮件主题……"},
					TextEdit{AssignTo: &body, Text: SJ.Body, ToolTipText: "请输入邮件内容", ColumnSpan: 2},
					TextEdit{AssignTo: &msgbox, ReadOnly: true},
					PushButton{
						AssignTo: &startBtn,
						Text:     "开始群发",
						OnClicked: func() {
							SJ.Name = user.Text()
							SJ.Pwd = password.Text()
							SJ.Host = host.Text()
							SJ.Subject = subject.Text()
							SJ.Body = body.Text()
							SJ.Send = emails.Text()
							SaveData()

							if runing == false {
								runing = true
								startBtn.SetText("停止发送")
								go sendThread(msgbox, emails)
							} else {
								runing = false
								startBtn.SetText("开始群发")
							}
						},
					},
				},
			},
		},
	}.Run()
}
Exemple #10
0
func main() {
	var inTE, outTE *walk.TextEdit

	MainWindow{
		Title:   "SCREAMO",
		MinSize: Size{600, 400},
		Layout:  VBox{},
		Children: []Widget{
			HSplitter{
				Children: []Widget{
					TextEdit{AssignTo: &inTE},
					TextEdit{AssignTo: &outTE, ReadOnly: true},
				},
			},
			PushButton{
				Text: "SCREAM",
				OnClicked: func() {
					outTE.SetText(strings.ToUpper(inTE.Text()))
				},
			},
		},
	}.Run()
}
Exemple #11
0
func main() {
	var aTE, bTE, cTE, dTE *walk.LineEdit
	var outTE *walk.TextEdit
	var mw *walk.MainWindow

	defer func() {
		if e := recover(); e != nil {
			walk.MsgBox(mw, "Error", fmt.Sprintf("%v", e), walk.MsgBoxIconInformation)
		}
	}()

	MainWindow{
		AssignTo: &mw,
		Title:    "24 Game",
		MinSize:  Size{600, 400},
		Layout:   VBox{},
		Children: []Widget{
			Composite{
				Layout: HBox{},
				Children: []Widget{
					Label{Text: "a"},
					LineEdit{AssignTo: &aTE},
					Label{Text: "b"},
					LineEdit{AssignTo: &bTE},
					Label{Text: "c"},
					LineEdit{AssignTo: &cTE},
					Label{Text: "d"},
					LineEdit{AssignTo: &dTE},
					PushButton{
						Text: "Go",
						OnClicked: func() {
							rand.Seed(time.Now().Unix())
							aTE.SetText(fmt.Sprint(rand.Intn(13) + 1))
							bTE.SetText(fmt.Sprint(rand.Intn(13) + 1))
							cTE.SetText(fmt.Sprint(rand.Intn(13) + 1))
							dTE.SetText(fmt.Sprint(rand.Intn(13) + 1))
						},
					},
				},
			},
			TextEdit{AssignTo: &outTE, ReadOnly: true},
			PushButton{
				Text: "Compute",
				OnClicked: func() {
					a, err := strconv.ParseInt(aTE.Text(), 10, 64)
					b, err := strconv.ParseInt(bTE.Text(), 10, 64)
					c, err := strconv.ParseInt(cTE.Text(), 10, 64)
					d, err := strconv.ParseInt(dTE.Text(), 10, 64)
					if err != nil {
						walk.MsgBox(mw, "Error", err.Error(), walk.MsgBoxIconInformation)
					}
					outTE.SetText("")
					for solution := range findSolution(a, b, c, d) {
						outTE.AppendText(fmt.Sprintf("%s = 24\r\n", solution))
					}
					if outTE.Text() == "" {
						outTE.SetText("No solution.")
					}
				},
			},
		},
	}.Run()
}
Exemple #12
0
//please check intel host bridge for PCIEBAR (0:0:0:60)
//usualy it's 0xE0000000
func main() {
	var Busno, Devno, Funcno, Regno, outTE *walk.TextEdit
	PCIEBAR := 14
	MainWindow{
		Title:   "PCI address Calculator",
		MinSize: Size{500, 150},
		Layout:  VBox{},
		Children: []Widget{
			HSplitter{
				Children: []Widget{
					Label{Text: "Bus:"},
					TextEdit{
						AssignTo: &Busno,
					},
					Label{Text: "Dev:"},
					TextEdit{
						AssignTo: &Devno,
					},
					Label{Text: "Func:"},
					TextEdit{
						AssignTo: &Funcno,
					},
					Label{Text: "Reg:"},
					TextEdit{
						AssignTo: &Regno,
					},
					PushButton{
						Text: "Get",
						OnClicked: func() {
							BB, _ := strconv.Atoi(Busno.Text())
							DD, _ := strconv.Atoi(Devno.Text())
							FF, _ := strconv.Atoi(Funcno.Text())
							RR, _ := strconv.Atoi(Regno.Text())
							pcimmaddr := PCIEBAR<<28 + BB<<20 + DD<<15 + FF<<12 + (RR & 0xfc)
							pciaddr := 1<<31 + BB<<16 + DD<<11 + FF<<8 + (RR & 0xfc)
							outTE.SetText(fmt.Sprintf("pci io address: %X\r\npci mmio address: %X", pciaddr, pcimmaddr))
						},
					},
				},
			},
			TextEdit{AssignTo: &outTE, ReadOnly: true},
		},
	}.Run()
}
Exemple #13
0
func main() {
	mw := new(MyMainWindow)
	var openButton *walk.PushButton
	var hostEdit, destEdit, portEdit *walk.LineEdit
	var logTextEdit *walk.TextEdit
	closeMessage := make(chan int)

	MainWindow{
		AssignTo: &mw.MainWindow,
		Title:    "SCREAMO",
		MinSize:  Size{600, 400},
		Layout:   VBox{},
		Children: []Widget{
			Composite{
				Layout: Grid{},
				Children: []Widget{
					Label{
						Row:    0,
						Column: 0,
						Text:   "JmsHost:",
					},
					LineEdit{
						AssignTo: &hostEdit,
						Row:      0,
						Column:   1,
						Text:     "192.168.1.105",
					},
					Label{
						Row:    1,
						Column: 0,
						Text:   "JmsDest:",
					},
					LineEdit{
						AssignTo: &destEdit,
						Row:      1,
						Column:   1,
						Text:     "/topic/IDC.QuoteExchange.bond2app",
					},
					Label{
						Row:    2,
						Column: 0,
						Text:   "JmsPort:",
					},
					LineEdit{
						AssignTo: &portEdit,
						Row:      2,
						Column:   1,
						Text:     "61612",
					},
				},
			},

			Composite{
				Layout: HBox{},
				Children: []Widget{
					PushButton{
						AssignTo: &openButton,
						Text:     "Open",
						OnClicked: func() {
							if openButton.Text() == "Open" {
								go openstomp(hostEdit.Text(), destEdit.Text(), portEdit.Text(), logTextEdit, closeMessage)
								openButton.SetText("Close")
							} else {
								go stopstomp(closeMessage)
								openButton.SetText("Open")
							}
						},
					},
					PushButton{
						Text: "Clear",
						OnClicked: func() {
							logTextEdit.SetText("")
						},
					},
				},
			},

			TextEdit{
				AssignTo: &logTextEdit,
				MinSize:  Size{100, 50},
				Text:     "",
				ReadOnly: true,
			},
		},
	}.Run()
}
Exemple #14
0
func sendThread(msgbox, es *walk.TextEdit) {
	sendTo := strings.Split(SJ.Send, "\r\n")
	susscess := 0
	count := len(sendTo)
	for index, to := range sendTo {
		if runing == false {
			break
		}
		msgbox.SetText("发送到" + to + "..." + strconv.Itoa((index/count)*100) + "%")
		err := SendMail(SJ.Name, SJ.Pwd, SJ.Host, to, SJ.Subject, SJ.Body, "html")
		if err != nil {
			msgbox.AppendText("\r\n失败:" + err.Error() + "\r\n")
			if err.Error() == "550 Mailbox not found or access denied" {
				SJ.Send = strings.Join(DelArrayVar(strings.Split(SJ.Send, "\r\n"), to), "\r\n")
				es.SetText(SJ.Send)
			}
			time.Sleep(1 * time.Second)
			continue
		} else {
			susscess++
			msgbox.AppendText("\r\n发送成功!")
			SJ.Send = strings.Join(DelArrayVar(strings.Split(SJ.Send, "\r\n"), to), "\r\n")
			es.SetText(SJ.Send)
		}
		time.Sleep(1 * time.Second)
	}
	SaveData()
	msgbox.AppendText("停止发送!成功 " + strconv.Itoa(susscess) + " 条\r\n")
}
Exemple #15
0
func main() {
	LoadData()
	chEnd = make(chan bool)
	var emails, body, msgbox *walk.TextEdit
	var user, password, host, subject *walk.LineEdit
	var db *walk.DataBinder
	var ep walk.ErrorPresenter
	var startBtn *walk.PushButton
	mw := new(MyMainWindow)
	mw.SetFixedSize(false)
	mw.SetMaximizeBox(false)

	MainWindow{
		Title:    "邮件群发器 By 一曲忧伤",
		MinSize:  Size{300, 200},
		AssignTo: &mw.MainWindow,
		DataBinder: DataBinder{
			AssignTo:       &db,
			DataSource:     SJ,
			ErrorPresenter: ErrorPresenterRef{&ep},
		},
		ScreenCenter: true,
		Layout:       HBox{},
		Children: []Widget{
			TextEdit{
				AssignTo:    &emails,
				Text:        SJ.Send,
				ToolTipText: "待发送邮件列表,每行一个",
			},

			VSplitter{
				Children: []Widget{
					LineEdit{
						AssignTo:  &user,
						Text:      Bind(SJ.Name, Regexp{"^([a-z0-9A-Z]+[-|\\.]?)+[a-z0-9A-Z]@([a-z0-9A-Z]+(-[a-z0-9A-Z]+)?\\.)+[a-zA-Z]{2,}$"}),
						CueBanner: "请输入邮箱用户名",
					},
					LineEdit{
						AssignTo:     &password,
						Text:         SJ.Pwd,
						PasswordMode: true,
						CueBanner:    "请输入邮箱登录密码",
					},
					LineEdit{
						AssignTo:  &host,
						Text:      Bind(SJ.Host, Regexp{"^(\\d{1,2}|1\\d\\d|2[0-4]\\d|25[0-5])\\.(\\d{1,2}|1\\d\\d|2[0-4]\\d|25[0-5])\\.(\\d{1,2}|1\\d\\d|2[0-4]\\d|25[0-5])\\.(\\d{1,2}|1\\d\\d|2[0-4]\\d|25[0-5])$"}),
						CueBanner: "SMTP服务器:端口",
					},
					LineEdit{AssignTo: &subject,
						MaxLength: 10,
						Text:      Bind(SJ.Subject, Regexp{"^([a-z0-9A-Z])+$"}),
						CueBanner: "请输入邮件主题……",
					},
					TextEdit{AssignTo: &body,
						Text:        Bind(SJ.Body, SelRequired{}),
						ToolTipText: "请输入邮件内容",
						ColumnSpan:  2,
					},
					TextEdit{AssignTo: &msgbox,
						ReadOnly: true,
					},
					LineErrorPresenter{
						AssignTo:    &ep,
						ColumnSpan:  2,
						ToolTipText: "测试",
					},
					PushButton{
						AssignTo: &startBtn,
						Text:     "开始群发",
						OnClicked: func() {
							if err := db.Submit(); err == nil {
								SJ.Name = user.Text()
								SJ.Pwd = password.Text()
								SJ.Host = host.Text()
								SJ.Subject = subject.Text()
								SJ.Body = body.Text()
								SJ.Send = emails.Text()
								SaveData()

								if runing == false {
									runing = true
									startBtn.SetText("停止发送")
									go sendThread(msgbox, emails)
								} else {
									runing = false
									startBtn.SetText("开始群发")
								}
							} else {
								return
							}

						},
					},
				},
			},
		},
	}.Run()
}