adds vendor directory
vendors dependencies in standard `vendor` directory, managed by glide
This commit is contained in:
222
vendor/github.com/mattn/go-gtk/example/action/action.go
generated
vendored
Normal file
222
vendor/github.com/mattn/go-gtk/example/action/action.go
generated
vendored
Normal file
@@ -0,0 +1,222 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"reflect"
|
||||
"unsafe"
|
||||
|
||||
"github.com/mattn/go-gtk/glib"
|
||||
"github.com/mattn/go-gtk/gtk"
|
||||
)
|
||||
|
||||
func CreateWindow() *gtk.Window {
|
||||
window := gtk.NewWindow(gtk.WINDOW_TOPLEVEL)
|
||||
window.SetDefaultSize(700, 300)
|
||||
vbox := gtk.NewVBox(false, 1)
|
||||
CreateMenuAndToolbar(window, vbox)
|
||||
CreateActivatableDemo(vbox)
|
||||
window.Add(vbox)
|
||||
return window
|
||||
}
|
||||
|
||||
func CreateMenuAndToolbar(w *gtk.Window, vbox *gtk.VBox) {
|
||||
action_group := gtk.NewActionGroup("my_group")
|
||||
ui_manager := CreateUIManager()
|
||||
accel_group := ui_manager.GetAccelGroup()
|
||||
w.AddAccelGroup(accel_group)
|
||||
AddFileMenuActions(action_group)
|
||||
AddEditMenuActions(action_group)
|
||||
AddChoicesMenuActions(action_group)
|
||||
ui_manager.InsertActionGroup(action_group, 0)
|
||||
menubar := ui_manager.GetWidget("/MenuBar")
|
||||
vbox.PackStart(menubar, false, false, 0)
|
||||
toolbar := ui_manager.GetWidget("/ToolBar")
|
||||
vbox.PackStart(toolbar, false, false, 0)
|
||||
eventbox := gtk.NewEventBox()
|
||||
vbox.PackStart(eventbox, false, false, 0)
|
||||
// label := gtk.NewLabel("Right-click to see the popup menu.")
|
||||
// vbox.PackStart(label, false, false, 0)
|
||||
}
|
||||
|
||||
func CreateActivatableDemo(vbox *gtk.VBox) {
|
||||
action_entry := gtk.NewAction("ActionEntry",
|
||||
"Button attached to Action", "", gtk.STOCK_INFO)
|
||||
action_entry.Connect("activate", func() {
|
||||
fmt.Println("Action clicked")
|
||||
})
|
||||
frame1 := gtk.NewFrame("GtkActivatable interface demonstration")
|
||||
frame1.SetBorderWidth(5)
|
||||
hbox2 := gtk.NewHBox(false, 5)
|
||||
hbox2.SetSizeRequest(400, 50)
|
||||
hbox2.SetBorderWidth(5)
|
||||
button1 := gtk.NewButton()
|
||||
button1.SetSizeRequest(250, 0)
|
||||
button1.SetRelatedAction(action_entry)
|
||||
hbox2.PackStart(button1, false, false, 0)
|
||||
hbox2.PackStart(gtk.NewVSeparator(), false, false, 0)
|
||||
button2 := gtk.NewButtonWithLabel("Hide Action")
|
||||
button2.SetSizeRequest(150, 0)
|
||||
button2.Connect("clicked", func() {
|
||||
action_entry.SetVisible(false)
|
||||
fmt.Println("Hide Action")
|
||||
})
|
||||
hbox2.PackStart(button2, false, false, 0)
|
||||
button3 := gtk.NewButtonWithLabel("Unhide Action")
|
||||
button3.SetSizeRequest(150, 0)
|
||||
button3.Connect("clicked", func() {
|
||||
action_entry.SetVisible(true)
|
||||
fmt.Println("Show Action")
|
||||
})
|
||||
hbox2.PackStart(button3, false, false, 0)
|
||||
frame1.Add(hbox2)
|
||||
vbox.PackStart(frame1, false, true, 0)
|
||||
}
|
||||
|
||||
func CreateUIManager() *gtk.UIManager {
|
||||
UI_INFO := `
|
||||
<ui>
|
||||
<menubar name='MenuBar'>
|
||||
<menu action='FileMenu'>
|
||||
<menu action='FileNew'>
|
||||
<menuitem action='FileNewStandard' />
|
||||
<menuitem action='FileNewFoo' />
|
||||
<menuitem action='FileNewGoo' />
|
||||
</menu>
|
||||
<separator />
|
||||
<menuitem action='FileQuit' />
|
||||
</menu>
|
||||
<menu action='EditMenu'>
|
||||
<menuitem action='EditCopy' />
|
||||
<menuitem action='EditPaste' />
|
||||
<menuitem action='EditSomething' />
|
||||
</menu>
|
||||
<menu action='ChoicesMenu'>
|
||||
<menuitem action='ChoiceOne'/>
|
||||
<menuitem action='ChoiceTwo'/>
|
||||
<menuitem action='ChoiceThree'/>
|
||||
<separator />
|
||||
<menuitem action='ChoiceToggle'/>
|
||||
</menu>
|
||||
</menubar>
|
||||
<toolbar name='ToolBar'>
|
||||
<toolitem action='FileNewStandard' />
|
||||
<toolitem action='FileQuit' />
|
||||
</toolbar>
|
||||
<popup name='PopupMenu'>
|
||||
<menuitem action='EditCopy' />
|
||||
<menuitem action='EditPaste' />
|
||||
<menuitem action='EditSomething' />
|
||||
</popup>
|
||||
</ui>
|
||||
`
|
||||
ui_manager := gtk.NewUIManager()
|
||||
ui_manager.AddUIFromString(UI_INFO)
|
||||
return ui_manager
|
||||
}
|
||||
|
||||
func OnMenuFileNewGeneric() {
|
||||
fmt.Println("A File|New menu item was selected.")
|
||||
}
|
||||
|
||||
func OnMenuFileQuit() {
|
||||
fmt.Println("quit app...")
|
||||
gtk.MainQuit()
|
||||
}
|
||||
|
||||
func OnMenuOther(ctx *glib.CallbackContext) {
|
||||
v := reflect.ValueOf(ctx.Target())
|
||||
if v.Kind() == reflect.Ptr {
|
||||
fmt.Printf("Item %s(%p) was selected", v.Elem(), v.Interface())
|
||||
fmt.Println()
|
||||
if w, ok := v.Elem().Interface().(gtk.IWidget); ok {
|
||||
v := reflect.ValueOf(ctx.Target())
|
||||
v2 := v.Elem()
|
||||
fmt.Println(v.Kind(), v2.Kind())
|
||||
fmt.Println("Menu item ", w.GetName(), " was selected")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func OnMenuOther2(widget unsafe.Pointer, event unsafe.Pointer,
|
||||
data unsafe.Pointer) {
|
||||
fmt.Println("Menu item ", "", " was selected")
|
||||
}
|
||||
|
||||
func AddFileMenuActions(action_group *gtk.ActionGroup) {
|
||||
action_group.AddAction(gtk.NewAction("FileMenu", "File", "", ""))
|
||||
|
||||
action_filenewmenu := gtk.NewAction("FileNew", "", "", gtk.STOCK_NEW)
|
||||
action_group.AddAction(action_filenewmenu)
|
||||
|
||||
action_new := gtk.NewAction("FileNewStandard", "_New",
|
||||
"Create a new file", gtk.STOCK_NEW)
|
||||
action_new.Connect("activate", OnMenuFileNewGeneric)
|
||||
action_group.AddActionWithAccel(action_new, "")
|
||||
|
||||
action_new_foo := gtk.NewAction("FileNewFoo", "New Foo",
|
||||
"Create new foo", gtk.STOCK_NEW)
|
||||
action_new_foo.Connect("activate", OnMenuFileNewGeneric)
|
||||
action_group.AddAction(action_new_foo)
|
||||
|
||||
action_new_goo := gtk.NewAction("FileNewGoo", "_New Goo",
|
||||
"Create new goo", gtk.STOCK_NEW)
|
||||
action_new_goo.Connect("activate", OnMenuFileNewGeneric)
|
||||
action_group.AddAction(action_new_goo)
|
||||
|
||||
action_filequit := gtk.NewAction("FileQuit", "", "", gtk.STOCK_QUIT)
|
||||
action_filequit.Connect("activate", OnMenuFileQuit)
|
||||
action_group.AddActionWithAccel(action_filequit, "")
|
||||
}
|
||||
|
||||
func AddEditMenuActions(action_group *gtk.ActionGroup) {
|
||||
action_group.AddAction(gtk.NewAction("EditMenu", "Edit", "", ""))
|
||||
|
||||
action_editcopy := gtk.NewAction("EditCopy", "", "", gtk.STOCK_COPY)
|
||||
action_editcopy.Connect("activate", OnMenuOther)
|
||||
action_group.AddActionWithAccel(action_editcopy, "")
|
||||
|
||||
action_editpaste := gtk.NewAction("EditPaste", "", "", gtk.STOCK_PASTE)
|
||||
action_editpaste.Connect("activate", OnMenuOther)
|
||||
action_group.AddActionWithAccel(action_editpaste, "")
|
||||
|
||||
action_editsomething := gtk.NewAction("EditSomething", "Something", "", "")
|
||||
action_editsomething.Connect("activate", OnMenuOther)
|
||||
action_group.AddActionWithAccel(action_editsomething, "<control><alt>S")
|
||||
}
|
||||
|
||||
func AddChoicesMenuActions(action_group *gtk.ActionGroup) {
|
||||
action_group.AddAction(gtk.NewAction("ChoicesMenu", "Choices", "", ""))
|
||||
|
||||
var ra_list []*gtk.RadioAction
|
||||
ra_one := gtk.NewRadioAction("ChoiceOne", "One", "", "", 1)
|
||||
ra_list = append(ra_list, ra_one)
|
||||
|
||||
ra_two := gtk.NewRadioAction("ChoiceTwo", "Two", "", "", 2)
|
||||
ra_list = append(ra_list, ra_two)
|
||||
|
||||
ra_three := gtk.NewRadioAction("ChoiceThree", "Three", "", "", 2)
|
||||
ra_list = append(ra_list, ra_three)
|
||||
|
||||
var sl *glib.SList
|
||||
for _, ra := range ra_list {
|
||||
ra.SetGroup(sl)
|
||||
sl = ra.GetGroup()
|
||||
action_group.AddAction(ra)
|
||||
}
|
||||
|
||||
ra_last := gtk.NewToggleAction("ChoiceToggle", "Toggle", "", "")
|
||||
ra_last.SetActive(true)
|
||||
action_group.AddAction(ra_last)
|
||||
}
|
||||
|
||||
func main() {
|
||||
gtk.Init(nil)
|
||||
window := CreateWindow()
|
||||
window.SetPosition(gtk.WIN_POS_CENTER)
|
||||
window.Connect("destroy", func(ctx *glib.CallbackContext) {
|
||||
fmt.Println("destroy pending...")
|
||||
gtk.MainQuit()
|
||||
}, "foo")
|
||||
window.ShowAll()
|
||||
gtk.Main()
|
||||
}
|
43
vendor/github.com/mattn/go-gtk/example/alignment/alignment.go
generated
vendored
Normal file
43
vendor/github.com/mattn/go-gtk/example/alignment/alignment.go
generated
vendored
Normal file
@@ -0,0 +1,43 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"github.com/mattn/go-gtk/gtk"
|
||||
"os"
|
||||
)
|
||||
|
||||
func main() {
|
||||
gtk.Init(&os.Args)
|
||||
window := gtk.NewWindow(gtk.WINDOW_TOPLEVEL)
|
||||
window.SetTitle("Alignment")
|
||||
window.Connect("destroy", gtk.MainQuit)
|
||||
|
||||
notebook := gtk.NewNotebook()
|
||||
window.Add(notebook)
|
||||
|
||||
align := gtk.NewAlignment(0.5, 0.5, 0.5, 0.5)
|
||||
notebook.AppendPage(align, gtk.NewLabel("Alignment"))
|
||||
|
||||
button := gtk.NewButtonWithLabel("Hello World!")
|
||||
align.Add(button)
|
||||
|
||||
fixed := gtk.NewFixed()
|
||||
notebook.AppendPage(fixed, gtk.NewLabel("Fixed"))
|
||||
|
||||
button2 := gtk.NewButtonWithLabel("Pulse")
|
||||
fixed.Put(button2, 30, 30)
|
||||
|
||||
progress := gtk.NewProgressBar()
|
||||
fixed.Put(progress, 30, 70)
|
||||
|
||||
button.Connect("clicked", func() {
|
||||
progress.SetFraction(0.1 + 0.9*progress.GetFraction()) //easter egg
|
||||
})
|
||||
button2.Connect("clicked", func() {
|
||||
progress.Pulse()
|
||||
})
|
||||
|
||||
window.ShowAll()
|
||||
window.SetSizeRequest(200, 200)
|
||||
|
||||
gtk.Main()
|
||||
}
|
48
vendor/github.com/mattn/go-gtk/example/arrow/arrow.go
generated
vendored
Normal file
48
vendor/github.com/mattn/go-gtk/example/arrow/arrow.go
generated
vendored
Normal file
@@ -0,0 +1,48 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"github.com/mattn/go-gtk/gtk"
|
||||
"os"
|
||||
)
|
||||
|
||||
func createArrowButton(at gtk.ArrowType, st gtk.ShadowType) *gtk.Button {
|
||||
b := gtk.NewButton()
|
||||
a := gtk.NewArrow(at, st)
|
||||
|
||||
b.Add(a)
|
||||
|
||||
b.Show()
|
||||
a.Show()
|
||||
|
||||
return b
|
||||
}
|
||||
|
||||
func main() {
|
||||
gtk.Init(&os.Args)
|
||||
|
||||
window := gtk.NewWindow(gtk.WINDOW_TOPLEVEL)
|
||||
window.SetTitle("Arrow Buttons")
|
||||
window.Connect("destroy", gtk.MainQuit)
|
||||
|
||||
box := gtk.NewHBox(false, 0)
|
||||
box.Show()
|
||||
window.Add(box)
|
||||
|
||||
up := createArrowButton(gtk.ARROW_UP, gtk.SHADOW_IN)
|
||||
down := createArrowButton(gtk.ARROW_DOWN, gtk.SHADOW_OUT)
|
||||
left := createArrowButton(gtk.ARROW_LEFT, gtk.SHADOW_ETCHED_IN)
|
||||
right := createArrowButton(gtk.ARROW_RIGHT, gtk.SHADOW_ETCHED_OUT)
|
||||
|
||||
box.PackStart(up, false, false, 3)
|
||||
box.PackStart(down, false, false, 3)
|
||||
box.PackStart(left, false, false, 3)
|
||||
box.PackStart(right, false, false, 3)
|
||||
|
||||
up.Clicked(func() { println("↑") })
|
||||
down.Clicked(func() { println("↓") })
|
||||
left.Clicked(func() { println("←") })
|
||||
right.Clicked(func() { println("→") })
|
||||
|
||||
window.Show()
|
||||
gtk.Main()
|
||||
}
|
26
vendor/github.com/mattn/go-gtk/example/builder/builder.go
generated
vendored
Normal file
26
vendor/github.com/mattn/go-gtk/example/builder/builder.go
generated
vendored
Normal file
@@ -0,0 +1,26 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"os"
|
||||
|
||||
"github.com/mattn/go-gtk/example/builder/callback"
|
||||
"github.com/mattn/go-gtk/gtk"
|
||||
)
|
||||
|
||||
//"github.com/mattn/go-gtk/example/builder/callback"
|
||||
func main() {
|
||||
gtk.Init(&os.Args)
|
||||
|
||||
builder := gtk.NewBuilder()
|
||||
|
||||
builder.AddFromFile("hello.ui")
|
||||
obj := builder.GetObject("window1")
|
||||
|
||||
window := gtk.WidgetFromObject(obj)
|
||||
window.Show()
|
||||
window.Connect("destroy", gtk.MainQuit)
|
||||
|
||||
callback.Init(builder)
|
||||
|
||||
gtk.Main()
|
||||
}
|
37
vendor/github.com/mattn/go-gtk/example/builder/callback/callback.go
generated
vendored
Normal file
37
vendor/github.com/mattn/go-gtk/example/builder/callback/callback.go
generated
vendored
Normal file
@@ -0,0 +1,37 @@
|
||||
package callback
|
||||
|
||||
import (
|
||||
"unsafe"
|
||||
|
||||
"github.com/mattn/go-gtk/glib"
|
||||
"github.com/mattn/go-gtk/gtk"
|
||||
)
|
||||
|
||||
var aboutdialog *gtk.AboutDialog
|
||||
|
||||
func Init(builder *gtk.Builder) {
|
||||
aboutdialog = >k.AboutDialog{
|
||||
*(*gtk.Dialog)(unsafe.Pointer(&builder.GetObject("aboutdialog1").Object))}
|
||||
builder.ConnectSignalsFull(func(builder *gtk.Builder, obj *glib.GObject, sig, handler string, conn *glib.GObject, flags glib.ConnectFlags, user_data interface{}) {
|
||||
switch handler {
|
||||
case "on_imagemenuitem1_activate":
|
||||
obj.SignalConnect(sig, on_imagemenuitem1_activate, user_data, flags)
|
||||
case "on_show_aboutdialog_activate":
|
||||
obj.SignalConnect(sig, on_show_aboutdialog_activate, user_data, flags)
|
||||
case "gtk_widget_hide":
|
||||
obj.SignalConnect(sig, func(c *glib.CallbackContext) {
|
||||
gtk.WidgetFromObject(c.Target().(*glib.GObject)).Hide()
|
||||
}, nil, flags)
|
||||
}
|
||||
}, nil)
|
||||
}
|
||||
|
||||
//export on_imagemenuitem1_activate
|
||||
func on_imagemenuitem1_activate() {
|
||||
gtk.MainQuit()
|
||||
}
|
||||
|
||||
//export on_show_aboutdialog_activate
|
||||
func on_show_aboutdialog_activate() {
|
||||
aboutdialog.Run()
|
||||
}
|
139
vendor/github.com/mattn/go-gtk/example/builder/hello.ui
generated
vendored
Normal file
139
vendor/github.com/mattn/go-gtk/example/builder/hello.ui
generated
vendored
Normal file
@@ -0,0 +1,139 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<interface>
|
||||
<requires lib="gtk+" version="2.16"/>
|
||||
<!-- interface-naming-policy toplevel-contextual -->
|
||||
<object class="GtkAboutDialog" id="aboutdialog1">
|
||||
<property name="can_focus">False</property>
|
||||
<property name="border_width">5</property>
|
||||
<property name="type_hint">dialog</property>
|
||||
<property name="program_name">go-gtk builder</property>
|
||||
<property name="version">0.1</property>
|
||||
<property name="copyright">The library is available under the same terms and conditions as the Go,
|
||||
the BSD style license, and the LGPL (Lesser GNU Public License).
|
||||
The idea is that if you can use Go (and Gtk) in a project, you should also be able to use go-gtk.</property>
|
||||
<property name="comments" translatable="yes">example program for go-gtk</property>
|
||||
<property name="website">https://github.com/mattn/go-gtk</property>
|
||||
<property name="authors">Yasuhiro Matsumoto</property>
|
||||
<signal name="response" handler="gtk_widget_hide" swapped="no"/>
|
||||
<child internal-child="vbox">
|
||||
<object class="GtkVBox" id="dialog-vbox1">
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">False</property>
|
||||
<property name="spacing">2</property>
|
||||
<child internal-child="action_area">
|
||||
<object class="GtkHButtonBox" id="dialog-action_area1">
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">False</property>
|
||||
<property name="layout_style">end</property>
|
||||
</object>
|
||||
<packing>
|
||||
<property name="expand">False</property>
|
||||
<property name="fill">True</property>
|
||||
<property name="pack_type">end</property>
|
||||
<property name="position">0</property>
|
||||
</packing>
|
||||
</child>
|
||||
<child>
|
||||
<placeholder/>
|
||||
</child>
|
||||
</object>
|
||||
</child>
|
||||
</object>
|
||||
<object class="GtkImage" id="image1">
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">False</property>
|
||||
<property name="pixbuf">../../data/mattn-logo.png</property>
|
||||
</object>
|
||||
<object class="GtkWindow" id="window1">
|
||||
<property name="can_focus">False</property>
|
||||
<property name="title" translatable="yes">builder</property>
|
||||
<child>
|
||||
<object class="GtkVBox" id="vbox1">
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">False</property>
|
||||
<child>
|
||||
<object class="GtkMenuBar" id="menubar1">
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">False</property>
|
||||
<child>
|
||||
<object class="GtkMenuItem" id="file">
|
||||
<property name="use_action_appearance">False</property>
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">False</property>
|
||||
<property name="label" translatable="yes">_File</property>
|
||||
<property name="use_underline">True</property>
|
||||
<child type="submenu">
|
||||
<object class="GtkMenu" id="exit">
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">False</property>
|
||||
<child>
|
||||
<object class="GtkImageMenuItem" id="do_exit">
|
||||
<property name="label">gtk-quit</property>
|
||||
<property name="use_action_appearance">False</property>
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">False</property>
|
||||
<property name="use_underline">True</property>
|
||||
<property name="use_stock">True</property>
|
||||
<signal name="activate" handler="on_imagemenuitem1_activate" swapped="no"/>
|
||||
</object>
|
||||
</child>
|
||||
</object>
|
||||
</child>
|
||||
</object>
|
||||
</child>
|
||||
<child>
|
||||
<object class="GtkMenuItem" id="help">
|
||||
<property name="use_action_appearance">False</property>
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">False</property>
|
||||
<property name="right_justified">True</property>
|
||||
<property name="label" translatable="yes">_Help</property>
|
||||
<property name="use_underline">True</property>
|
||||
<child type="submenu">
|
||||
<object class="GtkMenu" id="about">
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">False</property>
|
||||
<child>
|
||||
<object class="GtkImageMenuItem" id="show_aboutdialog">
|
||||
<property name="label">gtk-about</property>
|
||||
<property name="use_action_appearance">False</property>
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">False</property>
|
||||
<property name="use_underline">True</property>
|
||||
<property name="use_stock">True</property>
|
||||
<signal name="activate" handler="on_show_aboutdialog_activate" after="yes" swapped="no"/>
|
||||
</object>
|
||||
</child>
|
||||
</object>
|
||||
</child>
|
||||
</object>
|
||||
</child>
|
||||
</object>
|
||||
<packing>
|
||||
<property name="expand">False</property>
|
||||
<property name="fill">True</property>
|
||||
<property name="position">0</property>
|
||||
</packing>
|
||||
</child>
|
||||
<child>
|
||||
<object class="GtkLinkButton" id="linkbutton1">
|
||||
<property name="use_action_appearance">False</property>
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">True</property>
|
||||
<property name="receives_default">True</property>
|
||||
<property name="has_tooltip">True</property>
|
||||
<property name="tooltip_markup"><b>http://mattn.kaoriya.net/</b></property>
|
||||
<property name="image">image1</property>
|
||||
<property name="relief">none</property>
|
||||
<property name="uri">http://mattn.kaoriya.net/</property>
|
||||
</object>
|
||||
<packing>
|
||||
<property name="expand">True</property>
|
||||
<property name="fill">True</property>
|
||||
<property name="position">1</property>
|
||||
</packing>
|
||||
</child>
|
||||
</object>
|
||||
</child>
|
||||
</object>
|
||||
</interface>
|
19
vendor/github.com/mattn/go-gtk/example/clipboard/clipboard.go
generated
vendored
Normal file
19
vendor/github.com/mattn/go-gtk/example/clipboard/clipboard.go
generated
vendored
Normal file
@@ -0,0 +1,19 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"github.com/mattn/go-gtk/gdk"
|
||||
"github.com/mattn/go-gtk/gtk"
|
||||
)
|
||||
|
||||
func main() {
|
||||
gtk.Init(nil)
|
||||
clipboard := gtk.NewClipboardGetForDisplay(
|
||||
gdk.DisplayGetDefault(),
|
||||
gdk.SELECTION_CLIPBOARD)
|
||||
fmt.Println(clipboard.WaitForText())
|
||||
clipboard.SetText("helloworld")
|
||||
gtk.MainIterationDo(true)
|
||||
clipboard.Store()
|
||||
gtk.MainIterationDo(true)
|
||||
}
|
355
vendor/github.com/mattn/go-gtk/example/demo/demo.go
generated
vendored
Normal file
355
vendor/github.com/mattn/go-gtk/example/demo/demo.go
generated
vendored
Normal file
@@ -0,0 +1,355 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"github.com/mattn/go-gtk/gdkpixbuf"
|
||||
"github.com/mattn/go-gtk/glib"
|
||||
"github.com/mattn/go-gtk/gtk"
|
||||
"os"
|
||||
"os/exec"
|
||||
"path/filepath"
|
||||
"regexp"
|
||||
"sort"
|
||||
"strings"
|
||||
)
|
||||
|
||||
func uniq(strings []string) (ret []string) {
|
||||
return
|
||||
}
|
||||
|
||||
func authors() []string {
|
||||
if b, err := exec.Command("git", "log").Output(); err == nil {
|
||||
lines := strings.Split(string(b), "\n")
|
||||
|
||||
var a []string
|
||||
r := regexp.MustCompile(`^Author:\s*([^ <]+).*$`)
|
||||
for _, e := range lines {
|
||||
ms := r.FindStringSubmatch(e)
|
||||
if ms == nil {
|
||||
continue
|
||||
}
|
||||
a = append(a, ms[1])
|
||||
}
|
||||
sort.Strings(a)
|
||||
var p string
|
||||
lines = []string{}
|
||||
for _, e := range a {
|
||||
if p == e {
|
||||
continue
|
||||
}
|
||||
lines = append(lines, e)
|
||||
p = e
|
||||
}
|
||||
return lines
|
||||
}
|
||||
return []string{"Yasuhiro Matsumoto <mattn.jp@gmail.com>"}
|
||||
}
|
||||
|
||||
func main() {
|
||||
gtk.Init(&os.Args)
|
||||
|
||||
window := gtk.NewWindow(gtk.WINDOW_TOPLEVEL)
|
||||
window.SetPosition(gtk.WIN_POS_CENTER)
|
||||
window.SetTitle("GTK Go!")
|
||||
window.SetIconName("gtk-dialog-info")
|
||||
window.Connect("destroy", func(ctx *glib.CallbackContext) {
|
||||
fmt.Println("got destroy!", ctx.Data().(string))
|
||||
gtk.MainQuit()
|
||||
}, "foo")
|
||||
|
||||
//--------------------------------------------------------
|
||||
// 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("Demo")
|
||||
framebox1 := gtk.NewVBox(false, 1)
|
||||
frame1.Add(framebox1)
|
||||
|
||||
frame2 := gtk.NewFrame("Demo")
|
||||
framebox2 := gtk.NewVBox(false, 1)
|
||||
frame2.Add(framebox2)
|
||||
|
||||
vpaned.Pack1(frame1, false, false)
|
||||
vpaned.Pack2(frame2, false, false)
|
||||
|
||||
//--------------------------------------------------------
|
||||
// GtkImage
|
||||
//--------------------------------------------------------
|
||||
dir, _ := filepath.Split(os.Args[0])
|
||||
imagefile := filepath.Join(dir, "../../data/go-gtk-logo.png")
|
||||
|
||||
label := gtk.NewLabel("Go Binding for GTK")
|
||||
label.ModifyFontEasy("DejaVu Serif 15")
|
||||
framebox1.PackStart(label, false, true, 0)
|
||||
|
||||
//--------------------------------------------------------
|
||||
// GtkEntry
|
||||
//--------------------------------------------------------
|
||||
entry := gtk.NewEntry()
|
||||
entry.SetText("Hello world")
|
||||
framebox1.Add(entry)
|
||||
|
||||
image := gtk.NewImageFromFile(imagefile)
|
||||
framebox1.Add(image)
|
||||
|
||||
//--------------------------------------------------------
|
||||
// GtkScale
|
||||
//--------------------------------------------------------
|
||||
scale := gtk.NewHScaleWithRange(0, 100, 1)
|
||||
scale.Connect("value-changed", func() {
|
||||
fmt.Println("scale:", int(scale.GetValue()))
|
||||
})
|
||||
framebox2.Add(scale)
|
||||
|
||||
//--------------------------------------------------------
|
||||
// GtkHBox
|
||||
//--------------------------------------------------------
|
||||
buttons := gtk.NewHBox(false, 1)
|
||||
|
||||
//--------------------------------------------------------
|
||||
// GtkButton
|
||||
//--------------------------------------------------------
|
||||
button := gtk.NewButtonWithLabel("Button with label")
|
||||
button.Clicked(func() {
|
||||
fmt.Println("button clicked:", button.GetLabel())
|
||||
messagedialog := gtk.NewMessageDialog(
|
||||
button.GetTopLevelAsWindow(),
|
||||
gtk.DIALOG_MODAL,
|
||||
gtk.MESSAGE_INFO,
|
||||
gtk.BUTTONS_OK,
|
||||
entry.GetText())
|
||||
messagedialog.Response(func() {
|
||||
fmt.Println("Dialog OK!")
|
||||
|
||||
//--------------------------------------------------------
|
||||
// GtkFileChooserDialog
|
||||
//--------------------------------------------------------
|
||||
filechooserdialog := gtk.NewFileChooserDialog(
|
||||
"Choose File...",
|
||||
button.GetTopLevelAsWindow(),
|
||||
gtk.FILE_CHOOSER_ACTION_OPEN,
|
||||
gtk.STOCK_OK,
|
||||
gtk.RESPONSE_ACCEPT)
|
||||
filter := gtk.NewFileFilter()
|
||||
filter.AddPattern("*.go")
|
||||
filechooserdialog.AddFilter(filter)
|
||||
filechooserdialog.Response(func() {
|
||||
fmt.Println(filechooserdialog.GetFilename())
|
||||
filechooserdialog.Destroy()
|
||||
})
|
||||
filechooserdialog.Run()
|
||||
messagedialog.Destroy()
|
||||
})
|
||||
messagedialog.Run()
|
||||
})
|
||||
buttons.Add(button)
|
||||
|
||||
//--------------------------------------------------------
|
||||
// GtkFontButton
|
||||
//--------------------------------------------------------
|
||||
fontbutton := gtk.NewFontButton()
|
||||
fontbutton.Connect("font-set", func() {
|
||||
fmt.Println("title:", fontbutton.GetTitle())
|
||||
fmt.Println("fontname:", fontbutton.GetFontName())
|
||||
fmt.Println("use_size:", fontbutton.GetUseSize())
|
||||
fmt.Println("show_size:", fontbutton.GetShowSize())
|
||||
})
|
||||
buttons.Add(fontbutton)
|
||||
framebox2.PackStart(buttons, false, false, 0)
|
||||
|
||||
buttons = gtk.NewHBox(false, 1)
|
||||
|
||||
//--------------------------------------------------------
|
||||
// GtkToggleButton
|
||||
//--------------------------------------------------------
|
||||
togglebutton := gtk.NewToggleButtonWithLabel("ToggleButton with label")
|
||||
togglebutton.Connect("toggled", func() {
|
||||
if togglebutton.GetActive() {
|
||||
togglebutton.SetLabel("ToggleButton ON!")
|
||||
} else {
|
||||
togglebutton.SetLabel("ToggleButton OFF!")
|
||||
}
|
||||
})
|
||||
buttons.Add(togglebutton)
|
||||
|
||||
//--------------------------------------------------------
|
||||
// GtkCheckButton
|
||||
//--------------------------------------------------------
|
||||
checkbutton := gtk.NewCheckButtonWithLabel("CheckButton with label")
|
||||
checkbutton.Connect("toggled", func() {
|
||||
if checkbutton.GetActive() {
|
||||
checkbutton.SetLabel("CheckButton CHECKED!")
|
||||
} else {
|
||||
checkbutton.SetLabel("CheckButton UNCHECKED!")
|
||||
}
|
||||
})
|
||||
buttons.Add(checkbutton)
|
||||
|
||||
//--------------------------------------------------------
|
||||
// GtkRadioButton
|
||||
//--------------------------------------------------------
|
||||
buttonbox := gtk.NewVBox(false, 1)
|
||||
radiofirst := gtk.NewRadioButtonWithLabel(nil, "Radio1")
|
||||
buttonbox.Add(radiofirst)
|
||||
buttonbox.Add(gtk.NewRadioButtonWithLabel(radiofirst.GetGroup(), "Radio2"))
|
||||
buttonbox.Add(gtk.NewRadioButtonWithLabel(radiofirst.GetGroup(), "Radio3"))
|
||||
buttons.Add(buttonbox)
|
||||
//radiobutton.SetMode(false);
|
||||
radiofirst.SetActive(true)
|
||||
|
||||
framebox2.PackStart(buttons, false, false, 0)
|
||||
|
||||
//--------------------------------------------------------
|
||||
// GtkVSeparator
|
||||
//--------------------------------------------------------
|
||||
vsep := gtk.NewVSeparator()
|
||||
framebox2.PackStart(vsep, false, false, 0)
|
||||
|
||||
//--------------------------------------------------------
|
||||
// GtkComboBoxEntry
|
||||
//--------------------------------------------------------
|
||||
combos := gtk.NewHBox(false, 1)
|
||||
comboboxentry := gtk.NewComboBoxText()
|
||||
comboboxentry.AppendText("Monkey")
|
||||
comboboxentry.AppendText("Tiger")
|
||||
comboboxentry.AppendText("Elephant")
|
||||
comboboxentry.Connect("changed", func() {
|
||||
fmt.Println("value:", comboboxentry.GetActiveText())
|
||||
})
|
||||
combos.Add(comboboxentry)
|
||||
|
||||
//--------------------------------------------------------
|
||||
// GtkComboBox
|
||||
//--------------------------------------------------------
|
||||
combobox := gtk.NewComboBoxText()
|
||||
combobox.AppendText("Peach")
|
||||
combobox.AppendText("Banana")
|
||||
combobox.AppendText("Apple")
|
||||
combobox.SetActive(1)
|
||||
combobox.Connect("changed", func() {
|
||||
fmt.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() {
|
||||
fmt.Println("changed")
|
||||
})
|
||||
|
||||
//--------------------------------------------------------
|
||||
// GtkMenuItem
|
||||
//--------------------------------------------------------
|
||||
cascademenu := gtk.NewMenuItemWithMnemonic("_File")
|
||||
menubar.Append(cascademenu)
|
||||
submenu := gtk.NewMenu()
|
||||
cascademenu.SetSubmenu(submenu)
|
||||
|
||||
var menuitem *gtk.MenuItem
|
||||
menuitem = gtk.NewMenuItemWithMnemonic("E_xit")
|
||||
menuitem.Connect("activate", func() {
|
||||
gtk.MainQuit()
|
||||
})
|
||||
submenu.Append(menuitem)
|
||||
|
||||
cascademenu = gtk.NewMenuItemWithMnemonic("_View")
|
||||
menubar.Append(cascademenu)
|
||||
submenu = gtk.NewMenu()
|
||||
cascademenu.SetSubmenu(submenu)
|
||||
|
||||
checkmenuitem := gtk.NewCheckMenuItemWithMnemonic("_Disable")
|
||||
checkmenuitem.Connect("activate", func() {
|
||||
vpaned.SetSensitive(!checkmenuitem.GetActive())
|
||||
})
|
||||
submenu.Append(checkmenuitem)
|
||||
|
||||
menuitem = gtk.NewMenuItemWithMnemonic("_Font")
|
||||
menuitem.Connect("activate", func() {
|
||||
fsd := gtk.NewFontSelectionDialog("Font")
|
||||
fsd.SetFontName(fontbutton.GetFontName())
|
||||
fsd.Response(func() {
|
||||
fmt.Println(fsd.GetFontName())
|
||||
fontbutton.SetFontName(fsd.GetFontName())
|
||||
fsd.Destroy()
|
||||
})
|
||||
fsd.SetTransientFor(window)
|
||||
fsd.Run()
|
||||
})
|
||||
submenu.Append(menuitem)
|
||||
|
||||
cascademenu = gtk.NewMenuItemWithMnemonic("_Help")
|
||||
menubar.Append(cascademenu)
|
||||
submenu = gtk.NewMenu()
|
||||
cascademenu.SetSubmenu(submenu)
|
||||
|
||||
menuitem = gtk.NewMenuItemWithMnemonic("_About")
|
||||
menuitem.Connect("activate", func() {
|
||||
dialog := gtk.NewAboutDialog()
|
||||
dialog.SetName("Go-Gtk Demo!")
|
||||
dialog.SetProgramName("demo")
|
||||
dialog.SetAuthors(authors())
|
||||
dir, _ := filepath.Split(os.Args[0])
|
||||
imagefile := filepath.Join(dir, "../../data/mattn-logo.png")
|
||||
pixbuf, _ := gdkpixbuf.NewPixbufFromFile(imagefile)
|
||||
dialog.SetLogo(pixbuf)
|
||||
dialog.SetLicense("The library is available under the same terms and conditions as the Go, the BSD style license, and the LGPL (Lesser GNU Public License). The idea is that if you can use Go (and Gtk) in a project, you should also be able to use go-gtk.")
|
||||
dialog.SetWrapLicense(true)
|
||||
dialog.Run()
|
||||
dialog.Destroy()
|
||||
})
|
||||
submenu.Append(menuitem)
|
||||
|
||||
//--------------------------------------------------------
|
||||
// GtkStatusbar
|
||||
//--------------------------------------------------------
|
||||
statusbar := gtk.NewStatusbar()
|
||||
context_id := statusbar.GetContextId("go-gtk")
|
||||
statusbar.Push(context_id, "GTK binding for Go!")
|
||||
|
||||
framebox2.PackStart(statusbar, false, false, 0)
|
||||
|
||||
//--------------------------------------------------------
|
||||
// Event
|
||||
//--------------------------------------------------------
|
||||
window.Add(vbox)
|
||||
window.SetSizeRequest(600, 600)
|
||||
window.ShowAll()
|
||||
gtk.Main()
|
||||
}
|
64
vendor/github.com/mattn/go-gtk/example/dnd/dnd.go
generated
vendored
Normal file
64
vendor/github.com/mattn/go-gtk/example/dnd/dnd.go
generated
vendored
Normal file
@@ -0,0 +1,64 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"os"
|
||||
"strings"
|
||||
"unsafe"
|
||||
|
||||
"github.com/mattn/go-gtk/gdk"
|
||||
"github.com/mattn/go-gtk/glib"
|
||||
"github.com/mattn/go-gtk/gtk"
|
||||
)
|
||||
|
||||
func main() {
|
||||
gtk.Init(&os.Args)
|
||||
window := gtk.NewWindow(gtk.WINDOW_TOPLEVEL)
|
||||
window.SetTitle("GTK DND")
|
||||
window.Connect("destroy", gtk.MainQuit)
|
||||
|
||||
vbox := gtk.NewVBox(true, 0)
|
||||
vbox.SetBorderWidth(5)
|
||||
|
||||
targets := []gtk.TargetEntry{
|
||||
{"text/uri-list", 0, 0},
|
||||
{"STRING", 0, 1},
|
||||
{"text/plain", 0, 2},
|
||||
}
|
||||
dest := gtk.NewLabel("drop me file")
|
||||
dest.DragDestSet(
|
||||
gtk.DEST_DEFAULT_MOTION|
|
||||
gtk.DEST_DEFAULT_HIGHLIGHT|
|
||||
gtk.DEST_DEFAULT_DROP,
|
||||
targets,
|
||||
gdk.ACTION_COPY)
|
||||
dest.DragDestAddUriTargets()
|
||||
dest.Connect("drag-data-received", func(ctx *glib.CallbackContext) {
|
||||
sdata := gtk.NewSelectionDataFromNative(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.NewMessageDialog(
|
||||
window,
|
||||
gtk.DIALOG_MODAL,
|
||||
gtk.MESSAGE_INFO,
|
||||
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()
|
||||
}
|
92
vendor/github.com/mattn/go-gtk/example/drawable/drawable.go
generated
vendored
Normal file
92
vendor/github.com/mattn/go-gtk/example/drawable/drawable.go
generated
vendored
Normal file
@@ -0,0 +1,92 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"github.com/mattn/go-gtk/gdk"
|
||||
"github.com/mattn/go-gtk/glib"
|
||||
"github.com/mattn/go-gtk/gtk"
|
||||
"os"
|
||||
"unsafe"
|
||||
)
|
||||
|
||||
type point struct {
|
||||
x int
|
||||
y int
|
||||
}
|
||||
|
||||
func main() {
|
||||
gtk.Init(&os.Args)
|
||||
window := gtk.NewWindow(gtk.WINDOW_TOPLEVEL)
|
||||
window.SetTitle("GTK DrawingArea")
|
||||
window.Connect("destroy", gtk.MainQuit)
|
||||
|
||||
vbox := gtk.NewVBox(true, 0)
|
||||
vbox.SetBorderWidth(5)
|
||||
drawingarea := gtk.NewDrawingArea()
|
||||
|
||||
var p1, p2 point
|
||||
var gdkwin *gdk.Window
|
||||
var pixmap *gdk.Pixmap
|
||||
var gc *gdk.GC
|
||||
p1.x = -1
|
||||
p1.y = -1
|
||||
colors := []string{
|
||||
"black",
|
||||
"gray",
|
||||
"blue",
|
||||
"purple",
|
||||
"red",
|
||||
"orange",
|
||||
"yellow",
|
||||
"green",
|
||||
"darkgreen",
|
||||
}
|
||||
|
||||
drawingarea.Connect("configure-event", func() {
|
||||
if pixmap != nil {
|
||||
pixmap.Unref()
|
||||
}
|
||||
allocation := drawingarea.GetAllocation()
|
||||
pixmap = gdk.NewPixmap(drawingarea.GetWindow().GetDrawable(), allocation.Width, allocation.Height, 24)
|
||||
gc = gdk.NewGC(pixmap.GetDrawable())
|
||||
gc.SetRgbFgColor(gdk.NewColor("white"))
|
||||
pixmap.GetDrawable().DrawRectangle(gc, true, 0, 0, -1, -1)
|
||||
gc.SetRgbFgColor(gdk.NewColor(colors[0]))
|
||||
gc.SetRgbBgColor(gdk.NewColor("white"))
|
||||
})
|
||||
|
||||
drawingarea.Connect("motion-notify-event", func(ctx *glib.CallbackContext) {
|
||||
arg := ctx.Args(0)
|
||||
mev := *(**gdk.EventMotion)(unsafe.Pointer(&arg))
|
||||
var mt gdk.ModifierType
|
||||
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.EventMask(mt)&gdk.BUTTON_PRESS_MASK) != 0 {
|
||||
pixmap.GetDrawable().DrawLine(gc, p1.x, p1.y, p2.x, p2.y)
|
||||
gdkwin.Invalidate(nil, false)
|
||||
}
|
||||
colors = append(colors[1:], colors[0])
|
||||
gc.SetRgbFgColor(gdk.NewColor(colors[0]))
|
||||
p1 = p2
|
||||
})
|
||||
|
||||
drawingarea.Connect("expose-event", func() {
|
||||
if pixmap == nil {
|
||||
return
|
||||
}
|
||||
gdkwin.GetDrawable().DrawDrawable(gc, pixmap.GetDrawable(), 0, 0, 0, 0, -1, -1)
|
||||
})
|
||||
|
||||
drawingarea.SetEvents(int(gdk.POINTER_MOTION_MASK | gdk.POINTER_MOTION_HINT_MASK | gdk.BUTTON_PRESS_MASK))
|
||||
vbox.Add(drawingarea)
|
||||
|
||||
window.Add(vbox)
|
||||
window.SetSizeRequest(400, 400)
|
||||
window.ShowAll()
|
||||
|
||||
gdkwin = drawingarea.GetWindow()
|
||||
|
||||
gtk.Main()
|
||||
}
|
48
vendor/github.com/mattn/go-gtk/example/event/event.go
generated
vendored
Normal file
48
vendor/github.com/mattn/go-gtk/example/event/event.go
generated
vendored
Normal file
@@ -0,0 +1,48 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"github.com/mattn/go-gtk/gdk"
|
||||
"github.com/mattn/go-gtk/glib"
|
||||
"github.com/mattn/go-gtk/gtk"
|
||||
"os"
|
||||
"unsafe"
|
||||
)
|
||||
|
||||
func main() {
|
||||
gtk.Init(&os.Args)
|
||||
window := gtk.NewWindow(gtk.WINDOW_TOPLEVEL)
|
||||
window.SetTitle("GTK Events")
|
||||
window.Connect("destroy", gtk.MainQuit)
|
||||
|
||||
event := make(chan interface{})
|
||||
|
||||
window.Connect("key-press-event", func(ctx *glib.CallbackContext) {
|
||||
arg := ctx.Args(0)
|
||||
event <- *(**gdk.EventKey)(unsafe.Pointer(&arg))
|
||||
})
|
||||
window.Connect("motion-notify-event", func(ctx *glib.CallbackContext) {
|
||||
arg := ctx.Args(0)
|
||||
event <- *(**gdk.EventMotion)(unsafe.Pointer(&arg))
|
||||
})
|
||||
|
||||
go func() {
|
||||
for {
|
||||
e := <-event
|
||||
switch ev := e.(type) {
|
||||
case *gdk.EventKey:
|
||||
fmt.Println("key-press-event:", ev.Keyval)
|
||||
break
|
||||
case *gdk.EventMotion:
|
||||
fmt.Println("motion-notify-event:", int(ev.X), int(ev.Y))
|
||||
break
|
||||
}
|
||||
}
|
||||
}()
|
||||
|
||||
window.SetEvents(int(gdk.POINTER_MOTION_MASK | gdk.POINTER_MOTION_HINT_MASK | gdk.BUTTON_PRESS_MASK))
|
||||
window.SetSizeRequest(400, 400)
|
||||
window.ShowAll()
|
||||
|
||||
gtk.Main()
|
||||
}
|
59
vendor/github.com/mattn/go-gtk/example/example.mk
generated
vendored
Normal file
59
vendor/github.com/mattn/go-gtk/example/example.mk
generated
vendored
Normal file
@@ -0,0 +1,59 @@
|
||||
EXAMPLES := \
|
||||
example/action/action \
|
||||
example/alignment/alignment \
|
||||
example/builder/builder \
|
||||
example/clipboard/clipboard \
|
||||
example/demo/demo \
|
||||
example/arrow/arrow \
|
||||
example/dnd/dnd \
|
||||
example/drawable/drawable \
|
||||
example/event/event \
|
||||
example/expander/expander \
|
||||
example/iconview/iconview \
|
||||
example/listview/listview \
|
||||
example/locale/locale \
|
||||
example/notebook/notebook \
|
||||
example/number/number \
|
||||
example/sourceview/sourceview \
|
||||
example/spinbutton/spinbutton \
|
||||
example/statusicon/statusicon \
|
||||
example/table/table \
|
||||
example/thread/thread \
|
||||
example/toolbar/toolbar \
|
||||
example/treeview/treeview \
|
||||
example/twitterstream/twitterstream
|
||||
|
||||
.PHONY: example
|
||||
example: $(EXAMPLES)
|
||||
@true
|
||||
|
||||
.PHONY: clean-example
|
||||
clean-example:
|
||||
rm -f $(EXAMPLES)
|
||||
|
||||
%: %.go
|
||||
cd $(@D) && go build -x
|
||||
|
||||
example/action/action: example/action/action.go
|
||||
example/alignment/alignment: example/alignment/alignment.go
|
||||
example/builder/builder: example/builder/builder.go
|
||||
example/clipboard/clipboard: example/clipboard/clipboard.go
|
||||
example/demo/demo: example/demo/demo.go
|
||||
example/arrow/arrow: example/arrow/arrow.go
|
||||
example/dnd/dnd: example/dnd/dnd.go
|
||||
example/drawable/drawable: example/drawable/drawable.go
|
||||
example/event/event: example/event/event.go
|
||||
example/expander/expander: example/expander/expander.go
|
||||
example/iconview/iconview: example/iconview/iconview.go
|
||||
example/listview/listview: example/listview/listview.go
|
||||
example/locale/locale: example/locale/locale.go
|
||||
example/notebook/notebook: example/notebook/notebook.go
|
||||
example/number/number: example/number/number.go
|
||||
example/sourceview/sourceview: example/sourceview/sourceview.go
|
||||
example/spinbutton/spinbutton: example/spinbutton/spinbutton.go
|
||||
example/statusicon/statusicon: example/statusicon/statusicon.go
|
||||
example/table/table: example/table/table.go
|
||||
example/thread/thread: example/thread/thread.go
|
||||
example/toolbar/toolbar: example/toolbar/toolbar.go
|
||||
example/treeview/treeview: example/treeview/treeview.go
|
||||
example/twitterstream/twitterstream: example/twitterstream/twitterstream.go
|
24
vendor/github.com/mattn/go-gtk/example/expander/expander.go
generated
vendored
Normal file
24
vendor/github.com/mattn/go-gtk/example/expander/expander.go
generated
vendored
Normal file
@@ -0,0 +1,24 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"github.com/mattn/go-gtk/gtk"
|
||||
"os"
|
||||
)
|
||||
|
||||
func main() {
|
||||
gtk.Init(&os.Args)
|
||||
window := gtk.NewWindow(gtk.WINDOW_TOPLEVEL)
|
||||
window.SetTitle("We love Expander")
|
||||
window.Connect("destroy", gtk.MainQuit)
|
||||
|
||||
vbox := gtk.NewVBox(true, 0)
|
||||
vbox.SetBorderWidth(5)
|
||||
expander := gtk.NewExpander("dan the ...")
|
||||
expander.Add(gtk.NewLabel("404 contents not found"))
|
||||
vbox.PackStart(expander, false, false, 0)
|
||||
|
||||
window.Add(vbox)
|
||||
window.ShowAll()
|
||||
|
||||
gtk.Main()
|
||||
}
|
40
vendor/github.com/mattn/go-gtk/example/iconview/iconview.go
generated
vendored
Normal file
40
vendor/github.com/mattn/go-gtk/example/iconview/iconview.go
generated
vendored
Normal file
@@ -0,0 +1,40 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"os"
|
||||
"unsafe"
|
||||
|
||||
"github.com/mattn/go-gtk/gdkpixbuf"
|
||||
"github.com/mattn/go-gtk/glib"
|
||||
"github.com/mattn/go-gtk/gtk"
|
||||
)
|
||||
|
||||
func main() {
|
||||
gtk.Init(&os.Args)
|
||||
window := gtk.NewWindow(gtk.WINDOW_TOPLEVEL)
|
||||
window.SetTitle("GTK Icon View")
|
||||
window.Connect("destroy", gtk.MainQuit)
|
||||
|
||||
swin := gtk.NewScrolledWindow(nil, nil)
|
||||
|
||||
store := gtk.NewListStore(gdkpixbuf.GetType(), glib.G_TYPE_STRING)
|
||||
iconview := gtk.NewIconViewWithModel(store)
|
||||
iconview.SetPixbufColumn(0)
|
||||
iconview.SetTextColumn(1)
|
||||
swin.Add(iconview)
|
||||
|
||||
gtk.StockListIDs().ForEach(func(d unsafe.Pointer, v interface{}) {
|
||||
id := glib.GPtrToString(d)
|
||||
var iter gtk.TreeIter
|
||||
store.Append(&iter)
|
||||
store.Set(&iter,
|
||||
0, gtk.NewImage().RenderIcon(id, gtk.ICON_SIZE_SMALL_TOOLBAR, "").GPixbuf,
|
||||
1, id)
|
||||
})
|
||||
|
||||
window.Add(swin)
|
||||
window.SetSizeRequest(500, 200)
|
||||
window.ShowAll()
|
||||
|
||||
gtk.Main()
|
||||
}
|
21
vendor/github.com/mattn/go-gtk/example/idle/idle.go
generated
vendored
Normal file
21
vendor/github.com/mattn/go-gtk/example/idle/idle.go
generated
vendored
Normal file
@@ -0,0 +1,21 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"time"
|
||||
|
||||
"github.com/mattn/go-gtk/glib"
|
||||
)
|
||||
|
||||
func main() {
|
||||
glib.IdleAdd(func() bool {
|
||||
fmt.Println("start")
|
||||
return false
|
||||
})
|
||||
glib.TimeoutAdd(1000, func() bool {
|
||||
fmt.Println(fmt.Sprintf("%v", time.Now()))
|
||||
return true
|
||||
})
|
||||
|
||||
glib.NewMainLoop(nil, false).Run()
|
||||
}
|
46
vendor/github.com/mattn/go-gtk/example/listview/listview.go
generated
vendored
Normal file
46
vendor/github.com/mattn/go-gtk/example/listview/listview.go
generated
vendored
Normal file
@@ -0,0 +1,46 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"os"
|
||||
"unsafe"
|
||||
|
||||
"github.com/mattn/go-gtk/gdkpixbuf"
|
||||
"github.com/mattn/go-gtk/glib"
|
||||
"github.com/mattn/go-gtk/gtk"
|
||||
)
|
||||
|
||||
func main() {
|
||||
gtk.Init(&os.Args)
|
||||
window := gtk.NewWindow(gtk.WINDOW_TOPLEVEL)
|
||||
window.SetTitle("GTK Stock Icons")
|
||||
window.Connect("destroy", gtk.MainQuit)
|
||||
|
||||
swin := gtk.NewScrolledWindow(nil, nil)
|
||||
|
||||
store := gtk.NewListStore(glib.G_TYPE_STRING, glib.G_TYPE_BOOL, gdkpixbuf.GetType())
|
||||
treeview := gtk.NewTreeView()
|
||||
swin.Add(treeview)
|
||||
|
||||
treeview.SetModel(store)
|
||||
treeview.AppendColumn(gtk.NewTreeViewColumnWithAttributes("name", gtk.NewCellRendererText(), "text", 0))
|
||||
treeview.AppendColumn(gtk.NewTreeViewColumnWithAttributes("check", gtk.NewCellRendererToggle(), "active", 1))
|
||||
treeview.AppendColumn(gtk.NewTreeViewColumnWithAttributes("icon", gtk.NewCellRendererPixbuf(), "pixbuf", 2))
|
||||
n := 0
|
||||
gtk.StockListIDs().ForEach(func(d unsafe.Pointer, v interface{}) {
|
||||
id := glib.GPtrToString(d)
|
||||
var iter gtk.TreeIter
|
||||
store.Append(&iter)
|
||||
store.Set(&iter,
|
||||
0, id,
|
||||
1, (n == 1),
|
||||
2, gtk.NewImage().RenderIcon(id, gtk.ICON_SIZE_SMALL_TOOLBAR, "").GPixbuf,
|
||||
)
|
||||
n = 1 - n
|
||||
})
|
||||
|
||||
window.Add(swin)
|
||||
window.SetSizeRequest(400, 200)
|
||||
window.ShowAll()
|
||||
|
||||
gtk.Main()
|
||||
}
|
17
vendor/github.com/mattn/go-gtk/example/locale/locale.go
generated
vendored
Normal file
17
vendor/github.com/mattn/go-gtk/example/locale/locale.go
generated
vendored
Normal file
@@ -0,0 +1,17 @@
|
||||
package main
|
||||
|
||||
import "github.com/mattn/go-gtk/gtk"
|
||||
import "github.com/mattn/go-gtk/glib"
|
||||
import "fmt"
|
||||
import "syscall"
|
||||
|
||||
func main() {
|
||||
gtk.SetLocale()
|
||||
|
||||
bs, _, _, err := glib.LocaleFromUtf8("こんにちわ世界\n")
|
||||
if err == nil {
|
||||
syscall.Write(syscall.Stdout, bs)
|
||||
} else {
|
||||
fmt.Println(err.Message())
|
||||
}
|
||||
}
|
42
vendor/github.com/mattn/go-gtk/example/notebook/notebook.go
generated
vendored
Normal file
42
vendor/github.com/mattn/go-gtk/example/notebook/notebook.go
generated
vendored
Normal file
@@ -0,0 +1,42 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"github.com/mattn/go-gtk/gtk"
|
||||
"os"
|
||||
"strconv"
|
||||
)
|
||||
|
||||
func main() {
|
||||
gtk.Init(&os.Args)
|
||||
window := gtk.NewWindow(gtk.WINDOW_TOPLEVEL)
|
||||
window.SetTitle("GTK Notebook")
|
||||
window.Connect("destroy", gtk.MainQuit)
|
||||
|
||||
notebook := gtk.NewNotebook()
|
||||
for n := 1; n <= 10; n++ {
|
||||
page := gtk.NewFrame("demo" + strconv.Itoa(n))
|
||||
notebook.AppendPage(page, gtk.NewLabel("demo"+strconv.Itoa(n)))
|
||||
|
||||
vbox := gtk.NewHBox(false, 1)
|
||||
|
||||
prev := gtk.NewButtonWithLabel("go prev")
|
||||
prev.Clicked(func() {
|
||||
notebook.PrevPage()
|
||||
})
|
||||
vbox.Add(prev)
|
||||
|
||||
next := gtk.NewButtonWithLabel("go next")
|
||||
next.Clicked(func() {
|
||||
notebook.NextPage()
|
||||
})
|
||||
vbox.Add(next)
|
||||
|
||||
page.Add(vbox)
|
||||
}
|
||||
|
||||
window.Add(notebook)
|
||||
window.SetSizeRequest(400, 200)
|
||||
window.ShowAll()
|
||||
|
||||
gtk.Main()
|
||||
}
|
56
vendor/github.com/mattn/go-gtk/example/number/number.go
generated
vendored
Normal file
56
vendor/github.com/mattn/go-gtk/example/number/number.go
generated
vendored
Normal file
@@ -0,0 +1,56 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"github.com/mattn/go-gtk/glib"
|
||||
"github.com/mattn/go-gtk/gtk"
|
||||
"os"
|
||||
"strconv"
|
||||
"unsafe"
|
||||
)
|
||||
|
||||
func main() {
|
||||
gtk.Init(&os.Args)
|
||||
|
||||
dialog := gtk.NewDialog()
|
||||
dialog.SetTitle("number input")
|
||||
|
||||
vbox := dialog.GetVBox()
|
||||
|
||||
label := gtk.NewLabel("Numnber:")
|
||||
vbox.Add(label)
|
||||
|
||||
input := gtk.NewEntry()
|
||||
input.SetEditable(true)
|
||||
vbox.Add(input)
|
||||
|
||||
input.Connect("insert-text", func(ctx *glib.CallbackContext) {
|
||||
a := (*[2000]uint8)(unsafe.Pointer(ctx.Args(0)))
|
||||
p := (*int)(unsafe.Pointer(ctx.Args(2)))
|
||||
i := 0
|
||||
for a[i] != 0 {
|
||||
i++
|
||||
}
|
||||
s := string(a[0:i])
|
||||
if s == "." {
|
||||
if *p == 0 {
|
||||
input.StopEmission("insert-text")
|
||||
}
|
||||
} else {
|
||||
_, err := strconv.ParseFloat(s, 64)
|
||||
if err != nil {
|
||||
input.StopEmission("insert-text")
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
button := gtk.NewButtonWithLabel("OK")
|
||||
button.Connect("clicked", func() {
|
||||
fmt.Println(input.GetText())
|
||||
gtk.MainQuit()
|
||||
})
|
||||
vbox.Add(button)
|
||||
|
||||
dialog.ShowAll()
|
||||
gtk.Main()
|
||||
}
|
61
vendor/github.com/mattn/go-gtk/example/sourceview/sourceview.go
generated
vendored
Normal file
61
vendor/github.com/mattn/go-gtk/example/sourceview/sourceview.go
generated
vendored
Normal file
@@ -0,0 +1,61 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"github.com/mattn/go-gtk/gtk"
|
||||
gsv "github.com/mattn/go-gtk/gtksourceview"
|
||||
"os"
|
||||
)
|
||||
|
||||
func main() {
|
||||
gtk.Init(&os.Args)
|
||||
window := gtk.NewWindow(gtk.WINDOW_TOPLEVEL)
|
||||
window.SetTitle("SourceView")
|
||||
window.Connect("destroy", gtk.MainQuit)
|
||||
|
||||
swin := gtk.NewScrolledWindow(nil, nil)
|
||||
swin.SetPolicy(gtk.POLICY_AUTOMATIC, gtk.POLICY_AUTOMATIC)
|
||||
swin.SetShadowType(gtk.SHADOW_IN)
|
||||
sourcebuffer := gsv.NewSourceBufferWithLanguage(gsv.SourceLanguageManagerGetDefault().GetLanguage("cpp"))
|
||||
sourceview := gsv.NewSourceViewWithBuffer(sourcebuffer)
|
||||
|
||||
var start gtk.TextIter
|
||||
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()
|
||||
}
|
56
vendor/github.com/mattn/go-gtk/example/spinbutton/spinbutton.go
generated
vendored
Normal file
56
vendor/github.com/mattn/go-gtk/example/spinbutton/spinbutton.go
generated
vendored
Normal file
@@ -0,0 +1,56 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"github.com/mattn/go-gtk/glib"
|
||||
"github.com/mattn/go-gtk/gtk"
|
||||
"strconv"
|
||||
)
|
||||
|
||||
func main() {
|
||||
gtk.Init(nil)
|
||||
window := gtk.NewWindow(gtk.WINDOW_TOPLEVEL)
|
||||
window.SetPosition(gtk.WIN_POS_CENTER)
|
||||
window.SetTitle("GTK Go!")
|
||||
window.Connect("destroy", func(ctx *glib.CallbackContext) {
|
||||
fmt.Println("got destroy!", ctx.Data().(string))
|
||||
gtk.MainQuit()
|
||||
}, "foo")
|
||||
|
||||
//--------------------------------------------------------
|
||||
// GtkHBox
|
||||
//--------------------------------------------------------
|
||||
fixed := gtk.NewFixed()
|
||||
|
||||
//--------------------------------------------------------
|
||||
// GtkSpinButton
|
||||
//--------------------------------------------------------
|
||||
spinbutton1 := gtk.NewSpinButtonWithRange(1.0, 10.0, 1.0)
|
||||
spinbutton1.SetDigits(3)
|
||||
spinbutton1.Spin(gtk.SPIN_STEP_FORWARD, 7.0)
|
||||
fixed.Put(spinbutton1, 40, 50)
|
||||
|
||||
spinbutton1.OnValueChanged(func() {
|
||||
val := spinbutton1.GetValueAsInt()
|
||||
fval := spinbutton1.GetValue()
|
||||
fmt.Println("SpinButton changed, new value: " + strconv.Itoa(val) + " | " + strconv.FormatFloat(fval, 'f', 2, 64))
|
||||
min, max := spinbutton1.GetRange()
|
||||
fmt.Println("Range: " + strconv.FormatFloat(min, 'f', 2, 64) + " " + strconv.FormatFloat(max, 'f', 2, 64))
|
||||
fmt.Println("Digits: " + strconv.Itoa(int(spinbutton1.GetDigits())))
|
||||
})
|
||||
|
||||
adjustment := gtk.NewAdjustment(2.0, 1.0, 8.0, 2.0, 0.0, 0.0)
|
||||
spinbutton2 := gtk.NewSpinButton(adjustment, 1.0, 1)
|
||||
spinbutton2.SetRange(0.0, 20.0)
|
||||
spinbutton2.SetValue(18.0)
|
||||
spinbutton2.SetIncrements(2.0, 4.0)
|
||||
fixed.Put(spinbutton2, 150, 50)
|
||||
|
||||
//--------------------------------------------------------
|
||||
// Event
|
||||
//--------------------------------------------------------
|
||||
window.Add(fixed)
|
||||
window.SetSizeRequest(600, 600)
|
||||
window.ShowAll()
|
||||
gtk.Main()
|
||||
}
|
40
vendor/github.com/mattn/go-gtk/example/statusicon/statusicon.go
generated
vendored
Normal file
40
vendor/github.com/mattn/go-gtk/example/statusicon/statusicon.go
generated
vendored
Normal file
@@ -0,0 +1,40 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"github.com/mattn/go-gtk/glib"
|
||||
"github.com/mattn/go-gtk/gtk"
|
||||
"os"
|
||||
)
|
||||
|
||||
func main() {
|
||||
gtk.Init(&os.Args)
|
||||
|
||||
glib.SetApplicationName("go-gtk-statusicon-example")
|
||||
|
||||
mi := gtk.NewMenuItemWithLabel("Popup!")
|
||||
mi.Connect("activate", func() {
|
||||
gtk.MainQuit()
|
||||
})
|
||||
nm := gtk.NewMenu()
|
||||
nm.Append(mi)
|
||||
nm.ShowAll()
|
||||
|
||||
si := gtk.NewStatusIconFromStock(gtk.STOCK_FILE)
|
||||
si.SetTitle("StatusIcon Example")
|
||||
si.SetTooltipMarkup("StatusIcon Example")
|
||||
si.Connect("popup-menu", func(cbx *glib.CallbackContext) {
|
||||
nm.Popup(nil, nil, gtk.StatusIconPositionMenu, si, uint(cbx.Args(0)), uint32(cbx.Args(1)))
|
||||
})
|
||||
|
||||
fmt.Println(`
|
||||
Can you see statusicon in systray?
|
||||
If you don't see it and if you use 'unity', try following.
|
||||
|
||||
# gsettings set com.canonical.Unity.Panel systray-whitelist \
|
||||
"$(gsettings get com.canonical.Unity.Panel systray-whitelist \|
|
||||
sed -e "s/]$/, 'go-gtk-statusicon-example']/")"
|
||||
`)
|
||||
|
||||
gtk.Main()
|
||||
}
|
31
vendor/github.com/mattn/go-gtk/example/table/table.go
generated
vendored
Normal file
31
vendor/github.com/mattn/go-gtk/example/table/table.go
generated
vendored
Normal file
@@ -0,0 +1,31 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"github.com/mattn/go-gtk/gtk"
|
||||
"os"
|
||||
)
|
||||
|
||||
func main() {
|
||||
gtk.Init(&os.Args)
|
||||
window := gtk.NewWindow(gtk.WINDOW_TOPLEVEL)
|
||||
window.SetTitle("GTK Table")
|
||||
window.Connect("destroy", gtk.MainQuit)
|
||||
|
||||
swin := gtk.NewScrolledWindow(nil, nil)
|
||||
swin.SetPolicy(gtk.POLICY_AUTOMATIC, gtk.POLICY_AUTOMATIC)
|
||||
|
||||
table := gtk.NewTable(5, 5, false)
|
||||
for y := uint(0); y < 5; y++ {
|
||||
for x := uint(0); x < 5; x++ {
|
||||
table.Attach(gtk.NewButtonWithLabel(fmt.Sprintf("%02d:%02d", x, y)), x, x+1, y, y+1, gtk.FILL, gtk.FILL, 5, 5)
|
||||
}
|
||||
}
|
||||
swin.AddWithViewPort(table)
|
||||
|
||||
window.Add(swin)
|
||||
window.SetDefaultSize(200, 200)
|
||||
window.ShowAll()
|
||||
|
||||
gtk.Main()
|
||||
}
|
55
vendor/github.com/mattn/go-gtk/example/textview/textview.go
generated
vendored
Normal file
55
vendor/github.com/mattn/go-gtk/example/textview/textview.go
generated
vendored
Normal file
@@ -0,0 +1,55 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"github.com/mattn/go-gtk/gdk"
|
||||
"github.com/mattn/go-gtk/glib"
|
||||
"github.com/mattn/go-gtk/gtk"
|
||||
"unsafe"
|
||||
)
|
||||
|
||||
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()
|
||||
}
|
51
vendor/github.com/mattn/go-gtk/example/thread/thread.go
generated
vendored
Normal file
51
vendor/github.com/mattn/go-gtk/example/thread/thread.go
generated
vendored
Normal file
@@ -0,0 +1,51 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"runtime"
|
||||
"strconv"
|
||||
"time"
|
||||
|
||||
"github.com/mattn/go-gtk/gdk"
|
||||
"github.com/mattn/go-gtk/glib"
|
||||
"github.com/mattn/go-gtk/gtk"
|
||||
)
|
||||
|
||||
func main() {
|
||||
runtime.GOMAXPROCS(10)
|
||||
glib.ThreadInit(nil)
|
||||
gdk.ThreadsInit()
|
||||
gdk.ThreadsEnter()
|
||||
gtk.Init(nil)
|
||||
window := gtk.NewWindow(gtk.WINDOW_TOPLEVEL)
|
||||
window.Connect("destroy", gtk.MainQuit)
|
||||
|
||||
vbox := gtk.NewVBox(false, 1)
|
||||
|
||||
label1 := gtk.NewLabel("")
|
||||
vbox.Add(label1)
|
||||
label2 := gtk.NewLabel("")
|
||||
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()
|
||||
}
|
108
vendor/github.com/mattn/go-gtk/example/toolbar/toolbar.go
generated
vendored
Normal file
108
vendor/github.com/mattn/go-gtk/example/toolbar/toolbar.go
generated
vendored
Normal file
@@ -0,0 +1,108 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"github.com/mattn/go-gtk/glib"
|
||||
"github.com/mattn/go-gtk/gtk"
|
||||
)
|
||||
|
||||
func main() {
|
||||
gtk.Init(nil)
|
||||
window := gtk.NewWindow(gtk.WINDOW_TOPLEVEL)
|
||||
window.SetPosition(gtk.WIN_POS_CENTER)
|
||||
window.SetTitle("GTK Go!")
|
||||
window.Connect("destroy", func(ctx *glib.CallbackContext) {
|
||||
gtk.MainQuit()
|
||||
}, "")
|
||||
|
||||
vbox := gtk.NewVBox(false, 0)
|
||||
|
||||
toolbar := gtk.NewToolbar()
|
||||
toolbar.SetStyle(gtk.TOOLBAR_ICONS)
|
||||
vbox.PackStart(toolbar, false, false, 5)
|
||||
|
||||
btnnew := gtk.NewToolButtonFromStock(gtk.STOCK_NEW)
|
||||
btnclose := gtk.NewToolButtonFromStock(gtk.STOCK_CLOSE)
|
||||
separator := gtk.NewSeparatorToolItem()
|
||||
btncustom := gtk.NewToolButton(nil, "Custom")
|
||||
btnmenu := gtk.NewMenuToolButtonFromStock("gtk.STOCK_CLOSE")
|
||||
btnmenu.SetArrowTooltipText("This is a tool tip")
|
||||
|
||||
btnnew.OnClicked(onToolButtonClicked)
|
||||
btnclose.OnClicked(onToolButtonClicked)
|
||||
btncustom.OnClicked(onToolButtonClicked)
|
||||
|
||||
toolmenu := gtk.NewMenu()
|
||||
menuitem := gtk.NewMenuItemWithMnemonic("8")
|
||||
menuitem.Show()
|
||||
toolmenu.Append(menuitem)
|
||||
menuitem = gtk.NewMenuItemWithMnemonic("16")
|
||||
menuitem.Show()
|
||||
toolmenu.Append(menuitem)
|
||||
menuitem = gtk.NewMenuItemWithMnemonic("32")
|
||||
menuitem.Show()
|
||||
toolmenu.Append(menuitem)
|
||||
btnmenu.SetMenu(toolmenu)
|
||||
|
||||
toolbar.Insert(btnnew, -1)
|
||||
toolbar.Insert(btnclose, -1)
|
||||
toolbar.Insert(separator, -1)
|
||||
toolbar.Insert(btncustom, -1)
|
||||
toolbar.Insert(btnmenu, -1)
|
||||
|
||||
hbox := gtk.NewHBox(false, 0)
|
||||
vbox.PackStart(hbox, true, true, 0)
|
||||
|
||||
toolbar2 := gtk.NewToolbar()
|
||||
toolbar2.SetOrientation(gtk.ORIENTATION_VERTICAL)
|
||||
hbox.PackStart(toolbar2, false, false, 5)
|
||||
btnhelp := gtk.NewToolButtonFromStock(gtk.STOCK_HELP)
|
||||
btnhelp.OnClicked(onToolButtonClicked)
|
||||
toolbar2.Insert(btnhelp, -1)
|
||||
|
||||
btntoggle := gtk.NewToggleToolButton()
|
||||
btntoggle2 := gtk.NewToggleToolButtonFromStock(gtk.STOCK_ITALIC)
|
||||
toolbar2.Insert(btntoggle, -1)
|
||||
toolbar2.Insert(btntoggle2, -1)
|
||||
|
||||
for i := 0; i < toolbar.GetNItems(); i++ {
|
||||
gti := toolbar.GetNthItem(i)
|
||||
switch gti.(type) {
|
||||
case *gtk.ToolButton:
|
||||
fmt.Printf("toolbar[%d] is a *gtk.ToolButton\n", i)
|
||||
w := gti.(*gtk.ToolButton).GetIconWidget()
|
||||
gti.(*gtk.ToolButton).SetIconWidget(w)
|
||||
case *gtk.ToggleToolButton:
|
||||
fmt.Printf("toolbar[%d] is a *gtk.ToggleToolButton\n", i)
|
||||
gti.(*gtk.ToggleToolButton).SetActive(true)
|
||||
case *gtk.SeparatorToolItem:
|
||||
fmt.Printf("toolbar[%d] is a *gtk.SeparatorToolItem\n", i)
|
||||
default:
|
||||
fmt.Printf("toolbar: Item is of unknown type\n")
|
||||
}
|
||||
}
|
||||
|
||||
for i := 0; i < toolbar2.GetNItems(); i++ {
|
||||
gti := toolbar2.GetNthItem(i)
|
||||
switch gti.(type) {
|
||||
case *gtk.ToolButton:
|
||||
fmt.Printf("toolbar2[%d] is a *gtk.ToolButton\n", i)
|
||||
case *gtk.ToggleToolButton:
|
||||
fmt.Printf("toolbar2[%d] is a *gtk.ToggleToolButton\n", i)
|
||||
gti.(*gtk.ToggleToolButton).SetActive(true)
|
||||
case *gtk.SeparatorToolItem:
|
||||
fmt.Printf("toolbar2[%d] is a *gtk.SeparatorToolItem\n", i)
|
||||
default:
|
||||
fmt.Printf("toolbar2: Item is of unknown type\n")
|
||||
}
|
||||
}
|
||||
|
||||
window.Add(vbox)
|
||||
window.SetSizeRequest(600, 600)
|
||||
window.ShowAll()
|
||||
gtk.Main()
|
||||
}
|
||||
|
||||
func onToolButtonClicked() {
|
||||
fmt.Println("ToolButton clicked")
|
||||
}
|
78
vendor/github.com/mattn/go-gtk/example/toolpalette/toolpalette.go
generated
vendored
Normal file
78
vendor/github.com/mattn/go-gtk/example/toolpalette/toolpalette.go
generated
vendored
Normal file
@@ -0,0 +1,78 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"github.com/mattn/go-gtk/glib"
|
||||
"github.com/mattn/go-gtk/gtk"
|
||||
)
|
||||
|
||||
func main() {
|
||||
gtk.Init(nil)
|
||||
window := gtk.NewWindow(gtk.WINDOW_TOPLEVEL)
|
||||
window.SetPosition(gtk.WIN_POS_CENTER)
|
||||
window.SetTitle("GTK Go!")
|
||||
window.Connect("destroy", func(ctx *glib.CallbackContext) {
|
||||
gtk.MainQuit()
|
||||
}, "")
|
||||
|
||||
box := gtk.NewHPaned()
|
||||
|
||||
palette := gtk.NewToolPalette()
|
||||
group := gtk.NewToolItemGroup("Tools")
|
||||
b := gtk.NewToolButtonFromStock(gtk.STOCK_NEW)
|
||||
b.OnClicked(func() { fmt.Println("You clicked new!") })
|
||||
group.Insert(b, -1)
|
||||
b = gtk.NewToolButtonFromStock(gtk.STOCK_CLOSE)
|
||||
group.Insert(b, -1)
|
||||
b = gtk.NewToolButtonFromStock(gtk.STOCK_REDO)
|
||||
group.Insert(b, -1)
|
||||
b = gtk.NewToolButtonFromStock(gtk.STOCK_REFRESH)
|
||||
group.Insert(b, -1)
|
||||
b = gtk.NewToolButtonFromStock(gtk.STOCK_QUIT)
|
||||
group.Insert(b, -1)
|
||||
b = gtk.NewToolButtonFromStock(gtk.STOCK_YES)
|
||||
group.Insert(b, -1)
|
||||
b = gtk.NewToolButtonFromStock(gtk.STOCK_NO)
|
||||
group.Insert(b, -1)
|
||||
b = gtk.NewToolButtonFromStock(gtk.STOCK_PRINT)
|
||||
group.Insert(b, -1)
|
||||
b = gtk.NewToolButtonFromStock(gtk.STOCK_NETWORK)
|
||||
group.Insert(b, -1)
|
||||
b = gtk.NewToolButtonFromStock(gtk.STOCK_INFO)
|
||||
group.Insert(b, -1)
|
||||
b = gtk.NewToolButtonFromStock(gtk.STOCK_HOME)
|
||||
group.Insert(b, -1)
|
||||
b = gtk.NewToolButtonFromStock(gtk.STOCK_INDEX)
|
||||
group.Insert(b, -1)
|
||||
b = gtk.NewToolButtonFromStock(gtk.STOCK_FIND)
|
||||
group.Insert(b, -1)
|
||||
b = gtk.NewToolButtonFromStock(gtk.STOCK_FILE)
|
||||
group.Insert(b, -1)
|
||||
b = gtk.NewToolButtonFromStock(gtk.STOCK_EXECUTE)
|
||||
group.Insert(b, -1)
|
||||
palette.Add(group)
|
||||
|
||||
bcopy := gtk.NewToolButtonFromStock(gtk.STOCK_COPY)
|
||||
bcut := gtk.NewToolButtonFromStock(gtk.STOCK_CUT)
|
||||
bdelete := gtk.NewToolButtonFromStock(gtk.STOCK_DELETE)
|
||||
|
||||
group = gtk.NewToolItemGroup("Stuff")
|
||||
group.Insert(bcopy, -1)
|
||||
group.Insert(bcut, -1)
|
||||
group.Insert(bdelete, -1)
|
||||
palette.Add(group)
|
||||
|
||||
frame := gtk.NewVBox(false, 1)
|
||||
align := gtk.NewAlignment(0, 0, 0, 0)
|
||||
image := gtk.NewImageFromFile("./turkey.jpg")
|
||||
align.Add(image)
|
||||
frame.Add(align)
|
||||
|
||||
box.Pack1(palette, true, false)
|
||||
box.Pack2(frame, false, false)
|
||||
|
||||
window.Add(box)
|
||||
window.SetSizeRequest(600, 600)
|
||||
window.ShowAll()
|
||||
gtk.Main()
|
||||
}
|
BIN
vendor/github.com/mattn/go-gtk/example/toolpalette/turkey.jpg
generated
vendored
Normal file
BIN
vendor/github.com/mattn/go-gtk/example/toolpalette/turkey.jpg
generated
vendored
Normal file
Binary file not shown.
After Width: | Height: | Size: 32 KiB |
60
vendor/github.com/mattn/go-gtk/example/treeview/treeview.go
generated
vendored
Normal file
60
vendor/github.com/mattn/go-gtk/example/treeview/treeview.go
generated
vendored
Normal file
@@ -0,0 +1,60 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"github.com/mattn/go-gtk/gdkpixbuf"
|
||||
"github.com/mattn/go-gtk/glib"
|
||||
"github.com/mattn/go-gtk/gtk"
|
||||
"os"
|
||||
"strconv"
|
||||
)
|
||||
|
||||
func main() {
|
||||
gtk.Init(&os.Args)
|
||||
window := gtk.NewWindow(gtk.WINDOW_TOPLEVEL)
|
||||
window.SetTitle("GTK Folder View")
|
||||
window.Connect("destroy", gtk.MainQuit)
|
||||
|
||||
swin := gtk.NewScrolledWindow(nil, nil)
|
||||
|
||||
store := gtk.NewTreeStore(gdkpixbuf.GetType(), glib.G_TYPE_STRING)
|
||||
treeview := gtk.NewTreeView()
|
||||
swin.Add(treeview)
|
||||
|
||||
treeview.SetModel(store.ToTreeModel())
|
||||
treeview.AppendColumn(gtk.NewTreeViewColumnWithAttributes("pixbuf", gtk.NewCellRendererPixbuf(), "pixbuf", 0))
|
||||
treeview.AppendColumn(gtk.NewTreeViewColumnWithAttributes("text", gtk.NewCellRendererText(), "text", 1))
|
||||
|
||||
for n := 1; n <= 10; n++ {
|
||||
var iter1, iter2, iter3 gtk.TreeIter
|
||||
store.Append(&iter1, nil)
|
||||
store.Set(&iter1, gtk.NewImage().RenderIcon(gtk.STOCK_DIRECTORY, gtk.ICON_SIZE_SMALL_TOOLBAR, "").GPixbuf, "Folder"+strconv.Itoa(n))
|
||||
store.Append(&iter2, &iter1)
|
||||
store.Set(&iter2, gtk.NewImage().RenderIcon(gtk.STOCK_DIRECTORY, gtk.ICON_SIZE_SMALL_TOOLBAR, "").GPixbuf, "SubFolder"+strconv.Itoa(n))
|
||||
store.Append(&iter3, &iter2)
|
||||
store.Set(&iter3, gtk.NewImage().RenderIcon(gtk.STOCK_FILE, gtk.ICON_SIZE_SMALL_TOOLBAR, "").GPixbuf, "File"+strconv.Itoa(n))
|
||||
}
|
||||
|
||||
treeview.Connect("row_activated", func() {
|
||||
var path *gtk.TreePath
|
||||
var column *gtk.TreeViewColumn
|
||||
treeview.GetCursor(&path, &column)
|
||||
mes := "TreePath is: " + path.String()
|
||||
dialog := gtk.NewMessageDialog(
|
||||
treeview.GetTopLevelAsWindow(),
|
||||
gtk.DIALOG_MODAL,
|
||||
gtk.MESSAGE_INFO,
|
||||
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()
|
||||
}
|
6
vendor/github.com/mattn/go-gtk/example/twitterstream/settings.json.example
generated
vendored
Normal file
6
vendor/github.com/mattn/go-gtk/example/twitterstream/settings.json.example
generated
vendored
Normal file
@@ -0,0 +1,6 @@
|
||||
{
|
||||
"AccessSecret": "ACCCESS_TOKEN_SECRET",
|
||||
"AccessToken": "ACCESS_TOKEN",
|
||||
"ClientSecret": "CLIENT_SECRET",
|
||||
"ClientToken": "CLIENT_TOKEN"
|
||||
}
|
249
vendor/github.com/mattn/go-gtk/example/twitterstream/twitterstream.go
generated
vendored
Normal file
249
vendor/github.com/mattn/go-gtk/example/twitterstream/twitterstream.go
generated
vendored
Normal file
@@ -0,0 +1,249 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"bufio"
|
||||
"compress/gzip"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"log"
|
||||
"net/http"
|
||||
"net/url"
|
||||
"os"
|
||||
"runtime"
|
||||
"strings"
|
||||
"sync"
|
||||
|
||||
"github.com/garyburd/go-oauth/oauth"
|
||||
"github.com/mattn/go-gtk/gdkpixbuf"
|
||||
"github.com/mattn/go-gtk/gtk"
|
||||
)
|
||||
|
||||
var (
|
||||
alive = true
|
||||
)
|
||||
|
||||
func readURL(url string) ([]byte, *http.Response) {
|
||||
r, err := http.Get(url)
|
||||
if err != nil {
|
||||
return nil, nil
|
||||
}
|
||||
var b []byte
|
||||
if b, err = ioutil.ReadAll(r.Body); err != nil {
|
||||
return nil, nil
|
||||
}
|
||||
return b, r
|
||||
}
|
||||
|
||||
func bytes2pixbuf(data []byte, typ string) *gdkpixbuf.Pixbuf {
|
||||
var loader *gdkpixbuf.Loader
|
||||
if strings.Index(typ, "jpeg") >= 0 {
|
||||
loader, _ = gdkpixbuf.NewLoaderWithMimeType("image/jpeg")
|
||||
} else {
|
||||
loader, _ = gdkpixbuf.NewLoaderWithMimeType("image/png")
|
||||
}
|
||||
loader.SetSize(24, 24)
|
||||
loader.Write(data)
|
||||
loader.Close()
|
||||
return loader.GetPixbuf()
|
||||
}
|
||||
|
||||
type tweet struct {
|
||||
Text string
|
||||
Identifier string `json:"id_str"`
|
||||
Source string
|
||||
User struct {
|
||||
Name string
|
||||
ScreenName string `json:"screen_name"`
|
||||
FollowersCount int `json:"followers_count"`
|
||||
ProfileImageUrl string `json:"profile_image_url"`
|
||||
}
|
||||
Place *struct {
|
||||
Id string
|
||||
FullName string `json:"full_name"`
|
||||
}
|
||||
Entities struct {
|
||||
HashTags []struct {
|
||||
Indices [2]int
|
||||
Text string
|
||||
}
|
||||
UserMentions []struct {
|
||||
Indices [2]int
|
||||
ScreenName string `json:"screen_name"`
|
||||
} `json:"user_mentions"`
|
||||
Urls []struct {
|
||||
Indices [2]int
|
||||
Url string
|
||||
DisplayUrl string `json:"display_url"`
|
||||
ExpandedUrl *string `json:"expanded_url"`
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func stream(client *oauth.Client, cred *oauth.Credentials, f func(*tweet)) {
|
||||
param := make(url.Values)
|
||||
uri := "https://userstream.twitter.com/1.1/user.json"
|
||||
client.SignParam(cred, "GET", uri, param)
|
||||
uri = uri + "?" + param.Encode()
|
||||
res, err := http.Get(uri)
|
||||
if err != nil {
|
||||
log.Fatal("failed to get tweets:", err)
|
||||
}
|
||||
defer res.Body.Close()
|
||||
if res.StatusCode != 200 {
|
||||
log.Fatal("failed to get tweets:", err)
|
||||
}
|
||||
var buf *bufio.Reader
|
||||
if res.Header.Get("Content-Encoding") == "gzip" {
|
||||
gr, err := gzip.NewReader(res.Body)
|
||||
if err != nil {
|
||||
log.Fatal("failed to make gzip decoder:", err)
|
||||
}
|
||||
buf = bufio.NewReader(gr)
|
||||
} else {
|
||||
buf = bufio.NewReader(res.Body)
|
||||
}
|
||||
var last []byte
|
||||
for alive {
|
||||
b, _, err := buf.ReadLine()
|
||||
last = append(last, b...)
|
||||
var t tweet
|
||||
err = json.Unmarshal(last, &t)
|
||||
if err != nil {
|
||||
continue
|
||||
}
|
||||
last = []byte{}
|
||||
if t.Text == "" {
|
||||
continue
|
||||
}
|
||||
f(&t)
|
||||
}
|
||||
}
|
||||
|
||||
func post(client *oauth.Client, cred *oauth.Credentials, s string) {
|
||||
param := make(url.Values)
|
||||
param.Set("status", s)
|
||||
uri := "https://api.twitter.com/1.1/statuses/update.json"
|
||||
client.SignParam(cred, "POST", uri, param)
|
||||
res, err := http.PostForm(uri, url.Values(param))
|
||||
if err != nil {
|
||||
log.Println("failed to post tweet:", err)
|
||||
return
|
||||
}
|
||||
defer res.Body.Close()
|
||||
if res.StatusCode != 200 {
|
||||
log.Println("failed to get timeline:", err)
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
func display(t *tweet, buffer *gtk.TextBuffer, tag *gtk.TextTag) {
|
||||
var iter gtk.TextIter
|
||||
pixbufbytes, resp := readURL(t.User.ProfileImageUrl)
|
||||
buffer.GetStartIter(&iter)
|
||||
if resp != nil {
|
||||
buffer.InsertPixbuf(&iter, bytes2pixbuf(pixbufbytes, resp.Header.Get("Content-Type")))
|
||||
}
|
||||
buffer.Insert(&iter, " ")
|
||||
buffer.InsertWithTag(&iter, t.User.ScreenName, tag)
|
||||
buffer.Insert(&iter, ":"+t.Text+"\n")
|
||||
gtk.MainIterationDo(false)
|
||||
}
|
||||
|
||||
func show(client *oauth.Client, cred *oauth.Credentials, f func(t *tweet)) {
|
||||
param := make(url.Values)
|
||||
uri := "https://api.twitter.com/1.1/statuses/home_timeline.json"
|
||||
client.SignParam(cred, "GET", uri, param)
|
||||
uri = uri + "?" + param.Encode()
|
||||
res, err := http.Get(uri)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
defer res.Body.Close()
|
||||
if res.StatusCode != 200 {
|
||||
return
|
||||
}
|
||||
var tweets []tweet
|
||||
json.NewDecoder(res.Body).Decode(&tweets)
|
||||
for _, t := range tweets {
|
||||
f(&t)
|
||||
}
|
||||
}
|
||||
|
||||
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()
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user