本文整理汇总了Golang中github.com/mattn/go-gtk/gtk.NewMenu函数的典型用法代码示例。如果您正苦于以下问题:Golang NewMenu函数的具体用法?Golang NewMenu怎么用?Golang NewMenu使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了NewMenu函数的19个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。
示例1: mkMenuBar
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
}
开发者ID:kch42,项目名称:biomed,代码行数:48,代码来源:main.go
示例2: main
func main() {
gtk.Init(&os.Args)
glib.SetApplicationName("go-gtk-statusicon-example")
mi := gtk.NewMenuItemWithLabel("Popup!")
mi.Connect("activate", func() {
gtk.MainQuit()
})
nm := gtk.NewMenu()
nm.Append(mi)
nm.ShowAll()
si := gtk.NewStatusIconFromStock(gtk.STOCK_FILE)
si.SetTitle("StatusIcon Example")
si.SetTooltipMarkup("StatusIcon Example")
si.Connect("popup-menu", func(cbx *glib.CallbackContext) {
nm.Popup(nil, nil, gtk.StatusIconPositionMenu, si, uint(cbx.Args(0)), uint(cbx.Args(1)))
})
println(`
Can you see statusicon in systray?
If you don't see it and if you use 'unity', try following.
# gsettings set com.canonical.Unity.Panel systray-whitelist \
"$(gsettings get com.canonical.Unity.Panel systray-whitelist \|
sed -e "s/]$/, 'go-gtk-statusicon-example']/")"
`)
gtk.Main()
}
开发者ID:JessonChan,项目名称:go-gtk,代码行数:31,代码来源:statusicon.go
示例3: main
func main() {
FreeConsole()
gtk.Init(nil)
screenHeight := gdk.ScreenHeight()
screenWidth := gdk.ScreenWidth()
window := gtk.NewWindow(gtk.WINDOW_TOPLEVEL)
window.SetTitle("mgc")
window.SetIconName("gtk-about")
window.Connect("destroy", func() {
gtk.MainQuit()
})
vbox := gtk.NewVBox(false, 0)
menubar := gtk.NewMenuBar()
vbox.PackStart(menubar, false, false, 0)
menu := gtk.NewMenuItemWithMnemonic("_File")
menubar.Append(menu)
submenu := gtk.NewMenu()
menu.SetSubmenu(submenu)
menuitem := gtk.NewMenuItemWithMnemonic("E_xit")
menuitem.Connect("activate", func() {
gtk.MainQuit()
})
submenu.Append(menuitem)
hpaned := gtk.NewHPaned()
leftFrame := gtk.NewFrame("")
rightFrame := gtk.NewFrame("")
leftLabel := gtk.NewLabel("Left")
rightLabel := gtk.NewLabel("Right")
leftFrame.Add(leftLabel)
rightFrame.Add(rightLabel)
hpaned.Pack1(leftFrame, true, false)
hpaned.Pack2(rightFrame, true, false)
vbox.Add(hpaned)
window.Add(vbox)
window.SetSizeRequest(screenWidth/4*3, screenHeight/4*3)
window.ShowAll()
gtk.Main()
}
开发者ID:vsannikov,项目名称:mgc,代码行数:54,代码来源:main.go
示例4: 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
}
开发者ID:paua-app,项目名称:curly-octo-moo,代码行数:37,代码来源:test002.go
示例5: mkQuickOpen
func (g *GUI) mkQuickOpen() (*gtk.Menu, bool) {
maps := allMaps()
if (maps == nil) || (len(maps) == 0) {
return nil, false
}
menu := gtk.NewMenu()
for name, p := range maps {
mitem := gtk.NewMenuItemWithLabel(name)
p2 := p
mitem.Connect("activate", func() { g.openWorld(p2) })
menu.Append(mitem)
}
return menu, true
}
开发者ID:kch42,项目名称:biomed,代码行数:16,代码来源:main.go
示例6: newMenuFromItems
// newMenuFromItems returns a GTK menu from a pathtree.Items map. This function
// calls itself recursively and takes a relpath used to build the absolute path
// needed by the pass command.
func newMenuFromItems(items pathtree.Items, relpath string) *gtk.Menu {
result := gtk.NewMenu()
for k, v := range items {
mi := gtk.NewMenuItemWithLabel(k)
abspath := relpath + k
if len(v) > 0 {
mi.SetSubmenu(newMenuFromItems(v, abspath+"/"))
} else {
mi.Connect("activate", func() {
exec.Command("pass", abspath, "-c").Run()
})
}
result.Append(mi)
}
return result
}
开发者ID:marcusolsson,项目名称:passtray,代码行数:23,代码来源:main.go
示例7: main
func main() {
gtk.Init(nil)
window := gtk.NewWindow(gtk.WINDOW_TOPLEVEL)
window.SetPosition(gtk.WIN_POS_CENTER)
window.SetTitle("GoMADScan")
window.SetIconName("GoMADScan-info")
window.Connect("destroy", func(ctx *glib.CallbackContext) {
// fmt.Println("got destroy!", ctx.Data().(string))
gtk.MainQuit()
}, "")
//--------------------------------------------------------
// 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("")
framebox1 := gtk.NewVBox(false, 1)
frame1.Add(framebox1)
frame2 := gtk.NewFrame("Column index for search (0: all columns)")
framebox2 := gtk.NewVBox(false, 1)
frame2.Add(framebox2)
vpaned.Pack1(frame1, false, false)
vpaned.Pack2(frame2, false, false)
//--------------------------------------------------------
// GtkImage
//--------------------------------------------------------
dir := os.Getenv("GOPATH")
if dir == "" {
dir = filepath.Join(os.Getenv("HOME"), "/go")
}
imagefile := filepath.Join(dir, "/src/github.com/carushi/GoMADScan/image/logo.png")
label := gtk.NewLabel("Go-based Modification associated database scanner")
label.ModifyFontEasy("DejaVu Serif 15")
framebox1.PackStart(label, false, true, 0)
image := gtk.NewImageFromFile(imagefile)
framebox1.Add(image)
//--------------------------------------------------------
// Data input and output filename
//--------------------------------------------------------
arg := arguments{
0,
filepath.Join(dir, "/src/github.com/carushi/GoMADScan/data/Sample_modification_site"),
filepath.Join(dir, "/src/github.com/carushi/GoMADScan/data/Ras_gene_synonym.txt"),
filepath.Join(dir, "/src/github.com/carushi/GoMADScan/data/output.txt"),
false,
true,
"\t"}
//--------------------------------------------------------
// GtkScale
//--------------------------------------------------------
scale := gtk.NewHScaleWithRange(0, 20, 1)
scale.Connect("value-changed", func() {
arg.column = int(scale.GetValue())
// fmt.Println("scale:", int(scale.GetValue()))
})
framebox2.Add(scale)
//--------------------------------------------------------
// InputArea
//--------------------------------------------------------
ientry := gtk.NewEntry()
ientry.SetText(arg.inputPath)
inputs := gtk.NewHBox(false, 1)
button := gtk.NewButtonWithLabel("Choose input file")
button.Clicked(func() {
//--------------------------------------------------------
// GtkFileChooserDialog
//--------------------------------------------------------
filechooserdialog := gtk.NewFileChooserDialog(
"Choose File...",
button.GetTopLevelAsWindow(),
gtk.FILE_CHOOSER_ACTION_OPEN,
gtk.STOCK_OK,
gtk.RESPONSE_ACCEPT)
filter := gtk.NewFileFilter()
filter.AddPattern("*")
filechooserdialog.AddFilter(filter)
filechooserdialog.Response(func() {
//.........这里部分代码省略.........
开发者ID:carushi,项目名称:GoMADScan,代码行数:101,代码来源:GoMADScan.go
示例8: main
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()
}
开发者ID:abiosoft,项目名称:gocalc,代码行数:69,代码来源:gui.go
示例9: main
// main reads the config file, connects to each IMAP server in a separate thread
// and watches the notify channel for messages telling it to update the status
// icon.
func main() {
conf, err := goconf.ReadConfigFile(os.Getenv("HOME") + "/.hasmailrc")
if err != nil {
fmt.Println("Failed to load configuration file, exiting...\n", err)
return
}
// This channel will be used to tell us if we should exit the program
quit := make(chan os.Signal, 1)
signal.Notify(quit, os.Interrupt)
// GTK engage!
gtk.Init(&os.Args)
glib.SetApplicationName("hasmail")
defer gtk.MainQuit()
// Set up the tray icon
si := gtk.NewStatusIconFromStock(gtk.STOCK_DISCONNECT)
si.SetTitle("hasmail")
si.SetTooltipMarkup("Not connected")
// Set up the tray icon right click menu
mi := gtk.NewMenuItemWithLabel("Quit")
mi.Connect("activate", func() {
quit <- syscall.SIGINT
})
nm := gtk.NewMenu()
nm.Append(mi)
nm.ShowAll()
si.Connect("popup-menu", func(cbx *glib.CallbackContext) {
nm.Popup(nil, nil, gtk.StatusIconPositionMenu, si, uint(cbx.Args(0)), uint32(cbx.Args(1)))
})
/* If the user clicks the tray icon, here's what happens:
* - if only a single account has new emails, and a click command has been
* specified for that account, execute it
* - if the user has specified a default click handler, execute that
* - otherwise, do nothing
*/
si.Connect("activate", func(cbx *glib.CallbackContext) {
command, geterr := conf.GetString("default", "click")
nonZero := 0
nonZeroAccount := ""
for account, unseenList := range parts.Unseen {
if len(unseenList) > 0 {
nonZero++
nonZeroAccount = account
}
}
// Can't just use HasOption here because that also checks "default" section,
// even though Get* doesn't...
if nonZero == 1 {
acommand, ageterr := conf.GetString(nonZeroAccount, "click")
if ageterr == nil {
command = acommand
geterr = ageterr
}
}
if geterr == nil {
fmt.Printf("Executing user command: %s\n", command)
shell := os.Getenv("SHELL")
if shell == "" {
shell = "/bin/sh"
}
sh := exec.Command(shell, "-c", command)
sh.Env = os.Environ()
err = sh.Start()
if err != nil {
fmt.Printf("Failed to run command '%s' on click\n", command)
fmt.Println(err)
}
} else {
fmt.Println("No action defined for click\n", geterr)
}
})
go gtk.Main()
// Connect to all accounts
sections := conf.GetSections()
notify := make(chan bool, len(sections))
for _, account := range sections {
// default isn't really an account
if account == "default" {
continue
}
initConnection(notify, conf, account)
}
// Let the user know that we've now initiated all the connections
si.SetFromStock(gtk.STOCK_CONNECT)
si.SetTooltipText("Connecting")
//.........这里部分代码省略.........
开发者ID:jonhoo,项目名称:hasmail,代码行数:101,代码来源:hasmail.go
示例10: main
func main() {
if len(os.Args) < 2 {
filename = ""
} else {
filename = os.Args[1]
}
gtk.Init(nil)
window := gtk.NewWindow(gtk.WINDOW_TOPLEVEL)
window.SetTitle(filename)
window.Connect("destroy", gtk.MainQuit)
vbox := gtk.NewVBox(false, 1)
menubar := gtk.NewMenuBar()
vbox.PackStart(menubar, false, false, 0)
webview = webkit.NewWebView()
vbox.Add(webview)
filemenu := gtk.NewMenuItemWithMnemonic("_File")
menubar.Append(filemenu)
submenu := gtk.NewMenu()
filemenu.SetSubmenu(submenu)
menu_open := gtk.NewMenuItemWithMnemonic("_Open")
menu_open.Connect("activate", func() {
filechooserdialog := gtk.NewFileChooserDialog(
"Choose file",
window,
gtk.FILE_CHOOSER_ACTION_OPEN,
gtk.STOCK_OK,
gtk.RESPONSE_ACCEPT)
filter := gtk.NewFileFilter()
filter.AddPattern("*.md")
filter.AddPattern("*.markdown")
filter.SetName("Markdown files")
filechooserdialog.AddFilter(filter)
filechooserdialog.Response(func() {
filename = (filechooserdialog.GetFilename())
filechooserdialog.Destroy()
})
filechooserdialog.Run()
reload()
})
submenu.Append(menu_open)
menu_reload = gtk.NewMenuItemWithMnemonic("_Reload")
menu_reload.Connect("activate", func() {
reload()
})
submenu.Append(menu_reload)
menu_exit = gtk.NewMenuItemWithMnemonic("E_xit")
menu_exit.Connect("activate", func() {
gtk.MainQuit()
})
submenu.Append(menu_exit)
viewmenu := gtk.NewMenuItemWithMnemonic("_View")
menubar.Append(viewmenu)
viewsubmenu := gtk.NewMenu()
viewmenu.SetSubmenu(viewsubmenu)
menu_dark := gtk.NewCheckMenuItemWithMnemonic("D_ark Theme")
menu_dark.Connect("activate", func() {
if menu_dark.GetActive() {
dark_theme = true
} else {
dark_theme = false
}
reload()
})
viewsubmenu.Append(menu_dark)
window.Add(vbox)
window.SetSizeRequest(480, 600)
bytesSlice := bytesFromXpmData(xpm_data)
icon_file := "/tmp/hackdown-icon.xpm"
ioutil.WriteFile(icon_file, bytesSlice, os.ModePerm)
window.SetIconFromFile(icon_file)
window.ShowAll()
webview.LoadString(getContent(), "text/html", "utf-8", ".")
gtk.Main()
}
开发者ID:thefryscorer,项目名称:hackdown,代码行数:88,代码来源:main.go
示例11: init_tabby
func init_tabby() {
init_navigation()
init_inotify()
search_view.Init()
source_buf = gtksourceview.NewSourceBuffer()
source_buf.Connect("paste-done", paste_done_cb, nil)
source_buf.Connect("mark-set", mark_set_cb, nil)
source_buf.Connect("modified-changed", buf_changed_cb, nil)
init_lang()
source_buf.CreateTag("instance", map[string]string{"background": "#FF8080"})
tree_store = gtk.NewTreeStore(glib.G_TYPE_STRING)
tree_view = file_tree.NewFileTree()
tree_view.ModifyFontEasy("Regular 8")
tree_model = tree_store.ToTreeModel()
tree_view.SetModel(tree_model)
tree_view.SetHeadersVisible(false)
tree_view.Connect("cursor-changed", tree_view_select_cb, nil)
error_view = gtk.NewTextView()
error_view.ModifyFontEasy("Monospace Regular 8")
error_view.SetEditable(false)
error_buf = error_view.GetBuffer()
source_view = gtksourceview.NewSourceViewWithBuffer(source_buf)
source_view.ModifyFontEasy("Monospace Regular 10")
source_view.SetAutoIndent(true)
source_view.SetHighlightCurrentLine(true)
source_view.SetShowLineNumbers(true)
source_view.SetRightMarginPosition(80)
source_view.SetShowRightMargin(true)
source_view.SetIndentWidth(2)
source_view.SetTabWidth(2)
source_view.SetInsertSpacesInsteadOfTabs(opt.space_not_tab)
source_view.SetDrawSpaces(gtksourceview.SOURCE_DRAW_SPACES_TAB)
source_view.SetSmartHomeEnd(gtksourceview.SOURCE_SMART_HOME_END_ALWAYS)
source_view.SetWrapMode(gtk.WRAP_WORD)
vbox := gtk.NewVBox(false, 0)
inner_hpaned := gtk.NewHPaned()
view_vpaned := gtk.NewVPaned()
outer_hpaned := gtk.NewHPaned()
outer_hpaned.Add1(inner_hpaned)
inner_hpaned.Add2(view_vpaned)
menubar := gtk.NewMenuBar()
vbox.PackStart(menubar, false, false, 0)
vbox.PackStart(outer_hpaned, true, true, 0)
file_item := gtk.NewMenuItemWithMnemonic("_File")
menubar.Append(file_item)
file_submenu := gtk.NewMenu()
file_item.SetSubmenu(file_submenu)
accel_group := gtk.NewAccelGroup()
new_item := gtk.NewMenuItemWithMnemonic("_New")
file_submenu.Append(new_item)
new_item.Connect("activate", new_cb, nil)
new_item.AddAccelerator("activate", accel_group, gdk.KEY_n, gdk.CONTROL_MASK, gtk.ACCEL_VISIBLE)
open_item := gtk.NewMenuItemWithMnemonic("_Open")
file_submenu.Append(open_item)
open_item.Connect("activate", open_cb, nil)
open_item.AddAccelerator("activate", accel_group, gdk.KEY_o, gdk.CONTROL_MASK, gtk.ACCEL_VISIBLE)
open_rec_item := gtk.NewMenuItemWithMnemonic("Open _Recursively")
file_submenu.Append(open_rec_item)
open_rec_item.Connect("activate", open_rec_cb, nil)
save_item := gtk.NewMenuItemWithMnemonic("_Save")
file_submenu.Append(save_item)
save_item.Connect("activate", save_cb, nil)
save_item.AddAccelerator("activate", accel_group, gdk.KEY_s, gdk.CONTROL_MASK, gtk.ACCEL_VISIBLE)
save_as_item := gtk.NewMenuItemWithMnemonic("Save _as")
file_submenu.Append(save_as_item)
save_as_item.Connect("activate", save_as_cb, nil)
close_item := gtk.NewMenuItemWithMnemonic("_Close")
file_submenu.Append(close_item)
close_item.Connect("activate", close_cb, nil)
close_item.AddAccelerator("activate", accel_group, gdk.KEY_w, gdk.CONTROL_MASK, gtk.ACCEL_VISIBLE)
exit_item := gtk.NewMenuItemWithMnemonic("E_xit")
file_submenu.Append(exit_item)
exit_item.Connect("activate", exit_cb, nil)
navigation_item := gtk.NewMenuItemWithMnemonic("_Navigation")
menubar.Append(navigation_item)
navigation_submenu := gtk.NewMenu()
navigation_item.SetSubmenu(navigation_submenu)
prev_instance_item := gtk.NewMenuItemWithMnemonic("_Previous Instance")
navigation_submenu.Append(prev_instance_item)
prev_instance_item.Connect("activate", prev_instance_cb, nil)
//.........这里部分代码省略.........
开发者ID:JessonChan,项目名称:tabby,代码行数:101,代码来源:main.go
示例12: main
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()
}
开发者ID:mattn,项目名称:gocalc,代码行数:90,代码来源:gui.go
示例13: main
func main() {
flag.Parse()
usr, err := user.Current()
if err != nil {
fmt.Println("Couldn't get home directory:", err)
return
}
file, err := ioutil.ReadFile(usr.HomeDir + "/.gpuush")
if err != nil {
fmt.Println("Config file error:", err)
return
}
err = json.Unmarshal(file, &conf)
if err != nil {
fmt.Println("Config file error:", err)
return
}
success := login(conf.Email, conf.Pass)
if !success {
return
}
if background {
quit := make(chan os.Signal, 1)
signal.Notify(quit, os.Interrupt)
gtk.Init(&os.Args)
glib.SetApplicationName("gpuush")
defer gtk.MainQuit()
si := gtk.NewStatusIconFromFile("/usr/local/share/gpuush/icon.png")
si.SetTitle("gpuush")
si.SetTooltipMarkup("gpuush")
nm := gtk.NewMenu()
mi := gtk.NewMenuItemWithLabel("Take Screenshot")
mi.Connect("activate", func() {
go takeScreenshot()
})
nm.Append(mi)
nm.ShowAll()
mi = gtk.NewMenuItemWithLabel("Quit")
mi.Connect("activate", func() {
quit <- syscall.SIGINT
})
nm.Append(mi)
nm.ShowAll()
si.Connect("popup-menu", func(cbx *glib.CallbackContext) {
nm.Popup(nil, nil, gtk.StatusIconPositionMenu, si, uint(cbx.Args(0)), uint32(cbx.Args(1)))
})
go gtk.Main()
for {
select {
case <-quit:
return
}
}
} else if screenshot {
takeScreenshot()
} else {
result := uploadFile(flag.Arg(0))
if len(result) > 0 {
notify(result)
copy(result)
} else {
notify("Upload failed")
}
}
}
开发者ID:xthexder,项目名称:gpuush,代码行数:77,代码来源:gpuush.go
示例14: main
func main() {
flag.Parse()
runtime.GOMAXPROCS(runtime.NumCPU())
common.SetDefaultGtkTheme()
machinePassword = uuid.New()[:4]
clremoton = newClient(&remoton.Client{Prefix: "/remoton", TLSConfig: &tls.Config{}})
sigs := make(chan os.Signal, 1)
signal.Notify(sigs, syscall.SIGHUP, syscall.SIGINT, syscall.SIGABRT, syscall.SIGKILL, syscall.SIGTERM)
go func() {
<-sigs
clremoton.Terminate()
}()
gtk.Init(nil)
window := gtk.NewWindow(gtk.WINDOW_TOPLEVEL)
window.SetPosition(gtk.WIN_POS_CENTER)
window.SetTitle("REMOTON CLIENT")
window.Connect("destroy", func(ctx *glib.CallbackContext) {
gtk.MainQuit()
clremoton.Terminate()
}, "quit")
window.SetIcon(common.GetIconGdkPixbuf())
appLayout := gtk.NewVBox(false, 1)
menu := gtk.NewMenuBar()
appLayout.Add(menu)
cascademenu := gtk.NewMenuItemWithMnemonic("_Help")
menu.Append(cascademenu)
submenu := gtk.NewMenu()
cascademenu.SetSubmenu(submenu)
menuitem := gtk.NewMenuItemWithMnemonic("_About")
menuitem.Connect("activate", func() {
dialog := common.GtkAboutDialog()
dialog.SetProgramName("Client Desktop")
dialog.SetComments("Share your desktop secure")
dialog.Run()
dialog.Destroy()
})
submenu.Append(menuitem)
hpaned := gtk.NewHPaned()
appLayout.Add(hpaned)
statusbar := gtk.NewStatusbar()
contextID := statusbar.GetContextId("remoton-desktop-client")
//---
//CONTROL
//---
frameControl := gtk.NewFrame("Controls")
controlBox := gtk.NewVBox(false, 1)
frameControl.Add(controlBox)
controlBox.Add(gtk.NewLabel("MACHINE ID"))
machineIDEntry := gtk.NewEntry()
machineIDEntry.SetEditable(false)
controlBox.Add(machineIDEntry)
machineAuthEntry := gtk.NewEntry()
machineAuthEntry.SetEditable(false)
controlBox.Add(machineAuthEntry)
controlBox.Add(gtk.NewLabel("Server"))
serverEntry := gtk.NewEntry()
serverEntry.SetText("127.0.0.1:9934")
if os.Getenv("REMOTON_SERVER") != "" {
serverEntry.SetText(os.Getenv("REMOTON_SERVER"))
serverEntry.SetEditable(false)
}
controlBox.Add(serverEntry)
controlBox.Add(gtk.NewLabel("Auth Server"))
authServerEntry := gtk.NewEntry()
authServerEntry.SetText("public")
controlBox.Add(authServerEntry)
var getCertFilename func() string
localCert := filepath.Join(filepath.Dir(os.Args[0]), "cert.pem")
if _, err := os.Stat(localCert); err == nil || os.IsExist(err) {
controlBox.Add(gtk.NewLabel("Cert local"))
getCertFilename = func() string {
return localCert
}
} else if os.Getenv("REMOTON_CERT_FILE") != "" {
controlBox.Add(gtk.NewLabel("Cert enviroment"))
getCertFilename = func() string {
return os.Getenv("REMOTON_CERT_FILE")
}
} else {
btnCert := gtk.NewFileChooserButton("Cert", gtk.FILE_CHOOSER_ACTION_OPEN)
getCertFilename = btnCert.GetFilename
controlBox.Add(btnCert)
}
btnSrv := gtk.NewButtonWithLabel("Start")
clremoton.VNC.OnConnection(func(addr net.Addr) {
//.........这里部分代码省略.........
开发者ID:bit4bit,项目名称:remoton,代码行数:101,代码来源:main.go
示例15: 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
//--------------------------------------------------------
//.........这里部分代码省略.........
开发者ID:adrien3d,项目名称:gobox,代码行数:101,代码来源:gtk2.go
示例16: main
func main() {
gtk.Init(nil)
window := gtk.NewWindow(gtk.WINDOW_TOPLEVEL)
window.SetPosition(gtk.WIN_POS_CENTER)
window.SetTitle("GTK Go!")
window.Connect("destroy", func(ctx *glib.CallbackContext) {
gtk.MainQuit()
}, "")
vbox := gtk.NewVBox(false, 0)
toolbar := gtk.NewToolbar()
toolbar.SetStyle(gtk.TOOLBAR_ICONS)
vbox.PackStart(toolbar, false, false, 5)
btnnew := gtk.NewToolButtonFromStock(gtk.STOCK_NEW)
btnclose := gtk.NewToolButtonFromStock(gtk.STOCK_CLOSE)
separator := gtk.NewSeparatorToolItem()
btncustom := gtk.NewToolButton(nil, "Custom")
btnmenu := gtk.NewMenuToolButtonFromStock("gtk.STOCK_CLOSE")
btnmenu.SetArrowTooltipText("This is a tool tip")
btnnew.OnClicked(onToolButtonClicked)
btnclose.OnClicked(onToolButtonClicked)
btncustom.OnClicked(onToolButtonClicked)
toolmenu := gtk.NewMenu()
menuitem := gtk.NewMenuItemWithMnemonic("8")
menuitem.Show()
toolmenu.Append(menuitem)
menuitem = gtk.NewMenuItemWithMnemonic("16")
menuitem.Show()
toolmenu.Append(menuitem)
menuitem = gtk.NewMenuItemWithMnemonic("32")
menuitem.Show()
toolmenu.Append(menuitem)
btnmenu.SetMenu(toolmenu)
toolbar.Insert(btnnew, -1)
toolbar.Insert(btnclose, -1)
toolbar.Insert(separator, -1)
toolbar.Insert(btncustom, -1)
toolbar.Insert(btnmenu, -1)
hbox := gtk.NewHBox(false, 0)
vbox.PackStart(hbox, true, true, 0)
toolbar2 := gtk.NewToolbar()
toolbar2.SetOrientation(gtk.ORIENTATION_VERTICAL)
hbox.PackStart(toolbar2, false, false, 5)
btnhelp := gtk.NewToolButtonFromStock(gtk.STOCK_HELP)
btnhelp.OnClicked(onToolButtonClicked)
toolbar2.Insert(btnhelp, -1)
btntoggle := gtk.NewToggleToolButton()
btntoggle2 := gtk.NewToggleToolButtonFromStock(gtk.STOCK_ITALIC)
toolbar2.Insert(btntoggle, -1)
toolbar2.Insert(btntoggle2, -1)
for i := 0; i < toolbar.GetNItems(); i++ {
gti := toolbar.GetNthItem(i)
switch gti.(type) {
case *gtk.ToolButton:
fmt.Printf("toolbar[%d] is a *gtk.ToolButton\n", i)
w := gti.(*gtk.ToolButton).GetIconWidget()
gti.(*gtk.ToolButton).SetIconWidget(w)
case *gtk.ToggleToolButton:
fmt.Printf("toolbar[%d] is a *gtk.ToggleToolButton\n", i)
gti.(*gtk.ToggleToolButton).SetActive(true)
case *gtk.SeparatorToolItem:
fmt.Printf("toolbar[%d] is a *gtk.SeparatorToolItem\n", i)
default:
fmt.Printf("toolbar: Item is of unknown type\n")
}
}
for i := 0; i < toolbar2.GetNItems(); i++ {
gti := toolbar2.GetNthItem(i)
switch gti.(type) {
case *gtk.ToolButton:
fmt.Printf("toolbar2[%d] is a *gtk.ToolButton\n", i)
case *gtk.ToggleToolButton:
fmt.Printf("toolbar2[%d] is a *gtk.ToggleToolButton\n", i)
gti.(*gtk.ToggleToolButton).SetActive(true)
case *gtk.SeparatorToolItem:
fmt.Printf("toolbar2[%d] is a *gtk.SeparatorToolItem\n", i)
default:
fmt.Printf("toolbar2: Item is of unknown type\n")
}
}
window.Add(vbox)
window.SetSizeRequest(600, 600)
window.ShowAll()
gtk.Main()
}
开发者ID:hauke96,项目名称:go-gtk,代码行数:96,代码来源:toolbar.go
示例17: InitializeGUI
//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()
//.........这里部分代码省略.........
开发者ID:jatovar,项目名称:sic-xe,代码行数:101,代码来源:guinterface.go
示例18: 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"
|
请发表评论