Console application on Linux

I am trying to program a console application on Linux that uses pieces of wxPython (specifically wxBitmap and wxImage). Basically, I have wxBitmap objects living on a Windows box, and I have a network service that can scrape the data from the wxBitmap object, send it to the linux box, where I reconsititute it as a file and place it on a web page.

(Imagine a live food Menu with images of the items we sell...we want any changes to the menu to be propagated instantly to the website from our Point of Sale system).

The code I use works gloriously on a Windows box. I create an wx.App object (that I then ignore) and use the wxBitmap/wxImage classes without hassle.

However, when moving this code over to Linux, it seems that there is some dependency within the wx.App object that REQUIRES it be run from an instance of X.
Like this...

Python 2.6.6 (r266:84292, Sep 15 2010, 15:52:39)
[GCC 4.4.5] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import wx
>>> app=wx.App(False)
Unable to access the X Display, is $DISPLAY set properly?

I need to be able to use the wxBitmap/wxImage objects either without instantiating a wx.App object or to be able to instantiate a wx.App object without triggering the dependency on X.

Note that I pass in False to wx.App, which means I don't want anything redirected to a window. This SHOULD work. But it doesn't.

Any wisdom from anyone on how to make a NON-X depedent wxPython app?

Christopher L. Spencer

I am trying to program a console application on Linux that uses pieces
of wxPython (specifically wxBitmap and wxImage).

Solution 1: don't use wxPython. PIL has eveyting you can do with wxBitmap and wxImage and more, and is designed for condole, web app, etc use.

However, I understand there may be good reasons to use wxPython, so:

The code I use works gloriously on a Windows box.

Yup -- in this case is looks like a feature, but personally, I think it demonstrates how Windows really was never designed to be a server OS -- why is the UI always present???

However, when moving this code over to Linux, it seems that there is
some dependency within the wx.App object that REQUIRES it be run from an
instance of X.

Indeed -- wx uses the UI toolkit for a lot, and it does need to be initialized when the wxApp is -- that is what wx is designed for. There may be some thing you can do without initializing a wxApp, but working with wx.Bitmap is not one of them.

So you have three options:

1) don't use wx -- see above.
2) run an X server, it doesn't have to do much, and despite what I wrote above, it's not much overhead these days.
3) run a virtual Xserver:
   Xvfb can be used -- it looks and acts like an X server to your app, but doesn't actually display anything anywhere. It can be a pain to configure, but with luck your disto will have it set up for you.

-Chris

···

On 3/4/11 4:56 AM, Christopher L. Spencer 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

I am trying to program a console application on Linux that uses pieces
of wxPython (specifically wxBitmap and wxImage). Basically, I have
wxBitmap objects living on a Windows box, and I have a network service
that can scrape the data from the wxBitmap object, send it to the linux
box, where I reconsititute it as a file and place it on a web page.

(Imagine a live food Menu with images of the items we sell...we want any
changes to the menu to be propagated instantly to the website from our
Point of Sale system).

The code I use works gloriously on a Windows box. I create an wx.App
object (that I then ignore) and use the wxBitmap/wxImage classes without
hassle.

However, when moving this code over to Linux, it seems that there is
some dependency within the wx.App object that REQUIRES it be run from an
instance of X.

Correct. Initializing wx.App initializes GTK+ which does require an X Server to be able to function. Even if that restriction wasn't there you will need an X Server to be able to create and manipulate wx.Bitmaps because that is a UI dependent format and in some cases at least the content of the bitmap lives on the X Server rather than in the application client.

Any wisdom from anyone on how to make a NON-X depedent wxPython app?

There are a few things that you can use to provide an X compatible interface without an actual display. You can have one of those running that your sever app can connect to by having the DISPLAY environment variable set properly. However I'm not sure why you even need to use wx on your server piece. Why don't you just save the wx.Bitmap or wx.Image to a PNG or other image file format and then send the file data as-is up to the server? Not only would it not need wx.Bitamp/wx.Image on the server to do anything with it, but the data transmitted will likely be much smaller as well.

···

On 3/4/11 4:56 AM, Christopher L. Spencer wrote:

--
Robin Dunn
Software Craftsman

Thank you for your reply. The reasons I can't just send the .png file over is VERY complicated and has to do with legacy code.

I have a solution now that I think I'm happy with. I appreciate the advice.

Christopher L. Spencer

···

On 3/4/2011 12:00 PM, Robin Dunn wrote:

On 3/4/11 4:56 AM, Christopher L. Spencer wrote:

I am trying to program a console application on Linux that uses pieces
of wxPython (specifically wxBitmap and wxImage). Basically, I have
wxBitmap objects living on a Windows box, and I have a network service
that can scrape the data from the wxBitmap object, send it to the linux
box, where I reconsititute it as a file and place it on a web page.

(Imagine a live food Menu with images of the items we sell...we want any
changes to the menu to be propagated instantly to the website from our
Point of Sale system).

The code I use works gloriously on a Windows box. I create an wx.App
object (that I then ignore) and use the wxBitmap/wxImage classes without
hassle.

However, when moving this code over to Linux, it seems that there is
some dependency within the wx.App object that REQUIRES it be run from an
instance of X.

Correct. Initializing wx.App initializes GTK+ which does require an X Server to be able to function. Even if that restriction wasn't there you will need an X Server to be able to create and manipulate wx.Bitmaps because that is a UI dependent format and in some cases at least the content of the bitmap lives on the X Server rather than in the application client.

Any wisdom from anyone on how to make a NON-X depedent wxPython app?

There are a few things that you can use to provide an X compatible interface without an actual display. You can have one of those running that your sever app can connect to by having the DISPLAY environment variable set properly. However I'm not sure why you even need to use wx on your server piece. Why don't you just save the wx.Bitmap or wx.Image to a PNG or other image file format and then send the file data as-is up to the server? Not only would it not need wx.Bitamp/wx.Image on the server to do anything with it, but the data transmitted will likely be much smaller as well.