Changeset 4084

Show
Ignore:
Timestamp:
06/02/07 12:30:02 (6 years ago)
Author:
DrewCormier
Message:

successfully implemented threading in wx environment. image refreshes every time packet is received. other various changes

Location:
experimental/components/image_display/trunk/image_display
Files:
2 modified

Legend:

Unmodified
Added
Removed
  • experimental/components/image_display/trunk/image_display/WorkModule.py

    r4073 r4084  
    5252        self.process_thread = threading.Thread(target=self.Process) 
    5353        self.process_thread.start() 
     54  
     55        self.toggle = 1 
    5456   
    5557                 
     
    7476 
    7577            while len(self.data_queue) > 0: 
    76                 #get data from the buffer: 
     78                #get data from the buffer:            
    7779                self.data_queue_lock.acquire() 
    7880                new_data = self.data_queue.pop() 
    7981                self.data_queue_lock.release() 
    8082 
     83#                my_file = open("/sdr/tmp.jpg", 'w') 
     84#                my_file.write(new_data) 
     85#                my_file.close() 
     86 
    8187                #rescale the image to the standardized size             
    82                 self.image.Rescale(self.width, self.height)  
     88                #self.image.Rescale(self.width, self.height)  
     89                 
     90                #create new image out of the incomming bytes 
     91                #self.image.SetData(new_data)            
    8392 
    84                 #create new image out of the incomming bytes 
    85                 self.image.SetData(new_data)             
     93                self.set_image() 
     94                if self.toggle == 1: 
     95                 self.toggle = 0 
     96                else: 
     97                 self.toggle = 1 
    8698 
    87                 self.image_display_ref.prnt_orb.prnt_frame.refresh(self.image)   
    88   
     99 
    89100            # reset the signal event variable 
    90101            self.data_signal.clear() 
    91                                  
    92102 
     103    def set_image(self): 
     104        locker = wx.MutexGuiLocker()   #should refresh the gui when leaving the scope of this function 
     105                                       #should i start this function as a thread for this to work? 
     106        if self.toggle == 1: 
     107         tmp_filename = '/sdr/wxpython_cover_2.jpg' 
     108        else: 
     109         tmp_filename = '/sdr/wxpython_cover.jpg' 
     110 
     111        self.image = wx.Image(tmp_filename, wx.BITMAP_TYPE_JPEG)  # load a jpeg from file 
     112        self.image_display_ref.prnt_orb.prnt_frame.refresh(self.image)   
     113  
     114 
  • experimental/components/image_display/trunk/image_display/image_display.py

    r4073 r4084  
    108108class ORB_Init: 
    109109    """Takes care of initializing the ORB and bind the object""" 
    110      
     110 
     111    # remove __init__ for threading approach.  thread cannot take input args? 
    111112    def __init__(self, prnt_frame, uuid, label): 
    112         self.prnt_frame = prnt_frame 
     113 
     114        print uuid 
     115        # for __init__: 
     116        #self.prnt_frame = prnt_frame 
     117        # for no __init__: 
     118        self.prnt_frame = app.frame 
    113119 
    114120        # initialize the orb 
     
    131137         
    132138        self.orb.run() 
    133        
     139 
     140def ORB_Init_fun(): 
     141        orb = ORB_Init(app, uuid, label)  
     142 
    134143 
    135144#------------------------------------------------------------------- 
     
    148157        self.frame_size = temp_bmp.GetWidth(), temp_bmp.GetHeight()   
    149158        wx.Frame.__init__(self, parent, id, self.title, wx.DefaultPosition, self.frame_size) 
    150  
    151  
    152  
    153159 
    154160        self.bmp = wx.StaticBitmap(parent=self, bitmap = temp_bmp) 
     
    160166 
    161167    def OnStartBtnButton(self, event):  
    162         # locker = wx.MutexGuiLocker() 
    163168        orb = ORB_Init(self,uuid, label)  
    164169        event.Skip()  
     
    166171 
    167172    def refresh(self, image): 
    168         #locker = wx.MutexGuiLocker() 
    169173        temp = image.ConvertToBitmap() 
    170174        size = temp.GetWidth(), temp.GetHeight() 
     
    177181    def OnInit(self): 
    178182        image = wx.Image("/sdr/wxpython_cover.jpg", wx.BITMAP_TYPE_JPEG) 
     183                 
    179184        self.frame = Frame(image) 
    180185        self.frame.Show() 
     
    184189 
    185190 
    186 class AppThread(threading.Thread): 
    187     def run(self): 
    188         app = App() 
    189         app.MainLoop() 
    190  
    191  
    192 class ORBThread(threading.Thread): 
    193     def run(self): 
    194         orb = ORB_Init(uuid, label) 
    195  
    196      
     191class my_threads: 
     192    def __init__(self): 
     193 
     194        ## for non-global app: 
     195        #self.app = App() 
     196        #self.app_thread = threading.Thread(target=self.app.MainLoop) 
     197 
     198        #for global app: 
     199        self.app_thread = threading.Thread(target=app.MainLoop) 
     200 
     201        self.app_thread.start() 
     202 
     203        ## with arguments: 
     204        #self.orb_thread = threading.Thread(target=ORB_Init(app.frame, uuid, label)) 
     205        #without arguments: 
     206        self.orb_thread = threading.Thread(target=ORB_Init_fun) 
     207 
     208        self.orb_thread.start() 
     209 
     210        print "\nthe orb thread has been started\n" 
     211 
     212   
    197213#------------------------------------------------------------------- 
    198214# Code run when this file is executed 
     
    207223    print "Identifier - " + uuid + "  Label - " + label 
    208224    
    209     i_am_threading = False 
     225    i_am_threading = True 
    210226 
    211227    if i_am_threading: 
    212         print "starting the App thread\n" 
    213         mainAppThread = AppThread() 
    214         mainAppThread.start() 
    215  
    216         print "starting the ORB thread\n" 
    217         mainORBThread = ORBThread() 
    218         mainORBThread.start() 
     228        #for global app: 
     229        app = App() 
     230         
     231        threads_running = my_threads() 
    219232     
    220233    else: