[R-gui] Re: RGui windows question

Philippe Grosjean phgrosjean at sciviews.org
Sat Aug 14 14:18:09 CEST 2004


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')?
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?

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

.......................................................<?}))><....
 ) ) ) ) )
( ( ( ( (   Prof. Philippe Grosjean
\  ___   )
 \/ECO\ (   Numerical Ecology of Aquatic Systems
 /\___/  )  Mons-Hainaut University, Pentagone
/ ___  /(   8, Av. du Champ de Mars, 7000 Mons, Belgium
 /NUM\/  )
 \___/\ (   phone: + 32.65.37.34.97, fax: + 32.65.37.33.12
       \ )  email: Philippe.Grosjean at umh.ac.be
 ) ) ) ) )  SciViews project coordinator (http://www.sciviews.org)
( ( ( ( (
...................................................................



More information about the R-SIG-GUI mailing list