Esempio n. 1
3
// real open file dialog
func (tmw *TaxMainWindow) openFileDia() error {
	dlg := new(walk.FileDialog)
	dlg.FilePath = tmw.prevFilePath
	dlg.Filter = "Excel Files(*.xls;*.xlsx)|*.xls;*.xlsx"
	dlg.Title = "请选择Excel文件"

	if ok, err := dlg.ShowOpen(tmw); err != nil {
		return err
	} else if !ok {
		return nil
	}

	// 拿到选择的文件的路径放入tmw struct
	tmw.prevFilePath = dlg.FilePath

	fmt.Println(tmw.prevFilePath)
	// pre clear data
	truncateData(vatTable)
	// invoke taxxlsx read and save 2 db
	if iSuc := xls.ReadAndSave(tmw.prevFilePath); iSuc {
		walk.MsgBox(tmw, "成功", "导入成功", walk.MsgBoxIconInformation)
		// 显示默认列表数据
		model.RestRows(defaDisplayData())
	}
	return nil
}
Esempio n. 2
0
func DeleteVariable(mw *walk.MainWindow, m *env.Model, name string) {
	if win.IDYES == walk.MsgBox(mw, "Information", "You want to delete variable "+name, walk.MsgBoxYesNo) {
		if !m.DeleteVariable(name) {
			walk.MsgBox(mw, "Error", "Please ensure the variable has already existed.", walk.MsgBoxOK)
		}
	}
}
Esempio n. 3
0
func (mw *MyWindow) OpenAdmin() {
	if mw.urlIP == "" {
		walk.MsgBox(mw, "提示信息", "请先点击切换IP,再点击打开后台管理页面按钮。", walk.MsgBoxIconInformation)
		return
	}

	url := fmt.Sprintf("http://%s/admin", mw.urlIP)
	if mw.urlIP == "114.114.114.114" {
		url = "http://www.baidu.com"
	}
	walk.MsgBox(mw, "提示信息", fmt.Sprintf("正在尝试打开管理后台:%s,请耐心等待!", url), walk.MsgBoxIconInformation)
	for mw.ok {
		url = fmt.Sprintf("http://%s/admin", mw.urlIP)
		if mw.urlIP == "114.114.114.114" {
			url = "http://www.baidu.com"
		}
		info := fmt.Sprintf("%s正在尝试打开管理后台: %s\n", INFO, url)
		mw.lv.PostAppendText(info)
		resp, err := http.Get(url)
		if err != nil {
			time.Sleep(3 * time.Second)
			continue
		}
		if resp.StatusCode == http.StatusOK {
			cmd := fmt.Sprintf("cmd /k start %s", url)
			mw.iman.DoCmd(cmd)
			mw.iman.Run()
			resp.Body.Close()
			walk.MsgBox(mw, "提示信息", "服务器连接正常,可通过浏览器进行管理!", walk.MsgBoxIconWarning)
			return
		}
		resp.Body.Close()
	}

}
Esempio n. 4
0
func ApplyEnv(mw *walk.MainWindow, usrModel *env.Model, sysModel *env.Model) bool {
	if err := usrModel.Apply(); err != nil {
		walk.MsgBox(mw, "Error", fmt.Sprintf("%s", err), walk.MsgBoxOK)
		return false
	}
	if err := sysModel.Apply(); err != nil {
		walk.MsgBox(mw, "Error", fmt.Sprintf("%s", err), walk.MsgBoxOK)
		return false
	}
	return true
}
Esempio n. 5
0
/**
** 查看所有项目的方法
**/
func CreateProj_Query(owner walk.Form) {
	var dlg *walk.Dialog
	var tv *walk.TableView
	var dialog = Dialog{}
	model := xorm.NewProjectModel()

	dialog.AssignTo = &dlg
	dialog.Title = "项目管理"
	dialog.Layout = VBox{}
	dialog.MinSize = Size{650, 300}
	dialog.Children = []Widget{
		TableView{
			AssignTo:              &tv,
			AlternatingRowBGColor: walk.RGB(255, 255, 224),
			ColumnsOrderable:      true,
			Columns: []TableViewColumn{
				{Title: "编号", Width: 50},
				{Title: "名称"},
				{Title: "创建者"},
				{Title: "创建时间", Format: "2006-01-02 15:04:05", Width: 130},
				{Title: "描述", Width: 200},
			},
			Model: model,
		},
		Composite{
			Layout: HBox{},
			Children: []Widget{
				HSpacer{},
				PushButton{
					Text: "创建",
					OnClicked: func() {
						CreateProj_Triggered(owner, model)
					},
				},
				PushButton{
					Text: "删除",
					OnClicked: func() {
						indexs := tv.SelectedIndexes()
						if indexs.Len() == 0 {
							walk.MsgBox(owner, "提示", "请选择要删除的数据", walk.MsgBoxIconError)
							return
						}
						walk.MsgBox(owner, "提示", "确认是否删除此工程", walk.MsgBoxOKCancel)

						obj := model.GetItemByindex(int64(indexs.At(0)))
						xorm.DeleteProjectByObj(obj)
						model.ResetRows()
					},
				},
			},
		},
	}
	dialog.Run(owner)
}
Esempio n. 6
0
func EditVariable(mw *walk.MainWindow, m *env.Model, name string, value string) {
	if ret, newName, newValue := ShowDialog(mw, name, value); ret == 0 {
		if newName != name {
			walk.MsgBox(mw, "Error", "You can't change the variable name when editing.", walk.MsgBoxOK)
			return
		}
		if !m.EditVariable(name, newValue) {
			walk.MsgBox(mw, "Error", "Please ensure the variable has already existed.", walk.MsgBoxOK)
			return
		}
	}
}
Esempio n. 7
0
func (mw *MyMainWindow) openAddd_Triggered() {
	fmt.Println(mw.Size())
	if err := db.Submit(); err != nil {
		log.Println(err)
		walk.MsgBox(mw, "错误提示", err.Error(), walk.MsgBoxIconError)

		return
	}
	UserConfig.SaveConfig()
	walk.MsgBox(mw, "提示信息", "保存用户成功.", walk.MsgBoxIconInformation)

}
Esempio n. 8
0
func (mw *MyWindow) msg(level, message string) {
	switch level {
	case "INFO":
		walk.MsgBox(mw, "提示信息", message, walk.MsgBoxIconInformation)
		log.Printf("%s\n", message)
	case "DEBUG":
		walk.MsgBox(mw, "警告信息", message, walk.MsgBoxIconWarning)
		log.Printf("%s\n", message)
	case "ERROR":
		walk.MsgBox(mw, "错误信息", message, walk.MsgBoxIconError)
		log.Printf("%s\n", message)
	}
}
Esempio n. 9
0
func NewVariable(mw *walk.MainWindow, m *env.Model) {
	if ret, name, value := ShowDialog(mw, "", ""); ret == 0 {
		if !m.AddVariable(name, value) {
			walk.MsgBox(mw, "Error", "The variable has already existed.", walk.MsgBoxOK)
		}
	}
}
Esempio n. 10
0
func (mw *PersonMainWindow) tv_ItemActivated() {
	msg := ``
	for _, i := range mw.tv.SelectedIndexes() {
		msg = msg + "\n" + mw.model.items[i].Name
	}
	walk.MsgBox(mw, "title", msg, walk.MsgBoxIconInformation)
}
Esempio n. 11
0
func (mw *MainWindow) showError(err error) {
	if err == nil {
		return
	}

	walk.MsgBox(mw, "Error", err.Error(), walk.MsgBoxOK|walk.MsgBoxIconError)
}
Esempio n. 12
0
func (mw *MyWindow) msg(level string, message string) {
	switch level {
	case INFO:
		log.SetPrefix(INFO)
		title := "提示信息"
		log.Printf("%s\n", message)
		mw.notifyIcon.ShowInfo(title, message)
		walk.MsgBox(mw, title, message, walk.MsgBoxIconInformation)
	case DEBUG:
		log.SetPrefix(DEBUG)
		title := "警告信息"
		log.Printf("%s\n", message)
		mw.notifyIcon.ShowWarning(title, message)
		walk.MsgBox(mw, title, message, walk.MsgBoxIconWarning)
	}
}
Esempio n. 13
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
}
Esempio n. 14
0
func (mw *MyDialog) myMsg(title, message string, style walk.MsgBoxStyle) {
	switch style {
	case walk.MsgBoxIconInformation:
		mw.ni.ShowInfo(title, message)
	case walk.MsgBoxIconWarning:
		mw.ni.ShowWarning(title, message)
	}
	log.Println(message)
	walk.MsgBox(mw, title, message, style)
}
Esempio n. 15
0
File: listbox.go Progetto: etel/walk
func main() {
	walk.Initialize(walk.InitParams{PanicOnError: true})
	defer walk.Shutdown()

	myWindow, _ := walk.NewMainWindow()

	myWindow.SetLayout(walk.NewVBoxLayout())
	myWindow.SetTitle("Listbox example")

	splitter, _ := walk.NewSplitter(myWindow)
	splitter.SetOrientation(walk.Vertical)

	lb, _ := walk.NewListBox(splitter)

	valueEdit, _ := walk.NewTextEdit(splitter)
	valueEdit.SetReadOnly(true)

	//env model
	em := NewEnvModel()

	for _, env := range os.Environ() {
		i := strings.Index(env, "=")
		if i == 0 {
			continue
		}
		varName := env[0:i]
		value := env[i+1:]
		envItem := EnvItem{varName, value}

		em.envItems = append(em.envItems, envItem)
	}

	fmt.Println("The len of Model", em.ItemCount())
	lb.SetModel(em)
	lb.CurrentIndexChanged().Attach(func() {
		if curVar, ok := em.Value(lb.CurrentIndex()).(string); ok {
			value := em.envItems[lb.CurrentIndex()].value
			value = strings.Replace(value, ";", "\r\n", -1)
			valueEdit.SetText(value)
			fmt.Println("CurrentIndex:", lb.CurrentIndex())
			fmt.Println("CurrentEnvVarName:", curVar)
		}
	})
	lb.DblClicked().Attach(func() {
		value := em.envItems[lb.CurrentIndex()].value
		value = strings.Replace(value, ";", "\r\n", -1)
		valueEdit.SetText(value)
		walk.MsgBox(myWindow, "About", value, walk.MsgBoxOK|walk.MsgBoxIconInformation)
	})
	myWindow.Show()
	myWindow.SetMinMaxSize(walk.Size{320, 240}, walk.Size{})
	myWindow.SetSize(walk.Size{400, 500})
	myWindow.Run()
}
Esempio n. 16
0
func downLoadXCGUIDll() {
	mw, _ := walk.NewMainWindow()
	ret := walk.MsgBox(mw, "下载提示", "没有找到XCGUI.dll,是否要联网下载?", walk.MsgBoxIconQuestion+walk.MsgBoxOKCancel)
	if ret != 1 {
		walk.MsgBox(mw, "警告信息", "请在重新运行程序前将XCGUI.dll放到运行目录.", walk.MsgBoxIconWarning)
		mw.Close()
		os.Exit(1)
	}

	resp, err := http.Get("http://git.oschina.net/CodyGuo/xcgui/raw/master/lib/XCGUI.dll")
	if err != nil {
		log.Println("[ERROR] 下载失败,请检查网络.")
		walk.MsgBox(mw, "错误信息", "XCGUI.dll 下载失败,请检查网络.", walk.MsgBoxIconError)
		mw.Close()
	}

	if resp.StatusCode == http.StatusOK {
		log.Println("[INFO] 正在下载 XCGUI.dll .")

		downFile, err := os.Create("XCGUI.dll")
		if err != nil {
			log.Fatal(err)
		}
		// 不要忘记关闭打开的文件.
		defer downFile.Close()

		body, err := ioutil.ReadAll(resp.Body)
		io.Copy(downFile, bytes.NewReader(body))
		log.Println("[INFO] XCGUI.dll 下载成功.正在运行主程序.")

		walk.MsgBox(mw, "提示信息", "下载成功, 请点击确定继续运行程序.", walk.MsgBoxIconInformation)
		mw.Close()
	} else {
		log.Printf("[ERROR] 下载失败,%s.\n", resp.Status)

		walk.MsgBox(mw, "错误信息", "[ERROR] 下载失败,请检查网络.", walk.MsgBoxIconError)
		mw.Close()
	}

	mw.Run()
}
Esempio n. 17
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()
}
Esempio n. 18
0
func (nw *NetWin) sendAndResp() {
	str := nw.input.Text()
	err := nw.connSend(str)
	if err != nil {
		walk.MsgBox(nw, "发送", "连接服务器失败", walk.MsgBoxOK)
		return
	}

	go func() {
		var buf []byte
		var ch chan int
		ch <- nw.data.se.Read(buf)
		select {
		case ch <- 0:
			walk.MsgBox(nw, "响应", "获取返回失败", walk.MsgBoxOK)
			break
		default:
			jklog.L().Infoln("buf: ", buf)
			break
		}
	}()
}
Esempio n. 19
0
func (mw *MyDialog) MyMsg(title, message string, style walk.MsgBoxStyle) (result int) {
	switch style {
	case walk.MsgBoxIconInformation, walk.MsgBoxOKCancel + walk.MsgBoxIconInformation:
		mw.ni.ShowInfo(title, message)
	case walk.MsgBoxIconWarning:
		mw.ni.ShowWarning(title, message)
	case walk.MsgBoxIconError:
		mw.ni.ShowError(title, message)
	}

	result = walk.MsgBox(mw, title, message, style)

	return
}
Esempio n. 20
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()
}
Esempio n. 21
0
File: main.go Progetto: xausee/touch
func main() {
	con, ok := sign.CreateSingInWindow()
	if ok {
		fl, err := con.GetFriends()
		if err != nil {
			walk.MsgBox(nil, "错误", err.Error(), walk.MsgBoxOK)
		}
		model := mainwin.NewUserModel(fl)

		win := &mainwin.TouchMainWindow{Model: model, Connect: con}
		win.Create()
		win.Run()
		con.Disconnect()
	}
}
Esempio n. 22
0
func main() {
	walk.Initialize(walk.InitParams{PanicOnError: true})
	defer walk.Shutdown()

	myWindow, _ := walk.NewMainWindow()

	myWindow.SetLayout(walk.NewVBoxLayout())
	myWindow.SetTitle("Go GUI example")

	myButton1, _ := walk.NewPushButton(myWindow)
	myButton1.SetText("XXXX")

	lb, _ := walk.NewListBox(myWindow)

	em := NewEnvModel()

	for _, env := range os.Environ() {
		i := strings.Index(env, "=")
		if i == 0 {
			continue
		}
		varName := env[0:i]
		value := env[i+1:]
		envItem := EnvItem{varName, value}

		em.envItems = append(em.envItems, envItem)
	}

	fmt.Println("The len of Model", em.ItemCount())
	lb.SetModel(em)
	lb.CurrentIndexChanged().Attach(func() {
		if curVar, ok := em.Value(lb.CurrentIndex()).(string); ok {
			myButton1.SetText(curVar)
			fmt.Println("CurrentIndex:", lb.CurrentIndex())
			fmt.Println("CurrentEnvVarName:", curVar)
		}
	})
	lb.DblClicked().Attach(func() {
		value := em.envItems[lb.CurrentIndex()].value
		walk.MsgBox(myWindow, "About", value, walk.MsgBoxOK|walk.MsgBoxIconInformation)
	})
	myWindow.Show()
	myWindow.SetMinMaxSize(walk.Size{320, 240}, walk.Size{})
	myWindow.SetSize(walk.Size{400, 500})
	myWindow.Run()
}
Esempio n. 23
0
func RunMaster() (err error) {
	mw := new(MyWindow)
	err = mw.init()
	if err != nil {
		return err
	}

	mw.SetScreenCenter(true)
	mw.SetForegroundWindow()
	mw.SwitchToThisWindow(true)

	var runNum int
	mw.ui.CreateBtn.Clicked().Attach(func() {
		if mw.ui.SecTitileLe.Text() != "" {
			runNum += 1
			if runNum > 1 {
				// 只允许打开一个子窗体
				dlg.Dispose()
			}
			RunChild(mw, mw.ui.SecTitileLe.Text())
		} else {
			walk.MsgBox(mw, "提示", "请填写子窗体标题.", walk.MsgBoxIconInformation)
		}
	})

	// 主窗体关闭时,关闭子窗体
	mw.Closing().Attach(func(canceled *bool, reason walk.CloseReason) {
		if reason == walk.CloseReasonUnknown {
			if runNum >= 1 {
				dlg.Close(0)
			}
		} else {
			defer dlg.Close(1)
		}
	})

	mw.Show()
	fmt.Println("主窗体运行中...--> 【 " + mw.Title() + " 】.")
	ok := mw.Run()
	if ok != 0 {
		return errors.New("运行主窗体错误.")
	}

	return nil
}
Esempio n. 24
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.
	notifyIcon, _ := walk.NewNotifyIcon()
	defer notifyIcon.Dispose()

	// Set the icon and a tool tip text.
	notifyIcon.SetIcon(icon)
	notifyIcon.SetToolTip("Click for info or use the context menu to exit.")

	// When the left mouse button is pressed, bring up our about box.
	notifyIcon.MouseDown().Attach(func(x, y int, button walk.MouseButton) {
		if button != walk.LeftButton {
			return
		}

		walk.MsgBox(mw, "About", "Walk NotifyIcon Example", walk.MsgBoxIconInformation)
	})

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

	// The notify icon is hidden initially, so we have to make it visible.
	notifyIcon.SetVisible(true)

	// Run the message loop.
	mw.Run()
}
Esempio n. 25
0
func (mw *MyMainWindow) openAction_Triggered() {
	walk.MsgBox(mw, "Open", "Nothing to see here...", walk.MsgBoxIconInformation|walk.MsgBoxOK)
}
Esempio n. 26
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()
}
Esempio n. 27
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()
}
Esempio n. 28
0
func (mw *MyMainWindow) lb_ItemActivated() {
	value := mw.model.items[mw.lb.CurrentIndex()].value

	walk.MsgBox(mw, "Value", value, walk.MsgBoxIconInformation)
}
Esempio n. 29
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()
}
Esempio n. 30
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()
}