tags:

views:

61

answers:

2

Can I find out if my toplevel window is maximized, and can I maximize it programmatically? I am using R's tcltk package 8.5 on Windows XP.

The reason for the question is: I want to enforce a <Visibility> event by calling first withdraw and then deiconify. However, if the window was maximized before these two function calls, it is not after these calls. Is there an easier way to enforce the event?

+1  A: 

Wrote a function that propagates the Visibility event to a given widget and all its children.

tkevent.propagate <- function(w,e) {
  tkevent.generate(w, e)
  children <- as.character(tkwinfo("children", w))
  if(length(children)>0) lapply(children, function(c) tkevent.propagate(c,e))
}

This way, I don't need to call withdraw/deiconify and get my event to each widget.

Karsten W.
+1  A: 

You can discover the whether the window is maximized with wm state $toplevel (look for zoomed as a return value). But…

The OS doesn't generate <Visibility> events properly for you on Windows; you only get them on the window being mapped, and that's subtly different. (Windows tells you much less about the stacking order and its consequences than X does; Tk's pretty close to X's model.) You don't say why you want this event though; perhaps there's something else that will serve your real purpose?

Donal Fellows
BTW, I'm using Tcl syntax; you may need to convert for R (which I'm totally ignorant about).
Donal Fellows
The R equivalent to your command is tkwm.state(toplvl) and works just fine! What do you mean by "the window being mapped"? The purpose I bind to <Visibility> is this: I have a window with a "update" button and a notebook below that button. Now I want to execute some code after the user presses the update button on the currently selected tab, and on the other tabs whenever they are selected. The <Visibility> solution works now as far as I can see, but if there is something more natural I really would like to know.
Karsten W.
@Karsten: If you're using the notebook from the ttk widget set, you get a `<<NotebookTabChanged>>` (virtual) event when a different tab is chosen. The ttk notebook reports which tab is selected with `$nb select` (and no further arguments). http://www.tcl.tk/man/tcl8.5/TkCmd/ttk_notebook.htm#M29
Donal Fellows