Example #1
0
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()
}
Example #2
0
File: gui.go Project: postfix/go-uv
func main() {
	gtk.Init(nil)
	window := gtk.Window(gtk.GTK_WINDOW_TOPLEVEL)
	window.SetTitle("Clock")
	vbox := gtk.VBox(false, 1)
	label := gtk.Label("")
	vbox.Add(label)
	window.Add(vbox)
	window.SetDefaultSize(300, 20)
	window.ShowAll()

	timer, _ := uv.TimerInit(nil)
	timer.Start(func(h *uv.Handle, status int) {
		label.SetLabel(fmt.Sprintf("%v", time.Now()))
	}, 1000, 1000)

	idle, _ := uv.IdleInit(nil)
	idle.Start(func(h *uv.Handle, status int) {
		gtk.MainIterationDo(false)
	})

	window.Connect("destroy", func() {
		timer.Close(nil)
		idle.Close(nil)
	})

	uv.DefaultLoop().Run()
}
func main() {
	gtk.Init(nil)
	window := gtk.Window(gtk.GTK_WINDOW_TOPLEVEL)
	window.SetTitle("Click me")
	label := gtk.Label("There have been no clicks yet")
	var clicks int
	button := gtk.ButtonWithLabel("click me")
	button.Clicked(func() {
		clicks++
		if clicks == 1 {
			label.SetLabel("Button clicked 1 time")
		} else {
			label.SetLabel(fmt.Sprintf("Button clicked %d times",
				clicks))
		}
	})
	vbox := gtk.VBox(false, 1)
	vbox.Add(label)
	vbox.Add(button)
	window.Add(vbox)
	window.Connect("destroy", func() {
		gtk.MainQuit()
	})
	window.ShowAll()
	gtk.Main()
}
Example #4
0
func main() {

	gtk.Init(&os.Args)
	window := gtk.Window(gtk.GTK_WINDOW_TOPLEVEL)

	window.Connect("delete-event", func() {
		println("Delete-event occured\n")
	})

	window.Connect("destroy", func() { gtk.MainQuit() })

	button := gtk.ButtonWithLabel("Hello, World")

	button.Clicked(func() {
		println("Hello, World\n")
	})

	button.Clicked(func() {
		gtk.MainQuit()
	})

	window.Add(button)
	window.ShowAll()
	gtk.Main()
}
Example #5
0
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()
}
Example #6
0
func main() {
	gtk.Init(&os.Args)
	window := gtk.Window(gtk.GTK_WINDOW_TOPLEVEL)
	window.SetTitle("GTK Notebook")
	window.Connect("destroy", gtk.MainQuit)

	notebook := gtk.Notebook()
	for n := 1; n <= 10; n++ {
		page := gtk.Frame("demo" + strconv.Itoa(n))
		notebook.AppendPage(page, gtk.Label("demo"+strconv.Itoa(n)))

		vbox := gtk.HBox(false, 1)

		prev := gtk.ButtonWithLabel("go prev")
		prev.Clicked(func() {
			notebook.PrevPage()
		})
		vbox.Add(prev)

		next := gtk.ButtonWithLabel("go next")
		next.Clicked(func() {
			notebook.NextPage()
		})
		vbox.Add(next)

		page.Add(vbox)
	}

	window.Add(notebook)
	window.SetSizeRequest(400, 200)
	window.ShowAll()

	gtk.Main()
}
Example #7
0
func showLogin() {
	window := gtk.Window(gtk.GTK_WINDOW_POPUP)
	window.Connect("destroy", gtk.MainQuit)
	window.SetSizeRequest()
	window.ShowAll()

	gtk.Main()
}
Example #8
0
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()
}
Example #9
0
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()
}
func main() {
	gtk.Init(nil)
	win := gtk.Window(gtk.GTK_WINDOW_TOPLEVEL)
	win.SetTitle("Goodbye, World!")
	win.SetSizeRequest(300, 200)
	win.Connect("destroy", gtk.MainQuit)
	button := gtk.ButtonWithLabel("Goodbye, World!")
	win.Add(button)
	button.Connect("clicked", gtk.MainQuit)
	win.ShowAll()
	gtk.Main()
}
Example #11
0
func main() {
	gtk.Init(&os.Args)
	window := gtk.Window(gtk.GTK_WINDOW_TOPLEVEL)
	window.SetTitle("GTK DrawingArea")
	window.Connect("destroy", gtk.MainQuit)

	vbox := gtk.VBox(true, 0)
	vbox.SetBorderWidth(5)

	targets := []gtk.GtkTargetEntry{
		{"text/uri-list", 0, 0},
		{"STRING", 0, 1},
		{"text/plain", 0, 2},
	}
	dest := gtk.Label("drop me file")
	dest.DragDestSet(
		gtk.GTK_DEST_DEFAULT_MOTION|
			gtk.GTK_DEST_DEFAULT_HIGHLIGHT|
			gtk.GTK_DEST_DEFAULT_DROP,
		targets,
		gdk.GDK_ACTION_COPY)
	dest.DragDestAddUriTargets()
	dest.Connect("drag-data-received", func(ctx *glib.CallbackContext) {
		sdata := gtk.SelectionDataFromNative(unsafe.Pointer(ctx.Args(3)))
		if sdata != nil {
			a := (*[2000]uint8)(sdata.GetData())
			files := strings.Split(string(a[0:sdata.GetLength()-1]), "\n")
			for i := range files {
				filename, _, _ := glib.FilenameFromUri(files[i])
				files[i] = filename
			}
			dialog := gtk.MessageDialog(
				window,
				gtk.GTK_DIALOG_MODAL,
				gtk.GTK_MESSAGE_INFO,
				gtk.GTK_BUTTONS_OK,
				strings.Join(files, "\n"))
			dialog.SetTitle("D&D")
			dialog.Response(func() {
				dialog.Destroy()
			})
			dialog.Run()
		}
	})
	vbox.Add(dest)

	window.Add(vbox)

	window.SetSizeRequest(300, 100)
	window.ShowAll()
	gtk.Main()
}
Example #12
0
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()
}
Example #13
0
func main() {
	gtk.Init(nil)
	window := gtk.Window(gtk.GTK_WINDOW_TOPLEVEL)
	window.SetPosition(gtk.GTK_WIN_POS_CENTER)
	window.SetTitle("GTK Go!")
	window.Connect("destroy", func(ctx *glib.CallbackContext) {
		println("got destroy!", ctx.Data().(string))
		gtk.MainQuit()
	}, "foo")

	//--------------------------------------------------------
	// GtkHBox
	//--------------------------------------------------------
	box := gtk.VBox(false, 1)

	//--------------------------------------------------------
	// GtkSpinButton
	//--------------------------------------------------------
	spinbutton1 := gtk.SpinButtonWithRange(1.0, 10.0, 1.0)
	spinbutton1.SetDigits(3)
	spinbutton1.Spin(gtk.GTK_SPIN_STEP_FORWARD, 7.0)
	box.Add(spinbutton1)

	spinbutton1.ValueChanged(func() {
		val := spinbutton1.GetValueAsInt()
		fval := spinbutton1.GetValue()
		println("SpinButton changed, new value: " + strconv.Itoa(val) + " | " + strconv.FormatFloat(fval, 'f', 2, 64))
		min, max := spinbutton1.GetRange()
		println("Range: " + strconv.FormatFloat(min, 'f', 2, 64) + " " + strconv.FormatFloat(max, 'f', 2, 64))
		println("Digits: " + strconv.Itoa(int(spinbutton1.GetDigits())))
	})

	adjustment := gtk.Adjustment(2.0, 1.0, 8.0, 2.0, 0.0, 0.0)
	spinbutton2 := gtk.SpinButton(adjustment, 1.0, 1)
	spinbutton2.SetRange(0.0, 20.0)
	spinbutton2.SetValue(18.0)
	spinbutton2.SetIncrements(2.0, 4.0)
	box.Add(spinbutton2)

	//--------------------------------------------------------
	// Event
	//--------------------------------------------------------
	window.Add(box)
	window.SetSizeRequest(600, 600)
	window.ShowAll()
	gtk.Main()
}
Example #14
0
func main() {
	gtk.Init(&os.Args)
	window := gtk.Window(gtk.GTK_WINDOW_TOPLEVEL)
	window.SetTitle("We love Expander")
	window.Connect("destroy", gtk.MainQuit)

	vbox := gtk.VBox(true, 0)
	vbox.SetBorderWidth(5)
	expander := gtk.Expander("dan the ...")
	expander.Add(gtk.Label("404 contents not found"))
	vbox.PackStart(expander, false, false, 0)

	window.Add(vbox)
	window.ShowAll()

	gtk.Main()
}
Example #15
0
func main() {
	runtime.GOMAXPROCS(10)
	glib.ThreadInit(nil)
	gdk.ThreadsInit()
	gdk.ThreadsEnter()
	gtk.Init(nil)
	window := gtk.Window(gtk.GTK_WINDOW_TOPLEVEL)
	window.Connect("destroy", gtk.MainQuit)

	vbox := gtk.VBox(false, 1)

	label1 := gtk.Label("")
	vbox.Add(label1)
	label2 := gtk.Label("")
	vbox.Add(label2)

	window.Add(vbox)

	window.SetSizeRequest(100, 100)
	window.ShowAll()
	time.Sleep(1000 * 1000 * 100)
	go (func() {
		for i := 0; i < 300000; i++ {
			gdk.ThreadsEnter()
			label1.SetLabel(strconv.Itoa(i))
			gdk.ThreadsLeave()
		}
		gtk.MainQuit()
	})()
	go (func() {
		for i := 300000; i >= 0; i-- {
			gdk.ThreadsEnter()
			label2.SetLabel(strconv.Itoa(i))
			gdk.ThreadsLeave()
		}
		gtk.MainQuit()
	})()
	gtk.Main()
}
Example #16
0
func main() {
	gtk.Init(&os.Args)
	window := gtk.Window(gtk.GTK_WINDOW_TOPLEVEL)
	window.SetTitle("GTK Events")
	window.Connect("destroy", gtk.MainQuit)

	window.Connect("key-press-event", func(ctx *glib.CallbackContext) {
		arg := ctx.Args(0)
		kev := *(**gdk.EventKey)(unsafe.Pointer(&arg))
		println("key-press-event:", kev.Keyval)
	})
	window.Connect("motion-notify-event", func(ctx *glib.CallbackContext) {
		arg := ctx.Args(0)
		mev := *(**gdk.EventMotion)(unsafe.Pointer(&arg))
		println("motion-notify-event:", int(mev.X), int(mev.Y))
	})

	window.SetEvents(int(gdk.GDK_POINTER_MOTION_MASK | gdk.GDK_POINTER_MOTION_HINT_MASK | gdk.GDK_BUTTON_PRESS_MASK))
	window.SetSizeRequest(400, 400)
	window.ShowAll()

	gtk.Main()
}
Example #17
0
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()
}
Example #18
0
func main() {
	gtk.Init(&os.Args)
	window := gtk.Window(gtk.GTK_WINDOW_TOPLEVEL)
	window.SetTitle("Alignment")
	window.Connect("destroy", gtk.MainQuit)

	notebook := gtk.Notebook()
	window.Add(notebook)

	align := gtk.Alignment(0.5, 0.5, 0.5, 0.5)
	notebook.AppendPage(align, gtk.Label("Alignment"))

	button := gtk.ButtonWithLabel("Hello World!")
	align.Add(button)

	fixed := gtk.Fixed()
	notebook.AppendPage(fixed, gtk.Label("Fixed"))

	button2 := gtk.ButtonWithLabel("Pulse")
	fixed.Put(button2, 30, 30)

	progress := gtk.ProgressBar()
	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()
}
Example #19
0
File: demo.go Project: leif/go-gtk
func main() {
	var menuitem *gtk.GtkMenuItem
	gtk.Init(nil)
	window := gtk.Window(gtk.GTK_WINDOW_TOPLEVEL)
	window.SetPosition(gtk.GTK_WIN_POS_CENTER)
	window.SetTitle("GTK Go!")
	window.Connect("destroy", func(ctx *glib.CallbackContext) {
		println("got destroy!", ctx.Data().(string))
		gtk.MainQuit()
	}, "foo")

	//--------------------------------------------------------
	// GtkVBox
	//--------------------------------------------------------
	vbox := gtk.VBox(false, 1)

	//--------------------------------------------------------
	// GtkMenuBar
	//--------------------------------------------------------
	menubar := gtk.MenuBar()
	vbox.PackStart(menubar, false, false, 0)

	//--------------------------------------------------------
	// GtkVPaned
	//--------------------------------------------------------
	vpaned := gtk.VPaned()
	vbox.Add(vpaned)

	//--------------------------------------------------------
	// GtkFrame
	//--------------------------------------------------------
	frame1 := gtk.Frame("Demo")
	framebox1 := gtk.VBox(false, 1)
	frame1.Add(framebox1)

	frame2 := gtk.Frame("Demo")
	framebox2 := gtk.VBox(false, 1)
	frame2.Add(framebox2)

	vpaned.Pack1(frame1, false, false)
	vpaned.Pack2(frame2, false, false)

	//--------------------------------------------------------
	// GtkImage
	//--------------------------------------------------------
	dir, _ := path.Split(os.Args[0])
	imagefile := path.Join(dir, "../../data/go-gtk-logo.png")

	label := gtk.Label("Go Binding for GTK")
	label.ModifyFontEasy("DejaVu Serif 15")
	framebox1.PackStart(label, false, true, 0)

	//--------------------------------------------------------
	// GtkEntry
	//--------------------------------------------------------
	entry := gtk.Entry()
	entry.SetText("Hello world")
	framebox1.Add(entry)

	image := gtk.ImageFromFile(imagefile)
	framebox1.Add(image)

	//--------------------------------------------------------
	// GtkScale
	//--------------------------------------------------------
	scale := gtk.HScaleWithRange(0, 100, 1)
	scale.Connect("value-changed", func() {
		println("scale:", int(scale.GetValue()))
	})
	framebox2.Add(scale)

	//--------------------------------------------------------
	// GtkHBox
	//--------------------------------------------------------
	buttons := gtk.HBox(false, 1)

	//--------------------------------------------------------
	// GtkButton
	//--------------------------------------------------------
	button := gtk.ButtonWithLabel("Button with label")
	button.Clicked(func() {
		println("button clicked:", button.GetLabel())
		messagedialog := gtk.MessageDialog(
			button.GetTopLevelAsWindow(),
			gtk.GTK_DIALOG_MODAL,
			gtk.GTK_MESSAGE_INFO,
			gtk.GTK_BUTTONS_OK,
			entry.GetText())
		messagedialog.Response(func() {
			println("Dialog OK!")

			//--------------------------------------------------------
			// GtkFileChooserDialog
			//--------------------------------------------------------
			filechooserdialog := gtk.FileChooserDialog(
				"Choose File...",
				button.GetTopLevelAsWindow(),
				gtk.GTK_FILE_CHOOSER_ACTION_OPEN,
				gtk.GTK_STOCK_OK,
				int(gtk.GTK_RESPONSE_ACCEPT))
			filter := gtk.FileFilter()
			filter.AddPattern("*.go")
			filechooserdialog.AddFilter(filter)
			filechooserdialog.Response(func() {
				println(filechooserdialog.GetFilename())
				filechooserdialog.Destroy()
			})
			filechooserdialog.Run()
			messagedialog.Destroy()
		})
		messagedialog.Run()
	})
	buttons.Add(button)

	//--------------------------------------------------------
	// GtkFontButton
	//--------------------------------------------------------
	fontbutton := gtk.FontButton()
	fontbutton.Connect("font-set", func() {
		println("title:", fontbutton.GetTitle())
		println("fontname:", fontbutton.GetFontName())
		println("use_size:", fontbutton.GetUseSize())
		println("show_size:", fontbutton.GetShowSize())
	})
	buttons.Add(fontbutton)
	framebox2.PackStart(buttons, false, false, 0)

	buttons = gtk.HBox(false, 1)

	//--------------------------------------------------------
	// GtkToggleButton
	//--------------------------------------------------------
	togglebutton := gtk.ToggleButtonWithLabel("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.CheckButtonWithLabel("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.VBox(false, 1)
	radiofirst := gtk.RadioButtonWithLabel(nil, "Radio1")
	buttonbox.Add(radiofirst)
	buttonbox.Add(gtk.RadioButtonWithLabel(radiofirst.GetGroup(), "Radio2"))
	buttonbox.Add(gtk.RadioButtonWithLabel(radiofirst.GetGroup(), "Radio3"))
	buttons.Add(buttonbox)
	//radiobutton.SetMode(false);
	radiofirst.SetActive(true)

	framebox2.PackStart(buttons, false, false, 0)

	//--------------------------------------------------------
	// GtkVSeparator
	//--------------------------------------------------------
	vsep := gtk.VSeparator()
	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()
	})
	submenu.Append(menuitem)

	cascademenu = gtk.MenuItemWithMnemonic("_View")
	menubar.Append(cascademenu)
	submenu = gtk.Menu()
	cascademenu.SetSubmenu(submenu)

	checkmenuitem := gtk.CheckMenuItemWithMnemonic("_Disable")
	checkmenuitem.Connect("activate", func() {
		vpaned.SetSensitive(!checkmenuitem.GetActive())
	})
	submenu.Append(checkmenuitem)

	menuitem = gtk.MenuItemWithMnemonic("_Font")
	menuitem.Connect("activate", func() {
		fsd := gtk.FontSelectionDialog("Font")
		fsd.SetFontName(fontbutton.GetFontName())
		fsd.Response(func() {
			println(fsd.GetFontName())
			fontbutton.SetFontName(fsd.GetFontName())
			fsd.Destroy()
		})
		fsd.SetTransientFor(window)
		fsd.Run()
	})
	submenu.Append(menuitem)

	cascademenu = gtk.MenuItemWithMnemonic("_Help")
	menubar.Append(cascademenu)
	submenu = gtk.Menu()
	cascademenu.SetSubmenu(submenu)

	menuitem = gtk.MenuItemWithMnemonic("_About")
	menuitem.Connect("activate", func() {
		dialog := gtk.AboutDialog()
		dialog.SetName("Go-Gtk Demo!")
		dialog.SetProgramName("demo")
		dialog.SetAuthors([]string{
			"Yasuhiro Matsumoto <*****@*****.**>",
			"David Roundy <*****@*****.**>",
			"Mark Andrew Gerads",
			"Tobias Kortkamp",
			"Mikhail Trushnikov",
			"Federico Sogaro <*****@*****.**>"})
		dir, _ := path.Split(os.Args[0])
		imagefile := path.Join(dir, "../../data/mattn-logo.png")
		pixbuf, _ := gdkpixbuf.PixbufFromFile(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.Statusbar()
	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()
}
Example #20
0
func AuthWindow() *GhAuthWindow {
	authWindow := &GhAuthWindow{gtk.Window(gtk.GTK_WINDOW_TOPLEVEL)}
	authWindow.build()
	return authWindow
}
Example #21
0
func SyncWindow() *GhSyncWindow {
	syncWindow := &GhSyncWindow{gtk.Window(gtk.GTK_WINDOW_POPUP), true}
	syncWindow.build()
	return syncWindow
}
Example #22
0
func main() {
	gtk.Init(&os.Args)
	window := gtk.Window(gtk.GTK_WINDOW_TOPLEVEL)
	window.SetTitle("GTK DrawingArea")
	window.Connect("destroy", gtk.MainQuit)

	vbox := gtk.VBox(true, 0)
	vbox.SetBorderWidth(5)
	drawingarea := gtk.DrawingArea()

	var p1, p2 point
	var gdkwin *gdk.GdkWindow
	var pixmap *gdk.GdkPixmap
	var gc *gdk.GdkGC
	p1.x = -1
	p1.y = -1

	drawingarea.Connect("configure-event", func() {
		if pixmap != nil {
			pixmap.Unref()
		}
		var allocation gtk.GtkAllocation
		drawingarea.GetAllocation(&allocation)
		pixmap = gdk.Pixmap(drawingarea.GetWindow().GetDrawable(), allocation.Width, allocation.Height, 24)
		gc = gdk.GC(pixmap.GetDrawable())
		gc.SetRgbFgColor(gdk.Color("white"))
		pixmap.GetDrawable().DrawRectangle(gc, true, 0, 0, -1, -1)
		gc.SetRgbFgColor(gdk.Color("black"))
		gc.SetRgbBgColor(gdk.Color("white"))
	})

	drawingarea.Connect("motion-notify-event", func(ctx *glib.CallbackContext) {
		if gdkwin == nil {
			gdkwin = drawingarea.GetWindow()
		}
		arg := ctx.Args(0)
		mev := *(**gdk.EventMotion)(unsafe.Pointer(&arg))
		var mt gdk.GdkModifierType
		if mev.IsHint != 0 {
			gdkwin.GetPointer(&p2.x, &p2.y, &mt)
		} else {
			p2.x, p2.y = int(mev.X), int(mev.Y)
		}
		if p1.x != -1 && p2.x != -1 && (gdk.GdkEventMask(mt)&gdk.GDK_BUTTON_PRESS_MASK) != 0 {
			pixmap.GetDrawable().DrawLine(gc, p1.x, p1.y, p2.x, p2.y)
			drawingarea.GetWindow().Invalidate(nil, false)
		}
		p1 = p2
	})

	drawingarea.Connect("expose-event", func() {
		if pixmap != nil {
			drawingarea.GetWindow().GetDrawable().DrawDrawable(gc, pixmap.GetDrawable(), 0, 0, 0, 0, -1, -1)
		}
	})

	drawingarea.SetEvents(int(gdk.GDK_POINTER_MOTION_MASK | gdk.GDK_POINTER_MOTION_HINT_MASK | gdk.GDK_BUTTON_PRESS_MASK))
	vbox.Add(drawingarea)

	window.Add(vbox)
	window.SetSizeRequest(400, 400)
	window.ShowAll()

	gtk.Main()
}
Example #23
0
func main() {
	var prueba int

	var Actual Juego

	Actual.Init()

	var heuristica int

	heuristica = 1

	var r1 [4]int
	var r2 [8]int

	Actual.fila1 = Actual.fila1Objetivo
	Actual.fila2 = Actual.fila2Objetivo

	r1 = Actual.fila1Objetivo
	r2 = Actual.fila2Objetivo

	//fmt.Println(r1,r2)

	prueba = 100
	//var menuitem *gtk.GtkMenuItem
	gtk.Init(nil)
	window := gtk.Window(gtk.GTK_WINDOW_TOPLEVEL)
	window.SetPosition(gtk.GTK_WIN_POS_CENTER)
	window.SetTitle(" A star")
	window.Connect("destroy", func(ctx *glib.CallbackContext) {
		println("got destory!\n", ctx.Data().(string))
		gtk.MainQuit()
	}, "foo")

	vbox := gtk.HBox(false, 14)

	//menubar:=gtk.MenuBar()
	//vbox.PackStart(menubar,false,false,0)

	vpaned := gtk.VPaned()
	vbox.Add(vpaned)

	frame := gtk.Frame("Profundiad")
	framebox := gtk.HBox(false, 14)

	framebox1 := gtk.VBox(true, 0)
	frame1 := gtk.Frame("Rompecabezas ")

	frame.Add(framebox)
	frame1.Add(framebox1)

	drawingarea := gtk.DrawingArea()

	vpaned.Add(frame)
	vpaned.Add(frame1)

	button := gtk.ButtonWithLabel("Resolver")
	button2 := gtk.ButtonWithLabel("Desordenar")
	button3 := gtk.ButtonWithLabel(" Nivel de Desorden")

	//TxtPasos:=gtk.Entry()

	frameHu := gtk.VBox(true, 2)

	lheuristica := gtk.Label("Heuristica")
	comboBox := gtk.ComboBoxEntryNewText()
	comboBox.AppendText("Piezas Desordenadas")
	comboBox.AppendText("Distancia entre Piezas")

	comboBox.Connect("changed", func() {
		if strings.EqualFold(comboBox.GetActiveText(), "Piezas Desordenadas") {
			heuristica = 2
		} else {
			heuristica = 1
		}
	})

	frameHu.Add(lheuristica)
	frameHu.Add(comboBox)

	entry := gtk.Entry()

	framebox.Add(entry)

	framebox.Add(button)
	framebox.Add(frameHu)

	framebox.Add(button2)
	framebox.Add(button3)

	//framebox1.Add(TxtPasos)
	//var gdkwin *gdk.GdkWindow
	var pixmap *gdk.GdkPixmap
	var gc *gdk.GdkGC

	drawingarea.Connect("configure-event", func() {
		if pixmap != nil {
			pixmap.Unref()
		}
		var allocation gtk.GtkAllocation
		drawingarea.GetAllocation(&allocation)
		pixmap = gdk.Pixmap(drawingarea.GetWindow().GetDrawable(), allocation.Width, allocation.Height, 24)
		gc = gdk.GC(pixmap.GetDrawable())
		gc.SetRgbFgColor(gdk.Color("white"))
		pixmap.GetDrawable().DrawRectangle(gc, true, 0, 0, -1, -1)
		gc.SetRgbFgColor(gdk.Color("blue"))
		gc.SetRgbBgColor(gdk.Color("white"))
		pixmap.GetDrawable().DrawArc(gc, false, 100, 100, 200, 200, 0, 30000)
		pixmap.GetDrawable().DrawArc(gc, false, 150, 150, 100, 100, 0, 30000)

		pixmap.GetDrawable().DrawLine(gc, 200, 100, 200, 300)
		pixmap.GetDrawable().DrawLine(gc, 100, 200, 300, 200)

		pixmap.GetDrawable().DrawLine(gc, 130, 130, 165, 165)
		pixmap.GetDrawable().DrawLine(gc, 235, 235, 270, 270)

		pixmap.GetDrawable().DrawLine(gc, 271, 129, 235, 165)
		pixmap.GetDrawable().DrawLine(gc, 165, 235, 129, 271)

		pixmap.GetDrawable().DrawString(gdk.FontsetLoad("-adobe-helvetica-bold-r-normal--12-120-75-75-p-70-iso8859-1"), gc, 200, 200, strconv.Itoa(prueba))

		pixmap.GetDrawable().DrawString(gdk.FontsetLoad("-adobe-helvetica-bold-r-normal--12-120-75-75-p-70-iso8859-1"), gc, 100, 200, strconv.Itoa(prueba))

		pixmap.GetDrawable().DrawString(gdk.FontsetLoad("-adobe-helvetica-bold-r-normal--12-120-75-75-p-70-iso8859-1"), gc, 100, 300, strconv.Itoa(prueba))
		pixmap.GetDrawable().DrawString(gdk.FontsetLoad("-adobe-helvetica-bold-r-normal--12-120-75-75-p-70-iso8859-1"), gc, 200, 300, strconv.Itoa(prueba))

	})

	drawingarea.Connect("expose-event", func() {
		if pixmap != nil {
			drawingarea.GetWindow().GetDrawable().DrawDrawable(gc, pixmap.GetDrawable(), 0, 0, 0, 0, -1, -1)
			gc.SetRgbFgColor(gdk.Color("white"))
			pixmap.GetDrawable().DrawRectangle(gc, true, 0, 0, -1, -1)
			gc.SetRgbFgColor(gdk.Color("blue"))
			gc.SetRgbBgColor(gdk.Color("white"))
			pixmap.GetDrawable().DrawArc(gc, false, 100, 100, 200, 200, 0, 30000)
			pixmap.GetDrawable().DrawArc(gc, false, 150, 150, 100, 100, 0, 30000)

			pixmap.GetDrawable().DrawLine(gc, 200, 100, 200, 300)
			pixmap.GetDrawable().DrawLine(gc, 100, 200, 300, 200)

			pixmap.GetDrawable().DrawLine(gc, 130, 130, 165, 165)
			pixmap.GetDrawable().DrawLine(gc, 235, 235, 270, 270)

			pixmap.GetDrawable().DrawLine(gc, 271, 129, 235, 165)
			pixmap.GetDrawable().DrawLine(gc, 165, 235, 129, 271)

			pixmap.GetDrawable().DrawString(gdk.FontsetLoad("-adobe-helvetica-bold-r-normal--12-120-75-75-p-70-iso8859-1"), gc, 210, 190, strconv.Itoa(r1[0]))
			pixmap.GetDrawable().DrawString(gdk.FontsetLoad("-adobe-helvetica-bold-r-normal--12-120-75-75-p-70-iso8859-1"), gc, 210, 140, strconv.Itoa(r2[0]))
			pixmap.GetDrawable().DrawString(gdk.FontsetLoad("-adobe-helvetica-bold-r-normal--12-120-75-75-p-70-iso8859-1"), gc, 260, 190, strconv.Itoa(r2[1]))

			pixmap.GetDrawable().DrawString(gdk.FontsetLoad("-adobe-helvetica-bold-r-normal--12-120-75-75-p-70-iso8859-1"), gc, 210, 230, strconv.Itoa(r1[1]))
			pixmap.GetDrawable().DrawString(gdk.FontsetLoad("-adobe-helvetica-bold-r-normal--12-120-75-75-p-70-iso8859-1"), gc, 260, 230, strconv.Itoa(r2[2]))
			pixmap.GetDrawable().DrawString(gdk.FontsetLoad("-adobe-helvetica-bold-r-normal--12-120-75-75-p-70-iso8859-1"), gc, 210, 280, strconv.Itoa(r2[3]))

			pixmap.GetDrawable().DrawString(gdk.FontsetLoad("-adobe-helvetica-bold-r-normal--12-120-75-75-p-70-iso8859-1"), gc, 170, 230, strconv.Itoa(r1[2]))
			pixmap.GetDrawable().DrawString(gdk.FontsetLoad("-adobe-helvetica-bold-r-normal--12-120-75-75-p-70-iso8859-1"), gc, 170, 280, strconv.Itoa(r2[4]))
			pixmap.GetDrawable().DrawString(gdk.FontsetLoad("-adobe-helvetica-bold-r-normal--12-120-75-75-p-70-iso8859-1"), gc, 120, 230, strconv.Itoa(r2[5]))

			pixmap.GetDrawable().DrawString(gdk.FontsetLoad("-adobe-helvetica-bold-r-normal--12-120-75-75-p-70-iso8859-1"), gc, 170, 190, strconv.Itoa(r1[3]))
			pixmap.GetDrawable().DrawString(gdk.FontsetLoad("-adobe-helvetica-bold-r-normal--12-120-75-75-p-70-iso8859-1"), gc, 120, 190, strconv.Itoa(r2[6]))
			pixmap.GetDrawable().DrawString(gdk.FontsetLoad("-adobe-helvetica-bold-r-normal--12-120-75-75-p-70-iso8859-1"), gc, 170, 140, strconv.Itoa(r2[7]))

			drawingarea.GetWindow().Invalidate(nil, false)
		}
	})

	button.Clicked(func() {
		//prueba=prueba+1
		vdeep := entry.GetText()

		fo, err := os.Create("Pasos")
		if err != nil {
			panic(err)
		}
		defer fo.Close()

		Actual.tipoHeuristica = heuristica
		Actual.HeuristicaJuego()

		deep, err := strconv.Atoi(vdeep)
		if err == nil {
			fmt.Println("", deep)
			b, camino := AStar(Actual, deep)
			if b {

				for i := 0; i < len(camino); i++ {

					r1 = camino[i].fila1
					r2 = camino[i].fila2

					var Valores string
					Valores = "["

					for j := 0; j < len(r1); j++ {
						Valores = Valores + " " + strconv.Itoa(r1[j])
					}
					Valores = Valores + "]["

					for j := 0; j < len(r2); j++ {
						Valores = Valores + " " + strconv.Itoa(r2[j])
					}
					Valores = Valores + "] " + strconv.Itoa(camino[i].heuristica) + "\n"

					if _, err := fo.WriteString(Valores); err != nil {
						panic(err)
					}

				}

			} else {
				fmt.Println("No encontro la soluciĆ³n")
			}
		}
	})

	button2.Clicked(func() {

		Actual.Init()
		Actual.tipoHeuristica = heuristica
		Actual.HeuristicaJuego()

		r1 = Actual.fila1
		r2 = Actual.fila2

		//prueba=prueba+1
		//fmt.Println("->",prueba)
	})

	button3.Clicked(func() {

		Actual.fila1 = r1
		Actual.fila2 = r2

		Actual.Init2()
		Actual.tipoHeuristica = heuristica
		Actual.HeuristicaJuego()

		r1 = Actual.fila1
		r2 = Actual.fila2
	})

	drawingarea.SetEvents(int(gdk.GDK_POINTER_MOTION_MASK | gdk.GDK_POINTER_MOTION_HINT_MASK | gdk.GDK_BUTTON_PRESS_MASK))
	framebox1.Add(drawingarea)

	window.Add(vbox)
	window.SetSizeRequest(600, 600)
	window.ShowAll()
	gtk.Main()
}
Example #24
0
func MainWindow() *GhMainWindow {
	mainWindow := &GhMainWindow{gtk.Window(gtk.GTK_WINDOW_TOPLEVEL), nil}
	mainWindow.build()
	return mainWindow
}
Example #25
0
func Init(size uint) {
	var (
		files          *gtk.GtkHBox
		examples_cnt   int
		newfile_flag   bool
		cs_desc_normal *_Ctype_char
		cs_desc_bold   *_Ctype_char
	)

	s = new(solver.Solver)
	s.Size = size

	if s.Size == 9 {
		cs_desc_normal = C.CString("Sans 14")
		cs_desc_bold = C.CString("Sans Bold 14")
	} else {
		cs_desc_normal = C.CString("Sans 16")
		cs_desc_bold = C.CString("Sans Bold 16")
	}
	desc_normal = C.pango_font_description_from_string(cs_desc_normal)
	desc_bold = C.pango_font_description_from_string(cs_desc_bold)
	C.free_string(cs_desc_normal)
	C.free_string(cs_desc_bold)

	gtk.Init(&os.Args)

	window := gtk.Window(gtk.GTK_WINDOW_TOPLEVEL)
	window.SetResizable(false)
	window.SetTitle("Sudoku solver")
	window.Connect("destroy", func() {
		gtk.MainQuit()
	})
	window.Connect("key-press-event", func(ctx *glib.CallbackContext) {
		arg := ctx.Args(0)
		kev := *(**gdk.EventKey)(unsafe.Pointer(&arg))
		r, st := rune(kev.Keyval), gdk.GdkModifierType(kev.State)
		if st&gdk.GDK_CONTROL_MASK != 0 {
			if r == 122 || r == 90 { // Ctrl-Z
				m := cs_pop()
				clear()
				for i := uint(0); i < s.Size; i++ {
					for j := uint(0); j < s.Size; j++ {
						v := int(m[i][j])
						if v != 0 {
							entries[i][j].SetText(strconv.Itoa(v))
						}
					}
				}
			}
		}
	})

	vbox := gtk.VBox(false, 10)

	table := gtk.Table(3, s.Size/3, false)
	bg := [2]*gdk.GdkColor{gdk.Color("white"), gdk.Color("#e9f2ea")}
	for y := uint(0); y < 3; y++ {
		for x := uint(0); x < s.Size/3; x++ {
			subtable := gtk.Table(s.Size/3, 3, false)
			for sy := uint(0); sy < s.Size/3; sy++ {
				for sx := uint(0); sx < 3; sx++ {
					w := gtk.Entry()
					w.SetWidthChars(1)
					w.SetMaxLength(1)
					if s.Size == 9 {
						w.SetSizeRequest(23, 25)
					} else {
						w.SetSizeRequest(25, 27)
					}
					w.Connect("key-press-event", func(ctx *glib.CallbackContext) bool {
						data := ctx.Data().([]uint)
						y, x := data[0], data[1]
						arg := ctx.Args(0)
						kev := *(**gdk.EventKey)(unsafe.Pointer(&arg))
						r := rune(kev.Keyval)
						switch r & 0xFF {
						case 81:
							if x != 0 || y != 0 {
								if x == 0 {
									x = s.Size - 1
									y--
								} else {
									x--
								}
							}
						case 82:
							if y != 0 {
								y--
							}
						case 83:
							if x != s.Size-1 || y != s.Size-1 {
								if x == s.Size-1 {
									x = 0
									y++
								} else {
									x++
								}
							}
						case 84:
							if y != s.Size-1 {
								y++
							}
						}
						if y != data[0] || x != data[1] {
							entries[y][x].GrabFocus()
						}
						if unicode.IsOneOf([]*unicode.RangeTable{unicode.L, unicode.Z}, r) {
							return true
						}
						return false
					}, []uint{(s.Size/3)*y + sy, 3*x + sx})
					w.Connect("grab-focus", func(ctx *glib.CallbackContext) {
						data := ctx.Data().([]uint)
						y, x := data[0], data[1]
						for k := 0; k < 2; k++ {
							for i := uint(0); i < s.Size; i++ {
								modify_base(unsafe.Pointer(entries[i][prev_x].Widget), bg[k])
							}
							for j := uint(0); j < s.Size; j++ {
								modify_base(unsafe.Pointer(entries[prev_y][j].Widget), bg[k])
							}
							prev_y, prev_x = y, x
						}
					}, []uint{(s.Size/3)*y + sy, 3*x + sx})
					subtable.Attach(w, sx, sx+1, sy, sy+1, gtk.GTK_FILL, gtk.GTK_FILL, 0, 0)
					entries[(s.Size/3)*y+sy][3*x+sx] = w
					modify_font((s.Size/3)*y+sy, 3*x+sx, desc_bold)
				}
			}
			table.Attach(subtable, x, x+1, y, y+1, gtk.GTK_FILL, gtk.GTK_FILL, 3, 3)
		}
	}

	solve_btn := gtk.ButtonWithLabel("Solve")
	solve_btn.Clicked(func() {
		var m1, m2 [9][9]uint

		for i := uint(0); i < s.Size; i++ {
			for j := uint(0); j < s.Size; j++ {
				v, _ := strconv.Atoi(entries[i][j].GetText())
				m1[i][j] = uint(v)
			}
		}
		if !check_field(&m1) {
			return
		}
		cs_push(m1)
		s.Load(m1)
		s.Solve()
		if s.Finals != s.Size*s.Size {
			// let's try some tough algorithms :)
			s.ToughSolve()
		}
		for i := uint(0); i < s.Size; i++ {
			for j := uint(0); j < s.Size; j++ {
				v := int(s.Get(i, j))
				m2[i][j] = uint(v)
				if v != 0 {
					entries[i][j].SetText(strconv.Itoa(v))
				} else {
					var c_string [9]string
					// get list of candidates
					c_uint, l := s.GetCandidates(i, j)
					for k := uint(0); k < l; k++ {
						c_string[k] = strconv.Itoa(int(c_uint[k]))
					}
					// make a tooltip with them
					entries[i][j].SetTooltipText(strings.Join(c_string[:l], " "))
				}
			}
		}
		// check for differences
		for i := uint(0); i < s.Size; i++ {
			for j := uint(0); j < s.Size; j++ {
				if m1[i][j] == m2[i][j] {
					modify_font(i, j, desc_bold)
				} else {
					modify_font(i, j, desc_normal)
				}
			}
		}
	})
	clear_btn := gtk.ButtonWithLabel("Clear")
	clear_btn.Clicked(func() {
		m := [9][9]uint{}
		for i := uint(0); i < s.Size; i++ {
			for j := uint(0); j < s.Size; j++ {
				m[i][j] = s.Get(i, j)
			}
		}
		cs_push(m)
		clear()
	})

	examples = gtk.ComboBoxText()
	// scan `examples` folder
	sz := strconv.Itoa(int(s.Size))
	dir, err := os.Open("examples/" + sz + "x" + sz)
	if err == nil {
		names, err := dir.Readdirnames(0)
		if err == nil {
			for _, v := range names {
				examples.AppendText(v)
				examples_cnt++
			}
		}
		dir.Close()
	}
	examples.Connect("changed", func() {
		sz := strconv.Itoa(int(s.Size))
		load_sudoku("examples/" + sz + "x" + sz + "/" + examples.GetActiveText())
	})

	newfile := gtk.Entry()
	newfile.Connect("activate", func() {
		filename := newfile.GetText()
		if filename != "" {
			sz := strconv.Itoa(int(s.Size))
			f, err := os.Create("examples/" + sz + "x" + sz + "/" + filename)
			if err == nil {
				for i := uint(0); i < s.Size; i++ {
					for j := uint(0); j < s.Size; j++ {
						v := []byte(entries[i][j].GetText())
						if len(v) == 0 || v[0] < 49 || v[0] > byte(48+s.Size) {
							v = []byte{' '}
						}
						f.Write(v)
						if (j+1)%3 == 0 && j+1 != s.Size {
							f.WriteString("*")
						}
					}
					f.WriteString("\n")
					if (i+1)%(s.Size/3) == 0 && i+1 != s.Size {
						if s.Size == 9 {
							f.WriteString("***********\n")
						} else {
							f.WriteString("*******\n")
						}
					}
				}
				f.Close()
			}
			examples.AppendText(filename)
			examples.SetActive(examples_cnt)
			examples_cnt++
		}
		files.ShowAll()
		newfile.SetText("")
		newfile.Hide()
	})

	icon := gtk.Image()
	icon.SetFromStock(gtk.GTK_STOCK_SAVE_AS, gtk.GTK_ICON_SIZE_BUTTON)
	export := gtk.Button()
	export.SetImage(icon)
	export.Clicked(func() {
		if !newfile_flag {
			files.Add(newfile)
			newfile_flag = true
		}
		files.ShowAll()
		examples.Hide()
		export.Hide()
		newfile.GrabFocus()
	})

	files = gtk.HBox(false, 0)
	files.Add(export)
	files.Add(examples)

	buttons := gtk.HBox(true, 5)
	buttons.Add(solve_btn)
	buttons.Add(clear_btn)

	vbox.Add(table)
	vbox.Add(files)
	vbox.Add(buttons)

	window.Add(vbox)
	window.ShowAll()
}
func QueuedHighlightsWindow() *GhQueuedHighlightsWindow {
	queuedHighlightsWindow := &GhQueuedHighlightsWindow{gtk.Window(gtk.GTK_WINDOW_TOPLEVEL)}
	queuedHighlightsWindow.build()
	return queuedHighlightsWindow
}
Example #27
0
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()
}
Example #28
0
File: main.go Project: mattn/tabby
func init_tabby() {
	init_navigation()
	gdk.ThreadsInit()
	init_inotify()

	search_view.Init()

	source_buf = gtk.SourceBuffer()
	source_buf.Connect("paste-done", paste_done_cb, nil)
	source_buf.Connect("mark-set", mark_set_cb, nil)
	source_buf.Connect("changed", buf_changed_cb, nil)

	init_lang()

	source_buf.CreateTag("instance", map[string]string{"background": "#FF8080"})

	tree_store = gtk.TreeStore(gtk.GTK_TYPE_STRING)
	tree_view = file_tree.NewFileTree()
	tree_view.ModifyFontEasy("Regular 8")
	tree_model = tree_store.ToTreeModel()
	tree_view.SetModel(tree_model)
	tree_view.SetHeadersVisible(false)
	tree_view.Connect("cursor-changed", tree_view_select_cb, nil)

	error_view = gtk.TextView()
	error_view.ModifyFontEasy("Monospace Regular 8")
	error_view.SetEditable(false)
	error_buf = error_view.GetBuffer()

	source_view = gtk.SourceViewWithBuffer(source_buf)
	source_view.ModifyFontEasy("Monospace Regular 10")
	source_view.SetAutoIndent(true)
	source_view.SetHighlightCurrentLine(true)
	source_view.SetShowLineNumbers(true)
	source_view.SetRightMarginPosition(80)
	source_view.SetShowRightMargin(true)
	source_view.SetIndentWidth(2)
	source_view.SetTabWidth(2)
	source_view.SetInsertSpacesInsteadOfTabs(opt.space_not_tab)
	source_view.SetDrawSpaces(gtk.GTK_SOURCE_DRAW_SPACES_TAB)
	source_view.SetSmartHomeEnd(gtk.GTK_SOURCE_SMART_HOME_END_ALWAYS)
	source_view.SetWrapMode(gtk.GTK_WRAP_WORD)

	vbox := gtk.VBox(false, 0)
	inner_hpaned := gtk.HPaned()
	view_vpaned := gtk.VPaned()
	outer_hpaned := gtk.HPaned()
	outer_hpaned.Add1(inner_hpaned)
	inner_hpaned.Add2(view_vpaned)

	menubar := gtk.MenuBar()
	vbox.PackStart(menubar, false, false, 0)
	vbox.PackStart(outer_hpaned, true, true, 0)

	file_item := gtk.MenuItemWithMnemonic("_File")
	menubar.Append(file_item)
	file_submenu := gtk.Menu()
	file_item.SetSubmenu(file_submenu)

	accel_group := gtk.AccelGroup()

	new_item := gtk.MenuItemWithMnemonic("_New")
	file_submenu.Append(new_item)
	new_item.Connect("activate", new_cb, nil)
	new_item.AddAccelerator("activate", accel_group, gdk.GDK_KEY_n,
		int(gdk.GDK_CONTROL_MASK), gtk.GTK_ACCEL_VISIBLE)

	open_item := gtk.MenuItemWithMnemonic("_Open")
	file_submenu.Append(open_item)
	open_item.Connect("activate", open_cb, nil)
	open_item.AddAccelerator("activate", accel_group, gdk.GDK_KEY_o,
		int(gdk.GDK_CONTROL_MASK), gtk.GTK_ACCEL_VISIBLE)

	open_rec_item := gtk.MenuItemWithMnemonic("Open _Recursively")
	file_submenu.Append(open_rec_item)
	open_rec_item.Connect("activate", open_rec_cb, nil)

	save_item := gtk.MenuItemWithMnemonic("_Save")
	file_submenu.Append(save_item)
	save_item.Connect("activate", save_cb, nil)
	save_item.AddAccelerator("activate", accel_group, gdk.GDK_KEY_s,
		int(gdk.GDK_CONTROL_MASK), gtk.GTK_ACCEL_VISIBLE)

	save_as_item := gtk.MenuItemWithMnemonic("Save _as")
	file_submenu.Append(save_as_item)
	save_as_item.Connect("activate", save_as_cb, nil)

	close_item := gtk.MenuItemWithMnemonic("_Close")
	file_submenu.Append(close_item)
	close_item.Connect("activate", close_cb, nil)
	close_item.AddAccelerator("activate", accel_group, gdk.GDK_KEY_w,
		int(gdk.GDK_CONTROL_MASK), gtk.GTK_ACCEL_VISIBLE)

	exit_item := gtk.MenuItemWithMnemonic("E_xit")
	file_submenu.Append(exit_item)
	exit_item.Connect("activate", exit_cb, nil)

	navigation_item := gtk.MenuItemWithMnemonic("_Navigation")
	menubar.Append(navigation_item)
	navigation_submenu := gtk.Menu()
	navigation_item.SetSubmenu(navigation_submenu)

	prev_instance_item := gtk.MenuItemWithMnemonic("_Previous Instance")
	navigation_submenu.Append(prev_instance_item)
	prev_instance_item.Connect("activate", prev_instance_cb, nil)
	prev_instance_item.AddAccelerator("activate", accel_group, gdk.GDK_KEY_F2,
		0, gtk.GTK_ACCEL_VISIBLE)

	next_instance_item := gtk.MenuItemWithMnemonic("_Next Instance")
	navigation_submenu.Append(next_instance_item)
	next_instance_item.Connect("activate", next_instance_cb, nil)
	next_instance_item.AddAccelerator("activate", accel_group, gdk.GDK_KEY_F3,
		0, gtk.GTK_ACCEL_VISIBLE)

	prev_result_item := gtk.MenuItemWithMnemonic("Prev search result")
	navigation_submenu.Append(prev_result_item)
	prev_result_item.Connect("activate", func() { search_view.PrevResult() }, nil)
	prev_result_item.AddAccelerator("activate", accel_group, gdk.GDK_KEY_F4,
		0, gtk.GTK_ACCEL_VISIBLE)

	next_result_item := gtk.MenuItemWithMnemonic("Next search result")
	navigation_submenu.Append(next_result_item)
	next_result_item.Connect("activate", func() { search_view.NextResult() }, nil)
	next_result_item.AddAccelerator("activate", accel_group, gdk.GDK_KEY_F5,
		0, gtk.GTK_ACCEL_VISIBLE)

	find_item := gtk.MenuItemWithMnemonic("_Find")
	navigation_submenu.Append(find_item)
	find_item.Connect("activate", find_cb, nil)
	find_item.AddAccelerator("activate", accel_group, gdk.GDK_KEY_f,
		int(gdk.GDK_CONTROL_MASK), gtk.GTK_ACCEL_VISIBLE)

	find_file_item := gtk.MenuItemWithMnemonic("_Find file")
	navigation_submenu.Append(find_file_item)
	find_file_item.Connect("activate", find_file_cb, nil)
	find_file_item.AddAccelerator("activate", accel_group, gdk.GDK_KEY_d,
		int(gdk.GDK_CONTROL_MASK), gtk.GTK_ACCEL_VISIBLE)

	fnr_item := gtk.MenuItemWithMnemonic("Find and Replace")
	navigation_submenu.Append(fnr_item)
	fnr_item.Connect("activate", fnr_cb, nil)
	fnr_item.AddAccelerator("activate", accel_group, gdk.GDK_KEY_r,
		int(gdk.GDK_CONTROL_MASK), gtk.GTK_ACCEL_VISIBLE)

	prev_file_item := gtk.MenuItemWithMnemonic("Prev File")
	navigation_submenu.Append(prev_file_item)
	prev_file_item.Connect("activate", prev_file_cb, nil)
	prev_file_item.AddAccelerator("activate", accel_group, gdk.GDK_KEY_F7,
		0, gtk.GTK_ACCEL_VISIBLE)

	next_file_item := gtk.MenuItemWithMnemonic("Next File")
	navigation_submenu.Append(next_file_item)
	next_file_item.Connect("activate", next_file_cb, nil)
	next_file_item.AddAccelerator("activate", accel_group, gdk.GDK_KEY_F8,
		0, gtk.GTK_ACCEL_VISIBLE)

	tools_item := gtk.MenuItemWithMnemonic("_Tools")
	menubar.Append(tools_item)
	tools_submenu := gtk.Menu()
	tools_item.SetSubmenu(tools_submenu)

	gofmt_item := gtk.MenuItemWithMnemonic("_Gofmt")
	tools_submenu.Append(gofmt_item)
	gofmt_item.Connect("activate", gofmt_cb, nil)
	gofmt_item.AddAccelerator("activate", accel_group, gdk.GDK_KEY_F9,
		0, gtk.GTK_ACCEL_VISIBLE)

	gofmtAll_item := gtk.MenuItemWithMnemonic("Gofmt _All")
	tools_submenu.Append(gofmtAll_item)
	gofmtAll_item.Connect("activate", gofmt_all, nil)
	gofmtAll_item.AddAccelerator("activate", accel_group, gdk.GDK_KEY_F9,
		int(gdk.GDK_CONTROL_MASK), gtk.GTK_ACCEL_VISIBLE)

	options_item := gtk.MenuItemWithMnemonic("_Options")
	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()
}
Example #29
0
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() {
		go func() {
			gdk.ThreadsEnter()
			button.SetSensitive(false)
			gdk.ThreadsLeave()
			r, err := http.Get("http://twitter.com/statuses/public_timeline.json")
			if err == nil {
				var b []byte
				if r.ContentLength == -1 {
					b, err = ioutil.ReadAll(r.Body)
				} else {
					b = make([]byte, r.ContentLength)
					_, err = io.ReadFull(r.Body, b)
				}
				if err != nil {
					println(err.String())
					return
				}
				var j interface{}
				json.NewDecoder(bytes.NewBuffer(b)).Decode(&j)
				arr := j.([]interface{})
				for i := 0; i < len(arr); i++ {
					data := arr[i].(map[string]interface{})
					icon := data["user"].(map[string]interface{})["profile_image_url"].(string)
					var iter gtk.GtkTextIter
					gdk.ThreadsEnter()
					buffer.GetStartIter(&iter)
					buffer.InsertPixbuf(&iter, url2pixbuf(icon))
					gdk.ThreadsLeave()
					name := data["user"].(map[string]interface{})["screen_name"].(string)
					text := data["text"].(string)
					gdk.ThreadsEnter()
					buffer.Insert(&iter, " ")
					buffer.InsertWithTag(&iter, name, tag)
					buffer.Insert(&iter, ":"+text+"\n")
					gtk.MainIterationDo(false)
					gdk.ThreadsLeave()
				}
			}
			button.SetSensitive(true)
		}()
	})
	vbox.PackEnd(button, false, false, 0)

	window.Add(vbox)
	window.SetSizeRequest(800, 500)
	window.ShowAll()
	gdk.ThreadsEnter()
	gtk.Main()
	gdk.ThreadsLeave()
}
Example #30
0
func main() {
	gtk.Init(&os.Args)

	window := gtk.Window(gtk.GTK_WINDOW_TOPLEVEL)
	window.SetTitle("GoTalk")
	window.Connect("destroy", func() {
		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()

	entry := gtk.Entry()
	vbox.PackEnd(entry, false, false, 0)

	window.Add(vbox)
	window.SetSizeRequest(300, 400)
	window.ShowAll()

	dialog := gtk.Dialog()
	dialog.SetTitle(window.GetTitle())
	sgroup := gtk.SizeGroup(gtk.GTK_SIZE_GROUP_HORIZONTAL)

	hbox := gtk.HBox(false, 1)
	dialog.GetVBox().Add(hbox)
	label := gtk.Label("username:"******"password:"******"talk.google.com:443", username_, password_)
	if err != nil {
		log.Fatal(err)
	}

	entry.Connect("activate", func() {
		text := entry.GetText()
		tokens := strings.SplitN(text, " ", 2)
		if len(tokens) == 2 {
			func() {
				defer recover()
				talk.Send(xmpp.Chat{Remote: tokens[0], Type: "chat", Text: tokens[1]})
				entry.SetText("")
			}()
		}
	})

	go func() {
		for {
			func() {
				defer recover()
				chat, err := talk.Recv()
				if err != nil {
					log.Fatal(err)
				}

				var iter gtk.GtkTextIter
				buffer.GetStartIter(&iter)
				buffer.Insert(&iter, chat.Remote+": "+chat.Text+"\n")
			}()
		}
	}()

	gtk.Main()
}