COSMOS core  1.0.2 (beta)
Comprehensive Open-architecture Solution for Mission Operations Systems
imu_stream_plot2.GraphFrame Class Reference
Inheritance diagram for imu_stream_plot2.GraphFrame:
Collaboration diagram for imu_stream_plot2.GraphFrame:

Public Member Functions

def __init__ (self)
 
def create_menu (self)
 
def create_main_panel (self)
 
def create_status_bar (self)
 
def init_plot (self)
 
def draw_plot (self)
 
def on_pause_button (self, event)
 
def on_update_pause_button (self, event)
 
def on_cb_grid (self, event)
 
def on_cb_xlab (self, event)
 
def on_save_plot (self, event)
 
def on_redraw_timer (self, event)
 
def on_exit (self, event)
 
def flash_status_message (self, msg, flash_len_ms=1500)
 
def on_flash_status_off (self, event)
 

Public Attributes

 datagen
 
 data
 
 paused
 
 redraw_timer
 
 menubar
 
 panel
 
 canvas
 
 xmin_control
 
 xmax_control
 
 ymin_control
 
 ymax_control
 
 pause_button
 
 cb_grid
 
 cb_xlab
 
 hbox1
 
 hbox2
 
 vbox
 
 statusbar
 
 dpi
 
 fig
 
 axes
 
 plot_data
 
 timeroff
 

Static Public Attributes

string title = 'Demo: dynamic matplotlib graph'
 

Detailed Description

The main frame of the application

Constructor & Destructor Documentation

def imu_stream_plot2.GraphFrame.__init__ (   self)
119  def __init__(self):
120  wx.Frame.__init__(self, None, -1, self.title)
121 
122  self.datagen = DataGen()
123  self.data = [self.datagen.next()]
124  self.paused = False
125 
126  self.create_menu()
127  self.create_status_bar()
128  self.create_main_panel()
129 
130  self.redraw_timer = wx.Timer(self)
131  self.Bind(wx.EVT_TIMER, self.on_redraw_timer, self.redraw_timer)
132  self.redraw_timer.Start(100)
133 

Member Function Documentation

