wxDC - Standalone and with CGI?

Dear List,
Is it possible to use wxPython in a server sided CGI script? I always get an
error message that no graphic device handle could be opened when i import
with from wxPython import *. I need to create images with the wxDC drawing
functions and save the image buffer to an image file on HD.
How can i do that? Is there another approach to do this? My drawing routines
are all finished. I need to show the resulting images in a standalone
wxPython application (very interactive, not still images) as well as to
create them with the CGI script.
Oliver

I would suggest if you absolutly need to use GDI drawing of some form to write
a drawing 'server' process that communicated with the CGI level through a
comms protocol (XMLRPC tend to be quite easy) or even through a file system
approach - you will almost certainly need to serialise the access to this
server.

I doubt it is possible to initialise wx in the context of CGI - but I could be
wrong.

Have you considered using other less GUI-oriented drawing libraries?

Regards,
Stuart

···

On Wednesday 03 December 2003 22:51, Oliver Walczak wrote:

Dear List,
Is it possible to use wxPython in a server sided CGI script? I always get
an error message that no graphic device handle could be opened when i
import with from wxPython import *. I need to create images with the wxDC
drawing functions and save the image buffer to an image file on HD.
How can i do that? Is there another approach to do this? My drawing
routines are all finished. I need to show the resulting images in a
standalone wxPython application (very interactive, not still images) as
well as to create them with the CGI script.
Oliver

Oliver Walczak wrote:

Dear List,
Is it possible to use wxPython in a server sided CGI script?

No, wxWidnows needs access to the UI in order to be initialized.

···

--
Robin Dunn
Software Craftsman
http://wxPython.org Java give you jitters? Relax with wxPython!

Robin Dunn wrote:

Oliver Walczak wrote:

Dear List,
Is it possible to use wxPython in a server sided CGI script?

No, wxWidnows needs access to the UI in order to be initialized.

That still doesn't prevent it from being used in a cgi script. I use wxDC's from a python apache server all the time. The trick is not to open up an gui windows. These tend to annoy anyone looking at the server.

I have a drawer class that draws on a wxMemoryDC() and saves the file to disk as a "gif"
Here is a small snippet to give you a taste.

class Drawer:
def save(self, filename):
  dc = wxMemoryDC() bmp = wxEmptyBitmap(width, height)
  dc.SelectObject(bmp)
  self._draw(dc)
  bmp.SaveFile(filename, type)

usage...
app = wxPySimpleApp()
wxInitAllImageHandlers()
d = Drawer(...)
d.save(filename)

This app sets up the gui environment and writes out a gif file. I think it can be used in a cgi environment, otherwise you can call this from your cgi script.

Brian

Brian Kelley wrote:

> No, wxWidnows needs access to the UI in order to be initialized.

That still doesn't prevent it from being used in a cgi script. I use
wxDC's from a python apache server all the time. The trick is not to
open up an gui windows. These tend to annoy anyone looking at the server.

The server does need to be running an X-server, however (Or, I suppose
you could connect to some other X server) A lot of servers do not have X
running, that's why I'd really like to get Xvfb to work.

-Chris

···

--
Christopher Barker, Ph.D.
Oceanographer
                                        
NOAA/OR&R/HAZMAT (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