Пример #1
0
func NewBug(p chan string, btype έντομο.Type) gui.Widget {
	attrs := append([]string{"title"}, bug.ListAttributes()...)
	fields := []gui.Widget{}
	b := btype.Create()
	for _, attr := range attrs {
		fields = append(fields, gui.Row(gui.Text(attr+":"), AttributeChooser(b, attr, WriteLater)))
	}
	maintext := gui.TextArea("")
	fields = append(fields, gui.Text("Comment:"))
	fields = append(fields, maintext)
	submit := gui.Button("Submit bug")
	go func() {
		mainstr := ""
		for {
			select {
			case mainstr = <-maintext.Changes():
				// Nothing to do...
			case _ = <-submit.Clicks():
				b.ScheduleChange(mainstr)
				b.FlushPending()
				p <- "/"
				return
			}
		}
	}()
	fields = append(fields, submit)
	return gui.Column(fields...)
}
Пример #2
0
func Page() gui.Window {
	paths := make(chan string)
	x := gui.Column(Header("/", paths), BugList(paths))
	go func() {
		for {
			p := <-paths
			p = p[1:]
			fmt.Println("My path is actually", p)
			psplit := strings.SplitN(p, "-", 2)
			newp := x
			if len(psplit) != 2 {
				switch p {
				case "/", "":
					newp = gui.Column(Header(p, paths), BugList(paths))
				case "new":
					newp = gui.Column(Header(p, paths), NewBug(paths, έντομο.Type("bug")))
				default:
					if page, err := ioutil.ReadFile(".entomon/Static/" + p + ".txt"); err == nil {
						newp = gui.Column(Header(p, paths), gui.Text(string(page)))
					} else if page, err := ioutil.ReadFile(".entomon/Static/" + p + ".md"); err == nil {
						newp = gui.Column(Header(p, paths), gui.Markdown(string(page)))
					} else if page, err := ioutil.ReadFile(".entomon/Static/" + p + ".html"); err == nil {
						newp = gui.Column(Header(p, paths),
							gui.Text("This html shouldn't be escaped"), gui.Text(string(page)))
					} else {
						newp = gui.Column(Header(p, paths), gui.Text("I don't understand: "+p))
					}
				}
			} else {
				bnum, err := strconv.Atoi(psplit[1])
				if err != nil || len(psplit[0]) == 0 {
					newp = gui.Column(Header(p, paths), BugList(paths))
				} else {
					newp = gui.Column(Header(p, paths), BugPage(paths, έντομο.Type(psplit[0]), bnum))
				}
			}
			x.Updater() <- newp
			x = newp
		}
	}()
	return gui.Window{"Title", "/", x}
}
Пример #3
0
func BugList(p chan string) gui.Widget {
	bugs := []gui.Widget{}
	bl, err := bug.List()
	if err != nil {
		panic("bug.List: " + err.String())
	}
	attributes := bug.ListAttributes()
	bugtable := [][]gui.Widget{{gui.Text("id")}}
	for _, a := range attributes {
		bugtable[0] = append(bugtable[0], gui.Text(a))
	}
	bugtable[0] = append(bugtable[0], gui.Text("date"), gui.Text("bug"))
	for bnum, b := range bl {
		b.Comments() // to get attributes
		bugname := fmt.Sprint(bug, "-", bnum)
		// bugs = append(bugs, gui.Text(""), gui.Text(bugname))
		cs, err := b.Comments()
		if err != nil || len(cs) == 0 {
			continue
		}
		// for _, c := range cs {
		// 	bugs = append(bugs, gui.Text(c.Author), gui.Text(c.Date), gui.Text(c.Text))
		// }
		bid := gui.Button(bugname)
		row := []gui.Widget{bid}
		for _, a := range attributes {
			row = append(row, AttributeChooser(b, a, WriteNow))
		}
		bdate := gui.Text(cs[0].Date)
		//btitle := AttributeChooser(b, "title")
		btitle := gui.Markdown(b.Attributes["title"])
		row = append(row, bdate, btitle)
		go func() {
			for {
				select {
				case _ = <-bid.Clicks():
					p <- "/" + bugname
				case _ = <-bdate.Clicks():
					p <- "/" + bugname
				}
			}
		}()
		bugtable = append(bugtable, row)
	}
	bugs = append(bugs, gui.Text(""), gui.Text(""), gui.Table(bugtable))
	return gui.Column(bugs...)
}
Пример #4
0
func BugPage(p chan string, btype έντομο.Type, bnum int) gui.Widget {
	bl, err := btype.List()
	if err != nil {
		return gui.Text("Error: " + err.String())
	}
	if bnum >= len(bl) {
		return gui.Text(fmt.Sprint("Error: no such ", btype, " as number ", bnum))
	}
	b := bl[bnum]
	cs, err := b.Comments()
	if err != nil {
		return gui.Text("Error: " + err.String())
	}
	attrs := []gui.Widget{}
	for attr := range b.Attributes {
		attrs = append(attrs, gui.Row(gui.Text(attr+":"), AttributeChooser(b, attr, WriteNow)))
	}
	newcomment := gui.TextArea("")
	attrs = append(attrs, gui.Text("New comment:"))
	attrs = append(attrs, newcomment)
	submit := gui.Button("Add comment")
	attrs = append(attrs, submit)
	go func() {
		commentstr := ""
		for {
			select {
			case commentstr = <-newcomment.Changes():
				fmt.Println("Got nice comment:", commentstr)
				// Nothing to do...
			case _ = <-submit.Clicks():
				fmt.Println("Got add comment pushed.")
				b.AddComment(commentstr)
				p <- "/" + string(btype) + "-" + fmt.Sprint(bnum)
				return
			}
		}
	}()
	var bugs []gui.Widget
	for _, c := range cs {
		if len(c.Text) > 0 {
			bugs = append(bugs, gui.Row(gui.Text(c.Author), gui.Text(c.Date)),
				gui.Markdown(c.Text))
		}
	}
	return gui.Column(append(attrs, gui.Table(transpose(bugs)))...)
}
Пример #5
0
func RadioButtons(vs ...string) interface {
	gui.Widget
	gui.String
	gui.Changeable
} {
	var bs []interface {
		gui.Changeable
		gui.Bool
		gui.String
	}
	var ws []gui.Widget
	for _, v := range vs {
		b := gui.RadioButton(v)
		bs = append(bs, b)
		ws = append(ws, b)
	}
	col := gui.Column(ws...)
	grp := gui.RadioGroup(bs...)
	return &radiobuttons{col, grp, grp}
}
Пример #6
0
func main() {
	http.HandleFunc("/style.css", styleServer)
	buttonA := gui.Button("A")
	buttonB := gui.Button("B")
	buttonA.OnClick(func() gui.Refresh {
		fmt.Println("I clicked on button A")
		buttonB.SetString(buttonB.GetString() + buttonB.GetString())
		return gui.StillClean
	})
	buttonB.OnClick(func() gui.Refresh {
		fmt.Println("I clicked on button A")
		t := buttonB.GetString()
		buttonB.SetString(t[:len(t)/2+1])
		return gui.StillClean
	})
	iscool := gui.Checkbox()
	name := gui.EditText("Enter name here")
	hello := gui.Text("Hello world!")
	name.OnChange(func() gui.Refresh {
		hello.SetString("Hello " + name.GetString() + "!")
		return gui.StillClean
	})
	testing_checkbox := LabelledCheckbox("testing")
	testing_checkbox.OnChange(func() gui.Refresh {
		fmt.Println("Hello world")
		if testing_checkbox.GetBool() {
			testing_checkbox.SetString("this test is currently true")
		} else {
			testing_checkbox.SetString("this test is now false")
		}
		return gui.NeedsRefresh
	})

	// Now let's test out a set of radio buttons
	radio := RadioButtons("apples", "lemons", "oranges", "pears")
	radio_report := gui.Text("I like to eat tasty fruit")
	menu := gui.Menu("apples", "lemons", "oranges", "pears")
	radio.OnChange(func() gui.Refresh {
		menu.SetString(radio.GetString())
		radio_report.SetString("I like to eat " + radio.GetString())
		return gui.NeedsRefresh
	})

	menu.OnChange(func() gui.Refresh {
		radio.SetString(menu.GetString())
		radio_report.SetString("I like to eat " + radio.GetString())
		return radio.HandleChange()
	})

	err := gui.Run(12346,
		gui.Column(
			iscool,
			testing_checkbox,
			gui.Row(buttonA, buttonB),
			gui.Row(gui.Text("Name:"), name),
			hello,
			gui.Text("Goodbye world!"),
			radio,
			radio_report,
			menu,
		))
	if err != nil {
		panic("ListenAndServe: " + err.String())
	}
}