找回密码
 注册
查看: 3038|回复: 0

R语言:getGraphicsEvent()函数中文帮助文档(中英文对照)

[复制链接]
发表于 2012-2-16 22:00:10 | 显示全部楼层 |阅读模式
getGraphicsEvent(grDevices)
getGraphicsEvent()所属R语言包:grDevices

                                        Wait for a mouse or keyboard event from a graphics window
                                         从图形窗口的鼠标或键盘事件的等待

                                         译者:生物统计家园网 机器人LoveR

描述----------Description----------

This function waits for input from a graphics window in the form of a mouse or keyboard event.
该函数等待从图形窗口中的鼠标或键盘事件的形式输入。


用法----------Usage----------


getGraphicsEvent(prompt = "Waiting for input",
                 onMouseDown = NULL, onMouseMove = NULL,
                 onMouseUp = NULL, onKeybd = NULL,
                 consolePrompt = prompt)
setGraphicsEventHandlers(which = dev.cur(), ...)
getGraphicsEventEnv(which = dev.cur())
setGraphicsEventEnv(which = dev.cur(), env)




参数----------Arguments----------

参数:prompt
prompt to be displayed to the user in the graphics window
提示用户在图形窗口中显示


参数:onMouseDown
a function to respond to mouse clicks
一个函数来响应鼠标点击


参数:onMouseMove
a function to respond to mouse movement
一个函数来响应鼠标动作


参数:onMouseUp
a function to respond to mouse button releases
一个函数来响应鼠标按钮发布


参数:onKeybd
a function to respond to key presses
一个函数来响应按键


参数:consolePrompt
prompt to be displayed to the user in the console
提示显示在控制台的用户


参数:which
which graphics device does the call apply to?
申请调用图形设备?


参数:...
items including handlers to be placed in the event environment
项目包括被放置在事件环境的处理程序


参数:env
an environment to be used as the event environment
环境事件的环境中使用


Details

详情----------Details----------

These functions allow user input from some graphics devices (currently only the windows() and X11(type="Xlib") screen displays in base R). Event handlers may be installed to respond to events involving the mouse or keyboard.
这些功能允许用户输入一些图形处理装置(目前只有windows()和X11(type="Xlib")在基地ŕ屏幕显示)。事件处理程序可以安装,以应对事件涉及的鼠标或键盘。

The functions are related as follows.  If any of the first five arguments to getGraphicsEvent are given, then it uses those in a call to setGraphicsEventHandlers to replace any existing handlers in the current device.  This is for compatibility with pre-2.12.0 R versions.  The current normal way to set up event handlers is to  set them using setGraphicsEventHandlers or setGraphicsEventEnv on one or more graphics devices, and then use getGraphicsEvent() with no arguments to retrieve event data. getGraphicsEventEnv() may be used to save the event environment for use later.
有关职能如下。如果有任何的前五个参数getGraphicsEvent给出,那么它在调用setGraphicsEventHandlers取代任何现有的处理程序当前设备的使用。这是与前2.12.0 R版本的兼容性。目前正常的方式,成立事件处理程序是设置使用setGraphicsEventHandlers或setGraphicsEventEnv一个或多个图形设备上,然后用getGraphicsEvent()不带参数,以获取事件数据。 getGraphicsEventEnv()可用于保存事件的环境后使用。

The names of the arguments in getGraphicsEvent are special.  When handling events, the graphics system will look through the event  environment for functions named onMouseDown, onMouseMove, onMouseUp and onKeybd and use them as event handlers.  It will use  prompt for a label on the graphics device.  Two other special names are which, which will identify the graphics device, and result, where the result of the last event handler will be stored before being returned by getGraphicsEvent().
getGraphicsEvent参数的名称是特别。在处理事件时,图形系统将名为onMouseDown,onMouseMove,onMouseUp和onKeybd“事件处理程序中使用它们的功能,通过事件环境。它会使用prompt图形设备上的标签。另外两个特殊的名字是的which,这将确定图形设备,和前的最后一个事件处理程序的结果将被存储result返回getGraphicsEvent(),其中。

The mouse event handlers should be functions with header  function(buttons, x, y).  The coordinates x and y will be passed to mouse event handlers in device independent coordinates (i.e. the lower left corner of the window is (0,0),  the upper right is (1,1)).  The buttons argument  will be a vector listing the buttons that are pressed at the time of the event, with 0 for left, 1 for middle, and 2  for right.
鼠标事件的处理程序应该是头function(buttons, x, y)功能。坐标x和y将被传递到鼠标事件处理程序在独立于设备坐标(即较低的窗口的左上角是(0,0),右上方是(1,1)) 。 buttons参数将列出的按钮,在事件发生时,按下左0,1中,右2是一个向量。

