| 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_display. |
|---|
| 9 | |
|---|
| 10 | OSSIE image_display 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_display 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_display; 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 | import wx |
|---|
| 29 | import threading |
|---|
| 30 | |
|---|
| 31 | |
|---|
| 32 | class WorkClass: |
|---|
| 33 | """This class provides a place for the main processing of the |
|---|
| 34 | component to reside.""" |
|---|
| 35 | |
|---|
| 36 | def __init__(self, image_display_ref, buffer_size): |
|---|
| 37 | |
|---|
| 38 | # debug statement: |
|---|
| 39 | print "work class __init__ called in image_display" |
|---|
| 40 | |
|---|
| 41 | self.image_display_ref = image_display_ref |
|---|
| 42 | self.buffer_size = buffer_size |
|---|
| 43 | |
|---|
| 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 | self.process_thread = threading.Thread(target=self.Process) |
|---|
| 51 | self.process_thread.start() |
|---|
| 52 | |
|---|
| 53 | |
|---|
| 54 | def __del__(self): |
|---|
| 55 | # Destructor |
|---|
| 56 | pass |
|---|
| 57 | |
|---|
| 58 | def AddData(self, bytesIn): |
|---|
| 59 | self.data_queue_lock.acquire() |
|---|
| 60 | self.data_queue.insert(0, bytesIn) |
|---|
| 61 | self.data_queue_lock.release() |
|---|
| 62 | self.data_signal.set() |
|---|
| 63 | |
|---|
| 64 | def Release(self): |
|---|
| 65 | self.is_running = False |
|---|
| 66 | self.data_signal.set() |
|---|
| 67 | |
|---|
| 68 | def Process(self): |
|---|
| 69 | print "Process in work module of image display has been called" |
|---|
| 70 | while self.is_running: |
|---|
| 71 | self.data_signal.wait() #wait for data_signal to be .set() in AddData |
|---|
| 72 | |
|---|
| 73 | print len(self.data_queue) |
|---|
| 74 | |
|---|
| 75 | while len(self.data_queue) > 0: |
|---|
| 76 | self.data_queue_lock.acquire() |
|---|
| 77 | new_data = self.data_queue.pop() |
|---|
| 78 | self.data_queue_lock.release() |
|---|
| 79 | |
|---|
| 80 | # get data out of tuple |
|---|
| 81 | bytesIn = new_data |
|---|
| 82 | |
|---|
| 83 | # debuggin loop - outputs the data that I'm getting |
|---|
| 84 | for x in range(len(bytesIn)): |
|---|
| 85 | print bytesIn[x] # print the first byte |
|---|
| 86 | |
|---|
| 87 | # put display code here |
|---|
| 88 | # convert bytesIn into a python image |
|---|
| 89 | |
|---|
| 90 | # refresh the image |
|---|
| 91 | print "this is where I should be refreshing the image" |
|---|
| 92 | |
|---|
| 93 | image = wx.Image("/sdr/buddha.jpg", wx.BITMAP_TYPE_JPEG) # load a jpeg from file. maybe start out with None |
|---|
| 94 | self.image_display_ref.prnt_orb.prnt_frame.refresh(image) |
|---|
| 95 | |
|---|
| 96 | # # not sure if I need this code: |
|---|
| 97 | # # reset the signal event variable |
|---|
| 98 | # self.data_signal.clear() |
|---|
| 99 | |
|---|
| 100 | |
|---|