26 from time import time as gettime |
26 from time import time as gettime |
27 import numpy |
27 import numpy |
28 |
28 |
29 import wx |
29 import wx |
30 import wx.lib.buttons |
30 import wx.lib.buttons |
31 import matplotlib |
31 |
32 matplotlib.use('WX') |
32 try: |
33 import matplotlib.pyplot |
33 import matplotlib |
34 from matplotlib.backends.backend_wx import FigureCanvasWx as FigureCanvas |
34 matplotlib.use('WX') |
35 from mpl_toolkits.mplot3d import Axes3D |
35 import matplotlib.pyplot |
|
36 from matplotlib.backends.backend_wx import FigureCanvasWx as FigureCanvas |
|
37 from mpl_toolkits.mplot3d import Axes3D |
|
38 USE_MPL = True |
|
39 except: |
|
40 USE_MPL = False |
36 |
41 |
37 from graphics import DebugDataConsumer, DebugViewer, REFRESH_PERIOD |
42 from graphics import DebugDataConsumer, DebugViewer, REFRESH_PERIOD |
38 from controls import CustomGrid, CustomTable |
43 from controls import CustomGrid, CustomTable |
39 from dialogs.ForceVariableDialog import ForceVariableDialog |
44 from dialogs.ForceVariableDialog import ForceVariableDialog |
40 from util.BitmapLibrary import GetBitmap |
45 from util.BitmapLibrary import GetBitmap |
42 def AppendMenu(parent, help, id, kind, text): |
47 def AppendMenu(parent, help, id, kind, text): |
43 parent.Append(help=help, id=id, kind=kind, text=text) |
48 parent.Append(help=help, id=id, kind=kind, text=text) |
44 |
49 |
45 def GetDebugVariablesTableColnames(): |
50 def GetDebugVariablesTableColnames(): |
46 _ = lambda x : x |
51 _ = lambda x : x |
47 return [_("Variable"), _("Value"), _("3DAxis")] |
52 cols = [_("Variable"), _("Value")] |
|
53 if USE_MPL: |
|
54 cols.append(_("3DAxis")) |
|
55 return cols |
48 |
56 |
49 class VariableTableItem(DebugDataConsumer): |
57 class VariableTableItem(DebugDataConsumer): |
50 |
58 |
51 def __init__(self, parent, variable): |
59 def __init__(self, parent, variable): |
52 DebugDataConsumer.__init__(self) |
60 DebugDataConsumer.__init__(self) |
317 self.VariablesGrid.SetColSize(col, 100) |
325 self.VariablesGrid.SetColSize(col, 100) |
318 |
326 |
319 self.Table.ResetView(self.VariablesGrid) |
327 self.Table.ResetView(self.VariablesGrid) |
320 self.VariablesGrid.RefreshButtons() |
328 self.VariablesGrid.RefreshButtons() |
321 |
329 |
322 self.GraphicsPanel = wx.Panel(self, style=wx.TAB_TRAVERSAL) |
330 if USE_MPL: |
323 |
331 self.GraphicsPanel = wx.Panel(self, style=wx.TAB_TRAVERSAL) |
324 graphics_panel_sizer = wx.BoxSizer(wx.VERTICAL) |
332 |
325 |
333 graphics_panel_sizer = wx.BoxSizer(wx.VERTICAL) |
326 self.GraphicsCanvasWindow = wx.ScrolledWindow(self.GraphicsPanel, style=wx.HSCROLL|wx.VSCROLL) |
334 |
327 self.GraphicsCanvasWindow.Bind(wx.EVT_SIZE, self.OnGraphicsCanvasWindowResize) |
335 self.GraphicsCanvasWindow = wx.ScrolledWindow(self.GraphicsPanel, style=wx.HSCROLL|wx.VSCROLL) |
328 graphics_panel_sizer.AddWindow(self.GraphicsCanvasWindow, 1, flag=wx.GROW) |
336 self.GraphicsCanvasWindow.Bind(wx.EVT_SIZE, self.OnGraphicsCanvasWindowResize) |
329 |
337 graphics_panel_sizer.AddWindow(self.GraphicsCanvasWindow, 1, flag=wx.GROW) |
330 graphics_canvas_window_sizer = wx.BoxSizer(wx.VERTICAL) |
338 |
331 |
339 graphics_canvas_window_sizer = wx.BoxSizer(wx.VERTICAL) |
332 self.GraphicsFigure = matplotlib.figure.Figure() |
340 |
333 self.GraphicsFigure.subplots_adjust(hspace=0) |
341 self.GraphicsFigure = matplotlib.figure.Figure() |
334 self.GraphicsAxes = [] |
342 self.GraphicsFigure.subplots_adjust(hspace=0) |
335 |
343 self.GraphicsAxes = [] |
336 self.GraphicsCanvas = FigureCanvas(self.GraphicsCanvasWindow, -1, self.GraphicsFigure) |
344 |
337 graphics_canvas_window_sizer.AddWindow(self.GraphicsCanvas, 1, flag=wx.GROW) |
345 self.GraphicsCanvas = FigureCanvas(self.GraphicsCanvasWindow, -1, self.GraphicsFigure) |
338 |
346 graphics_canvas_window_sizer.AddWindow(self.GraphicsCanvas, 1, flag=wx.GROW) |
339 self.GraphicsCanvasWindow.SetSizer(graphics_canvas_window_sizer) |
347 |
340 |
348 self.GraphicsCanvasWindow.SetSizer(graphics_canvas_window_sizer) |
341 self.Graphics3DFigure = matplotlib.figure.Figure() |
349 |
342 self.Graphics3DFigure.subplotpars.update(left=0.0, right=1.0, bottom=0.0, top=1.0) |
350 self.Graphics3DFigure = matplotlib.figure.Figure() |
343 |
351 self.Graphics3DFigure.subplotpars.update(left=0.0, right=1.0, bottom=0.0, top=1.0) |
344 self.LastMotionTime = gettime() |
352 |
345 self.Graphics3DAxes = self.Graphics3DFigure.gca(projection='3d') |
353 self.LastMotionTime = gettime() |
346 self.Graphics3DAxes.set_color_cycle(['b']) |
354 self.Graphics3DAxes = self.Graphics3DFigure.gca(projection='3d') |
347 setattr(self.Graphics3DAxes, "_on_move", self.OnGraphics3DMotion) |
355 self.Graphics3DAxes.set_color_cycle(['b']) |
348 |
356 setattr(self.Graphics3DAxes, "_on_move", self.OnGraphics3DMotion) |
349 self.Graphics3DCanvas = FigureCanvas(self.GraphicsPanel, -1, self.Graphics3DFigure) |
357 |
350 self.Graphics3DCanvas.SetMinSize(wx.Size(0, 0)) |
358 self.Graphics3DCanvas = FigureCanvas(self.GraphicsPanel, -1, self.Graphics3DFigure) |
351 graphics_panel_sizer.AddWindow(self.Graphics3DCanvas, 1, flag=wx.GROW) |
359 self.Graphics3DCanvas.SetMinSize(wx.Size(0, 0)) |
352 |
360 graphics_panel_sizer.AddWindow(self.Graphics3DCanvas, 1, flag=wx.GROW) |
353 self.Graphics3DAxes.mouse_init() |
361 |
354 |
362 self.Graphics3DAxes.mouse_init() |
355 self.GraphicsPanel.SetSizer(graphics_panel_sizer) |
363 |
356 |
364 self.GraphicsPanel.SetSizer(graphics_panel_sizer) |
357 self.SplitHorizontally(self.MainPanel, self.GraphicsPanel, -200) |
365 |
|
366 self.SplitHorizontally(self.MainPanel, self.GraphicsPanel, -200) |
|
367 |
|
368 else: |
|
369 self.Initialize(self.MainPanel) |
358 |
370 |
359 self.ResetGraphics() |
371 self.ResetGraphics() |
360 |
372 |
361 def RefreshNewData(self): |
373 def RefreshNewData(self): |
362 if self.HasNewData: |
374 if self.HasNewData: |
373 self.VariablesGrid.SetCellValue(row, col, str(self.Table.GetValueByName(row, "Value"))) |
385 self.VariablesGrid.SetCellValue(row, col, str(self.Table.GetValueByName(row, "Value"))) |
374 else: |
386 else: |
375 self.Table.ResetView(self.VariablesGrid) |
387 self.Table.ResetView(self.VariablesGrid) |
376 self.VariablesGrid.RefreshButtons() |
388 self.VariablesGrid.RefreshButtons() |
377 |
389 |
378 # Refresh graphics |
390 if USE_MPL: |
379 idx = 0 |
391 # Refresh graphics |
380 for item in self.Table.GetData(): |
392 idx = 0 |
381 data = item.GetData() |
393 for item in self.Table.GetData(): |
382 if data is not None: |
394 data = item.GetData() |
383 self.GraphicsAxes[idx].clear() |
395 if data is not None: |
384 self.GraphicsAxes[idx].plot(data[:, 0], data[:, 1]) |
396 self.GraphicsAxes[idx].clear() |
385 idx += 1 |
397 self.GraphicsAxes[idx].plot(data[:, 0], data[:, 1]) |
386 self.GraphicsCanvas.draw() |
398 idx += 1 |
387 |
399 self.GraphicsCanvas.draw() |
388 # Refresh 3D graphics |
400 |
389 while len(self.Graphics3DAxes.lines) > 0: |
401 # Refresh 3D graphics |
390 self.Graphics3DAxes.lines.pop() |
402 while len(self.Graphics3DAxes.lines) > 0: |
391 if self.Axis3DValues is not None: |
403 self.Graphics3DAxes.lines.pop() |
392 self.Graphics3DAxes.plot( |
404 if self.Axis3DValues is not None: |
393 self.Axis3DValues[0][1].GetData()[self.Axis3DValues[0][0]:, 1], |
405 self.Graphics3DAxes.plot( |
394 self.Axis3DValues[1][1].GetData()[self.Axis3DValues[1][0]:, 1], |
406 self.Axis3DValues[0][1].GetData()[self.Axis3DValues[0][0]:, 1], |
395 zs = self.Axis3DValues[2][1].GetData()[self.Axis3DValues[2][0]:, 1]) |
407 self.Axis3DValues[1][1].GetData()[self.Axis3DValues[1][0]:, 1], |
396 self.Graphics3DCanvas.draw() |
408 zs = self.Axis3DValues[2][1].GetData()[self.Axis3DValues[2][0]:, 1]) |
|
409 self.Graphics3DCanvas.draw() |
397 |
410 |
398 self.Thaw() |
411 self.Thaw() |
399 |
412 |
400 def UnregisterObsoleteData(self): |
413 def UnregisterObsoleteData(self): |
401 items = [(idx, item) for idx, item in enumerate(self.Table.GetData())] |
414 items = [(idx, item) for idx, item in enumerate(self.Table.GetData())] |
490 def ResetGraphicsValues(self): |
503 def ResetGraphicsValues(self): |
491 for item in self.Table.GetData(): |
504 for item in self.Table.GetData(): |
492 item.ResetData() |
505 item.ResetData() |
493 |
506 |
494 def ResetGraphics(self): |
507 def ResetGraphics(self): |
495 self.GraphicsFigure.clear() |
508 if USE_MPL: |
496 self.GraphicsAxes = [] |
509 self.GraphicsFigure.clear() |
497 |
510 self.GraphicsAxes = [] |
498 axes_num = 0 |
511 |
499 for item in self.Table.GetData(): |
512 axes_num = 0 |
500 if item.IsNumVariable(): |
513 for item in self.Table.GetData(): |
501 axes_num += 1 |
514 if item.IsNumVariable(): |
502 |
515 axes_num += 1 |
503 for idx in xrange(axes_num): |
516 |
504 if idx == 0: |
517 for idx in xrange(axes_num): |
505 axes = self.GraphicsFigure.add_subplot(axes_num, 1, idx + 1) |
518 if idx == 0: |
506 else: |
519 axes = self.GraphicsFigure.add_subplot(axes_num, 1, idx + 1) |
507 axes = self.GraphicsFigure.add_subplot(axes_num, 1, idx + 1, sharex=self.GraphicsAxes[0]) |
520 else: |
508 self.GraphicsAxes.append(axes) |
521 axes = self.GraphicsFigure.add_subplot(axes_num, 1, idx + 1, sharex=self.GraphicsAxes[0]) |
509 |
522 self.GraphicsAxes.append(axes) |
510 self.RefreshGraphicsCanvasWindowScrollbars() |
523 |
511 self.GraphicsCanvas.draw() |
524 self.RefreshGraphicsCanvasWindowScrollbars() |
512 |
525 self.GraphicsCanvas.draw() |
513 self.Reset3DGraphics() |
526 |
|
527 self.Reset3DGraphics() |
514 |
528 |
515 def Reset3DGraphics(self): |
529 def Reset3DGraphics(self): |
516 axis = [item for item in self.Table.GetData() if item.GetAxis3D()] |
530 axis = [item for item in self.Table.GetData() if item.GetAxis3D()] |
517 if len(axis) == 3: |
531 if len(axis) == 3: |
518 max_tick = None |
532 max_tick = None |