OpenCV 2.1: Integration video capture into wxPython

1,960 views
Skip to first unread message

Convoluted

unread,
Nov 26, 2010, 5:31:07 PM11/26/10
to wxPython-users
Hello all. I would like to integrate a live video stream from an
attached video device (webcam, USB capture, etc) into a panel in a
wxPython GUI. I initially found sample code from the folks at OpenCV
(http://opencv.willowgarage.com/wiki/wxpython) but it seems to be
older versions of OpenCV, namely version 1.x. I have attempted to
convert this code for OpenCV 2.1 but I'm having difficulties getting
the GUI to execute. I'm not sure what exactly the problem is, but I
suspect that there might be a few more changes from 1.x to 2.1 other
than just syntax. Does anyone have any experience with OpenCV 2.1 +
wxPython? I would be grateful for any suggestions. Here is my attempt
to far:

import wx
import sys
import cv

sys.path.append('C:\OpenCV2.1\Python2.6\Lib\site-packages')

class captureTest(wx.Frame):
TIMER_PLAY_ID = 101
def __init__(self, parent):
wx.Frame.__init__(self, parent, -1)

self.capture = cv.CaptureFromCAM(0)
capturedImage = cv.QueryFrame(self.capture)
self.SetSize((capturedImage.width, capturedImage.height))
self.displayPanel = wx.Panel(self, -1)
#dst = cv.CreateImage(cv.GetSize(capturedImage),
cv.IPL_DEPTH_16S, 3) # NEED THIS?
cv.CvtColor(capturedImage, capturedImageModified,
cv.CV_BGR2RGB)
self.buildBmp =
wx.BitmapFromBuffer(capturedImageModified.width,
capturedImageModified.height, capturedImageModified.tostring())
self.Bind(wx.EVT_PAINT, self.onPaint)

self.playTimer = wx.Timer(self, self.TIMER_PLAY_ID)
wx.EVT_TIMER(self, self.TIMER_PLAY_ID, self.onNextFrame)
fps = gui.cvGetCaptureProperty(self.capture,
gui.CV_CAP_PROP_FPS)

self.Show(True)
if fps!=0: self.playTimer.Start(1000/fps) #every X ms
else: self.playTimer.Start(1000/15) #assuming 15 fps

def onPaint(self, evt):
if self.buildBmp:
dc=wx.BufferedPaintDC(self.displayPanel, self.buildBmp)
evt.Skip()

def onNextFrame(self, evt):
capturedImage = cv.QueryFrame(self.capture)
if capturedImage:
cv.CvtColor(capturedImage, capturedImageModified,
cv.CV_BGR2RGB)

self.buildBmp.CopyFromBuffer(capturedImageModified.tostring())
self.Refresh()
evt.Skip()

if __name__=="__main__":
app = wx.App()
app.RestoreStdio()
captureTest(None)
app.MainLoop()

David Lyon

unread,
Nov 26, 2010, 6:03:07 PM11/26/10
to wxpytho...@googlegroups.com
imo Python is going to be too slow for frame-by-frame capture with open-cv.

Have you thought about having the video loop in c and sending a message
in python to the C loop when you need to pick up a frame?

I'm working in OpenCV using python.multiprocessing but I am doing
all the video handling in C++. The C++ code sends messages to the python
code in a message bus on tcp/ip when it finds information in the images.

The 'brain' is in python..

Then I have a 'dumb' wxpython display, also connected to the tcp/ip
bus which picks up information and displays it to the user.

http://bitbucket.org/djlyon/smp-driverless-car-robot/src


Convoluted

