当前位置: 首页>>代码示例>>Golang>>正文


Golang gdk.ThreadsInit函数代码示例

本文整理汇总了Golang中github.com/mattn/go-gtk/gdk.ThreadsInit函数的典型用法代码示例。如果您正苦于以下问题:Golang ThreadsInit函数的具体用法?Golang ThreadsInit怎么用?Golang ThreadsInit使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了ThreadsInit函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。

示例1: main

func main() {
	libusb.Init()
	// Todo check for errors

	dmxControllers := k8062.GetDmxControlers()
	fmt.Printf("Got %d devices\n", len(dmxControllers))

	checkForErrors(dmxControllers)
	// yuval
	if os.Getenv("OSC_TEST") != "" {
		if len(dmxControllers) == 0 {
			return
		}
	}

	for _, d := range dmxControllers {
		defer d.Close()
	}
	gui := true
	if gui {
		dmxControllers = append(dmxControllers, <-GetGuiController())
		gdk.ThreadsInit()
	}

	lightFixtures := openFixtures()

	keyframes := getKeyFrames()

	setupOsc()

	worker(keyframes, dmxControllers, lightFixtures)

}
开发者ID:uvgroovy,项目名称:dmx,代码行数:33,代码来源:dmxd.go

示例2: main

func main() {
	glib.ThreadInit(nil)
	gdk.ThreadsInit()
	gtk.Init(nil)
	runGUI([]string{os.Getenv("SHELL")})

}
开发者ID:nlamirault,项目名称:mert,代码行数:7,代码来源:mert.go

示例3: main

func main() {
	gtk.Init(nil)
	gdk.ThreadsInit()
	MainGui.buildSplash()
	MainGui.buildGUI()
	MainGui.SplashWindow.ShowAll()
	go unlinked_main()
	gtk.Main()
}
开发者ID:spaghetty,项目名称:gunnify,代码行数:9,代码来源:gunnify.go

示例4: main

func main() {
	if debug {
		logging.SetLogging("DEBUG")
	} else {
		logging.SetLogging("INFO")
	}
	log.Printf("[INFO] Start Actarus")
	runtime.GOMAXPROCS(runtime.NumCPU())
	glib.ThreadInit(nil)
	gdk.ThreadsInit()
	gtk.Init(nil)
	runGUI()
}
开发者ID:nlamirault,项目名称:actarus,代码行数:13,代码来源:actarus.go

示例5: main

func main() {
	glib.ThreadInit(nil)
	gdk.ThreadsInit()
	gdk.ThreadsEnter()
	gtk.Init(nil)

	gui := new(GUI)
	gui.Init()
	gui.Show()

	gtk.Main()
	gdk.ThreadsLeave()
}
开发者ID:kch42,项目名称:biomed,代码行数:13,代码来源:main.go

示例6: main

func main() {
	gdk.ThreadsInit()
	if false == init_args() {
		return
	}
	load_options()
	defer save_options()

	gdk.ThreadsEnter()
	gtk.Init(nil)
	init_tabby()
	gtk.Main()
}
开发者ID:udhos,项目名称:tabby,代码行数:13,代码来源:main.go

示例7: InitWebKit

func InitWebKit() {
	gtk.Init(nil)
	gdk.ThreadsInit()
	c = make(chan bool, 2)
	gdk.ThreadsEnter()
	webview = CreateWebView(func() {
		fmt.Printf("HEEEERLoad Finished\n")
		c <- true
	})
	gdk.ThreadsLeave()

	go func() {
		gdk.ThreadsEnter()
		gtk.Main()
		gdk.ThreadsLeave()
	}()
}
开发者ID:zackb,项目名称:code,代码行数:17,代码来源:webkit.go

示例8: Startup

func Startup() {
	gdk.ThreadsInit()
	gdk.ThreadsEnter()
	initializeEnvironment()
	gtk.Init(nil)

	window := windows.MainWindow()
	window.ShowAll()

	config := models.Config()
	if config.AccessToken == "" {
		authWindow := windows.AuthWindow()
		authWindow.ShowAll()
	}

	gtk.Main()
}
开发者ID:chdorner,项目名称:ghighlighter,代码行数:17,代码来源:main.go

