Beispiel #1
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()
}
Beispiel #2
0
func main() {
	font := Font{
		Family:    "Times New Roman",
		PointSize: 13,
		Bold:      true,
	}
	usr, _ := user.Current()
	usrModel := env.NewModel(0)
	sysModel := env.NewModel(1)
	var usrTableView, sysTableView *walk.TableView
	var mw *walk.MainWindow
	MainWindow{
		Title:    "Enviroment Variable",
		Size:     Size{600, 700},
		Layout:   VBox{},
		AssignTo: &mw,
		Font:     font,
		Children: []Widget{
			VSplitter{
				Children: []Widget{
					GroupBox{
						Title:  "User variables for " + usr.Username,
						Font:   font,
						Layout: VBox{},
						Children: []Widget{
							TableView{
								AssignTo:              &usrTableView,
								AlternatingRowBGColor: walk.RGB(255, 255, 224),
								ColumnsOrderable:      true,
								Columns: []TableViewColumn{
									{Title: "name", Width: 200},
									{Title: "value"},
								},
								LastColumnStretched: true,
								Model:               usrModel,
								OnItemActivated: func() {
									index := usrTableView.CurrentIndex()
									if index != -1 {
										EditVariable(mw, usrModel, usrModel.GetVariable(index).Name, usrModel.GetVariable(index).Value)
									}
								},
							},
							Composite{
								Layout: HBox{},
								Children: []Widget{
									HSpacer{},
									PushButton{
										Text: "New...",
										OnClicked: func() {
											NewVariable(mw, usrModel)
										},
									},
									PushButton{
										Text: "Edit...",
										OnClicked: func() {
											index := usrTableView.CurrentIndex()
											if index != -1 {
												EditVariable(mw, usrModel, usrModel.GetVariable(index).Name, usrModel.GetVariable(index).Value)
											}
										},
									},
									PushButton{
										Text: "Delete",
										OnClicked: func() {
											index := usrTableView.CurrentIndex()
											if index != -1 {
												DeleteVariable(mw, usrModel, usrModel.GetVariable(index).Name)
											}
										},
									},
								},
							},
						},
					},
					GroupBox{
						Title:  "System variables",
						Font:   font,
						Layout: VBox{},
						Children: []Widget{
							TableView{
								AssignTo:              &sysTableView,
								AlternatingRowBGColor: walk.RGB(255, 255, 224),
								ColumnsOrderable:      true,
								Columns: []TableViewColumn{
									{Title: "Variable", Width: 200},
									{Title: "Value"},
								},
								LastColumnStretched: true,
								Model:               sysModel,
								OnItemActivated: func() {
									index := sysTableView.CurrentIndex()
									if index != -1 {
										EditVariable(mw, sysModel, sysModel.GetVariable(index).Name, sysModel.GetVariable(index).Value)
									}
								},
							},
							Composite{
								Layout: HBox{},
								Children: []Widget{
									HSpacer{},
									PushButton{
										Text: "New...",
										OnClicked: func() {
											NewVariable(mw, sysModel)
										},
									},
									PushButton{
										Text: "Edit...",
										OnClicked: func() {
											index := sysTableView.CurrentIndex()
											if index != -1 {
												EditVariable(mw, sysModel, sysModel.GetVariable(index).Name, sysModel.GetVariable(index).Value)
											}
										},
									},
									PushButton{
										Text: "Delete",
										OnClicked: func() {
											index := sysTableView.CurrentIndex()
											if index != -1 {
												DeleteVariable(mw, sysModel, sysModel.GetVariable(index).Name)
											}
										},
									},
								},
							},
						},
					},
				},
			},
			Composite{
				Layout: HBox{},
				Children: []Widget{
					HSpacer{},
					PushButton{
						Text: "OK",
						OnClicked: func() {
							if ApplyEnv(mw, usrModel, sysModel) {
								mw.Close()
							}
						},
					},
					PushButton{
						Text: "Cancel",
						OnClicked: func() {
							mw.Close()
						},
					},
				},
			},
		},
	}.Run()

}