Rev 590 |
Rev 592 |
Go to most recent revision |
Blame |
Compare with Previous |
Last modification |
View Log
| RSS feed
#!/usr/bin/env python
# -*- coding: iso-8859-15 -*-
# generated by wxGlade 0.6.3 on Thu Sep 24 15:46:36 2009
import sys
import wx
import wx.lib
import wx.lib.plot
# Needs Numeric or numarray or NumPy
try:
import numpy.oldnumeric as _Numeric
except:
try:
import numarray as _Numeric #if numarray is used it is renamed Numeric
except:
try:
import Numeric as _Numeric
except:
msg= """
This module requires the Numeric/numarray or NumPy module,
which could not be imported. It probably is not installed
(it's not part of the standard Python distribution). See the
Numeric Python site (http://numpy.scipy.org) for information on
downloading source or binaries."""
raise ImportError, "Numeric,numarray or NumPy not found. \n" + msg
# begin wxGlade: extracode
# end wxGlade
class MenuBar(wx.MenuBar):
def __init__(self, *args, **kwds):
# content of this block not found: did you rename this class?
pass
def __set_properties(self):
# content of this block not found: did you rename this class?
pass
def __do_layout(self):
# content of this block not found: did you rename this class?
pass
# end of class MenuBar
class wxFrame(wx.Panel):
def __init__(self, *args, **kwds):
# content of this block not found: did you rename this class?
pass
def __set_properties(self):
# content of this block not found: did you rename this class?
pass
def __do_layout(self):
# content of this block not found: did you rename this class?
pass
# end of class wxFrame
class MyFrame(wx.Frame):
def __init__(self, *args, **kwds):
# content of this block not found: did you rename this class?
pass
def __set_properties(self):
# content of this block not found: did you rename this class?
pass
def __do_layout(self):
# content of this block not found: did you rename this class?
pass
# end of class MyFrame
class MainFrame(wx.Frame):
def __init__(self, *args, **kwds):
# begin wxGlade: MainFrame.__init__
kwds["style"] = wx.DEFAULT_FRAME_STYLE
wx.Frame.__init__(self, *args, **kwds)
# Menu Bar
self.frame_1_menubar = wx.MenuBar()
wxglade_tmp_menu = wx.Menu()
wxglade_tmp_menu.Append(wx.NewId(), "Exit", "", wx.ITEM_NORMAL)
self.frame_1_menubar.Append(wxglade_tmp_menu, "File")
wxglade_tmp_menu = wx.Menu()
wxglade_tmp_menu.Append(wx.NewId(), "Clear", "", wx.ITEM_NORMAL)
wxglade_tmp_menu.Append(wx.NewId(), "Import", "", wx.ITEM_NORMAL)
self.frame_1_menubar.Append(wxglade_tmp_menu, "TestSet")
wxglade_tmp_menu = wx.Menu()
self.frame_1_menubar.Append(wxglade_tmp_menu, "MK")
wxglade_tmp_menu = wx.Menu()
self.frame_1_menubar.Append(wxglade_tmp_menu, "Help")
self.SetMenuBar(self.frame_1_menubar)
# Menu Bar end
self.Port = wx.StaticText(self, -1, "Port")
self.text_ctrl_1 = wx.TextCtrl(self, -1, "")
self.label_5 = wx.StaticText(self, -1, "label_5")
self.text_ctrl_5 = wx.TextCtrl(self, -1, "")
self.label_2 = wx.StaticText(self, -1, "Motor(s)")
self.text_ctrl_2 = wx.TextCtrl(self, -1, "")
self.label_6 = wx.StaticText(self, -1, "label_6")
self.text_ctrl_6 = wx.TextCtrl(self, -1, "")
self.label_3 = wx.StaticText(self, -1, "Channel(s)")
self.text_ctrl_3 = wx.TextCtrl(self, -1, "")
self.label_7 = wx.StaticText(self, -1, "label_7")
self.text_ctrl_7 = wx.TextCtrl(self, -1, "")
self.label_4 = wx.StaticText(self, -1, "Speed(s)")
self.text_ctrl_4 = wx.TextCtrl(self, -1, "")
self.label_8 = wx.StaticText(self, -1, "label_8")
self.text_ctrl_8 = wx.TextCtrl(self, -1, "")
self.button_1 = wx.Button(self, -1, "button_1")
self.GraphPanel = wx.Panel(self, -1, style=wx.DOUBLE_BORDER|wx.TAB_TRAVERSAL)
self.choice_3 = wx.Choice(self, -1, choices=[])
self.choice_4 = wx.Choice(self, -1, choices=[])
self.TestListCtrl = wx.ListCtrl(self, -1, style=wx.LC_REPORT|wx.SUNKEN_BORDER)
self.__set_properties()
self.__do_layout()
self.Bind(wx.EVT_MENU, self.OnImport, id=-1)
# end wxGlade
def setApp(self, app):
self.app = app
def __set_properties(self):
# begin wxGlade: MainFrame.__set_properties
self.SetTitle("VibrationTest")
self.GraphPanel.SetMinSize((800,300))
# end wxGlade
def __do_layout(self):
# begin wxGlade: MainFrame.__do_layout
sizer_1 = wx.BoxSizer(wx.VERTICAL)
grid_sizer_2 = wx.GridSizer(2, 1, 4, 4)
sizer_2 = wx.BoxSizer(wx.HORIZONTAL)
grid_sizer_1 = wx.GridSizer(5, 4, 4, 4)
sizer_1.Add((20, 20), 0, 0, 0)
grid_sizer_1.Add(self.Port, 0, wx.ALIGN_RIGHT, 0)
grid_sizer_1.Add(self.text_ctrl_1, 0, 0, 0)
grid_sizer_1.Add(self.label_5, 0, wx.ALIGN_RIGHT, 0)
grid_sizer_1.Add(self.text_ctrl_5, 0, 0, 0)
grid_sizer_1.Add(self.label_2, 0, wx.ALIGN_RIGHT, 0)
grid_sizer_1.Add(self.text_ctrl_2, 0, 0, 0)
grid_sizer_1.Add(self.label_6, 0, wx.ALIGN_RIGHT, 0)
grid_sizer_1.Add(self.text_ctrl_6, 0, 0, 0)
grid_sizer_1.Add(self.label_3, 0, wx.ALIGN_RIGHT, 0)
grid_sizer_1.Add(self.text_ctrl_3, 0, 0, 0)
grid_sizer_1.Add(self.label_7, 0, wx.ALIGN_RIGHT, 0)
grid_sizer_1.Add(self.text_ctrl_7, 0, 0, 0)
grid_sizer_1.Add(self.label_4, 0, wx.ALIGN_RIGHT, 0)
grid_sizer_1.Add(self.text_ctrl_4, 0, 0, 0)
grid_sizer_1.Add(self.label_8, 0, wx.ALIGN_RIGHT, 0)
grid_sizer_1.Add(self.text_ctrl_8, 0, 0, 0)
grid_sizer_1.Add(self.button_1, 0, 0, 0)
sizer_1.Add(grid_sizer_1, 0, 0, 2)
sizer_1.Add((20, 20), 0, 0, 0)
sizer_1.Add(self.GraphPanel, 1, wx.ALIGN_CENTER_HORIZONTAL, 0)
sizer_2.Add(self.choice_3, 0, 0, 0)
sizer_2.Add(self.choice_4, 0, 0, 0)
sizer_1.Add(sizer_2, 0, wx.EXPAND, 0)
sizer_1.Add((20, 20), 0, 0, 0)
grid_sizer_2.Add(self.TestListCtrl, 1, wx.ALL|wx.EXPAND, 0)
sizer_1.Add(grid_sizer_2, 1, wx.EXPAND, 0)
self.SetSizer(sizer_1)
sizer_1.Fit(self)
self.Layout()
# end wxGlade
# List events
self.TestListCtrl.Bind(wx.EVT_LIST_ITEM_SELECTED, self.OnTestSelected, self.TestListCtrl)
# Configure Graph
self.client = wx.lib.plot.PlotCanvas(self.GraphPanel)
self.client.SetPointLabelFunc(self.DrawPointLabel)
self.client.SetFont(wx.Font(10,wx.SWISS,wx.NORMAL,wx.NORMAL))
self.client.SetFontSizeAxis(10)
self.client.SetFontSizeLegend(7)
self.client.setLogScale((False,False))
self.client.SetXSpec('auto')
self.client.SetYSpec('auto')
data1 = 2.*_Numeric.pi*_Numeric.arange(200)/200.
data1.shape = (100, 2)
data1[:,1] = _Numeric.sin(data1[:,0])
markers1 = wx.lib.plot.PolyMarker(data1, legend='Green Markers', colour='green', marker='circle',size=1)
pi = 3.1415
markers2 = wx.lib.plot.PolyMarker([(0., 0.), (pi/4., 1.), (pi/2, 0.),
(3.*pi/4., -1)], legend='Cross Legend', colour='blue',
marker='cross')
#self.client.Draw(wx.lib.plot.PlotGraphics([markers1,markers2],"Graph Title", "X Axis", "Y Axis"))
# Configure TestListCtrl
self.TestListCtrl.InsertColumn(0, "Name")
self.TestListCtrl.InsertColumn(1, "Result")
def DrawPointLabel(self, dc, mDataDict):
"""This is the fuction that defines how the pointLabels are plotted
dc - DC that will be passed
mDataDict - Dictionary of data that you want to use for the pointLabel
As an example I have decided I want a box at the curve point
with some text information about the curve plotted below.
Any wxDC method can be used.
"""
# ----------
dc.SetPen(wx.Pen(wx.BLACK))
dc.SetBrush(wx.Brush( wx.BLACK, wx.SOLID ) )
sx, sy = mDataDict["scaledXY"] #scaled x,y of closest point
dc.DrawRectangle( sx-5,sy-5, 10, 10) #10by10 square centered on point
px,py = mDataDict["pointXY"]
cNum = mDataDict["curveNum"]
pntIn = mDataDict["pIndex"]
legend = mDataDict["legend"]
#make a string to display
s = "Crv# %i, '%s', Pt. (%.2f,%.2f), PtInd %i" %(cNum, legend, px, py, pntIn)
dc.DrawText(s, sx , sy+1)
# -----------
def OnTestSelected(self, event):
testId = event.m_itemIndex
print "Test Selected id=%d" % (testId)
vibTest = self.app.getTest(testId)
nb = vibTest.getDataLen()
self.client.Clear()
xydata = _Numeric.arange(nb*2)
xydata.shape = (nb, 2)
xydata[:,1] = vibTest.getRawData()
line = wx.lib.plot.PolyLine(xydata, legend= 'Raw Data', colour='red')
self.client.Draw(wx.lib.plot.PlotGraphics([line],"Graph Title", "Time", "Acc"), yAxis= (-100,100))
def OnImport(self, event): # wxGlade: MainFrame.<event_handler>
self.app.Import()
# end of class MainFrame
class VibTest:
def __init__(self, name, rawData):
self.name = name
self.rawData = _Numeric.array(rawData)
self.dc = self.rawData.mean()
self.rawData -= self.dc
self.dataLen = len(rawData)
def getName(self):
return self.name
def getRawData(self):
return self.rawData
def getDataLen(self):
return self.dataLen
class App(wx.App):
def __init__(self, par):
self.VibTests = []
wx.App.__init__(self, par)
def AddTest(self, name, rawData):
test = VibTest(name, rawData)
self.VibTests.append(test)
index = self.frame_1.TestListCtrl.InsertStringItem(sys.maxint, test.name)
self.frame_1.TestListCtrl.SetStringItem(index, 1, "OK")
def getTest(self, testId):
return self.VibTests[testId]
def OnInit(self):
wx.InitAllImageHandlers()
self.frame_1 = MainFrame(None, -1, "")
self.frame_1.setApp(self);
self.SetTopWindow(self.frame_1)
self.frame_1.Show()
return 1
def Import(self):
print "Import"
logfile = open("../Misc/Matlab/Data/unbal200.txt", "r")
data = None
for line in logfile:
values = line.split(',')
if data == None:
nbCols = len(values)
print "%d cols" % nbCols
data = []
for i in range(nbCols):
data.append([])
for i in range(nbCols):
data[i].append(int(values[i]))
logfile.close()
for i in range(nbCols):
self.AddTest("Imported %d"%i, data[i])
# end of class App
if __name__ == "__main__":
VibrationTestGui = App(0)
VibrationTestGui.MainLoop()