[wxPython] Q: Program wants to know "Am I running in a GUI environment?"

Hi,

I originally wrote the program as a command-line text-only beastie, and
am trying to wrap it in wxPython window-dressing, without losing the
ability to run it in a text-only environment.

Is there an approved, cross-platform way for a program to determine if
it can make use of the GUI (something like checking the DISPLAY
envrironment variable, but usable in Linux, Windoze and possibly in the
future BeOS.)

I originally wrote the program as a command-line text-only beastie, and
am trying to wrap it in wxPython window-dressing, without losing the
ability to run it in a text-only environment.

Is there an approved, cross-platform way for a program to determine if
it can make use of the GUI (something like checking the DISPLAY
envrironment variable, but usable in Linux, Windoze and possibly in the
future BeOS.)

I've seen a couple apps use a -nogui command-line flag, but I don't think
there is a standard way to do it automatically.

···

--
Robin Dunn
Software Craftsman
robin@AllDunn.com
http://wxpython.org Java give you jitters?
http://wxpros.com Relax with wxPython!

I have created an application frame, derived from wxFrame. That frame
has a menubar. In the frame, I have put a wxScrolledWindow.

What I want to do is have a the user select a menu item, and have that
event call a method in the scrolled window. The problem is that I have
no idea how to identify the scrolled window, as it doesn't exist when I
create my class from wxFrame. How do I do this?

Save a reference to the window in whatever object has the menu event
handler. Then it is just a matter of calling self.win.method() from within
the event handler.

···

--
Robin Dunn
Software Craftsman
robin@AllDunn.com
http://wxpython.org Java give you jitters?
http://wxpros.com Relax with wxPython!

What is the difference between these two ways of capturing mouse events?

self.Connect(-1, -1, wxEVT_LEFT_DOWN, self.OnLeftButtonEvent)

and:

EVT_LEFT_DOWN(self, self.OnLeftButtonEvent)

Nothing. The second is just a convenience for the first and a way to get
closer to the docs.

···

--
Robin Dunn
Software Craftsman
robin@AllDunn.com
http://wxpython.org Java give you jitters?
http://wxpros.com Relax with wxPython!

Kevin Cole writes:

Hi,

I originally wrote the program as a command-line text-only beastie, and
am trying to wrap it in wxPython window-dressing, without losing the
ability to run it in a text-only environment.

Is there an approved, cross-platform way for a program to determine if
it can make use of the GUI (something like checking the DISPLAY
envrironment variable, but usable in Linux, Windoze and possibly in the
future BeOS.)

Python try/except

If you can't open a display, then there'll be an exception that you can
catch.

self.memDC = wxMemoryDC()
temp_bitmap = wxEmptyBitmap(1000,1000)
self.memDC.SelectObject(temp_bitmap)

Thios works, fine, except that the background is black (which makes
sense) HOw can I get a different background color?

self.memDC.SetBackground(wxBrush(colour))
self.memDC.Clear()

BTW, a DC is a scarce resource on windows so you probably don't want to save
it in self, but should jusr create it each time it is needed.

···

--
Robin Dunn
Software Craftsman
robin@AllDunn.com
http://wxpython.org Java give you jitters?
http://wxpros.com Relax with wxPython!