Title: | 'SciViews' - Manage GUIs in R |
---|---|
Description: | Manage Graphical User Interfaces (GUI) in R. It is independent from any particular GUI widgets ('Tk', 'Gtk2', native, ...). It centralizes info about GUI elements currently used, and it dispatches GUI calls to the particular toolkits in use in function of the context (is R run at the terminal, within a 'Tk' application, a HTML page?). |
Authors: | Philippe Grosjean [aut, cre] |
Maintainer: | Philippe Grosjean <[email protected]> |
License: | GPL-2 |
Version: | 1.0.1 |
Built: | 2024-11-01 11:30:12 UTC |
Source: | https://github.com/SciViews/svGUI |
Determine if R code execution can be interrupted by the GUI, e.g., using a
modal dialog box. It depends both on R being in interactive()
mode and the
ask
flag of the GUI being set to TRUE
.
dont_ask(gui = .GUI) dontAsk(gui = .GUI)
dont_ask(gui = .GUI) dontAsk(gui = .GUI)
gui |
A |
dontAsk
and dont_ask
are aliases.
TRUE
if the GUI cannot interrupt R. The function triggering the
dialog box should then not be displayed and it should return the default
value as the result. The function returns TRUE
if R is run in a non
interactive session, or if ask
is set to FALSE
for the GUI, or if it is
not specified (ask
is NULL
) then getOptions("gui.ask")
is used.
# What is the current state for the default GUI? dont_ask()
# What is the current state for the default GUI? dont_ask()
The gui
object contains and manages GUI-related data.
## S3 method for class 'gui' gui$x ## S3 method for class 'gui' print(x, ...) is.gui(x)
## S3 method for class 'gui' gui$x ## S3 method for class 'gui' print(x, ...) is.gui(x)
gui |
A |
x |
An object or a function for |
... |
Further arguments (not used yet). |
# Create a GUI gui_add("myGUI") is.gui(myGUI) myGUI # Put an object in the GUI environment (fake button) myGUI$button <- "my_button" # Retrieve it myGUI$button # Get the curent status of the GUI myGUI$status # Eliminate this GUI and all its objects gui_remove("myGUI")
# Create a GUI gui_add("myGUI") is.gui(myGUI) myGUI # Put an object in the GUI environment (fake button) myGUI$button <- "my_button" # Retrieve it myGUI$button # Get the curent status of the GUI myGUI$status # Eliminate this GUI and all its objects gui_remove("myGUI")
Create and manipulate gui
objects to manage 'SciViews'-compatible GUIs
(Graphical User Interfaces).
gui_add(gui.name = ".GUI", widgets = c("nativeGUI", "textCLI"), ask) guiAdd(gui.name = ".GUI", widgets = c("nativeGUI", "textCLI"), ask) gui_change( gui.name = ".GUI", widgets = c("nativeGUI", "textCLI"), reset = FALSE, ask ) guiChange( gui.name = ".GUI", widgets = c("nativeGUI", "textCLI"), reset = FALSE, ask ) gui_remove(gui.name) guiRemove(gui.name) gui_list() guiList() gui_widgets(gui, gui.name = ".GUI") guiWidgets(gui, gui.name = ".GUI") gui_widgets(x, reset = FALSE) <- value guiWidgets(x, reset = FALSE) <- value gui_ask(gui.or.name, ask) guiAsk(gui.or.name, ask) gui_ask(x) <- value guiAsk(x) <- value
gui_add(gui.name = ".GUI", widgets = c("nativeGUI", "textCLI"), ask) guiAdd(gui.name = ".GUI", widgets = c("nativeGUI", "textCLI"), ask) gui_change( gui.name = ".GUI", widgets = c("nativeGUI", "textCLI"), reset = FALSE, ask ) guiChange( gui.name = ".GUI", widgets = c("nativeGUI", "textCLI"), reset = FALSE, ask ) gui_remove(gui.name) guiRemove(gui.name) gui_list() guiList() gui_widgets(gui, gui.name = ".GUI") guiWidgets(gui, gui.name = ".GUI") gui_widgets(x, reset = FALSE) <- value guiWidgets(x, reset = FALSE) <- value gui_ask(gui.or.name, ask) guiAsk(gui.or.name, ask) gui_ask(x) <- value guiAsk(x) <- value
gui.name |
The name of the GUI. It is also the name of the object stored
in |
widgets |
The list of widgets that GUI uses, listed in a priority order. |
ask |
Logical indicating if modal dialog boxes should be display
( |
reset |
Should the GUI's main parameters (widgets, ask) be reset to default values? |
gui |
A |
x |
A |
value |
The list of widgets to add to this GUI, in priority order, or
should we change ask to |
gui.or.name |
A |
# A 'gui' object named .GUI is automatically created in 'SciViews:TempEnv' gui_list() # Create a new GUI object to manage a separate GUI in the same R session gui_add("myGUI") gui_list() # Change general properties of this GUI gui_ask(myGUI) <- FALSE # Add widgets to this GUI (you must provide methods for them) # see the svDialogs package for examples gui_widgets(myGUI) <- "tcltkWidgets" gui_widgets(myGUI) # Added to existing ones if reset is FALSE # Remove this new GUI gui_remove("myGUI")
# A 'gui' object named .GUI is automatically created in 'SciViews:TempEnv' gui_list() # Create a new GUI object to manage a separate GUI in the same R session gui_add("myGUI") gui_list() # Change general properties of this GUI gui_ask(myGUI) <- FALSE # Add widgets to this GUI (you must provide methods for them) # see the svDialogs package for examples gui_widgets(myGUI) <- "tcltkWidgets" gui_widgets(myGUI) # Added to existing ones if reset is FALSE # Remove this new GUI gui_remove("myGUI")
Using setUI()
is the preferred way to set a property in a gui
object.
Similarly, startUI()
should be used to indicate that an UI action requiring
user input is initiated (say, a modal input or file selection dialog box).
setUI(..., gui = .GUI) ## S3 method for class 'gui' setUI(fun, call, args, res, widgets, status, msg = NULL, ..., gui = .GUI) startUI(..., gui = .GUI) ## S3 method for class 'gui' startUI( fun, call, default, widgets = NULL, status = "busy-modal", msg = "Displaying a modal dialog box", msg.no.ask = "A modal dialog box was by-passed", ..., gui = .GUI )
setUI(..., gui = .GUI) ## S3 method for class 'gui' setUI(fun, call, args, res, widgets, status, msg = NULL, ..., gui = .GUI) startUI(..., gui = .GUI) ## S3 method for class 'gui' startUI( fun, call, default, widgets = NULL, status = "busy-modal", msg = "Displaying a modal dialog box", msg.no.ask = "A modal dialog box was by-passed", ..., gui = .GUI )
... |
Any other property of the GUI, provided as named arguments. |
gui |
A |
fun |
The name of the calling function. Only required if |
call |
The call in the generic as obtained by |
args |
A list with checked and/or reworked arguments for a method. The generic can do this work, so that code does not need to be duplicated in all its methods. |
res |
Any data returned by the GUI (the results). |
widgets |
The class name of the current widgets implementation. |
status |
Description of the current GUI status. Could be "ok", "busy",
"busy-modal" (a modal dialog box is currently displayed), "by-passed" (the
GUI was by-passed because |
msg |
The message that explains the status. Cannot be provided without status. |
default |
The default value to return if the UI is by-passed because in
non interactive mode, or ask is |
msg.no.ask |
The message that explains the status in case the UI is by-passed. |
gui
: Set an UI property for a gui
object.
gui
: Start an UI for a gui
object.
# Imagine you implement a new input box # In your function, you have this code: myInput <- function(default = "an answer", gui = .GUI) { # Start a GUI action... or by-pass it! if (gui$startUI("myInput", call = match.call(), default = default, msg = "Displaying an input dialog box", msg.no.ask = "An input dialog box was by-passed")) { # Here the input dialog box is displayed and R waits for user feedback # ... [your code here] res <- "some results" # Imagine this is the text typed in the box # When the input dialog box is closed, the function should do: setUI(res = res, status = NULL) } invisible(gui) }
# Imagine you implement a new input box # In your function, you have this code: myInput <- function(default = "an answer", gui = .GUI) { # Start a GUI action... or by-pass it! if (gui$startUI("myInput", call = match.call(), default = default, msg = "Displaying an input dialog box", msg.no.ask = "An input dialog box was by-passed")) { # Here the input dialog box is displayed and R waits for user feedback # ... [your code here] res <- "some results" # Imagine this is the text typed in the box # When the input dialog box is closed, the function should do: setUI(res = res, status = NULL) } invisible(gui) }