def imu_stream_plot2.GraphFrame.create_menu (   self)
134  def create_menu(self):
135  self.menubar = wx.MenuBar()
136 
137  menu_file = wx.Menu()
138  m_expt = menu_file.Append(-1, "&Save plot\tCtrl-S", "Save plot to file")
139  self.Bind(wx.EVT_MENU, self.on_save_plot, m_expt)
140  menu_file.AppendSeparator()
141  m_exit = menu_file.Append(-1, "E&xit\tCtrl-X", "Exit")
142  self.Bind(wx.EVT_MENU, self.on_exit, m_exit)
143 
144  self.menubar.Append(menu_file, "&File")
145  self.SetMenuBar(self.menubar)
146 
def imu_stream_plot2.GraphFrame.create_main_panel (   self)
147  def create_main_panel(self):
148  self.panel = wx.Panel(self)
149 
150  self.init_plot()
151  self.canvas = FigCanvas(self.panel, -1, self.fig)
152 
153  self.xmin_control = BoundControlBox(self.panel, -1, "X min", 0)
154  self.xmax_control = BoundControlBox(self.panel, -1, "X max", 50)
155  self.ymin_control = BoundControlBox(self.panel, -1, "Y min", 0)
156  self.ymax_control = BoundControlBox(self.panel, -1, "Y max", 100)
157 
158  self.pause_button = wx.Button(self.panel, -1, "Pause")
159  self.Bind(wx.EVT_BUTTON, self.on_pause_button, self.pause_button)
160  self.Bind(wx.EVT_UPDATE_UI, self.on_update_pause_button, self.pause_button)
161 
162  self.cb_grid = wx.CheckBox(self.panel, -1,
163  "Show Grid",
164  style=wx.ALIGN_RIGHT)
165  self.Bind(wx.EVT_CHECKBOX, self.on_cb_grid, self.cb_grid)
166  self.cb_grid.SetValue(True)
167 
168  self.cb_xlab = wx.CheckBox(self.panel, -1,
169  "Show X labels",
170  style=wx.ALIGN_RIGHT)
171  self.Bind(wx.EVT_CHECKBOX, self.on_cb_xlab, self.cb_xlab)
172  self.cb_xlab.SetValue(True)
173 
174  self.hbox1 = wx.BoxSizer(wx.HORIZONTAL)
175  self.hbox1.Add(self.pause_button, border=5, flag=wx.ALL | wx.ALIGN_CENTER_VERTICAL)
176  self.hbox1.AddSpacer(20)
177  self.hbox1.Add(self.cb_grid, border=5, flag=wx.ALL | wx.ALIGN_CENTER_VERTICAL)
178  self.hbox1.AddSpacer(10)
179  self.hbox1.Add(self.cb_xlab, border=5, flag=wx.ALL | wx.ALIGN_CENTER_VERTICAL)
180 
181  self.hbox2 = wx.BoxSizer(wx.HORIZONTAL)
182  self.hbox2.Add(self.xmin_control, border=5, flag=wx.ALL)
183  self.hbox2.Add(self.xmax_control, border=5, flag=wx.ALL)
184  self.hbox2.AddSpacer(24)
185  self.hbox2.Add(self.ymin_control, border=5, flag=wx.ALL)
186  self.hbox2.Add(self.ymax_control, border=5, flag=wx.ALL)
187 
188  self.vbox = wx.BoxSizer(wx.VERTICAL)
189  self.vbox.Add(self.canvas, 1, flag=wx.LEFT | wx.TOP | wx.GROW)
190  self.vbox.Add(self.hbox1, 0, flag=wx.ALIGN_LEFT | wx.TOP)
191  self.vbox.Add(self.hbox2, 0, flag=wx.ALIGN_LEFT | wx.TOP)
192 
193  self.panel.SetSizer(self.vbox)
194  self.vbox.Fit(self)
195 
def imu_stream_plot2.GraphFrame.create_status_bar (   self)
196  def create_status_bar(self):
197  self.statusbar = self.CreateStatusBar()
198 
def imu_stream_plot2.GraphFrame.init_plot (   self)
199  def init_plot(self):
200  self.dpi = 100
201  self.fig = Figure((3.0, 3.0), dpi=self.dpi)
202 
203  self.axes = self.fig.add_subplot(111)
204  self.axes.set_axis_bgcolor('black')
205  self.axes.set_title('IMU data', size=12)
206 
207  pylab.setp(self.axes.get_xticklabels(), fontsize=8)
208  pylab.setp(self.axes.get_yticklabels(), fontsize=8)
209 
210  # plot the data as a line series, and save the reference
211  # to the plotted line series
212  #
213  self.plot_data = self.axes.plot(
214  self.data,
215  linewidth=1,
216  color=(1, 1, 0),
217  )[0]
218 
def imu_stream_plot2.GraphFrame.draw_plot (   self)
Redraws the plot
219  def draw_plot(self):
220  """ Redraws the plot
221  """
222  # when xmin is on auto, it "follows" xmax to produce a
223  # sliding window effect. therefore, xmin is assigned after
224  # xmax.
225  #
226  if self.xmax_control.is_auto():
227  xmax = len(self.data) if len(self.data) > 50 else 50
228  else:
229  xmax = int(self.xmax_control.manual_value())
230 
231  if self.xmin_control.is_auto():
232  xmin = xmax - 50
233  else:
234  xmin = int(self.xmin_control.manual_value())
235 
236  # for ymin and ymax, find the minimal and maximal values
237  # in the data set and add a mininal margin.
238  #
239  # note that it's easy to change this scheme to the
240  # minimal/maximal value in the current display, and not
241  # the whole data set.
242  #
243  if self.ymin_control.is_auto():
244  ymin = round(min(self.data), 0) - 1
245  else:
246  ymin = int(self.ymin_control.manual_value())
247 
248  if self.ymax_control.is_auto():
249  ymax = round(max(self.data), 0) + 1
250  else:
251  ymax = int(self.ymax_control.manual_value())
252 
253  self.axes.set_xbound(lower=xmin, upper=xmax)
254  self.axes.set_ybound(lower=ymin, upper=ymax)
255 
256  # anecdote: axes.grid assumes b=True if any other flag is
257  # given even if b is set to False.
258  # so just passing the flag into the first statement won't
259  # work.
260  #
261  if self.cb_grid.IsChecked():
262  self.axes.grid(True, color='gray')
263  else:
264  self.axes.grid(False)
265 
266  # Using setp here is convenient, because get_xticklabels
267  # returns a list over which one needs to explicitly
268  # iterate, and setp already handles this.
269  #
270  pylab.setp(self.axes.get_xticklabels(),
271  visible=self.cb_xlab.IsChecked())
272 
273  self.plot_data.set_xdata(np.arange(len(self.data)))
274  self.plot_data.set_ydata(np.array(self.data))
275 
276  self.canvas.draw()
277 
def imu_stream_plot2.GraphFrame.on_pause_button (   self,
  event 
)
278  def on_pause_button(self, event):
279  self.paused = not self.paused
280 
def imu_stream_plot2.GraphFrame.on_update_pause_button (   self,
  event 
)
281  def on_update_pause_button(self, event):
282  label = "Resume" if self.paused else "Pause"
283  self.pause_button.SetLabel(label)
284 
def imu_stream_plot2.GraphFrame.on_cb_grid (   self,
  event 
)
285  def on_cb_grid(self, event):
286  self.draw_plot()
287 
def imu_stream_plot2.GraphFrame.on_cb_xlab (   self,
  event 
)
288  def on_cb_xlab(self, event):
289  self.draw_plot()
290 
def imu_stream_plot2.GraphFrame.on_save_plot (   self,
  event 
)
291  def on_save_plot(self, event):
292  file_choices = "PNG (*.png)|*.png"
293 
294  dlg = wx.FileDialog(
295  self,
296  message="Save plot as...",
297  defaultDir=os.getcwd(),
298  defaultFile="plot.png",
299  wildcard=file_choices,
300  style=wx.SAVE)
301 
302  if dlg.ShowModal() == wx.ID_OK:
303  path = dlg.GetPath()
304  self.canvas.print_figure(path, dpi=self.dpi)
305  self.flash_status_message("Saved to %s" % path)
306 
def imu_stream_plot2.GraphFrame.on_redraw_timer (   self,
  event 
)
307  def on_redraw_timer(self, event):
308  # if paused do not add data, but still redraw the plot
309  # (to respond to scale modifications, grid change, etc.)
310  #
311  if not self.paused:
312  self.data.append(self.datagen.next())
313 
314  self.draw_plot()
315 
def imu_stream_plot2.GraphFrame.on_exit (   self,
  event 
)
316  def on_exit(self, event):
317  self.Destroy()
318 
def imu_stream_plot2.GraphFrame.flash_status_message (   self,
  msg,
  flash_len_ms = 1500 
)
319  def flash_status_message(self, msg, flash_len_ms=1500):
320  self.statusbar.SetStatusText(msg)
321  self.timeroff = wx.Timer(self)
322  self.Bind(
323  wx.EVT_TIMER,
324  self.on_flash_status_off,
325  self.timeroff)
326  self.timeroff.Start(flash_len_ms, oneShot=True)
327 
def imu_stream_plot2.GraphFrame.on_flash_status_off (   self,
  event 
)
328  def on_flash_status_off(self, event):
329  self.statusbar.SetStatusText('')
330 
331 

