本文整理汇总了Golang中github.com/mattn/go-gtk/gtk.Window函数的典型用法代码示例。如果您正苦于以下问题:Golang Window函数的具体用法?Golang Window怎么用?Golang Window使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了Window函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: main
func main() {
gtk.Init(&os.Args)
window := gtk.Window(gtk.GTK_WINDOW_TOPLEVEL)
window.SetTitle("GTK Icon View")
window.Connect("destroy", gtk.MainQuit)
swin := gtk.ScrolledWindow(nil, nil)
store := gtk.ListStore(gdkpixbuf.GetGdkPixbufType(), glib.G_TYPE_STRING)
iconview := gtk.IconViewWithModel(store)
iconview.SetPixbufColumn(0)
iconview.SetTextColumn(1)
swin.Add(iconview)
gtk.GtkStockListIDs().ForEach(func(d interface{}, v interface{}) {
id := glib.GPtrToString(d)
var iter gtk.GtkTreeIter
store.Append(&iter)
store.Set(&iter,
gtk.Image().RenderIcon(id, gtk.GTK_ICON_SIZE_SMALL_TOOLBAR, "").Pixbuf,
id)
})
window.Add(swin)
window.SetSizeRequest(500, 200)
window.ShowAll()
gtk.Main()
}
示例2: main
func main() {
gtk.Init(nil)
window := gtk.Window(gtk.GTK_WINDOW_TOPLEVEL)
window.SetTitle("Clock")
vbox := gtk.VBox(false, 1)
label := gtk.Label("")
vbox.Add(label)
window.Add(vbox)
window.SetDefaultSize(300, 20)
window.ShowAll()
timer, _ := uv.TimerInit(nil)
timer.Start(func(h *uv.Handle, status int) {
label.SetLabel(fmt.Sprintf("%v", time.Now()))
}, 1000, 1000)
idle, _ := uv.IdleInit(nil)
idle.Start(func(h *uv.Handle, status int) {
gtk.MainIterationDo(false)
})
window.Connect("destroy", func() {
timer.Close(nil)
idle.Close(nil)
})
uv.DefaultLoop().Run()
}
示例3: main
func main() {
gtk.Init(nil)
window := gtk.Window(gtk.GTK_WINDOW_TOPLEVEL)
window.SetTitle("Click me")
label := gtk.Label("There have been no clicks yet")
var clicks int
button := gtk.ButtonWithLabel("click me")
button.Clicked(func() {
clicks++
if clicks == 1 {
label.SetLabel("Button clicked 1 time")
} else {
label.SetLabel(fmt.Sprintf("Button clicked %d times",
clicks))
}
})
vbox := gtk.VBox(false, 1)
vbox.Add(label)
vbox.Add(button)
window.Add(vbox)
window.Connect("destroy", func() {
gtk.MainQuit()
})
window.ShowAll()
gtk.Main()
}
示例4: main
func main() {
gtk.Init(&os.Args)
window := gtk.Window(gtk.GTK_WINDOW_TOPLEVEL)
window.Connect("delete-event", func() {
println("Delete-event occured\n")
})
window.Connect("destroy", func() { gtk.MainQuit() })
button := gtk.ButtonWithLabel("Hello, World")
button.Clicked(func() {
println("Hello, World\n")
})
button.Clicked(func() {
gtk.MainQuit()
})
window.Add(button)
window.ShowAll()
gtk.Main()
}
示例5: main
func main() {
gtk.Init(&os.Args)
window := gtk.Window(gtk.GTK_WINDOW_TOPLEVEL)
window.SetTitle("GTK Stock Icons")
window.Connect("destroy", gtk.MainQuit)
swin := gtk.ScrolledWindow(nil, nil)
store := gtk.ListStore(glib.G_TYPE_STRING, glib.G_TYPE_BOOL, gdkpixbuf.GetGdkPixbufType())
treeview := gtk.TreeView()
swin.Add(treeview)
treeview.SetModel(store.ToTreeModel())
treeview.AppendColumn(gtk.TreeViewColumnWithAttributes("name", gtk.CellRendererText(), "text", 0))
treeview.AppendColumn(gtk.TreeViewColumnWithAttributes("check", gtk.CellRendererToggle(), "active", 1))
treeview.AppendColumn(gtk.TreeViewColumnWithAttributes("icon", gtk.CellRendererPixbuf(), "pixbuf", 2))
n := 0
gtk.GtkStockListIDs().ForEach(func(d interface{}, v interface{}) {
id := glib.GPtrToString(d)
var iter gtk.GtkTreeIter
store.Append(&iter)
store.Set(&iter, id, (n == 1), gtk.Image().RenderIcon(id, gtk.GTK_ICON_SIZE_SMALL_TOOLBAR, "").Pixbuf)
n = 1 - n
})
window.Add(swin)
window.SetSizeRequest(400, 200)
window.ShowAll()
gtk.Main()
}
示例6: main
func main() {
gtk.Init(&os.Args)
window := gtk.Window(gtk.GTK_WINDOW_TOPLEVEL)
window.SetTitle("GTK Notebook")
window.Connect("destroy", gtk.MainQuit)
notebook := gtk.Notebook()
for n := 1; n <= 10; n++ {
page := gtk.Frame("demo" + strconv.Itoa(n))
notebook.AppendPage(page, gtk.Label("demo"+strconv.Itoa(n)))
vbox := gtk.HBox(false, 1)
prev := gtk.ButtonWithLabel("go prev")
prev.Clicked(func() {
notebook.PrevPage()
})
vbox.Add(prev)
next := gtk.ButtonWithLabel("go next")
next.Clicked(func() {
notebook.NextPage()
})
vbox.Add(next)
page.Add(vbox)
}
window.Add(notebook)
window.SetSizeRequest(400, 200)
window.ShowAll()
gtk.Main()
}
示例7: showLogin
func showLogin() {
window := gtk.Window(gtk.GTK_WINDOW_POPUP)
window.Connect("destroy", gtk.MainQuit)
window.SetSizeRequest()
window.ShowAll()
gtk.Main()
}
示例8: main
func main() {
gtk.Init(nil)
window := gtk.Window(gtk.GTK_WINDOW_TOPLEVEL)
window.SetTitle("webkit")
window.Connect("destroy", gtk.MainQuit)
vbox := gtk.VBox(false, 1)
entry := gtk.Entry()
entry.SetText("http://golang.org/")
vbox.PackStart(entry, false, false, 0)
swin := gtk.ScrolledWindow(nil, nil)
swin.SetPolicy(gtk.GTK_POLICY_AUTOMATIC, gtk.GTK_POLICY_AUTOMATIC)
swin.SetShadowType(gtk.GTK_SHADOW_IN)
webview := webkit.WebView()
webview.Connect("load-committed", func() {
entry.SetText(webview.GetUri())
})
swin.Add(webview)
vbox.Add(swin)
entry.Connect("activate", func() {
webview.LoadUri(entry.GetText())
})
button := gtk.ButtonWithLabel("load String")
button.Clicked(func() {
webview.LoadString("hello Go GTK!", "text/plain", "utf-8", ".")
})
vbox.PackStart(button, false, false, 0)
button = gtk.ButtonWithLabel("load HTML String")
button.Clicked(func() {
webview.LoadHtmlString(HTML_STRING, ".")
})
vbox.PackStart(button, false, false, 0)
button = gtk.ButtonWithLabel("Google Maps")
button.Clicked(func() {
webview.LoadHtmlString(MAP_EMBED, ".")
})
vbox.PackStart(button, false, false, 0)
window.Add(vbox)
window.SetSizeRequest(600, 600)
window.ShowAll()
proxy := os.Getenv("HTTP_PROXY")
if len(proxy) > 0 {
soup_uri := webkit.SoupUri(proxy)
webkit.GetDefaultSession().Set("proxy-uri", soup_uri)
soup_uri.Free()
}
entry.Emit("activate")
gtk.Main()
}
示例9: main
func main() {
gtk.Init(&os.Args)
window := gtk.Window(gtk.GTK_WINDOW_TOPLEVEL)
window.SetTitle("SourceView")
window.Connect("destroy", gtk.MainQuit)
swin := gtk.ScrolledWindow(nil, nil)
swin.SetPolicy(gtk.GTK_POLICY_AUTOMATIC, gtk.GTK_POLICY_AUTOMATIC)
swin.SetShadowType(gtk.GTK_SHADOW_IN)
sourcebuffer := gsv.SourceBufferWithLanguage(gsv.SourceLanguageManagerGetDefault().GetLanguage("cpp"))
sourceview := gsv.SourceViewWithBuffer(sourcebuffer)
var start gtk.GtkTextIter
sourcebuffer.GetStartIter(&start)
sourcebuffer.BeginNotUndoableAction()
sourcebuffer.Insert(&start, `#include <iostream>
template<class T>
struct foo_base {
T operator+(T const &rhs) const {
T tmp(static_cast<T const &>(*this));
tmp += rhs;
return tmp;
}
};
class foo : public foo_base<foo> {
private:
int v;
public:
foo(int v) : v(v) {}
foo &operator+=(foo const &rhs){
this->v += rhs.v;
return *this;
}
operator int() { return v; }
};
int main(void) {
foo a(1), b(2);
a += b;
std::cout << (int)a << std::endl;
}
`)
sourcebuffer.EndNotUndoableAction()
swin.Add(sourceview)
window.Add(swin)
window.SetSizeRequest(400, 300)
window.ShowAll()
gtk.Main()
}
示例10: main
func main() {
gtk.Init(nil)
win := gtk.Window(gtk.GTK_WINDOW_TOPLEVEL)
win.SetTitle("Goodbye, World!")
win.SetSizeRequest(300, 200)
win.Connect("destroy", gtk.MainQuit)
button := gtk.ButtonWithLabel("Goodbye, World!")
win.Add(button)
button.Connect("clicked", gtk.MainQuit)
win.ShowAll()
gtk.Main()
}
示例11: main
func main() {
gtk.Init(&os.Args)
window := gtk.Window(gtk.GTK_WINDOW_TOPLEVEL)
window.SetTitle("GTK DrawingArea")
window.Connect("destroy", gtk.MainQuit)
vbox := gtk.VBox(true, 0)
vbox.SetBorderWidth(5)
targets := []gtk.GtkTargetEntry{
{"text/uri-list", 0, 0},
{"STRING", 0, 1},
{"text/plain", 0, 2},
}
dest := gtk.Label("drop me file")
dest.DragDestSet(
gtk.GTK_DEST_DEFAULT_MOTION|
gtk.GTK_DEST_DEFAULT_HIGHLIGHT|
gtk.GTK_DEST_DEFAULT_DROP,
targets,
gdk.GDK_ACTION_COPY)
dest.DragDestAddUriTargets()
dest.Connect("drag-data-received", func(ctx *glib.CallbackContext) {
sdata := gtk.SelectionDataFromNative(unsafe.Pointer(ctx.Args(3)))
if sdata != nil {
a := (*[2000]uint8)(sdata.GetData())
files := strings.Split(string(a[0:sdata.GetLength()-1]), "\n")
for i := range files {
filename, _, _ := glib.FilenameFromUri(files[i])
files[i] = filename
}
dialog := gtk.MessageDialog(
window,
gtk.GTK_DIALOG_MODAL,
gtk.GTK_MESSAGE_INFO,
gtk.GTK_BUTTONS_OK,
strings.Join(files, "\n"))
dialog.SetTitle("D&D")
dialog.Response(func() {
dialog.Destroy()
})
dialog.Run()
}
})
vbox.Add(dest)
window.Add(vbox)
window.SetSizeRequest(300, 100)
window.ShowAll()
gtk.Main()
}
示例12: main
func main() {
gtk.Init(&os.Args)
window := gtk.Window(gtk.GTK_WINDOW_TOPLEVEL)
window.SetTitle("GTK Folder View")
window.Connect("destroy", gtk.MainQuit)
swin := gtk.ScrolledWindow(nil, nil)
store := gtk.TreeStore(gdkpixbuf.GetGdkPixbufType(), glib.G_TYPE_STRING)
treeview := gtk.TreeView()
swin.Add(treeview)
treeview.SetModel(store.ToTreeModel())
treeview.AppendColumn(gtk.TreeViewColumnWithAttributes("pixbuf", gtk.CellRendererPixbuf(), "pixbuf", 0))
treeview.AppendColumn(gtk.TreeViewColumnWithAttributes("text", gtk.CellRendererText(), "text", 1))
for n := 1; n <= 10; n++ {
var iter1, iter2, iter3 gtk.GtkTreeIter
store.Append(&iter1, nil)
store.Set(&iter1, gtk.Image().RenderIcon(gtk.GTK_STOCK_DIRECTORY, gtk.GTK_ICON_SIZE_SMALL_TOOLBAR, "").Pixbuf, "Folder"+strconv.Itoa(n))
store.Append(&iter2, &iter1)
store.Set(&iter2, gtk.Image().RenderIcon(gtk.GTK_STOCK_DIRECTORY, gtk.GTK_ICON_SIZE_SMALL_TOOLBAR, "").Pixbuf, "SubFolder"+strconv.Itoa(n))
store.Append(&iter3, &iter2)
store.Set(&iter3, gtk.Image().RenderIcon(gtk.GTK_STOCK_FILE, gtk.GTK_ICON_SIZE_SMALL_TOOLBAR, "").Pixbuf, "File"+strconv.Itoa(n))
}
treeview.Connect("row_activated", func() {
var path *gtk.GtkTreePath
var column *gtk.GtkTreeViewColumn
treeview.GetCursor(&path, &column)
mes := "TreePath is: " + path.String()
dialog := gtk.MessageDialog(
treeview.GetTopLevelAsWindow(),
gtk.GTK_DIALOG_MODAL,
gtk.GTK_MESSAGE_INFO,
gtk.GTK_BUTTONS_OK,
mes)
dialog.SetTitle("TreePath")
dialog.Response(func() {
dialog.Destroy()
})
dialog.Run()
})
window.Add(swin)
window.SetSizeRequest(400, 200)
window.ShowAll()
gtk.Main()
}
示例13: main
func main() {
gtk.Init(nil)
window := gtk.Window(gtk.GTK_WINDOW_TOPLEVEL)
window.SetPosition(gtk.GTK_WIN_POS_CENTER)
window.SetTitle("GTK Go!")
window.Connect("destroy", func(ctx *glib.CallbackContext) {
println("got destroy!", ctx.Data().(string))
gtk.MainQuit()
}, "foo")
//--------------------------------------------------------
// GtkHBox
//--------------------------------------------------------
box := gtk.VBox(false, 1)
//--------------------------------------------------------
// GtkSpinButton
//--------------------------------------------------------
spinbutton1 := gtk.SpinButtonWithRange(1.0, 10.0, 1.0)
spinbutton1.SetDigits(3)
spinbutton1.Spin(gtk.GTK_SPIN_STEP_FORWARD, 7.0)
box.Add(spinbutton1)
spinbutton1.ValueChanged(func() {
val := spinbutton1.GetValueAsInt()
fval := spinbutton1.GetValue()
println("SpinButton changed, new value: " + strconv.Itoa(val) + " | " + strconv.FormatFloat(fval, 'f', 2, 64))
min, max := spinbutton1.GetRange()
println("Range: " + strconv.FormatFloat(min, 'f', 2, 64) + " " + strconv.FormatFloat(max, 'f', 2, 64))
println("Digits: " + strconv.Itoa(int(spinbutton1.GetDigits())))
})
adjustment := gtk.Adjustment(2.0, 1.0, 8.0, 2.0, 0.0, 0.0)
spinbutton2 := gtk.SpinButton(adjustment, 1.0, 1)
spinbutton2.SetRange(0.0, 20.0)
spinbutton2.SetValue(18.0)
spinbutton2.SetIncrements(2.0, 4.0)
box.Add(spinbutton2)
//--------------------------------------------------------
// Event
//--------------------------------------------------------
window.Add(box)
window.SetSizeRequest(600, 600)
window.ShowAll()
gtk.Main()
}
示例14: main
func main() {
gtk.Init(&os.Args)
window := gtk.Window(gtk.GTK_WINDOW_TOPLEVEL)
window.SetTitle("We love Expander")
window.Connect("destroy", gtk.MainQuit)
vbox := gtk.VBox(true, 0)
vbox.SetBorderWidth(5)
expander := gtk.Expander("dan the ...")
expander.Add(gtk.Label("404 contents not found"))
vbox.PackStart(expander, false, false, 0)
window.Add(vbox)
window.ShowAll()
gtk.Main()
}
示例15: main
func main() {
runtime.GOMAXPROCS(10)
glib.ThreadInit(nil)
gdk.ThreadsInit()
gdk.ThreadsEnter()
gtk.Init(nil)
window := gtk.Window(gtk.GTK_WINDOW_TOPLEVEL)
window.Connect("destroy", gtk.MainQuit)
vbox := gtk.VBox(false, 1)
label1 := gtk.Label("")
vbox.Add(label1)
label2 := gtk.Label("")
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()
}