Ejemplo n.º 1
0
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()
}
Ejemplo n.º 2
0
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()
}
Ejemplo n.º 3
0
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()
}
Ejemplo n.º 4
0
Archivo: main.go Proyecto: etel/walk
func main() {
	walk.Initialize(walk.InitParams{})
	defer walk.Shutdown()

	if _, err := runMainWindow(); err != nil {
		log.Fatal(err)
	}
}
Ejemplo n.º 5
0
Archivo: listbox.go Proyecto: 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()
}
Ejemplo n.º 6
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()
}
Ejemplo n.º 7
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.
	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()
}
Ejemplo n.º 8
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()
}
Ejemplo n.º 9
0
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()
}
Ejemplo n.º 10
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()
}
Ejemplo n.º 11
0
func main() {
	walk.Initialize(walk.InitParams{PanicOnError: true})
	defer walk.Shutdown()

	rand.Seed(time.Now().UnixNano())

	mainWnd, _ := walk.NewMainWindow()

	mw := &MainWindow{
		MainWindow: mainWnd,
		model:      NewFooModel(),
	}

	mw.SetLayout(walk.NewVBoxLayout())
	mw.SetTitle("Walk TableView Example")

	resetRowsButton, _ := walk.NewPushButton(mw)
	resetRowsButton.SetText("Reset Rows")

	resetRowsButton.Clicked().Attach(func() {
		// Get some fresh data.
		mw.model.ResetRows()
	})

	tableView, _ := walk.NewTableView(mw)

	tableView.SetAlternatingRowBGColor(walk.RGB(255, 255, 224))
	tableView.SetReorderColumnsEnabled(true)

	// Everybody loves check boxes.
	tableView.SetCheckBoxes(true)

	// Don't forget to set the model.
	tableView.SetModel(mw.model)

	mw.SetMinMaxSize(walk.Size{320, 240}, walk.Size{})
	mw.SetSize(walk.Size{800, 600})
	mw.Show()

	mw.Run()
}
Ejemplo n.º 12
0
func main() {
	walk.Initialize(walk.InitParams{PanicOnError: true})
	defer walk.Shutdown()

	mainWnd, _ := walk.NewMainWindow()

	mw := &MainWindow{MainWindow: mainWnd}
	mw.SetTitle("Walk Drawing Example")

	mw.SetLayout(walk.NewVBoxLayout())

	mw.paintWidget, _ = walk.NewCustomWidget(mw, 0, func(canvas *walk.Canvas, updateBounds walk.Rectangle) error {
		return mw.drawStuff(canvas, updateBounds)
	})
	mw.paintWidget.SetClearsBackground(true)
	mw.paintWidget.SetInvalidatesOnResize(true)

	mw.SetMinMaxSize(walk.Size{320, 240}, walk.Size{})
	mw.SetSize(walk.Size{800, 600})
	mw.Show()

	mw.Run()
}
Ejemplo n.º 13
0
Archivo: pi.go Proyecto: etel/walk
func main() {
	walk.Initialize(walk.InitParams{PanicOnError: true})
	defer walk.Shutdown()

	RunMyDialog(nil)
}
Ejemplo n.º 14
0
func main() {
	walk.Initialize(walk.InitParams{})
	defer walk.Shutdown()

	mw := new(MyMainWindow)

	openImage, err := walk.NewBitmapFromFile("../img/open.png")
	if err != nil {
		log.Fatal(err)
	}

	var openAction *walk.Action
	var recentMenu *walk.Menu

	menuActions, err := CreateActions(
		Menu{
			Text: "&File",
			Items: []MenuItem{
				Action{
					AssignTo:    &openAction,
					Text:        "&Open",
					Image:       openImage,
					OnTriggered: func() { mw.openAction_Triggered() },
				},
				Menu{
					AssignTo: &recentMenu,
					Text:     "Recent",
				},
				Action{},
				Action{
					Text:        "E&xit",
					OnTriggered: func() { walk.App().Exit(0) },
				},
			},
		})
	if err != nil {
		log.Fatal(err)
	}

	openRecent1Action := walk.NewAction()
	openRecent1Action.SetText("Blah")
	recentMenu.Actions().Add(openRecent1Action)

	openRecent2Action := walk.NewAction()
	openRecent2Action.SetText("Yadda")
	recentMenu.Actions().Add(openRecent2Action)

	openRecent3Action := walk.NewAction()
	openRecent3Action.SetText("Oink")
	recentMenu.Actions().Add(openRecent3Action)

	toolBarActions, err := CreateActions(
		ActionRef{openAction},
		Action{Text: "Show Dialog", OnTriggered: func() { mw.showDialogAction_Triggered() }})
	if err != nil {
		log.Fatal(err)
	}

	if err := (MainWindow{
		AssignTo:       &mw.MainWindow,
		Title:          "FTPS cycle finder",
		MenuActions:    menuActions,
		ToolBarActions: toolBarActions,
		MinSize:        Size{600, 400},
		Size:           Size{800, 600},
		Layout:         HBox{Margins: Margins{6, 6, 6, 6}},
		Children: []Widget{
			ToolBar{Orientation: Vertical, Actions: toolBarActions},
			Composite{
				Layout: VBox{MarginsZero: true},
				Children: []Widget{
					Composite{
						Layout: HBox{MarginsZero: true},
						Children: []Widget{
							Label{Text: "File"},
							LineEdit{ContextMenuActions: []*walk.Action{openAction}},
							ToolButton{Text: "..."},
						},
					},
					Composite{
						Layout: HBox{MarginsZero: true},
						Children: []Widget{
							PushButton{Text: "Check"},
							PushButton{Text: "Check and Fix"},
							PushButton{Text: "Clear"},
							HSpacer{},
							Label{Text: "Parameter"},
							LineEdit{MaxLength: 10},
						},
					},
					Composite{
						Layout: HBox{MarginsZero: true},
						Children: []Widget{
							LineEdit{Text: "Ready.", ReadOnly: true},
							ProgressBar{StretchFactor: 10},
						},
					},
					TextEdit{ReadOnly: true},
				},
			},
		},
	}.Create(nil)); err != nil {
		log.Fatal(err)
	}

	mw.Show()
	mw.Run()
}
Ejemplo n.º 15
0
func main() {
	walk.Initialize(walk.InitParams{PanicOnError: true})
	defer walk.Shutdown()

	mainWnd, _ := walk.NewMainWindow()

	mw := &MainWindow{
		MainWindow:    mainWnd,
		fileInfoModel: &FileInfoModel{},
	}

	mw.SetTitle("Walk File Browser Example")
	mw.SetLayout(walk.NewHBoxLayout())

	fileMenu, _ := walk.NewMenu()
	fileMenuAction, _ := mw.Menu().Actions().AddMenu(fileMenu)
	fileMenuAction.SetText("&File")

	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 File Browser Example", walk.MsgBoxOK|walk.MsgBoxIconInformation)
	})
	helpMenu.Actions().Add(aboutAction)

	splitter, _ := walk.NewSplitter(mw)

	mw.treeView, _ = walk.NewTreeView(splitter)

	mw.treeView.ItemExpanded().Attach(func(item *walk.TreeViewItem) {
		children := item.Children()
		if children.Len() == 1 && children.At(0).Text() == "" {
			mw.populateTreeViewItem(item)
		}
	})

	mw.treeView.SelectionChanged().Attach(func(old, new *walk.TreeViewItem) {
		mw.selTvwItem = new
		mw.showError(mw.fileInfoModel.ResetRows(pathForTreeViewItem(new)))
	})

	drives, _ := walk.DriveNames()

	mw.treeView.SetSuspended(true)
	for _, drive := range drives {
		driveItem := newTreeViewItem(drive[:2])
		mw.treeView.Items().Add(driveItem)
	}
	mw.treeView.SetSuspended(false)

	mw.tableView, _ = walk.NewTableView(splitter)
	mw.tableView.SetModel(mw.fileInfoModel)
	mw.tableView.SetSingleItemSelection(true)

	mw.tableView.CurrentIndexChanged().Attach(func() {
		var url string

		index := mw.tableView.CurrentIndex()
		if index > -1 {
			name := mw.fileInfoModel.items[index].Name
			url = path.Join(pathForTreeViewItem(mw.selTvwItem), name)
		}

		mw.preview.SetURL(url)
	})

	mw.preview, _ = walk.NewWebView(splitter)

	mw.SetMinMaxSize(walk.Size{600, 400}, walk.Size{})
	mw.SetSize(walk.Size{800, 600})
	mw.Show()

	mw.Run()
}
Ejemplo n.º 16
0
func main() {
	walk.Initialize(walk.InitParams{})
	defer walk.Shutdown()

	mw := new(MyMainWindow)

	var openAction *walk.Action
	var recentMenu *walk.Menu

	menuActions, err := CreateActions(
		Menu{
			Text: "&File",
			Items: []MenuItem{
				Action{
					AssignTo:    &openAction,
					Text:        "&Open",
					Image:       "../img/open.png",
					OnTriggered: func() { mw.openAction_Triggered() },
				},
				Menu{
					AssignTo: &recentMenu,
					Text:     "Recent",
				},
				Separator{},
				Action{
					Text:        "E&xit",
					OnTriggered: func() { walk.App().Exit(0) },
				},
			},
		})
	if err != nil {
		log.Fatal(err)
	}

	openRecent1Action := walk.NewAction()
	openRecent1Action.SetText("Blah")
	recentMenu.Actions().Add(openRecent1Action)

	openRecent2Action := walk.NewAction()
	openRecent2Action.SetText("Yadda")
	recentMenu.Actions().Add(openRecent2Action)

	openRecent3Action := walk.NewAction()
	openRecent3Action.SetText("Oink")
	recentMenu.Actions().Add(openRecent3Action)

	toolBarActions, err := CreateActions(
		ActionRef{openAction},
		Separator{},
		Action{Text: "Show Dialog", OnTriggered: func() { mw.showDialogAction_Triggered() }})
	if err != nil {
		log.Fatal(err)
	}

	if err := (MainWindow{
		AssignTo:       &mw.MainWindow,
		Title:          "Walk Declarative Example",
		MenuActions:    menuActions,
		ToolBarActions: toolBarActions,
		MinSize:        Size{600, 400},
		Size:           Size{1024, 768},
		Layout:         HBox{MarginsZero: true},
		Children: []Widget{
			TabWidget{
				MarginsZero: true,
				PageTitles:  []string{"golang.org/doc/", "golang.org/ref/", "golang.org/pkg/"},
				Pages: []Widget{
					WebView{URL: "http://golang.org/doc/"},
					WebView{URL: "http://golang.org/ref/"},
					WebView{URL: "http://golang.org/pkg/"},
				},
			},
		},
	}.Create()); err != nil {
		log.Fatal(err)
	}

	mw.Show()
	mw.Run()
}