如何在"gframe"中添加上下文菜单? [英] How to add a context menu to a `gframe`?

查看:112
本文介绍了如何在"gframe"中添加上下文菜单?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在gWidgets2中的gframe中添加上下文菜单?我尝试了以下构造,但似乎无法将addPopupMenu附加到gframe:

How can I add a context menu to a gframe in gWidgets2? I tried the following construct, but it seems that I cannot attach a addPopupMenu to a gframe:

 require(gWidgets2)
 w <- gwindow("gformlayout", visible=T)
 f <- gframe("frame", horizontal=FALSE, container=w)
 l <- glabel("Lorem ipsum dolor sit amet, \nconsectetur adipiscing elit.", container=f)
 b <- gbutton("change name", container=f, handler=function(h,...) {
     names(f) <- "new name"
 })
 lst <- list(gaction('world', handler=function(h,...) svalue(world) <- "world"), 
             gaction('continent', handler=function(h,...) svalue(world) <- "continent"), 
             gaction('country', handler=function(h,...) svalue(world) <- "country"), 
             gaction('state', handler=function(h,...) svalue(world) <- "state"))
 add3rdmousePopupMenu(f, lst)
 #addPopupMenu(f, lst)
 add3rdmousePopupMenu(b, lst)

上下文菜单可以很好地附加到按钮上,但不能附加到gframe上.那么,如何添加右键单击gframe标签时会弹出的上下文菜单?

The context-menu is attached fine to the button, but NOT to the gframe. So how can I add a context menu that would pop-up when right-clicking the gframe label?

更新
根据答案,我尝试了以下代码:

UPDATE
As per the answers, I tried the code below:

require(gWidgets2)
f <- gframe("", cont=gwindow())
l <- glabel("label")                    # no cont argument
add3rdmousePopupMenu(l, list(a=gaction("Hi"))) 
f$block$setLabelWidget(l$block)         # the voodoo

但是当我在label上按right-click时,我仅获得用于选择文本的标准Gtk上下文菜单:

But when I right-click on the label, I only get the standard Gtk context menu for selecting text:

在Ubuntu 14.04和Gtk + 2.24.23中使用.我的sessionInfo():

Using Ubuntu 14.04 with Gtk+ 2.24.23. My sessionInfo():

> sessionInfo()
R version 3.0.2 (2013-09-25)
Platform: x86_64-pc-linux-gnu (64-bit)

locale:
 [1] LC_CTYPE=en_US.UTF-8       LC_NUMERIC=C               LC_TIME=en_US.UTF-8        LC_COLLATE=en_US.UTF-8    
 [5] LC_MONETARY=en_US.UTF-8    LC_MESSAGES=en_US.UTF-8    LC_PAPER=en_US.UTF-8       LC_NAME=C                 
 [9] LC_ADDRESS=C               LC_TELEPHONE=C             LC_MEASUREMENT=en_US.UTF-8 LC_IDENTIFICATION=C       

attached base packages:
[1] splines   grid      stats     graphics  grDevices utils     datasets  methods   base     

other attached packages:
 [1] reshape2_1.4         gWidgets2RGtk2_1.0-3 memoise_0.2.1        Hmisc_3.14-4         Formula_1.1-1       
 [6] survival_2.37-7      lattice_0.20-29      RGtk2_2.20.29        gWidgets2_1.0-6      digest_0.6.4        

loaded via a namespace (and not attached):
[1] cluster_1.14.4      latticeExtra_0.6-26 plyr_1.8.1          RColorBrewer_1.0-5  Rcpp_0.11.2        
[6] stringr_0.6.2       tools_3.0.2 

推荐答案

@landroni我没有检查,但是如果可以将弹出菜单直接添加到gframe标签中会感到惊讶.但是使用Gtk可以解决问题.这是将弹出菜单放置在标签位置的方法:

@landroni I didn't check, but would be surprised if popup menus could be added to gframe labels directly. But with Gtk things can be worked around. Here is how you can put a popup menu in the label position:

f <- gframe("", cont=gwindow())
l <- glabel("label")                    # no cont argument
add3rdmousePopupMenu(l, list(a=gaction("Hi"))) 
f$block$setLabelWidget(l$block)         # the voodoo
l$widget$setSelectable(FALSE)           # may not be needed

对于用户是否直观,我让您决定....

As for whether this is intuitive to the users, I'll let you decide....

这篇关于如何在"gframe"中添加上下文菜单?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