コード例 #1
0
ファイル: demo.go プロジェクト: norisatir/go-gtk3
func main() {
	gtk3.Init()

	var infoBuf, sourceBuf *gtk3.TextBuffer

	window := gtk3.NewWindow(gtk3.GtkWindowType.TOPLEVEL)
	window.SetTitle("Gtk+ Code Demos")
	window.Connect("destroy", gtk3.MainQuit)

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

	// Create tree
	tree := CreateTree()
	hbox.PackStart(tree, false, false, 0)

	notebook := gtk3.NewNotebook()
	hbox.PackStart(notebook, true, true, 0)

	notebook.AppendPage(CreateText(&infoBuf, false), gtk3.NewLabelWithMnemonic("_Info"))

	infoBuf.CreateTag("title", gtk3.P{"font": "Sans 18"})

	notebook.AppendPage(CreateText(&sourceBuf, true), gtk3.NewLabelWithMnemonic("_Source"))

	sourceBuf.CreateTag("comment", gtk3.P{"foreground": "DodgerBlue"})
	window.SetDefaultSize(600, 400)
	window.ShowAll()

	gtk3.Main()
}
コード例 #2
0
ファイル: standardmain.go プロジェクト: napsy/go-gtk3
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()
}
コード例 #3
0
ファイル: gtkapplication.go プロジェクト: napsy/go-gtk3
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()
}
コード例 #4
0
ファイル: tree_store.go プロジェクト: norisatir/go-gtk3
func DoTreeStore(w gtk3.WidgetLike) gtk3.WidgetLike {
	if window == nil {
		window = gtk3.NewWindow(gtk3.GtkWindowType.TOPLEVEL)
		window.SetScreen(w.W().GetScreen())
		window.SetTitle("Card planning sheet")
		window.Connect("destroy", func() { window = nil })

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

		vbox.PackStart(gtk3.NewLabel("Jonathan's Holiday Card Planning Sheet"), false, false, 0)

		sw := gtk3.NewScrolledWindow(nil, nil)
		sw.SetShadowType(gtk3.GtkShadow.ETCHED_IN)
		sw.SetPolicy(gtk3.GtkPolicy.AUTOMATIC, gtk3.GtkPolicy.AUTOMATIC)

		vbox.PackStart(sw, true, true, 0)

		// Create model
		model := createModel()

		// Create tree view
		treeview := gtk3.NewTreeViewWithModel(model)
		treeview.SetRulesHint(true)
		treeview.GetSelection().SetMode(gtk3.GtkSelectionMode.MULTIPLE)
		treeview.Connect("realize", func() { treeview.ExpandAll() })

		sw.Add(treeview)

		addColumns(treeview)

		window.SetDefaultSize(650, 400)
	}

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

	return window
}
コード例 #5
0
ファイル: button_box.go プロジェクト: norisatir/go-gtk3
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
}
コード例 #6
0
ファイル: textview.go プロジェクト: norisatir/go-gtk3
func DoTextView(w gtk3.WidgetLike) gtk3.WidgetLike {
	if window == nil {
		window = gtk3.NewWindow(gtk3.GtkWindowType.TOPLEVEL)
		window.SetScreen(w.W().GetScreen())
		window.SetDefaultSize(450, 450)
		window.Connect("destroy", func() { window.Destroy(); window = nil })
		window.SetTitle("TextView")
		window.SetBorderWidth(0)

		vpaned := gtk3.NewVPaned()
		vpaned.SetBorderWidth(5)
		window.Add(vpaned)

		view1 := gtk3.NewTextView()
		buffer := view1.GetBuffer()
		view2 := gtk3.NewTextViewWithBuffer(buffer)

		sw := gtk3.NewScrolledWindow(nil, nil)
		sw.SetPolicy(gtk3.GtkPolicy.AUTOMATIC, gtk3.GtkPolicy.AUTOMATIC)

		vpaned.Add1(sw)
		sw.Add(view1)

		sw = gtk3.NewScrolledWindow(nil, nil)
		sw.SetPolicy(gtk3.GtkPolicy.AUTOMATIC, gtk3.GtkPolicy.AUTOMATIC)

		vpaned.Add2(sw)
		sw.Add(view2)

		createTags(buffer)
		insertText(buffer)

		attachWidgets(view1)
		attachWidgets(view2)
	}

	if !window.GetVisible() {
		window.ShowAll()
	} else {
		window.Destroy()
		window = nil
		return nil
	}
	return window
}
コード例 #7
0
ファイル: combobox.go プロジェクト: jkeys089/go-gtk3
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
}
コード例 #8
0
ファイル: infobar.go プロジェクト: norisatir/go-gtk3
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
}
コード例 #9
0
ファイル: list_store.go プロジェクト: jkeys089/go-gtk3
func DoListStore(w gtk3.WidgetLike) gtk3.WidgetLike {
	var model *gtk3.ListStore
	if window == nil {
		window = gtk3.NewWindow(gtk3.GtkWindowType.TOPLEVEL)
		window.SetTitle("GtkListStore demo")
		window.Connect("destroy", func() { window = nil })
		window.SetBorderWidth(8)

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

		label := gtk3.NewLabel("This is the bug list (note: not based on real data...)")
		vbox.PackStart(label, false, false, 0)

		sw := gtk3.NewScrolledWindow(nil, nil)
		sw.SetShadowType(gtk3.GtkShadow.ETCHED_IN)
		sw.SetPolicy(gtk3.GtkPolicy.NEVER, gtk3.GtkPolicy.AUTOMATIC)
		vbox.PackStart(sw, true, true, 0)

		// create tree model
		model = createModel()

		// create tree view
		treeview := gtk3.NewTreeViewWithModel(model)
		treeview.SetRulesHint(true)
		treeview.SetSearchColumn(ColumnDescription)
		sw.Add(treeview)

		// Add columns to treeview
		addColumns(treeview)

		// Finish & Show
		window.SetDefaultSize(280, 250)
		window.Connect("delete-event", windowClosed)
	}

	if !window.GetVisible() {
		window.ShowAll()
		timeout = glib.GTimeoutAddFull(glib.GPriority.DEFAULT, 80,
			func() {
				var sIter gtk3.TreeIter
				model.GetIterFirst(&sIter)
				pulse := model.GetValue(&sIter, ColumnPulse).(uint)

				if pulse == ^uint(0) {
					pulse = 0
				} else {
					pulse++
				}
				model.SetValues(&sIter, gtk3.V{ColumnPulse: pulse, ColumnActive: true})
			})

	} else {
		window.Destroy()
		window = nil
		if timeout != 0 {
			glib.GSourceRemove(timeout)
			timeout = 0
		}
		return nil
	}

	return window
}
コード例 #10
0
ファイル: dialog.go プロジェクト: jkeys089/go-gtk3
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
}
コード例 #11
0
ファイル: menu.go プロジェクト: jkeys089/go-gtk3
func DoMenu(w gtk3.WidgetLike) gtk3.WidgetLike {
	if window == nil {
		window = gtk3.NewWindow(gtk3.GtkWindowType.TOPLEVEL)
		window.SetScreen(w.W().GetScreen())
		window.SetTitle("Menus")
		window.Connect("destroy", func() { window.Destroy(); window = nil })

		accelGroup := gtk3.NewAccelGroup()
		window.AddAccelGroup(accelGroup)
		window.SetBorderWidth(0)

		box := gtk3.NewHBox(0)
		window.Add(box)
		box.Show()

		box1 := gtk3.NewVBox(0)
		box.Add(box1)
		box1.Show()

		menubar := gtk3.NewMenuBar()
		box1.PackStart(menubar, false, true, 0)
		menubar.Show()

		menu := createMenu(2, true)

		menuitem := gtk3.NewMenuItemWithLabel("test\nline2")
		menuitem.SetSubmenu(menu)
		menubar.Append(menuitem)
		menuitem.Show()

		menuitem = gtk3.NewMenuItemWithLabel("foo")
		menuitem.SetSubmenu(createMenu(3, true))
		menubar.Append(menuitem)
		menuitem.Show()

		menuitem = gtk3.NewMenuItemWithLabel("bar")
		menuitem.SetSubmenu(createMenu(4, true))
		menubar.Append(menuitem)
		menuitem.Show()

		box2 := gtk3.NewVBox(10)
		box2.SetBorderWidth(10)
		box1.PackStart(box2, false, true, 0)
		box2.Show()

		button := gtk3.NewButtonWithLabel("Flip")
		button.Connect("clicked", changeOrientation, menubar)
		box2.PackStart(button, true, true, 0)
		button.Show()

		button = gtk3.NewButtonWithLabel("Close")
		button.Connect("clicked", func() { window.Destroy() })
		box2.PackStart(button, true, true, 0)
		button.SetCanDefault(true)
		button.GrabDefault()
		button.Show()
	}

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

	return window
}