Subversion Repositories Projects

Rev

Rev 593 | Rev 596 | 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.yAxesChoice = wx.ComboBox(self, -1, choices=["10", "25", "50", "100", "250"], style=wx.CB_DROPDOWN)
        self.graphTypeChoise = wx.ComboBox(self, -1, choices=["Raw Data", "Filtered Data", "Spectrum"], style=wx.CB_DROPDOWN)
        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)
        self.Bind(wx.EVT_COMBOBOX, self.onYAxesChange, self.yAxesChoice)
        # 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))
        self.yAxesChoice.SetSelection(2)
        self.graphTypeChoise.SetSelection(0)
        # 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, 0, 0)
        sizer_2.Add(self.yAxesChoice, 0, 0, 0)
        sizer_2.Add(self.graphTypeChoise, 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, size=(800,300))
       
        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))


        # Configure TestListCtrl
        self.TestListCtrl.InsertColumn(0, "Description")
        self.TestListCtrl.InsertColumn(1, "Speed")
        self.TestListCtrl.InsertColumn(2, "Channel")
        self.TestListCtrl.InsertColumn(3, "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)
         self.activeTestId = testId
         self.drawGraph()

    def drawGraph(self):
         vibTest = self.app.getTest(self.activeTestId)
         nb = vibTest.getDataLen()
         y = int(self.yAxesChoice.GetStringSelection())

         #self.client.Clear()
         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')
         self.client.Draw(wx.lib.plot.PlotGraphics([line],"Graph Title", "Time (ms)", "Acc"), yAxis= (-y,y))
         self.client.SetEnableGrid('Horizontal')


    def OnImport(self, event): # wxGlade: MainFrame.<event_handler>
        self.app.Import()

    def onYAxesChange(self, event): # wxGlade: MainFrame.<event_handler>
        self.drawGraph()

# end of class MainFrame


class VibTest:
    def __init__(self, descr, motor, speed, rawData):
        self.descr = descr
        self.motor = motor
        self.speed = speed
        self.rawData = _Numeric.array(rawData)
        self.dc = self.rawData.mean()
        self.rawData -= self.dc
        self.dataLen = len(rawData)

    def getDescr(self):
        return self.Descr

    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, descr, motor, speed, rawData):
        test = VibTest(descr, motor, speed, rawData)
        self.VibTests.append(test)

        index = self.frame_1.TestListCtrl.InsertStringItem(sys.maxint, test.descr)
        self.frame_1.TestListCtrl.SetStringItem(index, 3, "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("./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([])
            else:
              for i in range(nbCols):
                  data[i].append(int(values[i]))
        logfile.close()
        for i in range(nbCols):
            self.AddTest("Imported %d"%i, 0,0, data[i])
       
       
           

       
# end of class App

if __name__ == "__main__":
    VibrationTestGui = App(0)
    VibrationTestGui.MainLoop()