Exemple #1
0
func NewTalkWindow(mv *MainWindow, listenPort int, sendPort int) {
	walk.Initialize(walk.InitParams{PanicOnError: true})
	defer walk.Shutdown()

	talkWnd, err := walk.NewMainWindow()
	if err != nil {
		return
	}

	tw := &TalkWindow{MainWindow: talkWnd, ListenPort: listenPort, SendPort: sendPort}

	tw.SetTitle("I'm listing in" + strconv.Itoa(tw.ListenPort))

	tw.ShowText, _ = walk.NewTextEdit(tw)
	tw.ShowText.SetX(10)
	tw.ShowText.SetY(10)
	tw.ShowText.SetWidth(280)
	tw.ShowText.SetHeight(300)
	tw.ShowText.SetReadOnly(true)

	tw.SendText, _ = walk.NewTextEdit(tw)
	tw.SendText.SetX(10)
	tw.SendText.SetY(320)
	tw.SendText.SetWidth(200)
	tw.SendText.SetHeight(30)

	button1, _ := walk.NewPushButton(tw)
	button1.SetText("发送")
	button1.SetX(220)
	button1.SetY(320)
	button1.SetWidth(70)
	button1.SetHeight(30)
	button1.Clicked().Attach(func() {
		tw.Send()
	})

	tw.SetSize(walk.Size{320, 400})
	tw.Show()

	go tw.Listen()
	tw.Run()
}
Exemple #2
0
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()
}
Exemple #3
0
func (te TextEdit) Create(builder *Builder) error {
	w, err := walk.NewTextEdit(builder.Parent())
	if err != nil {
		return err
	}

	return builder.InitWidget(te, w, func() error {
		if te.AssignTo != nil {
			*te.AssignTo = w
		}

		return nil
	})
}
func NewPairChatWindow(_usr, _partner User) {
	walk.SetPanicOnError(true)
	myWindow, _ := walk.NewMainWindow()

	mw := &PairChatWindow{
		MainWindow: myWindow,
		usr:        _usr,
		partner:    _partner,
		msgChan:    make(chan *NsqMsg, 1),
	}

	mw.SetTitle(fmt.Sprintf("与%s私聊", _partner.Nick))

	msgEdit, _ := walk.NewTextEdit(mw)
	mw.msgEdit = msgEdit
	mw.msgEdit.SetSize(walk.Size{530, 100})
	mw.msgEdit.SetX(10)
	mw.msgEdit.SetY(360)
	mw.msgEdit.SetReadOnly(false)

	chatView, _ := NewChatMsgView(mw)
	mw.chatView = chatView
	mw.chatView.SetSize(walk.Size{530, 350})
	mw.chatView.SetX(10)
	mw.chatView.SetY(5)

	sendBtn, _ := walk.NewPushButton(mw)
	mw.sendBtn = sendBtn
	mw.sendBtn.SetText("发送")
	mw.sendBtn.SetX(480)
	mw.sendBtn.SetY(470)
	mw.sendBtn.SetSize(walk.Size{60, 30})
	mw.sendBtn.Clicked().Attach(mw.sendBtn_OnClick)

	mw.MainWindow.Show()

	mw.msgEdit.SetFocus()
	mw.SetMinMaxSize(walk.Size{565, 550}, walk.Size{565, 550})
	mw.SetSize(walk.Size{565, 550})

	pairChatMgr.register(mw.partner.Id, mw.msgChan)
	go mw.msgRouter()

	mw.MainWindow.Run()
	pairChatMgr.unregister(mw.partner.Id)
}
Exemple #5
0
func (te TextEdit) Create(parent walk.Container) error {
	w, err := walk.NewTextEdit(parent)
	if err != nil {
		return err
	}

	return InitWidget(te, w, func() error {
		if err := w.SetText(te.Text); err != nil {
			return err
		}

		w.SetReadOnly(te.ReadOnly)

		if te.AssignTo != nil {
			*te.AssignTo = w
		}

		return nil
	})
}
Exemple #6
0
func NewTextEdit(parent walk.Container, text string, w, h, x, y int) *TextEdit {
	t, err := walk.NewTextEdit(parent)
	if err != nil {
		return nil
	}

	font, _ := walk.NewFont("微软雅黑", 9, 0)
	t.SetFont(font)

	t.SetText(text)
	t.SetWidth(w)
	t.SetHeight(h)
	t.SetX(x)
	t.SetY(y)

	te := new(TextEdit)
	te.TextEdit = t

	return te
}
func NewGroupChatWindow(_usr User) {
	walk.SetPanicOnError(true)
	myWindow, _ := walk.NewMainWindow()

	mw := &GroupChatWindow{
		MainWindow: myWindow,
		usr:        _usr,
		usrModel:   NewUsrModel(),
	}

	mw.SetTitle("简易群聊:" + _usr.Nick)

	usrList, _ := walk.NewListBox(mw)
	mw.usrList = usrList
	mw.usrList.SetModel(mw.usrModel)
	mw.usrList.SetSize(walk.Size{100, 450})
	mw.usrList.SetX(10)
	mw.usrList.SetY(5)
	mw.usrList.ItemActivated().Attach(mw.userlist_ItemActivated)
	mw.usrList.CurrentIndexChanged().Attach(mw.userlist_CurrentIndexChanged)

	msgEdit, _ := walk.NewTextEdit(mw)
	mw.msgEdit = msgEdit
	mw.msgEdit.SetSize(walk.Size{500, 100})
	mw.msgEdit.SetX(120)
	mw.msgEdit.SetY(310)
	mw.msgEdit.SetReadOnly(false)

	chatView, _ := NewChatMsgView(mw)
	mw.chatView = chatView
	mw.chatView.SetSize(walk.Size{500, 300})
	mw.chatView.SetX(120)
	mw.chatView.SetY(5)

	sendBtn, _ := walk.NewPushButton(mw)
	mw.sendBtn = sendBtn
	mw.sendBtn.SetText("发送")
	mw.sendBtn.SetX(560)
	mw.sendBtn.SetY(420)
	mw.sendBtn.SetSize(walk.Size{60, 30})
	mw.sendBtn.Clicked().Attach(mw.sendBtn_OnClick)

	mw.MainWindow.Show()

	mw.msgEdit.SetFocus()
	mw.SetMinMaxSize(walk.Size{645, 500}, walk.Size{645, 500})
	mw.SetSize(walk.Size{645, 500})

	mw.chatMgr = &ChatMgr{
		topic:   "imtech",
		channel: mw.usr.Id,
		msgChan: make(chan *NsqMsg, 1),
	}
	go Receiver.registerMsgHandler(mw.chatMgr)
	go mw.msgRouter()

	mw.MainWindow.Run()
	mw.chatMgr.reader.Stop()
	Publisher.Stop()
	pairChatMgr.release()
	os.Exit(0)

}
Exemple #8
0
func (mw *MyDialog) init(owner walk.Form) (err error) {
	// 设置最小化
	mw.SetMinimizeBox(true)
	// 禁用最大化
	mw.SetMaximizeBox(false)
	// 窗口屏幕居中
	mw.SetFixedSize(true)

	mw.Dialog, err = walk.NewDialog(owner)
	mw.checkError(err)

	succeeded := false
	defer func() {
		if !succeeded {
			mw.Dispose()
		}
	}()

	// 设置主窗体大小
	mw.SetClientSize(walk.Size{600, 450})
	mw.checkError(err)

	// 设置主窗体标题
	mw.SetTitle("邮件群发-by Cody.Guo")
	mw.checkError(err)

	// 设置上传组合窗体
	mw.ui.mailListGb, err = walk.NewGroupBox(mw)
	mw.checkError(err)

	err = mw.ui.mailListGb.SetTitle("发送邮件列表")
	mw.checkError(err)

	err = mw.ui.mailListGb.SetBounds(walk.Rectangle{7, 8, 165, 434})
	mw.checkError(err)

	// 邮件编辑框
	mw.ui.mailListLe, err = walk.NewTextEdit(mw.ui.mailListGb)
	mw.checkError(err)

	err = mw.ui.mailListLe.SetBounds(walk.Rectangle{7, 25, 155, 405})
	mw.checkError(err)

	// 邮件服务器配置
	mw.ui.mailServerGb, err = walk.NewGroupBox(mw)
	mw.checkError(err)
	err = mw.ui.mailServerGb.SetTitle("邮件服务器配置")
	mw.checkError(err)
	err = mw.ui.mailServerGb.SetBounds(walk.Rectangle{185, 8, 405, 113})
	mw.checkError(err)

	// 用户名
	mw.ui.userNameLb, err = walk.NewLabel(mw.ui.mailServerGb)
	mw.checkError(err)
	err = mw.ui.userNameLb.SetText("用户名:")
	mw.checkError(err)
	err = mw.ui.userNameLb.SetBounds(walk.Rectangle{8, 20, 80, 20})
	mw.checkError(err)

	// 用户名编辑框
	mw.ui.userNameLe, err = walk.NewLineEdit(mw.ui.mailServerGb)
	mw.checkError(err)
	mw.ui.userNameLe.SetText(MS.UserName)

	err = mw.ui.userNameLe.SetBounds(walk.Rectangle{110, 20, 150, 20})
	mw.checkError(err)

	// 密码
	mw.ui.passwdLb, err = walk.NewLabel(mw.ui.mailServerGb)
	mw.checkError(err)

	err = mw.ui.passwdLb.SetText("密码:")
	mw.checkError(err)

	err = mw.ui.passwdLb.SetBounds(walk.Rectangle{8, 50, 80, 20})
	mw.checkError(err)

	// 密码编辑框
	mw.ui.passwdLe, err = walk.NewLineEdit(mw.ui.mailServerGb)
	mw.checkError(err)
	mw.ui.passwdLe.SetText(MS.Passwd)

	err = mw.ui.passwdLe.SetBounds(walk.Rectangle{110, 50, 150, 20})
	mw.checkError(err)

	mw.ui.passwdLe.SetPasswordMode(true)

	// SMTP服务器
	mw.ui.smtpLb, err = walk.NewLabel(mw.ui.mailServerGb)
	mw.checkError(err)

	err = mw.ui.smtpLb.SetText("SMTP服务器:")
	mw.checkError(err)

	err = mw.ui.smtpLb.SetBounds(walk.Rectangle{8, 80, 90, 20})
	mw.checkError(err)

	// // SMTP服务器编辑框
	mw.ui.smtpLe, err = walk.NewLineEdit(mw.ui.mailServerGb)
	mw.checkError(err)
	mw.ui.smtpLe.SetText(MS.Smtp)

	err = mw.ui.smtpLe.SetBounds(walk.Rectangle{110, 80, 150, 20})
	mw.checkError(err)

	// PORT 25
	mw.ui.portLe, err = walk.NewLineEdit(mw.ui.mailServerGb)
	mw.checkError(err)

	mw.ui.portLe.SetBounds(walk.Rectangle{270, 80, 30, 20})
	mw.ui.portLe.SetText(MS.Port)

	// 发送配置
	mw.ui.mailContentGb, err = walk.NewGroupBox(mw)
	mw.checkError(err)

	mw.ui.mailContentGb.SetTitle("发送配置")
	err = mw.ui.mailContentGb.SetBounds(walk.Rectangle{185, 135, 405, 187})
	mw.checkError(err)

	// 邮件主题
	mw.ui.mailSubLb, err = walk.NewLabel(mw.ui.mailContentGb)
	mw.checkError(err)

	mw.ui.mailSubLb.SetText("邮件主题:")
	err = mw.ui.mailSubLb.SetBounds(walk.Rectangle{8, 20, 80, 20})
	mw.checkError(err)

	// 邮件主题编辑框
	mw.ui.mailSubLe, err = walk.NewLineEdit(mw.ui.mailContentGb)
	mw.checkError(err)
	mw.ui.mailSubLe.SetText(MS.Subject)

	err = mw.ui.mailSubLe.SetBounds(walk.Rectangle{110, 20, 150, 20})
	mw.checkError(err)

	// 邮件内容
	mw.ui.mailBodyLb, err = walk.NewLabel(mw.ui.mailContentGb)
	mw.checkError(err)

	mw.ui.mailBodyLb.SetText("邮件内容:")
	err = mw.ui.mailBodyLb.SetBounds(walk.Rectangle{8, 50, 80, 20})
	mw.checkError(err)

	// 邮件内容编辑框
	mw.ui.mailBodyLe, err = walk.NewTextEdit(mw.ui.mailContentGb)
	mw.checkError(err)

	mw.ui.mailBodyLe.SetText(MS.Body)

	err = mw.ui.mailBodyLe.SetBounds(walk.Rectangle{110, 50, 280, 100})
	mw.checkError(err)

	// 附件
	mw.ui.mailAdjLb, err = walk.NewLabel(mw.ui.mailContentGb)
	mw.checkError(err)

	mw.ui.mailAdjLb.SetText("附件:")
	err = mw.ui.mailAdjLb.SetBounds(walk.Rectangle{8, 160, 80, 20})
	mw.checkError(err)

	// 附件编辑框
	mw.ui.mailAdjLe, err = walk.NewLineEdit(mw.ui.mailContentGb)
	mw.checkError(err)

	err = mw.ui.mailAdjLe.SetBounds(walk.Rectangle{110, 160, 150, 20})
	mw.checkError(err)

	mw.ui.mailAdjLe.SetText(MS.Adjunct)

	mw.ui.mailAdjLe.SetReadOnly(true)

	// 浏览
	mw.ui.browseBtn, err = walk.NewPushButton(mw.ui.mailContentGb)
	mw.checkError(err)
	mw.ui.browseBtn.SetText("浏览")
	err = mw.ui.browseBtn.SetBounds(walk.Rectangle{270, 155, 35, 30})
	mw.checkError(err)

	// 日志
	mw.ui.logLb, err = walk.NewLabel(mw)
	mw.checkError(err)

	mw.ui.logLb.SetText("日志")

	err = mw.ui.logLb.SetBounds(walk.Rectangle{185, 325, 30, 20})
	mw.checkError(err)

	// 日志输出
	mw.ui.lv, err = NewLogView(mw)
	mw.checkError(err)

	err = mw.ui.lv.SetBounds(walk.Rectangle{185, 345, 405, 70})
	mw.checkError(err)

	log.SetOutput(mw.ui.lv)

	// 发送邮件
	mw.ui.sendBtn, err = walk.NewPushButton(mw)
	mw.checkError(err)

	mw.ui.sendBtn.SetText("开始发送")

	err = mw.ui.sendBtn.SetBounds(walk.Rectangle{350, 420, 80, 30})
	mw.checkError(err)

	// // 设置背景
	// color := walk.RGB(255, 0, 0)
	// bg, _ := walk.NewSolidColorBrush(color)
	// mw.SetBackground(bg)

	// 设置字体和图标
	fount, _ := walk.NewFont("宋体", 11, 0)
	mw.SetFont(fount)
	mw.ui.mailListGb.SetFont(fount)
	mw.ui.mailServerGb.SetFont(fount)
	mw.ui.mailContentGb.SetFont(fount)

	succeeded = true

	return nil
}