Changeset 171 for trunk/synapse
- Timestamp:
- 08/26/10 13:57:22 (12 years ago)
- Location:
- trunk/synapse/Puzzlebox/Synapse
- Files:
-
- 1 added
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/synapse/Puzzlebox/Synapse/Interface.py
r170 r171 10 10 11 11 __changelog__ = """\ 12 Last Update: 2010.08.2 512 Last Update: 2010.08.26 13 13 14 14 """ … … 23 23 import simplejson as json 24 24 25 import random 26 from numpy import arange, sin, pi 27 from matplotlib.backends.backend_qt4agg import FigureCanvasQTAgg as FigureCanvas 28 from matplotlib.figure import Figure 25 try: 26 from matplotlib.backends.backend_qt4agg import FigureCanvasQTAgg as FigureCanvas 27 from matplotlib.figure import Figure 28 from numpy import arange, sin, pi 29 from Interface_Plot import rawEEGMatplotlibCanvas 30 MATPLOTLIB_AVAILABLE = True 31 except: 32 MATPLOTLIB_AVAILABLE = False 29 33 30 34 if (sys.platform != 'win32'): … … 164 168 165 169 166 self.matplot = rawEEGMatplotlibCanvas(self.tabEEGSignals, \ 167 width=8, \ 168 height=4, \ 169 dpi=100, \ 170 title='Raw EEG Waves') 170 if MATPLOTLIB_AVAILABLE: 171 self.matplot = rawEEGMatplotlibCanvas(self.tabEEGSignals, \ 172 width=8, \ 173 height=4, \ 174 dpi=100, \ 175 title='Raw EEG Waves') 171 176 172 177 … … 363 368 ################################################################## 364 369 365 def updateRawEegInterface(self):366 367 pass368 369 370 ##################################################################371 372 370 def processPacketThinkGear(self, packet): 373 371 … … 378 376 if ('rawEeg' in packet.keys()): 379 377 value = packet['rawEeg'] 380 self.matplot.update_figure(value) 378 if MATPLOTLIB_AVAILABLE: 379 self.matplot.update_figure(value) 381 380 382 381 … … 598 597 event.ignore() 599 598 600 601 #####################################################################602 #####################################################################603 604 class matplotlibCanvas(FigureCanvas):605 606 """Ultimately, this is a QWidget (as well as a FigureCanvasAgg, etc.)."""607 608 def __init__(self, parent=None, width=8, height=4, dpi=100, title=None):609 610 fig = Figure(figsize=(width, height), dpi=dpi)611 self.axes_top = fig.add_subplot(211)612 self.axes_bottom = fig.add_subplot(212)613 # We want the axes cleared every time plot() is called614 self.axes_top.hold(False)615 self.axes_bottom.hold(False)616 617 if title != None:618 fig.suptitle(title, fontsize=12)619 620 FigureCanvas.__init__(self, fig)621 self.setParent(parent)622 623 FigureCanvas.setSizePolicy(self,624 QtGui.QSizePolicy.Expanding,625 QtGui.QSizePolicy.Expanding)626 FigureCanvas.updateGeometry(self)627 628 629 #####################################################################630 #####################################################################631 632 class rawEEGMatplotlibCanvas(matplotlibCanvas):633 634 def __init__(self, *args, **kwargs):635 636 matplotlibCanvas.__init__(self, *args, **kwargs)637 638 self.DEBUG=DEBUG639 640 #timer = QtCore.QTimer(self)641 #QtCore.QObject.connect(timer, QtCore.SIGNAL("timeout()"), self.update_figure)642 #timer.start(256)643 644 self.update_top_frequency = \645 INTERFACE_RAW_EEG_UPDATE_FREQUENCY646 self.update_bottom_frequency = \647 INTERFACE_RAW_EEG_UPDATE_FREQUENCY / 2648 649 self.values_top = []650 self.values_bottom = []651 652 self.axes_top.set_xbound(0, self.update_top_frequency)653 self.axes_top.set_ybound(-2048, 2047)654 655 self.axes_bottom.set_xbound(0, self.update_bottom_frequency)656 self.axes_bottom.set_ybound(-512, 512)657 658 self.axes_top.grid(True)659 self.axes_bottom.grid(True)660 661 self.axes_top.text(self.update_top_frequency + 24, \662 0, \663 '%i Hz' % self.update_top_frequency, \664 rotation='vertical', \665 verticalalignment='center')666 667 self.axes_bottom.text(self.update_bottom_frequency + 12, \668 0, \669 '%i Hz' % self.update_bottom_frequency, \670 rotation='vertical', \671 verticalalignment='center')672 673 self.axes_top.set_autoscale_on(False)674 self.axes_bottom.set_autoscale_on(False)675 676 677 ##################################################################678 679 def update_figure(self, value):680 681 self.values_top.append(value)682 self.values_bottom.append(value)683 684 if len(self.values_top) == self.update_top_frequency:685 686 self.axes_top.plot(range(self.update_top_frequency), \687 self.values_top, \688 'b-', \689 scalex=False, \690 scaley=False)691 692 #self.axes_top.set_ylabel('%i Hz' % self.update_top_frequency)693 self.axes_top.grid(True)694 695 self.axes_top.text(self.update_top_frequency + 24, \696 0, \697 '%i Hz' % self.update_top_frequency, \698 rotation='vertical', \699 verticalalignment='center')700 701 self.draw()702 703 self.values_top = []704 705 706 if len(self.values_bottom) == self.update_bottom_frequency:707 708 self.axes_bottom.plot(range(self.update_bottom_frequency), \709 self.values_bottom, \710 'r-', \711 scalex=False, \712 scaley=False)713 714 #self.axes_bottom.set_ylabel('%i Hz' % self.update_bottom_frequency)715 self.axes_bottom.grid(True)716 717 self.axes_bottom.text(self.update_bottom_frequency + 12, \718 0, \719 '%i Hz' % self.update_bottom_frequency, \720 rotation='vertical', \721 verticalalignment='center')722 723 self.draw()724 725 self.values_bottom = []726 727
Note: See TracChangeset
for help on using the changeset viewer.