示例9: guiMain

func guiMain(ch <-chan Accounts) {
	glib.ThreadInit(nil)
	gdk.ThreadsInit()
	gdk.ThreadsEnter()
	gtk.Init(&os.Args)

	window := gtk.NewWindow(gtk.WINDOW_TOPLEVEL)
	window.SetPosition(gtk.WIN_POS_CENTER)
	window.SetTitle("password")
	window.Connect("destroy", gtk.MainQuit)

	entry := gtk.NewEntry()

	store := gtk.NewListStore(glib.G_TYPE_STRING)
	treeview := gtk.NewTreeView()
	treeview.SetModel(store)
	// treeview.AppendColumn(gtk.NewTreeViewColumnWithAttributes("icon", gtk.NewCellRendererPixbuf(), "pixbuf", 0))
	treeview.AppendColumn(gtk.NewTreeViewColumnWithAttributes("name", gtk.NewCellRendererText(), "text", 0))

	go func() {
		for accounts := range ch {
			gthread(func() {
				store.Clear()
				for _, a := range accounts {
					var iter gtk.TreeIter
					store.Append(&iter)
					store.Set(&iter, 0, a.Name)
				}
			})
		}
	}()

	swin := gtk.NewScrolledWindow(nil, nil)
	swin.Add(treeview)

	vbox := gtk.NewVBox(false, 0)
	vbox.PackStart(entry, false, false, 1)
	vbox.PackStart(swin, true, true, 0)

	window.Add(vbox)

	window.SetSizeRequest(460, 640)
	window.SetResizable(false)
	window.ShowAll()
}
开发者ID:pocke,项目名称:password,代码行数:45,代码来源:gui.go

示例10: main

func main() {
	runtime.GOMAXPROCS(10)
	glib.ThreadInit(nil)
	gdk.ThreadsInit()
	gdk.ThreadsEnter()
	gtk.Init(nil)
	window := gtk.NewWindow(gtk.WINDOW_TOPLEVEL)
	window.Connect("destroy", gtk.MainQuit)

	vbox := gtk.NewVBox(false, 1)

	label1 := gtk.NewLabel("")
	vbox.Add(label1)
	label2 := gtk.NewLabel("")
	vbox.Add(label2)

	window.Add(vbox)

	window.SetSizeRequest(100, 100)
	window.ShowAll()
	time.Sleep(1000 * 1000 * 100)
	go (func() {
		for i := 0; i < 300000; i++ {
			gdk.ThreadsEnter()
			label1.SetLabel(strconv.Itoa(i))
			gdk.ThreadsLeave()
		}
		gtk.MainQuit()
	})()
	go (func() {
		for i := 300000; i >= 0; i-- {
			gdk.ThreadsEnter()
			label2.SetLabel(strconv.Itoa(i))
			gdk.ThreadsLeave()
		}
		gtk.MainQuit()
	})()
	gtk.Main()
}
开发者ID:hauke96,项目名称:go-gtk,代码行数:39,代码来源:threads.go

示例11: guiMain

