• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Golang gtk.Main函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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

示例1: 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


示例2: 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


示例3: init

func init() {
	gtk.Init(nil)
	go func() {
		runtime.LockOSThread()
		gtk.Main()
	}()
}
开发者ID:divver,项目名称:webloop,代码行数:7,代码来源:webloop_test.go


示例4: 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


示例5: 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


示例6: 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


示例7: main

func main() {
	// Initialize GTK without parsing any command line arguments.
	gtk.Init(nil)

	// Create a new toplevel window, set its title, and connect it to the
	// "destroy" signal to exit the GTK main loop when it is destroyed.
	win, err := gtk.WindowNew(gtk.WINDOW_TOPLEVEL)
	if err != nil {
		log.Fatal("Unable to create window:", err)
	}
	win.SetTitle("Simple Example")
	win.Connect("destroy", func() {
		gtk.MainQuit()
	})

	// Create a new socket:
	s, err := gtkx.SocketNew()
	if err != nil {
		log.Fatal("Unable to create socket:", err)
	}

	//Adding the socket to the window:
	win.Add(s)

	// Getting the socketId:
	sId := s.GetId()
	fmt.Printf("Our socket: %v\n", sId)

	//Building a Plug for our Socket:
	p, err := gtkx.PlugNew(sId)
	if err != nil {
		log.Fatal("Unable to create plug:", err)
	}

	//Building a Button for our Plug:
	b, err := gtk.ButtonNewWithLabel("Click me .)")
	if err != nil {
		log.Fatal("Unable to create button:", err)
	}

	//Click events for the Button:
	b.Connect("clicked", func() {
		fmt.Printf("Yeah, such clicks!\n")
	})

	//Adding the Button to the Plug:
	p.Add(b)
	//Displaying the Plug:
	p.ShowAll()

	// Set the default window size.
	win.SetDefaultSize(800, 600)

	// Recursively show all widgets contained in this window.
	win.ShowAll()

	// Begin executing the GTK main loop.  This blocks until
	// gtk.MainQuit() is run.
	gtk.Main()
}
开发者ID:runjak,项目名称:gotk3,代码行数:60,代码来源:selfplug.go


示例8: Example

func Example() {
	gtk.Init(nil)
	go func() {
		runtime.LockOSThread()
		gtk.Main()
	}()

	ctx := webloop.New()
	view := ctx.NewView()
	defer view.Close()
	view.Open("http://google.com")
	err := view.Wait()
	if err != nil {
		fmt.Fprintf(os.Stderr, "Failed to load URL: %s", err)
		os.Exit(1)
	}
	res, err := view.EvaluateJavaScript("document.title")
	if err != nil {
		fmt.Fprintf(os.Stderr, "Failed to run JavaScript: %s", err)
		os.Exit(1)
	}
	fmt.Printf("JavaScript returned: %q\n", res)
	// output:
	// JavaScript returned: "Google"
}
开发者ID:divver,项目名称:webloop,代码行数:25,代码来源:example_test.go


示例9: 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


示例10: 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


示例11: main

func main() {
	// Initialize GTK without parsing any command line arguments.
	gtk.Init(nil)

	// Create a new toplevel window, set its title, and connect it to the
	// "destroy" signal to exit the GTK main loop when it is destroyed.
	win, err := gtk.WindowNew(gtk.WINDOW_TOPLEVEL)
	if err != nil {
		log.Fatal("Unable to create window:", err)
	}
	win.SetTitle("Simple Example")
	win.Connect("destroy", func() {
		gtk.MainQuit()
	})

	// Create a new label widget to show in the window.
	l, err := gtk.LabelNew("Hello, gotk3!")
	if err != nil {
		log.Fatal("Unable to create label:", err)
	}

	// Add the label to the window.
	win.Add(l)

	// Set the default window size.
	win.SetDefaultSize(800, 600)

	// Recursively show all widgets contained in this window.
	win.ShowAll()

	// Begin executing the GTK main loop.  This blocks until
	// gtk.MainQuit() is run.
	gtk.Main()
}
开发者ID:alimy,项目名称:gotk3,代码行数:34,代码来源:simple.go


