简体   繁体   中英

gWidgets resize/maximize modal window

My script needs to wait for user input before continuing its processing. After using the R gWidgets package to implement a GUI, I found that the gbasicdialog widget works better than gwindow because it is modal.

The gwindow widget has useful minimize and maximize buttons. The gbasicdialog widget does not have these buttons and I often display large gtables in the GUI, which means the user has to repeatedly click-and-drag to expand the window to see enough of the table.

So far, I adjust the size of the gtable widget as follows:

library(gWidget)
library(gWidgetsRGtk2)
library(RGtk2)
options(guiToolkit = "RGtk2")

mywindow <- gbasicdialog("Display table", do.buttons = FALSE)
# there can be multiple ggroups to one table, which all occupy the gbasicdialog
mygroup <- ggroup(container = mywindow, horizontal = FALSE) 
mytable <- gtable(a_data_frame, container = mygroup, expand = TRUE, fill = TRUE)
size(mytable) <- c(500, 500) # or any other large enough dimension
exitbutton <- gbutton("Done", container = mywindow, 
                      handler = function(h, ...) {
                      #some steps
                      dispose(mywindow)
                      })
visible(mywindow, TRUE)

How can I display the maximize/minimize buttons, or display as much of a large widget as possible, for a interactive/modal window?

After looking into the Gtk toolkit, there are certain methods that pertain to the GtkWindow and GtkDialog . The Maximize method (automatically maximizing the widget) applies to both but the SetDecorated method (displaying upper bar containing minimize,maximize,close buttons) only works for the GtkWindow.

We can obtain the resizing buttons using the gwindow widget while adding a repeat loop to pause execution of the remaining script, maintaining modal/interactive behaviour. The step to automatically maximize the widget, found in jverzani's comments, can also be added to this gwindow.

currentenv <- environment() # get current environment
mybool <- FALSE # remains FALSE until the gwindow is closed
mywindow <- gwindow("Display table") 

# Implement auto-maximized gwindow if needed
getToolkitWidget(mywindow)$maximize()

# there can be multiple ggroups to one table, which all occupy the gwindow
mygroup <- ggroup(container = mywindow, horizontal = FALSE) 
mytable <- gtable(a_data_frame, container = mygroup, expand = TRUE, fill = TRUE)
# Upon exit, assign TRUE to variable denoting gwindow is closed
exitbutton <- gbutton("Done", container = mygroup, 
                      handler = {
                          # (some steps)
                          # possibly returning svalue(mytable)

                          # remove ggroup to prevent error
                          delete(mywindow, mygroup) 

                          # close window and confirm closure
                          dispose(mywindow) 
                          assign("mybool", TRUE, envir = currentenv) 
                      })

# Executes repeat loop until mywindow is closed
repeat{
    if(mybool){
        break
    }
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM