本文整理汇总了Golang中github.com/mattn/go-gtk/gtk.NewTextView函数的典型用法代码示例。如果您正苦于以下问题:Golang NewTextView函数的具体用法?Golang NewTextView怎么用?Golang NewTextView使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了NewTextView函数的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。
示例1: main
func main() {
mc := memcache.New("127.0.0.1:11211")
gtk.Init(nil)
window := gtk.NewWindow(gtk.WINDOW_TOPLEVEL)
window.SetTitle("memcachedclient")
window.Connect("destroy", gtk.MainQuit)
vbox := gtk.NewVBox(false, 1)
swin := gtk.NewScrolledWindow(nil, nil)
textview := gtk.NewTextView()
textview.SetEditable(false)
textview.SetCursorVisible(false)
textview.ModifyFontEasy("monospace 12")
swin.Add(textview)
vbox.Add(swin)
buffer := textview.GetBuffer()
input := gtk.NewEntry()
input.SetEditable(true)
vbox.PackEnd(input, false, false, 0)
tag := buffer.CreateTag("red", map[string]string{"foreground": "#FF0000"})
input.Connect("activate", func() {
var iter gtk.TextIter
tokens := strings.SplitN(input.GetText(), " ", 3)
if len(tokens) == 2 && strings.ToUpper(tokens[0]) == "GET" {
if t, err := mc.Get(tokens[1]); err == nil {
buffer.GetEndIter(&iter)
buffer.Insert(&iter, string(t.Value)+"\n")
} else {
buffer.InsertWithTag(&iter, err.Error()+"\n", tag)
}
input.SetText("")
} else if len(tokens) == 3 && strings.ToUpper(tokens[0]) == "SET" {
if err := mc.Set(
&memcache.Item{
Key: tokens[1],
Value: []byte(tokens[2]),
}); err == nil {
buffer.GetEndIter(&iter)
buffer.InsertWithTag(&iter, "OK\n", tag)
} else {
buffer.InsertWithTag(&iter, err.Error()+"\n", tag)
}
input.SetText("")
}
})
input.GrabFocus()
window.Add(vbox)
window.SetSizeRequest(300, 500)
window.ShowAll()
gtk.Main()
}
开发者ID:mattn,项目名称:memcachedclient,代码行数:58,代码来源:memcachedclient.go
示例2: main
func main() {
gtk.Init(nil)
window := gtk.NewWindow(gtk.WINDOW_TOPLEVEL)
window.SetPosition(gtk.WIN_POS_CENTER)
window.SetTitle("GTK Go!")
window.SetIconName("textview")
window.Connect("destroy", gtk.MainQuit)
textview := gtk.NewTextView()
textview.SetEditable(true)
textview.SetCursorVisible(true)
var iter gtk.TextIter
buffer := textview.GetBuffer()
buffer.GetStartIter(&iter)
buffer.Insert(&iter, "Hello ")
tag := buffer.CreateTag("bold", map[string]string{"background": "#FF0000", "weight": "700"})
buffer.InsertWithTag(&iter, "Google!", tag)
u := "http://www.google.com"
tag.SetData("tag-name", unsafe.Pointer(&u))
textview.Connect("event-after", func(ctx *glib.CallbackContext) {
arg := ctx.Args(0)
if ev := *(**gdk.EventAny)(unsafe.Pointer(&arg)); ev.Type != gdk.BUTTON_RELEASE {
return
}
ev := *(**gdk.EventButton)(unsafe.Pointer(&arg))
var iter gtk.TextIter
textview.GetIterAtLocation(&iter, int(ev.X), int(ev.Y))
tags := iter.GetTags()
for n := uint(0); n < tags.Length(); n++ {
vv := tags.NthData(n)
tag := gtk.NewTextTagFromPointer(vv)
u := *(*string)(tag.GetData("tag-name"))
fmt.Println(u)
}
})
window.Add(textview)
window.SetSizeRequest(600, 600)
window.ShowAll()
gtk.Main()
}
开发者ID:hauke96,项目名称:go-gtk,代码行数:45,代码来源:textview.go
示例3: main
func main() {
gtk.Init(&os.Args)
window := gtk.NewWindow(gtk.WINDOW_TOPLEVEL)
window.SetTitle("µemacs/pp")
window.Connect("destroy", gtk.MainQuit)
window.Connect("key-press-event", handleKeyPress)
SetKeyReturn(kh.GTKKeyPressEvent{gdk.KEY_Return, 0})
swin := gtk.NewScrolledWindow(nil, nil)
sourcebuffer := gsv.NewSourceBufferWithLanguage(gsv.SourceLanguageManagerGetDefault().GetLanguage("cpp"))
sourceview = gsv.NewSourceViewWithBuffer(sourcebuffer)
var start gtk.TextIter
sourcebuffer.GetStartIter(&start)
sourcebuffer.Insert(&start, `writing stuff, awww yea!`)
textview = gtk.NewTextView()
textbuffer = textview.GetBuffer()
var bufiter gtk.TextIter
sourcebuffer.GetStartIter(&bufiter)
bufWrapper := ed.GtkTextBufferReadWriter{&sourceview.TextView.Container.Widget, bufiter, &sourcebuffer.TextBuffer}
var comiter gtk.TextIter
textbuffer.GetStartIter(&comiter)
comWrapper := ed.GtkTextBufferReadWriter{&textview.Container.Widget, comiter, textbuffer}
microemacs = editor.Editor{"", &bufWrapper, &comWrapper}
vbox := gtk.NewVBox(false, 0)
vbox.PackStart(swin, true, true, 0)
vbox.PackEnd(textview, false, true, 0)
swin.Add(sourceview)
window.Add(vbox)
window.SetSizeRequest(300, 300)
window.ShowAll()
gtk.Main()
}
开发者ID:pilsprog,项目名称:micro-emacs-pp,代码行数:41,代码来源:main.go
示例4: 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() {
go func() {
gdk.ThreadsEnter()
button.SetSensitive(false)
gdk.ThreadsLeave()
r, err := http.Get("https://api.twitter.com/1/statuses/user_timeline.json?screen_name=go_nuts")
if err == nil {
var b []byte
if r.ContentLength == -1 {
b, err = ioutil.ReadAll(r.Body)
} else {
b = make([]byte, r.ContentLength)
_, err = io.ReadFull(r.Body, b)
}
if err != nil {
fmt.Println(err)
return
}
var j interface{}
err = json.NewDecoder(bytes.NewBuffer(b)).Decode(&j)
if err != nil {
fmt.Println(err)
return
}
arr := j.([]interface{})
for i := 0; i < len(arr); i++ {
data := arr[i].(map[string]interface{})
icon := data["user"].(map[string]interface{})["profile_image_url"].(string)
var iter gtk.TextIter
pixbufbytes, resp := readURL(icon)
gdk.ThreadsEnter()
buffer.GetEndIter(&iter)
if resp != nil {
buffer.InsertPixbuf(&iter, bytes2pixbuf(pixbufbytes, resp.Header.Get("Content-Type")))
}
gdk.ThreadsLeave()
name := data["user"].(map[string]interface{})["screen_name"].(string)
text := data["text"].(string)
gdk.ThreadsEnter()
buffer.Insert(&iter, " ")
buffer.InsertWithTag(&iter, name, tag)
buffer.Insert(&iter, ":"+text+"\n")
gtk.MainIterationDo(false)
gdk.ThreadsLeave()
}
} else {
fmt.Println(err)
}
button.SetSensitive(true)
}()
})
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,代码行数:82,代码来源:twitter.go
示例5: 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
示例6: main
//.........这里部分代码省略.........
// GtkComboBoxEntry
//--------------------------------------------------------
combos := gtk.NewHBox(false, 1)
comboboxentry := gtk.NewComboBoxEntryNewText()
comboboxentry.AppendText("Monkey")
comboboxentry.AppendText("Tiger")
comboboxentry.AppendText("Elephant")
comboboxentry.Connect("changed", func() {
println("value:", comboboxentry.GetActiveText())
})
combos.Add(comboboxentry)
//--------------------------------------------------------
// GtkComboBox
//--------------------------------------------------------
combobox := gtk.NewComboBoxNewText()
combobox.AppendText("Peach")
combobox.AppendText("Banana")
combobox.AppendText("Apple")
combobox.SetActive(1)
combobox.Connect("changed", func() {
println("value:", combobox.GetActiveText())
})
combos.Add(combobox)
framebox2.PackStart(combos, false, false, 0)
//--------------------------------------------------------
// GtkTextView
//--------------------------------------------------------
swin := gtk.NewScrolledWindow(nil, nil)
swin.SetPolicy(gtk.POLICY_AUTOMATIC, gtk.POLICY_AUTOMATIC)
swin.SetShadowType(gtk.SHADOW_IN)
textview := gtk.NewTextView()
var start, end gtk.TextIter
buffer := textview.GetBuffer()
buffer.GetStartIter(&start)
buffer.Insert(&start, "Hello ")
buffer.GetEndIter(&end)
buffer.Insert(&end, "World!")
tag := buffer.CreateTag("bold", map[string]string{
"background": "#FF0000", "weight": "700"})
buffer.GetStartIter(&start)
buffer.GetEndIter(&end)
buffer.ApplyTag(tag, &start, &end)
swin.Add(textview)
framebox2.Add(swin)
buffer.Connect("changed", func() {
println("changed")
})
//--------------------------------------------------------
// GtkMenuItem
//--------------------------------------------------------
cascademenu := gtk.NewMenuItemWithMnemonic("_File")
menubar.Append(cascademenu)
submenu := gtk.NewMenu()
cascademenu.SetSubmenu(submenu)
menuitem = gtk.NewMenuItemWithMnemonic("E_xit")
menuitem.Connect("activate", func() {
gtk.MainQuit()
})
submenu.Append(menuitem)
开发者ID:JessonChan,项目名称:go-gtk,代码行数:66,代码来源:demo.go
示例7: main
func main() {
flag.Parse()
common.SetDefaultGtkTheme()
runtime.GOMAXPROCS(runtime.NumCPU())
rclient = &remoton.Client{Prefix: "/remoton", TLSConfig: &tls.Config{}}
sigs := make(chan os.Signal, 1)
signal.Notify(sigs, syscall.SIGHUP, syscall.SIGINT, syscall.SIGABRT, syscall.SIGKILL, syscall.SIGTERM)
go func() {
<-sigs
chatSrv.Terminate()
tunnelSrv.Terminate()
}()
gtk.Init(nil)
window := gtk.NewWindow(gtk.WINDOW_TOPLEVEL)
window.SetPosition(gtk.WIN_POS_CENTER)
window.SetTitle("REMOTON SUPPORT")
window.Connect("destroy", func() {
gtk.MainQuit()
chatSrv.Terminate()
tunnelSrv.Terminate()
})
window.SetIcon(common.GetIconGdkPixbuf())
appLayout := gtk.NewVBox(false, 1)
menu := gtk.NewMenuBar()
appLayout.Add(menu)
cascademenu := gtk.NewMenuItemWithMnemonic("_Help")
menu.Append(cascademenu)
submenu := gtk.NewMenu()
cascademenu.SetSubmenu(submenu)
menuitem := gtk.NewMenuItemWithMnemonic("_About")
menuitem.Connect("activate", func() {
dialog := common.GtkAboutDialog()
dialog.SetProgramName("Support Desktop")
dialog.Run()
dialog.Destroy()
})
submenu.Append(menuitem)
hpaned := gtk.NewHPaned()
appLayout.Add(hpaned)
//---
//CHAT
//---
frameChat := gtk.NewFrame("Chat")
chatBox := gtk.NewVBox(false, 1)
frameChat.Add(chatBox)
swinChat := gtk.NewScrolledWindow(nil, nil)
chatHistory := gtk.NewTextView()
swinChat.Add(chatHistory)
chatEntry := gtk.NewEntry()
chatEntry.Connect("key-press-event", func(ctx *glib.CallbackContext) {
arg := ctx.Args(0)
event := *(**gdk.EventKey)(unsafe.Pointer(&arg))
if event.Keyval == gdk.KEY_Return {
msgToSend := chatEntry.GetText()
chatSrv.Send(msgToSend)
chatHistorySend(chatHistory, msgToSend)
chatEntry.SetText("")
}
})
chatSrv.OnRecv(func(msg string) {
log.Println(msg)
chatHistoryRecv(chatHistory, msg)
})
chatBox.Add(chatEntry)
chatBox.Add(swinChat)
//---
//CONTROL
//---
frameControl := gtk.NewFrame("Control")
controlBox := gtk.NewVBox(false, 1)
frameControl.Add(controlBox)
controlBox.Add(gtk.NewLabel("Machine ID"))
machineIDEntry := gtk.NewEntry()
controlBox.Add(machineIDEntry)
controlBox.Add(gtk.NewLabel("Machine AUTH"))
machineAuthEntry := gtk.NewEntry()
controlBox.Add(machineAuthEntry)
controlBox.Add(gtk.NewLabel("Server"))
serverEntry := gtk.NewEntry()
serverEntry.SetText("localhost:9934")
if os.Getenv("REMOTON_SERVER") != "" {
serverEntry.SetText(os.Getenv("REMOTON_SERVER"))
serverEntry.SetEditable(false)
//.........这里部分代码省略.........
开发者ID:bit4bit,项目名称:remoton,代码行数:101,代码来源:main.go
示例8: mainWindow
func mainWindow() {
gtk.Init(&os.Args)
// window settings
window_main := gtk.NewWindow(gtk.WINDOW_TOPLEVEL)
window_main.SetPosition(gtk.WIN_POS_CENTER)
window_main.SetTitle("Social Gopher")
window_main.Connect("destroy", func() {
println("[!] Quit application")
gtk.MainQuit()
})
// images
image_profile := loadImageAsset("profile")
image_stream := loadImageAsset("stream")
image_mentions := loadImageAsset("mentions")
image_interactions := loadImageAsset("interactions")
image_stars := loadImageAsset("stars")
image_messages := loadImageAsset("messages")
image_settings := loadImageAsset("settings")
// containers
container_main := gtk.NewHBox(false, 1)
container_left := gtk.NewVBox(false, 1)
container_right := gtk.NewVBox(false, 5)
container_compose := gtk.NewHBox(false, 5)
container_profile := gtk.NewHBox(false, 5)
container_profile.Add(image_profile)
container_left.SetBorderWidth(5)
container_right.SetBorderWidth(5)
// toolbar
button_stream := gtk.NewToolButton(image_stream, "My Stream")
button_mentions := gtk.NewToolButton(image_mentions, "Mentions")
button_interactions := gtk.NewToolButton(image_interactions, "Interactions")
button_stars := gtk.NewToolButton(image_stars, "Stars")
button_messages := gtk.NewToolButton(image_messages, "Messages")
button_settings := gtk.NewToolButton(image_settings, "Settings")
button_separator := gtk.NewSeparatorToolItem()
toolbar := gtk.NewToolbar()
toolbar.SetOrientation(gtk.ORIENTATION_VERTICAL)
toolbar.Insert(button_stream, -1)
toolbar.Insert(button_mentions, -1)
toolbar.Insert(button_interactions, -1)
toolbar.Insert(button_stars, -1)
toolbar.Insert(button_messages, -1)
toolbar.Insert(button_separator, -1)
toolbar.Insert(button_settings, -1)
// stream list
list_swin := gtk.NewScrolledWindow(nil, nil)
list_swin.SetPolicy(-1, 1)
list_swin.SetShadowType(2)
list_textView := gtk.NewTextView()
list_textView.SetEditable(false)
list_textView.SetCursorVisible(false)
list_textView.SetWrapMode(2)
list_swin.Add(list_textView)
list_buffer := list_textView.GetBuffer()
// compose message
compose := gtk.NewTextView()
compose.SetEditable(true)
compose.SetWrapMode(2)
compose_swin := gtk.NewScrolledWindow(nil, nil)
compose_swin.SetPolicy(1, 1)
compose_swin.SetShadowType(1)
compose_swin.Add(compose)
compose_counter := gtk.NewLabel("256")
compose_buffer := compose.GetBuffer()
compose_buffer.Connect("changed", func() {
chars_left := 256 - compose_buffer.GetCharCount()
compose_counter.SetText(strconv.Itoa(chars_left))
})
// post button and counter
button_post := gtk.NewButtonWithLabel("Post")
container_post := gtk.NewVBox(false, 1)
container_post.Add(compose_counter)
container_post.Add(button_post)
// button functions
button_stream.OnClicked(func() {
list_buffer.SetText("My Stream")
})
button_mentions.OnClicked(func() {
list_buffer.SetText("Mentions")
})
button_interactions.OnClicked(func() {
list_buffer.SetText("Interactions")
})
button_stars.OnClicked(func() {
list_buffer.SetText("Stars")
})
button_messages.OnClicked(func() {
list_buffer.SetText("Messages")
})
button_settings.OnClicked(func() {
accountWindow()
//.........这里部分代码省略.........
开发者ID:kisom,项目名称:socialgopher,代码行数:101,代码来源:app.go
示例9: init_tabby
func init_tabby() {
init_navigation()
init_inotify()
search_view.Init()
source_buf = gtksourceview.NewSourceBuffer()
source_buf.Connect("paste-done", paste_done_cb, nil)
source_buf.Connect("mark-set", mark_set_cb, nil)
source_buf.Connect("modified-changed", buf_changed_cb, nil)
init_lang()
source_buf.CreateTag("instance", map[string]string{"background": "#FF8080"})
tree_store = gtk.NewTreeStore(glib.G_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.NewTextView()
error_view.ModifyFontEasy("Monospace Regular 8")
error_view.SetEditable(false)
error_buf = error_view.GetBuffer()
source_view = gtksourceview.NewSourceViewWithBuffer(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(gtksourceview.SOURCE_DRAW_SPACES_TAB)
source_view.SetSmartHomeEnd(gtksourceview.SOURCE_SMART_HOME_END_ALWAYS)
source_view.SetWrapMode(gtk.WRAP_WORD)
vbox := gtk.NewVBox(false, 0)
inner_hpaned := gtk.NewHPaned()
view_vpaned := gtk.NewVPaned()
outer_hpaned := gtk.NewHPaned()
outer_hpaned.Add1(inner_hpaned)
inner_hpaned.Add2(view_vpaned)
menubar := gtk.NewMenuBar()
vbox.PackStart(menubar, false, false, 0)
vbox.PackStart(outer_hpaned, true, true, 0)
file_item := gtk.NewMenuItemWithMnemonic("_File")
menubar.Append(file_item)
file_submenu := gtk.NewMenu()
file_item.SetSubmenu(file_submenu)
accel_group := gtk.NewAccelGroup()
new_item := gtk.NewMenuItemWithMnemonic("_New")
file_submenu.Append(new_item)
new_item.Connect("activate", new_cb, nil)
new_item.AddAccelerator("activate", accel_group, gdk.KEY_n, gdk.CONTROL_MASK, gtk.ACCEL_VISIBLE)
open_item := gtk.NewMenuItemWithMnemonic("_Open")
file_submenu.Append(open_item)
open_item.Connect("activate", open_cb, nil)
open_item.AddAccelerator("activate", accel_group, gdk.KEY_o, gdk.CONTROL_MASK, gtk.ACCEL_VISIBLE)
open_rec_item := gtk.NewMenuItemWithMnemonic("Open _Recursively")
file_submenu.Append(open_rec_item)
open_rec_item.Connect("activate", open_rec_cb, nil)
save_item := gtk.NewMenuItemWithMnemonic("_Save")
file_submenu.Append(save_item)
save_item.Connect("activate", save_cb, nil)
save_item.AddAccelerator("activate", accel_group, gdk.KEY_s, gdk.CONTROL_MASK, gtk.ACCEL_VISIBLE)
save_as_item := gtk.NewMenuItemWithMnemonic("Save _as")
file_submenu.Append(save_as_item)
save_as_item.Connect("activate", save_as_cb, nil)
close_item := gtk.NewMenuItemWithMnemonic("_Close")
file_submenu.Append(close_item)
close_item.Connect("activate", close_cb, nil)
close_item.AddAccelerator("activate", accel_group, gdk.KEY_w, gdk.CONTROL_MASK, gtk.ACCEL_VISIBLE)
exit_item := gtk.NewMenuItemWithMnemonic("E_xit")
file_submenu.Append(exit_item)
exit_item.Connect("activate", exit_cb, nil)
navigation_item := gtk.NewMenuItemWithMnemonic("_Navigation")
menubar.Append(navigation_item)
navigation_submenu := gtk.NewMenu()
navigation_item.SetSubmenu(navigation_submenu)
prev_instance_item := gtk.NewMenuItemWithMnemonic("_Previous Instance")
navigation_submenu.Append(prev_instance_item)
prev_instance_item.Connect("activate", prev_instance_cb, nil)
//.........这里部分代码省略.........
开发者ID:JessonChan,项目名称:tabby,代码行数:101,代码来源:main.go
示例10: main
func main() {
runtime.LockOSThread()
gtk.Init(&os.Args)
gdk.ThreadsInit()
window := gtk.NewWindow(gtk.WINDOW_TOPLEVEL)
window.SetTitle("DMS GUI")
window.Connect("destroy", gtk.MainQuit)
vbox := gtk.NewVBox(false, 0)
window.Add(vbox)
hbox := gtk.NewHBox(false, 0)
vbox.PackStart(hbox, false, true, 0)
hbox.PackStart(gtk.NewLabel("Shared directory: "), false, true, 0)
dialog := gtk.NewFileChooserDialog(
"Select directory to share", window, gtk.FILE_CHOOSER_ACTION_SELECT_FOLDER,
gtk.STOCK_CANCEL, gtk.RESPONSE_CANCEL,
gtk.STOCK_OK, gtk.RESPONSE_ACCEPT)
button := gtk.NewFileChooserButtonWithDialog(dialog)
hbox.Add(button)
logView := gtk.NewTextView()
logView.SetEditable(false)
logView.ModifyFontEasy("monospace")
logView.SetWrapMode(gtk.WRAP_WORD_CHAR)
logViewScroller := gtk.NewScrolledWindow(nil, nil)
logViewScroller.Add(logView)
logViewScroller.SetPolicy(gtk.POLICY_AUTOMATIC, gtk.POLICY_ALWAYS)
vbox.PackEnd(logViewScroller, true, true, 0)
getPath := func() string {
return button.GetFilename()
}
window.ShowAll()
if dialog.Run() != gtk.RESPONSE_ACCEPT {
return
}
go func() {
dmsServer := dms.Server{
RootObjectPath: getPath(),
}
if err := dmsServer.Serve(); err != nil {
log.Fatalln(err)
}
defer dmsServer.Close()
runtime.LockOSThread()
gdk.ThreadsEnter()
button.Connect("selection-changed", func() {
dmsServer.RootObjectPath = getPath()
})
gdk.ThreadsLeave()
runtime.UnlockOSThread()
dmsServer.Serve()
}()
gtk.Main()
runtime.UnlockOSThread()
}
开发者ID:ronindev,项目名称:dms,代码行数:62,代码来源:main.go
示例11: main
//.........这里部分代码省略.........
} else {
arg.ignoreCase = false
}
})
buttons.Add(checkbutton)
checkMatchButton := gtk.NewCheckButtonWithLabel("Partial matching / Perfect matching")
checkMatchButton.Connect("toggled", func() {
if checkMatchButton.GetActive() {
arg.perfectMatch = false
} else {
arg.perfectMatch = true
}
})
buttons.Add(checkMatchButton)
combobox := gtk.NewComboBoxText()
for _, delim := range delimName {
combobox.AppendText(delim)
}
combobox.SetActive(0)
combobox.Connect("changed", func() {
fmt.Println("value:", combobox.GetActiveText())
arg.delim = combobox.GetActiveText()
})
buttons.Add(combobox)
//--------------------------------------------------------
// GtkTextView
//--------------------------------------------------------
swin := gtk.NewScrolledWindow(nil, nil)
swin.SetPolicy(gtk.POLICY_AUTOMATIC, gtk.POLICY_AUTOMATIC)
swin.SetShadowType(gtk.SHADOW_IN)
textview := gtk.NewTextView()
// var start, end gtk.TextIter
var end gtk.TextIter
buffer := textview.GetBuffer()
swin.Add(textview)
//--------------------------------------------------------
// Run button
//--------------------------------------------------------
runbutton := gtk.NewButtonWithLabel("Run")
runbutton.Clicked(func() {
arg.inputPath = ientry.GetText()
arg.filterPath = fentry.GetText()
arg.outputPath = oentry.GetText()
num, err := getKeysearchWords(arg)
buffer.GetStartIter(&end)
if err != nil {
log.Println(err)
buffer.Insert(&end, err.Error()+"\n")
} else {
buffer.Insert(&end, "GoMADScan found "+strconv.Itoa(num)+
" modification sites.\nThe result is written into "+arg.outputPath+".\n")
}
})
buttons.Add(runbutton)
framebox2.PackStart(buttons, false, false, 0)
//--------------------------------------------------------
// GtkVSeparator
//--------------------------------------------------------
vsep := gtk.NewVSeparator()
framebox2.PackStart(vsep, false, false, 0)
开发者ID:carushi,项目名称:GoMADScan,代码行数:66,代码来源:GoMADScan.go
示例12: main
func main() {
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"]}
runtime.LockOSThread()
gtk.Init(&os.Args)
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"})
hbox := gtk.NewHBox(false, 1)
vbox.PackEnd(hbox, false, true, 5)
label := gtk.NewLabel("Tweet")
hbox.PackStart(label, false, false, 5)
text := gtk.NewEntry()
hbox.PackEnd(text, true, true, 5)
text.Connect("activate", func() {
t := text.GetText()
text.SetText("")
post(client, cred, t)
})
window.Add(vbox)
window.SetSizeRequest(800, 500)
window.ShowAll()
var mutex sync.Mutex
go func() {
show(client, cred, func(t *tweet) {
mutex.Lock()
display(t, buffer, tag)
mutex.Unlock()
})
stream(client, cred, func(t *tweet) {
mutex.Lock()
display(t, buffer, tag)
var start, end gtk.TextIter
buffer.GetIterAtLine(&start, buffer.GetLineCount()-2)
buffer.GetEndIter(&end)
buffer.Delete(&start, &end)
mutex.Unlock()
})
}()
for alive {
mutex.Lock()
alive = gtk.MainIterationDo(false)
mutex.Unlock()
}
}
开发者ID:mattn,项目名称:go-gtk,代码行数:77,代码来源:twitterstream.go
示例13: InitializeGUI
//InitializeGUI es la funcion que inicializa y ejecuta todo el entorno gráfico de la aplicacion
func (p *Gui) InitializeGUI(errorstr string, file *os.File) {
gtk.Init(nil)
window := gtk.NewWindow(gtk.WINDOW_TOPLEVEL)
window.SetPosition(gtk.WIN_POS_CENTER)
window.Maximize()
window.SetTitle("Go-SIC ASM/SIM!")
window.SetIconName("gtk-dialog-info")
window.Connect("destroy", func(ctx *glib.CallbackContext) {
fmt.Println("got destroy!", ctx.Data().(string))
gtk.MainQuit()
}, "foo")
//--------------------------------------------------------
// GTK statusbar
//--------------------------------------------------------
statusbar := gtk.NewStatusbar()
context_id := statusbar.GetContextId("hola")
//--------------------------------------------------------
// GtkVBox
//--------------------------------------------------------
vbox := gtk.NewVBox(false, 1)
//--------------------------------------------------------
// GtkMenuBar
//--------------------------------------------------------
menubar := gtk.NewMenuBar()
vbox.PackStart(menubar, false, false, 0)
//--------------------------------------------------------
// GtkVPaned
//--------------------------------------------------------
vpaned := gtk.NewVPaned()
vbox.Add(vpaned)
//--------------------------------------------------------
// GtkFrame
//--------------------------------------------------------
frame1 := gtk.NewFrame("Código Fuente/Archivo intermedio/TABSIM")
framebox1 := gtk.NewVBox(false, 1)
frame1.Add(framebox1)
frame1.SetSizeRequest(300, 300)
frame2 := gtk.NewFrame("Debug/Código Objeto")
framebox2 := gtk.NewVBox(false, 1)
frame2.Add(framebox2)
vpaned.Pack1(frame1, false, false)
vpaned.Pack2(frame2, false, false)
//--------------------------------------------------------
// GtkHBox
//--------------------------------------------------------
ventanasPrincipales := gtk.NewHBox(false, 1)
//----------------------------------------------
label := gtk.NewLabel("Ensamblador SIC SIC/XE")
label.ModifyFontEasy("DejaVu Serif 15")
framebox1.PackStart(label, false, true, 0)
//--------------------------------------------------------
// GtkTextView
//--------------------------------------------------------
swin := gtk.NewScrolledWindow(nil, nil)
swin.SetPolicy(gtk.POLICY_AUTOMATIC, gtk.POLICY_AUTOMATIC)
swin.SetShadowType(gtk.SHADOW_IN)
textview := gtk.NewTextView()
textview.ModifyFontEasy("Sans 10")
var start, end gtk.TextIter
buffer := textview.GetBuffer()
buffer.GetStartIter(&start)
swin.Add(textview)
ventanasPrincipales.Add(swin)
//framebox1.Add(swin)
//--------------------------------------------------------
// GtkTextView
//--------------------------------------------------------
swin4 := gtk.NewScrolledWindow(nil, nil)
swin4.SetPolicy(gtk.POLICY_AUTOMATIC, gtk.POLICY_AUTOMATIC)
swin4.SetShadowType(gtk.SHADOW_IN)
textview4 := gtk.NewTextView()
textview4.ModifyFontEasy("Sans 10")
var start4, end4 gtk.TextIter
buffer4 := textview4.GetBuffer()
buffer4.GetStartIter(&start4)
swin4.Add(textview4)
ventanasPrincipales.Add(swin4)
//framebox1.Add(swin)
//--------------------------------------------------------
// GtkTextView
//--------------------------------------------------------
swin5 := gtk.NewScrolledWindow(nil, nil)
swin5.SetPolicy(gtk.POLICY_AUTOMATIC, gtk.POLICY_AUTOMATIC)
swin5.SetShadowType(gtk.SHADOW_IN)
textview5 := gtk.NewTextView()
//.........这里部分代码省略.........
开发者ID:jatovar,项目名称:sic-xe,代码行数:101,代码来源:guinterface.go
示例14: main
func main() {
gtk.Init(&os.Args)
window := gtk.NewWindow(gtk.WINDOW_TOPLEVEL)
window.SetTitle("GoTalk")
window.Connect("destroy", func() {
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()
entry := gtk.NewEntry()
vbox.PackEnd(entry, false, false, 0)
window.Add(vbox)
window.SetSizeRequest(300, 400)
window.ShowAll()
dialog := gtk.NewDialog()
dialog.SetTitle(window.GetTitle())
sgroup := gtk.NewSizeGroup(gtk.SIZE_GROUP_HORIZONTAL)
hbox := gtk.NewHBox(false, 1)
dialog.GetVBox().Add(hbox)
label := gtk.NewLabel("username:")
sgroup.AddWidget(label)
hbox.Add(label)
username := gtk.NewEntry()
hbox.Add(username)
hbox = gtk.NewHBox(false, 1)
dialog.GetVBox().Add(hbox)
label = gtk.NewLabel("password:")
sgroup.AddWidget(label)
hbox.Add(label)
password := gtk.NewEntry()
password.SetVisibility(false)
hbox.Add(password)
dialog.AddButton(gtk.STOCK_OK, gtk.RESPONSE_OK)
dialog.AddButton(gtk.STOCK_CANCEL, gtk.RESPONSE_CANCEL)
dialog.SetDefaultResponse(int(gtk.RESPONSE_OK))
dialog.SetTransientFor(window)
dialog.ShowAll()
res := dialog.Run()
username_ := username.GetText()
password_ := password.GetText()
dialog.Destroy()
if res != gtk.RESPONSE_OK {
os.Exit(0)
}
talk, err := xmpp.NewClient("talk.google.com:443", username_, password_)
if err != nil {
log.Fatal(err)
}
entry.Connect("activate", func() {
text := entry.GetText()
tokens := strings.SplitN(text, " ", 2)
if len(tokens) == 2 {
func() {
defer recover()
talk.Send(xmpp.Chat{Remote: tokens[0], Type: "chat", Text: tokens[1]})
entry.SetText("")
}()
}
})
go func() {
for {
func() {
defer recover()
chat, err := talk.Recv()
if err != nil {
log.Fatal(err)
}
var iter gtk.TextIter
buffer.GetStartIter(&iter)
if msg, ok := chat.(xmpp.Chat); ok {
buffer.Insert(&iter, msg.Remote+": "+msg.Text+"\n")
}
}()
}
}()
gtk.Main()
}
开发者ID:AudioAddict,项目名称:go-xmpp,代码行数:96,代码来源:example-gui.go
注:本文中的github.com/mattn/go-gtk/gtk.NewTextView函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论