Ejemplo n.º 1
0
func main() {
	gtk.Init(nil)
	window := gtk.NewWindow(gtk.WINDOW_TOPLEVEL)
	window.SetPosition(gtk.WIN_POS_CENTER)
	window.SetTitle("Hello GTK+Go world!")
	window.SetIconName("gtk-dialog-info")
	window.Connect("destroy", func(ctx *glib.CallbackContext) {
		gtk.MainQuit()
	}, "foo")
	vbox := gtk.NewVBox(false, 1)
	button := gtk.NewButtonWithLabel("Hello world!")
	button.SetTooltipMarkup("Say Hello World to everybody!")
	button.Clicked(func() {
		messagedialog := gtk.NewMessageDialog(
			button.GetTopLevelAsWindow(),
			gtk.DIALOG_MODAL,
			gtk.MESSAGE_INFO,
			gtk.BUTTONS_OK,
			"Hello!")
		messagedialog.Response(func() {
			messagedialog.Destroy()
		})
		messagedialog.Run()
	})
	vbox.PackStart(button, false, false, 0)
	window.Add(vbox)
	window.SetSizeRequest(300, 50)
	window.ShowAll()
	gtk.Main()
}
Ejemplo n.º 2
0
func (ed *BiomeInfoEditor) save() {
	dlg := gtk.NewFileChooserDialog("Save", nil, gtk.FILE_CHOOSER_ACTION_SAVE, "OK", gtk.RESPONSE_OK, "Cancel", gtk.RESPONSE_CANCEL)
	defer dlg.Destroy()
askFilename:
	if dlg.Run() == gtk.RESPONSE_OK {
		path := dlg.GetFilename()

		if _, err := os.Stat(path); err == nil {
			qdlg := gtk.NewMessageDialog(nil, gtk.DIALOG_MODAL, gtk.MESSAGE_QUESTION, gtk.BUTTONS_YES_NO, "File %s already exists. Overwrite?", path)
			resp := qdlg.Run()
			qdlg.Destroy()

			if resp != gtk.RESPONSE_YES {
				goto askFilename
			}
		}

		f, err := os.Create(path)
		if err != nil {
			errdlg("Could not save biome infos %s:\n%s", path, err.Error())
			goto askFilename
		}
		defer f.Close()

		if err := WriteBiomeInfos(ed.biolist.Biomes(), f); err != nil {
			errdlg("Could not save biome infos %s:\n%s", path, err.Error())
			goto askFilename
		}
	}
}
Ejemplo n.º 3
0
func (v *Status) SetMinutes(minutes int) {
	var bg string
	if minutes <= 5 {
		bg = "yellow"
	} else {
		bg = "#e0e0e0"
	}
	v.timeLabel.SetMarkup("<span background='" + bg + "' size='xx-large'>" + strconv.Itoa(minutes) + " min igjen</span>")

	if minutes <= 5 && v.warned == false {
		msg := "Du blir logget av om " + strconv.Itoa(minutes) + " minutter. Husk å lagre det du jobber med!\nLagre på USB-pinne eller send det til deg selv på epost."
		md := gtk.NewMessageDialog(v.window.GetTopLevelAsWindow(), gtk.DIALOG_MODAL,
			gtk.MESSAGE_WARNING, gtk.BUTTONS_OK, msg)
		md.SetTypeHint(gdk.WINDOW_TYPE_HINT_MENU)
		md.SetPosition(gtk.WIN_POS_CENTER)
		md.Connect("response", func() {
			md.Destroy()
		})
		md.ShowAll()
		v.warned = true
	}

	if minutes > 5 {
		v.warned = false
	}
}
Ejemplo n.º 4
0
Archivo: main.go Proyecto: kch42/biomed
func (g *GUI) save() {
	g.setBusy(true)
	g.mapw.Save()
	g.setBusy(false)

	dlg := gtk.NewMessageDialog(g.window, gtk.DIALOG_MODAL|gtk.DIALOG_DESTROY_WITH_PARENT, gtk.MESSAGE_INFO, gtk.BUTTONS_OK, "Map saved!")
	dlg.Run()
	dlg.Destroy()
}
Ejemplo n.º 5
0
func bump_message(m string) {
	dialog := gtk.NewMessageDialog(
		main_window.GetTopLevelAsWindow(),
		gtk.DIALOG_MODAL,
		gtk.MESSAGE_INFO,
		gtk.BUTTONS_OK,
		m)
	dialog.Run()
	dialog.Destroy()
}
Ejemplo n.º 6
0
Archivo: main.go Proyecto: udhos/tabby
func bump_question(m string) (b bool) {
	dialog := gtk.NewMessageDialog(
		main_window.GetTopLevelAsWindow(),
		gtk.DIALOG_MODAL,
		gtk.MESSAGE_WARNING,
		gtk.BUTTONS_YES_NO,
		m)
	b = dialog.Run() == gtk.RESPONSE_YES
	dialog.Destroy()
	return
}
Ejemplo n.º 7
0
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)

	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.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.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()
}
Ejemplo n.º 8
0
Archivo: main.go Proyecto: kch42/biomed
func (g *GUI) openWorld(p string) {
	region, centerX, centerZ, err := readWorld(p)
	if err != nil {
		dlg := gtk.NewMessageDialog(g.window, gtk.DIALOG_MODAL|gtk.DIALOG_DESTROY_WITH_PARENT, gtk.MESSAGE_WARNING, gtk.BUTTONS_OK, "Could not load world %s:\n%s", p, err.Error())
		dlg.Run()
		dlg.Destroy()
	}

	g.menuitemSave.SetSensitive(true)

	g.mapw.SetCenter(centerX, centerZ)
	g.mapw.SetRegion(region)
}
Ejemplo n.º 9
0
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.GetGdkPixbufType(), 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, "").Pixbuf, "Folder"+strconv.Itoa(n))
		store.Append(&iter2, &iter1)
		store.Set(&iter2, gtk.NewImage().RenderIcon(gtk.STOCK_DIRECTORY, gtk.ICON_SIZE_SMALL_TOOLBAR, "").Pixbuf, "SubFolder"+strconv.Itoa(n))
		store.Append(&iter3, &iter2)
		store.Set(&iter3, gtk.NewImage().RenderIcon(gtk.STOCK_FILE, gtk.ICON_SIZE_SMALL_TOOLBAR, "").Pixbuf, "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()
}
Ejemplo n.º 10
0
func dialogError(win *gtk.Window, err error) {

	log.Error(err)
	dialog := gtk.NewMessageDialog(
		win,
		gtk.DIALOG_MODAL,
		gtk.MESSAGE_ERROR,
		gtk.BUTTONS_CANCEL,
		err.Error(),
	)
	dialog.Response(func() {
		dialog.Destroy()
	})
	dialog.Run()
}
Ejemplo n.º 11
0
Archivo: main.go Proyecto: kch42/biomed
func (g *GUI) mkMenuBar() *gtk.MenuBar {
	menubar := gtk.NewMenuBar()

	fileMenu := gtk.NewMenu()

	open := gtk.NewImageMenuItemFromStock(gtk.STOCK_OPEN, g.accel)
	open.Connect("activate", g.openWorldDlg)
	fileMenu.Append(open)

	if quickopen, ok := g.mkQuickOpen(); ok {
		quickopenItem := gtk.NewMenuItemWithLabel("Open Map")
		quickopenItem.SetSubmenu(quickopen)
		fileMenu.Append(quickopenItem)
	}

	g.menuitemSave = gtk.NewImageMenuItemFromStock(gtk.STOCK_SAVE, g.accel)
	g.menuitemSave.Connect("activate", g.save)
	g.menuitemSave.SetSensitive(false)
	fileMenu.Append(g.menuitemSave)

	quit := gtk.NewImageMenuItemFromStock(gtk.STOCK_QUIT, g.accel)
	quit.Connect("activate", g.exitApp)
	fileMenu.Append(quit)

	fileMenuItem := gtk.NewMenuItemWithLabel("File")
	fileMenuItem.SetSubmenu(fileMenu)
	menubar.Append(fileMenuItem)

	helpMenu := gtk.NewMenu()

	controls := gtk.NewMenuItemWithLabel("Controls")
	controls.Connect("activate", func() {
		dlg := gtk.NewMessageDialog(g.window, gtk.DIALOG_MODAL, gtk.MESSAGE_INFO, gtk.BUTTONS_OK, "Click to use selected tool.\nMiddle mouse button to move around.")
		dlg.Run()
		dlg.Destroy()
	})
	helpMenu.Append(controls)

	about := gtk.NewImageMenuItemFromStock(gtk.STOCK_ABOUT, g.accel)
	about.Connect("activate", g.aboutDlg)
	helpMenu.Append(about)

	helpMenuItem := gtk.NewMenuItemWithLabel("Help")
	helpMenuItem.SetSubmenu(helpMenu)
	menubar.Append(helpMenuItem)

	return menubar
}
Ejemplo n.º 12
0
func (b *MsgBuilder) yesNo() bool {
	dlg := gtk.NewMessageDialog(nil, 0, gtk.MESSAGE_QUESTION, gtk.BUTTONS_YES_NO, "%s", b.Msg)
	dlg.SetTitle(firstOf(b.Dlg.Title, "Confirm?"))
	defer closeDialog(&dlg.Dialog)
	return dlg.Run() == gtk.RESPONSE_YES
}
Ejemplo n.º 13
0
func main() {
	gtk.Init(&os.Args)
	display = gtk.NewEntry()
	window := gtk.NewWindow(gtk.WINDOW_TOPLEVEL)
	window.SetTitle("Simple Go Calculator")
	window.Connect("destroy", Quit, nil)

	// Vertical box containing all components
	vbox := gtk.NewVBox(false, 1)

	// Menu bar
	menubar := gtk.NewMenuBar()
	vbox.PackStart(menubar, false, false, 0)

	// Add calculator display to vertical box
	display.SetCanFocus(false) // disable focus on calcuator display
	display.SetText("0")
	display.SetAlignment(1.0) //align text to right
	vbox.Add(display)

	// Menu items
	filemenu := gtk.NewMenuItemWithMnemonic("_File")
	menubar.Append(filemenu)
	filesubmenu := gtk.NewMenu()
	filemenu.SetSubmenu(filesubmenu)

	aboutmenuitem := gtk.NewMenuItemWithMnemonic("_About")
	aboutmenuitem.Connect("activate", func() {
		messagedialog := gtk.NewMessageDialog(
			window.GetTopLevelAsWindow(),
			gtk.DIALOG_MODAL,
			gtk.MESSAGE_INFO,
			gtk.BUTTONS_OK,
			"Simple Go Calculator")
		messagedialog.Response(func() {}, nil)
		messagedialog.Run()
		messagedialog.Destroy()
	},
		nil)
	filesubmenu.Append(aboutmenuitem)

	resetmenuitem := gtk.NewMenuItemWithMnemonic("_Reset")
	resetmenuitem.Connect("activate", func() { Reset(); display.SetText("0") }, nil)
	filesubmenu.Append(resetmenuitem)

	exitmenuitem := gtk.NewMenuItemWithMnemonic("E_xit")
	exitmenuitem.Connect("activate", Quit, nil)
	filesubmenu.Append(exitmenuitem)

	// Vertical box containing all buttons
	buttons := gtk.NewVBox(false, 5)

	for i := 0; i < 4; i++ {
		hbox := gtk.NewHBox(false, 5) // a horizontal box for each 4 buttons
		for j := 0; j < 4; j++ {
			b := gtk.NewButtonWithLabel(string(nums[i*4+j]))
			b.Clicked(Input(b), nil) //add click event
			hbox.Add(b)
		}
		buttons.Add(hbox) // add horizonatal box to vertical buttons' box
	}

	vbox.Add(buttons)

	window.Add(vbox)
	window.SetSizeRequest(250, 250)
	window.ShowAll()
	gtk.Main()
}
Ejemplo n.º 14
0
func main() {
	var menuitem *gtk.MenuItem
	gtk.Init(nil)
	window := gtk.NewWindow(gtk.WINDOW_TOPLEVEL)
	window.SetPosition(gtk.WIN_POS_CENTER)
	window.SetTitle("GoBox a0.1")
	window.SetIconName("gtk-dialog-info")
	window.Connect("destroy", func(ctx *glib.CallbackContext) {
		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("Dossier et Paramètres")
	framebox1 := gtk.NewVBox(false, 1)
	frame1.Add(framebox1)

	frame2 := gtk.NewFrame("Fonctions")
	framebox2 := gtk.NewVBox(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, "../../mattn/go-gtk/data/go-gtk-logo.png")
	  imagefile := path.Join(dir, "./go-gtk-logo.png")
	  println(dir)*/

	label := gtk.NewLabel("GoBox a0.1")
	label.ModifyFontEasy("DejaVu Serif 15")
	framebox1.PackStart(label, false, true, 0)

	//--------------------------------------------------------
	// GtkEntry
	//--------------------------------------------------------
	champIp := gtk.NewEntry()
	champIp.SetText("10.0.0.1")
	framebox1.Add(champIp)

	champPort := gtk.NewEntry()
	champPort.SetText("80")
	framebox1.Add(champPort)

	folder := "./"

	/*image := gtk.NewImageFromFile(imagefile)
	  framebox1.Add(image)*/
	buttons := gtk.NewHBox(false, 1)
	//--------------------------------------------------------
	// GtkButton
	//--------------------------------------------------------
	button := gtk.NewButtonWithLabel("Choisir le dossier")
	button.Clicked(func() {
		//--------------------------------------------------------
		// GtkFileChooserDialog
		//--------------------------------------------------------
		filechooserdialog := gtk.NewFileChooserDialog(
			"Sélectionnez le dossier ...",
			button.GetTopLevelAsWindow(),
			gtk.FILE_CHOOSER_ACTION_SELECT_FOLDER,
			gtk.STOCK_OK,
			gtk.RESPONSE_ACCEPT)
		/*filter := gtk.NewFileFilter()
		  filter.AddPattern("*.go")
		  filechooserdialog.AddFilter(filter)*/
		filechooserdialog.Response(func() {
			println(filechooserdialog.GetFilename())
			folder = filechooserdialog.GetFilename() + "/"
			filechooserdialog.Destroy()
		})
		filechooserdialog.Run()
	})
	buttons.Add(button)

	//--------------------------------------------------------
	// GtkToggleButton
	//--------------------------------------------------------
	togglebutton := gtk.NewToggleButtonWithLabel("Lancer la synchronisation")
	togglebutton.Connect("toggled", func() {
		if togglebutton.GetActive() {
			togglebutton.SetLabel("Synchronisation ON")
			//Appel fonction synchro avec paramètres
			println(folder, champIp.GetText(), champPort.GetText())
			sync(folder, champIp.GetText(), champPort.GetText())
		} else {
			togglebutton.SetLabel("Synchronisation OFF")
		}
	})
	buttons.Add(togglebutton)

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

	//--------------------------------------------------------
	// GtkVSeparator
	//--------------------------------------------------------
	vsep := gtk.NewVSeparator()
	framebox2.PackStart(vsep, false, false, 0)

	//--------------------------------------------------------
	// GtkMenuItem
	//--------------------------------------------------------
	cascademenu := gtk.NewMenuItemWithMnemonic("_Fichier")
	menubar.Append(cascademenu)
	submenu := gtk.NewMenu()
	cascademenu.SetSubmenu(submenu)

	menuitem = gtk.NewMenuItemWithMnemonic("Q_uitter")
	menuitem.Connect("activate", func() {
		gtk.MainQuit()
	})
	submenu.Append(menuitem)

	cascademenu = gtk.NewMenuItemWithMnemonic("_Aide")
	menubar.Append(cascademenu)
	submenu = gtk.NewMenu()
	cascademenu.SetSubmenu(submenu)

	auteurs := gtk.NewEntry()
	auteurs.SetText("Application crée en MCS par Olivier CANO et Adrien CHAPELET")

	menuitem = gtk.NewMenuItemWithMnemonic("À_ propos")
	menuitem.Connect("activate", func() {
		messagedialog := gtk.NewMessageDialog(
			button.GetTopLevelAsWindow(),
			gtk.DIALOG_MODAL,
			gtk.MESSAGE_INFO,
			gtk.BUTTONS_OK,
			auteurs.GetText())
		messagedialog.Response(func() {
			messagedialog.Destroy()
		})
		messagedialog.Run()
	})
	submenu.Append(menuitem)

	//--------------------------------------------------------
	// GtkStatusbar
	//--------------------------------------------------------
	statusbar := gtk.NewStatusbar()
	context_id := statusbar.GetContextId("go-gtk")
	statusbar.Push(context_id, "En attente de synchronisation")

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

	//--------------------------------------------------------
	// Event
	//--------------------------------------------------------
	window.Add(vbox)
	window.SetSizeRequest(500, 300)
	window.ShowAll()
	gtk.Main()
}
Ejemplo n.º 15
0
func (b *MsgBuilder) error() {
	dlg := gtk.NewMessageDialog(nil, 0, gtk.MESSAGE_ERROR, gtk.BUTTONS_OK, "%s", b.Msg)
	dlg.SetTitle(firstOf(b.Dlg.Title, "Error"))
	defer closeDialog(&dlg.Dialog)
	dlg.Run()
}
Ejemplo n.º 16
0
func errdlg(msg string, params ...interface{}) {
	dlg := gtk.NewMessageDialog(nil, gtk.DIALOG_MODAL|gtk.DIALOG_DESTROY_WITH_PARENT, gtk.MESSAGE_ERROR, gtk.BUTTONS_OK, msg, params...)
	dlg.Run()
	dlg.Destroy()
}
Ejemplo n.º 17
0
Archivo: main.go Proyecto: kch42/biomed
func (g *GUI) reportError(msg string) {
	dlg := gtk.NewMessageDialog(g.window, gtk.DIALOG_MODAL|gtk.DIALOG_DESTROY_WITH_PARENT, gtk.MESSAGE_ERROR, gtk.BUTTONS_OK, msg)
	dlg.Run()
	dlg.Destroy()
	os.Exit(1)
}
Ejemplo n.º 18
0
//InitializeGUI es la funcion que inicializa y ejecuta todo el entorno gráfico de la aplicacion
func (p *Gui) InitializeGUI(errorstr string, file *os.File) {
	gtk.Init(nil)

	window := gtk.NewWindow(gtk.WINDOW_TOPLEVEL)
	window.SetPosition(gtk.WIN_POS_CENTER)
	window.Maximize()
	window.SetTitle("Go-SIC ASM/SIM!")
	window.SetIconName("gtk-dialog-info")
	window.Connect("destroy", func(ctx *glib.CallbackContext) {
		fmt.Println("got destroy!", ctx.Data().(string))
		gtk.MainQuit()
	}, "foo")

	//--------------------------------------------------------
	//	GTK statusbar
	//--------------------------------------------------------
	statusbar := gtk.NewStatusbar()
	context_id := statusbar.GetContextId("hola")
	//--------------------------------------------------------
	// GtkVBox
	//--------------------------------------------------------
	vbox := gtk.NewVBox(false, 1)

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

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

	//--------------------------------------------------------
	// GtkFrame
	//--------------------------------------------------------
	frame1 := gtk.NewFrame("Código Fuente/Archivo intermedio/TABSIM")
	framebox1 := gtk.NewVBox(false, 1)
	frame1.Add(framebox1)
	frame1.SetSizeRequest(300, 300)

	frame2 := gtk.NewFrame("Debug/Código Objeto")
	framebox2 := gtk.NewVBox(false, 1)
	frame2.Add(framebox2)

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

	//--------------------------------------------------------
	// GtkHBox
	//--------------------------------------------------------
	ventanasPrincipales := gtk.NewHBox(false, 1)
	//----------------------------------------------

	label := gtk.NewLabel("Ensamblador SIC SIC/XE")
	label.ModifyFontEasy("DejaVu Serif 15")
	framebox1.PackStart(label, false, true, 0)
	//--------------------------------------------------------
	// GtkTextView
	//--------------------------------------------------------
	swin := gtk.NewScrolledWindow(nil, nil)

	swin.SetPolicy(gtk.POLICY_AUTOMATIC, gtk.POLICY_AUTOMATIC)
	swin.SetShadowType(gtk.SHADOW_IN)
	textview := gtk.NewTextView()

	textview.ModifyFontEasy("Sans 10")
	var start, end gtk.TextIter
	buffer := textview.GetBuffer()
	buffer.GetStartIter(&start)
	swin.Add(textview)
	ventanasPrincipales.Add(swin)
	//framebox1.Add(swin)
	//--------------------------------------------------------
	// GtkTextView
	//--------------------------------------------------------
	swin4 := gtk.NewScrolledWindow(nil, nil)

	swin4.SetPolicy(gtk.POLICY_AUTOMATIC, gtk.POLICY_AUTOMATIC)
	swin4.SetShadowType(gtk.SHADOW_IN)
	textview4 := gtk.NewTextView()

	textview4.ModifyFontEasy("Sans 10")
	var start4, end4 gtk.TextIter
	buffer4 := textview4.GetBuffer()
	buffer4.GetStartIter(&start4)
	swin4.Add(textview4)
	ventanasPrincipales.Add(swin4)
	//framebox1.Add(swin)
	//--------------------------------------------------------
	// GtkTextView
	//--------------------------------------------------------
	swin5 := gtk.NewScrolledWindow(nil, nil)

	swin5.SetPolicy(gtk.POLICY_AUTOMATIC, gtk.POLICY_AUTOMATIC)
	swin5.SetShadowType(gtk.SHADOW_IN)
	textview5 := gtk.NewTextView()

	textview5.ModifyFontEasy("Sans 10")
	var start5, end5 gtk.TextIter
	buffer5 := textview5.GetBuffer()
	buffer5.GetStartIter(&start5)
	swin5.Add(textview5)
	ventanasPrincipales.Add(swin5)
	framebox1.PackStart(ventanasPrincipales, true, true, 1)
	//framebox1.Add(swin)
	//--------------------------------------------------------
	// GtkHBox
	//--------------------------------------------------------
	ventanas := gtk.NewHBox(false, 1)
	//--------------------------------------------------------
	// GtkTextView
	//--------------------------------------------------------
	swin2 := gtk.NewScrolledWindow(nil, nil)

	swin2.SetPolicy(gtk.POLICY_AUTOMATIC, gtk.POLICY_AUTOMATIC)
	swin2.SetShadowType(gtk.SHADOW_IN)
	textview2 := gtk.NewTextView()
	textview2.SetEditable(false)
	var start2, end2 gtk.TextIter
	buffer2 := textview2.GetBuffer()
	buffer2.GetStartIter(&start2)
	swin2.Add(textview2)
	//framebox2.Add(swin2)
	ventanas.Add(swin2)
	//--------------------------------------------------------
	// GtkTextView
	//--------------------------------------------------------
	swin3 := gtk.NewScrolledWindow(nil, nil)

	swin3.SetPolicy(gtk.POLICY_AUTOMATIC, gtk.POLICY_AUTOMATIC)
	swin3.SetShadowType(gtk.SHADOW_IN)
	textview3 := gtk.NewTextView()
	textview3.SetEditable(false)
	var start3, end3 gtk.TextIter
	buffer3 := textview3.GetBuffer()
	buffer3.GetStartIter(&start3)
	swin3.Add(textview3)
	//framebox2.Add(swin2)
	ventanas.Add(swin3)
	framebox2.PackStart(ventanas, true, true, 1)

	//--------------------------------------------------------
	// GtkEntry
	//--------------------------------------------------------
	entry := gtk.NewEntry()
	entry.SetText("Para comenzar, favor de escoger un archivo del directorio....")
	//entry.SetSensitive(false)
	entry.SetEditable(false)
	framebox2.Add(entry)

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

	//--------------------------------------------------------
	// GtkButton //**OPEN FILE****//
	//--------------------------------------------------------
	button := gtk.NewButtonWithLabel("Elegir archivo...")
	var filename string
	var isXE bool
	button.Clicked(func() {
		fmt.Println("button clicked:", button.GetLabel())
		messagedialog := gtk.NewMessageDialog(
			button.GetTopLevelAsWindow(),
			gtk.DIALOG_MODAL,
			gtk.MESSAGE_INFO,
			gtk.BUTTONS_OK,
			"Escoja un archivo .*s o *.x de su directorio")
		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("*.s")
			filter.AddPattern("*.x")
			filechooserdialog.AddFilter(filter)
			filechooserdialog.Response(func() {
				/*aqui va el dialogo */
				filename = filechooserdialog.GetFilename()
				var extension = filepath.Ext(filename)
				if extension == ".x" {
					isXE = true
				} else {
					isXE = false
				}
				fmt.Println(filechooserdialog.GetFilename())
				statusbar.Push(context_id, filename)
				dat, err := ioutil.ReadFile(filechooserdialog.GetFilename())
				if err == nil {
					buffer.GetStartIter(&start)
					buffer.GetEndIter(&end)
					buffer.Delete(&start, &end)

					buffer.Insert(&start, string(dat))
					entry.SetText("Ahora haz click en el boton '¡Analizar!'")
					//fmt.Print(string(dat))
				}
				filechooserdialog.Destroy()
			})
			filechooserdialog.Run()
			messagedialog.Destroy()
		})
		messagedialog.Run()
	})
	buttons.Add(button)
	//--------------------------------------------------------
	// GtkButton
	//--------------------------------------------------------
	button2 := gtk.NewButtonWithLabel("Ensamblar!")
	button2.Clicked(func() {
		fmt.Println("button clicked:", button2.GetLabel())
		messagedialog2 := gtk.NewMessageDialog(
			button.GetTopLevelAsWindow(),
			gtk.DIALOG_MODAL,
			gtk.MESSAGE_INFO,
			gtk.BUTTONS_OK,
			"Analisis lexico y sintactico presiona OK para continuar...")
		messagedialog2.Response(func() {
			fmt.Println(filename)
			statusbar.Push(context_id, filename)
			file, err := os.Open(filename)
			if err != nil {
				log.Fatalf("Error al cargar el archivo: %s", err.Error())
			} else {
				//*********************************************************
				util.GetTabSim().Allocate()
				if isXE == false {
					fmt.Println("IS SIC")
					errorstr = parser.New().Parse(file, true, false)
					file, err = os.Open(filename)

					util.GetAssembler().CreateOpCodeTable()
					errorstr = parser.New().Parse(file, false, false)
					file.Close()
					//util.GetAssembler().PrintCode()
					util.GetAssembler().FormatCodeToHEX()
					buffer2.GetStartIter(&start2)
					buffer2.GetEndIter(&end2)
					buffer2.Delete(&start2, &end2)
					if len(errorstr) > 0 {
						buffer2.Insert(&start2, string(errorstr+util.GetTabSim().Errores))

						strArray := strings.Split(filename, ".s")
						f, err := os.OpenFile(strArray[0]+".ts", os.O_WRONLY|os.O_CREATE, 0600)
						if err != nil {
							panic(err)
						}
						defer f.Close()
						if _, err = f.WriteString(errorstr); err != nil {
							panic(err)
						}
					} else {
						buffer2.Insert(&start2, "Correcto!"+util.GetTabSim().Errores)
					}
					///*******************************************************
					///*******************************************************
					tabsimlines := util.GetTabSim().ReturnTable()
					buffer5.GetStartIter(&start5)
					buffer5.GetEndIter(&end5)
					buffer5.Delete(&start5, &end5)
					if len(tabsimlines) > 0 {
						buffer5.Insert(&start5, string(tabsimlines))
					}
					///*******************************************************
					///*******************************************************
					util.GetTabSim().DecToHex()
					objectCode := util.GetAssembler().ObjCode()
					var obj string
					for i := 0; i < len(objectCode); i++ {

						if len(objectCode[i]) > 10 {

							obj += objectCode[i]
						}
						if i == len(objectCode)-1 {
							obj += objectCode[i]
						}
					}
					buffer3.GetStartIter(&start3)
					buffer3.GetEndIter(&end3)
					buffer3.Delete(&start3, &end3)
					if len(obj) > 0 {
						buffer3.Insert(&start3, string(obj))
					}
					f2 := newFile(strings.Split(filename, ".s")[0], ".os")
					if _, err = f2.WriteString(obj); err != nil {
						panic(err)
					}
					///*******************************************************
					///*******************************************************
					var todostr string
					lines, err := readLines(filename)
					if err == nil {
						addrsstr := util.GetTabSim().GetProgPcStr()
						//fmt.Println(addrsstr)
						for i := 0; i < len(lines); i++ {
							if addrsstr[i+1] == "" {
								addrsstr[i+1] = addrsstr[i]
								todostr += addrsstr[i] + "\t" + lines[i] + "\n"
							} else {
								todostr += addrsstr[i] + "\t" + lines[i] + "\t" + util.GetTabSim().Progobjstr[i] + "\n"
							}
						}
						//util.GetTabSim().PrintProgpc()
						//fmt.Print(todostr)
						addrsstr = nil
					}
					buffer4.GetStartIter(&start4)
					buffer4.GetEndIter(&end4)
					buffer4.Delete(&start4, &end4)
					if len(obj) > 0 {
						buffer4.Insert(&start4, string(todostr))
					}
				} else {
					fmt.Println("IS SIC XE")
					errorstr = parser.New().Parse(file, true, true)
					file, err = os.Open(filename)

					util.GetAssembler().CreateOpCodeTable()
					parser.New().Parse(file, false, true)
					file.Close()
					//util.GetAssembler().PrintCode()
					//util.GetAssembler().FormatCodeToHEX()
					buffer2.GetStartIter(&start2)
					buffer2.GetEndIter(&end2)
					buffer2.Delete(&start2, &end2)
					if len(errorstr) > 0 {
						buffer2.Insert(&start2, string(errorstr+util.GetTabSim().Errores))

						strArray := strings.Split(filename, ".x")
						f, err := os.OpenFile(strArray[0]+".tx", os.O_WRONLY|os.O_CREATE, 0600)
						if err != nil {
							panic(err)
						}
						defer f.Close()
						if _, err = f.WriteString(errorstr); err != nil {
							panic(err)
						}
					} else {
						buffer2.Insert(&start2, "Correcto!"+util.GetTabSim().Errores)
					}
					///*******************************************************
					///*******************************************************
					tabsimlines := util.GetTabSim().ReturnTable()
					buffer5.GetStartIter(&start5)
					buffer5.GetEndIter(&end5)
					buffer5.Delete(&start5, &end5)
					if len(tabsimlines) > 0 {
						buffer5.Insert(&start5, string(tabsimlines))
					}
					///*******************************************************
					///*******************************************************

					objectCode := util.GetAssembler().ObjCodeXE()
					util.GetTabSim().PcToHex()
					var obj string
					for i := 0; i < len(objectCode); i++ {

						if len(objectCode[i]) > 10 {

							obj += objectCode[i]
						}
						if i == len(objectCode)-1 {
							obj += objectCode[i]
						}
					}
					buffer3.GetStartIter(&start3)
					buffer3.GetEndIter(&end3)
					buffer3.Delete(&start3, &end3)
					if len(obj) > 0 {
						buffer3.Insert(&start3, string(obj))
					}
					f2 := newFile(strings.Split(filename, ".x")[0], ".ox")
					if _, err = f2.WriteString(obj); err != nil {
						panic(err)
					}
					///*******************************************************
					///*******************************************************
					var todostr string
					lines, err := readLines(filename)
					if err == nil {
						addrsstr := util.GetTabSim().GetProgPcStr()
						//fmt.Println(addrsstr)
						for i := 0; i < len(lines); i++ {
							if addrsstr[i+1] == "" {
								addrsstr[i+1] = addrsstr[i]
								todostr += addrsstr[i] + "\t" + lines[i] + "\tError" + "\n"
							} else {
								todostr += addrsstr[i] + "\t" + lines[i] + "\t \t"
								if i != 0 && i < len(lines)-1 {
									todostr += util.GetAssembler().Hexcode[i-1] + "\n"
								} else {
									todostr += "\n"
								}
							}
						}
						//util.GetTabSim().PrintProgpc()
						//fmt.Print(todostr)
						addrsstr = nil
					}
					buffer4.GetStartIter(&start4)
					buffer4.GetEndIter(&end4)
					buffer4.Delete(&start4, &end4)
					if len(obj) > 0 {
						buffer4.Insert(&start4, string(todostr))
					}
				}
			}
			entry.SetText("En la ventana debug se encuentran los errores lexicos y sintacticos del programa")
			fmt.Println("Dialog OK!")

			messagedialog2.Destroy()
		})
		messagedialog2.Run()
	})
	buttons.Add(button2)
	framebox2.PackStart(buttons, false, false, 0)

	/////////////////////////////////////////////

	button3 := gtk.NewButtonWithLabel("Cargador...")
	button3.Clicked(func() {
		strArray2 := strings.Split(filename, ".s")
		f2, err := os.OpenFile(strArray2[0]+".o", os.O_WRONLY|os.O_CREATE, 0600)
		var obj string
		objectCode := util.GetAssembler().ObjCode()
		for i := 0; i < len(objectCode); i++ {

			if len(objectCode[i]) > 10 {

				obj += objectCode[i]
			}
			if i == len(objectCode)-1 {
				obj += objectCode[i]
			}
		}
		if _, err = f2.WriteString(obj); err != nil {
			panic(err)
		}
		//nombre := strings.Split(strArray2[0], "work")

		cmd := exec.Command("script.sh", strArray2[0]+".o")

		err = cmd.Start()
		if err != nil {
			log.Fatal(err)
		}
		log.Printf("Waiting for command to finish...")
		//err = cmd.Wait()
		log.Printf("Command finished with error: %v", err)
	})

	buttons.Add(button3)

	////////////////////////////

	buttons = gtk.NewHBox(false, 1)

	//--------------------------------------------------------
	// GtkMenuItem ///***********SAVE FILE*****************///
	//--------------------------------------------------------
	cascademenu := gtk.NewMenuItemWithMnemonic("_File")
	menubar.Append(cascademenu)
	submenu := gtk.NewMenu()
	cascademenu.SetSubmenu(submenu)

	var menuitem2 *gtk.MenuItem
	menuitem2 = gtk.NewMenuItemWithMnemonic("G_uardar")
	menuitem2.Connect("activate", func() {
		strArray := strings.Split(filename, ".s")
		if len(strArray) <= 1 {
			strArray = strings.Split(filename, ".x")
		}
		if len(strArray) > 1 && len(filename) > 0 {
			statusbar.Push(context_id, filename)
			var s string
			buffer.GetStartIter(&start)
			buffer.GetEndIter(&end)
			s = buffer.GetText(&start, &end, true)
			fmt.Println(filename)
			err := ioutil.WriteFile(filename, []byte(s), 0644)
			if err != nil {
				panic(err)
			}
		} else {

			filechooserdialog := gtk.NewFileChooserDialog(
				"Choose File...",
				button.GetTopLevelAsWindow(),
				gtk.FILE_CHOOSER_ACTION_SAVE,
				gtk.STOCK_OK,
				gtk.RESPONSE_ACCEPT)
			filter := gtk.NewFileFilter()
			///***ALLOWS SIC AND SIC-XE EXTENSION***///
			filter.AddPattern("*.s")
			filter.AddPattern("*.x")
			filechooserdialog.AddFilter(filter)
			filechooserdialog.Response(func() {
				/*aqui va el dialogo */
				statusbar.Push(context_id, filename)
				filename = filechooserdialog.GetFilename()
				if len(filename) > 0 {
					fmt.Println(filechooserdialog.GetFilename())
					var s string
					buffer.GetStartIter(&start)
					buffer.GetEndIter(&end)
					s = buffer.GetText(&start, &end, true)

					err := ioutil.WriteFile(filename, []byte(s), 0644)
					if err != nil {
						panic(err)
					}
					entry.SetText("Haz click en el boton analizar")
				}
				filechooserdialog.Destroy()
			})
			filechooserdialog.Run()

		}
	})
	submenu.Append(menuitem2)

	var menuitem *gtk.MenuItem
	menuitem = gtk.NewMenuItemWithMnemonic("S_alir")
	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() {
		textview.SetSensitive(!checkmenuitem.GetActive())
		textview2.SetSensitive(!checkmenuitem.GetActive())
	})
	submenu.Append(checkmenuitem)

	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-SIC sim!")
		dialog.SetProgramName("Go-SIC sim")
		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.Push(context_id, "No hay archivo seleccionado")

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

	//--------------------------------------------------------
	// Event
	//--------------------------------------------------------
	window.Add(vbox)
	window.SetSizeRequest(600, 600)
	window.ShowAll()
	gtk.Main()
}
Ejemplo n.º 19
0
Archivo: gui.go Proyecto: mattn/gocalc
func main() {
	gtk.Init(&os.Args)
	display = gtk.NewEntry()
	display.SetAlignment(1.0)
	window := gtk.NewWindow(gtk.WINDOW_TOPLEVEL)
	window.SetTitle("Simple Go Calculator")
	window.Connect("destroy", Quit)

	// Vertical box containing all components
	vbox := gtk.NewVBox(false, 1)

	// Menu bar
	menubar := gtk.NewMenuBar()
	vbox.PackStart(menubar, false, false, 0)

	// Add calculator display to vertical box
	display.SetCanFocus(false) // disable focus on calcuator display
	vbox.Add(display)

	// Menu items
	filemenu := gtk.NewMenuItemWithMnemonic("_File")
	menubar.Append(filemenu)
	filesubmenu := gtk.NewMenu()
	filemenu.SetSubmenu(filesubmenu)

	aboutmenuitem := gtk.NewMenuItemWithMnemonic("_About")
	aboutmenuitem.Connect("activate", func() {
		messagedialog := gtk.NewMessageDialog(
			window.GetTopLevelAsWindow(),
			gtk.DIALOG_MODAL,
			gtk.MESSAGE_INFO,
			gtk.BUTTONS_OK,
			"Simple Go Calculator")
		messagedialog.Response(func() {})
		messagedialog.Run()
		messagedialog.Destroy()
	},
		nil)
	filesubmenu.Append(aboutmenuitem)

	resetmenuitem := gtk.NewMenuItemWithMnemonic("_Reset")
	resetmenuitem.Connect("activate", func() { Reset(); display.SetText("0") })
	filesubmenu.Append(resetmenuitem)

	exitmenuitem := gtk.NewMenuItemWithMnemonic("E_xit")
	exitmenuitem.Connect("activate", Quit)
	filesubmenu.Append(exitmenuitem)

	// Vertical box containing all buttons
	buttons := gtk.NewVBox(false, 5)

	bmap := map[string]*gtk.Button{}

	for i := 0; i < 4; i++ {
		hbox := gtk.NewHBox(false, 5) // a horizontal box for each 4 buttons
		for j := 0; j < 4; j++ {
			b := gtk.NewButtonWithLabel(string(nums[i*4+j]))
			b.Clicked(Input(b)) //add click event
			hbox.Add(b)
			bmap[string(nums[i*4+j])] = b
		}
		buttons.Add(hbox) // add horizonatal box to vertical buttons' box
	}

	vbox.Add(buttons)

	window.Connect("key-press-event", func(ctx *glib.CallbackContext) bool {
		arg := ctx.Args(0)
		kev := *(**gdk.EventKey)(unsafe.Pointer(&arg))
		c := (string(uint8(kev.Keyval % 0xff)))
		if kev.Keyval == gdk.KEY_Return {
			c = "="
			return true
		}
		if b, ok := bmap[c]; ok {
			Input(b)()
			b.GrabFocus()
		} else if kev.Keyval == gdk.KEY_Delete {
			Reset()
			display.SetText("0")
			return true
		}
		return false
	})

	window.Add(vbox)
	window.SetSizeRequest(250, 250)
	window.ShowAll()
	gtk.Main()
}
Ejemplo n.º 20
0
func main() {
	var menuitem *gtk.MenuItem
	gtk.Init(nil)
	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) {
		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, _ := path.Split(os.Args[0])
	imagefile := path.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() {
		println("scale:", int(scale.GetValue()))
	})
	framebox2.Add(scale)

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

	//--------------------------------------------------------
	// GtkButton
	//--------------------------------------------------------
	button := gtk.NewButtonWithLabel("Button with label")
	button.Clicked(func() {
		println("button clicked:", button.GetLabel())
		messagedialog := gtk.NewMessageDialog(
			button.GetTopLevelAsWindow(),
			gtk.DIALOG_MODAL,
			gtk.MESSAGE_INFO,
			gtk.BUTTONS_OK,
			entry.GetText())
		messagedialog.Response(func() {
			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() {
				println(filechooserdialog.GetFilename())
				filechooserdialog.Destroy()
			})
			filechooserdialog.Run()
			messagedialog.Destroy()
		})
		messagedialog.Run()
	})
	buttons.Add(button)

	//--------------------------------------------------------
	// GtkFontButton
	//--------------------------------------------------------
	fontbutton := gtk.NewFontButton()
	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.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.NewComboBoxEntryNewText()
	comboboxentry.AppendText("Monkey")
	comboboxentry.AppendText("Tiger")
	comboboxentry.AppendText("Elephant")
	comboboxentry.Connect("changed", func() {
		println("value:", comboboxentry.GetActiveText())
	})
	combos.Add(comboboxentry)

	//--------------------------------------------------------
	// GtkComboBox
	//--------------------------------------------------------
	combobox := gtk.NewComboBoxNewText()
	combobox.AppendText("Peach")
	combobox.AppendText("Banana")
	combobox.AppendText("Apple")
	combobox.SetActive(1)
	combobox.Connect("changed", func() {
		println("value:", combobox.GetActiveText())
	})
	combos.Add(combobox)

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

	//--------------------------------------------------------
	// GtkTextView
	//--------------------------------------------------------
	swin := gtk.NewScrolledWindow(nil, nil)
	swin.SetPolicy(gtk.POLICY_AUTOMATIC, gtk.POLICY_AUTOMATIC)
	swin.SetShadowType(gtk.SHADOW_IN)
	textview := gtk.NewTextView()
	var start, end gtk.TextIter
	buffer := textview.GetBuffer()
	buffer.GetStartIter(&start)
	buffer.Insert(&start, "Hello ")
	buffer.GetEndIter(&end)
	buffer.Insert(&end, "World!")
	tag := buffer.CreateTag("bold", map[string]string{
		"background": "#FF0000", "weight": "700"})
	buffer.GetStartIter(&start)
	buffer.GetEndIter(&end)
	buffer.ApplyTag(tag, &start, &end)
	swin.Add(textview)
	framebox2.Add(swin)

	buffer.Connect("changed", func() {
		println("changed")
	})

	//--------------------------------------------------------
	// GtkMenuItem
	//--------------------------------------------------------
	cascademenu := gtk.NewMenuItemWithMnemonic("_File")
	menubar.Append(cascademenu)
	submenu := gtk.NewMenu()
	cascademenu.SetSubmenu(submenu)

	menuitem = gtk.NewMenuItemWithMnemonic("E_xit")
	menuitem.Connect("activate", func() {
		gtk.MainQuit()
	})
	submenu.Append(menuitem)

	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() {
			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, _ := path.Split(os.Args[0])
		imagefile := path.Join(dir, "../../data/mattn-logo.png")
		pixbuf, _ := gdkpixbuf.NewFromFile(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()
}
Ejemplo n.º 21
0
Archivo: main.go Proyecto: kch42/biomed
func (g *GUI) betaWarning() {
	dlg := gtk.NewMessageDialog(g.window, gtk.DIALOG_MODAL|gtk.DIALOG_DESTROY_WITH_PARENT, gtk.MESSAGE_INFO, gtk.BUTTONS_OK, "This software is currently in beta.\nAlthough everything seems to work, you should make a backup of your maps, just in case!")
	dlg.Run()
	dlg.Destroy()
}
Ejemplo n.º 22
0
func event_play(x, y int) (bool, int) {
	vic, stones, err := game.Play(x, y)
	if err != nil {
		return false, vic
	}
	context_id := statusbar.GetContextId("go-gtk")
	statusbar.Push(context_id, fmt.Sprintf("[Player 1/2 : %d/%d stone before death] Last move is Player %d : %d/%d",
		game.countTake[1], game.countTake[0], player, x+1, y+1))
	if (hintx != lastx || hinty != lasty) && (hintx >= 0 && hinty >= 0) {
		draw_square(gc, pixmap, hintx, hinty)
	}
	for _, stone := range stones {
		countTake++
		if countTake > 19 {
			break
		}
		draw_square(gc, pixmap, stone[0], stone[1])
		if player == 1 {
			gc.SetRgbFgColor(gdk.NewColor("white"))
		} else {
			gc.SetRgbFgColor(gdk.NewColor("black"))
		}
		tmpx := 800
		tmpy := countTake * INTER
		tmpx = ((tmpx-INTER/2)/INTER)*INTER + INTER
		tmpy = ((tmpy-INTER/2)/INTER)*INTER + INTER
		pixmap.GetDrawable().DrawArc(gc, true, tmpx-(STONE/2)+10,
			tmpy-(STONE/2), STONE, STONE, 0, 64*360)
	}
	if player == 1 {
		gc.SetRgbFgColor(gdk.NewColor("black"))
		player = 2
	} else {
		gc.SetRgbFgColor(gdk.NewColor("white"))
		player = 1
	}
	lastx = x
	lasty = y
	x = x*INTER + INTER
	y = y*INTER + INTER
	pixmap.GetDrawable().DrawArc(gc, true, x-(STONE/2), y-(STONE/2), STONE, STONE, 0, 64*360)
	if vic != 0 {
		WINNER = fmt.Sprintf("And the winner is \"Player %d\"!", vic)
		context_id := statusbar.GetContextId("go-gtk")
		statusbar.Push(context_id, WINNER)
		stopGame = true
	}
	drawingarea.GetWindow().Invalidate(nil, false)
	if vic != 0 {
		messagedialog := gtk.NewMessageDialog(
			statusbar.GetTopLevelAsWindow(),
			gtk.DIALOG_MODAL,
			gtk.MESSAGE_INFO,
			gtk.BUTTONS_OK,
			WINNER)
		messagedialog.Response(func() {
			messagedialog.Destroy()
		})
		messagedialog.Run()
	}
	return true, vic
}