Skip to content
Prev 5057 / 63424 Next

tk non-widget commands (esp. update and winfo)

Peter Dalgaard BSA <p.dalgaard@biostat.ku.dk> writes:
Requiring the user to do the "type casting" will make the user's code
larger and will make it harder to adopt the package.  It would be nice
if the information would "flow more easily" to the programmer.  I
don't want to have to use more as.whatever than I have to in other
functions.
OK, instead of going for enchilladas, how about burritos:

For a graphics device, I would use
  > par("xaxp")  # to obtain values
  [1]  2 10  4
  > par (xaxp=c(2,10,4))  # to set values

Wouldn't something similar to this effect simplify the api and reduce
the number of commands in the package (vastly)?

1) Why not

  > tt<-tktoplevel()
  > button <- tkbutton(tt, text="Push", command=function()cat("Ouch\n"))
  > tkpar (button, c("text", "command"))
  $text
  [1]  "Push"

  $command
  [1] " R_call 0xbfeb1c "

  > tkpar (button, text="Yow!", command=function()cat("Yow\n"))

instead of:

  > tkcget (button, "-text")  # (hmm, shouldn't need '-' here!)
  [1] "b"
  > tkcget (button, "-command")  # (again, why '-command'?)
  [1] " R_call 0xbfeb1c "
  > tkconfigure (button, text="Yow!", command=function()cat("Yow\n"))
  [1] ""
  > # Doesn't return previous value...

This examples applies to a bunch of command pairs, like
cget/configure, itemcget/itemconfigure, imagecget/imageconfigure,
entrycget/entryconfigure, window.cget/window.configure, ...

2) Why not:

  > tt <- tktoplevel()
  > tkwm (tt, "minwidth")  # returns integers not strings
  [1] 1 1
  > tkwm (tt, minwidth=c(100,100))  # sets new values

instead of:

  > tkwm.minsize (tt)
  [1] "1 1"
  > tkwm.minsize (tt, "100","100")
  [1] ""

The second example would wipe out 25 or so tkwm.* commands to be
replaced by one tkwm.  (Same would apply for tkwinfo...)  Wouldn't
that also simplify maintenance and documentation?

Does this make sense?  Or does it sound like I've been smoking my corn
flakes instead of eating them?  Is anybody else using the package
tcltk and would it make sense to put some code behind those
suggestions?

Thanks,
  -tom