[R-gui] Re: RGui windows question

Duncan Murdoch murdoch at stats.uwo.ca
Sat Aug 14 14:33:38 CEST 2004


On Sat, 14 Aug 2004 14:18:09 +0200, "Philippe Grosjean"
<phgrosjean at sciviews.org> wrote:

>Duncan Murdoch wrote:
>>Okay, this is in place now in r-devel.  It'll probably be Monday
>>before I upload a new build though.
>
>>To add something to the right click menu for a graphics window, you
>>need to know the device number (dev.cur() returns it).  Say it's 2,
>>then
>
>>winMenuAddItem("$Graph2Popup", "Caption", "action")
>
>>works.
>
>This is fine, I love this addition! Is it possible to add something also to
>the context menu in 'locator' mode (the menu showing 'stop', 'continue')?

That would be easy, but I didn't do it because locator mode is modal.
Menu selections there won't be acted on until locator mode ends.

>Also, do you think it should be possible to change the behaviour of
>*existing* menu items this way, or even to disable (or hide?) them if action
>specified is ""? I know this is currently not possible, but do you think it
>can be done easily?

That's harder, because user-defined commands are stored differently
than general commands.  What we'd need would be access to the menu
structure in Graphapp from R, and we don't currently have that.  It
would be nice, but I don't think I'll have time to do it before the
feature freeze next month.

On the other hand, contributions would be welcome...

Duncan
>
>The reason of my question is because I would like to add some code in my GUI
>when, for instance, the user clicks 'Stay on top' in the context menu (just
>an example). So, if I can redirect this command to a custom function, I
>could do something like:
>
># Imagine the current topmost state of the R console is stored in an option
># named 'console.top' (I know you plan to place this in a dedicated package)
># My custom function that replaces the default behaviour of 'Stay on top'
># in the context menu of R console would look like this:
>
>cons.to.top <- function() {
>	ctop <- getOption("console.top")
>	if (is.null(ctop) || !is.logical(ctop)) ctop <- FALSE	# By default
>	ctop <- !ctop # Toggle the 'stay on top' state
>	# Change the 'stay on top' state of the R console
>	bringToTop(-1, stay = ctop)
>
>	# Here I can add code for actions I have to take in my GUI
>	# ...
>
>	invisible(ctop)
>}
>
># This command would change the default behaviour of 'Stay on top' by
>calling
># my custom function 'cons.to.top' instead
>winMenuAddItem("$ConsolePopup", "Stay on top", "cons.to.top")
>
>Note that if we have the possibility to hide existing items in the context
>menu, I could simply hide the default one, and then add my own custom entry
>entry... Well here, a mean to check/uncheck the corresponding custom menu
>entry is obviously missing to get exactly the same result!
>
>>Similar things work for the main menu of the graphics window, and for
>>the popup in the console.  I didn't do any others, because some don't
>>allow commands to be executed (e.g. the data editor is modal), and the
>>text editor gives no obvious way to specify which window you mean.
>
>Best,
>
>Philippe Grosjean



More information about the R-SIG-GUI mailing list