本文整理汇总了Golang中github.com/conformal/gotk3/glib.IdleAdd函数的典型用法代码示例。如果您正苦于以下问题:Golang IdleAdd函数的具体用法?Golang IdleAdd怎么用?Golang IdleAdd使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了IdleAdd函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。
示例1: TestWebView_URI
func TestWebView_URI(t *testing.T) {
setup()
defer teardown()
mux.HandleFunc("/", func(w http.ResponseWriter, _ *http.Request) {})
wantURI := server.URL + "/"
var gotURI string
webView.Connect("notify::uri", func() {
glib.IdleAdd(func() bool {
gotURI = webView.URI()
if gotURI != "" {
gtk.MainQuit()
}
return false
})
})
glib.IdleAdd(func() bool {
webView.LoadURI(server.URL)
return false
})
gtk.Main()
if wantURI != gotURI {
t.Errorf("want URI %q, got %q", wantURI, gotURI)
}
}
开发者ID:missionMeteora,项目名称:go-webkit2,代码行数:29,代码来源:webview_test.go
示例2: EvaluateJavaScript
// EvaluateJavaScript runs the JavaScript in script in the view's context and
// returns the script's result as a Go value.
func (v *View) EvaluateJavaScript(script string) (result interface{}, err error) {
resultChan := make(chan interface{}, 1)
errChan := make(chan error, 1)
glib.IdleAdd(func() bool {
v.WebView.RunJavaScript(script, func(result *gojs.Value, err error) {
glib.IdleAdd(func() bool {
if err == nil {
goval, err := result.GoValue()
if err != nil {
errChan <- err
return false
}
resultChan <- goval
} else {
errChan <- err
}
return false
})
})
return false
})
select {
case result = <-resultChan:
return result, nil
case err = <-errChan:
return nil, err
}
}
开发者ID:missionMeteora,项目名称:webloop,代码行数:32,代码来源:webloop.go
示例3: TestWebView_Title
func TestWebView_Title(t *testing.T) {
webView := NewWebView()
defer webView.Destroy()
wantTitle := "foo"
var gotTitle string
webView.Connect("notify::title", func() {
glib.IdleAdd(func() bool {
gotTitle = webView.Title()
if gotTitle != "" {
gtk.MainQuit()
}
return false
})
})
glib.IdleAdd(func() bool {
webView.LoadHTML("<html><head><title>"+wantTitle+"</title></head><body></body></html>", "")
return false
})
gtk.Main()
if wantTitle != gotTitle {
t.Errorf("want title %q, got %q", wantTitle, gotTitle)
}
}
开发者ID:missionMeteora,项目名称:go-webkit2,代码行数:27,代码来源:webview_test.go
示例4: txSenderAndReplyListener
// txSenderAndReplyListener triggers btcgui to send btcwallet a JSON
// request to create and send a transaction. If sending the transaction
// succeeds, the recipients in the send coins notebook tab are cleared.
// If the transaction fails because the wallet is not unlocked, the
// unlock dialog is shown, and after a successful unlock, creating and
// sending the tx is tried a second time.
//
// This is written to be run as a goroutine executing outside of the GTK
// main event loop.
func txSenderAndReplyListener(sendTo map[string]float64) {
triggers.sendTx <- sendTo
err := <-triggerReplies.sendTx
// -13 is the error code for needing an unlocked wallet.
if jsonErr, ok := err.(*btcjson.Error); ok {
switch jsonErr.Code {
case -13:
// Wallet must be unlocked first. Show unlock dialog.
glib.IdleAdd(func() {
unlockSuccessful := make(chan bool)
go func() {
for {
success, ok := <-unlockSuccessful
if !ok {
// A closed channel indicates
// the dialog was cancelled.
// Abort sending the transaction.
return
}
if success {
// Try send again.
go txSenderAndReplyListener(sendTo)
return
}
}
}()
d, err := createUnlockDialog(unlockForTxSend, unlockSuccessful)
if err != nil {
// TODO(jrick): log error to file
log.Printf("[ERR] could not create unlock dialog: %v\n", err)
return
}
d.Run()
d.Destroy()
})
default:
// Generic case to display an error.
glib.IdleAdd(func() {
d := errorDialog("Unable to send transaction",
fmt.Sprintf("%s\nError code: %d", jsonErr.Message, jsonErr.Code))
d.Run()
d.Destroy()
})
}
return
}
// Send was successful, so clear recipient widgets.
glib.IdleAdd(resetRecipients)
}
开发者ID:hsk81,项目名称:btcgui,代码行数:61,代码来源:sendcoins.go
示例5: main
func main() {
gtk.Init(nil)
win, err := gtk.WindowNew(gtk.WINDOW_TOPLEVEL)
if err != nil {
log.Fatal("Unable to create window:", err)
}
win.Connect("destroy", func() {
gtk.MainQuit()
})
win.Add(windowWidget())
// Native GTK is not thread safe, and thus, gotk3's GTK bindings may not
// be used from other goroutines. Instead, glib.IdleAdd() must be used
// to add a function to run in the GTK main loop when it is in an idle
// state.
//
// Two examples of using glib.IdleAdd() are shown below. The first runs
// a user created function, LabelSetTextIdle, and passes it two
// arguments for a label and the text to set it with. The second calls
// (*gtk.Label).SetText directly, passing in only the text as an
// argument.
//
// If the function passed to glib.IdleAdd() returns one argument, and
// that argument is a bool, this return value will be used in the same
// manner as a native g_idle_add() call. If this return value is false,
// the function will be removed from executing in the GTK main loop's
// idle state. If the return value is true, the function will continue
// to execute when the GTK main loop is in this state.
go func() {
for {
time.Sleep(time.Second)
s := fmt.Sprintf("Set a label %d time(s)!", nSets)
_, err := glib.IdleAdd(LabelSetTextIdle, topLabel, s)
if err != nil {
log.Fatal("IdleAdd() failed:", err)
}
nSets++
s = fmt.Sprintf("Set a label %d time(s)!", nSets)
_, err = glib.IdleAdd(bottomLabel.SetText, s)
if err != nil {
log.Fatal("IdleAdd() failed:", err)
}
nSets++
}
}()
win.ShowAll()
gtk.Main()
}
开发者ID:alimy,项目名称:gotk3,代码行数:51,代码来源:goroutines.go
示例6: updateAddresses
// updateAddresses listens for new wallet addresses, updating the GUI when
// necessary.
func updateAddresses() {
for {
addrs := <-updateChans.addrs
glib.IdleAdd(func() {
RecvCoins.Store.Clear()
})
for i := range addrs {
addr := addrs[i]
glib.IdleAdd(func() {
iter := RecvCoins.Store.Append()
RecvCoins.Store.Set(iter, []int{1},
[]interface{}{addr})
})
}
}
}
开发者ID:hsk81,项目名称:btcgui,代码行数:18,代码来源:updates.go
示例7: cmdGetAddressesByAccount
// cmdGetAddressesByAccount requests all addresses for an account.
//
// TODO(jrick): support non-default accounts.
// TODO(jrick): stop throwing away errors.
func cmdGetAddressesByAccount(ws *websocket.Conn) {
n := <-NewJSONID
msg, err := btcjson.CreateMessageWithId("getaddressesbyaccount", n, "")
if err != nil {
updateChans.addrs <- []string{}
}
replyHandlers.Lock()
replyHandlers.m[n] = func(result interface{}, err *btcjson.Error) {
if r, ok := result.([]interface{}); ok {
addrs := []string{}
for _, v := range r {
addrs = append(addrs, v.(string))
}
updateChans.addrs <- addrs
} else {
if err.Code == btcjson.ErrWalletInvalidAccountName.Code {
glib.IdleAdd(func() {
if dialog, err := createNewWalletDialog(); err != nil {
dialog.Run()
}
})
}
updateChans.addrs <- []string{}
}
}
replyHandlers.Unlock()
if err = websocket.Message.Send(ws, msg); err != nil {
replyHandlers.Lock()
delete(replyHandlers.m, n)
replyHandlers.Unlock()
updateChans.addrs <- []string{}
}
}
开发者ID:hsk81,项目名称:btcgui,代码行数:39,代码来源:updates.go
示例8: TestWebView_LoadURI_load_failed
func TestWebView_LoadURI_load_failed(t *testing.T) {
webView := NewWebView()
defer webView.Destroy()
loadFailed := false
loadFinished := false
webView.Connect("load-failed", func() {
loadFailed = true
})
webView.Connect("load-changed", func(_ *glib.Object, loadEvent LoadEvent) {
switch loadEvent {
case LoadFinished:
loadFinished = true
gtk.MainQuit()
}
})
glib.IdleAdd(func() bool {
// Load a bad URL to trigger load failure.
webView.LoadURI("http://127.0.0.1:99999")
return false
})
gtk.Main()
if !loadFailed {
t.Error("!loadFailed")
}
if !loadFinished {
t.Error("!loadFinished")
}
}
开发者ID:missionMeteora,项目名称:go-webkit2,代码行数:32,代码来源:webview_test.go
示例9: TestWebView_GetSnapshot
func TestWebView_GetSnapshot(t *testing.T) {
webView := NewWebView()
defer webView.Destroy()
webView.Connect("load-changed", func(_ *glib.Object, loadEvent LoadEvent) {
switch loadEvent {
case LoadFinished:
webView.GetSnapshot(func(img *image.RGBA, err error) {
if err != nil {
t.Errorf("GetSnapshot error: %q", err)
}
if img.Pix == nil {
t.Error("!img.Pix")
}
if img.Stride == 0 || img.Rect.Max.X == 0 || img.Rect.Max.Y == 0 {
t.Error("!img.Stride or !img.Rect.Max.X or !img.Rect.Max.Y")
}
gtk.MainQuit()
})
}
})
glib.IdleAdd(func() bool {
webView.LoadHTML(`<p id=foo>abc</p>`, "")
return false
})
gtk.Main()
}
开发者ID:missionMeteora,项目名称:go-webkit2,代码行数:29,代码来源:webview_test.go
示例10: TestWebView_RunJavaScript_exception
func TestWebView_RunJavaScript_exception(t *testing.T) {
webView := NewWebView()
defer webView.Destroy()
wantErr := errors.New("An exception was raised in JavaScript")
webView.Connect("load-changed", func(_ *glib.Object, loadEvent LoadEvent) {
switch loadEvent {
case LoadFinished:
webView.RunJavaScript(`throw new Error("foo")`, func(result *gojs.Value, err error) {
if result != nil {
ctx := webView.JavaScriptGlobalContext()
t.Errorf("want result == nil, got %q", ctx.ToStringOrDie(result))
}
if !reflect.DeepEqual(wantErr, err) {
t.Errorf("want error %q, got %q", wantErr, err)
}
gtk.MainQuit()
})
}
})
glib.IdleAdd(func() bool {
webView.LoadHTML(`<p></p>`, "")
return false
})
gtk.Main()
}
开发者ID:missionMeteora,项目名称:go-webkit2,代码行数:28,代码来源:webview_test.go
示例11: TestWebView_RunJavaScript
func TestWebView_RunJavaScript(t *testing.T) {
webView := NewWebView()
defer webView.Destroy()
wantResultString := "abc"
webView.Connect("load-changed", func(_ *glib.Object, loadEvent LoadEvent) {
switch loadEvent {
case LoadFinished:
webView.RunJavaScript(`document.getElementById("foo").innerHTML`, func(result *gojs.Value, err error) {
if err != nil {
t.Errorf("RunJavaScript error: %s", err)
}
resultString := webView.JavaScriptGlobalContext().ToStringOrDie(result)
if wantResultString != resultString {
t.Errorf("want result string %q, got %q", wantResultString, resultString)
}
gtk.MainQuit()
})
}
})
glib.IdleAdd(func() bool {
webView.LoadHTML(`<p id=foo>abc</p>`, "")
return false
})
gtk.Main()
}
开发者ID:missionMeteora,项目名称:go-webkit2,代码行数:28,代码来源:webview_test.go
示例12: downloadFile
func (self *PopupMenu) downloadFile(msgId, url, ext string) {
go func() {
glib.IdleAdd(func() {
NewFileChooserWindow(self.parent, msgId, url, ext).window.ShowAll()
})
}()
}
开发者ID:cslinmiso,项目名称:goline-gotk3,代码行数:7,代码来源:PopupMenu.go
示例13: TestWebView_LoadHTML
func TestWebView_LoadHTML(t *testing.T) {
webView := NewWebView()
defer webView.Destroy()
loadOk := false
webView.Connect("load-failed", func() {
t.Errorf("load failed")
})
webView.Connect("load-changed", func(_ *glib.Object, loadEvent LoadEvent) {
switch loadEvent {
case LoadFinished:
loadOk = true
gtk.MainQuit()
}
})
glib.IdleAdd(func() bool {
webView.LoadHTML("<p>hello</p>", "")
return false
})
gtk.Main()
if !loadOk {
t.Error("!loadOk")
}
}
开发者ID:missionMeteora,项目名称:go-webkit2,代码行数:27,代码来源:webview_test.go
示例14: NewView
// NewView creates a new View in the context.
func (c *Context) NewView() *View {
view := make(chan *View, 1)
glib.IdleAdd(func() bool {
webView := webkit2.NewWebView()
settings := webView.Settings()
settings.SetEnableWriteConsoleMessagesToStdout(true)
settings.SetUserAgentWithApplicationDetails("WebLoop", "v1")
v := &View{WebView: webView}
loadChangedHandler, _ := webView.Connect("load-changed", func(_ *glib.Object, loadEvent webkit2.LoadEvent) {
switch loadEvent {
case webkit2.LoadFinished:
// If we're here, then the load must not have failed, because
// otherwise we would've disconnected this handler in the
// load-failed signal handler.
v.load <- struct{}{}
}
})
webView.Connect("load-failed", func() {
v.lastLoadErr = ErrLoadFailed
webView.HandlerDisconnect(loadChangedHandler)
})
view <- v
return false
})
return <-view
}
开发者ID:missionMeteora,项目名称:webloop,代码行数:27,代码来源:webloop.go
示例15: updateConnectionState
// updateConnectionState listens for connection status changes to btcd
// and btcwallet, updating the GUI when necessary.
func updateConnectionState() {
// Statusbar messages for various connection states.
btcdd := "Disconnected from btcd"
btcwc := "Established connection to btcwallet"
btcwd := "Disconnected from btcwallet. Attempting reconnect..."
for {
select {
case conn := <-updateChans.btcwalletConnected:
if conn {
glib.IdleAdd(func() {
//MenuBar.Settings.New.SetSensitive(true)
//MenuBar.Settings.Encrypt.SetSensitive(true)
MenuBar.Settings.TxFee.SetSensitive(true)
// Lock/Unlock sensitivity is set by wallet notification.
RecvCoins.NewAddrBtn.SetSensitive(true)
StatusElems.Lab.SetText(btcwc)
StatusElems.Pb.Hide()
})
} else {
glib.IdleAdd(func() {
//MenuBar.Settings.New.SetSensitive(false)
//MenuBar.Settings.Encrypt.SetSensitive(false)
MenuBar.Settings.Lock.SetSensitive(false)
MenuBar.Settings.Unlock.SetSensitive(false)
MenuBar.Settings.TxFee.SetSensitive(false)
SendCoins.SendBtn.SetSensitive(false)
RecvCoins.NewAddrBtn.SetSensitive(false)
StatusElems.Lab.SetText(btcwd)
StatusElems.Pb.Hide()
})
}
case conn := <-updateChans.btcdConnected:
if conn {
glib.IdleAdd(func() {
SendCoins.SendBtn.SetSensitive(true)
})
} else {
glib.IdleAdd(func() {
SendCoins.SendBtn.SetSensitive(false)
StatusElems.Lab.SetText(btcdd)
StatusElems.Pb.Hide()
})
}
}
}
}
开发者ID:hsk81,项目名称:btcgui,代码行数:49,代码来源:updates.go
示例16: URI
// URI returns the URI of the current resource in the view.
func (v *View) URI() string {
uri := make(chan string, 1)
glib.IdleAdd(func() bool {
uri <- v.WebView.URI()
return false
})
return <-uri
}
开发者ID:missionMeteora,项目名称:webloop,代码行数:9,代码来源:webloop.go
示例17: Title
// Title returns the title of the current resource in the view.
func (v *View) Title() string {
title := make(chan string, 1)
glib.IdleAdd(func() bool {
title <- v.WebView.Title()
return false
})
return <-title
}
开发者ID:missionMeteora,项目名称:webloop,代码行数:9,代码来源:webloop.go
示例18: StartMainApplication
// StartMainApplication creates and opens the main window appWindow.
// It then preceeds to start all necessary goroutine to support the main
// application. Currently, this starts generating the JSON ID generator
// and attempts to open a connection to btcwallet.
//
// This is written to be called as a goroutine outside of the main GTK
// loop.
func StartMainApplication() {
// Read CA file to verify a btcwallet TLS connection.
cafile, err := ioutil.ReadFile(cfg.CAFile)
if err != nil {
IdlePreGUIError(fmt.Errorf("Cannot open CA file:\n%v", err))
}
glib.IdleAdd(func() {
w, err := CreateWindow()
if err != nil {
PreGUIError(fmt.Errorf("Cannot create application window:\n%v", err))
}
w.ShowAll()
})
// Write current application version to file.
if err := version.SaveToDataDir(cfg); err != nil {
log.Print(err)
}
// Begin generating new IDs for JSON calls.
go JSONIDGenerator(NewJSONID)
// Listen for updates and update GUI with new info. Attempt
// reconnect if connection is lost or cannot be established.
for {
replies := make(chan error)
done := make(chan int)
go func() {
ListenAndUpdate(cafile, replies)
close(done)
}()
selectLoop:
for {
select {
case <-done:
break selectLoop
case err := <-replies:
switch err {
case ErrConnectionRefused:
updateChans.btcwalletConnected <- false
time.Sleep(5 * time.Second)
case ErrConnectionLost:
updateChans.btcwalletConnected <- false
time.Sleep(5 * time.Second)
case nil:
// connected
updateChans.btcwalletConnected <- true
log.Print("Established connection to btcwallet.")
default:
// TODO(jrick): present unknown error to user in the
// GUI somehow.
log.Printf("Unknown connect error: %v", err)
}
}
}
}
}
开发者ID:hsk81,项目名称:btcgui,代码行数:65,代码来源:main.go
示例19: Open
// Open starts loading the resource at the specified URL.
func (v *View) Open(url string) {
v.load = make(chan struct{}, 1)
v.lastLoadErr = nil
glib.IdleAdd(func() bool {
if !v.destroyed {
v.WebView.LoadURI(url)
}
return false
})
}
开发者ID:missionMeteora,项目名称:webloop,代码行数:11,代码来源:webloop.go
示例20: IdlePreGUIError
// IdlePreGUIError runs PreGUIError within the context of the GTK main
// event loop. This function does not return.
func IdlePreGUIError(e error) {
glib.IdleAdd(func() {
PreGUIError(e)
})
// This function should block. However, simple adding a closure the
// main event loop does not block. Use an empty select to prevent the
// calling goroutine from continuing.
select {}
}
开发者ID:hsk81,项目名称:btcgui,代码行数:12,代码来源:main.go
注:本文中的github.com/conformal/gotk3/glib.IdleAdd函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论