Skip to content

[R-gui] Re: RGui windows question

5 messages · Philippe GROSJEAN, Duncan Murdoch

#
On Thu, 12 Aug 2004 15:58:41 +0200, Erich Neuwirth
<erich.neuwirth@univie.ac.at> wrote :
This would be fairly easy to do as follows.  I'd add fake user menu
names corresponding to the existing menus and you'd refer to those,
e.g.

winMenuAddItem('$GraphPopup', 'Caption', 'action')

The names I can think of off the top of my head would be

$ConsoleMain (the default location for new menu additions, but it
could also be specified, just for completeness)
$ConsolePopup
$GraphMain
$GraphPopup
$DataentryMain
$DataentryPopup

I'll have to check the code to see if we've got others that I've
forgotten.

We don't have separate popups for each instance of a graph window, so
you wouldn't be able to add local menu items to just one instance.
That would be harder.  Currently no information about the menu gets
passed to the command.  I might be able to record some information and
make it visible (so for example you'd call a function
"winPopupLocation" to find out where the last popup occurred).   

Duncan
#
On Fri, 13 Aug 2004 10:14:54 -0400, Duncan Murdoch
<murdoch@stats.uwo.ca> wrote :
Oops, that's wrong.  We *do* have separate popups for each instance of
a graph window.  This means that the items would have to be added
*after* the window is open, and would not be there if you opened a new
window later.  That makes managing them a little trickier.
#
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.

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.

Duncan Murdoch

On Fri, 13 Aug 2004 10:38:31 -0400, Duncan Murdoch
<murdoch@stats.uwo.ca> wrote:

            
#
Duncan Murdoch wrote:
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!
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@umh.ac.be
 ) ) ) ) )  SciViews project coordinator (http://www.sciviews.org)
( ( ( ( (
...................................................................
#
On Sat, 14 Aug 2004 14:18:09 +0200, "Philippe Grosjean"
<phgrosjean@sciviews.org> wrote:

            
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.
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