本文整理汇总了Golang中github.com/mattn/go-gtk/gtk.VBox函数的典型用法代码示例。如果您正苦于以下问题:Golang VBox函数的具体用法?Golang VBox怎么用?Golang VBox使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了VBox函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: 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()
}
示例2: 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()
}
示例3: TweetWidget
func TweetWidget(tweet gotter.Tweet) *gtk.GtkFrame {
frame := gtk.Frame(tweet.User.ScreenName)
hbox := gtk.HBox(false, 1)
imagePixbuf := *url2pixbuf(tweet.User.ProfileImageURL)
image := gtk.ImageFromPixbuf(imagePixbuf)
vbox := gtk.VBox(false, 1)
tweettext := gtk.TextView()
tweettext.SetWrapMode(gtk.GTK_WRAP_WORD)
tweettext.SetEditable(false)
tweetbuffer := tweettext.GetBuffer()
tweetbuffer.SetText(tweet.Text)
tweettime, _ := time.Parse(time.RubyDate, tweet.CreatedAt)
hour := (string)(strconv.Itoa(tweettime.Hour))
var minute string
if tweettime.Minute < 10 {
minute = "0" + (string)(strconv.Itoa(tweettime.Minute))
} else {
minute = (string)(strconv.Itoa(tweettime.Minute))
}
whenfromtext := gtk.Label(hour + ":" + minute)
//wherefromtext := gtk.Label(tweet.Source)
hbox.PackStart(image, false, false, 0)
hbox.PackEndDefaults(vbox)
vbox.PackStart(tweettext, false, false, 0)
vbox.PackEnd(whenfromtext, false, false, 0)
//vbox.PackEnd(wherefromtext, false, false, 0)
frame.Add(hbox)
return frame
}
示例4: 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()
}
示例5: 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()
}
示例6: 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()
}
示例7: 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()
}
示例8: 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()
}
示例9: main
func main() {
var menuitem *gtk.GtkMenuItem
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")
//--------------------------------------------------------
// GtkVBox
//--------------------------------------------------------
vbox := gtk.VBox(false, 1)
//--------------------------------------------------------
// GtkMenuBar
//--------------------------------------------------------
menubar := gtk.MenuBar()
vbox.PackStart(menubar, false, false, 0)
//--------------------------------------------------------
// GtkVPaned
//--------------------------------------------------------
vpaned := gtk.VPaned()
vbox.Add(vpaned)
//--------------------------------------------------------
// GtkFrame
//--------------------------------------------------------
frame1 := gtk.Frame("Demo")
framebox1 := gtk.VBox(false, 1)
frame1.Add(framebox1)
frame2 := gtk.Frame("Demo")
framebox2 := gtk.VBox(false, 1)
frame2.Add(framebox2)
vpaned.Pack1(frame1, false, false)
vpaned.Pack2(frame2, false, false)
//--------------------------------------------------------
// GtkImage
//--------------------------------------------------------
dir, _ := path.Split(os.Args[0])
imagefile := path.Join(dir, "../../data/go-gtk-logo.png")
label := gtk.Label("Go Binding for GTK")
label.ModifyFontEasy("DejaVu Serif 15")
framebox1.PackStart(label, false, true, 0)
//--------------------------------------------------------
// GtkEntry
//--------------------------------------------------------
entry := gtk.Entry()
entry.SetText("Hello world")
framebox1.Add(entry)
image := gtk.ImageFromFile(imagefile)
framebox1.Add(image)
//--------------------------------------------------------
// GtkScale
//--------------------------------------------------------
scale := gtk.HScaleWithRange(0, 100, 1)
scale.Connect("value-changed", func() {
println("scale:", int(scale.GetValue()))
})
framebox2.Add(scale)
//--------------------------------------------------------
// GtkHBox
//--------------------------------------------------------
buttons := gtk.HBox(false, 1)
//--------------------------------------------------------
// GtkButton
//--------------------------------------------------------
button := gtk.ButtonWithLabel("Button with label")
button.Clicked(func() {
println("button clicked:", button.GetLabel())
messagedialog := gtk.MessageDialog(
button.GetTopLevelAsWindow(),
gtk.GTK_DIALOG_MODAL,
gtk.GTK_MESSAGE_INFO,
gtk.GTK_BUTTONS_OK,
entry.GetText())
messagedialog.Response(func() {
println("Dialog OK!")
//--------------------------------------------------------
// GtkFileChooserDialog
//--------------------------------------------------------
filechooserdialog := gtk.FileChooserDialog(
"Choose File...",
button.GetTopLevelAsWindow(),
gtk.GTK_FILE_CHOOSER_ACTION_OPEN,
gtk.GTK_STOCK_OK,
int(gtk.GTK_RESPONSE_ACCEPT))
//.........这里部分代码省略.........
示例10: 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)
drawingarea := gtk.DrawingArea()
var p1, p2 point
var gdkwin *gdk.GdkWindow
var pixmap *gdk.GdkPixmap
var gc *gdk.GdkGC
p1.x = -1
p1.y = -1
drawingarea.Connect("configure-event", func() {
if pixmap != nil {
pixmap.Unref()
}
var allocation gtk.GtkAllocation
drawingarea.GetAllocation(&allocation)
pixmap = gdk.Pixmap(drawingarea.GetWindow().GetDrawable(), allocation.Width, allocation.Height, 24)
gc = gdk.GC(pixmap.GetDrawable())
gc.SetRgbFgColor(gdk.Color("white"))
pixmap.GetDrawable().DrawRectangle(gc, true, 0, 0, -1, -1)
gc.SetRgbFgColor(gdk.Color("black"))
gc.SetRgbBgColor(gdk.Color("white"))
})
drawingarea.Connect("motion-notify-event", func(ctx *glib.CallbackContext) {
if gdkwin == nil {
gdkwin = drawingarea.GetWindow()
}
arg := ctx.Args(0)
mev := *(**gdk.EventMotion)(unsafe.Pointer(&arg))
var mt gdk.GdkModifierType
if mev.IsHint != 0 {
gdkwin.GetPointer(&p2.x, &p2.y, &mt)
} else {
p2.x, p2.y = int(mev.X), int(mev.Y)
}
if p1.x != -1 && p2.x != -1 && (gdk.GdkEventMask(mt)&gdk.GDK_BUTTON_PRESS_MASK) != 0 {
pixmap.GetDrawable().DrawLine(gc, p1.x, p1.y, p2.x, p2.y)
drawingarea.GetWindow().Invalidate(nil, false)
}
p1 = p2
})
drawingarea.Connect("expose-event", func() {
if pixmap != nil {
drawingarea.GetWindow().GetDrawable().DrawDrawable(gc, pixmap.GetDrawable(), 0, 0, 0, 0, -1, -1)
}
})
drawingarea.SetEvents(int(gdk.GDK_POINTER_MOTION_MASK | gdk.GDK_POINTER_MOTION_HINT_MASK | gdk.GDK_BUTTON_PRESS_MASK))
vbox.Add(drawingarea)
window.Add(vbox)
window.SetSizeRequest(400, 400)
window.ShowAll()
gtk.Main()
}
示例11: main
func main() {
var prueba int
var Actual Juego
Actual.Init()
var heuristica int
heuristica = 1
var r1 [4]int
var r2 [8]int
Actual.fila1 = Actual.fila1Objetivo
Actual.fila2 = Actual.fila2Objetivo
r1 = Actual.fila1Objetivo
r2 = Actual.fila2Objetivo
//fmt.Println(r1,r2)
prueba = 100
//var menuitem *gtk.GtkMenuItem
gtk.Init(nil)
window := gtk.Window(gtk.GTK_WINDOW_TOPLEVEL)
window.SetPosition(gtk.GTK_WIN_POS_CENTER)
window.SetTitle(" A star")
window.Connect("destroy", func(ctx *glib.CallbackContext) {
println("got destory!\n", ctx.Data().(string))
gtk.MainQuit()
}, "foo")
vbox := gtk.HBox(false, 14)
//menubar:=gtk.MenuBar()
//vbox.PackStart(menubar,false,false,0)
vpaned := gtk.VPaned()
vbox.Add(vpaned)
frame := gtk.Frame("Profundiad")
framebox := gtk.HBox(false, 14)
framebox1 := gtk.VBox(true, 0)
frame1 := gtk.Frame("Rompecabezas ")
frame.Add(framebox)
frame1.Add(framebox1)
drawingarea := gtk.DrawingArea()
vpaned.Add(frame)
vpaned.Add(frame1)
button := gtk.ButtonWithLabel("Resolver")
button2 := gtk.ButtonWithLabel("Desordenar")
button3 := gtk.ButtonWithLabel(" Nivel de Desorden")
//TxtPasos:=gtk.Entry()
frameHu := gtk.VBox(true, 2)
lheuristica := gtk.Label("Heuristica")
comboBox := gtk.ComboBoxEntryNewText()
comboBox.AppendText("Piezas Desordenadas")
comboBox.AppendText("Distancia entre Piezas")
comboBox.Connect("changed", func() {
if strings.EqualFold(comboBox.GetActiveText(), "Piezas Desordenadas") {
heuristica = 2
} else {
heuristica = 1
}
})
frameHu.Add(lheuristica)
frameHu.Add(comboBox)
entry := gtk.Entry()
framebox.Add(entry)
framebox.Add(button)
framebox.Add(frameHu)
framebox.Add(button2)
framebox.Add(button3)
//framebox1.Add(TxtPasos)
//var gdkwin *gdk.GdkWindow
var pixmap *gdk.GdkPixmap
var gc *gdk.GdkGC
drawingarea.Connect("configure-event", func() {
if pixmap != nil {
pixmap.Unref()
}
var allocation gtk.GtkAllocation
drawingarea.GetAllocation(&allocation)
//.........这里部分代码省略.........
示例12: build
func (window *GhMainWindow) build() {
window.SetTitle("ghighlights")
window.bindKeys()
window.Connect("destroy", gtk.MainQuit)
mainVBox := gtk.VBox(false, 1)
menubar := window.buildMenuBar()
mainVBox.PackStart(menubar, false, false, 0)
scrolledTextViewWindow := gtk.ScrolledWindow(nil, nil)
scrolledTextViewWindow.SetPolicy(gtk.GTK_POLICY_AUTOMATIC, gtk.GTK_POLICY_AUTOMATIC)
textView := gtkext.TextViewWithPlaceholder("Highlight")
textView.SetSizeRequest(600, 100)
textView.SetWrapMode(gtk.GTK_WRAP_WORD)
textView.SetAcceptsTab(false)
scrolledTextViewWindow.Add(textView)
scrolledTextViewWindow.SetSizeRequest(600, 100)
mainVBox.Add(scrolledTextViewWindow)
scrolledCommentTextViewWindow := gtk.ScrolledWindow(nil, nil)
scrolledCommentTextViewWindow.SetPolicy(gtk.GTK_POLICY_AUTOMATIC, gtk.GTK_POLICY_AUTOMATIC)
commentTextView := gtkext.TextViewWithPlaceholder("Comment")
commentTextView.SetSizeRequest(600, 40)
commentTextView.SetWrapMode(gtk.GTK_WRAP_WORD)
commentTextView.SetAcceptsTab(false)
scrolledCommentTextViewWindow.Add(commentTextView)
scrolledCommentTextViewWindow.SetSizeRequest(600, 40)
mainVBox.Add(scrolledCommentTextViewWindow)
readingHBox := gtk.HBox(false, 10)
pageNumberEntry := gtk.Entry()
pageTotalEntry := gtk.Entry()
readingsComboBox := gtk.ComboBoxText()
readings := models.Readings()
for _, reading := range readings.Items {
readingsComboBox.AppendText(reading.Title)
}
readingsComboBox.SetActive(0)
readingsComboBox.Connect("changed", func() {
reading := readings.FindByTitle(readingsComboBox.GetActiveText())
pageNumberEntry.SetText("0")
pageTotalEntry.SetText(strconv.Itoa(reading.TotalPages))
})
align := gtk.Alignment(1, 1, 1, 0)
align.Add(readingsComboBox)
readingHBox.Add(align)
pageHBox := gtk.HBox(false, 1)
pageHBox.Add(gtk.Label("Page"))
pageNumberEntry.SetAlignment(1)
pageNumberEntry.SetWidthChars(4)
pageNumberEntry.SetText("0")
pageHBox.Add(pageNumberEntry)
pageHBox.Add(gtk.Label("of"))
pageTotalEntry.SetAlignment(1)
pageTotalEntry.SetWidthChars(4)
if len(readings.Items) > 0 {
pageTotalEntry.SetText(strconv.Itoa(readings.Items[0].TotalPages))
}
pageHBox.Add(pageTotalEntry)
pageBoxAlignment := gtk.Alignment(0, 0, 0, 0)
pageBoxAlignment.Add(pageHBox)
readingHBox.Add(pageBoxAlignment)
mainVBox.Add(readingHBox)
addHighlightButton := gtk.ButtonWithLabel("Add highlight")
window.highlights = models.Highlights()
addHighlightButton.Clicked(func() {
reading := readings.FindByTitle(readingsComboBox.GetActiveText())
readingId := reading.ReadmillId
content := textView.GetStrippedText()
comment := commentTextView.GetStrippedText()
pageNumber, _ := strconv.Atoi(pageNumberEntry.GetText())
pageTotal, _ := strconv.Atoi(pageTotalEntry.GetText())
position := float32(pageNumber) / float32(pageTotal)
highlight := models.GhHighlight{content, readingId, position, time.Now(), comment}
window.highlights.Add(highlight)
readings.UpdateTotalPages(pageTotal, reading)
textView.DeleteText()
commentTextView.DeleteText()
})
readingHBox.PackEnd(addHighlightButton, false, false, 0)
window.Add(mainVBox)
//.........这里部分代码省略.........
示例13: main
func main() {
gdk.ThreadsInit()
gtk.Init(&os.Args)
window := gtk.Window(gtk.GTK_WINDOW_TOPLEVEL)
window.SetTitle("Twitter!")
window.Connect("destroy", gtk.MainQuit)
vbox := gtk.VBox(false, 1)
scrolledwin := gtk.ScrolledWindow(nil, nil)
textview := gtk.TextView()
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.ButtonWithLabel("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 {
return
}
for ts.Err() == nil {
t := tweet{}
if err := ts.UnmarshalNext(&t); err != nil {
fmt.Println("error reading tweet: ", err)
continue
}
var iter gtk.GtkTextIter
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()
}
示例14: main
func main() {
s.RunSpontaneous(r)
var menuitem *gtk.GtkMenuItem
gtk.Init(nil)
window := gtk.Window(gtk.GTK_WINDOW_TOPLEVEL)
window.SetPosition(gtk.GTK_WIN_POS_CENTER)
window.SetTitle("Plotomaton")
window.Connect("destroy", gtk.MainQuit)
vbox := gtk.VBox(false, 1)
menubar := gtk.MenuBar()
vbox.PackStart(menubar, false, false, 0)
vpaned := gtk.VPaned()
vbox.Add(vpaned)
frame1 := gtk.Frame("Text")
framebox1 := gtk.VBox(false, 1)
frame1.Add(framebox1)
frame2 := gtk.Frame("Input")
framebox2 := gtk.VBox(false, 1)
frame2.Add(framebox2)
vpaned.Pack1(frame1, false, false)
vpaned.Pack2(frame2, false, false)
//TODO: These buttons will have to be dynamically created for the option avalible.
buttons := []*gtk.GtkButton{gtk.Button(), gtk.Button(), gtk.Button(), gtk.Button(), gtk.Button(), gtk.Button(), gtk.Button(), gtk.Button(), gtk.Button(), gtk.Button(), gtk.Button(), gtk.Button(), gtk.Button(), gtk.Button(), gtk.Button()}
swin := gtk.ScrolledWindow(nil, nil)
swin.SetPolicy(gtk.GTK_POLICY_AUTOMATIC, gtk.GTK_POLICY_AUTOMATIC)
swin.SetShadowType(gtk.GTK_SHADOW_IN)
textview := gtk.TextView()
textview.SetCursorVisible(false)
textview.SetEditable(false)
textview.SetWrapMode(2)
var start, end gtk.GtkTextIter
buffer := textview.GetBuffer()
buffer.GetStartIter(&start)
buffer.GetEndIter(&end)
buffer.Delete(&start, &end)
for {
log = log.Future()
if cause := log.Cause(); cause != nil {
buffer.SetText(cause.Description())
}
if log == s.Now() {
break
}
}
swin.Add(textview)
for _, t := range buttons {
framebox2.Add(t)
}
for j, _ := range buttons {
//This looks weird but go functions have full access to their lexical environment
var k int = j
buttons[k].Clicked(func() {
// println(buttons[k].GetLabel())
// println(k)
updateChoice(k, buttons, textview)
})
}
framebox1.Add(swin)
cascademenu := gtk.MenuItemWithMnemonic("_File")
menubar.Append(cascademenu)
submenu := gtk.Menu()
cascademenu.SetSubmenu(submenu)
menuitem = gtk.MenuItemWithMnemonic("E_xit")
menuitem.Connect("activate", func() {
gtk.MainQuit()
})
submenu.Append(menuitem)
cascademenu = gtk.MenuItemWithMnemonic("_Help")
menubar.Append(cascademenu)
submenu = gtk.Menu()
cascademenu.SetSubmenu(submenu)
menuitem = gtk.MenuItemWithMnemonic("_About")
menuitem.Connect("activate", func() {
dialog := gtk.AboutDialog()
dialog.SetName("Plotamaton!")
dialog.SetProgramName("Plotamaton GTK-Client V0.1")
dialog.SetAuthors([]string{
"Sean Anderson", "Kieron Gillespie", "Sam Payson", "Kevin Reid"})
dir, _ := path.Split(os.Args[0])
//.........这里部分代码省略.........
示例15: Init
func Init(size uint) {
var (
files *gtk.GtkHBox
examples_cnt int
newfile_flag bool
cs_desc_normal *_Ctype_char
cs_desc_bold *_Ctype_char
)
s = new(solver.Solver)
s.Size = size
if s.Size == 9 {
cs_desc_normal = C.CString("Sans 14")
cs_desc_bold = C.CString("Sans Bold 14")
} else {
cs_desc_normal = C.CString("Sans 16")
cs_desc_bold = C.CString("Sans Bold 16")
}
desc_normal = C.pango_font_description_from_string(cs_desc_normal)
desc_bold = C.pango_font_description_from_string(cs_desc_bold)
C.free_string(cs_desc_normal)
C.free_string(cs_desc_bold)
gtk.Init(&os.Args)
window := gtk.Window(gtk.GTK_WINDOW_TOPLEVEL)
window.SetResizable(false)
window.SetTitle("Sudoku solver")
window.Connect("destroy", func() {
gtk.MainQuit()
})
window.Connect("key-press-event", func(ctx *glib.CallbackContext) {
arg := ctx.Args(0)
kev := *(**gdk.EventKey)(unsafe.Pointer(&arg))
r, st := rune(kev.Keyval), gdk.GdkModifierType(kev.State)
if st&gdk.GDK_CONTROL_MASK != 0 {
if r == 122 || r == 90 { // Ctrl-Z
m := cs_pop()
clear()
for i := uint(0); i < s.Size; i++ {
for j := uint(0); j < s.Size; j++ {
v := int(m[i][j])
if v != 0 {
entries[i][j].SetText(strconv.Itoa(v))
}
}
}
}
}
})
vbox := gtk.VBox(false, 10)
table := gtk.Table(3, s.Size/3, false)
bg := [2]*gdk.GdkColor{gdk.Color("white"), gdk.Color("#e9f2ea")}
for y := uint(0); y < 3; y++ {
for x := uint(0); x < s.Size/3; x++ {
subtable := gtk.Table(s.Size/3, 3, false)
for sy := uint(0); sy < s.Size/3; sy++ {
for sx := uint(0); sx < 3; sx++ {
w := gtk.Entry()
w.SetWidthChars(1)
w.SetMaxLength(1)
if s.Size == 9 {
w.SetSizeRequest(23, 25)
} else {
w.SetSizeRequest(25, 27)
}
w.Connect("key-press-event", func(ctx *glib.CallbackContext) bool {
data := ctx.Data().([]uint)
y, x := data[0], data[1]
arg := ctx.Args(0)
kev := *(**gdk.EventKey)(unsafe.Pointer(&arg))
r := rune(kev.Keyval)
switch r & 0xFF {
case 81:
if x != 0 || y != 0 {
if x == 0 {
x = s.Size - 1
y--
} else {
x--
}
}
case 82:
if y != 0 {
y--
}
case 83:
if x != s.Size-1 || y != s.Size-1 {
if x == s.Size-1 {
x = 0
y++
} else {
x++
}
}
case 84:
if y != s.Size-1 {
//.........这里部分代码省略.........