我想把gWidgets(john verzani)和Rgtk2组合起来。这可以被任何人用作范例。
算法如下:第一步:构造gwindow (或gframe)第二步:构造GTK可滚动文本视图第三步:将最后一个转换为gwidget第四步:将其添加到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的主题,我也想道歉。提前谢谢你
发布于 2012-01-16 01:10:05
您是对的,您可以使用add()将RGtk2对象插入到gWidgetsRGtk2图形用户界面中。但是在这种情况下,您可以省去使用getToolkitWidget()的一些工作
library(RGtk2)
library(gWidgets)
options(guiToolkit="RGtk2")
w <- gwindow(); txt <- gtext("", cont=w)
text_view <- getToolkitWidget(txt)
buffer <- text_view$getBuffer()
...要获得gtkScrollWindow对象,您需要知道它是text_view:text_view$getParent()的父对象。
最后一点,您的步骤3可以工作,应该为您的对象提供gWidgets方法,但这并不是必需的。只需添加RGtk2对象即可。我没有在重写gWidgets2中包含这些"as“方法(在github上,大部分都在工作,但没有完成),因为它看起来并不是那么有用。
https://stackoverflow.com/questions/8870635
复制相似问题