示例12: StartGTK

// StartGTK ensures that the GTK+ main loop has started. If it has already been
// started by StartGTK, it will not start it again. If another goroutine is
// already running the GTK+ main loop, StartGTK's behavior is undefined.
func (h *StaticRenderer) StartGTK() {
	startGTKOnce.Do(func() {
		gtk.Init(nil)
		go func() {
			runtime.LockOSThread()
			gtk.Main()
		}()
	})
}
开发者ID:divver,项目名称:webloop,代码行数:12,代码来源:static_renderer.go


示例13: main

func main() {
	/*
	   We set an environment variable so that we don't get bothered by xterm accessibility warnings
	   like "** (xterm:16917): WARNING **: Couldn't connect to accessibility bus: Failed to connect to socket /tmp/dbus-QznzMfGEXB: Connection refused"
	   See http://debbugs.gnu.org/cgi/bugreport.cgi?bug=15154
	*/
	os.Setenv("NO_AT_BRIDGE", "1")

	// Initialize GTK without parsing any command line arguments.
	gtk.Init(nil)

	// Create a new toplevel window, set its title, and connect it to the
	// "destroy" signal to exit the GTK main loop when it is destroyed.
	win, err := gtk.WindowNew(gtk.WINDOW_TOPLEVEL)
	if err != nil {
		log.Fatal("Unable to create window:", err)
	}
	win.SetTitle("Simple Example")
	win.Connect("destroy", func() {
		gtk.MainQuit()
	})

	// Create a new socket:
	s, err := gtkx.SocketNew()
	if err != nil {
		log.Fatal("Unable to create socket:", err)
	}

	//Adding the socket to the window:
	win.Add(s)

	// Getting the socketId:
	sId := s.GetId()
	fmt.Printf("Our socket: %v\n", sId)

	// Embedding something in the socket:
	xterm := exec.Command("xterm", "-into", gtkx.WindowIdToString(sId))

	go func() {
		xterm.Run()
	}()

	// Set the default window size.
	win.SetDefaultSize(800, 600)

	// Recursively show all widgets contained in this window.
	win.ShowAll()

	// Begin executing the GTK main loop.  This blocks until
	// gtk.MainQuit() is run.
	gtk.Main()
}
开发者ID:runjak,项目名称:gotk3,代码行数:52,代码来源:xterm.go


示例14: 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


示例15: main

func main() {
	goline.LoggerPrintln("Start Goline.")
	gtk.Init(&os.Args)
	css.SetupCss()
	if goline.Autologin && goline.AuthToken != "" {
		autologinWindow := NewAutologinWindow()
		autologinWindow.window.ShowAll()
		autologinWindow.Login()
	} else {
		loginWindow := NewLoginWindow()
		loginWindow.window.ShowAll()
	}
	gtk.Main()
}
开发者ID:cslinmiso,项目名称:goline-gotk3,代码行数:14,代码来源:main.go


示例16: main

func main() {
	gtk.Init(nil)

	// The first thing ever done is to create a GTK error dialog to
	// show any errors to the user.  If any fatal errors occur before
	// the main application window is shown, they will be shown using
	// this dialog.
	PreGUIErrorDialog = gtk.MessageDialogNew(nil, 0, gtk.MESSAGE_ERROR,
		gtk.BUTTONS_OK, "An unknown error occured.")
	PreGUIErrorDialog.SetPosition(gtk.WIN_POS_CENTER)
	PreGUIErrorDialog.Connect("destroy", func() {
		os.Exit(1)
	})

	tcfg, _, err := loadConfig()
	if err != nil {
		if e, ok := err.(*flags.Error); !ok || e.Type != flags.ErrHelp {
			PreGUIError(fmt.Errorf("Cannot open configuration:\n%v", err))
		} else {
			os.Exit(1)
		}
	}
	cfg = tcfg

	// Load help dialog on first open.  Use current and previous versions
	// can be used to control what level of new information must be
	// displayed.
	//
	//
	// As currently implemented, if current > previous version, or if
	// there are any errors opening and reading the file, any and all
	// tutorial information is displayed.
	prevRunVers, err := GetPreviousAppVersion(cfg)
	if err != nil || version.NewerThan(*prevRunVers) {
		d, err := CreateTutorialDialog(nil)
		if err != nil {
			// Nothing to show.
			PreGUIError(fmt.Errorf("Cannot create tutorial dialog:\n%v", err))
		}
		d.ShowAll()
		d.Run()
	} else {
		// No error or tutorial dialogs required, so create and show
		// main application window.
		go StartMainApplication()
	}

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


示例17: 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())
	win.ShowAll()

	gtk.Main()
}
开发者ID:kendellfab,项目名称:gotk3,代码行数:16,代码来源:signals.go