Member Data Documentation

string imu_stream_plot2.GraphFrame.title = 'Demo: dynamic matplotlib graph'
static
imu_stream_plot2.GraphFrame.datagen
imu_stream_plot2.GraphFrame.data
imu_stream_plot2.GraphFrame.paused
imu_stream_plot2.GraphFrame.redraw_timer
imu_stream_plot2.GraphFrame.menubar
imu_stream_plot2.GraphFrame.panel
imu_stream_plot2.GraphFrame.canvas
imu_stream_plot2.GraphFrame.xmin_control
imu_stream_plot2.GraphFrame.xmax_control
imu_stream_plot2.GraphFrame.ymin_control
imu_stream_plot2.GraphFrame.ymax_control
imu_stream_plot2.GraphFrame.pause_button
imu_stream_plot2.GraphFrame.cb_grid
imu_stream_plot2.GraphFrame.cb_xlab
imu_stream_plot2.GraphFrame.hbox1
imu_stream_plot2.GraphFrame.hbox2
imu_stream_plot2.GraphFrame.vbox
imu_stream_plot2.GraphFrame.statusbar
imu_stream_plot2.GraphFrame.dpi
imu_stream_plot2.GraphFrame.fig
imu_stream_plot2.GraphFrame.axes
imu_stream_plot2.GraphFrame.plot_data
imu_stream_plot2.GraphFrame.timeroff

The documentation for this class was generated from the following file: