Subversion Repositories Projects

Compare Revisions

Ignore whitespace Rev 606 → Rev 607

/VibrationTest/trunk/VibrationTest/VibrationTestGui.py
7,6 → 7,7
import wx
import wx.lib
import wx.lib.plot
import ConfigParser
 
# Needs Numeric or numarray or NumPy
try:
31,15 → 32,15
 
 
 
class SettingsFrame(wx.Frame):
class SettingsDialog(wx.Dialog):
def __init__(self, *args, **kwds):
# begin wxGlade: SettingsFrame.__init__
kwds["style"] = wx.DEFAULT_FRAME_STYLE
wx.Frame.__init__(self, *args, **kwds)
self.label_5 = wx.StaticText(self, -1, "COM Port ", style=wx.ALIGN_RIGHT)
self.comPortCtrl = wx.TextCtrl(self, -1, "")
self.button_5 = wx.Button(self, wx.ID_CANCEL, "")
self.button_6 = wx.Button(self, wx.ID_OK, "")
# begin wxGlade: SettingsDialog.__init__
kwds["style"] = wx.DEFAULT_DIALOG_STYLE
wx.Dialog.__init__(self, *args, **kwds)
self.label_5_copy = wx.StaticText(self, -1, "COM Port ", style=wx.ALIGN_RIGHT)
self.comPortCtrl_copy = wx.TextCtrl(self, -1, "")
self.button_5_copy = wx.Button(self, wx.ID_CANCEL, "")
self.button_6_copy = wx.Button(self, wx.ID_OK, "")
 
self.__set_properties()
self.__do_layout()
46,33 → 47,49
# end wxGlade
 
def __set_properties(self):
# begin wxGlade: SettingsFrame.__set_properties
# begin wxGlade: SettingsDialog.__set_properties
self.SetTitle("Settings")
# end wxGlade
 
def __do_layout(self):
# begin wxGlade: SettingsFrame.__do_layout
sizer_5 = wx.BoxSizer(wx.VERTICAL)
grid_sizer_3 = wx.GridSizer(1, 2, 0, 0)
sizer_6 = wx.BoxSizer(wx.HORIZONTAL)
grid_sizer_2 = wx.GridSizer(1, 2, 4, 4)
sizer_5.Add((20, 20), 0, 0, 0)
sizer_6.Add((20, 20), 0, 0, 0)
grid_sizer_2.Add(self.label_5, 0, wx.ALIGN_RIGHT|wx.ALIGN_CENTER_VERTICAL, 0)
grid_sizer_2.Add(self.comPortCtrl, 0, 0, 0)
sizer_6.Add(grid_sizer_2, 0, 0, 0)
sizer_6.Add((20, 20), 0, 0, 0)
sizer_5.Add(sizer_6, 1, wx.EXPAND, 0)
sizer_5.Add((20, 20), 0, 0, 0)
grid_sizer_3.Add(self.button_5, 0, wx.ALIGN_CENTER_HORIZONTAL|wx.ALIGN_CENTER_VERTICAL, 0)
grid_sizer_3.Add(self.button_6, 0, wx.ALIGN_CENTER_HORIZONTAL|wx.ALIGN_CENTER_VERTICAL, 0)
sizer_5.Add(grid_sizer_3, 0, wx.EXPAND, 0)
sizer_5.Add((20, 20), 0, 0, 0)
self.SetSizer(sizer_5)
sizer_5.Fit(self)
# begin wxGlade: SettingsDialog.__do_layout
sizer_5_copy = wx.BoxSizer(wx.VERTICAL)
grid_sizer_3_copy = wx.GridSizer(1, 2, 0, 0)
sizer_6_copy = wx.BoxSizer(wx.HORIZONTAL)
grid_sizer_2_copy = wx.GridSizer(1, 2, 4, 4)
sizer_5_copy.Add((20, 20), 0, 0, 0)
sizer_6_copy.Add((20, 20), 0, 0, 0)
grid_sizer_2_copy.Add(self.label_5_copy, 0, wx.ALIGN_RIGHT|wx.ALIGN_CENTER_VERTICAL, 0)
grid_sizer_2_copy.Add(self.comPortCtrl_copy, 0, 0, 0)
sizer_6_copy.Add(grid_sizer_2_copy, 0, 0, 0)
sizer_6_copy.Add((20, 20), 0, 0, 0)
sizer_5_copy.Add(sizer_6_copy, 1, wx.EXPAND, 0)
sizer_5_copy.Add((20, 20), 0, 0, 0)
grid_sizer_3_copy.Add(self.button_5_copy, 0, wx.ALIGN_CENTER_HORIZONTAL|wx.ALIGN_CENTER_VERTICAL, 0)
grid_sizer_3_copy.Add(self.button_6_copy, 0, wx.ALIGN_CENTER_HORIZONTAL|wx.ALIGN_CENTER_VERTICAL, 0)
sizer_5_copy.Add(grid_sizer_3_copy, 0, wx.EXPAND, 0)
sizer_5_copy.Add((20, 20), 0, 0, 0)
self.SetSizer(sizer_5_copy)
sizer_5_copy.Fit(self)
self.Layout()
# end wxGlade
 
# end of class SettingsDialog
 
 
class SettingsFrame(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 SettingsFrame
 
 
133,13 → 150,12
# Menu Bar
self.frame_1_menubar = wx.MenuBar()
wxglade_tmp_menu = wx.Menu()
wxglade_tmp_menu.Append(wx.NewId(), "Exit", "", wx.ITEM_NORMAL)
wxglade_tmp_menu.Append(101, "Settings", "", wx.ITEM_NORMAL)
wxglade_tmp_menu.Append(150, "Exit", "", wx.ITEM_NORMAL)
self.frame_1_menubar.Append(wxglade_tmp_menu, "File")
wxglade_tmp_menu = wx.Menu()
self.frame_1_menubar.Append(wxglade_tmp_menu, "Settings")
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)
wxglade_tmp_menu.Append(301, "Clear", "", wx.ITEM_NORMAL)
wxglade_tmp_menu.Append(302, "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")
170,8 → 186,9
self.__set_properties()
self.__do_layout()
 
self.Bind(wx.EVT_MENU, self.onClear, id=-1)
self.Bind(wx.EVT_MENU, self.OnImport, id=-1)
self.Bind(wx.EVT_MENU, self.OnSettings, id=101)
self.Bind(wx.EVT_MENU, self.onClear, id=301)
self.Bind(wx.EVT_MENU, self.OnImport, id=302)
self.Bind(wx.EVT_CHOICE, self.onGraphTypeChange, self.graphTypeChoice)
self.Bind(wx.EVT_CHOICE, self.onYAxisChange, self.yAxisChoice)
# end wxGlade
256,7 → 273,8
self.TestListCtrl.InsertColumn(0, "Description")
self.TestListCtrl.InsertColumn(1, "Speed")
self.TestListCtrl.InsertColumn(2, "Channel")
self.TestListCtrl.InsertColumn(3, "VibrationValue")
self.TestListCtrl.InsertColumn(3, "Vibration Value")
self.TestListCtrl.SetColumnWidth(3, 500)
 
