func (window *GhQueuedHighlightsWindow) build() {
	window.SetTitle("Queued Highlights")
	window.bindKeys()

	scrolledWindow := gtk.ScrolledWindow(nil, nil)
	scrolledWindow.SetPolicy(gtk.GTK_POLICY_AUTOMATIC, gtk.GTK_POLICY_AUTOMATIC)

	treeView := gtk.TreeView()
	scrolledWindow.Add(treeView)

	store := gtk.ListStore(glib.G_TYPE_STRING, glib.G_TYPE_STRING, glib.G_TYPE_DOUBLE, glib.G_TYPE_STRING, glib.G_TYPE_STRING)
	treeView.SetModel(store)

	treeView.AppendColumn(gtk.TreeViewColumnWithAttributes("Book", gtk.CellRendererText(), "text", 0))
	treeView.AppendColumn(gtk.TreeViewColumnWithAttributes("Content", gtk.CellRendererText(), "text", 1))
	treeView.AppendColumn(gtk.TreeViewColumnWithAttributes("Position", gtk.CellRendererText(), "text", 2))
	treeView.AppendColumn(gtk.TreeViewColumnWithAttributes("Timestamp", gtk.CellRendererText(), "text", 3))
	treeView.AppendColumn(gtk.TreeViewColumnWithAttributes("Comment", gtk.CellRendererText(), "text", 4))

	readings := models.Readings()
	highlights := models.Highlights()
	for _, highlight := range highlights.Items {
		var iter gtk.GtkTreeIter
		store.Append(&iter)

		reading := readings.FindByReadmillId(highlight.ReadingReadmillId)
		position := highlight.Position * 100
		timestamp := highlight.Timestamp.Format(time.Stamp)

		store.Set(&iter, reading.Title, highlight.Content, position, timestamp, highlight.Comment)
	}

	window.Add(scrolledWindow)
	window.SetSizeRequest(600, 400)
}
Exemplo n.º 2
0
func main() {
	gtk.Init(&os.Args)
	window := gtk.Window(gtk.GTK_WINDOW_TOPLEVEL)
	window.SetTitle("GTK Stock Icons")
	window.Connect("destroy", gtk.MainQuit)

	swin := gtk.ScrolledWindow(nil, nil)

	store := gtk.ListStore(glib.G_TYPE_STRING, glib.G_TYPE_BOOL, gdkpixbuf.GetGdkPixbufType())
	treeview := gtk.TreeView()
	swin.Add(treeview)

	treeview.SetModel(store.ToTreeModel())
	treeview.AppendColumn(gtk.TreeViewColumnWithAttributes("name", gtk.CellRendererText(), "text", 0))
	treeview.AppendColumn(gtk.TreeViewColumnWithAttributes("check", gtk.CellRendererToggle(), "active", 1))
	treeview.AppendColumn(gtk.TreeViewColumnWithAttributes("icon", gtk.CellRendererPixbuf(), "pixbuf", 2))
	n := 0
	gtk.GtkStockListIDs().ForEach(func(d interface{}, v interface{}) {
		id := glib.GPtrToString(d)
		var iter gtk.GtkTreeIter
		store.Append(&iter)
		store.Set(&iter, id, (n == 1), gtk.Image().RenderIcon(id, gtk.GTK_ICON_SIZE_SMALL_TOOLBAR, "").Pixbuf)
		n = 1 - n
	})

	window.Add(swin)
	window.SetSizeRequest(400, 200)
	window.ShowAll()

	gtk.Main()
}
Exemplo n.º 3
0
func main() {
	gtk.Init(&os.Args)
	window := gtk.Window(gtk.GTK_WINDOW_TOPLEVEL)
	window.SetTitle("GTK Icon View")
	window.Connect("destroy", gtk.MainQuit)

	swin := gtk.ScrolledWindow(nil, nil)

	store := gtk.ListStore(gdkpixbuf.GetGdkPixbufType(), glib.G_TYPE_STRING)
	iconview := gtk.IconViewWithModel(store)
	iconview.SetPixbufColumn(0)
	iconview.SetTextColumn(1)
	swin.Add(iconview)

	gtk.GtkStockListIDs().ForEach(func(d interface{}, v interface{}) {
		id := glib.GPtrToString(d)
		var iter gtk.GtkTreeIter
		store.Append(&iter)
		store.Set(&iter,
			gtk.Image().RenderIcon(id, gtk.GTK_ICON_SIZE_SMALL_TOOLBAR, "").Pixbuf,
			id)
	})

	window.Add(swin)
	window.SetSizeRequest(500, 200)
	window.ShowAll()

	gtk.Main()
}