SciViews GUI API - More tcltk

SciViews GUI API - More tcltk [R logo]

Help pages for package `tcltk2' version 0.9-5

.tk2dde.require | Use DDE (Dynamic Data Exchange) under Windows
makeTclNames | Manipulate R variables and functions from tcl and back
tclFun | Manipulate R variables and functions from tcl and back
tclGetValue | Manipulate R variables and functions from tcl and back
tclSetValue | Manipulate R variables and functions from tcl and back
tclVarExists | Manipulate R variables and functions from tcl and back
tclVarFind | Manipulate R variables and functions from tcl and back
tclVarname | Manipulate R variables and functions from tcl and back
tk2button | A themed series of tk widget
tk2canvas | A themed series of tk widget
tk2checkbutton | A themed series of tk widget
tk2column | Tk commands associated with the tk2XXX widgets
tk2combobox | A themed series of tk widget
tk2commands | Tk commands associated with the tk2XXX widgets
tk2dde | Use DDE (Dynamic Data Exchange) under Windows
tk2entry | A themed series of tk widget
tk2frame | A themed series of tk widget
tk2ico | Manipulate icons under Windows
tk2ico.taskbar.add | Manipulate icons under Windows
tk2ico.taskbar.delete | Manipulate icons under Windows
tk2ico.taskbar.modify | Manipulate icons under Windows
tk2ico.text | Manipulate icons under Windows
tk2insert.multi | Tk commands associated with the tk2XXX widgets
tk2killtip | Display and manage tooltips in tk widgets
tk2label | A themed series of tk widget
tk2labelframe | A themed series of tk widget
tk2listbox | A themed series of tk widget
tk2listinsert | Tk commands associated with the tk2XXX widgets
tk2mclistbox | A themed series of tk widget
tk2menu | A themed series of tk widget
tk2menubutton | A themed series of tk widget
tk2message | A themed series of tk widget
tk2notebook | A themed series of tk widget
tk2notetraverse | Tk commands associated with the tk2XXX widgets
tk2panedwindow | A themed series of tk widget
tk2progress | A themed series of tk widget
tk2radiobutton | A themed series of tk widget
tk2reg | Manipulate the registry under Windows
tk2scale | A themed series of tk widget
tk2scrollbar | A themed series of tk widget
tk2separator | A themed series of tk widget
tk2spinbox | A themed series of tk widget
tk2table | A themed series of tk widget
tk2text | A themed series of tk widget
tk2theme | Set or get the theme in use for themed widgets (tile)
tk2tip | Display and manage tooltips in tk widgets
tk2tree | A themed series of tk widget
tk2treeview | A themed series of tk widget
tk2widgets | A themed series of tk widget


Manipulate R variables and functions from tcl and back

Description

These functions are intended to provide a better "duality" between the name of variables in both R and tcl, including for function calls. It is possible to define a variable with the same name in R and tcl (the content is identical, but copied and coerced in the two respective environments). It is also possible to get the value of a tcl variable from R, and to call a R function from within tcl. These functionnalities are provided in the tcltk package, but Tcl variable usually have different internal names as R equivalents.

Usage

  makeTclNames(names, unique = FALSE)
  tclFun(f, name = deparse(substitute(f)))
  tclGetValue(name)
  tclSetValue(name, value)
  tclVarExists(name)
  tclVarFind(pattern)
  tclVarname(name, init = "", keep.existing = TRUE)

Arguments

names | Transform names so that they are valid for variables in tcl
unique | Should these names be unique in the vector?
f | An R function. currently, do no support functions with arguments.
name | The name of a variable
value | The value to place in a variable
pattern | A pattern to search for
init | Initial value to use when creating the variable
keep.existing | If the tcl variable already exist, should we keep its content?

Details

These functions are similar to tclVar() from package tcltk, except for the following change: here, it is possible to propose a name for the created tcl variable, or to set or retrieve the content of a tcl variable that is not mirrored in R.

Value

Most of these functions return a tclVar object.

Author(s)

Philippe Grosjean

See Also

tk2theme

Examples

  ## Not run:
    ## These cannot be run by examples() but should be OK when pasted
    ## into an interactive R session with the tcltk package loaded

        ## Tcl functions and variables manipulation
    tclVarExists("tcl_version")
    tclVarExists("probably_non_existant")
    tclVarFind("tcl*")

    # Using tclVarname() and tclGetValue()... intented for better match between R and Tcl variables
    Test <- tclVarname("Test", "this is a test!")
    # Now 'Test' exist both in R and in Tcl... In R, you need to use tclvalue(Test) to retrieve its content
    # If a variable already exists in Tcl, its content is preserved using keep.existing = TRUE
    .Tcl("set A_Variable {just to test...}") # Create a variable in Tcl and assign "just a test..." to it
    A_Variable <- tclVarname("A_Variable", "something else?") # Create the dual variable with same name
    tclvalue(A_Variable) # Content of the variable is not changed!

    # If you want to retrieve the content of a Tcl variable, but do not want to create a reference to it in R, use:
    .Tcl("set Another_Variable {something in it}")  # Create a Tcl variable, not visible from R
    tclGetValue("Another_Variable") # Get its content in R
  ## End(Not run)
[Package tcltk2 version 0.9-5 Index]


Tk commands associated with the tk2XXX widgets

Description

These commands supplement those available in the tcltk package to ease manipulation of tk2XXX widgets.

Usage

  tk2column(widget, action = c("add", "configure", "delete", "names", "cget", "nearest"), ...)
  tk2insert.multi(widget, where = "end", items)
  tk2listinsert(widget, ...)
  tk2notetraverse(nb)

Arguments

widget | The widget to which these actions apply
action | Which kind of action?
where | Where are these item added in the list (by default, at the end)
items | The items to add (either a vector for a single line, or a matrix for more items)
nb | A tk2notebook widget
... | Further arguments to the action

Details

tk2column manipulate columns of a tk2mclistbox widget, tk2insert.multi is used to insert multiple field entries in a tk2mclistbox widget, tk2listinsert eases the insertion of items in a tk2combobox widget, tk2notetraverse helps manage the tabs in a tk2notebook.

Author(s)

Philippe Grosjean

See Also

tk2widgets, tk2theme, tk2tip


Use DDE (Dynamic Data Exchange) under Windows

Description

DDE is the first Microsoft's attempt to make an inter-application mechanism. It is now superseeded by (D)Com, but it is still available. Being simpler than Com, DDE is interesting for simple tasks. Applications like Word, Excel, Windows Explorer, Internet Explorer, etc... provide services one can access through DDE (see examples).

Usage

    tk2dde(topic = NULL)
    tk2dde.services(service = "", topic = "")
    tk2dde.exec(service, topic, command, async = FALSE)
    tk2dde.poke(service, topic, item, data)
    tk2dde.request(service, topic, item, binary = FALSE)
    .tk2dde.require()

Arguments

topic | The 'topic' to reach or expose. A DDE server is accessed as 'service'|'topic'. In the case of tk2DDE(), a non null topic activates the DDE server, and a null topic deactivate it
service | The name of the service to reach. In tk2DDEservices, if both service and topic are empty, the list of all available DDE service is returned, otherwise, only available topics for a given service are listed
command | A string with the command to run in the external application (syntax depends on the server)
async | Is a command run asynchroneously (returns immediatelly, before the command is processed), or not?
item | The concerned item (usually a variable name, a range in a worksheet, etc...)
data | The new value for the item
binary | Should the return bez treated as binary data or not?

Note

This is only available under Windows. Trying to use these functions under other platforms raises an error. Under Windows, R is automatically configured as a DDE server with name TclEval|SciViewsR when this package is loaded

Author(s)

Philippe Grosjean

See Also

tk2reg

Examples

  ## Not run:
    ## These cannot be run by examples() but should be OK when pasted
    ## into an interactive R session with the tcltk package loaded

        ## Examples of DDE - Windows only
    ###### Examples using wish
    # Start a Wish84 console side-by-side with R.
    # (to get wish, you need to install ActiveTcl from
    # http://www.activestate.com/Products/ActiveTcl/)
    # Once it is done, start 'Wish84' from the start menu)
    # Register the Wish console as a DDE server, that is, type in it:
    # % package require dde
    # % dde servername wish

    # In R:
    tk2dde("R") # Return 0 if succeed
    tk2dde.services()
    # Evaluate some string in wish
    tk2dde.exec("TclEval", "wish", "{puts {Hello World!}}")
    # Give a value to a variable in wish
    tk2dde.poke("TclEval", "wish", "myvar", "This is a string!")
    tk2dde.poke("TclEval", "wish", "mynumvar", 34.56)

    # In wish, check that vars exist and have correct value
    # % puts $myvar
    # % puts $mynumvar

    # Get the value of one variable from wish into R
    tk2dde.request("TclEval", "wish", "myvar")
    tk2dde.request("TclEval", "wish", "mynumvar")
    # Note that you don't know here if it is a string, a numerical data, or so...
    # You have to know and convert yourself!

    # Now, the other way: execute a R function from wish
    # You first need to register a R function for callback
    # (I don't how yet to deal with arguments here, so, use functions without args!)
    doDDE <- function() cat("DDE execute!\n")  # A simple function without arguments
    tclFun(doDDE)
    # And in wish
    # % dde execute TclEval R doDDE

    # Once you have defined a variable using tclVar, you can get or change its value
    #from the dde server
    # However, tclVar gives cryptic names like ::RTcl1. so we prefer to use tclVarname
    myvar <- tclVarname("myvar", "this is a test...")
    tclvalue(myvar) # This is the way we access to this variable in R

    # In wish you get the value and change it:
    # % dde request TclEval R myvar
    # Again, dde poke does not work here and must be replaced by an execute command
    # This doesn't work (???)
    # % dde poke TclEval R myvar {yes! and it works...}
    # ... but this is fine
    # % dde execute TclEval R {set myvar {yes! and it works...}}

    # And in R...
    tclvalue(myvar)

    # You can also change the value of a variable, or run a command in R from
    #the command line using execdde.exe:
    # Copy %R_Home%\library\tcltk2\libs\execdde.exe somewhere in your path,
    # start a DOS window
    # and enter the following commands:
    # > execdde -s TclEval -t R -c doDDE > NUL
    # > if errorlevel 1 echo An error occurred... branch accordingly in your batch file!
    # > execdde -s TclEval -t R -c "set myvar {ok from execdde!}" > NUL

    # And in R:
    tclvalue(myvar)
    # Note that, thanks to separate event loops, this work also when R is calculating...

    # Other examples of DDE use:
    #### Manipulating Microsoft Excel ####
    # Start Excel with a blank workbook, then...

    # Change values in Excel from R:
    tk2dde.poke("Excel", "Sheet1", "R1C1:R2C1", "{5.7\n6.34}")   # Some data
    tk2dde.poke("Excel", "Sheet1", "R3C1", "{= A1 + A2}")        #... and a formula

    # Read values in Excel (note that results of formulas are returned)
    Res <- tk2dde.request("Excel", "Sheet1", "R1C1:R3C1")
    Res
    as.numeric(strsplit(Res, "\r\n", fixed = TRUE)[[1]])        # Convertion

    # Execute a command in Excel
    tk2dde.exec("Excel", "Sheet1", "{\[\Select(\"R1C1:R3C1\")]\[New(2,2)\]}")
    # New(2,2) create a bar graph in a separate sheet
    # Note: close this graph now, in order to run the remaining commands properly!

    # R as server and Excel as client
    # Prepare R as server
    tk2dde("SciViewsR") # Now, my server name is TclEval|SciViewsR !
    # Create a variable that will be shared with Excel
    XlVar <- tclVarname("XlVar", "this is a test!")
    # Enter a formula somewhere in Excel to link to this variable
    tk2dde.poke("Excel", "Sheet1", "R5C1", "=TclEval|SciViewsR!'::XlVar'")

    # Now, change the content in XlVar
    tclvalue(XlVar) <- "Another text..."
    # Rem: in my Excel, the content of the cell is not changed automatically...
    # I must reenter the formula for the changes to be considered!?

    #### Manipulating Microsoft Word ####
    # Start Word and then...
    tk2dde.exec("Winword", "System", "{\[EndOfDocument\]}")
    tk2dde.exec("Winword", "System", "{\[Insert \"Text from Tcl.\"\]}", async = TRUE)

    # Can also use:
    #  AppMaximize 1
    #  StatOfDocument
    #  EditFind .Find="hello" .PatternMatch=1
    #  FileExit 2
    #  FileClose 2 # 2 = close without saving, 1 = save first, 0 = prompt

    # If you need to start the application (Word) before using DDE, you must
    # wait that Word becomes ready!
    # This is a Tcl proc that shows how to do that
    #### TO DO: translate this in R...
    # proc doc2txt fn {
    #     package require dde
    #     package require Tk; # because we need [selection]
    #     eval exec [auto_execok start] [list $fn] &
    #
    #     #Loop to wait until Word is really there, and ready to talk
    #     set word ""
    #     while {$word==""} {
    #   set word [dde services Winword System]
    #   after 200
    #     }
    #     after 1000 ;# wait for the window to load...
    #     dde execute Winword System {[EditSelectAll]}
    #     dde execute Winword System {[EditCopy]}
    #     set res [selection get -selection CLIPBOARD]
    #     dde execute Winword System {[FileExit 2]}
    #     set res
    # }
    # doc2txt {C:\Temp\Test.doc}

    #### Control Matlab (don't work with Rel 12?!)
    # Start Matlab and then...
    tk2dde.exec("Matlab", "Engine", "{s = ones(5);}")
    # Then in Matlab, type s

    #### Manipulating Progman to create and delete shortcuts ####
    tk2dde.exec("progman", "progman", "{\[CreateGroup(Bogus)\]}")
    tk2dde.exec("progman", "progman", "{\[AddItem(notepad.exe,BogusPadLink)\]}")
    tk2dde.exec("progman", "progman", "{\[ShowGroup(Bogus,0)\]}")
    tk2dde.exec("progman", "progman", "{\[ShowGroup(Bogus,1)\]}")
    # And delete it...
    tk2dde.exec("progman", "progman", "{\[DeleteItem(BogusPadLink)\]}")
    tk2dde.exec("progman", "progman", "{\[DeleteGroup(Bogus)\]}")
    ## Rem: the same can be done with tcom, if installed:
    #.Tcl("package require tcom")
    #.Tcl("set sh [::tcom::ref createobject {WScript.Shell}]")
    #.Tcl("set lnk [$sh CreateShortcut {c:\\temp\\boguspad.lnk}]")
    #.Tcl("$lnk TargetPath {\"notepad.exe\"}")
    #.Tcl("$lnk WorkingDirectory {c:\\temp}")
    #.Tcl("$lnk Arguments Tutorial.txt")
    #.Tcl("$lnk Save")

    ## Controlling Internet Explorer through DDE
    # Start Internet Explorer, then...
    tk2dde.exec("iexplore", "WWW_OpenURL", "{http://www.sciviews.org/}")
    # It works, but return an error in R???
    tk2dde.exec("iexplore", "WWW_ShowFile", "{C:/progra~1/R/rw2001/doc/html/index.html}")
    # Idem
    # Info on the current opened window
    tk2dde.request("iexplore", "WWW_GetWindowInfo", "1")
    # and this does not work!)
    # tk2dde.request("iexplore", "WWW_ListWindows", "0")

    ## Controlling Windows explorer
    tk2dde.exec("Folders", "AppProperties", "{\[ViewFolder(\"C:\Temp\",\"C:\Temp\",5)\]}")
    #... or you can also try 'ExplodeFolder'

    # Search in folder
    tk2dde.exec("Folders", "AppProperties", "{\[FindFolder(\"\",\"C:\Temp\")\]}")
  ## End(Not run)


Manipulate icons under Windows

Description

Create, load and work with Windows icons. Change icons fo Windows, use icons in the taskbar under Windows 9X/2000/XP, ... These function are only useful for Windows.

Usage

  tk2ico.create(icofile)
  tk2ico.destroy(icon)
  tk2ico.hicon(icon)
  tk2ico.info(icon, convert = TRUE)
  tk2ico.load(file = "shell32.dll", res = "application")
  tk2ico.pos(icon, pos)
  tk2ico.set(win, icon, pos = NULL, type = c("all", "small", "big"))
  tk2ico.text(icon, text = NULL)
  tk2ico.taskbar.add(icon, pos = 0, text = tk2ico.text(icon), callback = NULL)
  tk2ico.taskbar.delete(icon)
  tk2ico.taskbar.modify(icon, pos = NULL, text = NULL)

Arguments

icofile | A file with a .ico extension, containing one or more Windows icons
icon | An icon object
convert | Do we convert the result into a data.frame?
file | A file having icon resources (.exe, or .dll)
res | The name of the resource from where the icon should be extracted
pos | A position (starting from 0) pointing to an icon in a multi-icon object
win | A tk window whose icon is changed
type | Do we change only the small, the large, or both icons?
text | Change a text for an icon
callback | Give a callback function called when the user clicks in the taskbar icon

Value

An icon object, which is a reference to an image resource in tcl. Do not forget to destroy it using tk2ico.destroy() when you do not need it any more!

Note

This is Windows-specific. It uses the winico 0.5 Tcl library. Under other platforms these functions just return NULL without error or warning. So, code that must run on different platforms could use these functions all the time, as soon as they correctly deal with possible NULL return.

Author(s)

Philippe Grosjean

See Also

tk2dde, tk2reg

Examples

  ## Not run:
    ## These cannot be run by examples() but should be OK when pasted
    ## into an interactive R session with the tcltk package loaded

        ## Examples of tk2ico - icon manipulation under Windows
    tt2 <- tktoplevel()
    # Load a system icon (there are: "application", "asterisk", "error",
    # "exclamation", "hand", "question", "information", "warning", and "winlogo".
    Warn <- tk2ico.load(res = "warning")
    tk2ico.info(Warn)
    # Change the text
    tk2ico.text(Warn)
    tk2ico.text(Warn, "Warning icon")
    tk2ico.text(Warn)
    # Get hicon
    tk2ico.hicon(Warn)
    # Change the icon of my window tt2
    tk2ico.set(tt2, Warn)
    # Do not forget to destroy icon to free resource when not needed any more
    tk2ico.destroy(Warn)
    rm(Warn)
    # Load an icon from the resource section of an exe, or dll
    Rico <- tk2ico.load(file.path(Sys.getenv("R_HOME"), "bin", "R.exe"), res = "R")
    tk2ico.info(Rico)
    tk2ico.set(tt2, Rico)
    tk2ico.destroy(Rico)
    rm(Rico)

    # Load one or several icons from an .ico file
    libdir <- file.path(.path.package(package="tcltk2")[1], "etc")
    SVico <- tk2ico.create(file.path(libdir, "SciViews.ico"))
    # The various resolution icons created from this file
    tk2ico.info(SVico)
    # Change the default position to 1
    tk2ico.pos(SVico, 1)
    # Change only the small icon (use Alt-Tab to see the large one)
    tk2ico.set(tt2, SVico, pos = 0, type = "small")

    ### This does not work!
    ## Set a taskbar icon (rem: should use callback usually)
    #tk2ico.taskbar.add(SVico, pos = 0, text = "{my tcltk taskbar icon}")
    ## Change its text...
    #tk2ico.tackbar.modify(SVico, text = "{text changed!}")
    ##... and delete it
    #tk2ico.taskbar.delete(SVico)

    # Destroy the icons
    tk2ico.destroy(SVico)
    rm(SVico)

    # When done, dispose of the window
    tkdestroy(tt2)
  ## End(Not run)


Manipulate the registry under Windows

Description

These functions access the Windows registry.

Usage

  tk2reg.broadcast()
  tk2reg.delete(keyname, valuename)
  tk2reg.deletekey(keyname)
  tk2reg.get(keyname, valuename)
  tk2reg.keys(keyname)
  tk2reg.set(keyname, valuename, data, type = c("sz", "expand_sz", "multi_sz",
      "dword", "dword_big_endian", "binary", "link", "resource_list", "none"))
  tk2reg.setkey(keyname)
  tk2reg.type(keyname, valuename)
  tk2reg.values(keyname)

Arguments

keyname | The name of the key.
valuename | A value in this key.
data | The data to place in the value.
type | The type of value in the registry. By default, it is "sz", that is, a string.

Value

Functions that should return a registry value return it in a character string no mather the type of value in the registry. You are responsible to coerce it to the correct type.

Note

For Windows only. These functions issue an error when they are called under other platforms. Take care while manipulating the Windows registry! You can easily lock the system completelly, if you delete important items, especially if you are logged as administrator on your computer. Make a backup of your registry first before experimenting with these function!!!

Author(s)

Philippe Grosjean

See Also

tk2dde, tk2ico

Examples

  ## Not run:
    ## These cannot be run by examples() but should be OK when pasted
    ## into an interactive R session with the tcltk package loaded

        ## Examples of tk2reg - registry manipulation under Windows
    # Rem: HKEY_LOCAL_MACHINE, HKEY_USERS, HKEY_CLASSES_ROOT, HKEY_CURRENT_USER,
    #      HKEY_CURRENT_CONFIG, HKEY_PERFORMANCE_DATA, HKEY_DYN_DATA
    Rkey <- "HKEY_LOCAL_MACHINE\\Software\\R-core\\R"   # The R key
    Rsubkey <- paste(Rkey, "subkey", sep = "\\")        # A subkey

    # Get all subkeys for Software in the local machine
    tk2reg.keys("HKEY_LOCAL_MACHINE\\Software")

    # Get all names in the R key
    tk2reg.values(Rkey)
    # Get info about registered R
    tk2reg.get(Rkey, "Current Version")
    tk2reg.get(Rkey, "InstallPath")

    # Create a subkey (explore the registry with regedit.exe to see it)
    tk2reg.setkey(Rsubkey)
    # Add something in it
    tk2reg.set(Rsubkey, "test", "a key added with tcltk2 registry!", type = "sz")

    # Get the type of a value
    tk2reg.type(Rsubkey, "test")
    # Get a value in a key
    tk2reg.get(Rsubkey, "test")

    # Delete a name in a key (take care: dangerous!)
    tk2reg.delete(Rsubkey, "test")
    # Delete a whole key (take care: very dangerous!)
    tk2reg.deletekey(Rsubkey)

    # An alternate way to get the path
    tk2reg.get("HKEY_LOCAL_MACHINE\\SYSTEM\\CurrentControlSet\\Control\\Session Manager\\Environment", "path")

    # Make sure that currently running apps are warned of your changes in the registry
    tk2reg.broadcast()

    # Delete temporary variables
    rm(list = c("Rkey", "Rsubkey"))
  ## End(Not run)


Set or get the theme in use for themed widgets (tile)

Description

In tcltk2, we propose a replacement for standard tcltk widgets. These new widgets can be "themed", that is, adapted to take various visual appearances. It can get the visual appearance of various Unix/Linux systems, of Windows (including XP) and of Aqua under MacOS. Custom themes can also be defined, or imported from GTK.

Usage

  tk2theme(theme = NULL)
  tk2theme.list()
  tk2theme.elements()

Arguments

theme The new theme to use

Value

A list of available themes for tk2therme.list() or of theme elements for tk2theme.elements()

Note

Themes are provided by the tk package Tile (currently in version 0.6.2). It is automatically installed under Windows, but for other platforms, you must download and compile Tile yourself (http://tktable.sourceforge.net/tile/)

Author(s)

Philippe Grosjean

See Also

tk2widgets, tk2tip

Examples

  ## Not run:
    ## These cannot be run by examples() but should be OK when pasted
    ## into an interactive R session with the tcltk package loaded

        ## Test all themes one after the other on the demo window
    tk2demo <- function() {
        tt <- tktoplevel()
        tktitle(tt) <- "tk2 demo"

        ## Change icon (under Windows)
        Info <- tk2ico.load(res = "information")
        tk2ico.set(tt, Info)
        tk2ico.destroy(Info)

        ## Add a menu with quit and all themes
        topMenu <- tk2menu(tt)
        tkconfigure(tt, menu = topMenu)
        fileMenu <- tk2menu(topMenu, tearoff = FALSE)
        tkadd(fileMenu, "command", label = "Quit",
                command = function() tkdestroy(tt))
        tkadd(topMenu, "cascade", label = "File", menu = fileMenu)
        Themes <- sort(tk2theme.list())
        themeMenu <- tk2menu(topMenu, tearoff = FALSE)
        for (i in 1:length(Themes)) {
                tkadd(themeMenu, "command", label = Themes[i],
                        command = eval(parse(text = paste("function() tk2theme(\"", Themes[i], "\")",
                    sep = ""))))
        }
        tkadd(topMenu, "cascade", label = "Theme", menu = themeMenu)

        #### TO DO: Add a toolbar

        ## Add a notebook with three tabs
        nb <- tk2notebook(tt)
        tcli1 <- tk2frame(nb)
        tkadd(nb, tcli1, text = "Tab 1")
        tcli2 <- tk2label(nb, text = "Nothing here.")
        tkadd(nb, tcli2, text = "Tab 2")
        tcli3 <- tk2label(nb, text = "Nothing here either.")
        tkadd(nb, tcli3, text = "Tab 3")
        tkselect(nb, tcli1)
        tkgrid(nb)

        ## Add a labelframe with new tile widgets
        tfrm1 <- tk2labelframe(tcli1, text = "tile widgets")
        tkgrid(tfrm1)

        # Add a label
        tlab <- tk2label(tfrm1, text = "This is a label... hover me to see a tooltip")
        tkgrid(tlab)
        # Define a tooltip for the label
        tk2tip(tlab, "A tooltip for the label \ndisplayed on two lines")

        # Add a button
        but <- tk2button(tfrm1, text = "Click me", width = 12,
                command = function() tkmessageBox(title = "tk2 demo",
                        message = "Hello, world!", icon = "info", type = "ok"))
        tkgrid(but)

        # Add a checkbutton
        tcb <- tk2checkbutton(tfrm1, text = " A check button")
        tkgrid(tcb)

        # Add radio buttons
        rbValue <- tclVar("oranges")
        rb1 <- tk2radiobutton(tfrm1, text = " Apples", variable = rbValue,
                value = "apples")
        rb2 <- tk2radiobutton(tfrm1, text = " Oranges", variable = rbValue,
                value = "oranges")
        tkgrid(rb1, sticky = "w")
        tkgrid(rb2, sticky = "w")

        # Add a progressbar
        tprog <- tk2progress(tfrm1, orient = "horizontal", from = 0,  to = 100)
        tkgrid(tprog)
        tkset(tprog, 0.5)

        # Add a slider #### TO DO: fix command!
        tscal <- tk2scale(tfrm1, orient = "horizontal", from = 0, to = 100,
                command = tkset(tprog, 0.2))
        tkgrid(tscal)

        ## Add a labelframe with additional widgets
        tfrm2 <- tk2labelframe(tcli1, text = "additional widgets", width = 50)
        tkgrid(tfrm2)

        # Add a combobox
        cb <- tk2combobox(tfrm2, value = "Banana")
        tkgrid(cb)
        # Fill the combobox list
        fruits <- c("Apple", "Orange", "Banana", "Pear")
        # TO DO: change this!!!
            #for (i in (1:4))
        #    tk2listinsert(cb, "end", fruits[i])
            tkinsert(cb, "end", "pear")

        tkfocus(tt)
        return(TRUE)
    }

    tk2demo()
    themes <- tk2theme.list()
    for (i in 1:length(themes)) {
        tk2theme(themes[i])
        Sys.sleep(2)
    }
  ## End(Not run)


Display and manage tooltips in tk widgets

Description

tk2tip provides a simple mechanism to display tooltips on tk widgets when the mouse hoover on top of them.

Usage

  tk2tip(widget, message)
  tk2killtip()

Arguments

widget | The widget to which a tooltip is attached
message | The message of the tooltip ("" to remove the tooltip)

Note

This implementation is done in pure tcl code

Author(s)

Philippe Grosjean

See Also

tk2widgets, tk2theme

Examples

  ## Not run:
    ## These cannot be run by examples() but should be OK when pasted
    ## into an interactive R session with the tcltk package loaded

        tt2 <- tktoplevel()
    lb <- tk2label(tt2, text = "Move mouse over me, or over the button to see tooltip")
    tkgrid(lb)
    tk2tip(lb, "A tooltip for the label \ndisplayed on two lines")
    but <- tk2button(tt2, text = "OK", width = 10,
        command = function() tkdestroy(tt2))
    tkgrid(but)
    tk2tip(but, "Another tooltip for the button")
    #### TO DO: show the use of tk2killtip()!
  ## End(Not run)


A themed series of tk widget

Description

A series of widgets you can use in your tk windows/dialog boxes.

Usage

  tk2button(parent, ...)
  tk2canvas(parent, ...)
  tk2checkbutton(parent, ...)
  tk2combobox(parent, ...)
  tk2entry(parent, ...)
  tk2frame(parent, ...)
  tk2label(parent, ...)
  tk2labelframe(parent, ...)
  tk2listbox(parent, ...)
  tk2mclistbox(parent, ...)
  tk2menu(parent, ...)
  tk2menubutton(parent, ...)
  tk2message(parent, ...)
  tk2notebook(parent, ...)
  tk2panedwindow(parent, ...)
  tk2progress(parent, ...)
  tk2radiobutton(parent, ...)
  tk2scale(parent, ...)
  tk2scrollbar(parent, ...)
  tk2separator(parent, ...)
  tk2spinbox(parent, ...)
  tk2table(parent, ...)
  tk2text(parent, ...)
  tk2tree(parent, ...)
  tk2treeview(parent, ...)

Arguments

parent | The parent window
... | Further arguments passed to the widget

Value

The reference to the created widget.

Note

Most of these widgets comes from the tile (currently 0.4) library

Author(s)

Philippe Grosjean

See Also

tk2theme, tk2tip, tk2commands

Examples

  ## Not run:
    ## These cannot be run by examples() but should be OK when pasted
    ## into an interactive R session with the tcltk package loaded

        ### A tk2notebook example
    tt2 <- tktoplevel()
    nb <- tk2notebook(tt2)
    tcli1 <- tk2label(nb, text = "Nothing here.")
    tkadd(nb, tcli1, text = "Test")
    tcli2 <- tk2frame(nb)
    but <- tk2button(tcli2, text = "Click me", command = function() tkdestroy(tt2))
    tkgrid(but)
    tkadd(nb, tcli2, text = "Button")
    tkselect(nb, tcli2)
    tkgrid(nb)

    ## A simple tk2panedwindow example
    tt2 <- tktoplevel()
    pw <- tk2panedwindow(tt2, orient = "vertical")
    lpw.1 <- tk2label(pw, text = "Panel 1")
    lpw.2 <- tk2label(pw, text = "Panel2")
    tkadd(pw, lpw.1, minsize = 100)
    tkadd(pw, lpw.2, minsize = 70)
    but <- tk2button(lpw.2, text = "OK", width = 10,
        command = function() tkdestroy(tt2))
    tkgrid(but)
    tkpack(pw, fill = "both", expand = "yes")
    # Resize the window and move the panel separator with the mouse

    ## A tk2combobox example
    tt2 <- tktoplevel()
    cb <- tk2combobox(tt2)
    tkgrid(cb)
    # Fill the combobox list
    fruits <- c("Apple", "Orange", "Banana", "Pear")
        # TO DO: change this!!!
        #for (i in (1:4))
    #    tk2listinsert(cb, "end", fruits[i])
        tkinsert(cb, "end", "pear")
        #tkconfigure(cb, value = "Pear")        # Set the current value for the combobox
    # or better: link it to a variable
    Fruit <- tclVar("Pear")
    tkconfigure(cb, textvariable = Fruit)
    # Create a button to get the content of the combobox
    but <- tk2button(tt2, text = "OK", width = 10,
        command = function() {tkdestroy(tt2); cat(tclvalue(Fruit), "\n")})
    tkgrid(but)

    ### An example of a tk2spinbox widget
    tt2 <- tktoplevel()
    tspin <- tk2spinbox(tt2, relief = "groove", from = 2, to = 20, increment = 2)
    tkgrid(tspin)
    #tdial <- tk2dial(tt2, from = 0, to = 20, resolution = 0.5, width = 70,
    #   tickinterval = 2)
    #tkgrid(tdial)
    tbut <- tk2button(tt2, text = "OK", width = 10,
        command = function() tkdestroy(tt2))
    tkgrid(tbut)

    ## A tk2mclistbox example
    tt2 <- tktoplevel()
    mlb <- tk2mclistbox(tt2, width = 55, resizablecolumns = TRUE)
    # Define the columns
    tk2column(mlb, "add", "name", label = "First name", width = 20)
    tk2column(mlb, "add", "lastname", label = "Last name", width = 20)
    tk2column(mlb, "add", "org", label = "Organisation", width = 15)
    tkgrid(mlb)
    # Fill the multicolumn list (we can use a vector, or a matrix of character strings)
    item1 <- c("Bryan", "Oackley", "ChannelPoint")
    items <- matrix(c("John", "Ousterhout", "Scriptics",
                      "Steve", "Miller", "TclTk inc."), ncol = 3, byrow = TRUE)
    tk2insert.multi(mlb, "end", item1)
    tk2insert.multi(mlb, "end", items)
    #### TO DO: bind events
    # Ex: .listbox label bind date <ButtonPress-1> "sortByDate
    # See the example.tcl in .\libs\mclistbox1.02 for a more complex example
    # Create a button to close the dialog box
    but <- tk2button(tt2, text = "OK", width = 10,
        command = function() tkdestroy(tt2))
    tkgrid(but)

    ### A simple tk2table example
    myRarray <- c("Animal", "\"sphinx moth\"", "oyster",
                  "Type", "insect", "mollusk")
    dim(myRarray) <- c(3, 2)
    for (i in (0:2))
      for (j in (0:1))
         .Tcl(paste("set tclarray(", i, ",", j, ") ", myRarray[i+1, j+1], sep = ""))
    tt2 <- tktoplevel()
    table1 <- tk2table(tt2, variable = "tclarray", rows = "3",
        cols = "2", titlerows = "1", selectmode = "extended", colwidth = "25",
        background = "white")
    tkpack(table1)
  ## End(Not run)