Exemplo n.º 1
0
Arquivo: rot13.go Projeto: DaviWei/iup
func main() {
	iup.Open()
	defer iup.Close()

	menu := iup.Menu(
		iup.Submenu("File",
			iup.Menu(
				iup.Item("Load File", (iup.ActionFunc)(onLoadFile)),
				iup.Item("Rotate", (iup.ActionFunc)(onRotate)),
				iup.Item("Quit", (iup.ActionFunc)(onQuit)))),
		iup.Submenu("Help",
			iup.Menu(
				iup.Item("About Iup", (iup.ActionFunc)(onAboutIup)),
				iup.Item("About go-iup", (iup.ActionFunc)(onAboutIupGo)))))

	text = iup.Text("MULTILINE=YES,EXPAND=YES,WORDWRAP=YES,SIZE=250x100,SCROLLBAR=YES")
	mainBox := iup.SetAttrs(iup.Vbox(
		iup.Label("Text to be rotated:"),
		text,
		iup.SetAttrs(iup.Hbox(
			iup.Button("Load File", "PADDING=3x3", (iup.ActionFunc)(onLoadFile)),
			iup.Button("Rotate", "PADDING=3x3", (iup.ActionFunc)(onRotate)),
			iup.Button("Quit", "PADDING=3x3", (iup.ActionFunc)(onQuit)),
		), "MARGIN", "0x0"),
	), "MARGIN", "5x5", "GAP", "3")

	mainDlg = iup.SetAttrs(iup.Dialog(mainBox), "TITLE", "Rot 13")
	iup.SetAttributeHandle(mainDlg, "MENU", menu)
	iup.Show(mainDlg)

	iup.MainLoop()
}
Exemplo n.º 2
0
Arquivo: rot13.go Projeto: DaviWei/iup
func onLoadFile(ih *iup.Ihandle) int {
	dlg := iup.FileDlg("ALLOWNEW=NO,DIALOGTYPE=Open,TITLE=Open")
	iup.SetAttributeHandle(dlg, "PARENTDIALOG", mainDlg)
	iup.Popup(dlg, iup.CENTER, iup.CENTER)
	if iup.GetInt(dlg, "STATUS") == -1 {
		return iup.IGNORE
	}

	filename := iup.GetAttribute(dlg, "VALUE")
	iup.Destroy(dlg)

	content, err := ioutil.ReadFile(filename)
	if err != nil {
		iup.Message("Error", fmt.Sprintf("Error: %s", err))
		return iup.IGNORE
	}

	iup.StoreAttribute(text, "VALUE", string(content))

	return iup.IGNORE
}