func guiMain(confglobal string, conflocal string) {
	var CallID string
	ch := make(chan string, 100)
	Config := ReadConfig(confglobal)
	Configlocal := ReadConfiglocal(conflocal)
	owner := Configlocal.Main.Owner

	//prepare config for XSI
	var xsiConfig xsi.ConfigT
	xsiConfig.Main.User = Configlocal.Main.Owner
	xsiConfig.Main.Password = Configlocal.Main.Password
	xsiConfig.Main.Host = Config.Main.Host
	xsiConfig.Main.HTTPHost = Config.Main.HTTPHost
	xsiConfig.Main.HTTPPort = Config.Main.HTTPPort
	def := xsi.MakeDef(xsiConfig)

	//start main client
	go clientMain(ch, Config)

	//prepare config for OCI
	var ociConfig ocip.ConfigT
	ociConfig.Main.User = Configlocal.Main.Owner
	ociConfig.Main.Password = Configlocal.Main.Password
	ociConfig.Main.Host = Config.Main.Host
	ociConfig.Main.OCIPPort = Config.Main.OCIPPort
	//set unavailable at start app
	ocip.OCIPsend(ociConfig, "UserCallCenterModifyRequest19", ConcatStr("", "userId=", owner), "agentACDState=Unavailable")
	//prepare timer
	timer := time.NewTimer(time.Second)
	timer.Stop()

	//init gthreads
	glib.ThreadInit(nil)
	gdk.ThreadsInit()
	gdk.ThreadsEnter()
	gtk.Init(nil)

	//names
	names := make(map[string]string)
	for iter, target := range Config.Main.TargetID {
		names[target] = Config.Main.Name[iter]
	}

	//icons to pixbuf map
	pix := make(map[string]*gdkpixbuf.Pixbuf)
	im_call := gtk.NewImageFromFile("ico/Call-Ringing-48.ico")
	pix["call"] = im_call.GetPixbuf()
	im_blank := gtk.NewImageFromFile("ico/Empty-48.ico")
	pix["blank"] = im_blank.GetPixbuf()
	im_green := gtk.NewImageFromFile("ico/Green-ball-48.ico")
	pix["green"] = im_green.GetPixbuf()
	im_grey := gtk.NewImageFromFile("ico/Grey-ball-48.ico")
	pix["grey"] = im_grey.GetPixbuf()
	im_yellow := gtk.NewImageFromFile("ico/Yellow-ball-48.ico")
	pix["yellow"] = im_yellow.GetPixbuf()

	window := gtk.NewWindow(gtk.WINDOW_TOPLEVEL)
	window.SetTitle("Call Center")
	window.SetIcon(pix["call"])
	window.SetPosition(gtk.WIN_POS_CENTER)
	window.SetSizeRequest(350, 500)
	window.SetDecorated(false)
	window.SetResizable(true)
	window.Connect("destroy", gtk.MainQuit)

	swin := gtk.NewScrolledWindow(nil, nil)
	swin.SetPolicy(gtk.POLICY_AUTOMATIC, gtk.POLICY_AUTOMATIC)
	swin.SetShadowType(gtk.SHADOW_IN)

	//owner
	owner1 := gtk.NewLabel(names[owner])
	owner2 := gtk.NewLabel("")
	owner3 := gtk.NewImage()

	//qstatus
	qlabel1 := gtk.NewLabel("В очереди:")
	qlabel2 := gtk.NewLabel("")

	//buttons
	b_av := gtk.NewButtonWithLabel("Доступен")
	b_av.SetCanFocus(false)
	b_av.Connect("clicked", func() {
		ocip.OCIPsend(ociConfig, "UserCallCenterModifyRequest19", ConcatStr("", "userId=", owner), "agentACDState=Available")
	})
	b_un := gtk.NewButtonWithLabel("Недоступен")
	b_un.SetCanFocus(false)
	b_un.Connect("clicked", func() {
		ocip.OCIPsend(ociConfig, "UserCallCenterModifyRequest19", ConcatStr("", "userId=", owner), "agentACDState=Unavailable")
	})
	b_wr := gtk.NewButtonWithLabel("Дообработка")
	b_wr.SetCanFocus(false)
	b_wr.Connect("clicked", func() {
		ocip.OCIPsend(ociConfig, "UserCallCenterModifyRequest19", ConcatStr("", "userId=", owner), "agentACDState=Wrap-Up")
	})

	//main table
	table := gtk.NewTable(3, 3, false)
	table.Attach(owner1, 0, 1, 0, 1, gtk.FILL, gtk.FILL, 1, 1)
	table.Attach(owner3, 1, 2, 0, 1, gtk.FILL, gtk.FILL, 1, 1)
	table.Attach(owner2, 2, 3, 0, 1, gtk.FILL, gtk.FILL, 1, 1)
//.........这里部分代码省略.........
开发者ID:fffilimonov,项目名称:BW_CCC,代码行数:101,代码来源:gui.go

示例12: main


//.........这里部分代码省略.........
	now := time.Now()
	switch now.Weekday() {
	case time.Monday:
		hm = *client.Options.Hours.MonCl
	case time.Tuesday:
		hm = *client.Options.Hours.TueCl
	case time.Wednesday:
		hm = *client.Options.Hours.WedCl
	case time.Thursday:
		hm = *client.Options.Hours.ThuCl
	case time.Friday:
		hm = *client.Options.Hours.FriCl
	case time.Saturday:
		hm = *client.Options.Hours.SatCl
	case time.Sunday:
		hm = *client.Options.Hours.SunCl
	}

	// Convert closing time to datetime
	hour, _ := strconv.Atoi(hm[0:2])
	min, _ := strconv.Atoi(hm[3:])
	closingTime := time.Date(now.Year(), now.Month(), now.Day(), hour, min-*client.Options.Hours.Min, 0, 0, time.Local)

	// Show login screen
	gtk.Init(nil)
	var user, userType string
	var userMinutes, extraMinutes int
	if client.ShortTime {
		userMinutes = *client.Options.ShortTimeLimit
		extraMinutes = 0
		user = window.ShortTime(client.Name, userMinutes)
	} else {
		extraMinutes = *client.Options.Minutes - DefaultMinutes
		user, userMinutes, userType = window.Login(*hostAPI, client.Name, extraMinutes, *client.Options.AgeL, *client.Options.AgeH)
		if userType == "G" {
			// If guest user, minutes is user.minutes left or the minutes limit on the client
			tempMinutes := int(math.Min(float64(userMinutes), float64(*client.Options.Minutes)))
			extraMinutes = tempMinutes - userMinutes
		}
	}

	// Calculate how long until closing time.
	// Adjust minutes acording to closing hours, so that maximum minutes does
	// not exceed available minutes until closing
	untilClose := int(closingTime.Sub(now).Minutes())
	if userMinutes+extraMinutes > untilClose {
		extraMinutes = untilClose - userMinutes
	}

	// Show status window
	conn := connect(*hostWS, user, client.Id)
	gdk.ThreadsInit()
	status := new(window.Status)

	status.Init(client.Name, user, userMinutes+extraMinutes)
	status.Show()
	status.Move()

	// goroutine to check for websocket messages and update status window
	// with number of minutes left
	go func() {
		var msg message
		for {
			err := websocket.JSON.Receive(conn, &msg)
			if err != nil {
				if err == io.EOF {
					println("ws disconnected")
					// reconnect
					conn = connect(*hostWS, user, client.Id)
				}
				continue
			}

			if msg.Status == "ping" {
				if msg.User.Minutes+extraMinutes <= 0 {
					gtk.MainQuit()
				}
				gdk.ThreadsEnter()
				status.SetMinutes(msg.User.Minutes + extraMinutes)
				gdk.ThreadsLeave()
			}
		}
	}()

	// This blocks until the 'logg out' button is clicked, or until the user
	// has spent all minutes
	gtk.Main()

	// Send log-out message to server
	logOffMsg := logOnOffMessage{Action: "log-off", Client: client.Id, User: user}
	err = websocket.JSON.Send(conn, logOffMsg)
	if err != nil {
		// Don't bother to resend. Server will log off user anyway, when the
		// connection is closed
	}

	// Force session restart
	cmd := exec.Command("/bin/sh", "-c", "/usr/bin/killall /usr/bin/lxsession")
	err = cmd.Run()
}
开发者ID:digibib,项目名称:mycel-client,代码行数:101,代码来源:client.go