def DrawPointLabel(self, dc, mDataDict):
"""This is the fuction that defines how the pointLabels are plotted
287,7 → 305,10
index = self.TestListCtrl.InsertStringItem(sys.maxint, test.descr)
self.TestListCtrl.SetStringItem(index, 1, str(test.speed))
self.TestListCtrl.SetStringItem(index, 2, test.channel)
self.TestListCtrl.SetStringItem(index, 3, str(test.getVibValue()))
 
vv = int(test.getVibValue())
vvs = "|%s| (%d)" % ("----------------------------------------------------------------------------------------------------"[0:min(vv,100)], vv)
self.TestListCtrl.SetStringItem(index, 3, vvs)
if (index == 0):
self.TestListCtrl.Select(index)
 
299,42 → 320,63
self.drawGraph()
 
def drawGraph(self):
vibTest = self.app.getTest(self.activeTestId)
nb = vibTest.getDataLen()
y = int(self.yAxisChoice.GetStringSelection())
 
if self.graphTypeChoice.GetSelection() == 0:
xydata = _Numeric.linspace(0,0.09*nb,2*nb)
xydata.shape = (nb, 2)
xydata[:,1] = vibTest.getRawData()
line = wx.lib.plot.PolyLine(xydata, legend= 'Raw Data', colour='red', width=2)
title = "Raw Signal: %s %s %d" %(vibTest.descr, vibTest.channel, vibTest.speed)
self.client.Draw(wx.lib.plot.PlotGraphics([line], title, "Time (ms)", "Acc"), yAxis= (-y,y))
self.client.SetEnableGrid('Horizontal')
nbSelected = self.TestListCtrl.SelectedItemCount
 
if self.graphTypeChoice.GetSelection() == 1:
xydata = _Numeric.linspace(0,0.09*nb,2*nb)
xydata.shape = (nb, 2)
xydata[:,1] = vibTest.getFilteredData()
line = wx.lib.plot.PolyLine(xydata, legend= 'Raw Data', colour='red', width=2)
title = "Filtered Signal: %s %s %d" %(vibTest.descr, vibTest.channel, vibTest.speed)
self.client.Draw(wx.lib.plot.PlotGraphics([line], title, "Time (ms)", "Acc"), yAxis= (-y,y))
if nbSelected > 1:
self.graphTypeChoice.Disable()
x = 1
data = []
idx = self.TestListCtrl.GetFirstSelected()
while idx != -1:
data.append([x,self.app.getTest(idx).getVibValue()])
x += 1
idx = self.TestListCtrl.GetNextSelected(idx)
line = wx.lib.plot.PolyLine(data, legend= 'Vibrations', colour='red', width=2)
markers = wx.lib.plot.PolyMarker(data, legend= '', colour='red', marker='circle',size=2)
title = "Comparing tests"
self.client.Draw(wx.lib.plot.PlotGraphics([line, markers], title, "Test", "Vibration Value"), xAxis=(1,max(x,10)), yAxis=(0,y))
self.client.SetEnableGrid('Horizontal')
 
elif self.graphTypeChoice.GetSelection() == 2:
xydata = _Numeric.linspace(0,5555,nb)
xydata.shape = (nb/2, 2)
xydata[:,1] = vibTest.getSpectrum()
else:
self.graphTypeChoice.Enable()
vibTest = self.app.getTest(self.activeTestId)
nb = vibTest.getDataLen()
 
line = wx.lib.plot.PolyLine(xydata, legend= 'Spectrum', colour='red')
markers = wx.lib.plot.PolyMarker(xydata, legend= '', colour='red', marker='circle',size=2)
if self.graphTypeChoice.GetSelection() == 0:
xydata = _Numeric.linspace(0,0.09*nb,2*nb)
xydata.shape = (nb, 2)
xydata[:,1] = vibTest.getRawData()
line = wx.lib.plot.PolyLine(xydata, legend= 'Raw Data', colour='red', width=2)
title = "Raw Signal: %s %s %d" %(vibTest.descr, vibTest.channel, vibTest.speed)
self.client.Draw(wx.lib.plot.PlotGraphics([line], title, "Time (ms)", "Acc"), yAxis= (-y,y))
self.client.SetEnableGrid('Horizontal')
title = "Spectrum: %s %s %d" %(vibTest.descr, vibTest.channel, vibTest.speed)
self.client.Draw(wx.lib.plot.PlotGraphics([line,markers], title, "Freq (Hz)", "Acc"), xAxis=(0,200), yAxis= (-0,y))
self.client.SetEnableGrid(True)
if self.graphTypeChoice.GetSelection() == 1:
xydata = _Numeric.linspace(0,0.09*nb,2*nb)
xydata.shape = (nb, 2)
xydata[:,1] = vibTest.getFilteredData()
line = wx.lib.plot.PolyLine(xydata, legend= 'Raw Data', colour='red', width=2)
title = "Filtered Signal: %s %s %d" %(vibTest.descr, vibTest.channel, vibTest.speed)
self.client.Draw(wx.lib.plot.PlotGraphics([line], title, "Time (ms)", "Acc"), yAxis= (-y,y))
self.client.SetEnableGrid('Horizontal')
elif self.graphTypeChoice.GetSelection() == 2:
xydata = _Numeric.linspace(0,5555,nb)
xydata.shape = (nb/2, 2)
xydata[:,1] = vibTest.getSpectrum()
line = wx.lib.plot.PolyLine(xydata, legend= 'Spectrum', colour='red')
markers = wx.lib.plot.PolyMarker(xydata, legend= '', colour='red', marker='circle',size=2)
title = "Spectrum: %s %s %d" %(vibTest.descr, vibTest.channel, vibTest.speed)
self.client.Draw(wx.lib.plot.PlotGraphics([line,markers], title, "Freq (Hz)", "Acc"), xAxis=(0,200), yAxis= (-0,y))
self.client.SetEnableGrid(True)
 
 
def OnImport(self, event): # wxGlade: MainFrame.<event_handler>
360,8 → 402,24
print "Event handler `onClear' not implemented"
event.Skip()
 
def OnSettings(self, event): # wxGlade: MainFrame.<event_handler>
dlg = SettingsDialog(self, -1, "Sample Dialog", size=(350, 200),
#style=wx.CAPTION | wx.SYSTEM_MENU | wx.THICK_FRAME,
style=wx.DEFAULT_DIALOG_STYLE, # & ~wx.CLOSE_BOX
)
dlg.CenterOnScreen()
 
# this does not return until the dialog is closed.
val = dlg.ShowModal()
 
dlg.Destroy()
 
# end of class MainFrame
 
class Setting:
def __init__(self, descr, defaultValue):
self.descr = descr
self.value = defaultValue
 
class VibTest:
def __init__(self, descr, motor, speed, channel, rawData):
413,16 → 471,55
self.vibValue = max(fd)-min(fd)
return self.vibValue
 
 
 
class App(wx.App):
 
SETTINGSFILE = "settings.cfg"
 
def __init__(self, par):
self.VibTests = []
 
wx.App.__init__(self, par)
 
# Init settings
self.settings={}
self.settings["serialPort"] = Setting("SerialPort", "COM1")
self.settings["hpf"] = Setting("HP Filter cutoff (Hz)", 50)
self.settings["lpf"] = Setting("LP Filter cutoff (Hz)", 400)
 
self.readSettings()
 
if len(sys.argv)>1:
self.Import(sys.argv[1])
 
 
def readSettings(self):
print "Reading settings"
cp = ConfigParser.ConfigParser()
 
try:
cp.read(App.SETTINGSFILE)
for setting in cp.items("DEFAULT"):
print " ",setting
try:
self.settings[setting[0]].value = setting[1]
except:
print "WARNING, unknown setting"
except:
print "ERROR reading settingsfile"
 
 
def storeSettings(self):
print "Storing settings"
 
cp = ConfigParser.ConfigParser()
for setting in self.settings.iteritems():
cp.set("", setting[0], setting[1].value)
 
file = open(App.SETTINGSFILE, "w")
cp.write(file)
file.close()
 
def AddTest(self, descr, motor, speed, channel, rawData):
test = VibTest(descr, motor, speed, channel, rawData)
self.VibTests.append(test)
437,6 → 534,7
self.frame_1.setApp(self);
self.SetTopWindow(self.frame_1)
 
self.frame_1.CenterOnScreen()
self.frame_1.Show()
return 1
 
/VibrationTest/trunk/VibrationTest/VibrationTestGui.wxg
1,7 → 1,7
<?xml version="1.0"?>
<!-- generated by wxGlade 0.6.3 on Thu Oct 01 23:32:39 2009 -->
<!-- generated by wxGlade 0.6.3 on Fri Oct 02 18:21:56 2009 -->
 
<application path="C:\DATA\MK\SVN\Projects\VibrationTest\trunk\VibrationTest\VibrationTestGui.py" name="VibrationTestGui" class="App" option="0" language="python" top_window="frame_1" encoding="ISO-8859-15" use_gettext="0" overwrite="0" use_new_namespace="1" for_version="2.6" is_template="0">
<application path="D:\Fred\MK_Proj\VibrationTest\trunk\VibrationTest\VibrationTestGui.py" name="VibrationTestGui" class="App" option="0" language="python" top_window="frame_1" encoding="ISO-8859-15" use_gettext="0" overwrite="0" use_new_namespace="1" for_version="2.6" is_template="0">
<object class="MainFrame" name="frame_1" base="EditFrame">
<style>wxDEFAULT_FRAME_STYLE</style>
<title>VibrationTest</title>
11,18 → 11,24
<menus>
<menu name="" label="File">
<item>
<label>Settings</label>
<id>101</id>
<handler>OnSettings</handler>
</item>
<item>
<label>Exit</label>
<id>150</id>
</item>
</menu>
<menu name="" handler="OnSettings" label="Settings">
</menu>
<menu name="" label="TestSet">
<menu name="" itemid="300" label="TestSet">
<item>
<label>Clear</label>
<id>301</id>
<handler>onClear</handler>
</item>
<item>
<label>Import</label>
<id>302</id>
<handler>OnImport</handler>
</item>
</menu>
315,10 → 321,10
</object>
</object>
</object>
<object class="SettingsFrame" name="SettingsFrame" base="EditFrame">
<style>wxDEFAULT_FRAME_STYLE</style>
<object class="SettingsDialog" name="SettingDialog" base="EditDialog">
<style>wxDEFAULT_DIALOG_STYLE</style>
<title>Settings</title>
<object class="wxBoxSizer" name="sizer_5" base="EditBoxSizer">
<object class="wxBoxSizer" name="sizer_5_copy" base="EditBoxSizer">
<orient>wxVERTICAL</orient>
<object class="sizeritem">
<border>0</border>
332,7 → 338,7
<flag>wxEXPAND</flag>
<border>0</border>
<option>1</option>
<object class="wxBoxSizer" name="sizer_6" base="EditBoxSizer">
<object class="wxBoxSizer" name="sizer_6_copy" base="EditBoxSizer">
<orient>wxHORIZONTAL</orient>
<object class="sizeritem">
<border>0</border>
345,7 → 351,7
<object class="sizeritem">
<border>0</border>
<option>0</option>
<object class="wxGridSizer" name="grid_sizer_2" base="EditGridSizer">
<object class="wxGridSizer" name="grid_sizer_2_copy" base="EditGridSizer">
<hgap>4</hgap>
<rows>1</rows>
<cols>2</cols>
354,7 → 360,7
<flag>wxALIGN_RIGHT|wxALIGN_CENTER_VERTICAL</flag>
<border>0</border>
<option>0</option>
<object class="wxStaticText" name="label_5" base="EditStaticText">
<object class="wxStaticText" name="label_5_copy" base="EditStaticText">
<style>wxALIGN_RIGHT</style>
<attribute>1</attribute>
<label>COM Port </label>
363,7 → 369,7
<object class="sizeritem">
<border>0</border>
<option>0</option>
<object class="wxTextCtrl" name="comPortCtrl" base="EditTextCtrl">
<object class="wxTextCtrl" name="comPortCtrl_copy" base="EditTextCtrl">
</object>
</object>
</object>
390,7 → 396,7
<flag>wxEXPAND</flag>
<border>0</border>
<option>0</option>
<object class="wxGridSizer" name="grid_sizer_3" base="EditGridSizer">
<object class="wxGridSizer" name="grid_sizer_3_copy" base="EditGridSizer">
<hgap>0</hgap>
<rows>1</rows>
<cols>2</cols>
399,7 → 405,7
<flag>wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL</flag>
<border>0</border>
<option>0</option>
<object class="wxButton" name="button_5" base="EditButton">
<object class="wxButton" name="button_5_copy" base="EditButton">
<stockitem>CANCEL</stockitem>
<label>&amp;Cancel</label>
</object>
408,7 → 414,7
<flag>wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL</flag>
<border>0</border>
<option>0</option>
<object class="wxButton" name="button_6" base="EditButton">
<object class="wxButton" name="button_6_copy" base="EditButton">
<stockitem>OK</stockitem>
<label>&amp;OK</label>
</object>