/
ggroup.R
135 lines (104 loc) · 4.57 KB
/
ggroup.R
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
## class in aaaClasses.R
## constructor
setMethod(".ggroup",
signature(toolkit="guiWidgetsToolkittcltk"),
function(toolkit,
horizontal = TRUE, spacing = 5,
use.scrollwindow = FALSE,
container = NULL, ...
) {
force(toolkit)
theArgs = list(...) # raise.on.dragmotion
if(is.null(spacing))
spacing = 0
if(is.null(container)) {
cat(gettext("No NULL containers in tcltk. Creating a new window\n"))
container=gwindow()
} else if(is.logical(container) && container) {
container = gwindow()
}
if(!is(container,"guiWidget")) {
container = gwindow()
}
tt <- getWidget(container)
## implement scrollbars if asked.
if(use.scrollwindow == TRUE) {
## cf http://mail.python.org/pipermail/python-list/1999-June/005180.html
block <- ttkframe(tt)
tkpack(block, expand=TRUE, fill="both")
xscr <- ttkscrollbar(block, orient="horizontal",
command=function(...)tkxview(widget,...))
yscr <- ttkscrollbar(block,
command=function(...)tkyview(widget,...))
widget <- tkcanvas(block)
tkconfigure(widget, xscrollcommand = function(...) tkset(xscr,...))
tkconfigure(widget, yscrollcommand = function(...) tkset(yscr,...))
## Pack into a grid
## see tkFAQ 10.1 -- makes for automatic resizing
tkgrid(widget,row=0,column=0, sticky="news")
tkgrid(yscr,row=0,column=1, sticky="ns")
tkgrid(xscr, row=1, column=0, sticky="ew")
tkgrid.columnconfigure(block, 0, weight=1)
tkgrid.rowconfigure(block, 0, weight=1)
## call in autoscroll
tcl("autoscroll", xscr)
tcl("autoscroll", yscr)
## Set up frame
gp <- ttkframe(widget)
tcl(widget,"create","window",0,0,anchor="nw",window=gp)
#tkgrid(gp, row = 0, column = 0, sticky="news")
tkgrid.columnconfigure(widget,0,weight=1)
tkgrid.rowconfigure(widget,0,weight=1)
tcl("update","idletasks")
tkbind(widget,"<Configure>",function() {
bbox <- tcl(widget,"bbox","all")
tcl(widget,"config",scrollregion=bbox)
})
tkbind(gp,"<Configure>",function() {
bbox <- tcl(widget,"bbox","all")
tcl(widget,"config",scrollregion=bbox)
})
} else {
gp <- ttkframe(tt)
tkconfigure(gp, borderwidth=10) # XXX
block <- gp
widget <- NULL # for later
}
tkconfigure(gp, padding=spacing)
if(!is.null(theArgs$debug))
tkconfigure(gp,borderwidth=4, relief="solid")
obj = new("gGrouptcltk",block=block, widget=gp, horizontal=horizontal,
e = new.env())
## to move widget when scrolling
## if(!is.null(widget <- tag(value,"scrollable.widget"))) {
## tkxview.moveto(widget,1)
## tkyview.moveto(widget,1)
## }
## .tag(obj,toolkit, i="scrollable.widget") <- widget
obj@e$i <- widget
## attach to container if there
if(!is.null(container)) {
add(container, obj,...)
}
## raise if we drag across
if(!is.null(theArgs$raise.on.dragmotion)) {
# tkbind(gp, "<Motion>", function(W) {
# tkfocus(W)
# })
}
return(obj)
})
##################################################
## methods
setReplaceMethod(".svalue",
signature(toolkit="guiWidgetsToolkittcltk",obj="gGrouptcltk"),
function(obj, toolkit, index=NULL, drop=NULL, ..., value) {
## adds some breathing room to object
## value is pixels
gp <- getWidget(obj)
# tkcofigure(gp,padx=value,pady=value)
tkconfigure(gp,padding = value)
return(obj)
})
##################################################
## handlers