本文整理匯總了Golang中github.com/mattn/go-gtk/gtk.ScrolledWindow函數的典型用法代碼示例。如果您正苦於以下問題:Golang ScrolledWindow函數的具體用法?Golang ScrolledWindow怎麽用?Golang ScrolledWindow使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。
在下文中一共展示了ScrolledWindow函數的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: 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()
}
示例2: build
func (window *GhQueuedHighlightsWindow) build() {
window.SetTitle("Queued Highlights")
window.bindKeys()
scrolledWindow := gtk.ScrolledWindow(nil, nil)
scrolledWindow.SetPolicy(gtk.GTK_POLICY_AUTOMATIC, gtk.GTK_POLICY_AUTOMATIC)
treeView := gtk.TreeView()
scrolledWindow.Add(treeView)
store := gtk.ListStore(glib.G_TYPE_STRING, glib.G_TYPE_STRING, glib.G_TYPE_DOUBLE, glib.G_TYPE_STRING, glib.G_TYPE_STRING)
treeView.SetModel(store)
treeView.AppendColumn(gtk.TreeViewColumnWithAttributes("Book", gtk.CellRendererText(), "text", 0))
treeView.AppendColumn(gtk.TreeViewColumnWithAttributes("Content", gtk.CellRendererText(), "text", 1))
treeView.AppendColumn(gtk.TreeViewColumnWithAttributes("Position", gtk.CellRendererText(), "text", 2))
treeView.AppendColumn(gtk.TreeViewColumnWithAttributes("Timestamp", gtk.CellRendererText(), "text", 3))
treeView.AppendColumn(gtk.TreeViewColumnWithAttributes("Comment", gtk.CellRendererText(), "text", 4))
readings := models.Readings()
highlights := models.Highlights()
for _, highlight := range highlights.Items {
var iter gtk.GtkTreeIter
store.Append(&iter)
reading := readings.FindByReadmillId(highlight.ReadingReadmillId)
position := highlight.Position * 100
timestamp := highlight.Timestamp.Format(time.Stamp)
store.Set(&iter, reading.Title, highlight.Content, position, timestamp, highlight.Comment)
}
window.Add(scrolledWindow)
window.SetSizeRequest(600, 400)
}
示例3: 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()
}
示例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("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()
}
示例6: 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()
}
示例7: Init
func (v *SearchView) Init() {
v.store = gtk.TreeStore(gtk.GTK_TYPE_STRING)
v.view = file_tree.NewSearchTree()
v.view.ModifyFontEasy("Regular 8")
v.model = v.store.ToTreeModel()
v.view.SetModel(v.model)
v.view.AppendColumn(gtk.TreeViewColumnWithAttributes("",
gtk.CellRendererText(), "text", 0))
v.view.SetHeadersVisible(false)
v.view.Connect("cursor-changed", func() { v.Select() }, nil)
v.window = gtk.ScrolledWindow(nil, nil)
v.window.SetPolicy(gtk.GTK_POLICY_AUTOMATIC, gtk.GTK_POLICY_AUTOMATIC)
v.window.Add(v.view)
v.window.SetVisible(opt.show_search)
}
示例8: build
func (window *GhAuthWindow) build() {
window.bindKeys()
window.SetModal(true)
window.SetTitle("Readmill Authentication")
window.Connect("destroy", func() {
config := models.Config()
if config.AccessToken == "" {
gtk.MainQuit()
}
})
scrolledWindow := gtk.ScrolledWindow(nil, nil)
scrolledWindow.SetPolicy(gtk.GTK_POLICY_AUTOMATIC, gtk.GTK_POLICY_AUTOMATIC)
scrolledWindow.SetShadowType(gtk.GTK_SHADOW_IN)
webview := webkit.WebView()
webview.Connect("load-committed", func() {
uri := webview.GetUri()
matched, _ := regexp.MatchString(`^`+constants.READMILL_REDIRECT_URI+`/\?code=`, uri)
if matched {
webview.StopLoading()
codeRegex, _ := regexp.Compile(`\?code=([^&]*)`)
result := codeRegex.FindStringSubmatch(uri)
code := result[1]
token := readmilloauth.GetToken(constants.READMILL_CLIENT_ID, constants.READMILL_CLIENT_SECRET, constants.READMILL_REDIRECT_URI, code)
userId := readmilloauth.GetUserId(token)
config := models.Config()
config.AccessToken = token
config.UserId = userId
config.Write()
window.Destroy()
}
})
scrolledWindow.Add(webview)
authorizeUri := readmilloauth.AuthorizeUri(constants.READMILL_CLIENT_ID, constants.READMILL_REDIRECT_URI)
webview.LoadUri(authorizeUri)
window.Add(scrolledWindow)
window.SetSizeRequest(500, 650)
}
示例9: inotify_dialog
// Returns true in case of reloading files, and false in case of keeping as is.
func inotify_dialog(s map[string]int) bool {
if nil == accel_group {
accel_group = gtk.AccelGroup()
}
inotify_dlg := gtk.Dialog()
defer inotify_dlg.Destroy()
inotify_dlg.SetTitle("Some files have beed modified outside of tabby")
inotify_dlg.AddButton("_Reload all", int(gtk.GTK_RESPONSE_ACCEPT))
inotify_dlg.AddButton("_Keep all as is", int(gtk.GTK_RESPONSE_CANCEL))
w := inotify_dlg.GetWidgetForResponse(int(gtk.GTK_RESPONSE_ACCEPT))
inotify_dlg.AddAccelGroup(accel_group)
w.AddAccelerator("clicked", accel_group, gdk.GDK_KEY_Return,
0, gtk.GTK_ACCEL_VISIBLE)
inotify_dlg.SetSizeRequest(800, 350)
inotify_store := gtk.TreeStore(gtk.GTK_TYPE_STRING)
inotify_view := gtk.TreeView()
inotify_view.AppendColumn(
gtk.TreeViewColumnWithAttributes("text", gtk.CellRendererText(), "text", 0))
inotify_view.ModifyFontEasy("Regular 8")
inotify_model := inotify_store.ToTreeModel()
inotify_view.SetModel(inotify_model)
inotify_view.SetHeadersVisible(false)
var iter gtk.GtkTreeIter
for name, _ := range s {
inotify_store.Append(&iter, nil)
inotify_store.Set(&iter, name)
}
inotify_view.SetVisible(true)
view_window := gtk.ScrolledWindow(nil, nil)
view_window.SetPolicy(gtk.GTK_POLICY_AUTOMATIC, gtk.GTK_POLICY_AUTOMATIC)
view_window.SetVisible(true)
view_window.Add(inotify_view)
vbox := inotify_dlg.GetVBox()
vbox.Add(view_window)
if int(gtk.GTK_RESPONSE_ACCEPT) == inotify_dlg.Run() {
return true
}
return false
}
示例10: main
func main() {
gtk.Init(&os.Args)
window := gtk.Window(gtk.GTK_WINDOW_TOPLEVEL)
window.SetTitle("GTK Table")
window.Connect("destroy", gtk.MainQuit)
swin := gtk.ScrolledWindow(nil, nil)
swin.SetPolicy(gtk.GTK_POLICY_AUTOMATIC, gtk.GTK_POLICY_AUTOMATIC)
table := gtk.Table(5, 5, false)
for y := uint(0); y < 5; y++ {
for x := uint(0); x < 5; x++ {
table.Attach(gtk.ButtonWithLabel(fmt.Sprintf("%02d:%02d", x, y)), x, x+1, y, y+1, gtk.GTK_FILL, gtk.GTK_FILL, 5, 5)
}
}
swin.AddWithViewPort(table)
window.Add(swin)
window.SetDefaultSize(200, 200)
window.ShowAll()
gtk.Main()
}
示例11: main
//.........這裏部分代碼省略.........
framebox2.PackStart(vsep, false, false, 0)
//--------------------------------------------------------
// GtkComboBoxEntry
//--------------------------------------------------------
combos := gtk.HBox(false, 1)
comboboxentry := gtk.ComboBoxEntryNewText()
comboboxentry.AppendText("Monkey")
comboboxentry.AppendText("Tiger")
comboboxentry.AppendText("Elephant")
comboboxentry.Connect("changed", func() {
println("value:", comboboxentry.GetActiveText())
})
combos.Add(comboboxentry)
//--------------------------------------------------------
// GtkComboBox
//--------------------------------------------------------
combobox := gtk.ComboBoxNewText()
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.ScrolledWindow(nil, nil)
swin.SetPolicy(gtk.GTK_POLICY_AUTOMATIC, gtk.GTK_POLICY_AUTOMATIC)
swin.SetShadowType(gtk.GTK_SHADOW_IN)
textview := gtk.TextView()
var start, end gtk.GtkTextIter
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.MenuItemWithMnemonic("_File")
menubar.Append(cascademenu)
submenu := gtk.Menu()
cascademenu.SetSubmenu(submenu)
menuitem = gtk.MenuItemWithMnemonic("E_xit")
menuitem.Connect("activate", func() {
gtk.MainQuit()
示例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: init_tabby
//.........這裏部分代碼省略.........
menubar.Append(options_item)
options_submenu := gtk.Menu()
options_item.SetSubmenu(options_submenu)
search_chkitem := gtk.CheckMenuItemWithMnemonic("Show _Searchview")
options_submenu.Append(search_chkitem)
search_chkitem.SetActive(opt.show_search)
search_chkitem.Connect("toggled", func() { search_chk_cb(search_chkitem.GetActive()) }, nil)
error_chkitem := gtk.CheckMenuItemWithMnemonic("Show _Errorview")
options_submenu.Append(error_chkitem)
error_chkitem.SetActive(opt.show_error)
error_chkitem.Connect("toggled", func() { error_chk_cb(error_chkitem.GetActive()) }, nil)
notab_chkitem := gtk.CheckMenuItemWithMnemonic("Spaces for _Tabs")
options_submenu.Append(notab_chkitem)
notab_chkitem.SetActive(opt.space_not_tab)
notab_chkitem.Connect("toggled", func() { notab_chk_cb(notab_chkitem.GetActive()) }, nil)
font_item := gtk.MenuItemWithMnemonic("_Font")
options_submenu.Append(font_item)
font_item.Connect("activate", font_cb, nil)
tabsize_item := gtk.MenuItemWithMnemonic("_Tab size")
options_submenu.Append(tabsize_item)
tabsize_submenu := gtk.Menu()
tabsize_item.SetSubmenu(tabsize_submenu)
const tabsize_cnt = 8
tabsize_chk := make([]*gtk.GtkCheckMenuItem, tabsize_cnt)
for y := 0; y < tabsize_cnt; y++ {
tabsize_chk[y] = gtk.CheckMenuItemWithMnemonic(strconv.Itoa(y + 1))
tabsize_submenu.Append(tabsize_chk[y])
cur_ind := y
tabsize_chk[y].Connect("activate", func() {
if false == tabsize_chk[cur_ind].GetActive() {
active_cnt := 0
for j := 0; j < tabsize_cnt; j++ {
if tabsize_chk[j].GetActive() {
active_cnt++
}
}
if 0 == active_cnt {
tabsize_chk[cur_ind].SetActive(true)
}
return
}
for j := 0; j < tabsize_cnt; j++ {
if j != cur_ind {
tabsize_chk[j].SetActive(false)
}
}
options_set_tabsize(cur_ind + 1)
},
nil)
}
tree_window := gtk.ScrolledWindow(nil, nil)
tree_window.SetPolicy(gtk.GTK_POLICY_AUTOMATIC, gtk.GTK_POLICY_AUTOMATIC)
inner_hpaned.Add1(tree_window)
tree_window.Add(tree_view)
outer_hpaned.Add2(search_view.window)
text_window := gtk.ScrolledWindow(nil, nil)
text_window.SetPolicy(gtk.GTK_POLICY_AUTOMATIC, gtk.GTK_POLICY_ALWAYS)
view_vpaned.Add1(text_window)
text_window.Add(source_view)
error_window = gtk.ScrolledWindow(nil, nil)
error_window.SetPolicy(gtk.GTK_POLICY_AUTOMATIC, gtk.GTK_POLICY_ALWAYS)
view_vpaned.Add2(error_window)
error_window.Add(error_view)
inner_hpaned.Connect("size_request", func() { ohp_cb(outer_hpaned.GetPosition()) }, nil)
view_vpaned.Connect("size_request", func() { ihp_cb(inner_hpaned.GetPosition()) }, nil)
source_view.Connect("size_request", func() { vvp_cb(view_vpaned.GetPosition()) }, nil)
outer_hpaned.SetPosition(opt.ohp_position)
inner_hpaned.SetPosition(opt.ihp_position)
view_vpaned.SetPosition(opt.vvp_position)
main_window = gtk.Window(gtk.GTK_WINDOW_TOPLEVEL)
main_window.AddAccelGroup(accel_group)
main_window.SetSizeRequest(400, 200) //minimum size
main_window.Resize(opt.window_width, opt.window_height)
main_window.Move(opt.window_x, opt.window_y)
main_window.Connect("destroy", exit_cb, "")
main_window.Connect("configure-event", window_event_cb, "")
main_window.Add(vbox)
// init_tabby blocks for some reason when is called after ShowAll.
init_vars()
main_window.ShowAll()
error_window.SetVisible(opt.show_error)
// Cannot be called before ShowAll. This is also not clear.
file_switch_to(file_stack_pop())
stack_prev(&file_stack_max)
if "" == cur_file {
new_cb()
}
source_view.GrabFocus()
}
示例15: Gui
func Gui() {
//--------------------------------------------------------
// Setting up the GTK-Foo
//--------------------------------------------------------
gdk.ThreadsInit()
gtk.Init(&os.Args)
window := gtk.Window(gtk.GTK_WINDOW_TOPLEVEL)
window.SetTitle("Zwitscher!")
window.Connect("destroy", func() {
gtk.MainQuit()
})
vbox := gtk.VBox(false, 1)
notebook := gtk.Notebook()
//--------------------------------------------------------
// Home View
//--------------------------------------------------------
vboxHome := gtk.VBox(false, 1)
scrolledWinHome := gtk.ScrolledWindow(nil, nil)
//Disable hscrollbar, enable vscrollbar
scrolledWinHome.SetPolicy(gtk.GTK_POLICY_NEVER, gtk.GTK_POLICY_ALWAYS)
vboxHome.Add(scrolledWinHome)
vboxScrolledWinHome := gtk.VBox(false, 1)
scrolledWinHome.AddWithViewPort(vboxScrolledWinHome)
tweetwidgets := []*gtk.GtkFrame{}
buttonUpdateTimeline := gtk.ButtonWithLabel("Update Timeline")
buttonUpdateTimeline.Clicked(func() {
var tweet gotter.Tweet
tweets, err := gotter.GetTweets(accounts.Credentials, "https://api.twitter.com/1/statuses/home_timeline.json", map[string]string{})
if err != nil {
println("failed to get tweets:", err.String())
return
}
for i := len(tweets) - 1; i >= 0; i-- {
tweet = tweets[i]
id, _ := strconv.Atoi64(tweet.Identifier)
if accounts.Maxreadid < id {
if len(tweetwidgets) > 20 {
tweetwidgets[0].Destroy()
tweetwidgets = tweetwidgets[1:]
}
tweetwidget := TweetWidget(tweet)
vboxScrolledWinHome.PackEnd(tweetwidget, false, false, 0)
tweetwidget.ShowAll()
tweetwidgets = append(tweetwidgets, tweetwidget)
accounts.Maxreadid = id
}
}
})
vboxHome.PackEnd(buttonUpdateTimeline, false, false, 0)
notebook.AppendPage(vboxHome, gtk.Label("Home"))
//--------------------------------------------------------
// Mentions View
//--------------------------------------------------------
scrolledwin := gtk.ScrolledWindow(nil, nil)
notebook.AppendPage(scrolledwin, gtk.Label("Mentions"))
//--------------------------------------------------------
// Messages View
//--------------------------------------------------------
scrolledwin = gtk.ScrolledWindow(nil, nil)
notebook.AppendPage(scrolledwin, gtk.Label("Messages"))
vbox.Add(notebook)
//--------------------------------------------------------
// Fild for Tweets
//--------------------------------------------------------
hbox := gtk.HBox(false, 1)
dir, _ := filepath.Split(os.Args[0])
imagefile := filepath.Join(dir, "Awesome Smiley Original.jpg")
image := gtk.ImageFromFile(imagefile)
hbox.PackStart(image, false, false, 0)
buttonZwitscher := gtk.ButtonWithLabel("Zwitscher!")
newTweetTextField := gtk.Entry()
charCounterLabel := gtk.Label("140")
buttonZwitscher.SetTooltipMarkup("Tweet")
buttonZwitscher.Clicked(func() {
charCounterLabel.SetLabel("140")
SendTweet(newTweetTextField.GetText())
newTweetTextField.SetText("")
})
newTweetTextField.Connect("key-release-event", func() {
length := utf8.RuneCountInString(newTweetTextField.GetText())
charCounterLabel.SetLabel((string)(strconv.Itoa(140 - length)))
})
newTweetTextField.Connect("activate", func() {
if newTweetTextField.GetText() != "" { //pressed enter, and text is not empty
charCounterLabel.SetLabel("140")
SendTweet(newTweetTextField.GetText())
newTweetTextField.SetText("")
//.........這裏部分代碼省略.........