R: Rgtk2: gwidgets: gWidgetsRGtk2

北城以北 提交于 2019-12-13 16:45:39

问题


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

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)

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.

The code in R is as follows:

###########################
# 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)
    }

###########################

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

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


回答1:


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

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

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.



来源:https://stackoverflow.com/questions/8870635/r-rgtk2-gwidgets-gwidgetsrgtk2

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!