unread,
Nov 26, 2010, 7:28:20 PM11/26/10
to wxPython-users
I would tend to agree, and this was definitely the case with the
VideoCapture library (http://videocapture.sourceforge.net/) but OpenCV
appears to be more efficient. If I utilize OpenCV's highgui and a
compiled Python library (.pyd) I can actually get some excellent
results, 640x480 @ 30fps with ~10% CPU usage on old Intel T-series
dual core CPU (see below for code, it's very simple). Now I'm not sure
if the speed is attributed to highgui but in theory should I not be
able to achieve a similar result with wxPython?

I also like the idea of sending the vision processing to C, but I
can't even image how I would achieve this. I've used TCP/IP to send
simple strings between two Python programs, but how would I grab the
frame from the C/C++ program (don't have much experience with C++)? Or
would the string I send be the image data that then needs to be
converted to an image (in which case, would this not require the
majority of processing?). I'm not even sure where to begin searching
out this solution. Perhaps the answer lies in the link you posted
(which I haven't yet taken a look at).

Please keep the suggestion coming! Thanks

import cv
cv.NamedWindow("camera", 1)
capture = cv.CaptureFromCAM(0)
while True:
img = cv.QueryFrame(capture)
cv.ShowImage("camera", img)
if cv.WaitKey(10) == 27:
break

On Nov 26, 3:03 pm, David Lyon <david.lyon.preissh...@gmail.com>
wrote:
> imo Python is going to be too slow for frame-by-frame capture with open-cv.
>
> Have you thought about having the video loop in c and sending a message
> in python to the C loop when you need to pick up a frame?
>
> I'm working in OpenCV using python.multiprocessing but I am doing
> all the video handling in C++. The C++ code sends messages to the python
> code in a message bus on tcp/ip when it finds information in the images.
>
> The 'brain' is in python..
>
> Then I have a 'dumb' wxpython display, also connected to the tcp/ip
> bus which picks up information and displays it to the user.
>
> http://bitbucket.org/djlyon/smp-driverless-car-robot/src
>
> > To unsubscribe, send email to wxPython-user...@googlegroups.com<wxPython-users%2Bunsu...@googlegroups.com>
> > or visithttp://groups.google.com/group/wxPython-users?hl=en
>
>

Micah Nordland

unread,
Nov 26, 2010, 9:58:20 PM11/26/10
to wxpytho...@googlegroups.com


import cv
cv.NamedWindow("camera", 1)
capture = cv.CaptureFromCAM(0)
while True:
   img = cv.QueryFrame(capture)
   cv.ShowImage("camera", img)
   if cv.WaitKey(10) == 27:
       break

is that all you do? will that take from a camera source and display it on the screen? 
--
To unsubscribe, send email to wxPython-user...@googlegroups.com



--
Hi, I will kill all ads in google gmail.
They will all be dead and gone for all my emails to you. HA HA bye bye ads I just massacred you!!!

Convoluted

unread,
Nov 26, 2010, 11:01:32 PM11/26/10
to wxPython-users
Yes indeed. The code is found in the "camera.py" in the folder
OpenCV2.1\samples\python. It uses OpenCV's highGUI module, which is
great for testing, but too limited for what I need.

In case anyone is interested, I was able to get the above wxPython
code to work by playing around with some of the functions/values. Not
exactly sure what I changed to make it work, but nevertheless it does
work. Seems to be fairly finicky. The video capture also seems to be
very efficient, only utilizing 5% cpu to provide 640x480 at around
20fps (guessing, may be slightly higher). The FPS can also be
modified, but I'm sure increasing it will eat up more processing
power.

On Nov 26, 6:58 pm, Micah Nordland <mpnordl...@gmail.com> wrote:
> > import cv
> > cv.NamedWindow("camera", 1)
> > capture = cv.CaptureFromCAM(0)
> > while True:
> >    img = cv.QueryFrame(capture)
> >    cv.ShowImage("camera", img)
> >    if cv.WaitKey(10) == 27:
> >        break
>
> > is that all you do? will that take from a camera source and display it on
>
> the screen?
>
> >  --
> > To unsubscribe, send email to wxPython-user...@googlegroups.com<wxPython-users%2Bunsu...@googlegroups.com>
> > or visithttp://groups.google.com/group/wxPython-users?hl=en

David Lyon

unread,
Nov 27, 2010, 9:15:55 AM11/27/10
to wxpytho...@googlegroups.com
I tried and got the same problem as you originally asked about.

Can you post back your final code so that I can see the fix?


Convoluted

unread,
Nov 27, 2010, 2:19:23 PM11/27/10
to wxPython-users
Sure, no problem. The code is below. I also added in double buffering
to eliminate flicker (Windows only, Linux/Mac users, remove the double
buffering code), and it is currently set at 15FPS. I've tested it on
an integrated webcam on Win 7 using Python 2.6.6 ad wxPython 2.8.10.
You will also need pywin32 for the double buffering and OpenCV 2.1 in
your c: directory (or just change path in code so it points to the
compiled .pyd library).

Please try it out on your system at let me know how it goes. Like I
mentioned, it's a bit finicky at the moment. For instance, sometimes
when I run the code it will ask for the video source, which ends up
crashing the code. Other times it won't and will end up displaying the
feed quite nicely. If you get the box asking for the video source
repeatedly, just restart your PC and it seems to fix this. I haven't
tested the code very much, so any suggestions for improvement are
definitely welcome.

By the way, is there any better way to post code here? I read it
should be attached or something, but I don't see the option...

import wx
import win32api
import win32con

import sys
import cv

sys.path.append('C:\OpenCV2.1\Python2.6\Lib\site-packages')

class captureTest(wx.Frame):
TIMER_PLAY_ID = 101
def __init__(self, parent):
wx.Frame.__init__(self, parent, -1)


def SetCompositeMode(self, on=True):
exstyle = win32api.GetWindowLong(self.GetHandle(),
win32con.GWL_EXSTYLE)
if on:
exstyle |= win32con.WS_EX_COMPOSITED
else:
exstyle &= ~win32con.WS_EX_COMPOSITED
win32api.SetWindowLong(self.GetHandle(),
win32con.GWL_EXSTYLE, exstyle)

SetCompositeMode(self, True)

self.capture = cv.CaptureFromCAM(0)
capImg = cv.QueryFrame(self.capture)
self.SetSize((capImg.width, capImg.height))
self.displayPanel = wx.Panel(self, -1)
cv.CvtColor(capImg, capImg, cv.CV_BGR2RGB)
self.buildBmp = wx.BitmapFromBuffer(capImg.width,
capImg.height, capImg.tostring())
self.Bind(wx.EVT_PAINT, self.onPaint)

self.playTimer = wx.Timer(self, self.TIMER_PLAY_ID)
wx.EVT_TIMER(self, self.TIMER_PLAY_ID, self.onNextFrame)
fps = cv.GetCaptureProperty(self.capture, cv.CV_CAP_PROP_FPS)

self.Show(True)
if fps!=0: self.playTimer.Start(1000/fps) #every X ms
else: self.playTimer.Start(1000/15) #assuming 15 fps

def onPaint(self, evt):
if self.buildBmp:
dc=wx.BufferedPaintDC(self.displayPanel, self.buildBmp)
evt.Skip()

def onNextFrame(self, evt):
capImg = cv.QueryFrame(self.capture)
if capImg:
cv.CvtColor(capImg, capImg, cv.CV_BGR2RGB)
self.buildBmp.CopyFromBuffer(capImg.tostring())
self.Refresh()
evt.Skip()

if __name__=="__main__":
app = wx.App()
app.RestoreStdio()
captureTest(None)
app.MainLoop()




I would really like to get a nice working piece of code and I'm sure
with combined support we can get it done

On Nov 27, 6:15 am, David Lyon <david.lyon.preissh...@gmail.com>
wrote:
> I tried and got the same problem as you originally asked about.
>
> Can you post back your final code so that I can see the fix?
>
> > <wxPython-users%2Bunsu...@googlegroups.com<wxPython-users%252Buns...@googlegroups.com>
>
> > > > or visithttp://groups.google.com/group/wxPython-users?hl=en
>
> > > --
> > > Hi, I will kill all ads in google gmail.
> > > They will all be dead and gone for all my emails to you. HA HA bye bye
> > ads I
> > > just massacred you!!!
>
> > --
> > To unsubscribe, send email to wxPython-user...@googlegroups.com<wxPython-users%2Bunsu...@googlegroups.com>
> > or visithttp://groups.google.com/group/wxPython-users?hl=en
>
>

Mike Driscoll

unread,
Nov 29, 2010, 10:59:06 AM11/29/10
to wxPython-users
If mplayer can do it, then you can probably use the mplayerCtrl
widget:

http://pypi.python.org/pypi/MplayerCtrl/

I have used it for video playback, but as I understand it, mplayer can
also do streaming...

-------------------
Mike Driscoll

Blog: http://blog.pythonlibrary.org

yoav glazner

unread,
Nov 29, 2010, 6:02:34 PM11/29/10
to wxpytho...@googlegroups.com
If you don't have to use OpenCV try VideoCapture.
example attached...
cam_testing.py

David Lyon

unread,
Nov 29, 2010, 7:23:07 PM11/29/10
to wxpytho...@googlegroups.com
Thanks for posting both those examples.

I'm so frustrated - the webcam I bought works with every other program in linux except for opencv. Due to some missing codec or something.

I can pump images off an image buffer - so I am going to try this - many thanks.

--
To unsubscribe, send email to wxPython-user...@googlegroups.com

Convoluted

unread,
Nov 29, 2010, 8:14:55 PM11/29/10
to wxPython-users
Yoav, I've looked into using VideoCapture with wxPython, but was
getting rather poor results compared to OpenCV. Just streaming at 15
FPS was maxing my CPU usage. The video also appeared more grainy. The
testing was done using Webcamspy without using any other features than
just video acquisition. David, I hope you find use out of the example.
Please do report back and let me know it works. Mike, that's a really
great idea, I'll have to look into that more. The major draw of OpenCV
at the moment is being able to perform some vision processing (motion
tracking) but for pure streaming mplayer would be a great choice.
Cheers all.

On Nov 29, 4:23 pm, David Lyon <david.lyon.preissh...@gmail.com>
wrote:
> Thanks for posting both those examples.
>
> I'm so frustrated - the webcam I bought works with every other program in
> linux except for opencv. Due to some missing codec or something.
>
> I can pump images off an image buffer - so I am going to try this - many
> thanks.
>
> On Tue, Nov 30, 2010 at 10:02 AM, yoav glazner <yoavglaz...@gmail.com>wrote:
> > To unsubscribe, send email to wxPython-user...@googlegroups.com<wxPython-users%2Bunsu...@googlegroups.com>
> > or visithttp://groups.google.com/group/wxPython-users?hl=en
>
>

Ricardo Pedroso

unread,
Nov 29, 2010, 9:15:23 PM11/29/10
to wxpytho...@googlegroups.com
On Tue, Nov 30, 2010 at 1:14 AM, Convoluted <xeno...@gmail.com> wrote:
> Yoav, I've looked into using VideoCapture with wxPython, but was
> getting rather poor results compared to OpenCV. Just streaming at 15
> FPS was maxing my CPU usage. The video also appeared more grainy. The
> testing was done using Webcamspy without using any other features than
> just video acquisition. David, I hope you find use out of the example.
> Please do report back and let me know it works. Mike, that's a really
> great idea, I'll have to look into that more. The major draw of OpenCV
> at the moment is being able to perform some vision processing (motion
> tracking) but for pure streaming mplayer would be a great choice.
> Cheers all.
>
> On Nov 29, 4:23 pm, David Lyon <david.lyon.preissh...@gmail.com>
> wrote:
>> Thanks for posting both those examples.
>>
>> I'm so frustrated - the webcam I bought works with every other program in
>> linux except for opencv. Due to some missing codec or something.

I attached two samples that work for me in linux.

One using OpenCV a modified version of one posted here in this thread.
The other using gstreamer

Both seems to works OK with wxPython 2.8.11.0 (gtk2-unicode) on Ubuntu 10.10

Sorry if this is out of context, but I didn't follow this thread very close.
But I think sample code is always welcome ;)

Ricardo

cv_webcam.py
gst_webcam.py

David Lyon

unread,
Dec 1, 2010, 7:36:36 PM12/1/10
to wxpytho...@googlegroups.com
I've worked out that I need to recompile OpenCV from svn to get
my webcam to work. I was just using an old packaged version.

It's been so helpful getting these examples.

I'm building an in-car system with a wx console on a mini-itx
computer. As in:

   http://www.mini-itx.com/store/

I want to attach webcams and use OpenCV to read stuff as I
drive.

I've got a project up at:

  http://bitbucket.org/djlyon/smp-driverless-car-robot

--
To unsubscribe, send email to wxPython-user...@googlegroups.com

Convoluted

unread,
Dec 3, 2010, 4:29:48 PM12/3/10
to wxPython-users
Glad you found some use in the code samples. Are you still planning on
use C to process the video, or just wxPython? I'm also interested in
using a small vehicle PC to monitor a webcam feed, and I'm curious
what sort of processor usage you are achieving on a small PC. I've
taken a look at your project, looks quite interesting. I'll keep an
eye out for your advancement on it. If you are able to enhance the
video acquisition code, please post it here.

Ricardo, thanks for those samples. I've heard of GStreamer, but
haven't used it. I mind end up doing a comparison between the three
video acquisition methods.

On Dec 1, 4:36 pm, David Lyon <david.lyon.preissh...@gmail.com> wrote:
> I've worked out that I need to recompile OpenCV from svn to get
> my webcam to work. I was just using an old packaged version.
>
> It's been so helpful getting these examples.
>
> I'm building an in-car system with a wx console on a mini-itx
> computer. As in:
>
>    http://www.mini-itx.com/store/
>
> I want to attach webcams and use OpenCV to read stuff as I
> drive.
>
> I've got a project up at:
>
>  http://bitbucket.org/djlyon/smp-driverless-car-robot
>
> On Tue, Nov 30, 2010 at 1:15 PM, Ricardo Pedroso <rmdpedr...@gmail.com>wrote:
> > To unsubscribe, send email to wxPython-user...@googlegroups.com<wxPython-users%2Bunsu...@googlegroups.com>
> > or visithttp://groups.google.com/group/wxPython-users?hl=en

David Lyon

unread,
Dec 3, 2010, 9:08:03 PM12/3/10
to wxpytho...@googlegroups.com
Thanks. Actually I'm not really fussed whether it's in C++ or python. I'm
told that python adds 10% latency which to me doesn't seem too bad.

I'd like to keep the display monitor portion in wxpython. As it will be
much easier in the long run to maintain. It's just unfornuate for me
that the video in the standard releases of OpenCV didn't work.

Well I am building OpenCV from svn and I will see how it goes from
there.

Cheers :)


Convoluted

unread,
Dec 4, 2010, 9:06:37 PM12/4/10
to wxPython-users
To expand on Mike's suggestion, I tried the MPlayer route with
MPlayerCtrl and it turns out to be a very feasible solution. In case
anyone's interested, here's a simple example how to integrate a webcam
feed in wxPython (adapted from MPlayerCtrl's "simple example"). I
installed the SMPlayer package and just pointed to the mplayer.exe in
SMPlayer\mplayer\. Nice thing about this method is that the processing
is done through MPlayer and not wxPython, so I would imagine if the
video feed crashed it shouldn't crash wxPython.

On a side note, I'm having an issue with all webcam capture methods. I
get the error "the wx.app object must be created first". Seems to only
happen when launching the application for the second time in IDLE. No
problems from command prompt or launching for the first time in IDLE.
Anyone know how to remedy this problem? Occurred on Windows 7 x64 with
wxPython 2.8.11.0. Thanks

import wx
import MplayerCtrl as mpc

class Frame(wx.Frame):
def __init__(self, parent, id):
wx.Frame.__init__(self, parent, id)
self.mpc = mpc.MplayerCtrl(self, -1, 'c:\Program Files
(x86)\SMPlayer\mplayer\mplayer.exe')
wx.FutureCall(1000, self.mpc.Loadfile, 'tv:// -tv')
self.Show()

if __name__ == '__main__':
app = wx.App(redirect=False)
f = Frame(None, -1)
app.MainLoop()




On Dec 3, 6:08 pm, David Lyon <david.lyon.preissh...@gmail.com> wrote:
> Thanks. Actually I'm not really fussed whether it's in C++ or python. I'm
> told that python adds 10% latency which to me doesn't seem too bad.
>
> I'd like to keep the display monitor portion in wxpython. As it will be
> much easier in the long run to maintain. It's just unfornuate for me
> that the video in the standard releases of OpenCV didn't work.
>
> Well I am building OpenCV from svn and I will see how it goes from
> there.
>
> Cheers :)
>
> > <wxPython-users%2Bunsu...@googlegroups.com<wxPython-users%252Buns...@googlegroups.com>
>
> > > > or visithttp://groups.google.com/group/wxPython-users?hl=en
>
> > --
> > To unsubscribe, send email to wxPython-user...@googlegroups.com<wxPython-users%2Bunsu...@googlegroups.com>
> > or visithttp://groups.google.com/group/wxPython-users?hl=en

ktemo

unread,
Dec 5, 2010, 3:37:08 AM12/5/10
to wxPython-users
Hi all

i found this, and it works :D


import wx
from opencv import cv, highgui

class LivePanel(wx.Panel):

def __init__(self, parent, id):
wx.Panel.__init__(self, parent, id)

self.cap = highgui.cvCreateCameraCapture(0)
self.Bind(wx.EVT_IDLE, self.onIdle)

def onIdle(self, event):

img = highgui.cvQueryFrame(self.cap)
self.displayImage(img)
event.RequestMore()

def displayImage(self, img, offset=(0,0)):

bitmap = wx.BitmapFromBuffer(img.width, img.height,
img.imageData)
dc = wx.ClientDC(self)
dc.DrawBitmap(bitmap, offset[0], offset[1], False)

# Main Procedure
app = wx.PySimpleApp()
pFrame = wx.Frame(None, -1, "Media Player", size = (640, 480))
livePanel = LivePanel(pFrame,-1)
livePanel.SetPosition(wx.Point(0,0))
livePanel.SetSize(wx.Size(640,480))
pFrame.Show()
app.MainLoop()

this the original code:
http://eupparee.wordpress.com/2009/02/10/capture-live-by-using-opencv-and-wxpython/

Robin Dunn

unread,
Dec 6, 2010, 1:25:24 PM12/6/10
to wxpytho...@googlegroups.com
On 12/4/10 6:06 PM, Convoluted wrote:

> On a side note, I'm having an issue with all webcam capture methods. I
> get the error "the wx.app object must be created first". Seems to only
> happen when launching the application for the second time in IDLE. No
> problems from command prompt or launching for the first time in IDLE.
> Anyone know how to remedy this problem? Occurred on Windows 7 x64 with
> wxPython 2.8.11.0. Thanks

Either use an IDE that always runs the launched programs and the shell
in external processes (not in the same process as the IDE) or find a way
to make IDLE do that. (I seem to recall that there was a branch of IDLE
development that had that option, and it has since been merged into the
trunk, but I don't remember any more details.) There can only be one
wx.App in a process, and creating new ones after the first has exited
can sometimes be problematic.


--
Robin Dunn
Software Craftsman
http://wxPython.org

Dev Player

unread,
Dec 6, 2010, 2:25:35 PM12/6/10
to wxpytho...@googlegroups.com
On Mon, Dec 6, 2010 at 1:25 PM, Robin Dunn <ro...@alldunn.com> wrote:
... There can only be one wx.App in a process, and creating new ones after the first has exited can sometimes be problematic.
Robin Dunn
Question out of my depth here.
 
It has been stated often that wxPython (it's message loop and event processing) needs to be the main thread, meaning the first thread. I'm not quite sure how an OS knows what "main" thread means.
 
Because this is true for threads is it true for processes? Is the first process the main process? Or is it unlike threads in that every process is "the main process", all processes are equal in the eyes of Python and wxPython, they're all the same. I'm thinking the later to be the case.
 
In either case would this be a bad (or even doable) [not withstanding syntax or proper parameterization] solution to OP's issue:
 
main.py
-----------
if __name__ == '__main__':
    import multiprocessing
    import wxgui    # module has only defs and classes no instances or running code
    import videoui    # module has only defs and classes no instances or running code
    import netstreams    # same thing again
 
if __name__ == '__main__':
    netstream = Process(target=netstreams.reactorloop(), ...)
    netstream.start()
    netstream.join()
 
if __name__ == '__main__':
    gui = Process(target=wxgui.app.MainLoop(), ...)
    gui.start()
    gui.join()
 
if __name__ == '__main__':
    video = Process(target=videoui.CaptureLoop(), ...)
    video.start()
    video.join()
 
if __name__ == '__main__':  # line is necessary according to docs

 

Robin Dunn

unread,
Dec 6, 2010, 4:16:07 PM12/6/10
to wxpytho...@googlegroups.com
On 12/6/10 11:25 AM, Dev Player wrote:
> On Mon, Dec 6, 2010 at 1:25 PM, Robin Dunn <ro...@alldunn.com
> <mailto:ro...@alldunn.com>> wrote:
>
> ... There can only be one wx.App in a process, and creating new ones
> after the first has exited can sometimes be problematic.
> Robin Dunn
>
> Question out of my depth here.
> It has been stated often that wxPython (it's message loop and event
> processing) needs to be the main thread, meaning the first thread. I'm
> not quite sure how an OS knows what "main" thread means.

Normally the "main thread" in any context is the one that is active when
a program is started, before the program creates any new threads for
itself. The OS is aware of this but as far as the wx UI is concerned it
doesn't really care. OTOH wx does care about which thread it should
consider to be the main thread, but it doesn't have to be the same one
that was created for the process by the system before stating the
program, (but it usually is.) Whichever thread creates the wx.App
object will be the one that wx treats as the main thread.


> Because this is true for threads is it true for processes?

No. Processes are totally isolated from each other by the system
(except for any IPC that they do for themselves of course.)


> Is the first
> process the main process? Or is it unlike threads in that every process
> is "the main process", all processes are equal in the eyes of Python and
> wxPython, they're all the same. I'm thinking the later to be the case.
> In either case would this be a bad (or even doable) [not withstanding
> syntax or proper parameterization] solution to OP's issue:


Theoretically it should be possible to have more than one process in a
process group to have a wx UI, but each of them would have to create a
wx.App and run MainLoop(), and I suppose that it's possible that that
may interfere with the IPC that the subprocess module is using for the
processes to communicate with each other.

Dev Player

unread,
Dec 6, 2010, 4:50:02 PM12/6/10
to wxpytho...@googlegroups.com


On Mon, Dec 6, 2010 at 4:16 PM, Robin Dunn <ro...@alldunn.com> wrote:
... Whichever thread creates the wx.App object will be the one that wx treats as the main thread.
 
So does the code:
 
import wxgui   
if __name__ == '__main__':
    gui = Process(target=wxgui.app.MainLoop(), ...)
    gui.start()
    gui.join()

Needs to be adapted to:
 
import pregui
if __name__ == '__main__':
    gui = Process(target=pregui.run(), ...)
    gui.start()
    gui.join()
pregui.py
-------------
import wxgui
def run():
    app = wx.App()
    mygui = wxgui.MainFrame()
    app.MainLoop()
 
So that the wx.App instance is created in the same Python module and OS process as the where the MainLoop() is called at? ??
 
 
Theoretically it should be possible to have more than one process in a process group
Didn't know there were such things as process groups. Will have to learn about them some other time.
 
...to have a wx UI, but each of them would have to create a wx.App and run MainLoop(),
Makes good sense.
 
...and I suppose that it's possible that that may interfere with the IPC that the subprocess module is using for the processes to communicate with each other.
Something to learn and understand another time for me.
 

Robin Dunn

unread,
Dec 6, 2010, 11:18:44 PM12/6/10
to wxpytho...@googlegroups.com


It does not have to be the same Python module, but it does have to be
the same OS process and the same thread in that process.

David Lyon

unread,
Dec 6, 2010, 11:24:18 PM12/6/10
to wxpytho...@googlegroups.com
hey - seems really cool..

I'm still researching all the hardware and o/s aspects of my particular
project. I'm so impressed by everybody's postings..

I've been looking at different linux distros to run in the car on the
mini-itx board. Choices seem to be : puppy-linux, damn-small-linux,
Fluxbuntu, and TinyMe. Also Windows works on a lot of car pc's.

Anyway.. how does this affect video capture in wx?

Well combined we seem to know quite a lot about this field. In
the car pc space, there isn't actually a lot out there. Not past
install the Operating system.

If we know wx, then it means we in theory might know about
user interfaces.

So I am putting out the idea of a wx based car pc system,
based on some usb bootable linux distro, that could control
camera's, stereo (a video player), navigation and maybe even
the disco lights in back.. lol.. (joking).

wx and python are an ideal combination for such a device
after all who could be bothered doing such a thing in C.

So far, I haven't found anything active in this space.. and I
don't think it would be so hard to start up and run..

--
To unsubscribe, send email to wxPython-user...@googlegroups.com

Reply all
Reply to author
Forward
0 new messages