Example #1
0
func main() {
	// Allow app control from command line (in co-operation with the starter script):
	fmt.Println("Type 'r' to restart, 'e' to exit.")
	go func() {
		var cmd string
		for {
			fmt.Scanf("%s", &cmd)
			switch cmd {
			case "r": // restart
				os.Exit(1)
			case "e": // exit
				os.Exit(0)
			}
		}
	}()

	// Create GUI server
	server := gwu.NewServer("showcase", "")
	server.SetText("Gowut - Showcase of Features")

	server.AddSessCreatorName("show", "Showcase of Features - Gowut")
	server.AddSHandler(SessHandler{})

	// Start GUI server
	if err := server.Start("show"); err != nil {
		fmt.Println("Error: Cound not start GUI server:", err)
		return
	}
}
Example #2
0
func main() {
	// Create GUI server
	server := gwu.NewServer("guitest", "")
	//server := gwu.NewServerTLS("guitest", "", "test_tls/cert.pem", "test_tls/key.pem")
	server.SetText("Test GUI Application")

	server.AddSessCreatorName("login", "Login Window")
	server.AddSHandler(SessHandler{})

	win := gwu.NewWindow("home", "Home Window")
	l := gwu.NewLabel("Home, sweet home of " + server.Text())
	l.Style().SetFontWeight(gwu.FONT_WEIGHT_BOLD).SetFontSize("130%")
	win.Add(l)
	win.Add(gwu.NewLabel("Click on the button to login:"******"Login")
	b.AddEHandlerFunc(func(e gwu.Event) {
		e.ReloadWin("login")
	}, gwu.ETYPE_CLICK)
	win.Add(b)

	server.AddWin(win)

	server.SetLogger(log.New(os.Stdout, "", log.LstdFlags))

	// Start GUI server
	if err := server.Start(); err != nil {
		fmt.Println("Error: Cound not start GUI server:", err)
		return
	}
}
Example #3
0
func startWebServer() {
	tables := gwu.NewHorizontalPanel()
	tables.SetVAlign(gwu.VA_TOP)
	updateTables(tables)

	win := gwu.NewWindow("scrolls", "ClockworkAgent")
	win.Style().SetFullWidth()
	win.SetHAlign(gwu.HA_CENTER)
	win.Style().SetBackground(`
		url(images/background.jpg) no-repeat center center fixed;
		background-size: cover;
	`)
	win.Add(tables)
	win.AddEHandlerFunc(func(e gwu.Event) {
		updateTables(tables)
	}, gwu.ETYPE_WIN_LOAD)

	server := gwu.NewServer("", "localhost:8080")
	server.AddWin(win)
	wd, err := os.Getwd()
	deny(err)
	server.AddStaticDir("images", wd+"/images")
	server.Start("scrolls")
}
Example #4
0
func main() {
	// Create and build a window
	win := gwu.NewWindow("main", "Test GUI Window")
	win.Style().SetFullWidth()
	win.SetHAlign(gwu.HA_CENTER)
	win.SetCellPadding(2)

	// Button which changes window content
	win.Add(gwu.NewLabel("I'm a label! Try clicking on the button=>"))
	btn := gwu.NewButton("Click me")
	btn.AddEHandler(&MyButtonHandler{text: ":-)"}, gwu.ETYPE_CLICK)
	win.Add(btn)
	btnsPanel := gwu.NewNaturalPanel()
	btn.AddEHandlerFunc(func(e gwu.Event) {
		// Create and add a new button...
		newbtn := gwu.NewButton("Extra #" + strconv.Itoa(btnsPanel.CompsCount()))
		newbtn.AddEHandlerFunc(func(e gwu.Event) {
			btnsPanel.Remove(newbtn) // ...which removes itself when clicked
			e.MarkDirty(btnsPanel)
		}, gwu.ETYPE_CLICK)
		btnsPanel.Insert(newbtn, 0)
		e.MarkDirty(btnsPanel)
	}, gwu.ETYPE_CLICK)
	win.Add(btnsPanel)

	// ListBox examples
	p := gwu.NewHorizontalPanel()
	p.Style().SetBorder2(1, gwu.BRD_STYLE_SOLID, gwu.CLR_BLACK)
	p.SetCellPadding(2)
	p.Add(gwu.NewLabel("A drop-down list being"))
	widelb := gwu.NewListBox([]string{"50", "100", "150", "200", "250"})
	widelb.Style().SetWidth("50")
	widelb.AddEHandlerFunc(func(e gwu.Event) {
		widelb.Style().SetWidth(widelb.SelectedValue() + "px")
		e.MarkDirty(widelb)
	}, gwu.ETYPE_CHANGE)
	p.Add(widelb)
	p.Add(gwu.NewLabel("pixel wide. And a multi-select list:"))
	listBox := gwu.NewListBox([]string{"First", "Second", "Third", "Forth", "Fifth", "Sixth"})
	listBox.SetMulti(true)
	listBox.SetRows(4)
	p.Add(listBox)
	countLabel := gwu.NewLabel("Selected count: 0")
	listBox.AddEHandlerFunc(func(e gwu.Event) {
		countLabel.SetText("Selected count: " + strconv.Itoa(len(listBox.SelectedIndices())))
		e.MarkDirty(countLabel)
	}, gwu.ETYPE_CHANGE)
	p.Add(countLabel)
	win.Add(p)

	// Self-color changer check box
	greencb := gwu.NewCheckBox("I'm a check box. When checked, I'm green!")
	greencb.AddEHandlerFunc(func(e gwu.Event) {
		if greencb.State() {
			greencb.Style().SetBackground(gwu.CLR_GREEN)
		} else {
			greencb.Style().SetBackground("")
		}
		e.MarkDirty(greencb)
	}, gwu.ETYPE_CLICK)
	win.Add(greencb)

	// TextBox with echo
	p = gwu.NewHorizontalPanel()
	p.Add(gwu.NewLabel("Enter your name:"))
	tb := gwu.NewTextBox("")
	tb.AddSyncOnETypes(gwu.ETYPE_KEY_UP)
	p.Add(tb)
	p.Add(gwu.NewLabel("You entered:"))
	nameLabel := gwu.NewLabel("")
	nameLabel.Style().SetColor(gwu.CLR_RED)
	tb.AddEHandlerFunc(func(e gwu.Event) {
		nameLabel.SetText(tb.Text())
		e.MarkDirty(nameLabel)
	}, gwu.ETYPE_CHANGE, gwu.ETYPE_KEY_UP)
	p.Add(nameLabel)
	win.Add(p)

	// Create and start a GUI server (omitting error check)
	server := gwu.NewServer("guitest", "localhost:8081")
	server.SetText("Test GUI App")
	server.AddWin(win)
	server.Start("") // Also opens windows list in browser
}