Subversion Repositories Projects

Rev

Rev 606 | Rev 608 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 606 Rev 607
Line 5... Line 5...
5
import sys
5
import sys
6
import os
6
import os
7
import wx
7
import wx
8
import wx.lib
8
import wx.lib
9
import wx.lib.plot
9
import wx.lib.plot
-
 
10
import ConfigParser
Line 10... Line 11...
10
 
11
 
11
# Needs Numeric or numarray or NumPy
12
# Needs Numeric or numarray or NumPy
12
try:
13
try:
13
    import numpy.oldnumeric as _Numeric
14
    import numpy.oldnumeric as _Numeric
Line 29... Line 30...
29
# begin wxGlade: extracode
30
# begin wxGlade: extracode
30
# end wxGlade
31
# end wxGlade
Line 31... Line 32...
31
 
32
 
32
 
33
 
33
 
34
 
34
class SettingsFrame(wx.Frame):
35
class SettingsDialog(wx.Dialog):
35
    def __init__(self, *args, **kwds):
36
    def __init__(self, *args, **kwds):
36
        # begin wxGlade: SettingsFrame.__init__
37
        # begin wxGlade: SettingsDialog.__init__
37
        kwds["style"] = wx.DEFAULT_FRAME_STYLE
38
        kwds["style"] = wx.DEFAULT_DIALOG_STYLE
38
        wx.Frame.__init__(self, *args, **kwds)
39
        wx.Dialog.__init__(self, *args, **kwds)
39
        self.label_5 = wx.StaticText(self, -1, "COM Port ", style=wx.ALIGN_RIGHT)
40
        self.label_5_copy = wx.StaticText(self, -1, "COM Port ", style=wx.ALIGN_RIGHT)
Line 40... Line 41...
40
        self.comPortCtrl = wx.TextCtrl(self, -1, "")
41
        self.comPortCtrl_copy = wx.TextCtrl(self, -1, "")
41
        self.button_5 = wx.Button(self, wx.ID_CANCEL, "")
42
        self.button_5_copy = wx.Button(self, wx.ID_CANCEL, "")
42
        self.button_6 = wx.Button(self, wx.ID_OK, "")
43
        self.button_6_copy = wx.Button(self, wx.ID_OK, "")
Line 43... Line 44...
43
 
44
 
44
        self.__set_properties()
45
        self.__set_properties()
45
        self.__do_layout()
46
        self.__do_layout()
46
        # end wxGlade
47
        # end wxGlade
Line 47... Line 48...
47
 
48
 
48
    def __set_properties(self):
49
    def __set_properties(self):
49
        # begin wxGlade: SettingsFrame.__set_properties
50
        # begin wxGlade: SettingsDialog.__set_properties
50
        self.SetTitle("Settings")
51
        self.SetTitle("Settings")
51
        # end wxGlade
52
        # end wxGlade
52
 
53
 
53
    def __do_layout(self):
54
    def __do_layout(self):
54
        # begin wxGlade: SettingsFrame.__do_layout
55
        # begin wxGlade: SettingsDialog.__do_layout
55
        sizer_5 = wx.BoxSizer(wx.VERTICAL)
56
        sizer_5_copy = wx.BoxSizer(wx.VERTICAL)
56
        grid_sizer_3 = wx.GridSizer(1, 2, 0, 0)
57
        grid_sizer_3_copy = wx.GridSizer(1, 2, 0, 0)
57
        sizer_6 = wx.BoxSizer(wx.HORIZONTAL)
58
        sizer_6_copy = wx.BoxSizer(wx.HORIZONTAL)
58
        grid_sizer_2 = wx.GridSizer(1, 2, 4, 4)
59
        grid_sizer_2_copy = wx.GridSizer(1, 2, 4, 4)
59
        sizer_5.Add((20, 20), 0, 0, 0)
60
        sizer_5_copy.Add((20, 20), 0, 0, 0)
60
        sizer_6.Add((20, 20), 0, 0, 0)
61
        sizer_6_copy.Add((20, 20), 0, 0, 0)
