Is there an easy way to render wxPython panels to file without displaying
them on a screen?
This is a bit of a trick, and may not be possible at all....
Context: We have an interactive application based on wxPython, matplotlib,
etc. The interactive application consists of a graphical frontend and a
backend server. We have been creating a passive viewer for this application,
running on the headless backend, that dumps matplotlib images to graphics
files and they get served up by a web server, giving us a simple, portable
viewer for the data. The goal is to have the web view mimic the native
application as much as possible.
very cool!
However, some of the things we want to display are currently displayed on
wxPython panels (gauge representations of data, for example).
Are these custom-drawn? i.e, with a DC or GC? rather than standard
controls? If so you may be able to draw them to an off-screen bitmap
and go from there. Though I think wx still requires X to be
initialized to use DCs and GCs -- but maybe port then to Cairo or
something?
As far as I
can tell, we can't create images of the fully rendered panels without
actually displaying them on screen.
Particularly if you are using standard controls, yes, that's quite true.
The backend servers are headless,
non-interactive, and are not running X11. We don't really want to display
anything on them.
There is a "dummy" X server, I think it's called Xvfb (virtual frame
buffer). I also see a devbian package called: xserver-xorg-video-dummy
Running that would give you an Xserver that the app would think was
there, but wouldn't require a monitor of video card, or any of the
heavy-weight X stuff.
Though if your goal is to have a desktop and Web UI that are the same,
I'd suggeset a different route:
Do your UI in the browser, then for the desktop version, embed a
browser window in a desktop app. I call this a "Browser Interface,
Local Server" app.
Most (all) of the Python Web frameworks come with a self-contained
http server. You can:
Start up a wxPython app.
start up another thread, and start up your web app in that thread
create a Browser Window in the wxPython app, and point it at your
server (localhost:some_high_port)
This works pretty well, and you can intercept some actions in the web
server, and call into wxPython (with CallAfter, etc) to give the user
a more desktop-like experience, if need be.
There are a few options for embedding a browser window:
- Wrapping the system browser, I think wxHTML2 or somethingn like that works.
- wxWebKit: gives you the WebKit browser component, with wx for display
- Chrome Embedded Framework (PyCEF) -- the full Chrome browser,
embedded in a Pyton app.
HTH,
-Chris
···
On Mon, Jul 15, 2013 at 11:04 AM, Anthony Floyd <anthonyfloyd@gmail.com> wrote:
--
Christopher Barker, Ph.D.
Oceanographer
Emergency Response Division
NOAA/NOS/OR&R (206) 526-6959 voice
7600 Sand Point Way NE (206) 526-6329 fax
Seattle, WA 98115 (206) 526-6317 main reception
Chris.Barker@noaa.gov