aDialog(traitr)
aDialog()所属R语言包:traitr
Create a Dialog instance...
创建一个Dialog实例...
译者:生物统计家园网 机器人LoveR
描述----------Description----------
Create a Dialog instance
创建一个对话框实例
用法----------Usage----------
参数----------Arguments----------
参数:items
List of item instances to create the model for the dialog object. May also be an item group (anItemGroup).
列表项实例创建对话框对象模型的。也可能是一个项目组(anItemGroup“)。
参数:title
Title of dialog
对话框的标题
参数:help_string
String for default Help button
字符串为默认的“帮助”按钮
参数:buttons
Character vector of button names. "OK","Cancel","Help","Undo","Redo" are some standard ones. "SPACE" and "SPRING" adjust the layout.
按钮名称的字符向量。 “OK”,“取消”,“帮助”,“撤销”,“重做”的一些标准。 “SPACE”和“弹簧”调整布局。
参数:...
How to pass in other properties and methods of the dialog object. For example OK_handler. </table>
如何通过在对话框对象的属性和方法。例如OK_handler。 </ TABLE>
Details
详细信息----------Details----------
A dialog is like an item group, in that it combines items into a model. However, an item group is meant to be incorporated into other GUIS, whereas a dialog creates its own window and decorations. A dialog has default buttons, and options for adding in menubars, toolbars, and statusbars. The choice of buttons can be specified at construction. <br>
对话是这样一个项目组,因为它结合到一个模型中的项目。但是,一个项目组的目的是要成立到其他GUIS,而一个对话框,创建自己的窗口和装饰。在菜单栏,工具栏和状态栏添加一个对话框,默认的按钮和选项。在建筑的选择按钮,可以指定。参考
Methods:
方法:
The main method that a dialog has is its OK_handler which is a method called when the "OK" button is clicked (one of the default buttons).
一个对话的主要方法是它的OK_handler这是一种所谓的“OK”按钮被按下时的默认按钮。
The getters and setters for the main value for an item are get_NAME and set_NAME, where NAME is the item name. The name is specified when the item is constructed (through its name property) or more conveniently, taken from the name of the component in the items list that defines the items for dialog or item group.
getter和setter方法的主要价值的项目是get_NAME和set_NAME,其中NAME是该项目的名称。构建项目时,通过它的name属性,或更方便的items列表定义对话框的项目或项目组中的组件的名称,从指定的名称。
The method to_R returns the items' values as a list (useful in combination with do.call).
的方法to_R项目的返回值作为一个列表(适用于搭配do.call)。
The method get_item_by_name returns an item object by its name. (Names should be unique.) This is useful if more properties than the main one for an item are needed to be set. (The main value is set via the setter.) The example shows how the validate property of some items can be set.
的方法get_item_by_name返回一个项目的对象,它的名字。 (名称应该是唯一的。)如果需要设置更多的性能比一个项目的主要原因之一,这是非常有用的。 (主要的价值是通过设置的setter)的示例显示了如何验证可以设置一些项目的属性。
The method is_valid is TRUE if all items validate and FALSE otherwise.
的方法is_valid是TRUE,如果所有项目验证和FALSE否则。
The method model_value_changed(.) is called whenever an item property is changed either through the GUI. A dialog observes itself.
的方法model_value_changed(.)的项目属性被更改时被调用通过GUI。一个对话框,观察本身。
For each item one can listen for changes with the method property_NAME_value_changed(., value, old_value).
对于每一个项目,一个可以听的方法property_NAME_value_changed(., value, old_value)。
Properties that are of interest:
有兴趣的属性:
status_text If non-NULL, when GUI is drawn, a status bar will be made with this text. The method set_status_text can be used to update the status
status_text如果非NULL,GUI绘制时,状态栏将这个文本。方法set_status_text可以用来更新状态
menu_list A menu list to specify a menubar. (See gmenu.)
menu_listA指定一个菜单栏,菜单列表。 (见gmenu)。
toolbar_list A menu list to specify a toolbar. (See gtoolbar.)
toolbar_list的菜单列表中指定的工具栏。 (见gtoolbar)。
buttons A list of buttons names. The default is c("OK", "SPACE", "Cancel", "Help"). The special names SPACE and SPRING adjust their positioning, otherwise the values are button names. When a button is clicked, the handler buttonname_handler is called, where the buttonname is stripped on non-alphanumeric characters. The basic buttons and Redo and Undo have default handlers. Likely, only OK_handler will need redefining. The property default_button can be specified to make a button the default one (so that it is activated when a user presses the enter key).
buttonsA按钮的名称列表。默认的c("OK", "SPACE", "Cancel", "Help")。特殊名字SPACE和SPRING调整自己的定位,否则的值是按钮的名称。当按钮被点击的处理程序buttonname_handler被称为buttonName被剥离非字母数字字符。基本按钮和Redo和Undo有默认的处理程序。很可能,只有OK_handler将需要重新定义。属性default_button可以指定使一个按钮的默认(这样它被激活时,用户按下进入键)。
值----------Value----------
Returns a proto object. See its show_help method for details.
返回原对象。详细信息,请参阅其“show_help方法。
实例----------Examples----------
## a Basic example[#一个简单的例子]
dlg <- aDialog(items=list(
a = numericItem(0),
b = stringItem("a")
),
title="The title",
help_string="Help on this dialog"
)
## Not run: dlg$make_gui()[#不运行:DLG $ make_gui()]
##[#]
##[#]
## example with model_value_changed[#与model_value_changed的例子]
plotIt <- function(n, mean, sd, ...) hist(rnorm(n, mean, sd))
dlg <- aDialog(items=list(
n = integerItem(10),
mean = numericItem(0),
sd = numericItem(1),
out=graphicDeviceItem()
),
buttons="Cancel",
model_value_changed=function(.) if(.$is_valid()) do.call("plotIt", .$to_R())
)
##[#]
## validation for n, sd[#为n,SD验证]
n <- dlg$get_item_by_name("n")
n$validate <- function(., rawvalue) if(rawvalue <= 1) stop("n must be positive integer") else rawvalue
sd <- dlg$get_item_by_name("sd")
sd$validate <- function(., rawvalue) if(rawvalue <- 0) stop("sd must be positive") else rawvalue
## Not run: dlg$make_gui()[#不运行:DLG $ make_gui()]
##[#]
##[#]
## subtle point about scope. Proto methods can be defined via $<- or [[<- but there is a difference.[#微妙的一点范围。原方法可以定义通过$ < - 或[[< - 但是有差别的。]
## $<- does not have lexical scope whereas [[<- does. The $<- might be more natural to type,[#$ < - 不词法范围,而[< - 。 $ < - 可能是更自然的输入,]
## but [[<- might be more natural to use. In this example, The "b" button does not work, as it can't find the[#[< - 可能是更自然的使用。在这个例子中,“B”按钮不工作,因为它不能找到]
## function a -- the frame of evaluation is the environment dlg (not its enclosing frame).[#函数 - 框架的评价是环境DLG(不包含它的框架)。]
## Thanks to Gabor for his help with this.[#感谢的Gabor对他的帮助。]
scope_example <- function() {
a <- function(...) print("hi")
dlg <- aDialog(items=list(),
buttons=c("a","b","c"),
a_handler=function(.) a(), ## like [[<-, not $<-[#喜欢[< - ,$ < - ]
title="a, c work; b doesn't"
)
dlg$b_handler <- function(.) a() ## $<- has unbound variables found in dlg[#$ < - 绑定的变量在DLG]
dlg[['c_handler']] <- a ## [[<- uses lexical scope for unbound variables[#[[< - 使用未绑定变量的词法范围]
}
## Not run: scope_example()[#不运行:scope_example()]
转载请注明:出自 生物统计家园网(http://www.biostatistic.net)。
注:
注1:为了方便大家学习,本文档为生物统计家园网机器人LoveR翻译而成,仅供个人R语言学习参考使用,生物统计家园保留版权。
注2:由于是机器人自动翻译,难免有不准确之处,使用时仔细对照中、英文内容进行反复理解,可以帮助R语言的学习。
注3:如遇到不准确之处,请在本贴的后面进行回帖,我们会逐渐进行修订。
|