COSMOS core  1.0.2 (beta)
Comprehensive Open-architecture Solution for Mission Operations Systems
imu_stream_plot.GraphFrame Class Reference
Inheritance diagram for imu_stream_plot.GraphFrame:
Collaboration diagram for imu_stream_plot.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_plot.GraphFrame.__init__ (   self)
125  def __init__(self):
126  wx.Frame.__init__(self, None, -1, self.title)
127 
128  self.datagen = DataGen()
129  self.data = [self.datagen.next()]
130  self.paused = False
131 
132  self.create_menu()
133  self.create_status_bar()
134  self.create_main_panel()
135 
136  self.redraw_timer = wx.Timer(self)
137  self.Bind(wx.EVT_TIMER, self.on_redraw_timer, self.redraw_timer)
138  self.redraw_timer.Start(100)
139 

Member Function Documentation

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

Member Data Documentation

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

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