本文整理汇总了Golang中github.com/mattn/go-gtk/gtk.MenuItem类的典型用法代码示例。如果您正苦于以下问题:Golang MenuItem类的具体用法?Golang MenuItem怎么用?Golang MenuItem使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了MenuItem类的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: createMenu
func createMenu() *gtk.MenuBar {
menubar := gtk.NewMenuBar()
vpaned := gtk.NewVPaned()
//--------------------------------------------------------
// GtkMenuItem
//--------------------------------------------------------
cascademenu := gtk.NewMenuItemWithMnemonic("_File")
menubar.Append(cascademenu)
submenu := gtk.NewMenu()
cascademenu.SetSubmenu(submenu)
var menuitem *gtk.MenuItem
menuitem = gtk.NewMenuItemWithMnemonic("E_xit")
menuitem.Connect("activate", func() {
gtk.MainQuit()
})
submenu.Append(menuitem)
cascademenu = gtk.NewMenuItemWithMnemonic("_View")
menubar.Append(cascademenu)
submenu = gtk.NewMenu()
cascademenu.SetSubmenu(submenu)
checkmenuitem := gtk.NewCheckMenuItemWithMnemonic("_Disable")
checkmenuitem.Connect("activate", func() {
vpaned.SetSensitive(!checkmenuitem.GetActive())
})
submenu.Append(checkmenuitem)
cascademenu = gtk.NewMenuItemWithMnemonic("_Help")
menubar.Append(cascademenu)
submenu = gtk.NewMenu()
cascademenu.SetSubmenu(submenu)
return menubar
}
示例2: main
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,
//.........这里部分代码省略.........
示例3: InitializeGUI
//.........这里部分代码省略.........
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***///
示例4: main
//.........这里部分代码省略.........
buffer := textview.GetBuffer()
swin.Add(textview)
//--------------------------------------------------------
// Run button
//--------------------------------------------------------
runbutton := gtk.NewButtonWithLabel("Run")
runbutton.Clicked(func() {
arg.inputPath = ientry.GetText()
arg.filterPath = fentry.GetText()
arg.outputPath = oentry.GetText()
num, err := getKeysearchWords(arg)
buffer.GetStartIter(&end)
if err != nil {
log.Println(err)
buffer.Insert(&end, err.Error()+"\n")
} else {
buffer.Insert(&end, "GoMADScan found "+strconv.Itoa(num)+
" modification sites.\nThe result is written into "+arg.outputPath+".\n")
}
})
buttons.Add(runbutton)
framebox2.PackStart(buttons, false, false, 0)
//--------------------------------------------------------
// GtkVSeparator
//--------------------------------------------------------
vsep := gtk.NewVSeparator()
framebox2.PackStart(vsep, false, false, 0)
//--------------------------------------------------------
// GtkTextView
//--------------------------------------------------------
framebox2.Add(swin)
// buffer.Connect("changed", func() {
// // fmt.Println("changed")
// })
//--------------------------------------------------------
// GtkMenuItem
//--------------------------------------------------------
cascademenu := gtk.NewMenuItemWithMnemonic("_File")
menubar.Append(cascademenu)
submenu := gtk.NewMenu()
cascademenu.SetSubmenu(submenu)
var menuitem *gtk.MenuItem
menuitem = gtk.NewMenuItemWithMnemonic("_Exit")
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)
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("GoMADScan")
dialog.SetProgramName("GoMADScan")
dialog.SetAuthors(authors())
dialog.SetLicense("LGPL v3")
dialog.SetWrapLicense(true)
dialog.Run()
dialog.Destroy()
})
submenu.Append(menuitem)
//--------------------------------------------------------
// GtkStatusbar
//--------------------------------------------------------
statusbar := gtk.NewStatusbar()
context_id := statusbar.GetContextId("GoMADScan v0")
statusbar.Push(context_id, "Simple search GUI")
framebox2.PackStart(statusbar, false, false, 0)
//--------------------------------------------------------
// Event
//--------------------------------------------------------
window.Add(vbox)
window.SetSizeRequest(600, 600)
window.ShowAll()
gtk.Main()
}
示例5: main
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
//--------------------------------------------------------
//.........这里部分代码省略.........