| 1 | #! /usr/bin/env python |
|---|
| 2 | |
|---|
| 3 | ''' |
|---|
| 4 | /**************************************************************************** |
|---|
| 5 | |
|---|
| 6 | Copyright 2007 Virginia Polytechnic Institute and State University |
|---|
| 7 | |
|---|
| 8 | This file is part of the OSSIE image_capture. |
|---|
| 9 | |
|---|
| 10 | OSSIE image_capture is free software; you can redistribute it and/or modify |
|---|
| 11 | it under the terms of the GNU General Public License as published by |
|---|
| 12 | the Free Software Foundation; either version 2 of the License, or |
|---|
| 13 | (at your option) any later version. |
|---|
| 14 | |
|---|
| 15 | OSSIE image_capture is distributed in the hope that it will be useful, |
|---|
| 16 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
|---|
| 17 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|---|
| 18 | GNU General Public License for more details. |
|---|
| 19 | |
|---|
| 20 | You should have received a copy of the GNU General Public License |
|---|
| 21 | along with OSSIE image_capture; if not, write to the Free Software |
|---|
| 22 | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
|---|
| 23 | |
|---|
| 24 | ****************************************************************************/ |
|---|
| 25 | |
|---|
| 26 | ''' |
|---|
| 27 | |
|---|
| 28 | #!/usr/bin/env python |
|---|
| 29 | import threading |
|---|
| 30 | import wx |
|---|
| 31 | import time |
|---|
| 32 | |
|---|
| 33 | class WorkClass: |
|---|
| 34 | """This class provides a place for the main processing of the |
|---|
| 35 | component to reside.""" |
|---|
| 36 | |
|---|
| 37 | def __init__(self, image_capture_ref, buffer_size): |
|---|
| 38 | self.image_capture_ref = image_capture_ref |
|---|
| 39 | self.buffer_size = buffer_size |
|---|
| 40 | |
|---|
| 41 | self.toggle = 1 |
|---|
| 42 | self.width = 399 |
|---|
| 43 | self.height = 500 |
|---|
| 44 | self.data_queue = [] |
|---|
| 45 | self.data_queue_lock = threading.Lock() |
|---|
| 46 | self.data_signal = threading.Event() |
|---|
| 47 | |
|---|
| 48 | self.is_running = True |
|---|
| 49 | |
|---|
| 50 | |
|---|
| 51 | def __del__(self): |
|---|
| 52 | # Destructor |
|---|
| 53 | pass |
|---|
| 54 | |
|---|
| 55 | |
|---|
| 56 | def AddData(self, bytesOut): |
|---|
| 57 | self.data_queue_lock.acquire() |
|---|
| 58 | self.data_queue.insert(0, (bytesOut)) |
|---|
| 59 | self.data_queue_lock.release() |
|---|
| 60 | self.data_signal.set() |
|---|
| 61 | |
|---|
| 62 | |
|---|
| 63 | def Release(self): |
|---|
| 64 | self.is_running = False |
|---|
| 65 | self.data_signal.set() |
|---|
| 66 | |
|---|
| 67 | |
|---|
| 68 | def Process(self): |
|---|
| 69 | while self.is_running: |
|---|
| 70 | |
|---|
| 71 | # TODO: add code for image capture |
|---|
| 72 | |
|---|
| 73 | # image = wx.Image("/sdr/wxpython_cover_2.jpg", wx.BITMAP_TYPE_JPEG) # load a jpeg from file |
|---|
| 74 | # image.Scale(self.width,self.height) |
|---|
| 75 | # image_data = image.GetData() #returns a giant string |
|---|
| 76 | if self.toggle == 1: |
|---|
| 77 | my_file = open("/sdr/wxpython_cover_2.jpg", 'r') |
|---|
| 78 | self.toggle = 0 |
|---|
| 79 | else: |
|---|
| 80 | my_file = open("/sdr/wxpython_cover_3.jpg", 'r') |
|---|
| 81 | self.toggle = 1 |
|---|
| 82 | |
|---|
| 83 | image_data = my_file.read() |
|---|
| 84 | |
|---|
| 85 | my_file.close() |
|---|
| 86 | # image_data = repr(my_file) |
|---|
| 87 | # print "data in capture:" |
|---|
| 88 | # print image_data |
|---|
| 89 | |
|---|
| 90 | |
|---|
| 91 | # Output the new data |
|---|
| 92 | if self.image_capture_ref.outPort0_active: |
|---|
| 93 | self.image_capture_ref.outPort0_servant.send_data(image_data) |
|---|
| 94 | else: |
|---|
| 95 | # reset the signal event variable |
|---|
| 96 | self.data_signal.clear() |
|---|
| 97 | |
|---|
| 98 | time.sleep(.5) |
|---|