Hi,
I'm using wxPython embedded within R. It's working nicely on
Windows, but I'm still having some problems in Gtk/Fedora Linux.
I'm trying to make the interface appear not-too-object-oriented
from the R user's point of view, e.g.
wxMessageBox(title="Title",message="Message")
rather than telling the user that they have to define a class
for everything.
The way it's done currently is to write out a temporary file
(i.e. a Python module) which defines:
1. a class, and
2. a function to create an instance of that class
and then show the widget/window.
This is working without any problems for message dialogs, I can
create several message boxes, one after another without any
problems in R-wxPython (using Gtk/Linux).
But for frames and dialogs, when I run my function to show the
frame or dialog, nothing happens. But then the next time I ask
wxPython to show a widget/window/message box, then the previous
frame/dialog/widget/window appears:
frm <- wxFrm(title="The frame") # Create a frame object in R
frm <- wxAdd(frm, txt=wxTextCtrl()) # Add a text control
frm <- wxShow(frm) # Generate Python code and show frame
# NOTHING HAPPENS, UNTIL...
wxMessageBox(message="Hello")
Now the message box appears AND the frame, but the frame is not
interactive, i.e. there's no flashing cursor in the text area
for typing text into it, although the mouse pointer does
change to the correct text-mouse-pointer when the mouse is
inside the text area.
Also, I can't seem to close or destroy the late-appearing frame
window unless I manually kill it.
I'll include below the Python module automatically generated
(as a temporary file) by my R-wxPython interface, but first,
here's the R-Python command which calls the function from that
module:
.Python("wxRPyFrame",title,x,y,width,height,
.module = "/tmp/RtmpH13622/wx19495cff.py"))
Widget IDs are generated from within R using:
.Python("wxNewId", .module = "wxPython.wx")
···
------------------------------------------------------------------------------
/tmp/RtmpH13622/wx19495cff.py
------------------------------------------------------------------------------
import wxPython.wx
from wxPython.wx import *
import RS
def wxRPyFrame(Title,X,Y,Width,Height):
class theframe(wxFrame):
def __init__(self,parent,ID,title,pos,size):
id = 106
wxFrame.__init__(self,parent,id,title,pos,size)
self.txt = wxTextCtrl(parent=self,value='',style=(wxTE_MULTILINE|wxHSCROLL),name='wxRPyTextCtrl2',validator=wxDefaultValidator,id=107)
frm = theframe(parent=None,ID=106,title=Title,pos=wxPoint(X,Y),size=wxSize(Width,Height))
frm.Show(1)
return frm
------------------------------------------------------------------------------
Regards,
James