Search code examples
rgwidgets

R : How to show a Save File Dialog to save my file in gWidgets


I want to save my file by GUI Save wizard in gWidgets.

From Save Wizard I want to say as we can choose file with file.choose(), similarly how we can save our file using any save wizard in R gWidgets

Kindly give suggestion


Solution

  • Short answer: You can't. Long answer: you can by making your own menu.

    To do that create, the graphics device passing no_popup=TRUE to the constructor.

    Then you are free to add your own popup menu. The one in ggraphics is basically this (pointing you to gfile as Thomas did):

    library(gWidgets)
    g = ggraphics(cont=gwindow(), no_popup=TRUE)
    
    l <- list()
    l$copyAction <- gaction("Copy", "Copy current graph to clipboard", icon="copy",
                            handler=function(h, ...) copyToClipboard(obj))
    l$printAction <- gaction("Save", "Save current graph", icon="save",
                             handler=function(h,...) {
                               fname <- gfile(gettext("Filename to save to"), type="save")
                               if(nchar(fname)) {
                                 if(!file.exists(fname) || gconfirm(gettext("Overwrite file?")))
                                   svalue(obj) <- fname
                               }
                             })
    
    add3rdMousePopupmenu(g, l)