--- /dev/null
+"""
+Example to draw a cursor and report the data coords in wx
+"""
+
+import matplotlib
+matplotlib.use('WXAgg')
+
+from matplotlib.backends.backend_wxagg import FigureCanvasWxAgg as FigureCanvas
+from matplotlib.backends.backend_wx import NavigationToolbar2Wx
+from matplotlib.figure import Figure
+from numpy import arange, sin, pi
+
+import wx
+
+class CanvasFrame(wx.Frame):
+
+ def __init__(self, ):
+ wx.Frame.__init__(self,None,-1,
+ 'CanvasFrame',size=(550,350))
+
+ self.SetBackgroundColour(wx.NamedColor("WHITE"))
+
+ self.figure = Figure()
+ self.axes = self.figure.add_subplot(111)
+ t = arange(0.0,3.0,0.01)
+ s = sin(2*pi*t)
+
+ self.axes.plot(t,s)
+ self.axes.set_xlabel('t')
+ self.axes.set_ylabel('sin(t)')
+ self.figure_canvas = FigureCanvas(self, -1, self.figure)
+
+ # Note that event is a MplEvent
+ self.figure_canvas.mpl_connect('motion_notify_event', self.UpdateStatusBar)
+ self.figure_canvas.Bind(wx.EVT_ENTER_WINDOW, self.ChangeCursor)
+
+ self.sizer = wx.BoxSizer(wx.VERTICAL)
+ self.sizer.Add(self.figure_canvas, 1, wx.LEFT | wx.TOP | wx.GROW)
+ self.SetSizer(self.sizer)
+ self.Fit()
+
+ self.statusBar = wx.StatusBar(self, -1)
+ self.statusBar.SetFieldsCount(1)
+ self.SetStatusBar(self.statusBar)
+
+ self.toolbar = NavigationToolbar2Wx(self.figure_canvas)
+ self.sizer.Add(self.toolbar, 0, wx.LEFT | wx.EXPAND)
+ self.toolbar.Show()
+
+ def ChangeCursor(self, event):
+ self.figure_canvas.SetCursor(wx.StockCursor(wx.CURSOR_BULLSEYE))
+
+ def UpdateStatusBar(self, event):
+ if event.inaxes:
+ x, y = event.xdata, event.ydata
+ self.statusBar.SetStatusText(( "x= " + str(x) +
+ " y=" +str(y) ),
+ 0)
+
+class App(wx.App):
+
+ def OnInit(self):
+ 'Create the main window and insert the custom frame'
+ frame = CanvasFrame()
+ self.SetTopWindow(frame)
+ frame.Show(True)
+ return True
+
+if __name__=='__main__':
+ app = App(0)
+ app.MainLoop()
\ No newline at end of file
--- /dev/null
+import wx
+import matplotlib
+# We want matplotlib to use a wxPython backend
+matplotlib.use('WXAgg')
+from matplotlib.backends.backend_wxagg import FigureCanvasWxAgg as FigureCanvas
+from matplotlib.figure import Figure
+from matplotlib.backends.backend_wx import NavigationToolbar2Wx
+
+from enthought.traits.api import Any, Instance
+from enthought.traits.ui.wx.editor import Editor
+from enthought.traits.ui.basic_editor_factory import BasicEditorFactory
+
+class _MPLFigureEditor(Editor):
+
+ scrollable = True
+
+ def init(self, parent):
+ self.control = self._create_canvas(parent)
+ self.set_tooltip()
+
+ def update_editor(self):
+ pass
+
+ def _create_canvas(self, parent):
+ """ Create the MPL canvas. """
+ # The panel lets us add additional controls.
+ panel = wx.Panel(parent, -1, style=wx.CLIP_CHILDREN)
+ sizer = wx.BoxSizer(wx.VERTICAL)
+ panel.SetSizer(sizer)
+ # matplotlib commands to create a canvas
+ mpl_control = FigureCanvas(panel, -1, self.value)
+ sizer.Add(mpl_control, 1, wx.LEFT | wx.TOP | wx.GROW)
+ toolbar = NavigationToolbar2Wx(mpl_control)
+ sizer.Add(toolbar, 0, wx.EXPAND)
+ self.value.canvas.SetMinSize((10,10))
+ return panel
+
+class MPLFigureEditor(BasicEditorFactory):
+
+ klass = _MPLFigureEditor
+
+
+if __name__ == "__main__":
+ # Create a window to demo the editor
+ from enthought.traits.api import HasTraits, Button
+ from enthought.traits.ui.api import View, Item
+ from numpy import sin, cos, linspace, pi
+
+ class Test(HasTraits):
+
+ change_graph = Button()
+ figure = Instance(Figure, ())
+ n = 12
+ view = View(Item('figure', editor=MPLFigureEditor(),
+ show_label=False),Item('change_graph', show_label=False),
+ width=400,
+ height=300,
+ resizable=True)
+
+ def __init__(self):
+ super(Test, self).__init__()
+ axes = self.figure.add_subplot(111)
+ t = linspace(0, 2*pi, 200)
+ axes.plot(sin(t)*(1+0.5*cos(11*t)), cos(t)*(1+0.5*cos(11*t)))
+
+ Test().configure_traits()
--- /dev/null
+from threading import Thread
+from time import sleep
+from enthought.traits.api import *
+from enthought.traits.ui.api import *
+from enthought.traits.ui.menu import NoButtons
+from mpleditor import MPLFigureEditor
+from matplotlib.figure import Figure
+from scipy import *
+from DbObjects import *
+from julian import julianToDatetime
+import sys
+import getopt
+import wx
+
+class AcquisitionThread(Thread):
+ def __init__ (self, dbname, plot_figure, cs_id, download_speed=None, upload_speed=None):
+ Thread.__init__(self)
+ self.dbname=dbname
+ self.plot_figure = plot_figure
+ self.cs_id = cs_id
+ self.download_speed = download_speed
+ self.upload_speed = upload_speed
+
+ def run(self):
+ cs = ClientSession(self.dbname, self.cs_id)
+ stmc = StatusMessageCollection(self.dbname, self.cs_id)
+ stmit = stmc.getIter()
+ x = []
+ y1 = []
+ y2 = []
+ while True:
+ try:
+ stm = next(stmit)
+ except StopIteration:
+ break
+ difftime =julianToDatetime(stm.timestamp)-julianToDatetime(cs.start_time)
+ x.append(difftime.seconds)
+ if self.download_speed:
+ y1.append(stm.download_speed)
+ if self.upload_speed:
+ y2.append(stm.upload_speed)
+ self.plot_figure(x, y1, y2)
+
+class ControlPanel(HasTraits):
+ #swarm widget
+ sw_id = String(auto_set=False, enter_set=True)
+ sw_torrent = String()
+ sw_filesize = String()
+ sw_purpose = String ()
+ sw_source = String()
+ sw_figure = Instance(Figure)
+
+ #btclients widget
+ btc_id = String()
+ btc_name = String()
+ btc_language = String()
+ btc_dht = Bool()
+ btc_streaming = Bool()
+
+ #client_sessions widget
+ cs_id = String(auto_set=False, enter_set=True)
+ cs_os = String()
+ cs_os_vs = String()
+ cs_os_cpu = String()
+ cs_os_ram = String()
+ cs_public_ip = String()
+ cs_public_port = String()
+ cs_ds_limit = String()
+ cs_us_limit = String()
+ cs_start_time = CStr()
+
+ #options widget
+ download_speed = Bool()
+ upload_speed = Bool()
+ plot = Button()
+
+ help = String('''
+ P2P-Next Analyzer
+ version 1.00
+ ''')
+
+ def __init__(self, figure, dbname):
+ self.dbname=dbname;
+ self.figure = figure;
+ self.axes = self.figure.add_axes((0.04,0.06,0.93,0.91))
+ self.axes.grid(linestyle='dashed')
+ #self.line = None
+
+ view = View(Group(
+ Group(Group(
+ Item('sw_id', label='Id', style='text'),
+ Item('10'),
+ Item('sw_torrent', label='Torrent'),
+ Item('sw_filesize', label='Filesize(Kb)'),
+ Item('sw_purpose', label='Purpose'),
+ Item('sw_source', label='Source'),
+ show_border=True, label='Swarm', style = 'readonly'),
+ Item('20'),
+ Group(
+ Item('cs_id', label='Id', style='text'),
+ Item('10'),
+ Item('cs_os', label='OS'),
+ Item('cs_os_vs', label='OS Version'),
+ Item('cs_os_cpu', label='System CPU'),
+ Item('cs_os_ram', label='System RAM'),
+ Item('cs_public_ip', label='Public IP'),
+ Item('cs_public_port', label='Public PORT'),
+ Item('cs_ds_limit', label='Download LMT'),
+ Item('cs_us_limit', label='Upload LMT'),
+ Item('cs_start_time', label='Start Time'),
+ show_border=True, label='Client Session', style = 'readonly'),
+ HGroup('download_speed', 'upload_speed',
+ show_border=True, label='Options'),
+ Item('20'),
+ Item('plot', show_label=False),
+ label="Control", dock='tab', style='simple'),
+ #Group(
+ #Group(
+ #Item('experiment', style='custom', show_label=False),
+ #label="Input",),
+ #Group(
+ #Item('results', style='custom', show_label=False),
+ #label="Results",),
+ #label='Experiment', dock="tab"),
+ Item('help', style='readonly', show_label=False, dock="tab"),
+ layout='tabbed')
+ )
+
+ def _sw_id_fired(self):
+ sw = Swarm(self.dbname, self.sw_id);
+ self.sw_torrent = sw.torrent
+ self.sw_filesize = sw.filesize;
+ self.sw_purpose = sw.purpose;
+ self.sw_source = sw.source;
+
+ def _cs_id_fired(self):
+ cs = ClientSession(self.dbname, self.cs_id);
+ self.cs_os = cs.system_os
+ self.cs_os_vs = cs.system_os_version
+ self.cs_os_cpu = cs.system_cpu
+ self.cs_os_ram = cs.system_ram
+ self.cs_public_ip = cs.public_ip
+ self.cs_public_port = cs.public_port
+ self.cs_ds_limit = cs.ds_limit
+ self.cs_us_limit = cs.us_limit
+ self.cs_start_time = julianToDatetime(cs.start_time)
+
+ def _plot_fired(self):
+ if len(self.cs_id) and (self.download_speed or self.upload_speed):
+ self.axes.clear()
+ self.axes.grid(linestyle='dashed')
+ AcquisitionThread(self.dbname, self.plot_figure, self.cs_id, self.download_speed, self.upload_speed).start()
+
+ def plot_figure(self, x, y1, y2):
+ if y1:
+ self.axes.plot(x, y1, label='download speed')
+ if y2:
+ self.axes.plot(x, y2, label='upload speed')
+ self.axes.legend(shadow=True, fancybox=True)
+ self.axes.set_xlabel("time (s)")
+ wx.CallAfter(self.figure.canvas.draw)
+
+class MainWindow(HasTraits):
+ figure = Instance(Figure)
+ panel = Instance(ControlPanel)
+ dbname = sys.argv[1];
+
+ def _figure_default(self):
+ figure = Figure()
+ return figure
+
+ def _panel_default(self):
+ return ControlPanel(figure=self.figure, dbname=self.dbname)
+
+ view = View(HSplit(Item('figure', editor=MPLFigureEditor(),
+ dock='vertical'),
+ Item('panel', style="custom", springy=True, width=-100),
+ show_labels=False,
+ ),
+ title='Editor',
+ resizable=True,
+ height=0.75, width=0.75,
+ buttons=NoButtons)
+
+if __name__ == '__main__':
+ MainWindow().configure_traits()