Esempio n. 1
0
func main() {
	var le *walk.LineEdit
	var wv *walk.WebView

	MainWindow{
		Title:   "Walk WebView Example",
		MinSize: Size{800, 600},
		Layout:  VBox{MarginsZero: true},
		Children: []Widget{
			LineEdit{
				AssignTo: &le,
				Text:     Bind("wv.URL"),
				OnKeyDown: func(key walk.Key) {
					if key == walk.KeyReturn {
						wv.SetURL(le.Text())
					}
				},
			},
			WebView{
				AssignTo: &wv,
				Name:     "wv",
				URL:      "http://golang.org",
			},
		},
	}.Run()
}
Esempio n. 2
0
// Spawns a window containing a webview pointed at the given URL, and waits for
// it to be closed. If the webview cannot be opened, returns an error
// immediately.
func WebviewWindow(serverURL string) (e error) {
	var mainWindow *walk.MainWindow
	var webView *walk.WebView

	log.Print("Starting to create webview window")
	if err := (declarative.MainWindow{
		AssignTo: &mainWindow,
		Title:    "WebCmd Webview",
		MinSize:  declarative.Size{600, 400},
		Size:     declarative.Size{800, 600},
		Visible:  true,
		Layout:   declarative.HBox{},
		Children: []declarative.Widget{
			declarative.WebView{
				AssignTo: &webView,
			},
		},
	}.Create()); err != nil {
		log.Println("Error while creating window. Usually happens when " +
			"compiled without -ldflags=\"-Hwindowsgui\" or a manifest. " +
			"see make.bat to compile with window support on windows.")
		return errors.New("Unable to create webview window")
	}
	log.Print("Create complete, initializing webView with URL ", serverURL)
	webView.SetURL(serverURL)

	mainWindow.Run()
	log.Print("Webview closed.")
	return nil
}
Esempio n. 3
0
func osOpenWindow(window *Window, url string, styleFlags int) {

	fmt.Println("osOpenWindow: ", window, url, styleFlags)

	var dia *walk.Dialog
	var le *walk.LineEdit
	var wv *walk.WebView

	windowStore[window.handle] = dia

	Dialog{
		AssignTo: &dia,
		Title:    "Window Title",
		MinSize:  Size{800, 600},
		Layout:   VBox{MarginsZero: true},
		Children: []Widget{
			LineEdit{
				AssignTo: &le,
				Text:     Bind("wv.URL"),
				OnKeyDown: func(key walk.Key) {
					if key == walk.KeyReturn {
						wv.SetURL(le.Text())
					}
				},
			},
			WebView{
				AssignTo: &wv,
				Name:     "wv",
				URL:      url,
			},
		},
	}.Run(mainWindow)
}
Esempio n. 4
0
File: webview.go Progetto: etel/walk
func main() {
	walk.Initialize(walk.InitParams{PanicOnError: true})
	defer walk.Shutdown()

	mw, _ := walk.NewMainWindow()
	mw.SetTitle("Walk WebView Example")
	mw.SetLayout(walk.NewVBoxLayout())
	mw.SetMinMaxSize(walk.Size{600, 400}, walk.Size{})
	mw.SetSize(walk.Size{800, 600})

	var webView *walk.WebView

	urlLineEdit, _ := walk.NewLineEdit(mw)
	urlLineEdit.ReturnPressed().Attach(func() {
		webView.SetURL(urlLineEdit.Text())
	})

	webView, _ = walk.NewWebView(mw)
	webView.SetURL("http://golang.org")

	mw.Show()
	mw.Run()
}
Esempio n. 5
0
func main() {
	var le *walk.LineEdit
	var wv *walk.WebView

	MainWindow{
		Title:   "Walk WebView Example",
		MinSize: Size{800, 600},
		Layout:  VBox{},
		Children: []Widget{
			LineEdit{
				AssignTo: &le,
				Text:     Bind("wv.URL"),
				OnReturnPressed: func() {
					wv.SetURL(le.Text())
				},
			},
			WebView{
				AssignTo: &wv,
				Name:     "wv",
				URL:      "http://golang.org",
			},
		},
	}.Run()
}
Esempio n. 6
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()
}