[R] Problem with geometry manager in TclTK

2009-10-19 Thread Gabriel Margarido
Hello, everyone.

I have the following problem with TclTk: I create some windows and want to
change their position with geometry manage (sometimes they will be centered,
sometimes not).
If the toplevel is created and its dimensions are gathered via 'tkwinfo', I
get (usually) correct values. However, if this window is created by a
function (in the following example, by 'ask.format') and this function is
called by another function ('inputDialog', as follows), I always get the
value '1' for width and height.

Provided below is quite detailed code, containing pretty much my entire
functions, except the parts not related to TclTk.

Thank you in advance,
Gabriel Margarido.

CODE:

library(tcltk)

ask.format - function() {
  ask.form - tktoplevel()
  tkgrab.set(ask.form)
  tkfocus(ask.form)
  tkwm.title(ask.form,Input Format)
  tkwm.resizable(ask.form, 0, 0)

  file.format - tclVar(1)
  ReturnFormat - ID_CANCEL

  Title.frame - tkframe(ask.form, relief=groove)
  tkgrid(tklabel(Title.frame,text=Input File Format, font=Times 15,
foreground=dark red))
  tkgrid(Title.frame)

  Choose.frame - tkframe(ask.form, relief=groove, borderwidth=2)
  file.format1 - tkradiobutton(Choose.frame)
  file.format2 - tkradiobutton(Choose.frame)
  tkconfigure(file.format1, variable=file.format, value=1)
  tkconfigure(file.format2, variable=file.format, value=2)
  tkgrid(tklabel(Choose.frame, text=Format 1 ),file.format1)
  tkgrid(tklabel(Choose.frame, text=Format 2 ),file.format2)
  tkgrid(Choose.frame)

  onOK - function() {
ReturnFormat - tclvalue(file.format)
tkgrab.release(ask.form)
tkdestroy(ask.form)
  }
  onCancel - function() {
tkgrab.release(ask.form)
tkdestroy(ask.form)
  }

  Buttons.frame - tkframe(ask.form, relief=groove)
  OK.but - tkbutton(Buttons.frame, text =  OK , command = onOK)
  cancel.but - tkbutton(Buttons.frame, text = Cancel, command = onCancel)
  tkgrid(cancel.but, OK.but, ipadx=20)
  tkgrid(Buttons.frame)


  print(as.integer(tclvalue(tkwinfo(height, ask.form


  tkbind(ask.form, Destroy, function() onCancel)
  tkbind(ask.form, KeyPress-Return, onOK)
  tkbind(ask.form, KeyPress-Escape, onCancel)

  tkwait.window(ask.form)

  return(ReturnFormat)
}



inputDialog - function() {
  input - tktoplevel(background=white)
  tkgrab.set(input)
  tkfocus(input)
  tkwm.title(input, Data Input)
  tkwm.resizable(input, 0, 0)

  OpenVal - c(0,0)

  getfile - function() {
### HERE I WOULD ALSO LOAD THE INPUT FILE, BUT THIS IS NOT RELEVANT
inputformat - ask.format()
if (inputformat == ID_CANCEL) return()
OpenVal[1] - 1
tkgrab.release(input)
tkdestroy(input)
  }

  tkgrid(tklabel(input, text = Choose an input
file,background=white,font=Times 13),columnspan=3)
  button.file - tkbutton(input, text = Open Input Data File, command =
getfile)
  button.exit - tkbutton(input, text = Exit, command = function()
{tkdestroy(input); OpenVal[2] - 1})
  tkgrid(button.file, button.exit)

  tkfocus(input)
  tkbind(input, Destroy, function() {tkgrab.release(input); OpenVal[2]
- 1})
  tkwait.window(input)

  return(OpenVal)
}

ask.format() ## this works, although with some variation in values
inputDialog() ## window size is always 1

[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


[R] Memory allocation

2009-01-16 Thread Gabriel Margarido
Hello everyone,

I have the following issue: one function generates a very big array (can be
more than 1 Gb) and returns a few variables, including this big one. Memory
allocation is OK while the function is running, but the final steps make
some copies that can be problematic. I looked for a way to return the values
without copying (even tried Rmemprof), but without success. Any ideas?
The code looks like this:

myfunc - function() {
...
bigarray - ...
...
final - list(..., bigarray=bigarray, ...)
class(final) - myfunc
final
}

Thank you in advance,
Gabriel.

[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.