Conveniently manipulate toolbars, whatever the window

Share:

Description

These functions provide an unifying way of dealing with (simple) toolbars in R. Currently, they support only Tcl/Tk toolbars and toolbuttons, but other graphical toolboxes could be supported too in the future.

Usage

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
toolAdd(toolbar, side = "top")
toolAddItem(toolbar, item, action, image = "", options = "")
toolDel(toolbar)
toolDelItem(toolbar, item)
toolNames()
toolItems(toolbar)
toolType(toolbar, warn = TRUE)
toolInvoke(toolbar, item)
toolChangeItem(toolbar, item, action = "", options = "")
toolStateItem(toolbar, item, active = TRUE)
toolRead(file = "Tools.txt")
toolReadPackage(package, subdir = "gui", file = "Tools.txt")

## S3 method for class 'guiTool'
print(x, ...)

Arguments

toolbar

name of a toolbar.

side

where to place the toolbar in the window (\"top\", \"bottom\", \"left\", or \"right\")?

item

name of a toolbar item (a toolbutton).

action

action the toolbutton triggers (R code).

image

name of an image to display in the toolbutton.

options

additional options, for instance "disable" to disable the toolbutton at creation.

warn

do we issue a warning if the type of menu is not recognized?

active

do we enable or disable the toolbutton?

file

a file containing toolbars specifications to read.

package

name of a package from where to load toolbars specifications.

subdir

subdirectory in the package where the toolbars specifications are stored. By default, it is the "gui" subdirectory.

x

an object of class 'guiTool'.

...

further arguments (currently not used).

Details

These functions care about creating, deleting and managing custom toolbars. Informations and handles to the various toolbars created with these functions are stored in the .guiTools variable, located in the SciViews:TempEnv environment.

Use 'img' resources to load images to display in the toolbuttons.

Value

toolAdd(), toolAddItem() return the handle to the newly created toolbar or toolbutton invisibly. toolDel() and toolDelItem() return invisibly TRUE if the resource is found and deleted, FALSE otherwise. toolNames() returns the list of all toolbars registered in .guiTools in the SciViews:TempEnv environment. toolInvoke() returns invisibly TRUE if the toolbutton was invoked, FALSE otherwise. toolRead() and toolReadPackage() return invisibly the list of toolbars that are imported and created.

Author(s)

Philippe Grosjean

See Also

tkToolAdd, imgReadPackage

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
## Not run: 
## These cannot be run by examples() but should be OK when pasted
## into an interactive R session with the tcltk package loaded
## Run these commands one at a time

winAdd("tt", title = "A Tk window with toolbars", pos ="-40+20")
imgReadPackage("svWidgets")     # Make sure images are loaded
## Create a toolbar and populate it
toolAdd("$Tk.tt/Main")
toolNames()
(toolItems("$Tk.tt/Main"))   # Still nothing in it
toolAddItem("$Tk.tt/Main", "List variables",
    action = "print(ls(envir = .GlobalEnv))", image = "$Tk.butCopy")
toolAddItem("$Tk.tt/Main", "Say yo!", action = "cat('yo!\n')")
toolAddItem("$Tk.tt/Main", "-")
toolAddItem("$Tk.tt/Main", "Search",
    action = "print(search())", image = "$Tk.butPaste")
(toolItems("$Tk.tt/Main"))
## Change state of buttons in the toolbar
toolStateItem("$Tk.tt/Main", "Search", FALSE)
toolStateItem("$Tk.tt/Main", "Search", TRUE)
toolStateItem("$Tk.tt/Main", "Say yo!", FALSE)
toolStateItem("$Tk.tt/Main", "Say yo!", TRUE)
## Invoke a button
toolInvoke("$Tk.tt/Main", "Say yo!")
## Remove a button and add another one (always at the end!)
toolDelItem("$Tk.tt/Main", "Say yo!")
toolAddItem("$Tk.tt/Main", "Say yo! twice", "cat('yo! yo!\n')")
(toolItems("$Tk.tt/Main"))
toolDel("$Tk.tt/Main")
toolNames()
(toolItems("$Tk.tt/Main"))
winDel("tt")

## End(Not run)