R:Rgtk2:小工具:gWidgetsRGtk2 [英] R: Rgtk2: gwidgets: gWidgetsRGtk2

查看:359
本文介绍了R:Rgtk2:小工具:gWidgetsRGtk2的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想将gWidgets(john verzani)与Rgtk2组合在一起. 任何人都可以将其用作范例.

I would like to combo gWidgets(john verzani) with Rgtk2. This could be used by anyone as a paradigm.

算法如下: 步骤1:构造一个gwindow(或一个gframe) 步骤2:构建GTK可滚动文本视图 步骤3:将最后一个转换为小工具 第4步:将其添加到gwindow(或gframe)中

The algorithm is as follows: STEP 1: Construct a gwindow (or a gframe) STEP 2: Construct a GTK scrollable text view STEP 3: Convert the last one into a gwidget STEP 4: Add it into the gwindow (or into the gframe)

我想知道这是否是正确的想法 而我面临的问题是GTK可滚动文本视图: 我无法使滚动条正常工作.

I wonder if this is a right thinking while the problem I face is with the GTK scrollable text view: I cannot make the scrollbars work.

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).

I do not want to use a GTK scrollable window, since I want the GTK text/table widget after it is converted into a gWidget, to enter also into a window (gWidget).

如果这不是stackoverflow的主题,我也想道歉.预先谢谢你

I also want to apologize if this is not a subject for stackoverflow. Thank you in advance

推荐答案

您是对的,可以使用add()将RGtk2对象插入gWidgetsRGtk2 GUI.但是在这种情况下,您可以使用getToolkitWidget()节省一些工作:

You are right in that you can use add() to insert RGtk2 objects into a gWidgetsRGtk2 GUI. But in this case, you can likely save yourself some work with 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().

To get your hands on the gtkScrollWindow object requires you to know that it is the parent of the text_view: text_view$getParent().

最后一条评论,您的第3步有效,应该为您的对象提供gWidgets方法,但这不是必需的.只需添加RGtk2对象.我没有在重写gWidgets2(在github上并且大多数情况下工作但未完成)中包括这些"as"方法,因为它似乎没有太大用处.

One last comment, your step 3 works and should give your object the gWidgets methods, but isn't necessary. Just add the RGtk2 object. I did not include these "as" methods in the rewrite, gWidgets2 (on github and mostly working but not finished) as it didn't seem so useful.

这篇关于R:Rgtk2:小工具:gWidgetsRGtk2的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