61
        grid_sizer_2.Add(self.label_5, 0, wx.ALIGN_RIGHT|wx.ALIGN_CENTER_VERTICAL, 0)
62
        grid_sizer_2_copy.Add(self.label_5_copy, 0, wx.ALIGN_RIGHT|wx.ALIGN_CENTER_VERTICAL, 0)
62
        grid_sizer_2.Add(self.comPortCtrl, 0, 0, 0)
63
        grid_sizer_2_copy.Add(self.comPortCtrl_copy, 0, 0, 0)
63
        sizer_6.Add(grid_sizer_2, 0, 0, 0)
64
        sizer_6_copy.Add(grid_sizer_2_copy, 0, 0, 0)
64
        sizer_6.Add((20, 20), 0, 0, 0)
65
        sizer_6_copy.Add((20, 20), 0, 0, 0)
65
        sizer_5.Add(sizer_6, 1, wx.EXPAND, 0)
66
        sizer_5_copy.Add(sizer_6_copy, 1, wx.EXPAND, 0)
66
        sizer_5.Add((20, 20), 0, 0, 0)
67
        sizer_5_copy.Add((20, 20), 0, 0, 0)
67
        grid_sizer_3.Add(self.button_5, 0, wx.ALIGN_CENTER_HORIZONTAL|wx.ALIGN_CENTER_VERTICAL, 0)
68
        grid_sizer_3_copy.Add(self.button_5_copy, 0, wx.ALIGN_CENTER_HORIZONTAL|wx.ALIGN_CENTER_VERTICAL, 0)
68
        grid_sizer_3.Add(self.button_6, 0, wx.ALIGN_CENTER_HORIZONTAL|wx.ALIGN_CENTER_VERTICAL, 0)
69
        grid_sizer_3_copy.Add(self.button_6_copy, 0, wx.ALIGN_CENTER_HORIZONTAL|wx.ALIGN_CENTER_VERTICAL, 0)
Line -... Line 70...
-
 
70
        sizer_5_copy.Add(grid_sizer_3_copy, 0, wx.EXPAND, 0)
-
 
71
        sizer_5_copy.Add((20, 20), 0, 0, 0)
-
 
72
        self.SetSizer(sizer_5_copy)
-
 
73
        sizer_5_copy.Fit(self)
-
 
74
        self.Layout()
-
 
75
        # end wxGlade
-
 
76
 
-
 
77
# end of class SettingsDialog
-
 
78
 
-
 
79
 
-
 
80
class SettingsFrame(wx.Frame):
-
 
81
    def __init__(self, *args, **kwds):
-
 
82
        # content of this block not found: did you rename this class?
-
 
83
        pass
-
 
84
 
-
 
85
    def __set_properties(self):
69
        sizer_5.Add(grid_sizer_3, 0, wx.EXPAND, 0)
86
        # content of this block not found: did you rename this class?
Line 70... Line 87...
70
        sizer_5.Add((20, 20), 0, 0, 0)
87
        pass
71
        self.SetSizer(sizer_5)
88
 
Line 131... Line 148...
131
        wx.Frame.__init__(self, *args, **kwds)
148
        wx.Frame.__init__(self, *args, **kwds)
Line 132... Line 149...
132
       
149
       
133
        # Menu Bar
150
        # Menu Bar
134
        self.frame_1_menubar = wx.MenuBar()
151
        self.frame_1_menubar = wx.MenuBar()
-
 
152
        wxglade_tmp_menu = wx.Menu()
135
        wxglade_tmp_menu = wx.Menu()
153
        wxglade_tmp_menu.Append(101, "Settings", "", wx.ITEM_NORMAL)
136
        wxglade_tmp_menu.Append(wx.NewId(), "Exit", "", wx.ITEM_NORMAL)
154
        wxglade_tmp_menu.Append(150, "Exit", "", wx.ITEM_NORMAL)
137
        self.frame_1_menubar.Append(wxglade_tmp_menu, "File")
155
        self.frame_1_menubar.Append(wxglade_tmp_menu, "File")
138
        wxglade_tmp_menu = wx.Menu()
