Exemplo n.º 1
0
// Initialize view to reflect the model:
func (v *FilesTreeView) init(model *models.FilesTreeStore) error {
	renderer1, err := gtk.CellRendererTextNew()
	if err != nil {
		return fmt.Errorf("Error CellRendererTextNew:", err)
	}
	renderer2, err := gtk.CellRendererPixbufNew()
	if err != nil {
		return fmt.Errorf("Error CellRendererPixbufNew:", err)
	}
	col1, err := gtk.TreeViewColumnNewWithAttribute("Type", renderer2, "pixbuf", 0)
	if err != nil {
		return fmt.Errorf("Error col1:", err)
	}
	col2, err := gtk.TreeViewColumnNewWithAttribute("Name", renderer1, "text", 1)
	if err != nil {
		return fmt.Errorf("Error col2:", err)
	}
	v.view, err = gtk.TreeViewNewWithModel(model.TreeStore())
	if err != nil {
		return fmt.Errorf("Error TreeViewNew", err)
	}
	v.view.AppendColumn(col1)
	v.view.AppendColumn(col2)
	v.scrolled.Add(v.view)
	return nil
}
Exemplo n.º 2
0
// Add a column to the tree view (during the initialization of the tree view)
func createColumn(title string, id int) *gtk.TreeViewColumn {
	cellRenderer, err := gtk.CellRendererTextNew()
	if err != nil {
		log.Fatal("Unable to create text cell renderer:", err)
	}

	column, err := gtk.TreeViewColumnNewWithAttribute(title, cellRenderer, "text", id)
	if err != nil {
		log.Fatal("Unable to create cell column:", err)
	}

	return column
}
Exemplo n.º 3
0
func presenceSubscriptionDialog(accounts []*account, sendSubscription func(accountID, peer string) error) *gtk.Dialog {
	builder := builderForDefinition("AddContact")

	//TODO: move model to XML builder
	model, _ := gtk.ListStoreNew(
		glib.TYPE_STRING, // account name
		glib.TYPE_STRING, // account_id
	)

	for _, acc := range accounts {
		model.Set(model.Append(), []int{0, 1}, []interface{}{acc.session.GetConfig().Account, acc.session.GetConfig().ID()})
	}

	accountsObj, _ := builder.GetObject("accounts")
	accountInput := accountsObj.(*gtk.ComboBox)
	accountInput.SetModel(&model.TreeModel)

	accountObj, _ := builder.GetObject("address")
	contactInput := accountObj.(*gtk.Entry)

	if len(accounts) > 0 {
		accountInput.SetActive(0)
	}

	renderer, _ := gtk.CellRendererTextNew()
	accountInput.PackStart(renderer, true)
	accountInput.AddAttribute(renderer, "text", 0)

	dialogObj, _ := builder.GetObject("AddContact")
	dialog := dialogObj.(*gtk.Dialog)

	builder.ConnectSignals(map[string]interface{}{
		"on_save_signal": func() {
			defer dialog.Destroy()

			//TODO: validate contact
			contact, _ := contactInput.GetText()

			//TODO error
			iter, _ := accountInput.GetActiveIter()

			val, _ := model.GetValue(iter, 1)
			accountID, _ := val.GetString()

			//TODO error
			sendSubscription(accountID, contact)
		},
	})

	return dialog
}
Exemplo n.º 4
0
// Add a column to the tree view (during the initialization of the tree view)
// We need to distinct the type of data shown in either column.
func createTextColumn(title string, id int) *gtk.TreeViewColumn {
	// In this column we want to show text, hence create a text renderer
	cellRenderer, err := gtk.CellRendererTextNew()
	if err != nil {
		log.Fatal("Unable to create text cell renderer:", err)
	}

	// Tell the renderer where to pick input from. Text renderer understands
	// the "text" property.
	column, err := gtk.TreeViewColumnNewWithAttribute(title, cellRenderer, "text", id)
	if err != nil {
		log.Fatal("Unable to create cell column:", err)
	}

	return column
}
Exemplo n.º 5
0
func main() {
	gtk.Init(&os.Args)

	// Declarations
	Window, _ = gtk.WindowNew(gtk.WINDOW_TOPLEVEL)
	RootBox, _ = gtk.BoxNew(gtk.ORIENTATION_VERTICAL, 6)
	TreeView, _ = gtk.TreeViewNew()
	Entry, _ = gtk.EntryNew()
	ListStore, _ = gtk.ListStoreNew(glib.TYPE_STRING)

	// Window properties
	Window.SetTitle("Products written in Go")
	Window.Connect("destroy", gtk.MainQuit)

	// TreeView properties
	{
		renderer, _ := gtk.CellRendererTextNew()
		column, _ := gtk.TreeViewColumnNewWithAttribute("Value", renderer, "text", 0)
		TreeView.AppendColumn(column)
	}
	TreeView.SetModel(ListStore)

	// TreeView selection properties
	sel, _ := TreeView.GetSelection()
	sel.SetMode(gtk.SELECTION_MULTIPLE)
	sel.Connect("changed", SelectionChanged)

	// Packing
	RootBox.PackStart(TreeView, true, true, 0)
	RootBox.PackStart(Entry, false, false, 0)
	Window.Add(RootBox)

	// Populating list
	// TODO: Add more values to the list
	AppendMultipleToList("Go", "Docker", "CockroachDB")

	Window.ShowAll()
	gtk.Main()
}
Exemplo n.º 6
0
Arquivo: newgtk.go Projeto: sqp/godock
// CellRendererText creates a *gtk.CellRendererText.
func CellRendererText() *gtk.CellRendererText {
	w, _ := gtk.CellRendererTextNew()
	return w
}
Exemplo n.º 7
0
func presenceSubscriptionDialog(accounts []*account, sendSubscription func(accountID, peer string) error) *gtk.Dialog {
	builder := builderForDefinition("AddContact")

	//TODO: move model to XML builder
	model, _ := gtk.ListStoreNew(
		glib.TYPE_STRING, // account name
		glib.TYPE_STRING, // account_id
	)

	for _, acc := range accounts {
		model.Set(model.Append(), []int{0, 1}, []interface{}{acc.session.GetConfig().Account, acc.session.GetConfig().ID()})
	}

	accountsObj, _ := builder.GetObject("accounts")
	accountInput := accountsObj.(*gtk.ComboBox)
	accountInput.SetModel(&model.TreeModel)

	accountObj, _ := builder.GetObject("address")
	contactInput := accountObj.(*gtk.Entry)

	if len(accounts) > 0 {
		accountInput.SetActive(0)
	}

	renderer, _ := gtk.CellRendererTextNew()
	accountInput.PackStart(renderer, true)
	accountInput.AddAttribute(renderer, "text", 0)

	dialogObj, _ := builder.GetObject("AddContact")
	dialog := dialogObj.(*gtk.Dialog)

	obj, _ := builder.GetObject("notification-area")
	notificationArea := obj.(*gtk.Box)

	failures := 0
	var notification *gtk.InfoBar

	builder.ConnectSignals(map[string]interface{}{
		"on_save_signal": func() {
			contact, _ := contactInput.GetText()
			isJid, errmsg := verifyXmppAddress(contact)

			if !isJid && failures > 0 {
				notificationArea.Remove(notification)
				notification = buildBadUsernameNotification(errmsg)
				notificationArea.Add(notification)
				notification.ShowAll()
				failures++
				log.Printf(errmsg)
				return
			}

			if !isJid {
				notification = buildBadUsernameNotification(errmsg)
				notificationArea.Add(notification)
				notification.ShowAll()
				failures++
				log.Printf(errmsg)
				return
			}

			iter, err := accountInput.GetActiveIter()
			if err != nil {
				log.Printf("Error encountered when getting account: %v", err)
				return
			}
			val, err := model.GetValue(iter, 1)
			if err != nil {
				log.Printf("Error encountered when getting account: %v", err)
				return
			}
			accountID, err := val.GetString()
			if err != nil {
				log.Printf("Error encountered when getting account: %v", err)
				return
			}

			err = sendSubscription(accountID, contact)
			if err != nil {
				log.Printf("Error encountered when sending subscription: %v", err)
				return
			}

			dialog.Destroy()
		},
	})

	return dialog
}
Exemplo n.º 8
0
func (*RealGtk) CellRendererTextNew() (gtki.CellRendererText, error) {
	return wrapCellRendererText(gtk.CellRendererTextNew())
}