Thanks, John, Here is some code to show what I want to do. BTW, it seems there is a bug in svalue in gWidgetstcltk for gtext when using the drop=T argument.
getsel <- function(obj, toolkit, ...) { ### get the selected text from gtext getWidget <- gWidgetstcltk:::getWidget if(tclvalue(tktag.ranges(getWidget(obj),"sel")) != "") ### notice ### gWidgetstcltk's _svalue(drop=T)_ has bug. should add tclvalue to the above line. { val = tclvalue(tkget(getWidget(obj),"sel.first","sel.last"))} else val =""#tclvalue(tkget(getWidget(obj),"0.0","end")) val = unlist(strsplit(val,"\n")) return(val) } get_index <- function(obj, toolkit, ...) { ### get the selected text from gtext, return the index instead of text. getWidget <- gWidgetstcltk:::getWidget if(tclvalue(tktag.ranges(getWidget(obj),"sel")) != ""){ val = strsplit(tclvalue(tktag.ranges(getWidget(obj), "sel")), " ")[[1]]} else val =c(0,0) return(as.numeric(val)) } require(gWidgets) #initial parameters, storing the relavant information freecodes <- c("node1","node2") n_coding <- 0 node <- character(10000) chunk <- character(10000) begin <- numeric(10000) end <- numeric(10000) imported_file <- readLines(file.path(R.home(),"COPYING")) codepanel <- gpanedgroup(container=gwindow("Code bar"), horizontal = FALSE) addcode = gdroplist(freecodes,0,container=codepanel,editable=TRUE) addcodebutton <- gbutton("Add new code",container=codepanel,handler=function(...) { if(svalue(addcode)!="") addcode[length(addcode)+1]<-svalue(addcode) } ) ## allow the user to change the extant codes -- related to "freecodes" parameter updatecodes <- gbutton("Update Codes",container=codepanel,handler=function(...) assign("freecodes",addcode[seq_len(length(addcode))],pos=1)) ## get the items in gdroplist, and push it to variable "freecodes" coding <- gbutton(" Coding ",container=codepanel,handler= function(...){ if (svalue(addcode)!="" && sel!=""){ sel <<- paste(getsel(ed),collapse="\n") sel_index <<- get_index(ed) n_coding <<- n_coding + 1 node[n_coding] <<- svalue(addcode) chunk[n_coding] <<- sel begin[n_coding] <<- sel_index[1] end[n_coding] <<- sel_index[2] }} ) ## coding: get seleted text from gtext and link it to specific code/node. ed <- gtext(con=T,width=500) # gtext svalue(ed) <- imported_file # push it file to gtext # steps to using this "toy": 1, enter new code names into the droplist box, for example node3, then click "add new code" 2, select specific code, for example node2. 3, select text chunk in the gtext, and click coding. repeat step 3 in coding process. 4, We can see what's been coded by inpecting variable of "node","chunk". What I don't know how to do: 1, When I select specific code, and click some button (for example highligh), all the text chunk related to that code will be highlighted (through color or font style etc.) 2, I would like to arganize the codes like a tree. The code tree and reorganized by drag and drop. 3, In the coding buttong, how can I avoid using <<- in handler function. 2008/1/22, j verzani <[EMAIL PROTECTED]>: > ronggui <ronggui.huang <at> gmail.com> writes: > > > Thanks. > > > > gWidgets is quite good. However, I want to get the selection text chunk as > > well as the index, but the index arguments does not work for gtext. > > > > > obj<-gtext(cont=T) > > > svalue(obj,drop=T) > > [1] "cde" > > > svalue(obj,drop=T,index=T) > > [1] "cde" > > > > > > The svalue method has the index argument for the widgets where you might want > to > return the index or value such with a radio button group or combobox. For > gtext, the drop argument when TRUE returns just the text selected by the > mouse, > otherwise the entire text buffer is returned. > > library(gWidgets) > options("guiToolkit"="RGtk2") > obj = gtext("sadfsad",cont=T) > svalue(obj) ## returns: "sadfsad\n" > svalue(obj,drop=TRUE) ## returns "" > ## now highlight some text > svalue(obj,drop=TRUE) ## returns "dfsa" > > If you want to email me a bit more detail as to what you are trying to do, I > can > let you know if gWidgets can work for you. > > --John > > > > > 2008/1/21, Gabor Grothendieck <ggrothendieck <at> gmail.com>: > > > > > > You can find examples of using tcltk here: > > > > > > http://www.sciviews.org/_rgui/tcltk/ > > > > > > Also the gwidgets package is a toolkit independent > > > layer that can run on top of tcltk or RGtk and it is described > > > with many examples here: > > > > > > http://wiener.math.csi.cuny.edu/pmg/gWidgets > > > > > > On Jan 21, 2008 4:02 AM, ronggui <ronggui.huang <at> gmail.com> wrote: > > > > What I want to do is: > > > > 1, creat a text box, insert text into that box. > > > > 2, select chunk of of the text by mouse, and link it to a lable. so I > > > would > > > > like a way to get that chunk of text. > > > > > > > > Can I do such job with tcltk? Any relavant tutorial materials? > > > > > > > > Thanks > > > > > > > > -- > > > > HUANG Ronggui > > > > > > > > Bachelor of Social Work, Fudan University, China > > > > > > > > Master of sociology, Fudan University, China > > > > > > > > Ph.D. Student , CityU of HK, > > > > > > > http://www.cityu.edu.hk/sa/psa_web2006/students/rdegree/huangronggui.html > > > > > > > > [[alternative HTML version deleted]] > > > > > > > > ______________________________________________ > > > > R-help <at> 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-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. > -- HUANG Ronggui Bachelor of Social Work, Fudan University, China Master of sociology, Fudan University, China Ph.D. Student , CityU of HK, http://www.cityu.edu.hk/sa/psa_web2006/students/rdegree/huangronggui.html ______________________________________________ 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.