-
 
139
        self.frame_1_menubar.Append(wxglade_tmp_menu, "Settings")
-
 
140
        wxglade_tmp_menu = wx.Menu()
156
        wxglade_tmp_menu = wx.Menu()
141
        wxglade_tmp_menu.Append(wx.NewId(), "Clear", "", wx.ITEM_NORMAL)
157
        wxglade_tmp_menu.Append(301, "Clear", "", wx.ITEM_NORMAL)
142
        wxglade_tmp_menu.Append(wx.NewId(), "Import", "", wx.ITEM_NORMAL)
158
        wxglade_tmp_menu.Append(302, "Import", "", wx.ITEM_NORMAL)
143
        self.frame_1_menubar.Append(wxglade_tmp_menu, "TestSet")
159
        self.frame_1_menubar.Append(wxglade_tmp_menu, "TestSet")
144
        wxglade_tmp_menu = wx.Menu()
160
        wxglade_tmp_menu = wx.Menu()
145
        self.frame_1_menubar.Append(wxglade_tmp_menu, "MK")
161
        self.frame_1_menubar.Append(wxglade_tmp_menu, "MK")
146
        wxglade_tmp_menu = wx.Menu()
162
        wxglade_tmp_menu = wx.Menu()
Line 168... Line 184...
168
        self.TestListCtrl = wx.ListCtrl(self, -1, style=wx.LC_REPORT|wx.SUNKEN_BORDER)
184
        self.TestListCtrl = wx.ListCtrl(self, -1, style=wx.LC_REPORT|wx.SUNKEN_BORDER)
Line 169... Line 185...
169
 
185
 
170
        self.__set_properties()
186
        self.__set_properties()
Line -... Line 187...
-
 
187
        self.__do_layout()
171
        self.__do_layout()
188
 
172
 
189
        self.Bind(wx.EVT_MENU, self.OnSettings, id=101)
173
        self.Bind(wx.EVT_MENU, self.onClear, id=-1)
190
        self.Bind(wx.EVT_MENU, self.onClear, id=301)
174
        self.Bind(wx.EVT_MENU, self.OnImport, id=-1)
191
        self.Bind(wx.EVT_MENU, self.OnImport, id=302)
175
        self.Bind(wx.EVT_CHOICE, self.onGraphTypeChange, self.graphTypeChoice)
192
        self.Bind(wx.EVT_CHOICE, self.onGraphTypeChange, self.graphTypeChoice)
Line 176... Line 193...
176
        self.Bind(wx.EVT_CHOICE, self.onYAxisChange, self.yAxisChoice)
193
        self.Bind(wx.EVT_CHOICE, self.onYAxisChange, self.yAxisChoice)
Line 255... Line 272...
255
        # Configure TestListCtrl
272
        # Configure TestListCtrl
256
        self.TestListCtrl.InsertColumn(0, "Description")
273
        self.TestListCtrl.InsertColumn(0, "Description")
257
        self.TestListCtrl.InsertColumn(1, "Speed")
274
        self.TestListCtrl.InsertColumn(1, "Speed")
258
        self.TestListCtrl.InsertColumn(2, "Channel")
275
        self.TestListCtrl.InsertColumn(2, "Channel")
259
        self.TestListCtrl.InsertColumn(3, "VibrationValue")
276
        self.TestListCtrl.InsertColumn(3, "Vibration Value")
-
 
277
        self.TestListCtrl.SetColumnWidth(3, 500)
Line 260... Line 278...
260
 
278
 
261
    def DrawPointLabel(self, dc, mDataDict):
279
    def DrawPointLabel(self, dc, mDataDict):
262
        """This is the fuction that defines how the pointLabels are plotted
280
        """This is the fuction that defines how the pointLabels are plotted
263
            dc - DC that will be passed
281
            dc - DC that will be passed
Line 285... Line 303...
285
 
303
 
286
    def onNewTest(self, test):
304
    def onNewTest(self, test):
287
        index = self.TestListCtrl.InsertStringItem(sys.maxint, test.descr)
