Menu                package:svWidgets                R Documentation

_C_o_n_v_e_n_i_e_n_t_l_y _m_a_n_i_p_u_l_a_t_e _m_e_n_u_s, _w_h_a_t_e_v_e_r _t_h_e _w_i_n_d_o_w

_D_e_s_c_r_i_p_t_i_o_n:

     These functions provide an unifying way of dealing with menus in
     R. It is ispired from the winMenuXXX() functions under Windows
     that allow easy manipulation of custom menus in Rgui.exe.
     Currently, they support all the functionnalities of winMenuXXX()
     functions and they bring a convenient similar layer on top of Tk
     menus to manipulate them in a similar way.

_U_s_a_g_e:

       MenuAdd(menu, ...)  
       MenuAddItem(menu, item, action, image = "", accel = "", options = "")
       MenuDel(menu)
       MenuDelItem(menu, item)
       MenuNames()
       MenuItems(menu)
       MenuType(menu, warn = TRUE)
       MenuChangeItem(menu, item, action = "", options = "")
       MenuStateItem(menu, item, active = TRUE)
       MenuRead(file = "Menus.txt")
       MenuReadPackage(package, subdir = "gui", file = "Menus.txt")

_A_r_g_u_m_e_n_t_s:

    menu: Name of a menu 

    item: Name of a menu item 

  action: Action the menu triggers (R code) 

   image: Name of an image to display at left of the menu item 

   accel: Accelerator (keystroke) to use to trigger this menu item 

 options: Additional options, for instance 'state = "disable"' to
          disable the menu at creation. 

     ...: Further options 

    warn: Do we issue a warning if the type of menu is not recognized? 

  active: Do we enable or disable the menu item? 

    file: A file containing menu specifications to read 

 package: Name of a package from where to load menu specifications 

  subdir: Subdirectory in the package where the menu specifications are
          stored. By default, it is the "gui" subdirectory. 

_D_e_t_a_i_l_s:

     These functions care about creating, deleting and managing custom
     menus. Informations and handles to the various menus created with
     these functions are stored in the .gui.Menus variable, located in
     the TempEnv environment.

_V_a_l_u_e:

     'MenuAdd()' return the handle to the newly created menu.
     'MenuNames()' return the list of all menus registered in
     .gui.Menus.

_A_u_t_h_o_r(_s):

     Philippe Grosjean

_S_e_e _A_l_s_o:

     'MenuNames', 'winMenuChangeItem'

_E_x_a_m_p_l_e_s:

       ## 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 and look at menus...
             
             # Create menus in Rgui, using a specification file
             MenuReadPackage("svWidgets")
             MenuNames()
             (MenuItems("$ConsoleMain/Testit"))
             
             # Create menus manually in Rgui
         MenuAdd("$ConsoleMain/Testit2")
             MenuAddItem("$ConsoleMain/Testit2", "Trial", "ls()")
             MenuNames()
             (MenuItems("$ConsoleMain/Testit2"))
             MenuStateItem("$ConsoleMain/Testit2", "Trial", FALSE)
             MenuStateItem("$ConsoleMain/Testit2", "Trial", TRUE)
             # This is buggy! -> MenuChangeItem("$ConsoleMain/Testit2", "Trial", "search()")
             (MenuItems("$ConsoleMain/Testit2"))
             
             # Create and manipulate Tk menus
             tkWinAdd("tt", title = "A Tk window with menus", pos ="-40+20")
             MenuAdd("$Tk.tt/Misc")
             MenuNames()
             (MenuItems("$Tk.tt/Misc"))   # Still nothing in it
             MenuAddItem("$Tk.tt/Misc", "List &variables", "print(ls(envir = .GlobalEnv))")
             MenuAddItem("$Tk.tt/Misc", "Say &yo!", "cat('yo!\n')")

             MenuDelItem("$Tk.tt/Misc", "Say &yo!")
             MenuAddItem("$Tk.tt/Misc", "-")
             MenuAddItem("$Tk.tt/Misc", "&Say yo! twice", "cat('yo! yo!\n')")
             (MenuItems("$Tk.tt/Misc"))

             tkImgReadPackage("svWidgets")   # Make sure images are loaded
             MenuAdd("$Tk.tt/Misc/Sub&Menu")
             MenuAddItem("$Tk.tt/Misc/Sub&Menu", "T&rial", "cat('Trial trigerred!\n')")
             MenuAddItem("$Tk.tt/Misc", "Tria&l2", "cat('Trail with image and accel!\n')",
                     image = "$Tk.butOpen", accel = "Ctrl+T")
             MenuNames()
             (MenuItems("$Tk.tt/Misc"))
             MenuStateItem("$Tk.tt/Misc", "Tria&l2", FALSE)
             MenuStateItem("$Tk.tt/Misc", "Tria&l2", TRUE)
             MenuStateItem("$Tk.tt/Misc", "Sub&Menu", FALSE)
             MenuStateItem("$Tk.tt/Misc", "Sub&Menu", TRUE)
             MenuChangeItem("$Tk.tt/Misc", "Tria&l2", options = "underline = 1")
             # This is the way to change binding
             tkbind(WinGet("tt"), "<Control-r>", function() tkMenuInvoke("$Tk.tt/Misc", "Tria&l2"))
             MenuChangeItem("$Tk.tt/Misc", "Tria&l2", action = 'cat("new action for Tria&l2!\n")')
             tkMenuInvoke("$Tk.tt/Misc", "Tria&l2")
             (MenuItems("$Tk.tt/Misc"))
             MenuDelItem("$Tk.tt/Misc", "Tria&l2")
             MenuDel("$Tk.tt/Misc")
             MenuNames()
             (MenuItems("$Tk.tt/Misc"))
             tkWinDelete("tt")
       ## End(Not run)

