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 |
257,6 → 274,7 |
self.TestListCtrl.InsertColumn(1, "Speed") |
self.TestListCtrl.InsertColumn(2, "Channel") |
self.TestListCtrl.InsertColumn(3, "VibrationValue") |
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,9 → 320,30 |
self.drawGraph() |
|
def drawGraph(self): |
|
y = int(self.yAxisChoice.GetStringSelection()) |
|
nbSelected = self.TestListCtrl.SelectedItemCount |
|
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') |
|
else: |
self.graphTypeChoice.Enable() |
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) |
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 |
|