1 Star 0 Fork 1

pispanda / walk

forked from arao / walk 
加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
listbox.go 1.92 KB
一键复制 编辑 原始数据 按行查看 历史
U-ultrahorst\elmar 提交于 2015-12-19 19:26 . remove unused method
// Copyright 2012 The Walk Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package main
import (
"fmt"
"log"
"os"
"strings"
)
import (
"github.com/lxn/walk"
. "github.com/lxn/walk/declarative"
)
func main() {
mw := &MyMainWindow{model: NewEnvModel()}
if _, err := (MainWindow{
AssignTo: &mw.MainWindow,
Title: "Walk ListBox Example",
MinSize: Size{240, 320},
Size: Size{300, 400},
Layout: VBox{MarginsZero: true},
Children: []Widget{
HSplitter{
Children: []Widget{
ListBox{
AssignTo: &mw.lb,
Model: mw.model,
OnCurrentIndexChanged: mw.lb_CurrentIndexChanged,
OnItemActivated: mw.lb_ItemActivated,
},
TextEdit{
AssignTo: &mw.te,
ReadOnly: true,
},
},
},
},
}.Run()); err != nil {
log.Fatal(err)
}
}
type MyMainWindow struct {
*walk.MainWindow
model *EnvModel
lb *walk.ListBox
te *walk.TextEdit
}
func (mw *MyMainWindow) lb_CurrentIndexChanged() {
i := mw.lb.CurrentIndex()
item := &mw.model.items[i]
mw.te.SetText(item.value)
fmt.Println("CurrentIndex: ", i)
fmt.Println("CurrentEnvVarName: ", item.name)
}
func (mw *MyMainWindow) lb_ItemActivated() {
value := mw.model.items[mw.lb.CurrentIndex()].value
walk.MsgBox(mw, "Value", value, walk.MsgBoxIconInformation)
}
type EnvItem struct {
name string
value string
}
type EnvModel struct {
walk.ListModelBase
items []EnvItem
}
func NewEnvModel() *EnvModel {
env := os.Environ()
m := &EnvModel{items: make([]EnvItem, len(env))}
for i, e := range env {
j := strings.Index(e, "=")
if j == 0 {
continue
}
name := e[0:j]
value := strings.Replace(e[j+1:], ";", "\r\n", -1)
m.items[i] = EnvItem{name, value}
}
return m
}
func (m *EnvModel) ItemCount() int {
return len(m.items)
}
func (m *EnvModel) Value(index int) interface{} {
return m.items[index].name
}
Go
1
https://gitee.com/pispanda/walk.git
git@gitee.com:pispanda/walk.git
pispanda
walk
walk
a5fea13dfac9

搜索帮助