本文整理汇总了Golang中github.com/lxn/walk.NewMainWindow函数的典型用法代码示例。如果您正苦于以下问题:Golang NewMainWindow函数的具体用法?Golang NewMainWindow怎么用?Golang NewMainWindow使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了NewMainWindow函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: main
func main() {
walk.Initialize(walk.InitParams{PanicOnError: true})
defer walk.Shutdown()
mw, _ := walk.NewMainWindow()
mw.SetTitle("Walk External Widgets Example")
mw.SetLayout(walk.NewHBoxLayout())
a, _ := NewMyWidget(mw)
a.SetName("a")
b, _ := NewMyWidget(mw)
b.SetName("b")
c, _ := NewMyWidget(mw)
c.SetName("c")
mpb, _ := NewMyPushButton(mw)
mpb.SetText("MyPushButton")
mw.SetSize(walk.Size{400, 300})
mw.Show()
mw.Run()
}
示例2: init
func (mw *MyWindow) init() (err error) {
mw.SetMinimizeBox(true)
mw.SetMaximizeBox(false)
mw.SetFixedSize(true)
mw.MainWindow, _ = walk.NewMainWindow()
succeeded := false
defer func() {
if !succeeded {
mw.Dispose()
}
}()
mw.SetClientSize(walk.Size{260, 160})
mw.SetTitle("主窗体")
mw.ui.SecTitileLb, _ = walk.NewLabel(mw)
mw.ui.SecTitileLb.SetText("子窗体:")
mw.ui.SecTitileLb.SetBounds(walk.Rectangle{10, 50, 50, 20})
mw.ui.SecTitileLe, _ = walk.NewLineEdit(mw)
mw.ui.SecTitileLe.SetBounds(walk.Rectangle{60, 50, 160, 20})
mw.ui.SecTitileLe.SetWidth(150)
mw.ui.CreateBtn, _ = walk.NewPushButton(mw)
mw.ui.CreateBtn.SetText("生成子窗体")
mw.ui.CreateBtn.SetBounds(walk.Rectangle{90, 100, 75, 25})
succeeded = true
return nil
}
示例3: main
func main() {
walk.Initialize(walk.InitParams{PanicOnError: true})
defer walk.Shutdown()
myWindow, _ := walk.NewMainWindow()
myWindow.SetLayout(walk.NewVBoxLayout())
myWindow.SetTitle("LogView example")
logView, _ := NewLogView(myWindow)
logView.PostAppendText("XXX")
log.SetOutput(logView)
go func() {
for i := 0; i < 10000; i++ {
time.Sleep(100 * time.Millisecond)
log.Println("Text" + "\r\n")
}
}()
myWindow.Show()
myWindow.SetMinMaxSize(walk.Size{320, 240}, walk.Size{})
myWindow.SetSize(walk.Size{400, 500})
myWindow.Run()
}
示例4: main
func main() {
walk.Initialize(walk.InitParams{PanicOnError: true})
defer walk.Shutdown()
mainWnd, _ := walk.NewMainWindow()
mw := &MainWindow{MainWindow: mainWnd}
mw.SetTitle("Walk WebView Example")
mw.SetLayout(walk.NewVBoxLayout())
mw.urlLineEdit, _ = walk.NewLineEdit(mw)
mw.urlLineEdit.ReturnPressed().Attach(func() {
mw.webView.SetURL(mw.urlLineEdit.Text())
})
mw.webView, _ = walk.NewWebView(mw)
mw.webView.SetURL("http://golang.org")
mw.SetMinMaxSize(walk.Size{600, 400}, walk.Size{})
mw.SetSize(walk.Size{800, 600})
mw.Show()
mw.Run()
}
示例5: Create
func (mw MainWindow) Create() error {
w, err := walk.NewMainWindow()
if err != nil {
return err
}
w.SetSuspended(true)
tlwi := topLevelWindowInfo{
Name: mw.Name,
Font: mw.Font,
ToolTipText: "",
MinSize: mw.MinSize,
MaxSize: mw.MaxSize,
ContextMenuActions: mw.ContextMenuActions,
OnKeyDown: mw.OnKeyDown,
OnMouseDown: mw.OnMouseDown,
OnMouseMove: mw.OnMouseMove,
OnMouseUp: mw.OnMouseUp,
OnSizeChanged: mw.OnSizeChanged,
DataBinder: mw.DataBinder,
Layout: mw.Layout,
Children: mw.Children,
}
builder := NewBuilder(nil)
return builder.InitWidget(tlwi, w, func() error {
if err := w.SetTitle(mw.Title); err != nil {
return err
}
if err := w.SetSize(mw.Size.toW()); err != nil {
return err
}
if err := addToActionList(w.Menu().Actions(), mw.MenuActions); err != nil {
return err
}
imageList, err := walk.NewImageList(walk.Size{16, 16}, 0)
if err != nil {
return err
}
w.ToolBar().SetImageList(imageList)
if err := addToActionList(w.ToolBar().Actions(), mw.ToolBarActions); err != nil {
return err
}
w.Show()
if mw.AssignTo != nil {
*mw.AssignTo = w
}
return nil
})
}
示例6: main
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()
}
示例7: NewLoginWindow
func NewLoginWindow() {
walk.SetPanicOnError(true)
myWindow, _ := walk.NewMainWindow()
mw := &LoginWindow{MainWindow: myWindow}
//mw.SetLayout(walk.NewVBoxLayout())
mw.SetTitle("nsq client")
userLabel, _ := walk.NewLabel(mw)
userLabel.SetText("用户名:")
userLabel.SetX(20)
userLabel.SetY(10)
userLabel.SetSize(walk.Size{40, 20})
userEdit, _ := walk.NewLineEdit(mw)
userEdit.SetReadOnly(false)
userEdit.SetX(70)
userEdit.SetY(10)
userEdit.SetSize(walk.Size{200, 20})
userEdit.KeyDown().Attach(mw.onKeyDown)
mw.userEdit = userEdit
pwdLabel, _ := walk.NewLabel(mw)
pwdLabel.SetText("密码:")
pwdLabel.SetX(20)
pwdLabel.SetY(40)
pwdLabel.SetSize(walk.Size{40, 20})
pwdEdit, _ := walk.NewLineEdit(mw)
pwdEdit.SetReadOnly(false)
pwdEdit.SetX(70)
pwdEdit.SetY(40)
pwdEdit.SetSize(walk.Size{200, 20})
pwdEdit.KeyDown().Attach(mw.onKeyDown)
mw.pwdEdit = pwdEdit
loginBtn, _ := walk.NewPushButton(mw)
loginBtn.SetText("登陆")
loginBtn.SetX(120)
loginBtn.SetY(70)
loginBtn.SetSize(walk.Size{60, 30})
loginBtn.Clicked().Attach(mw.loginBtn_OnClick)
mw.loginBtn = loginBtn
mw.Show()
mw.userEdit.SetFocus()
mw.SetMinMaxSize(walk.Size{300, 150}, walk.Size{})
mw.SetSize(walk.Size{300, 150})
mw.Run()
os.Exit(0)
}
示例8: NewMainWindow
func NewMainWindow() *MyWindows {
mw := new(MyWindows)
mw.MainWindow, _ = walk.NewMainWindow()
mw.ni, err = walk.NewNotifyIcon()
checkErr(err)
icon, _ := walk.NewIconFromResourceId(3)
mw.setVipIcon(icon)
mw.addAction()
mw.ni.SetVisible(true)
return mw
}
示例9: main
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()
}
示例10: Create
func (mw MainWindow) Create() error {
w, err := walk.NewMainWindow()
if err != nil {
return err
}
tlwi := topLevelWindowInfo{
Name: mw.Name,
Disabled: mw.Disabled,
Hidden: mw.Hidden,
Font: mw.Font,
MinSize: mw.MinSize,
MaxSize: mw.MaxSize,
ContextMenuActions: mw.ContextMenuActions,
DataBinder: mw.DataBinder,
Layout: mw.Layout,
Children: mw.Children,
}
return InitWidget(tlwi, w, func() error {
if err := w.SetTitle(mw.Title); err != nil {
return err
}
if err := w.SetSize(mw.Size.toW()); err != nil {
return err
}
if err := addToActionList(w.Menu().Actions(), mw.MenuActions); err != nil {
return err
}
imageList, err := walk.NewImageList(walk.Size{16, 16}, 0)
if err != nil {
return err
}
w.ToolBar().SetImageList(imageList)
if err := addToActionList(w.ToolBar().Actions(), mw.ToolBarActions); err != nil {
return err
}
if mw.AssignTo != nil {
*mw.AssignTo = w
}
return nil
})
}
示例11: main
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()
}
示例12: NewPairChatWindow
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)
}
示例13: main
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.
ni, _ := walk.NewNotifyIcon()
defer ni.Dispose()
// Set the icon and a tool tip text.
ni.SetIcon(icon)
ni.SetToolTip("Click for info or use the context menu to exit.")
// When the left mouse button is pressed, bring up our balloon.
ni.MouseDown().Attach(func(x, y int, button walk.MouseButton) {
if button != walk.LeftButton {
return
}
ni.ShowCustom(
"Walk NotifyIcon Example",
"There are multiple ShowX methods sporting different icons.")
})
// We put an exit action into the context menu.
exitAction := walk.NewAction()
exitAction.SetText("E&xit")
exitAction.Triggered().Attach(func() { walk.App().Exit(0) })
ni.ContextMenu().Actions().Add(exitAction)
// The notify icon is hidden initially, so we have to make it visible.
ni.SetVisible(true)
// Now that the icon is visible, we can bring up an info balloon.
ni.ShowInfo("Walk NotifyIcon Example", "Click the icon to show again.")
// Run the message loop.
mw.Run()
}
示例14: main
func main() {
walk.Initialize(walk.InitParams{PanicOnError: true})
defer walk.Shutdown()
mainWnd, err := walk.NewMainWindow()
if err != nil {
return
}
mw := &MainWindow{MainWindow: mainWnd}
mw.SetTitle("SocketIm Example")
button1, _ := walk.NewPushButton(mw)
button1.SetText("start port 8000")
button1.SetX(10)
button1.SetY(10)
button1.SetWidth(100)
button1.SetHeight(30)
button1.Clicked().Attach(func() {
go NewTalkWindow(mw, 8000, 8001)
button1.SetEnabled(false)
})
button2, _ := walk.NewPushButton(mw)
button2.SetText("start port 8001")
button2.SetX(10)
button2.SetY(60)
button2.SetWidth(100)
button2.SetHeight(30)
button2.Clicked().Attach(func() {
go NewTalkWindow(mw, 8001, 8000)
button2.SetEnabled(false)
})
mw.SetSize(walk.Size{120, 150})
mw.Show()
mw.Run()
}
示例15: NewTalkWindow
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()
}