305
        index = self.TestListCtrl.InsertStringItem(sys.maxint, test.descr)
288
        self.TestListCtrl.SetStringItem(index, 1, str(test.speed))
306
        self.TestListCtrl.SetStringItem(index, 1, str(test.speed))
-
 
307
        self.TestListCtrl.SetStringItem(index, 2, test.channel)
-
 
308
 
-
 
309
        vv = int(test.getVibValue())
289
        self.TestListCtrl.SetStringItem(index, 2, test.channel)
310
        vvs = "|%s| (%d)" % ("----------------------------------------------------------------------------------------------------"[0:min(vv,100)], vv)
290
        self.TestListCtrl.SetStringItem(index, 3, str(test.getVibValue()))
311
        self.TestListCtrl.SetStringItem(index, 3, vvs)
291
        if (index == 0):
312
        if (index == 0):
Line 292... Line 313...
292
            self.TestListCtrl.Select(index)
313
            self.TestListCtrl.Select(index)
Line 297... Line 318...
297
         print "Test Selected id=%d" % (testId)
318
         print "Test Selected id=%d" % (testId)
298
         self.activeTestId = testId
319
         self.activeTestId = testId
299
         self.drawGraph()
320
         self.drawGraph()
Line 300... Line 321...
300
 
321
 
-
 
322
    def drawGraph(self):
-
 
323
         
-
 
324
         y = int(self.yAxisChoice.GetStringSelection())
-
 
325
 
-
 
326
         nbSelected = self.TestListCtrl.SelectedItemCount
-
 
327
 
-
 
328
         if nbSelected > 1:
-
 
329
             self.graphTypeChoice.Disable()
-
 
330
             x = 1
-
 
331
             data = []
-
 
332
             idx = self.TestListCtrl.GetFirstSelected()
-
 
333
             while idx != -1:
-
 
334
                 data.append([x,self.app.getTest(idx).getVibValue()])
-
 
335
                 x += 1
-
 
336
                 idx = self.TestListCtrl.GetNextSelected(idx)
-
 
337
             line = wx.lib.plot.PolyLine(data, legend= 'Vibrations', colour='red', width=2)
-
 
338
             markers = wx.lib.plot.PolyMarker(data, legend= '', colour='red', marker='circle',size=2)
-
 
339
             title = "Comparing tests"
-
 
340
             self.client.Draw(wx.lib.plot.PlotGraphics([line, markers], title, "Test", "Vibration Value"), xAxis=(1,max(x,10)), yAxis=(0,y))
-
 
341
             self.client.SetEnableGrid('Horizontal')
-
 
342
 
-
 
343
         else:
301
    def drawGraph(self):
344
             self.graphTypeChoice.Enable()
302
         vibTest = self.app.getTest(self.activeTestId)
345
             vibTest = self.app.getTest(self.activeTestId)
303
         nb = vibTest.getDataLen()
-
 
Line 304... Line 346...
304
         y = int(self.yAxisChoice.GetStringSelection())
346
             nb = vibTest.getDataLen()
305
 
347
 
306
         if self.graphTypeChoice.GetSelection() == 0:
348
             if self.graphTypeChoice.GetSelection() == 0:
307
             xydata = _Numeric.linspace(0,0.09*nb,2*nb)
349
                 xydata = _Numeric.linspace(0,0.09*nb,2*nb)
Line 358... Line 400...
358
 
400
 
359
    def onClear(self, event): # wxGlade: MainFrame.<event_handler>
401
    def onClear(self, event): # wxGlade: MainFrame.<event_handler>
360
        print "Event handler `onClear' not implemented"
402
        print "Event handler `onClear' not implemented"
Line -... Line 403...
-
 
403
        event.Skip()
-
 
404
 
-
 
405
    def OnSettings(self, event): # wxGlade: MainFrame.<event_handler>
-
 
406
        dlg = SettingsDialog(self, -1, "Sample Dialog", size=(350, 200),
-
 
407
                         #style=wx.CAPTION | wx.SYSTEM_MENU | wx.THICK_FRAME,
-
 
408
                         style=wx.DEFAULT_DIALOG_STYLE, # & ~wx.CLOSE_BOX
-
 
409
                         )