示例18: RunGUI

// RunGUI initializes GTK, creates the toplevel window and all child widgets,
// opens the pages for the default session, and runs the Glib main event loop.
// This function blocks until the toplevel window is destroyed and the event
// loop exits.
func RunGUI() {
	gtk.Init(nil)

	window, _ := gtk.WindowNew(gtk.WINDOW_TOPLEVEL)
	window.Connect("destroy", func() {
		gtk.MainQuit()
	})
	window.SetDefaultGeometry(defaultWinWidth, defaultWinHeight)
	window.Show()

	wc := wk2.DefaultWebContext()
	wc.SetProcessModel(wk2.ProcessModelMultipleSecondaryProcesses)

	session := []PageDescription{HomePage}
	pm := NewPageManager(session)
	window.Add(pm)
	pm.Show()

	gtk.Main()
}
开发者ID:jrick,项目名称:xombrero2,代码行数:24,代码来源:xombrero.go


示例19: main

func main() {
	gtk.Init(nil)

	win := setupWindow()
	box, _ := gtk.BoxNew(gtk.ORIENTATION_VERTICAL, 0)
	win.Add(box)

	tv := setupTextView(box)

	props := []*BoolProperty{
		&BoolProperty{"cursor visible", (*tv).GetCursorVisible, (*tv).SetCursorVisible},
		&BoolProperty{"editable", (*tv).GetEditable, (*tv).SetEditable},
		&BoolProperty{"overwrite", (*tv).GetOverwrite, (*tv).SetOverwrite},
		&BoolProperty{"accepts tab", (*tv).GetAcceptsTab, (*tv).SetAcceptsTab},
	}

	setupPropertyCheckboxes(tv, box, props)

	win.ShowAll()

	gtk.Main()
}
开发者ID:alimy,项目名称:gotk3,代码行数:22,代码来源:boolprops.go


示例20: main

func main() {
	gtk.Init(nil)

	// gui boilerplate
	win, _ := gtk.WindowNew(gtk.WINDOW_TOPLEVEL)
	da, _ := gtk.DrawingAreaNew()
	win.Add(da)
	win.SetTitle("Arrow keys")
	win.Connect("destroy", gtk.MainQuit)
	win.ShowAll()

	// Data
	unitSize := 20.0
	x := 0.0
	y := 0.0
	keyMap := map[uint]func(){
		KEY_LEFT:  func() { x-- },
		KEY_UP:    func() { y-- },
		KEY_RIGHT: func() { x++ },
		KEY_DOWN:  func() { y++ },
	}

	// Event handlers
	da.Connect("draw", func(da *gtk.DrawingArea, cr *cairo.Context) {
		cr.SetSourceRGB(0, 0, 0)
		cr.Rectangle(x*unitSize, y*unitSize, unitSize, unitSize)
		cr.Fill()
	})
	win.Connect("key-press-event", func(win *gtk.Window, ev *gdk.Event) {
		keyEvent := &gdk.EventKey{ev}
		if move, found := keyMap[keyEvent.KeyVal()]; found {
			move()
			win.QueueDraw()
		}
	})

	gtk.Main()
}
开发者ID:alimy,项目名称:gotk3,代码行数:38,代码来源:game.go



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Golang gtk.MainQuit函数代码示例发布时间:2022-05-23
下一篇:
Golang gtk.LabelNew函数代码示例发布时间:2022-05-23
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap