Beispiel #1
0
func DoButtonBox(doWidget gtk3.WidgetLike) gtk3.WidgetLike {
	if window == nil {
		window = gtk3.NewWindow(gtk3.GtkWindowType.TOPLEVEL)
		window.SetScreen(doWidget.W().GetScreen())

		window.SetTitle("Button Boxes")
		window.Connect("destroy", func() { window.Destroy(); window = nil })

		main_vbox := gtk3.NewVBox(0)
		window.Add(main_vbox)

		frame_horz := gtk3.NewFrame("Horizontal Button Boxes")
		main_vbox.PackStart(frame_horz, true, true, 10)

		vbox := gtk3.NewVBox(0)
		frame_horz.Add(vbox)

		vbox.PackStart(createBBox(gtk3.GtkOrientation.HORIZONTAL, "Spread", 40, gtk3.GtkButtonBoxStyle.SPREAD), true, true, 0)
		vbox.PackStart(createBBox(gtk3.GtkOrientation.HORIZONTAL, "Edge", 40, gtk3.GtkButtonBoxStyle.EDGE), true, true, 5)
		vbox.PackStart(createBBox(gtk3.GtkOrientation.HORIZONTAL, "Start", 40, gtk3.GtkButtonBoxStyle.START), true, true, 5)
		vbox.PackStart(createBBox(gtk3.GtkOrientation.HORIZONTAL, "End", 40, gtk3.GtkButtonBoxStyle.END), true, true, 5)

		frame_vert := gtk3.NewFrame("Vertical Button Boxes")
		main_vbox.PackStart(frame_vert, true, true, 10)

		hbox := gtk3.NewHBox(0)
		frame_vert.Add(hbox)

		hbox.PackStart(createBBox(gtk3.GtkOrientation.VERTICAL, "Spread", 30, gtk3.GtkButtonBoxStyle.SPREAD), true, true, 0)
		hbox.PackStart(createBBox(gtk3.GtkOrientation.VERTICAL, "Edge", 30, gtk3.GtkButtonBoxStyle.EDGE), true, true, 5)
		hbox.PackStart(createBBox(gtk3.GtkOrientation.VERTICAL, "Start", 30, gtk3.GtkButtonBoxStyle.START), true, true, 5)
		hbox.PackStart(createBBox(gtk3.GtkOrientation.VERTICAL, "End", 30, gtk3.GtkButtonBoxStyle.END), true, true, 5)

	}

	if !window.GetVisible() {
		window.ShowAll()
	} else {
		window.Destroy()
		window = nil
		return nil
	}

	return window
}
Beispiel #2
0
func main() {
	// Initialize gtk3
	gtk3.Init()

	// Create windows
	w := gtk3.NewWindow(gtk3.GTK_WINDOW_TOPLEVEL, nil)
	w.Connect("destroy", gtk3.MainQuit)
	// Let's set a couple of window properties
	w.Set(gtk3.P{"title": "Go-GTK3 Demo", "resizable": true})

	b2 := gtk3.NewVBox(0)
	w.Add(b2)

	// Create GtkFrame
	f := gtk3.NewFrame("Button Play")
	b2.Add(f)

	// Create GtkBox
	box := gtk3.NewBox(gtk3.ORIENTATION_VERTICAL, 5)
	// Add it to window
	f.Add(box)

	// Create First Button
	fbut := gtk3.NewButtonWithLabel("Click Me")
	box.PackStart(fbut, false, false, 0)
	fbut.Connect("clicked", func() { box.ReorderChild(fbut, 2) })

	// Another one
	fbut2 := gtk3.NewButtonWithLabel("Disable my upper brother")
	box.PackStart(fbut2, false, false, 0)
	// So, let's disable him
	fbut2.Connect("clicked", func(s bool) { fbut.SetSensitive(s) }, false)

	// And another
	fbut3 := gtk3.NewButtonWithLabel("Don't do it")
	box.PackStart(fbut3, false, false, 0)
	fbut2.Connect("clicked", but_disabled, fbut3, fbut)

	fbut3.Connect("clicked", func() {
		fbut.SetSensitive(true)
		fbut3.SetLabel("There you go")
	})

	entry1 := gtk3.NewEntry()
	box.PackStart(entry1, false, false, 0)
	fbut4 := gtk3.NewButtonWithLabel("Get entry text, now!")
	box.PackStart(fbut4, false, false, 0)
	fbut4.Connect("clicked", func() {
		fbut4.SetLabel(entry1.GetText())
	})
	// Run applicaton
	w.ShowAll()
	gtk3.Main()
}
Beispiel #3
0
func main() {
	app := gtk3.NewApplication("si.go-gtk3.demoapp", gtk3.G_APPLICATION_FLAGS_NONE)

	// Create windows
	w := gtk3.NewWindow(gtk3.GTK_WINDOW_TOPLEVEL, nil)
	// Add window to GTKApplication
	app.AddWindow(w)
	// Let's set a couple of window properties
	w.Set(gtk3.P{"title": "Go-GTK3 Demo", "resizable": false})

	//Create frame
	f := gtk3.NewFrame("Button play")
	// Add it to window
	w.Add(f)

	// Create GtkBox
	box := gtk3.NewBox(gtk3.ORIENTATION_VERTICAL, 5)
	f.Add(box)

	// Create First Button
	fbut := gtk3.NewButtonWithLabel("Click Me")
	box.PackStart(fbut, false, false, 0)
	fbut.Connect("clicked", func() { box.ReorderChild(fbut, 2) })

	// Another one
	fbut2 := gtk3.NewButtonWithLabel("Disable my upper brother")
	box.PackStart(fbut2, false, false, 0)
	// So, let's disable him
	fbut2.Connect("clicked", func(s bool) { fbut.SetSensitive(s) }, false)

	// And another
	fbut3 := gtk3.NewButtonWithLabel("Don't do it")
	box.PackStart(fbut3, false, false, 0)
	fbut2.Connect("clicked", but_disabled, fbut3, fbut)

	fbut3.Connect("clicked", func() {
		fbut.SetSensitive(true)
		fbut3.SetLabel("There you go")
	})

	entry1 := gtk3.NewEntry()
	box.PackStart(entry1, false, false, 0)
	fbut4 := gtk3.NewButtonWithLabel("Get entry text, now!")
	box.PackStart(fbut4, false, false, 0)
	fbut4.Connect("clicked", func() {
		fbut4.SetLabel(entry1.GetText())
	})
	// Run applicaton
	w.ShowAll()
	app.Run()
}
Beispiel #4
0
func createBBox(orientation int, title string, spacing int, layout int) *gtk3.Frame {

	frame := gtk3.NewFrame(title)

	bbox := gtk3.NewButtonBox(orientation)
	bbox.SetLayout(layout)

	button := gtk3.NewButtonFromStock(gtk3.GtkStock.OK)
	bbox.Add(button)

	button = gtk3.NewButtonFromStock(gtk3.GtkStock.CANCEL)
	bbox.Add(button)
	button = gtk3.NewButtonFromStock(gtk3.GtkStock.HELP)
	bbox.Add(button)

	frame.Add(bbox)

	return frame
}
Beispiel #5
0
func DoComboBox(w gtk3.WidgetLike) gtk3.WidgetLike {
	if window == nil {
		window = gtk3.NewWindow(gtk3.GtkWindowType.TOPLEVEL)
		window.SetScreen(w.W().GetScreen())
		window.SetTitle("Combo boxes")
		window.Connect("destroy", func() { window.Destroy(); window = nil })
		window.SetBorderWidth(10)

		vbox := gtk3.NewVBox(2)
		window.Add(vbox)

		// A combobox demonstrating cell renderers, separators and insensitive rows
		frame := gtk3.NewFrame("Some stock icons")
		vbox.PackStart(frame, false, false, 0)

		box := gtk3.NewVBox(0)
		box.SetBorderWidth(5)
		frame.Add(box)

		model := createStockIconStore()
		combo := gtk3.NewComboBoxWithModel(model)
		box.Add(combo)

		var renderer gtk3.CellRendererLike

		renderer = gtk3.NewCellRendererPixbuf()
		combo.PackStart(renderer, false)
		combo.SetAttributes(renderer, gtk3.A{{"pixbuf", PixbufCol}})
		combo.SetCellDataFunc(renderer, setSensitive)

		renderer = gtk3.NewCellRendererText()
		combo.PackStart(renderer, true)
		combo.SetAttributes(renderer, gtk3.A{{"text", TextCol}})
		combo.SetCellDataFunc(renderer, setSensitive)

		combo.SetRowSeparatorFunc(isSeparator)
		combo.SetActive(0)

		// A ComboBox demonstrating trees.
		frame = gtk3.NewFrame("Where are we ?")
		vbox.PackStart(frame, false, false, 0)

		box = gtk3.NewVBox(0)
		box.SetBorderWidth(5)
		frame.Add(box)

		model1 := createCapitalStore()
		combo3 := gtk3.NewComboBoxWithModel(model1)
		box.Add(combo3)

		renderer1 := gtk3.NewCellRendererText()
		combo3.PackStart(renderer1, true)
		combo3.SetAttributes(renderer1, gtk3.A{{"text", 0}})

		combo3.SetCellDataFunc(renderer1, isCapitalSensitive)

		var iter gtk3.TreeIter
		path := gtk3.NewTreePathFromString("3:3")
		model1.ITreeModel().GetIter(&iter, path)
		combo3.SetActiveIter(&iter)

		// a combobox with validation
		frame = gtk3.NewFrame("Editable")
		vbox.PackStart(frame, false, false, 0)

		box = gtk3.NewVBox(0)
		box.SetBorderWidth(5)
		frame.Add(box)

		combo1 := gtk3.NewComboBoxTextWithEntry()
		box.Add(combo1)
		combo1.AppendText("One")
		combo1.AppendText("Two")
		combo1.AppendText("2\302\275")
		combo1.AppendText("Three")

		mask := "^([0-9]*|One|Two|2\302\275|Three)$"
		entry := combo1.GetChild().(*gtk3.Entry)
		entry.Connect("changed", setBackground, entry, mask)

		// A ComboBox with string IDs
		frame = gtk3.NewFrame("String IDs")
		vbox.PackStart(frame, false, false, 0)

		box = gtk3.NewVBox(0)
		vbox.SetBorderWidth(5)
		frame.Add(box)

		combo2 := gtk3.NewComboBoxText()
		combo2.Append("never", "Not visible")
		combo2.Append("when-active", "Visible when active")
		combo2.Append("always", "Always visible")
		box.Add(combo2)

		entry = gtk3.NewEntry()
		box.Add(entry)

		gobject.BindProperty(combo2, "active-id", entry, "text", gobject.GBindingFlags.BIDIRECTIONAL)
	}

	if !window.GetVisible() {
		window.ShowAll()
	} else {
		window.Destroy()
		window = nil
		return nil
	}

	return window
}
Beispiel #6
0
func DoInfoBar(w gtk3.WidgetLike) gtk3.WidgetLike {
	if window == nil {
		window = gtk3.NewWindow(gtk3.GtkWindowType.TOPLEVEL)
		window.SetScreen(w.W().GetScreen())

		window.SetTitle("Info Bars")
		window.Connect("destroy", func() { window.Destroy(); window = nil })
		window.SetBorderWidth(8)

		vbox := gtk3.NewVBox(0)
		window.Add(vbox)

		bar := gtk3.NewInfoBar()
		vbox.PackStart(bar, false, false, 0)
		bar.SetMessageType(gtk3.GtkMessage.INFO)
		label := gtk3.NewLabel("This is an info bar with message type GTK_MESSAGE_INFO")
		(bar.GetContentArea()).(*gtk3.Box).PackStart(label, false, false, 0)

		bar = gtk3.NewInfoBar()
		vbox.PackStart(bar, false, false, 0)
		bar.SetMessageType(gtk3.GtkMessage.WARNING)
		label = gtk3.NewLabel("This is an info bar with message type GTK_MESSAGE_WARNING")
		(bar.GetContentArea()).(*gtk3.Box).PackStart(label, false, false, 0)

		bar = gtk3.NewInfoBarWithButtons(gtk3.B{{gtk3.GtkStock.OK, gtk3.GtkResponse.OK}})
		bar.Connect("response", func(infoBar *gtk3.InfoBar, responseId int, data ...interface{}) {
			dialog := gtk3.NewMessageDialog(window, gtk3.GtkDialogFlags.MODAL|gtk3.GtkDialogFlags.DESTROY_WITH_PARENT,
				gtk3.GtkMessage.INFO,
				gtk3.GtkButtons.OK,
				"You Clicked a button on info bar")

			dialog.FormatSecondaryText("Your response has id %d", responseId)
			dialog.Run()
			dialog.Destroy()
		})
		vbox.PackStart(bar, false, false, 0)
		bar.SetMessageType(gtk3.GtkMessage.QUESTION)
		label = gtk3.NewLabel("This is an info bar with message type GTK_MESSAGE_QUESTION")
		(bar.GetContentArea()).(*gtk3.Box).PackStart(label, false, false, 0)

		bar = gtk3.NewInfoBar()
		vbox.PackStart(bar, false, false, 0)
		bar.SetMessageType(gtk3.GtkMessage.ERROR)
		label = gtk3.NewLabel("This is an info bar with message type GTK_MESSAGE_ERROR")
		(bar.GetContentArea()).(*gtk3.Box).PackStart(label, false, false, 0)

		bar = gtk3.NewInfoBar()
		vbox.PackStart(bar, false, false, 0)
		bar.SetMessageType(gtk3.GtkMessage.OTHER)
		label = gtk3.NewLabel("This is an info bar with message type GTK_MESSAGE_OTHER")
		(bar.GetContentArea()).(*gtk3.Box).PackStart(label, false, false, 0)

		frame := gtk3.NewFrame("Info bars")
		vbox.PackStart(frame, false, false, 8)

		vbox2 := gtk3.NewVBox(8)
		vbox.SetBorderWidth(8)
		frame.Add(vbox2)

		// Standard message dialog
		label = gtk3.NewLabel("An example of different info bars")
		vbox2.PackStart(label, false, false, 0)
	}

	if !window.GetVisible() {
		window.ShowAll()
	} else {
		window.Destroy()
		window = nil
		return nil
	}

	return window
}
Beispiel #7
0
func DoDialog(w gtk3.WidgetLike) gtk3.WidgetLike {
	if window == nil {
		window = gtk3.NewWindow(gtk3.GtkWindowType.TOPLEVEL)
		window.SetScreen(w.W().GetScreen())
		window.SetTitle("Dialogs")
		window.Connect("destroy", func() { window.Destroy(); window = nil })
		window.SetBorderWidth(8)

		frame := gtk3.NewFrame("Dialogs")
		window.Add(frame)

		vbox := gtk3.NewVBox(8)
		vbox.SetBorderWidth(8)
		frame.Add(vbox)

		// Standard message dialog
		hbox := gtk3.NewHBox(8)
		vbox.PackStart(hbox, false, false, 0)

		button := gtk3.NewButtonWithMnemonic("_Message Dialog")
		button.Connect("clicked", dialogClickedClosure(window))
		hbox.PackStart(button, false, false, 0)

		vbox.PackStart(gtk3.NewHSeparator(), false, false, 0)

		// Interactive dialog
		hbox = gtk3.NewHBox(8)
		vbox.PackStart(hbox, false, false, 0)
		vbox2 := gtk3.NewVBox(0)

		button = gtk3.NewButtonWithMnemonic("_Interactive Dialog")
		hbox.PackStart(vbox2, false, false, 0)
		vbox2.PackStart(button, false, false, 0)

		table := gtk3.NewGrid()
		table.SetRowSpacing(4)
		table.SetColumnSpacing(4)
		hbox.PackStart(table, false, false, 0)

		label := gtk3.NewLabelWithMnemonic("_Entry 1")
		table.Attach(label, 0, 0, 1, 1)

		entry1 := gtk3.NewEntry()
		table.Attach(entry1, 1, 0, 1, 1)
		label.SetMnemonicWidget(entry1)

		label = gtk3.NewLabelWithMnemonic("E_ntry 2")
		table.Attach(label, 0, 1, 1, 1)

		entry2 := gtk3.NewEntry()
		table.Attach(entry2, 1, 1, 1, 1)
		label.SetMnemonicWidget(entry2)

		button.Connect("clicked", interactiveDialog, window, entry1, entry2)
	}

	if !window.GetVisible() {
		window.ShowAll()
	} else {
		window.Destroy()
		window = nil
		return nil
	}
	return window
}