Example #1
0
func mainWindow() {
	gtk.Init(&os.Args)

	// window settings
	window_main := gtk.NewWindow(gtk.WINDOW_TOPLEVEL)
	window_main.SetPosition(gtk.WIN_POS_CENTER)
	window_main.SetTitle("Social Gopher")
	window_main.Connect("destroy", func() {
		println("[!] Quit application")
		gtk.MainQuit()
	})

	// images
	image_profile := loadImageAsset("profile")
	image_stream := loadImageAsset("stream")
	image_mentions := loadImageAsset("mentions")
	image_interactions := loadImageAsset("interactions")
	image_stars := loadImageAsset("stars")
	image_messages := loadImageAsset("messages")
	image_settings := loadImageAsset("settings")

	// containers
	container_main := gtk.NewHBox(false, 1)
	container_left := gtk.NewVBox(false, 1)
	container_right := gtk.NewVBox(false, 5)
	container_compose := gtk.NewHBox(false, 5)
	container_profile := gtk.NewHBox(false, 5)
	container_profile.Add(image_profile)
	container_left.SetBorderWidth(5)
	container_right.SetBorderWidth(5)

	// toolbar
	button_stream := gtk.NewToolButton(image_stream, "My Stream")
	button_mentions := gtk.NewToolButton(image_mentions, "Mentions")
	button_interactions := gtk.NewToolButton(image_interactions, "Interactions")
	button_stars := gtk.NewToolButton(image_stars, "Stars")
	button_messages := gtk.NewToolButton(image_messages, "Messages")
	button_settings := gtk.NewToolButton(image_settings, "Settings")
	button_separator := gtk.NewSeparatorToolItem()
	toolbar := gtk.NewToolbar()
	toolbar.SetOrientation(gtk.ORIENTATION_VERTICAL)
	toolbar.Insert(button_stream, -1)
	toolbar.Insert(button_mentions, -1)
	toolbar.Insert(button_interactions, -1)
	toolbar.Insert(button_stars, -1)
	toolbar.Insert(button_messages, -1)
	toolbar.Insert(button_separator, -1)
	toolbar.Insert(button_settings, -1)

	// stream list
	list_swin := gtk.NewScrolledWindow(nil, nil)
	list_swin.SetPolicy(-1, 1)
	list_swin.SetShadowType(2)
	list_textView := gtk.NewTextView()
	list_textView.SetEditable(false)
	list_textView.SetCursorVisible(false)
	list_textView.SetWrapMode(2)
	list_swin.Add(list_textView)
	list_buffer := list_textView.GetBuffer()

	// compose message
	compose := gtk.NewTextView()
	compose.SetEditable(true)
	compose.SetWrapMode(2)
	compose_swin := gtk.NewScrolledWindow(nil, nil)
	compose_swin.SetPolicy(1, 1)
	compose_swin.SetShadowType(1)
	compose_swin.Add(compose)
	compose_counter := gtk.NewLabel("256")
	compose_buffer := compose.GetBuffer()

	compose_buffer.Connect("changed", func() {
		chars_left := 256 - compose_buffer.GetCharCount()
		compose_counter.SetText(strconv.Itoa(chars_left))
	})

	// post button and counter
	button_post := gtk.NewButtonWithLabel("Post")
	container_post := gtk.NewVBox(false, 1)
	container_post.Add(compose_counter)
	container_post.Add(button_post)

	// button functions
	button_stream.OnClicked(func() {
		list_buffer.SetText("My Stream")
	})
	button_mentions.OnClicked(func() {
		list_buffer.SetText("Mentions")
	})
	button_interactions.OnClicked(func() {
		list_buffer.SetText("Interactions")
	})
	button_stars.OnClicked(func() {
		list_buffer.SetText("Stars")
	})
	button_messages.OnClicked(func() {
		list_buffer.SetText("Messages")
	})
	button_settings.OnClicked(func() {
		accountWindow()
	})
	button_post.Clicked(func() {
		compose_buffer.SetText("")
	})

	// add elements to containers
	container_left.PackStart(container_profile, false, true, 1)
	container_left.PackEnd(toolbar, true, true, 1)
	container_right.PackStart(list_swin, true, true, 1)
	container_right.PackEnd(container_compose, false, false, 1)
	container_compose.PackStart(compose_swin, true, true, 1)
	container_compose.PackEnd(container_post, false, true, 1)
	container_main.PackStart(container_left, false, true, 1)
	container_main.PackEnd(container_right, true, true, 1)

	window_main.Add(container_main)
	window_main.SetSizeRequest(500, 600)
	window_main.ShowAll()

	gtk.Main()
}
Example #2
0
func main() {
	gtk.Init(nil)
	window := gtk.NewWindow(gtk.WINDOW_TOPLEVEL)
	window.SetPosition(gtk.WIN_POS_CENTER)
	window.SetTitle("GTK Go!")
	window.Connect("destroy", func(ctx *glib.CallbackContext) {
		gtk.MainQuit()
	}, "")

	vbox := gtk.NewVBox(false, 0)

	toolbar := gtk.NewToolbar()
	toolbar.SetStyle(gtk.TOOLBAR_ICONS)
	vbox.PackStart(toolbar, false, false, 5)

	btnnew := gtk.NewToolButtonFromStock(gtk.STOCK_NEW)
	btnclose := gtk.NewToolButtonFromStock(gtk.STOCK_CLOSE)
	separator := gtk.NewSeparatorToolItem()
	btncustom := gtk.NewToolButton(nil, "Custom")
	btnmenu := gtk.NewMenuToolButtonFromStock("gtk.STOCK_CLOSE")
	btnmenu.SetArrowTooltipText("This is a tool tip")

	btnnew.OnClicked(onToolButtonClicked)
	btnclose.OnClicked(onToolButtonClicked)
	btncustom.OnClicked(onToolButtonClicked)

	toolmenu := gtk.NewMenu()
	menuitem := gtk.NewMenuItemWithMnemonic("8")
	menuitem.Show()
	toolmenu.Append(menuitem)
	menuitem = gtk.NewMenuItemWithMnemonic("16")
	menuitem.Show()
	toolmenu.Append(menuitem)
	menuitem = gtk.NewMenuItemWithMnemonic("32")
	menuitem.Show()
	toolmenu.Append(menuitem)
	btnmenu.SetMenu(toolmenu)

	toolbar.Insert(btnnew, -1)
	toolbar.Insert(btnclose, -1)
	toolbar.Insert(separator, -1)
	toolbar.Insert(btncustom, -1)
	toolbar.Insert(btnmenu, -1)

	hbox := gtk.NewHBox(false, 0)
	vbox.PackStart(hbox, true, true, 0)

	toolbar2 := gtk.NewToolbar()
	toolbar2.SetOrientation(gtk.ORIENTATION_VERTICAL)
	hbox.PackStart(toolbar2, false, false, 5)
	btnhelp := gtk.NewToolButtonFromStock(gtk.STOCK_HELP)
	btnhelp.OnClicked(onToolButtonClicked)
	toolbar2.Insert(btnhelp, -1)

	btntoggle := gtk.NewToggleToolButton()
	btntoggle2 := gtk.NewToggleToolButtonFromStock(gtk.STOCK_ITALIC)
	toolbar2.Insert(btntoggle, -1)
	toolbar2.Insert(btntoggle2, -1)

	for i := 0; i < toolbar.GetNItems(); i++ {
		gti := toolbar.GetNthItem(i)
		switch gti.(type) {
		case *gtk.ToolButton:
			fmt.Printf("toolbar[%d] is a *gtk.ToolButton\n", i)
			w := gti.(*gtk.ToolButton).GetIconWidget()
			gti.(*gtk.ToolButton).SetIconWidget(w)
		case *gtk.ToggleToolButton:
			fmt.Printf("toolbar[%d] is a *gtk.ToggleToolButton\n", i)
			gti.(*gtk.ToggleToolButton).SetActive(true)
		case *gtk.SeparatorToolItem:
			fmt.Printf("toolbar[%d] is a *gtk.SeparatorToolItem\n", i)
		default:
			fmt.Printf("toolbar: Item is of unknown type\n")
		}
	}

	for i := 0; i < toolbar2.GetNItems(); i++ {
		gti := toolbar2.GetNthItem(i)
		switch gti.(type) {
		case *gtk.ToolButton:
			fmt.Printf("toolbar2[%d] is a *gtk.ToolButton\n", i)
		case *gtk.ToggleToolButton:
			fmt.Printf("toolbar2[%d] is a *gtk.ToggleToolButton\n", i)
			gti.(*gtk.ToggleToolButton).SetActive(true)
		case *gtk.SeparatorToolItem:
			fmt.Printf("toolbar2[%d] is a *gtk.SeparatorToolItem\n", i)
		default:
			fmt.Printf("toolbar2: Item is of unknown type\n")
		}
	}

	window.Add(vbox)
	window.SetSizeRequest(600, 600)
	window.ShowAll()
	gtk.Main()
}