##// END OF EJS Templates
GUI - External plotter: Read items while queue is not empty
Miguel Valdez -
r710:22cee43073ff
parent child
Show More

The requested changes are too big and content was truncated. Show full diff

1 NO CONTENT: modified file
The requested commit or file is too big and content was truncated. Show full diff
@@ -1,137 +1,139
1 1 '''
2 2 Created on Jul 9, 2014
3 3
4 4 @author: roj-idl71
5 5 '''
6 6 import os
7 7 import datetime
8 8 import numpy
9 9
10 10 from time import sleep
11 11 from Queue import Queue
12 12 from threading import Lock
13 13 # from threading import Thread
14 14
15 15 from schainpy.model.proc.jroproc_base import Operation
16 16 from schainpy.model.serializer.data import obj2Dict, dict2Obj
17 17 from jroplot_correlation import *
18 18 from jroplot_heispectra import *
19 19 from jroplot_parameters import *
20 20 from jroplot_spectra import *
21 21 from jroplot_voltage import *
22 22
23 23
24 24 class Plotter(Operation):
25 25
26 26 isConfig = None
27 27 name = None
28 28 __queue = None
29 29
30 30 def __init__(self, plotter_name, plotter_queue=None):
31 31
32 32 Operation.__init__(self)
33 33
34 34 self.isConfig = False
35 35 self.name = plotter_name
36 36 self.__queue = plotter_queue
37 37
38 38 def getSubplots(self):
39 39
40 40 nrow = self.nplots
41 41 ncol = 1
42 42 return nrow, ncol
43 43
44 44 def setup(self, **kwargs):
45 45
46 46 print "Initializing ..."
47 47
48 48
49 49 def run(self, dataOut, id=None, **kwargs):
50 50
51 51 """
52 52
53 53 Input:
54 54 dataOut :
55 55 id :
56 56 """
57 57
58 58 packDict = {}
59 59
60 60 packDict['id'] = id
61 61 packDict['name'] = self.name
62 62 packDict['kwargs'] = kwargs
63 63
64 64 packDict['data'] = obj2Dict(dataOut)
65 65
66 66 self.__queue.put(packDict)
67 67
68 68 # class PlotManager(Thread):
69 69 class PlotManager():
70 70 __stop = False
71 71
72 72 def __init__(self, plotter_queue):
73 73
74 74 # Thread.__init__(self)
75 75 # self.setDaemon(True)
76 76
77 77 self.__queue = plotter_queue
78 78 self.__lock = Lock()
79 79
80 80 self.plotInstanceDict = {}
81 81 self.__stop = False
82 82
83 83 def run(self):
84 84
85 85 if self.__queue.empty():
86 86 return
87 87
88 88 self.__lock.acquire()
89 89
90 90 # if self.__queue.full():
91 91 # for i in range(int(self.__queue.qsize()/2)):
92 92 # serial_data = self.__queue.get()
93 93 # self.__queue.task_done()
94 94
95 95 n = int(self.__queue.qsize()/3 + 1)
96 96
97 97 for i in range(n):
98 98
99 99 serial_data = self.__queue.get()
100 100 self.__queue.task_done()
101 101
102 102 plot_id = serial_data['id']
103 103 plot_name = serial_data['name']
104 104 kwargs = serial_data['kwargs']
105 105 dataDict = serial_data['data']
106 106
107 107 dataPlot = dict2Obj(dataDict)
108 108
109 109 if plot_id not in self.plotInstanceDict.keys():
110 110 className = eval(plot_name)
111 111 self.plotInstanceDict[plot_id] = className()
112 112
113 113 plotter = self.plotInstanceDict[plot_id]
114 114 plotter.run(dataPlot, plot_id, **kwargs)
115 115
116 self.__lock.release()
116 117
118 def isEmpty(self):
117 119
118 self.__lock.release()
120 return self.__queue.empty()
119 121
120 122 def stop(self):
121 123
122 124 self.__lock.acquire()
123 125
124 126 self.__stop = True
125 127
126 128 self.__lock.release()
127 129
128 130 def close(self):
129 131
130 132 self.__lock.acquire()
131 133
132 134 for plot_id in self.plotInstanceDict.keys():
133 135 plotter = self.plotInstanceDict[plot_id]
134 136 plotter.close()
135 137
136 138 self.__lock.release()
137 139 No newline at end of file
General Comments 0
You need to be logged in to leave comments. Login now