示例13: Gui

func Gui() {
	//--------------------------------------------------------
	// Setting up the GTK-Foo
	//--------------------------------------------------------
	gdk.ThreadsInit()
	gtk.Init(&os.Args)
	window := gtk.Window(gtk.GTK_WINDOW_TOPLEVEL)
	window.SetTitle("Zwitscher!")
	window.Connect("destroy", func() {
		gtk.MainQuit()
	})

	vbox := gtk.VBox(false, 1)
	notebook := gtk.Notebook()

	//--------------------------------------------------------
	// Home View
	//--------------------------------------------------------
	vboxHome := gtk.VBox(false, 1)
	scrolledWinHome := gtk.ScrolledWindow(nil, nil)
	//Disable hscrollbar, enable vscrollbar
	scrolledWinHome.SetPolicy(gtk.GTK_POLICY_NEVER, gtk.GTK_POLICY_ALWAYS)
	vboxHome.Add(scrolledWinHome)
	vboxScrolledWinHome := gtk.VBox(false, 1)
	scrolledWinHome.AddWithViewPort(vboxScrolledWinHome)

	tweetwidgets := []*gtk.GtkFrame{}
	buttonUpdateTimeline := gtk.ButtonWithLabel("Update Timeline")
	buttonUpdateTimeline.Clicked(func() {
		var tweet gotter.Tweet
		tweets, err := gotter.GetTweets(accounts.Credentials, "https://api.twitter.com/1/statuses/home_timeline.json", map[string]string{})
		if err != nil {
			println("failed to get tweets:", err.String())
			return
		}
		for i := len(tweets) - 1; i >= 0; i-- {
			tweet = tweets[i]
			id, _ := strconv.Atoi64(tweet.Identifier)
			if accounts.Maxreadid < id {
				if len(tweetwidgets) > 20 {
					tweetwidgets[0].Destroy()
					tweetwidgets = tweetwidgets[1:]
				}
				tweetwidget := TweetWidget(tweet)
				vboxScrolledWinHome.PackEnd(tweetwidget, false, false, 0)
				tweetwidget.ShowAll()
				tweetwidgets = append(tweetwidgets, tweetwidget)
				accounts.Maxreadid = id
			}
		}
	})
	vboxHome.PackEnd(buttonUpdateTimeline, false, false, 0)
	notebook.AppendPage(vboxHome, gtk.Label("Home"))

	//--------------------------------------------------------
	// Mentions View
	//--------------------------------------------------------
	scrolledwin := gtk.ScrolledWindow(nil, nil)
	notebook.AppendPage(scrolledwin, gtk.Label("Mentions"))

	//--------------------------------------------------------
	// Messages View
	//--------------------------------------------------------
	scrolledwin = gtk.ScrolledWindow(nil, nil)
	notebook.AppendPage(scrolledwin, gtk.Label("Messages"))

	vbox.Add(notebook)

	//--------------------------------------------------------
	// Fild for Tweets
	//--------------------------------------------------------
	hbox := gtk.HBox(false, 1)

	dir, _ := filepath.Split(os.Args[0])
	imagefile := filepath.Join(dir, "Awesome Smiley Original.jpg")
	image := gtk.ImageFromFile(imagefile)
	hbox.PackStart(image, false, false, 0)

	buttonZwitscher := gtk.ButtonWithLabel("Zwitscher!")
	newTweetTextField := gtk.Entry()
	charCounterLabel := gtk.Label("140")

	buttonZwitscher.SetTooltipMarkup("Tweet")

	buttonZwitscher.Clicked(func() {
		charCounterLabel.SetLabel("140")
		SendTweet(newTweetTextField.GetText())
		newTweetTextField.SetText("")
	})

	newTweetTextField.Connect("key-release-event", func() {
		length := utf8.RuneCountInString(newTweetTextField.GetText())
		charCounterLabel.SetLabel((string)(strconv.Itoa(140 - length)))
	})

	newTweetTextField.Connect("activate", func() {
		if newTweetTextField.GetText() != "" { //pressed enter, and text is not empty
			charCounterLabel.SetLabel("140")
			SendTweet(newTweetTextField.GetText())
			newTweetTextField.SetText("")
//.........这里部分代码省略.........
开发者ID:mattn,项目名称:Zwitscher,代码行数:101,代码来源:gui.go

示例14: init_tabby

func init_tabby() {
	init_navigation()
	gdk.ThreadsInit()
	init_inotify()

	search_view.Init()

	source_buf = gtk.SourceBuffer()
	source_buf.Connect("paste-done", paste_done_cb, nil)
	source_buf.Connect("mark-set", mark_set_cb, nil)
	source_buf.Connect("changed", buf_changed_cb, nil)

	init_lang()

	source_buf.CreateTag("instance", map[string]string{"background": "#FF8080"})

	tree_store = gtk.TreeStore(gtk.GTK_TYPE_STRING)
	tree_view = file_tree.NewFileTree()
	tree_view.ModifyFontEasy("Regular 8")
	tree_model = tree_store.ToTreeModel()
	tree_view.SetModel(tree_model)
	tree_view.SetHeadersVisible(false)
	tree_view.Connect("cursor-changed", tree_view_select_cb, nil)

	error_view = gtk.TextView()
	error_view.ModifyFontEasy("Monospace Regular 8")
	error_view.SetEditable(false)
	error_buf = error_view.GetBuffer()

	source_view = gtk.SourceViewWithBuffer(source_buf)
	source_view.ModifyFontEasy("Monospace Regular 10")
	source_view.SetAutoIndent(true)
	source_view.SetHighlightCurrentLine(true)
	source_view.SetShowLineNumbers(true)
	source_view.SetRightMarginPosition(80)
	source_view.SetShowRightMargin(true)
	source_view.SetIndentWidth(2)
	source_view.SetTabWidth(2)
	source_view.SetInsertSpacesInsteadOfTabs(opt.space_not_tab)
	source_view.SetDrawSpaces(gtk.GTK_SOURCE_DRAW_SPACES_TAB)
	source_view.SetSmartHomeEnd(gtk.GTK_SOURCE_SMART_HOME_END_ALWAYS)
	source_view.SetWrapMode(gtk.GTK_WRAP_WORD)

	vbox := gtk.VBox(false, 0)
	inner_hpaned := gtk.HPaned()
	view_vpaned := gtk.VPaned()
	outer_hpaned := gtk.HPaned()
	outer_hpaned.Add1(inner_hpaned)
	inner_hpaned.Add2(view_vpaned)

	menubar := gtk.MenuBar()
	vbox.PackStart(menubar, false, false, 0)
	vbox.PackStart(outer_hpaned, true, true, 0)

	file_item := gtk.MenuItemWithMnemonic("_File")
	menubar.Append(file_item)
	file_submenu := gtk.Menu()
	file_item.SetSubmenu(file_submenu)

	accel_group := gtk.AccelGroup()

	new_item := gtk.MenuItemWithMnemonic("_New")
	file_submenu.Append(new_item)
	new_item.Connect("activate", new_cb, nil)
	new_item.AddAccelerator("activate", accel_group, gdk.GDK_KEY_n,
		int(gdk.GDK_CONTROL_MASK), gtk.GTK_ACCEL_VISIBLE)

	open_item := gtk.MenuItemWithMnemonic("_Open")
	file_submenu.Append(open_item)
	open_item.Connect("activate", open_cb, nil)
	open_item.AddAccelerator("activate", accel_group, gdk.GDK_KEY_o,
		int(gdk.GDK_CONTROL_MASK), gtk.GTK_ACCEL_VISIBLE)

	open_rec_item := gtk.MenuItemWithMnemonic("Open _Recursively")
	file_submenu.Append(open_rec_item)
	open_rec_item.Connect("activate", open_rec_cb, nil)

	save_item := gtk.MenuItemWithMnemonic("_Save")
	file_submenu.Append(save_item)
	save_item.Connect("activate", save_cb, nil)
	save_item.AddAccelerator("activate", accel_group, gdk.GDK_KEY_s,
		int(gdk.GDK_CONTROL_MASK), gtk.GTK_ACCEL_VISIBLE)

	save_as_item := gtk.MenuItemWithMnemonic("Save _as")
	file_submenu.Append(save_as_item)
	save_as_item.Connect("activate", save_as_cb, nil)

	close_item := gtk.MenuItemWithMnemonic("_Close")
	file_submenu.Append(close_item)
	close_item.Connect("activate", close_cb, nil)
	close_item.AddAccelerator("activate", accel_group, gdk.GDK_KEY_w,
		int(gdk.GDK_CONTROL_MASK), gtk.GTK_ACCEL_VISIBLE)

	exit_item := gtk.MenuItemWithMnemonic("E_xit")
	file_submenu.Append(exit_item)
	exit_item.Connect("activate", exit_cb, nil)

	navigation_item := gtk.MenuItemWithMnemonic("_Navigation")
	menubar.Append(navigation_item)
	navigation_submenu := gtk.Menu()
//.........这里部分代码省略.........
开发者ID:mattn,项目名称:tabby,代码行数:101,代码来源:main.go

示例15: main

func main() {
	gtk.Init(&os.Args)
	gdk.ThreadsInit()
	window := gtk.NewWindow(gtk.WINDOW_TOPLEVEL)
	window.SetTitle("Twitter!")
	window.Connect("destroy", gtk.MainQuit)

	vbox := gtk.NewVBox(false, 1)

	scrolledwin := gtk.NewScrolledWindow(nil, nil)
	textview := gtk.NewTextView()
	textview.SetEditable(false)
	textview.SetCursorVisible(false)
	scrolledwin.Add(textview)
	vbox.Add(scrolledwin)

	buffer := textview.GetBuffer()

	tag := buffer.CreateTag("blue", map[string]string{
		"foreground": "#0000FF", "weight": "700"})
	button := gtk.NewButtonWithLabel("Update Timeline")
	button.SetTooltipMarkup("update <b>public timeline</b>")
	button.Clicked(func() {
		b, err := ioutil.ReadFile("settings.json")
		if err != nil {
			fmt.Println(`"settings.json" not found: `, err)
			return
		}
		var config map[string]string
		err = json.Unmarshal(b, &config)
		if err != nil {
			fmt.Println(`can't read "settings.json": `, err)
			return
		}
		client := &oauth.Client{
			Credentials: oauth.Credentials{
				config["ClientToken"], config["ClientSecret"]}}
		cred := &oauth.Credentials{
			config["AccessToken"], config["AccessSecret"]}

		gdk.ThreadsEnter()
		button.SetSensitive(false)
		gdk.ThreadsLeave()
		go func() {
			ts, err := twitterstream.Open(client, cred,
				"https://stream.twitter.com/1/statuses/filter.json",
				url.Values{"track": {"picplz,instagr"}})
			if err != nil {
				println(err.Error())
				return
			}
			for ts.Err() == nil {
				t := tweet{}
				if err := ts.UnmarshalNext(&t); err != nil {
					fmt.Println("error reading tweet: ", err)
					continue
				}
				var iter gtk.TextIter
				pixbufbytes, resp := readURL(t.User.ProfileImageUrl)
				gdk.ThreadsEnter()
				buffer.GetStartIter(&iter)
				if resp != nil {
					buffer.InsertPixbuf(&iter, bytes2pixbuf(pixbufbytes, resp.Header.Get("Content-Type")))
				}
				gdk.ThreadsLeave()
				gdk.ThreadsEnter()
				buffer.Insert(&iter, " ")
				buffer.InsertWithTag(&iter, t.User.ScreenName, tag)
				buffer.Insert(&iter, ":"+t.Text+"\n")
				gtk.MainIterationDo(false)
				gdk.ThreadsLeave()
			}
		}()
	})
	vbox.PackEnd(button, false, false, 0)

	window.Add(vbox)
	window.SetSizeRequest(800, 500)
	window.ShowAll()
	gdk.ThreadsEnter()
	gtk.Main()
	gdk.ThreadsLeave()
}
开发者ID:arip33,项目名称:go-gtk,代码行数:83,代码来源:twitterstream.go


注:本文中的github.com/mattn/go-gtk/gdk.ThreadsInit函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。