![](/static/djangobb_forum/img/smilies/sad.png)
import time
import re
import sys
import random
from numpy import linspace, ndarray
import numpy
import wx
import wx.grid
from enable.api import Window
from chaco.api import ToolbarPlot
from chaco.api import create_line_plot, ArrayDataSource, ArrayPlotData, Plot, add_default_axes, add_default_grids, create_scatter_plot
from chaco import *
from chaco.tools.api import PanTool, ZoomTool, LegendTool
from scipy import arange
from class_Client_IP import *
c_ip=Client_IP(host,port)
chans=c_ip.getNameChans()
vals=c_ip.getValChans(chans)
lenth_c=len(chans)
lenth_v=len(vals)
#Y=
X=arange(-500.0, 0.0)
k=0
#X=
#Y=[, , ]
DATA=range(20)
#npoint=3
col=
class PlotFrame(wx.Frame):
“”“ This widget simply hosts an opaque enable.qt4_backend.Window
object, which provides the bridge between Enable/Chaco and the underlying
UI toolkit (qt4).
”“”
def __init__(self, parent, **kw):
self._create_data()
MainFrame=wx.Frame.__init__(self, parent, -1, “Графики”)
self.panelChaco = wx.Panel(self, id=3, pos=wx.Point(800,0), size=wx.Size(640,600))
self.getButton = wx.Button(id=4, label='Список каналов',parent=self.panelChaco, pos=wx.Point(10, 520), size=wx.Size(100, 30))
self.getButton.Bind(wx.EVT_BUTTON, self.OngetButton, id=4)
self.tableButton = wx.Button(id=5, label='Каналы в таблицу',parent=self.panelChaco, pos=wx.Point(250, 520), size=wx.Size(100, 30))
self.tableButton.Bind(wx.EVT_BUTTON, self.OntableButton, id=5)
self.grafButton = wx.Button(id=8, label='Каналы на график',parent=self.panelChaco, pos=wx.Point(250, 560), size=wx.Size(100, 30))
self.grafButton.Bind(wx.EVT_BUTTON, self.OngrafButton, id=8)
self.cancelButton = wx.Button(id=6, label='Выбрать все',parent=self.panelChaco, pos=wx.Point(130, 520), size=wx.Size(100, 30))
self.cancelButton.Bind(wx.EVT_BUTTON, self.OncancelButton, id=6)
self.invertButton = wx.Button(id=7, label='Инвертировать',parent=self.panelChaco, pos=wx.Point(130, 560), size=wx.Size(100, 30))
self.invertButton.Bind(wx.EVT_BUTTON, self.OninvertButton, id=7)
self.cleanButton = wx.Button(id=8, label='Очистить таблицу',parent=self.panelChaco, pos=wx.Point(370, 520), size=wx.Size(100, 30))
self.cleanButton.Bind(wx.EVT_BUTTON, self.OncleanButton, id=8)
#self.enable_window = create_chaco_plot(self)
self.create_chaco_plot()
self.checkListChan = wx.CheckListBox(choices=, name='checkListChan', parent=self.panelChaco, pos=wx.Point(10, 50), size=wx.Size(200, 450), style=0)
self.checkListChan.SetLabel('Channels')
self.table = wx.grid.Grid(parent=self.panelChaco, pos=wx.Point(220, 50),size=wx.Size(400,450))
self.table.CreateGrid(20,2)
self.table.SetColLabelValue(0, “Имя канала”)
self.table.SetColLabelValue(1, “Значение”)
self.table.SetColSize(0, 168)
self.table.SetColSize(1, 150)
timerId = wx.NewId()
self.timer = wx.Timer(self, timerId)
self.Bind(wx.EVT_TIMER, self.onTimer, id=timerId)
self.timer.Start(500.0, wx.TIMER_CONTINUOUS)
self.chlist=
self.vlist=
self.chlist1=
self.vlist1=
self.y=range(20)
def _create_data(self):
global DATA
for i in range(20):
DATA=range(500)
for j in range(500):
DATA=0
#print “DATA”, DATA
return
def onTimer(self, event):
global chans
chans=c_ip.getNameChans()
global vals
vals=c_ip.getValChans(chans)
vals1=c_ip.getValChans(chans)
global lenth_c
i=len(self.chlist)
if i>0:
self.vlist=c_ip.getValChans(self.chlist)
ind=0
while ind<i:
self.table.SetCellValue(ind, 0, “%s” %self.chlist)
self.table.SetCellValue(ind, 1, “%f” % self.vlist)
ind+=1
j=0
k=len(self.chlist1)
#print i,self.chlist
if k>0:
self.vlist1=c_ip.getValChans(self.chlist1)
knd=0
while knd<k:
global DATA
global X
for h in range (len(self.chlist1)):
if DATA!=0:
for j in range(1,500):
DATA
![](/static/djangobb_forum/img/smilies/big_smile.png)
DATA=self.vlist1
if X!=0:
for j in range(1,500):
X=X
X=vals1
## print “X timer”,X
#print “DATA timer”,DATA
knd+=1
#self.pd = ArrayPlotData(index = X)
for i in range (len(self.chlist1)):
self.pd.set_data(“DATA”+str(i), DATA)
## self.plot = Plot(self.pd, title=“Line Plot”, padding=50, border_visible=True)
## self.plot.resizable = “”
##
## self.plot.unified_draw = True
#### self.plot.legend.visible = True
#### for i in range (len(self.chlist1)):
#### self.plot.plot((“index”, “DATA”+str(i)), name=self.chlist1)
####
## # Attach some tools to the plot
## self.plot.tools.append(PanTool(self.plot))
## zoom = ZoomTool(component=self.plot, tool_mode=“box”, always_on=False)
## self.plot.overlays.append(zoom)
self.plot.request_redraw()
def OngetButton(self, event):
chansL=range(lenth_c-1)
for i in range (1,lenth_c):
chansL=chans
self.checkListChan.Set(chansL)
## def OngetButton(self, event):
## self.checkListChan.Set(chans)
def OntableButton(self, event):
global lenth_c
for row in range(lenth_c):
self.table.SetCellValue(row, 0, “”)
self.table.SetCellValue(row, 1, “”)
k=0
i=0
self.chlist=
self.vlist=
for row in range(lenth_c-1):
if (self.checkListChan.IsChecked(row)==1):
self.chlist.append(chans)
self.vlist.append(vals)
print k, row
#print row
self.table.SetCellValue(k, 0, self.chlist)
self.table.SetCellValue(k, 1, “%f” % self.vlist)
k=k+1
print “chlist=”, self.chlist
def OncancelButton(self, event):
for row in range(lenth_c-1):
self.checkListChan.Check(row,1)
def OninvertButton(self, event):
#event.Skip()
for row in range(lenth_c-1):
if (self.checkListChan.IsChecked(row)==1):
self.checkListChan.Check(row,0)
else:
self.checkListChan.Check(row,1)
def OngrafButton(self, event):
#event.Skip()
self.chlist1=
self.vlist1=
i=0
for row in range(lenth_c-1):
if (self.checkListChan.IsChecked(row)==1):
self.chlist1.append(chans)
self.vlist1.append(vals)
self.y=self.vlist1
i=i+1
if (i>20):
wx.MessageBox('более 20 каналов отобразить на графике невозможно', ‘Info’, wx.ICON_INFORMATION)
print “row=”,row, “i=”,i
## for i in range (i,len(self.y)):
## if (i<len(self.y)):
## self.y=range(len(self.y))
## for j in range(len(self.y)):
## self.y=0
## i=i+1
#npoint=i
print ‘y=’,self.y
print ‘self.chlist1=’,self.chlist1
self.create_chaco_plot_new()
#global Y
## for j in range(len(self.y)):
## print "type(self.y=", type(self.y)
## if (type(self.y)==int):
## self.y=range(len(self.y))
#транспонирование
## for j in range(len(self.y)):
##
## for i in range(len(self.y)):
## # if (self.y!=0):
## Y=self.y
## self.yt = numpy.matrix(self.y)
## Y=self.yt.T
#global X
#X=Y
#print “transpose”, Y, “X=”,X
#print Y.dtype.name
## X= ArrayDataSource(X)
## Y0= ArrayDataSource(Y)
## Y1= ArrayDataSource(Y)
## Y2= ArrayDataSource(Y)
#self.create_chaco_plot()
def OncleanButton(self, event):
self.chlist=
#global lenth_c
for row in range(20):
self.table.SetCellValue(row, 0, “”)
self.table.SetCellValue(row, 1, “”)
def create_chaco_plot(self):
#global X
# x=x+X
#print “global X=”,X
#col=
‘'’for j in range(2,35):
Y=range(10)
for i in range(10):
Y=y
print “len(Y)=”,len(Y), Y'''
#y=range(lenth_v)
‘'’for i in range(lenth_v):
y=vals
#print vals
print “y=”, y'''
## Y1=Y
## chan0 = ArrayDataSource(Y, sort_order=“none”)
## chan1 = ArrayDataSource(Y1, sort_order=“none”)
## chan2 = ArrayDataSource(Y, sort_order=“none”)
## print time
## plot=create_line_plot((time, chan1), color=“red”, width=2.0)
## plot=create_line_plot((time, chan0), color=“green”, width=2.0)
## plot=create_scatter_plot((time, chan2), color=“blue”)
self.pd = ArrayPlotData(index = X)
#print “index=”,index
#pd.set_data(“y”, y)
#for i in range(1):
# pd.set_data(“y”+str(i), y1)
#pd.set_data(“y”+str(i),“y”+str(i))
‘'’for i in range (33):
pd.set_data(“y”+str(i), Y)'''
#global Y
for i in range (20):
self.pd.set_data(“DATA”+str(i), DATA)
#print “из chaco”,Y
# Create some line plots of some of the data
self.plot = Plot(self.pd, title=“Line Plot”, padding=50, border_visible=True)
#plot = Plot(pd)
#plot =PlotValue(x)
#plot.padding = 50
#plot.fill_padding = True
#plot.bgcolor = “white”
#left, bottom = add_default_axes(plot)
#hgrid, vgrid = add_default_grids(plot)
#plot.type=“scatter”
self.plot = ToolbarPlot(self.pd)
self.plot.resizable = “”
#self.plot.bounds =
self.plot.unified_draw = True
self.plot.legend.visible = True
for i in range (20):
self.plot.plot((“index”, “DATA”+str(i)), name=“data”+str(i), color=col)
# Attach some tools to the plot
self.plot.tools.append(PanTool(self.plot))
zoom = ZoomTool(component=self.plot, tool_mode=“box”, always_on=False)
self.plot.overlays.append(zoom)
#plot.request_redraw()
return Window(self, -1, component = self.plot, size
![](/static/djangobb_forum/img/smilies/sad.png)
def create_chaco_plot_new(self):
global X
print X
self.pd = ArrayPlotData(index = X)
for i in range (20):
self.pd.set_data(“DATA”+str(i), DATA)
self.plot = Plot(self.pd, title=“Line Plot”, padding=50, border_visible=True)
self.plot = ToolbarPlot(self.pd)
#self.plot.resizable = “”
#self.plot.unified_draw = True
self.plot.legend.visible = True
for i in range (len(self.chlist1)):
self.plot.plot((“index”, “DATA”+str(i)), name=self.chlist1, color=col)
# Attach some tools to the plot
self.plot.tools.append(PanTool(self.plot))
zoom = ZoomTool(component=self.plot, tool_mode=“box”, always_on=False)
self.plot.overlays.append(zoom)
return Window(self, -1, component = self.plot, size
![](/static/djangobb_forum/img/smilies/sad.png)