我想将 gWidgets(john verzani) 与 Rgtk2 结合使用。任何人都可以将其用作范例。
算法如下: STEP 1:构造一个 gwindow(或 gframe) STEP 2:构造一个 GTK 可滚动文本视图 STEP 3:将最后一个转换为 gwidget STEP 4:将其添加到 gwindow(或 gframe)中
我想知道这是否是正确的想法,而我面临的问题是 GTK 可滚动文本视图:我无法使滚动条工作。
R中的代码如下:
###########################
# load libraries
library(RGtk2)
library(gWidgets)
library(gWidgetsRGtk2)
# data set
x <- c(1:9)
y <- c(10:19)
z <- c(20:29)
df <- data.frame(x, y, z)
df.co <- capture.output(df)
###########################
# STEP 1, library(gWidgets)
# Construct a gwindow (or a gframe)
G.Window <- gwindow()
###########################
# STEP 2, library(RGtk2)
# Construct a GTK scrollable text view
Gtk.Text.View <- gtkTextViewNew(show = TRUE)
# create a table to attach the scrollbars
Gtk.Table.New <- gtkTableNew(2, 2, show = TRUE)
# construct the scrollbars
Gtk.H <- gtkHScrollbarNew()
Gtk.V <- gtkVScrollbarNew()
# attach the text view and the scrollbars to the table
gtkTableAttach(Gtk.Table.New, Gtk.Text.View, 0, 1, 0, 1)
gtkTableAttach(Gtk.Table.New, Gtk.H, 0, 1, 1, 2)
gtkTableAttach(Gtk.Table.New, Gtk.V, 1, 2, 0, 1)
# The scrollbars are not functional, for now.
# So I thought of constructing a viewport.
# The problem I face is that I cannot make the scrollbars work.
Gtk.Viewport <- gtkViewportNew()
###########################
# STEP 3, library(gWidgetsRGtk2)
# Convert the table into a gwidget
G.Table.View <- as.gWidgetsRGtk2(Gtk.Table.New)
###########################
# STEP 4, library(gWidgets)
# Add the table into the gwindow (or into the gframe)
add(G.Window, Gtk.Table.New)
# STEP 5, make the buffer management
Gtk.Text.View.Get.Buffer <- gtkTextViewGetBuffer(Gtk.Text.View)
for (i in 1:length(df.co))
{
Gtk.Text.Buffer.Get.Bounds <- gtkTextBufferGetBounds(Gtk.Text.View.Get.Buffer)
Gtk.Text.Buffer.Insert <- gtkTextBufferInsert(Gtk.Text.View.Get.Buffer, iter=Gtk.Text.Buffer.Get.Bounds$end, text=paste(df.co[i], "\n", sep="", collapse=""), len=-1)
}
###########################
我不想使用 GTK 可滚动窗口,因为我希望 GTK 文本/表格小部件在转换为 gWidget 后也能进入窗口 (gWidget)。
如果这不是 stackoverflow 的主题,我也想道歉。先感谢您