Esempio n. 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
	}
}
Esempio n. 2
0
func main() {
	expanderDir = make(map[gwu.Expander]string)
	// Create and build a window
	win := gwu.NewWindow("main", "goperu - peruse files with browser")
	win.Style().SetFullWidth()
	win.SetHAlign(gwu.HA_LEFT)
	win.SetCellPadding(2)

	//win.SetTheme(gwu.THEME_DEBUG)

	p := gwu.NewPanel()
	p.Style().SetFullWidth()
	hostname, err := os.Hostname()
	if err != nil {
		hostname = ""
	}

	link := gwu.NewLink("goperu", "https://github.com/gnewton/goperu")
	p.Add(link)
	p.AddVSpace(10)

	l := gwu.NewLabel(hostname + ": Explore")
	l.Style().SetColor(gwu.CLR_GREEN)
	p.Add(l)

	p.AddVSpace(20)

	e := makeExpander(baseDir)

	expanderDir[e] = baseDir

	p.Add(e)
	e.AddEHandler(handler, gwu.ETYPE_STATE_CHANGE)
	//e.AddEHandler(handler, gwu.ETYPE_MOUSE_DOWN)
	win.Add(p)

	// Create and start a GUI server (omitting error check)
	server := gwu.NewServer("goperu", "localhost:8081")
	server.SetText("goperu")
	server.AddWin(win)
	server.Start("") // Also opens windows list in browser
}
Esempio n. 3
0
func main() {

	os.Mkdir("wikiPages", os.FileMode(os.ModeDir|0777))
	LoadFile("wikiFile.txt")
	fileName = "wikiFile.txt"

	// Create and build a window
	win := gwu.NewWindow("main", "AlfaWiki")
	//win.Style().SetFullWidth()
	win.SetHAlign(gwu.HA_CENTER)
	win.SetCellPadding(2)

	p := gwu.NewHorizontalPanel()
	//p.Style().SetBorder2(1, gwu.BRD_STYLE_SOLID, gwu.CLR_BLACK)
	p.SetCellPadding(2)

	p = gwu.NewHorizontalPanel()
	//p.Style().Set("width","100%")
	//p.Style().SetFullHeight()
	win.Add(p)

	html = gwu.NewHtml(fmt.Sprintf("MMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMM%v", string(blackfriday.MarkdownCommon([]byte(wikiText)))))
	html.Style().Set("width", "40%")
	html.Style().Set("min-width", "40%")
	html.Style().Set("word-break", "break-all")

	tb = gwu.NewTextBox(wikiText)
	tb.SetRows(50)
	tb.SetCols(80)
	//tb.Style().Set("width","100%")
	//tb.Style().Set("min-width","20em")
	tb.AddSyncOnETypes(gwu.ETYPE_KEY_UP)
	p.Add(tb)
	p.Add(html)

	v := gwu.NewPanel()
	//v.Style().SetFullHeight().SetBorderRight2(2, gwu.BRD_STYLE_SOLID, "#777777")
	//v.Style().Set("width","20%")
	p.Add(v)

	tb.AddEHandlerFunc(func(e gwu.Event) {
		wikiText = tb.Text()
		html.SetHtml(fmt.Sprintf("MMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMM%v", string(blackfriday.MarkdownCommon([]byte(tb.Text())))))
		e.MarkDirty(html)
		ioutil.WriteFile(
			fmt.Sprintf("wikiPages/%s", fileName),
			[]byte(wikiText), os.FileMode(os.O_WRONLY|os.O_CREATE|os.O_TRUNC|0777))
	}, gwu.ETYPE_CHANGE, gwu.ETYPE_KEY_UP)

	newPageBox = gwu.NewTextBox("New Page Name")
	newPageBox.SetRows(1)
	newPageBox.SetCols(20)
	v.Add(newPageBox)

	newPageButt := gwu.NewButton("New Page")
	newPageButt.AddEHandler(&NewPageHandler{text: "Not used"}, gwu.ETYPE_CLICK)
	v.Add(newPageButt)
	v.AddVSpace(20)

	files, _ := ioutil.ReadDir("wikiPages")
	for i, f := range files {
		b := gwu.NewButton(f.Name() + " " + strconv.Itoa(i))
		b.AddEHandler(&MyButtonHandler2{text: f.Name()}, gwu.ETYPE_CLICK)
		v.Add(b)
	}

	v.AddVSpace(1000)

	// Create and start a GUI server (omitting error check)
	server := gwu.NewServer("guitest", "localhost:8081")
	server.SetText("AlfaWiki")
	win.SetTheme("debug")
	win.AddHeadHtml(`<link rel="stylesheet" type="text/css" href="/mystyle.css">`)
	server.AddWin(win)

	server.Start("main") // Also opens windows list in browser

	for {

	}

}
Esempio n. 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
}