-
 
410
        dlg.CenterOnScreen()
-
 
411
 
-
 
412
        # this does not return until the dialog is closed.
-
 
413
        val = dlg.ShowModal()
-
 
414
 
361
        event.Skip()
415
        dlg.Destroy()
Line -... Line 416...
-
 
416
 
-
 
417
# end of class MainFrame
-
 
418
 
-
 
419
class Setting:
Line 362... Line 420...
362
 
420
    def __init__(self, descr, defaultValue):
363
# end of class MainFrame
421
        self.descr = descr
364
 
422
        self.value = defaultValue
365
 
423
 
Line 411... Line 469...
411
      if self.vibValue == None:
469
      if self.vibValue == None:
412
        fd = self.getFilteredData();
470
        fd = self.getFilteredData();
413
        self.vibValue = max(fd)-min(fd)
471
        self.vibValue = max(fd)-min(fd)
414
      return self.vibValue
472
      return self.vibValue
Line -... Line 473...
-
 
473
 
-
 
474
 
415
 
475
 
-
 
476
class App(wx.App):
-
 
477
 
-
 
478
    SETTINGSFILE = "settings.cfg"
416
class App(wx.App):
479
 
417
    def __init__(self, par):
480
    def __init__(self, par):
418
        self.VibTests = []
-
 
419
 
481
        self.VibTests = []
Line -... Line 482...
-
 
482
        wx.App.__init__(self, par)
-
 
483
 
-
 
484
        # Init settings
-
 
485
        self.settings={}
-
 
486
        self.settings["serialPort"] = Setting("SerialPort", "COM1")
-
 
487
        self.settings["hpf"] = Setting("HP Filter cutoff (Hz)", 50)
-
 
488
        self.settings["lpf"] = Setting("LP Filter cutoff (Hz)", 400)
-
 
489
 
420
        wx.App.__init__(self, par)
490
        self.readSettings()
421
 
491
 
Line -... Line 492...
-
 
492
        if len(sys.argv)>1:
-
 
493
            self.Import(sys.argv[1])
-
 
494
 
-
 
495
 
-
 
496
    def readSettings(self):
-
 
497
        print "Reading settings"
-
 
498
        cp = ConfigParser.ConfigParser()
-
 
499
 
-
 
500
        try:
-
 
501
            cp.read(App.SETTINGSFILE)
-
 
502
            for setting in cp.items("DEFAULT"):
-
 
503
                print " ",setting
-
 
504
                try:
-
 
505
                    self.settings[setting[0]].value = setting[1]
-
 
506
                except:
-
 
507
                    print "WARNING, unknown setting"
-
 
508
        except:
-
 
509
            print "ERROR reading settingsfile"
-
 
510
 
-
 
511
 
-
 
512
    def storeSettings(self):
-
 
513
        print "Storing settings"
-
 
514
 
-
 
515
        cp = ConfigParser.ConfigParser()
-
 
516
        for setting in self.settings.iteritems():
-
 
517
            cp.set("", setting[0], setting[1].value)
-
 
518
 
422
        if len(sys.argv)>1:
519
        file = open(App.SETTINGSFILE, "w")
423
            self.Import(sys.argv[1])
520
        cp.write(file)
424
 
521
        file.close()
425
 
522
 
Line 435... Line 532...
435
        wx.InitAllImageHandlers()
532
        wx.InitAllImageHandlers()
436
        self.frame_1 = MainFrame(None, -1, "")
533
        self.frame_1 = MainFrame(None, -1, "")
437
        self.frame_1.setApp(self);
534
        self.frame_1.setApp(self);
438
        self.SetTopWindow(self.frame_1)
535
        self.SetTopWindow(self.frame_1)
Line -... Line 536...
-
 
536
 
439
 
537
        self.frame_1.CenterOnScreen()
440
        self.frame_1.Show()
538
        self.frame_1.Show()
Line 441... Line 539...
441
        return 1
539
        return 1