Exemplo n.º 1
0
func uiSetup() {
	var err error

	cssProvider, err = gtk.CssProviderNew()
	e.Exit(err)
	err = cssProvider.LoadFromData(css)
	e.Exit(err)

	w.count, err = gtk.SpinButtonNewWithRange(1, 999, 1)
	e.Exit(err)
	w.count.SetValue(1)

	shuffle, err := gtk.ButtonNewWithLabel("Shuffle")
	e.Exit(err)

	w.showActionsText, err = gtk.CheckButtonNewWithMnemonic("Show actions _text")
	e.Exit(err)
	w.showPermutation, err = gtk.CheckButtonNewWithMnemonic("Show _permutation")
	e.Exit(err)

	w.cellSize, err = gtk.SpinButtonNewWithRange(1, 999, 1)
	e.Exit(err)
	w.cellSize.SetValue(32)

	cellSizeLabel, err := gtk.LabelNew("Cell size:")
	e.Exit(err)

	w.count.Connect("changed", uiShuffle)
	w.count.Connect("activate", uiShuffle)
	shuffle.Connect("clicked", uiShuffle)
	w.showActionsText.Connect("toggled", uiReset)
	w.showPermutation.Connect("toggled", uiReset)
	w.cellSize.Connect("changed", uiReset)

	panel, err := gtk.BoxNew(gtk.ORIENTATION_HORIZONTAL, 0)
	e.Exit(err)
	panel.SetSpacing(5)
	panel.Add(w.count)
	panel.Add(shuffle)
	panel.Add(w.showActionsText)
	panel.Add(w.showPermutation)
	panel.Add(cellSizeLabel)
	panel.Add(w.cellSize)

	w.fieldWindow, err = gtk.ScrolledWindowNew(nil, nil)
	e.Exit(err)

	layout, err := gtk.BoxNew(gtk.ORIENTATION_VERTICAL, 0)
	e.Exit(err)
	layout.Add(panel)
	layout.PackStart(w.fieldWindow, true, true, 0)

	window, err := gtk.WindowNew(gtk.WINDOW_TOPLEVEL)
	e.Exit(err)
	window.SetTitle(title)
	window.Add(layout)
	window.Connect("destroy", gtk.MainQuit)
	uiShuffle()
	window.ShowAll()
}
Exemplo n.º 2
0
func setup_box(orient gtk.Orientation) *gtk.Box {
	box, err := gtk.BoxNew(orient, 0)
	if err != nil {
		log.Fatal("Unable to create box:", err)
	}
	return box
}
Exemplo n.º 3
0
func setupPropertyCheckboxes(tv *gtk.TextView, outer *gtk.Box, props []*BoolProperty) {
	box, _ := gtk.BoxNew(gtk.ORIENTATION_HORIZONTAL, 0)
	for _, prop := range props {
		chk, _ := gtk.CheckButtonNewWithLabel(prop.Name)
		// initialize the checkbox with the property's current value
		chk.SetActive(prop.Get())
		p := prop // w/o this all the checkboxes will toggle the last property in props
		chk.Connect("toggled", func() {
			p.Set(chk.GetActive())
		})
		box.PackStart(chk, true, true, 0)
	}
	outer.PackStart(box, false, false, 0)
}
Exemplo n.º 4
0
func (dialog *EditMenuDialog) fillStack() error {
	for _, a := range stackAlternatives {
		box, err := gtk.BoxNew(gtk.ORIENTATION_VERTICAL, 6)
		if err != nil {
			return err
		}
		err = dialog.fillBox(box, a)
		if err != nil {
			return err
		}
		dialog.stack.AddNamed(box, string(a))
	}
	return nil
}
Exemplo n.º 5
0
// Initialize the game widgets
func (self *MainWindow) InitializeWidgets() {

	self.BoardView, self.err = gtk.DrawingAreaNew()
	self.MainArea, self.err = gtk.BoxNew(gtk.ORIENTATION_HORIZONTAL, 1)
	self.ScoreArea, self.err = gtk.BoxNew(gtk.ORIENTATION_VERTICAL, 2)
	self.BoardEventBox, self.err = gtk.EventBoxNew()
	self.Scores, self.err = gtk.LabelNew("Scores:")
	self.BlacksScore, self.err = gtk.LabelNew("Black pieces:")
	self.RedsScore, self.err = gtk.LabelNew("Black pieces:")
	self.BoardWidth = 640
	self.BoardHeight = 480
	self.BoardEventBox.Add(self.BoardView)
	if self.err != nil {
		log.Fatal("Failed to draw board")
	}

	self.BoardEventBox.AddEvents(int(gdk.BUTTON_PRESS_MASK))
	self.BoardEventBox.Connect("button_press_event", self.interactBoard)
	self.MainArea.PackStart(self.BoardEventBox, true, true, 10)
	self.MainArea.Add(self.ScoreArea)

	self.Scores.SetMarkup("<strong>%s</strong>")
	self.Scores.SetJustify(gtk.JUSTIFY_CENTER)

	self.ScoreArea.Add(self.Scores)
	self.BlacksScore.SetJustify(gtk.JUSTIFY_LEFT)
	self.RedsScore.SetJustify(gtk.JUSTIFY_LEFT)
	self.ScoreArea.Add(self.BlacksScore)
	self.ScoreArea.Add(self.RedsScore)

	self.Window.Add(self.MainArea)
	self.setBoardSize(8)
	self.BoardView.Connect("draw", self.drawBoard)
	self.Board.RenderText()

	self.Window.SetTitle("Checkers")
}
Exemplo n.º 6
0
// TestConnectNotifySignal ensures that property notification signals (those
// whose name begins with "notify::") are queried by the name "notify" (with the
// "::" and the property name omitted). This is because the signal is "notify"
// and the characters after the "::" are not recognized by the signal system.
//
// See
// https://developer.gnome.org/gobject/stable/gobject-The-Base-Object-Type.html#GObject-notify
// for background, and
// https://developer.gnome.org/gobject/stable/gobject-Signals.html#g-signal-new
// for the specification of valid signal names.
func TestConnectNotifySignal(t *testing.T) {
	runtime.LockOSThread()

	// Create any GObject that has defined properties.
	spacing := 0
	box, _ := gtk.BoxNew(gtk.ORIENTATION_HORIZONTAL, spacing)

	// Connect to a "notify::" signal to listen on property changes.
	box.Connect("notify::spacing", func() {
		gtk.MainQuit()
	})

	glib.IdleAdd(func(s string) bool {
		t.Log(s)
		spacing++
		box.SetSpacing(spacing)
		return true
	}, "IdleAdd executed")

	gtk.Main()
}
Exemplo n.º 7
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.º 8
0
func main() {
	gtk.Init(nil)

	win := setupWindow()
	box, _ := gtk.BoxNew(gtk.ORIENTATION_VERTICAL, 0)
	win.Add(box)

	tv := setupTextView(box)

	props := []*BoolProperty{
		&BoolProperty{"cursor visible", (*tv).GetCursorVisible, (*tv).SetCursorVisible},
		&BoolProperty{"editable", (*tv).GetEditable, (*tv).SetEditable},
		&BoolProperty{"overwrite", (*tv).GetOverwrite, (*tv).SetOverwrite},
		&BoolProperty{"accepts tab", (*tv).GetAcceptsTab, (*tv).SetAcceptsTab},
	}

	setupPropertyCheckboxes(tv, box, props)

	win.ShowAll()

	gtk.Main()
}
Exemplo n.º 9
0
func GraphViewCollectionNew(width, height int) (gvc *graphViewCollection, err error) {
	gvc = &graphViewCollection{}
	gvc.gmap = make(map[string]GraphViewIf)
	gvc.box, err = gtk.BoxNew(gtk.ORIENTATION_VERTICAL, 0)
	if err != nil {
		err = fmt.Errorf("GraphViewCollectionNew: Unable to create box:", err)
		return
	}
	gvc.header, err = gtk.HeaderBarNew()
	if err != nil {
		err = fmt.Errorf("GraphViewCollectionNew: Unable to create bar:", err)
		return
	}
	gvc.tabs, err = gtk.StackSwitcherNew()
	if err != nil {
		err = fmt.Errorf("GraphViewCollectionNew: Unable to create stackswitcher:", err)
		return
	}
	gvc.stack, err = gtk.StackNew()
	if err != nil {
		err = fmt.Errorf("GraphViewCollectionNew: Unable to create Stack:", err)
		return
	}
	gvc.box.PackStart(gvc.header, false, true, 0)
	gvc.header.Add(gvc.tabs)
	gvc.tabs.SetStack(gvc.stack)
	gvc.box.Add(gvc.stack)

	gvc.xmlview, err = XmlTextViewNew(width, height)
	if err != nil {
		err = fmt.Errorf("GraphViewCollectionNew: Could not create XML view.")
		return
	}
	gvc.stack.AddTitled(gvc.xmlview.Widget(), "XML View", "XML View")
	return
}
Exemplo n.º 10
0
func (v *ScaledView) init() (err error) {
	v.layoutBox, err = gtk.BoxNew(gtk.ORIENTATION_VERTICAL, 0)
	if err != nil {
		return
	}
	const (
		initialWidth  = 800
		initialHeight = 600
	)
	v.scene, err = ScrolledViewNew(initialWidth, initialHeight)
	if err != nil {
		return
	}
	var adj *gtk.Adjustment
	adj, err = gtk.AdjustmentNew(0.0, scaleMin, scaleMax, scaleStep, scalePStep, scalePage)
	v.scaler, err = gtk.ScaleNew(gtk.ORIENTATION_HORIZONTAL, adj)
	if err != nil {
		return
	}
	v.scaler.Connect("value-changed", scalerValueCallback, v)
	v.layoutBox.Add(v.scene.Widget())
	v.layoutBox.Add(v.scaler)
	return
}
Exemplo n.º 11
0
Arquivo: newgtk.go Projeto: sqp/godock
// Box recast a pointer to *gtk.Box.
func Box(orientation gtk.Orientation, spacing int) *gtk.Box {
	w, _ := gtk.BoxNew(orientation, spacing)
	return w
}