The keyboard event handler should be a function with header function(key).  A single element character vector will be passed to this handler, corresponding to the key press.  Shift and other modifier keys will have been processed, so shift-a will be passed as "A".  The following special keys may also be passed to the handler:
键盘事件处理程序应该是一个头function(key)功能。一个单一的元素特征向量,将传递给该处理程序,相应的按键。 Shift和其他修饰键将被处理,所以shift-a将"A"通过。以下特殊键也可以传递给处理程序:

Control keys, passed as "Ctrl-A", etc.
控制键,通过"Ctrl-A"等

Navigation keys, passed as one of "Left", "Up", "Right", "Down",      "PgUp", "PgDn", "End", "Home"
导航键,通过一个"Left", "Up", "Right", "Down",      "PgUp", "PgDn", "End", "Home"

Edit keys, passed as one of "Ins", "Del"
编辑键,作为"Ins", "Del"通过

Function keys, passed as one of "F1", "F2", ...
功能键,通过一个"F1", "F2", ...

The event handlers are standard R functions, and will be executed as though called from the event environment.  
事件处理程序是标准的R功能,将被执行,虽然从事件环境。

In an interactive session, events will be processed until
在一个交互式会话,事件将被处理,直到

one of the event handlers returns a non-NULL value which will be returned as the value of getGraphicsEvent, or
事件处理程序返回非NULL值将作为值getGraphicsEvent返回,或

the user interrupts the function from the console.
中断用户从控制台的功能。


值----------Value----------

When run interactively,  getGraphicsEvent returns a non-NULL value returned from one of the event handlers. In a non-interactive session, getGraphicsEvent will return NULL immediately.
当以交互方式运行,getGraphicsEvent返回一个非NULL从一个事件处理程序返回的值。在非交互式会话,getGraphicsEvent将返回NULL立即。

getGraphicsEventEnv returns the current event environment for the graphics device, or NULL if none has been set.
getGraphicsEventEnv图形设备返回当前事件的环境,或NULL如果没有设置。

setGraphicsEventEnv and setGraphicsEventHandlers return the previous event environment for the graphics device.
setGraphicsEventEnv和setGraphicsEventHandlers返回以前的事件环境的图形设备。


作者(S)----------Author(s)----------


Duncan Murdoch



举例----------Examples----------



savepar <- par(ask=FALSE)
dragplot <- function(..., xlim=NULL, ylim=NULL, xaxs="r", yaxs="r") {
    plot(..., xlim=xlim, ylim=ylim, xaxs=xaxs, yaxs=yaxs)
    startx <- NULL
    starty <- NULL
    usr <- NULL

    devset <- function()
        if (dev.cur() != eventEnv$which) dev.set(eventEnv$which)
        
    dragmousedown <- function(buttons, x, y) {
        startx <<- x
        starty <<- y
        devset()
        usr <<- par("usr")
        eventEnv$onMouseMove <- dragmousemove
        NULL
    }
   
    dragmousemove <- function(buttons, x, y) {
        devset()
        deltax <- diff(grconvertX(c(startx,x), "ndc", "user"))
        deltay <- diff(grconvertY(c(starty,y), "ndc", "user"))
        plot(..., xlim=usr[1:2]-deltax, xaxs="i",
                  ylim=usr[3:4]-deltay, yaxs="i")
        NULL
    }
   
    mouseup <- function(buttons, x, y) {   
            eventEnv$onMouseMove <- NULL
    }       
        
    keydown <- function(key) {
        if (key == "q") return(invisible(1))
        eventEnv$onMouseMove <- NULL
        NULL
    }
   
    setGraphicsEventHandlers(prompt="Click and drag, hit q to quit",
                     onMouseDown = dragmousedown,
                     onMouseUp = mouseup,
                     onKeybd = keydown)
    eventEnv <- getGraphicsEventEnv()
}

dragplot(rnorm(1000), rnorm(1000))
# This currently only works on the Windows[这种目前仅在Windows工程]
# and X11(type = "Xlib") screen devices...[和X11(类型=“Xlib的”)屏幕设备......]
getGraphicsEvent()
par(savepar)


转载请注明:出自 生物统计家园网(http://www.biostatistic.net)。


注:
注1:为了方便大家学习,本文档为生物统计家园网机器人LoveR翻译而成,仅供个人R语言学习参考使用,生物统计家园保留版权。
注2:由于是机器人自动翻译,难免有不准确之处,使用时仔细对照中、英文内容进行反复理解,可以帮助R语言的学习。
注3:如遇到不准确之处,请在本贴的后面进行回帖,我们会逐渐进行修订。
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

手机版|小黑屋|生物统计家园 网站价格

GMT+8, 2025-1-23 10:31 , Processed in 0.030728 second(s), 15 queries .

Powered by Discuz! X3.5

© 2001-2024 Discuz! Team.

快速回复 返回顶部 返回列表