Skip to content

[R-gui] FXPy R Gui toolkit?

5 messages · Greg Riddick, James Wettenhall, Philippe GROSJEAN +1 more

#
I've used wxWidgets on Windows and I don't think it's that hard to compile.
It works very well with DevC++ which comes bundled with the MingW compiler.
See: http://www.wxwindows.org/devcpp.htm

Also, I don't think an extra meg or two of libraries it that big of a deal.
Especially since the R base distribution is approaching 20 megs on some platforms.
No linking issues with wxPython b/c wxWidgets is just a pre-compiled library in this case.
Widgets are created dynamically by Python at run time. Python is easy to work with, but might as well make the whole gui compiled code IMHO.
#
Greg and others,

Sorry if this seems like rehashing the past, but I'm trying to 
at least cite actual examples, compilers etc. not just discuss 
general GUI philosophies for the future...

Thanks very much for the tips on building wxWindows without 
MS Visual C++.  I was just put off initially by my failed 
attempts to build wxWindows source code with MinGW from the 
command-line.

In terms of using pre-built binaries and going through 
Python, I think I'd now contradict my last email and look more 
favorably upon wxPython (Python interface to wxWindows/wxWidgets),
as Dirk and Greg and others suggested.  It has features FOX 
doesn't yet have like Unicode and doesn't seem to crash as often 
in my (very preliminary and extremely ignorant) tests.  So I've 
changed the email subject-line to wxPython.

Of course bringing in another scripting language (Python) is not 
optimal, but it just seems like such a daunting task for anyone 
to develop a direct R-wxWindows or R-FOX or R-... interface. 
So going through Python (or similar) doesn't seem too bad 
as a first step (as we can learn from R-Tcl/Tk).

So despite my initial pains of trying to build wxWindows from 
source, I did find it quite easy to call a wxPython script 
from RSPython:

library(RSPython)
importPythonModule("wxPython.wx")
.Python("wxHello",.module="wxHello")

[ "Hello World" WX window appears succesfully! ]

where the wxHello.py module is a GUI Hello-World wxPython 
script within my python search path. 

The python search path can be found with:
importPythonModule("sys")
.Python("path",.module="sys")

=================================================
wxHello.py
=================================================
from wxPython.wx import wxPySimpleApp, wxFrame

def wxHello():
    app = wxPySimpleApp()
    frame = wxFrame(None, -1, "Hello World")
    frame.Show(1)
    app.MainLoop()
=================================================

HOWEVER, I haven't had any luck so far with doing this step by 
step from R.  An example of what I tried is included below.
If anyone else feels like playing with RSPython / wxPython 
and has any ideas, I would be most appreciative. 

Regards,
James

Sys.putenv(PYTHONPATH="C:\\Python22")
library(RSPython)

# The first command I run in RSPython 0.4-0 (latest 
# Win32 binary) always fails no matter what it is.
importPythonModule("wxPython.wx")
# Error in .PythonInit(warn = T) : Error in python call: A 
# Python Exception Occurred.
importPythonModule("wxPython.wx")
app <- .Python("wxPySimpleApp",.module="wxPython.wx",.convert=F)
frame <- .PythonEval("wxFrame(None,-1,\"Hello World\")",
  .module="wxPython.wx",.convert=F)
frame <- .Python("wxFrame",.module="wxPython.wx",.convert=F)
.PythonMethod(app,"SetTopWindow",(frame["id"]),.module="wxPython.wx",.convert=F)
.PythonMethod(frame,"Show",1,.module="wxPython.wx",.convert=F)
.PythonMethod(app,"MainLoop",.module="wxPython.wx",.convert=F)

# NOTHING HAPPENS :
# app.MainLoop() exits instantly with no apparent error, and
# without showing the "Hello World" window.
1 day later
#
James,
If you succeed in using wxWindows (or wxPython) from R, it is nice. However,
speaking about "actual examples", I think R Commander with Tcl/Tk is one
(OK, we have already discussed, some people do not like much TclTk)... Don't
you think it should be possible to make a core R code, and make the "widget
part" interchangeable. That is, and application like R Commander that uses
TclTk currently could be adapted to use alternatively wxWindows, Gtk, or
whatever... providing the corresponding dialog boxes are coded with the
given widgets? At the end, the user could choose its preferred GUI.

Well, I see many problems here, because the different libraries have
different widgets and manage then also quite differently... but at least, we
could try. This would require:

1) To rewrite R Commander so that it can work with other graphical widgets
than TclTk. That is only a decision that John Fox can take. I did a SciViews
compatible version of R Commander with a very different interface that the
standard one quite easily, because John's code is written in a way that
permits it quite easily.

2) Once it is done, we would have a basis to try on an actual application
(that is, R Commander), these various libraries. I think it should be very
useful and much more constructive to work on actual applications.

Best,

Philippe Grosjean

.......................................................<?}))><....
 ) ) ) ) )
( ( ( ( (   Prof. Philippe Grosjean
\  ___   )
 \/ECO\ (   Numerical Ecology of Aquatic Systems
 /\___/  )  Mons-Hainaut University, Pentagone
/ ___  /(   8, Av. du Champ de Mars, 7000 Mons, Belgium
 /NUM\/  )
 \___/\ (   phone: + 32.65.37.34.97, fax: + 32.65.37.33.12
       \ )  email: Philippe.Grosjean@umh.ac.be
 ) ) ) ) )  SciViews project coordinator (http://www.sciviews.org)
( ( ( ( (
...................................................................
#
Dear Philippe et al.,

It's not clear to me how the Rcmdr package fits into this, more general,
discussion about GUIs for R. I initially wrote the package because I wanted
to use R in introductory social-statistics classes for which the
command-line interface isn't really appropriate -- and after waiting for
quite a while for something else to appear. Although I expect that
eventually someone will come up with a better basic-statistics GUI, or even
something more ambitious, I note that this hasn't happened yet -- at least
not that I'm aware.

With respect to the further development of the Rcmdr package, I'm open to
suggestions. If nothing else, the code can use some cleaning up, and if it
can be made independent of Tcl/Tk without an unreasonable amount of work,
I'm open to that as well. The useR conference should provide a forum for
discussing these and related questions.

Regards,
 John
#
On Thu, 6 May 2004, Philippe Grosjean wrote:
Phillipe,

Yes, that would be great!

Since my last post, I have played around with wxPython a bit 
more, and have now written a wxMessageBox function which 
works in almost exactly the same way as the tkMessageBox 
function,
e.g.
wxMessagesBox(title="Title",message="Message",
  type="yesnocancel",icon="question")

even though in wxPython's wxMessageDialog you would actually use 
flags like:
 wxOK | wxICON_INFORMATION
etc. 

i.e. I've written a wrapper to make it look more like 
tkMessageBox().

So yes, I am thinking that it would be nice to have all GUI 
toolkits look similar from R, but there is a bit of work to 
do... especially because wxWindows is object-oriented, whereas 
Tcl/Tk is not.

Regards,
James