Exemplo n.º 1
0
Arquivo: gui.go Projeto: 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()
}
Exemplo n.º 2
0
func TweetWidget(tweet gotter.Tweet) *gtk.GtkFrame {
	frame := gtk.Frame(tweet.User.ScreenName)
	hbox := gtk.HBox(false, 1)
	imagePixbuf := *url2pixbuf(tweet.User.ProfileImageURL)
	image := gtk.ImageFromPixbuf(imagePixbuf)

	vbox := gtk.VBox(false, 1)
	tweettext := gtk.TextView()
	tweettext.SetWrapMode(gtk.GTK_WRAP_WORD)
	tweettext.SetEditable(false)
	tweetbuffer := tweettext.GetBuffer()

	tweetbuffer.SetText(tweet.Text)

	tweettime, _ := time.Parse(time.RubyDate, tweet.CreatedAt)
	hour := (string)(strconv.Itoa(tweettime.Hour))
	var minute string
	if tweettime.Minute < 10 {
		minute = "0" + (string)(strconv.Itoa(tweettime.Minute))
	} else {
		minute = (string)(strconv.Itoa(tweettime.Minute))
	}
	whenfromtext := gtk.Label(hour + ":" + minute)
	//wherefromtext := gtk.Label(tweet.Source)

	hbox.PackStart(image, false, false, 0)
	hbox.PackEndDefaults(vbox)
	vbox.PackStart(tweettext, false, false, 0)
	vbox.PackEnd(whenfromtext, false, false, 0)
	//vbox.PackEnd(wherefromtext, false, false, 0)

	frame.Add(hbox)

	return frame
}
Exemplo n.º 3
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()
}
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()
}
Exemplo n.º 5
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()
}
Exemplo n.º 6
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()
}
Exemplo n.º 7
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()
}
Exemplo n.º 8
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()
}
Exemplo n.º 9
0
func main() {
	gtk.Init(&os.Args)

	dialog := gtk.Dialog()
	dialog.SetTitle("number input")

	vbox := dialog.GetVBox()

	label := gtk.Label("Numnber:")
	vbox.Add(label)

	input := gtk.Entry()
	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.ButtonWithLabel("OK")
	button.Connect("clicked", func() {
		println(input.GetText())
		gtk.MainQuit()
	})
	vbox.Add(button)

	dialog.ShowAll()
	gtk.Main()
}
Exemplo n.º 10
0
Arquivo: demo.go Projeto: 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()
}
Exemplo n.º 11
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()
}
Exemplo n.º 12
0
func (window *GhMainWindow) build() {
	window.SetTitle("ghighlights")
	window.bindKeys()
	window.Connect("destroy", gtk.MainQuit)

	mainVBox := gtk.VBox(false, 1)

	menubar := window.buildMenuBar()
	mainVBox.PackStart(menubar, false, false, 0)

	scrolledTextViewWindow := gtk.ScrolledWindow(nil, nil)
	scrolledTextViewWindow.SetPolicy(gtk.GTK_POLICY_AUTOMATIC, gtk.GTK_POLICY_AUTOMATIC)

	textView := gtkext.TextViewWithPlaceholder("Highlight")
	textView.SetSizeRequest(600, 100)
	textView.SetWrapMode(gtk.GTK_WRAP_WORD)
	textView.SetAcceptsTab(false)
	scrolledTextViewWindow.Add(textView)

	scrolledTextViewWindow.SetSizeRequest(600, 100)
	mainVBox.Add(scrolledTextViewWindow)

	scrolledCommentTextViewWindow := gtk.ScrolledWindow(nil, nil)
	scrolledCommentTextViewWindow.SetPolicy(gtk.GTK_POLICY_AUTOMATIC, gtk.GTK_POLICY_AUTOMATIC)

	commentTextView := gtkext.TextViewWithPlaceholder("Comment")
	commentTextView.SetSizeRequest(600, 40)
	commentTextView.SetWrapMode(gtk.GTK_WRAP_WORD)
	commentTextView.SetAcceptsTab(false)
	scrolledCommentTextViewWindow.Add(commentTextView)

	scrolledCommentTextViewWindow.SetSizeRequest(600, 40)
	mainVBox.Add(scrolledCommentTextViewWindow)

	readingHBox := gtk.HBox(false, 10)
	pageNumberEntry := gtk.Entry()
	pageTotalEntry := gtk.Entry()

	readingsComboBox := gtk.ComboBoxText()
	readings := models.Readings()
	for _, reading := range readings.Items {
		readingsComboBox.AppendText(reading.Title)
	}
	readingsComboBox.SetActive(0)
	readingsComboBox.Connect("changed", func() {
		reading := readings.FindByTitle(readingsComboBox.GetActiveText())
		pageNumberEntry.SetText("0")
		pageTotalEntry.SetText(strconv.Itoa(reading.TotalPages))
	})
	align := gtk.Alignment(1, 1, 1, 0)
	align.Add(readingsComboBox)
	readingHBox.Add(align)

	pageHBox := gtk.HBox(false, 1)
	pageHBox.Add(gtk.Label("Page"))

	pageNumberEntry.SetAlignment(1)
	pageNumberEntry.SetWidthChars(4)
	pageNumberEntry.SetText("0")
	pageHBox.Add(pageNumberEntry)

	pageHBox.Add(gtk.Label("of"))

	pageTotalEntry.SetAlignment(1)
	pageTotalEntry.SetWidthChars(4)
	if len(readings.Items) > 0 {
		pageTotalEntry.SetText(strconv.Itoa(readings.Items[0].TotalPages))
	}
	pageHBox.Add(pageTotalEntry)

	pageBoxAlignment := gtk.Alignment(0, 0, 0, 0)
	pageBoxAlignment.Add(pageHBox)
	readingHBox.Add(pageBoxAlignment)
	mainVBox.Add(readingHBox)

	addHighlightButton := gtk.ButtonWithLabel("Add highlight")
	window.highlights = models.Highlights()
	addHighlightButton.Clicked(func() {
		reading := readings.FindByTitle(readingsComboBox.GetActiveText())
		readingId := reading.ReadmillId

		content := textView.GetStrippedText()

		comment := commentTextView.GetStrippedText()

		pageNumber, _ := strconv.Atoi(pageNumberEntry.GetText())
		pageTotal, _ := strconv.Atoi(pageTotalEntry.GetText())
		position := float32(pageNumber) / float32(pageTotal)

		highlight := models.GhHighlight{content, readingId, position, time.Now(), comment}
		window.highlights.Add(highlight)

		readings.UpdateTotalPages(pageTotal, reading)

		textView.DeleteText()
		commentTextView.DeleteText()
	})
	readingHBox.PackEnd(addHighlightButton, false, false, 0)

	window.Add(mainVBox)
	return
}
Exemplo n.º 13
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()
}
Exemplo n.º 14
0
func Gui() {
	//--------------------------------------------------------
	// Setting up the GTK-Foo
	//--------------------------------------------------------
	gdk.ThreadsInit()
	gtk.Init(&os.Args)
	window := gtk.Window(gtk.GTK_WINDOW_TOPLEVEL)
	window.SetTitle("Zwitscher!")
	window.Connect("destroy", func() {
		gtk.MainQuit()
	})

	vbox := gtk.VBox(false, 1)
	notebook := gtk.Notebook()

	//--------------------------------------------------------
	// Home View
	//--------------------------------------------------------
	vboxHome := gtk.VBox(false, 1)
	scrolledWinHome := gtk.ScrolledWindow(nil, nil)
	//Disable hscrollbar, enable vscrollbar
	scrolledWinHome.SetPolicy(gtk.GTK_POLICY_NEVER, gtk.GTK_POLICY_ALWAYS)
	vboxHome.Add(scrolledWinHome)
	vboxScrolledWinHome := gtk.VBox(false, 1)
	scrolledWinHome.AddWithViewPort(vboxScrolledWinHome)

	tweetwidgets := []*gtk.GtkFrame{}
	buttonUpdateTimeline := gtk.ButtonWithLabel("Update Timeline")
	buttonUpdateTimeline.Clicked(func() {
		var tweet gotter.Tweet
		tweets, err := gotter.GetTweets(accounts.Credentials, "https://api.twitter.com/1/statuses/home_timeline.json", map[string]string{})
		if err != nil {
			println("failed to get tweets:", err.String())
			return
		}
		for i := len(tweets) - 1; i >= 0; i-- {
			tweet = tweets[i]
			id, _ := strconv.Atoi64(tweet.Identifier)
			if accounts.Maxreadid < id {
				if len(tweetwidgets) > 20 {
					tweetwidgets[0].Destroy()
					tweetwidgets = tweetwidgets[1:]
				}
				tweetwidget := TweetWidget(tweet)
				vboxScrolledWinHome.PackEnd(tweetwidget, false, false, 0)
				tweetwidget.ShowAll()
				tweetwidgets = append(tweetwidgets, tweetwidget)
				accounts.Maxreadid = id
			}
		}
	})
	vboxHome.PackEnd(buttonUpdateTimeline, false, false, 0)
	notebook.AppendPage(vboxHome, gtk.Label("Home"))

	//--------------------------------------------------------
	// Mentions View
	//--------------------------------------------------------
	scrolledwin := gtk.ScrolledWindow(nil, nil)
	notebook.AppendPage(scrolledwin, gtk.Label("Mentions"))

	//--------------------------------------------------------
	// Messages View
	//--------------------------------------------------------
	scrolledwin = gtk.ScrolledWindow(nil, nil)
	notebook.AppendPage(scrolledwin, gtk.Label("Messages"))

	vbox.Add(notebook)

	//--------------------------------------------------------
	// Fild for Tweets
	//--------------------------------------------------------
	hbox := gtk.HBox(false, 1)

	dir, _ := filepath.Split(os.Args[0])
	imagefile := filepath.Join(dir, "Awesome Smiley Original.jpg")
	image := gtk.ImageFromFile(imagefile)
	hbox.PackStart(image, false, false, 0)

	buttonZwitscher := gtk.ButtonWithLabel("Zwitscher!")
	newTweetTextField := gtk.Entry()
	charCounterLabel := gtk.Label("140")

	buttonZwitscher.SetTooltipMarkup("Tweet")

	buttonZwitscher.Clicked(func() {
		charCounterLabel.SetLabel("140")
		SendTweet(newTweetTextField.GetText())
		newTweetTextField.SetText("")
	})

	newTweetTextField.Connect("key-release-event", func() {
		length := utf8.RuneCountInString(newTweetTextField.GetText())
		charCounterLabel.SetLabel((string)(strconv.Itoa(140 - length)))
	})

	newTweetTextField.Connect("activate", func() {
		if newTweetTextField.GetText() != "" { //pressed enter, and text is not empty
			charCounterLabel.SetLabel("140")
			SendTweet(newTweetTextField.GetText())
			newTweetTextField.SetText("")
		}
	})
	hbox.PackStartDefaults(newTweetTextField)
	hbox.PackStart(charCounterLabel, false, false, 0)
	hbox.PackEnd(buttonZwitscher, false, false, 0)

	vbox.PackEnd(hbox, false, false, 0)

	//--------------------------------------------------------
	// Event
	//--------------------------------------------------------
	window.Add(vbox)
	window.SetSizeRequest(400, 550)
	window.ShowAll()

	gdk.ThreadsEnter()
	gtk.Main()
	gdk.ThreadsLeave()
}