Ejemplo n.º 1
0
 def OnSensorList (self, event):
     self.statusbar.SetStatusText('Sensor list selected')
     self.DestroyActivePanel() 
         
     self.modelistpanel = ModeListPanel(self)
     self.sizer = wx.BoxSizer(wx.VERTICAL)
     self.sizer.Add(self.modelistpanel, 1, wx.EXPAND)
     self.SetSizer(self.sizer)
     self.modelistpanel.showModeListPanel()
     self.modelistpanel.SetFocus()
     self.Layout()
Ejemplo n.º 2
0
 def update(self,event):
     if self.panelLoading:
         self.panelLoading.Destroy()   
         
     self.modelistpanel = ModeListPanel(self)
     self.sizer = wx.BoxSizer(wx.VERTICAL)
     self.sizer.Add(self.modelistpanel, 1, wx.EXPAND)
     self.SetSizer(self.sizer)
     self.modelistpanel.showModeListPanel()
     self.modelistpanel.SetFocus()
     self.Layout()
Ejemplo n.º 3
0
    def OnSensorList(self, event):
        self.statusbar.SetStatusText('Sensor list selected')
        self.DestroyActivePanel()

        self.modelistpanel = ModeListPanel(self)
        self.sizer = wx.BoxSizer(wx.VERTICAL)
        self.sizer.Add(self.modelistpanel, 1, wx.EXPAND)
        self.SetSizer(self.sizer)
        self.sensors, self.port = self.getvalues()
        self.modelistpanel.setRecordFile(self.record_file)
        self.modelistpanel.setPort(self.port)
        self.modelistpanel.setEcoMode(self.ecomode)
        self.modelistpanel.showModeListPanel()
        self.modelistpanel.ShowSensors()
        self.modelistpanel.SetFocus()
        self.Layout()
Ejemplo n.º 4
0
    def __init__(self):
        """
        Constructor.
        """
        wx.Frame.__init__(self,
                          None,
                          id=wx.ID_ANY,
                          title=u"Bernardo Plaza Project",
                          pos=(0, 0),
                          size=wx.Size(320, 240),
                          style=wx.DEFAULT_FRAME_STYLE | wx.TAB_TRAVERSAL)
        self.SetSizeHintsSz(wx.Size(320, 240), wx.Size(320, 240))
        self.SetFont(wx.Font(8, 74, 90, 90, False, "Calibri"))

        self.statusbar = self.CreateStatusBar(2, wx.ST_SIZEGRIP, wx.ID_ANY)
        self.statusbar.SetStatusWidths([-1, 80])
        self.statusbar.SetFont(wx.Font(6, 74, 90, 91, False, "Calibri Light"))
        statusbar_fields = ['Ready', 'Time']
        for i in range(len(statusbar_fields)):
            self.statusbar.SetStatusText(statusbar_fields[i], i)
        self.timer = wx.Timer(self)
        self.timer.Start(1000)
        self.timerDTC = wx.Timer(self, id=2)

        self.connection = None
        self.sensors = []
        self.port = None
        self.ecomode = False

        self.menubar = wx.MenuBar(0)
        self.menuFile = wx.Menu()
        self.menuSettings = wx.Menu()
        self.menuSensors = wx.MenuItem(self.menuSettings, wx.ID_ANY,
                                       u"Sensors", wx.EmptyString,
                                       wx.ITEM_NORMAL)
        self.menuSensors.SetBitmap(
            wx.Bitmap(u"./icons/Industry-Electrical-Sensor-icon.png",
                      wx.BITMAP_TYPE_ANY))
        self.menuSettings.AppendItem(self.menuSensors)

        self.menuRecordsSettings = wx.MenuItem(self.menuSettings, wx.ID_ANY,
                                               u"Records", wx.EmptyString,
                                               wx.ITEM_NORMAL)
        self.menuRecordsSettings.SetBitmap(
            wx.Bitmap(u"./icons/Actions-office-chart-line-stacked-icon.png",
                      wx.BITMAP_TYPE_ANY))
        self.menuSettings.AppendItem(self.menuRecordsSettings)

        self.menuAlarm = wx.MenuItem(self.menuSettings, wx.ID_ANY, u"Alarms",
                                     wx.EmptyString, wx.ITEM_NORMAL)
        self.menuAlarm.SetBitmap(
            wx.Bitmap(u"./icons/megaphone-icon.png", wx.BITMAP_TYPE_ANY))
        self.menuSettings.AppendItem(self.menuAlarm)

        self.menuSerial = wx.MenuItem(self.menuSettings, wx.ID_ANY,
                                      u"Serial port", wx.EmptyString,
                                      wx.ITEM_NORMAL)
        self.menuSerial.SetBitmap(
            wx.Bitmap(u"./icons/port-icon.png", wx.BITMAP_TYPE_ANY))
        self.menuSettings.AppendItem(self.menuSerial)

        self.menuEcoMode = wx.MenuItem(self.menuSettings, wx.ID_ANY,
                                       u"Enable Eco Mode", wx.EmptyString,
                                       wx.ITEM_CHECK)
        self.menuSettings.AppendItem(self.menuEcoMode)

        self.menuFile.AppendSubMenu(self.menuSettings, u"Settings")

        self.menuRecords = wx.MenuItem(self.menuFile, wx.ID_ANY, u"Records",
                                       wx.EmptyString, wx.ITEM_NORMAL)
        self.menuRecords.SetBitmap(
            wx.Bitmap(u"./icons/Folder-Chart-icon.png", wx.BITMAP_TYPE_ANY))
        self.menuFile.AppendItem(self.menuRecords)

        self.menuDTC = wx.MenuItem(self.menuFile, wx.ID_ANY,
                                   u"Diganostic Trouble Code", wx.EmptyString,
                                   wx.ITEM_NORMAL)
        self.menuDTC.SetBitmap(
            wx.Bitmap(u"./icons/Transport-Engine-icon.png",
                      wx.BITMAP_TYPE_ANY))
        self.menuFile.AppendItem(self.menuDTC)

        self.menuFile.AppendSeparator()

        self.menuModes = wx.Menu()
        self.menuGraphical = wx.MenuItem(self.menuModes, wx.ID_ANY,
                                         u"Graphical", wx.EmptyString,
                                         wx.ITEM_NORMAL)
        self.menuGraphical.SetBitmap(
            wx.Bitmap(u"./icons/speedometer-icon.png", wx.BITMAP_TYPE_ANY))
        self.menuModes.AppendItem(self.menuGraphical)

        self.menuNumerical = wx.MenuItem(self.menuModes, wx.ID_ANY,
                                         u"Numerical", wx.EmptyString,
                                         wx.ITEM_NORMAL)
        self.menuNumerical.SetBitmap(
            wx.Bitmap(u"./icons/Industry-Display-icon.png",
                      wx.BITMAP_TYPE_ANY))
        self.menuModes.AppendItem(self.menuNumerical)

        self.menuSensorList = wx.MenuItem(self.menuModes, wx.ID_ANY,
                                          u"Sensor List", wx.EmptyString,
                                          wx.ITEM_NORMAL)
        self.menuSensorList.SetBitmap(
            wx.Bitmap(u"./icons/Data-List-icon.png", wx.BITMAP_TYPE_ANY))
        self.menuModes.AppendItem(self.menuSensorList)

        self.menuFile.AppendSubMenu(self.menuModes, u"Modes")

        self.menuQuit = wx.MenuItem(self.menuFile, wx.ID_ANY, u"Quit",
                                    wx.EmptyString, wx.ITEM_NORMAL)
        self.menuQuit.SetBitmap(
            wx.Bitmap(u"./icons/Actions-dialog-cancel-icon.png",
                      wx.BITMAP_TYPE_ANY))
        self.menuFile.AppendItem(self.menuQuit)

        self.menubar.Append(self.menuFile, u"File")

        menuView = wx.Menu()
        self.menuStatus = wx.MenuItem(menuView, wx.ID_ANY, u"Show Status Bar",
                                      wx.EmptyString, wx.ITEM_CHECK)
        self.shst = menuView.AppendItem(self.menuStatus)

        menuView.Check(self.shst.GetId(), True)

        self.menubar.Append(menuView, u"View")

        self.menuHelp = wx.Menu()
        self.menuAbout = wx.MenuItem(self.menuHelp, wx.ID_ANY, u"About",
                                     wx.EmptyString, wx.ITEM_NORMAL)
        self.menuAbout.SetBitmap(
            wx.Bitmap(u"./icons/Actions-help-about-icon.png",
                      wx.BITMAP_TYPE_ANY))
        self.menuHelp.AppendItem(self.menuAbout)

        self.menubar.Append(self.menuHelp, u"Help")

        self.SetMenuBar(self.menubar)

        self.panelLoading = OBDLoadingPanel(self)
        self.sizer = wx.BoxSizer(wx.VERTICAL)
        self.sizer.Add(self.panelLoading, 1, wx.EXPAND)
        self.SetSizer(self.sizer)

        self.panelLoading.showLoadingScreen()
        self.panelLoading.SetFocus()
        #OBDLoadingPanel.gif.Play(False)

        # Connect Events
        self.Bind(wx.EVT_MENU, self.OnSensors, id=self.menuSensors.GetId())
        self.Bind(wx.EVT_MENU, self.OnRecords, id=self.menuRecords.GetId())
        self.Bind(wx.EVT_MENU, self.OnAlarms, id=self.menuAlarm.GetId())
        self.Bind(wx.EVT_MENU, self.OnEcoMode, id=self.menuEcoMode.GetId())
        self.Bind(wx.EVT_MENU,
                  self.OnRecordsSettings,
                  id=self.menuRecordsSettings.GetId())
        self.Bind(wx.EVT_MENU, self.OnDTC, id=self.menuDTC.GetId())
        self.Bind(wx.EVT_MENU, self.OnGraphical, id=self.menuGraphical.GetId())
        self.Bind(wx.EVT_MENU, self.OnNumerical, id=self.menuNumerical.GetId())
        self.Bind(wx.EVT_MENU,
                  self.OnSensorList,
                  id=self.menuSensorList.GetId())
        self.Bind(wx.EVT_MENU, self.OnQuit, id=self.menuQuit.GetId())
        self.Bind(wx.EVT_MENU,
                  self.ToggleStatusBar,
                  id=self.menuStatus.GetId())
        self.Bind(wx.EVT_MENU, self.OnAbout, id=self.menuAbout.GetId())
        self.Bind(wx.EVT_MENU, self.OnSerial, id=self.menuSerial.GetId())
        self.Bind(wx.EVT_TIMER, self.UpdateTime, self.timer)
        self.Bind(wx.EVT_TIMER, self.UpdateDTC, self.timerDTC)

        #panels
        self.settingsesorpanel = SettitingSensorPanel(self)
        self.settingalarmpanel = SettingAlarmsPanel(self)
        self.settingserialpanel = SettingSerialPanel(self)
        self.settingrecordpanel = SettingRecordPanel(self)
        self.modegraphicalpanel = ModeGraphicalPanel(self)
        self.dtcpanel = DTCsPanel(self)
        self.recordspanel = RecordsPanel(self)
        self.modelistpanel = ModeListPanel(self)
        self.modenumericalpanel = ModeNumericalPanel(self)

        if self.menuEcoMode.IsChecked():
            self.ecomode = True

        else:
            self.ecomode = False

        self.cfg = wx.Config('DTCs Settings')
        if self.cfg.Exists(
                'refresh'):  #port baudrate databits parity stop bits
            refreshtime = self.cfg.ReadInt('refresh')
            autodtc = self.cfg.ReadInt('autodtc')

            if autodtc == 1:
                self.timerDTC.Start(refreshtime * 1000)
            else:
                self.timerDTC.Stop()
        else:
            autodtc = 0
Ejemplo n.º 5
0
class PFCFrame(wx.Frame):
    """
    OBD frame.
    """
    def __init__(self):
        """
        Constructor.
        """
        wx.Frame.__init__(self,
                          None,
                          id=wx.ID_ANY,
                          title=u"Bernardo Plaza Project",
                          pos=(0, 0),
                          size=wx.Size(320, 240),
                          style=wx.DEFAULT_FRAME_STYLE | wx.TAB_TRAVERSAL)
        self.SetSizeHintsSz(wx.Size(320, 240), wx.Size(320, 240))
        self.SetFont(wx.Font(8, 74, 90, 90, False, "Calibri"))

        self.statusbar = self.CreateStatusBar(2, wx.ST_SIZEGRIP, wx.ID_ANY)
        self.statusbar.SetStatusWidths([-1, 80])
        self.statusbar.SetFont(wx.Font(6, 74, 90, 91, False, "Calibri Light"))
        statusbar_fields = ['Ready', 'Time']
        for i in range(len(statusbar_fields)):
            self.statusbar.SetStatusText(statusbar_fields[i], i)
        self.timer = wx.Timer(self)
        self.timer.Start(1000)
        self.timerDTC = wx.Timer(self, id=2)

        self.connection = None
        self.sensors = []
        self.port = None
        self.ecomode = False

        self.menubar = wx.MenuBar(0)
        self.menuFile = wx.Menu()
        self.menuSettings = wx.Menu()
        self.menuSensors = wx.MenuItem(self.menuSettings, wx.ID_ANY,
                                       u"Sensors", wx.EmptyString,
                                       wx.ITEM_NORMAL)
        self.menuSensors.SetBitmap(
            wx.Bitmap(u"./icons/Industry-Electrical-Sensor-icon.png",
                      wx.BITMAP_TYPE_ANY))
        self.menuSettings.AppendItem(self.menuSensors)

        self.menuRecordsSettings = wx.MenuItem(self.menuSettings, wx.ID_ANY,
                                               u"Records", wx.EmptyString,
                                               wx.ITEM_NORMAL)
        self.menuRecordsSettings.SetBitmap(
            wx.Bitmap(u"./icons/Actions-office-chart-line-stacked-icon.png",
                      wx.BITMAP_TYPE_ANY))
        self.menuSettings.AppendItem(self.menuRecordsSettings)

        self.menuAlarm = wx.MenuItem(self.menuSettings, wx.ID_ANY, u"Alarms",
                                     wx.EmptyString, wx.ITEM_NORMAL)
        self.menuAlarm.SetBitmap(
            wx.Bitmap(u"./icons/megaphone-icon.png", wx.BITMAP_TYPE_ANY))
        self.menuSettings.AppendItem(self.menuAlarm)

        self.menuSerial = wx.MenuItem(self.menuSettings, wx.ID_ANY,
                                      u"Serial port", wx.EmptyString,
                                      wx.ITEM_NORMAL)
        self.menuSerial.SetBitmap(
            wx.Bitmap(u"./icons/port-icon.png", wx.BITMAP_TYPE_ANY))
        self.menuSettings.AppendItem(self.menuSerial)

        self.menuEcoMode = wx.MenuItem(self.menuSettings, wx.ID_ANY,
                                       u"Enable Eco Mode", wx.EmptyString,
                                       wx.ITEM_CHECK)
        self.menuSettings.AppendItem(self.menuEcoMode)

        self.menuFile.AppendSubMenu(self.menuSettings, u"Settings")

        self.menuRecords = wx.MenuItem(self.menuFile, wx.ID_ANY, u"Records",
                                       wx.EmptyString, wx.ITEM_NORMAL)
        self.menuRecords.SetBitmap(
            wx.Bitmap(u"./icons/Folder-Chart-icon.png", wx.BITMAP_TYPE_ANY))
        self.menuFile.AppendItem(self.menuRecords)

        self.menuDTC = wx.MenuItem(self.menuFile, wx.ID_ANY,
                                   u"Diganostic Trouble Code", wx.EmptyString,
                                   wx.ITEM_NORMAL)
        self.menuDTC.SetBitmap(
            wx.Bitmap(u"./icons/Transport-Engine-icon.png",
                      wx.BITMAP_TYPE_ANY))
        self.menuFile.AppendItem(self.menuDTC)

        self.menuFile.AppendSeparator()

        self.menuModes = wx.Menu()
        self.menuGraphical = wx.MenuItem(self.menuModes, wx.ID_ANY,
                                         u"Graphical", wx.EmptyString,
                                         wx.ITEM_NORMAL)
        self.menuGraphical.SetBitmap(
            wx.Bitmap(u"./icons/speedometer-icon.png", wx.BITMAP_TYPE_ANY))
        self.menuModes.AppendItem(self.menuGraphical)

        self.menuNumerical = wx.MenuItem(self.menuModes, wx.ID_ANY,
                                         u"Numerical", wx.EmptyString,
                                         wx.ITEM_NORMAL)
        self.menuNumerical.SetBitmap(
            wx.Bitmap(u"./icons/Industry-Display-icon.png",
                      wx.BITMAP_TYPE_ANY))
        self.menuModes.AppendItem(self.menuNumerical)

        self.menuSensorList = wx.MenuItem(self.menuModes, wx.ID_ANY,
                                          u"Sensor List", wx.EmptyString,
                                          wx.ITEM_NORMAL)
        self.menuSensorList.SetBitmap(
            wx.Bitmap(u"./icons/Data-List-icon.png", wx.BITMAP_TYPE_ANY))
        self.menuModes.AppendItem(self.menuSensorList)

        self.menuFile.AppendSubMenu(self.menuModes, u"Modes")

        self.menuQuit = wx.MenuItem(self.menuFile, wx.ID_ANY, u"Quit",
                                    wx.EmptyString, wx.ITEM_NORMAL)
        self.menuQuit.SetBitmap(
            wx.Bitmap(u"./icons/Actions-dialog-cancel-icon.png",
                      wx.BITMAP_TYPE_ANY))
        self.menuFile.AppendItem(self.menuQuit)

        self.menubar.Append(self.menuFile, u"File")

        menuView = wx.Menu()
        self.menuStatus = wx.MenuItem(menuView, wx.ID_ANY, u"Show Status Bar",
                                      wx.EmptyString, wx.ITEM_CHECK)
        self.shst = menuView.AppendItem(self.menuStatus)

        menuView.Check(self.shst.GetId(), True)

        self.menubar.Append(menuView, u"View")

        self.menuHelp = wx.Menu()
        self.menuAbout = wx.MenuItem(self.menuHelp, wx.ID_ANY, u"About",
                                     wx.EmptyString, wx.ITEM_NORMAL)
        self.menuAbout.SetBitmap(
            wx.Bitmap(u"./icons/Actions-help-about-icon.png",
                      wx.BITMAP_TYPE_ANY))
        self.menuHelp.AppendItem(self.menuAbout)

        self.menubar.Append(self.menuHelp, u"Help")

        self.SetMenuBar(self.menubar)

        self.panelLoading = OBDLoadingPanel(self)
        self.sizer = wx.BoxSizer(wx.VERTICAL)
        self.sizer.Add(self.panelLoading, 1, wx.EXPAND)
        self.SetSizer(self.sizer)

        self.panelLoading.showLoadingScreen()
        self.panelLoading.SetFocus()
        #OBDLoadingPanel.gif.Play(False)

        # Connect Events
        self.Bind(wx.EVT_MENU, self.OnSensors, id=self.menuSensors.GetId())
        self.Bind(wx.EVT_MENU, self.OnRecords, id=self.menuRecords.GetId())
        self.Bind(wx.EVT_MENU, self.OnAlarms, id=self.menuAlarm.GetId())
        self.Bind(wx.EVT_MENU, self.OnEcoMode, id=self.menuEcoMode.GetId())
        self.Bind(wx.EVT_MENU,
                  self.OnRecordsSettings,
                  id=self.menuRecordsSettings.GetId())
        self.Bind(wx.EVT_MENU, self.OnDTC, id=self.menuDTC.GetId())
        self.Bind(wx.EVT_MENU, self.OnGraphical, id=self.menuGraphical.GetId())
        self.Bind(wx.EVT_MENU, self.OnNumerical, id=self.menuNumerical.GetId())
        self.Bind(wx.EVT_MENU,
                  self.OnSensorList,
                  id=self.menuSensorList.GetId())
        self.Bind(wx.EVT_MENU, self.OnQuit, id=self.menuQuit.GetId())
        self.Bind(wx.EVT_MENU,
                  self.ToggleStatusBar,
                  id=self.menuStatus.GetId())
        self.Bind(wx.EVT_MENU, self.OnAbout, id=self.menuAbout.GetId())
        self.Bind(wx.EVT_MENU, self.OnSerial, id=self.menuSerial.GetId())
        self.Bind(wx.EVT_TIMER, self.UpdateTime, self.timer)
        self.Bind(wx.EVT_TIMER, self.UpdateDTC, self.timerDTC)

        #panels
        self.settingsesorpanel = SettitingSensorPanel(self)
        self.settingalarmpanel = SettingAlarmsPanel(self)
        self.settingserialpanel = SettingSerialPanel(self)
        self.settingrecordpanel = SettingRecordPanel(self)
        self.modegraphicalpanel = ModeGraphicalPanel(self)
        self.dtcpanel = DTCsPanel(self)
        self.recordspanel = RecordsPanel(self)
        self.modelistpanel = ModeListPanel(self)
        self.modenumericalpanel = ModeNumericalPanel(self)

        if self.menuEcoMode.IsChecked():
            self.ecomode = True

        else:
            self.ecomode = False

        self.cfg = wx.Config('DTCs Settings')
        if self.cfg.Exists(
                'refresh'):  #port baudrate databits parity stop bits
            refreshtime = self.cfg.ReadInt('refresh')
            autodtc = self.cfg.ReadInt('autodtc')

            if autodtc == 1:
                self.timerDTC.Start(refreshtime * 1000)
            else:
                self.timerDTC.Stop()
        else:
            autodtc = 0

        #eventes
    def OnSensors(self, event):
        self.DestroyActivePanel()

        self.statusbar.SetStatusText('sensors selected')
        self.settingsesorpanel = SettitingSensorPanel(self)
        self.sizer = wx.BoxSizer(wx.VERTICAL)
        self.sizer.Add(self.settingsesorpanel, 1, wx.EXPAND)
        self.SetSizer(self.sizer)
        self.sensors, self.port = self.getvalues()
        self.settingsesorpanel.setSensors(self.sensors)
        self.settingsesorpanel.showSettingSensorPanel()
        self.settingsesorpanel.SetFocus()
        self.Layout()

    def OnAlarms(self, event):
        self.DestroyActivePanel()

        self.statusbar.SetStatusText('alarms selected')
        self.settingalarmpanel = SettingAlarmsPanel(self)
        self.sizer = wx.BoxSizer(wx.VERTICAL)
        self.sizer.Add(self.settingalarmpanel, 1, wx.EXPAND)
        self.SetSizer(self.sizer)
        self.sensors, self.port = self.getvalues()
        self.settingalarmpanel.setSensors(self.sensors)
        self.settingalarmpanel.showAlarmPPanel()
        self.settingalarmpanel.SetFocus()
        self.Layout()

    def OnRecords(self, event):
        self.DestroyActivePanel()

        self.statusbar.SetStatusText('records selected')
        self.recordspanel = RecordsPanel(self)
        self.sizer = wx.BoxSizer(wx.VERTICAL)
        self.sizer.Add(self.recordspanel, 1, wx.EXPAND)
        self.SetSizer(self.sizer)
        self.sensors, self.port = self.getvalues()
        self.recordspanel.setSensors(self.sensors)
        self.recordspanel.showRecordsPanel()
        self.recordspanel.SetFocus()
        self.Layout()

    def OnEcoMode(self, event):
        if self.menuEcoMode.IsChecked():
            self.statusbar.SetStatusText('Eco Mode On')
            self.ecomode = True

        else:
            self.statusbar.SetStatusText('Eco Mode Off')
            self.menuEcoMode.SetBitmap(
                wx.Bitmap(u"./icons/Heart-gray-icon.png", wx.BITMAP_TYPE_ANY))
            self.ecomode = False

    def update(self, event):
        self.path = os.path.dirname(__file__)
        self.record_path = os.path.join(self.path, 'recrods/')
        self.filedate = datetime.strftime(datetime.now(), '%Y-%m-%d-%H-%M-%S')
        self.record_file = "records-" + self.filedate + ".csv" + "\n"
        f = open(self.record_file, 'w')
        f.close()

        if not os.path.isdir(self.record_path):
            os.makedirs(self.record_path)

        if self.panelLoading:
            connection = self.panelLoading.getConnection()
            sensors = self.panelLoading.getSensors()
            port = self.panelLoading.getPort()
            c = self.panelLoading.getClass()
            self.panelLoading.Destroy()
            print('in update')
            print(connection)
        print(sensors)
        print(port)

        if connection:
            print 'if connection'
            self.modenumericalpanel.setConnection(connection)
            self.modelistpanel.setConnection(connection)
            self.modegraphicalpanel.setConnection(connection)

        if sensors:
            print 'sending sensors and port'
            self.modenumericalpanel.setSensors(sensors)
            self.modenumericalpanel.setPort(port)

            self.modegraphicalpanel.setSensors(sensors)
            self.modegraphicalpanel.setPort(port)
            self.modelistpanel.setSensors(sensors)
            self.modelistpanel.setPort(port)
            self.modenumericalpanel.setEcoMode(self.ecomode)
            self.modegraphicalpanel.setEcoMode(self.ecomode)
            self.modelistpanel.setEcoMode(self.ecomode)

            self.modelistpanel.setRecordFile(self.record_file)
            self.setvalues(sensors, port)
            self.dtcpanel.setPort(port)

            print 'sens and p gotten'
            self.setvalues(sensors, port)
            self.setclass(c)

        self.modenumericalpanel = ModeNumericalPanel(self)
        self.sizer = wx.BoxSizer(wx.VERTICAL)
        self.sizer.Add(self.modenumericalpanel, 1, wx.EXPAND)
        self.SetSizer(self.sizer)
        self.sensors, self.port = self.getvalues()
        self.modenumericalpanel.setPort(self.port)
        self.modenumericalpanel.setSensors(self.sensors)
        self.modegraphicalpanel.setEcoMode(self.ecomode)
        self.modenumericalpanel.showModeNumericalPanel()
        self.modenumericalpanel.ShowSensors()
        self.modenumericalpanel.SetFocus()
        self.Layout()

    def setvalues(self, sensors, port):
        self.sensors = sensors
        self.port = port

    def setclass(self, c):
        self.c = c

    def getvalues(self):
        return self.sensors, self.port

    def getport(self):
        return self.port

    def getsensor(self):
        return self.sensors

    def getClass(self):
        return self.c

    def OnSerial(self, etent):
        self.DestroyActivePanel()

        self.statusbar.SetStatusText('Serial Setting selected')
        self.settingserialpanel = SettingSerialPanel(self)
        self.sizer = wx.BoxSizer(wx.VERTICAL)
        self.sizer.Add(self.settingserialpanel, 1, wx.EXPAND)
        self.SetSizer(self.sizer)
        self.settingserialpanel.showSerialPanel()
        self.settingserialpanel.SetFocus()
        self.Layout()

    def OnSettings(self, event):
        self.statusbar.SetStatusText('settings selected')

    def OnRecordsSettings(self, event):
        self.DestroyActivePanel()

        self.statusbar.SetStatusText('records settings selected')
        self.settingrecordpanel = SettingRecordPanel(self)
        self.sizer = wx.BoxSizer(wx.VERTICAL)
        self.sizer.Add(self.settingrecordpanel, 1, wx.EXPAND)
        self.SetSizer(self.sizer)

        self.sensors, self.port = self.getvalues()
        self.settingrecordpanel.setSensors(self.sensors)
        self.settingrecordpanel.showSettingRecordPanel()
        self.settingrecordpanel.SetFocus()
        self.Layout()

    def OnDTC(self, event):
        self.DestroyActivePanel()
        self.statusbar.SetStatusText('DTC selected')
        self.dtcpanel = DTCsPanel(self)
        self.sizer = wx.BoxSizer(wx.VERTICAL)
        self.sizer.Add(self.dtcpanel, 1, wx.EXPAND)
        self.SetSizer(self.sizer)
        self.port = self.getport()
        getclass = self.getClass()
        self.dtcpanel.setClass(getclass)
        self.dtcpanel.setPort(self.port)
        self.dtcpanel.showDTCsPanel()
        self.dtcpanel.SetFocus()
        self.Layout()

    def OnGraphical(self, event):
        self.DestroyActivePanel()
        self.statusbar.SetStatusText('Graphical selected')
        self.modegraphicalpanel = ModeGraphicalPanel(self)
        self.sizer = wx.BoxSizer(wx.VERTICAL)
        self.sizer.Add(self.modegraphicalpanel, 1, wx.EXPAND)
        self.SetSizer(self.sizer)
        self.sensors, self.port = self.getvalues()
        self.modegraphicalpanel.setPort(self.port)
        self.modegraphicalpanel.setSensors(self.sensors)
        self.modegraphicalpanel.setEcoMode(self.ecomode)
        self.modegraphicalpanel.showGraphicalPanel()
        self.modegraphicalpanel.ShowSensors()
        self.modegraphicalpanel.SetFocus()
        self.Layout()

    def OnNumerical(self, event):
        self.statusbar.SetStatusText('Numerical selected')
        self.DestroyActivePanel()

        self.modenumericalpanel = ModeNumericalPanel(self)
        self.sizer = wx.BoxSizer(wx.VERTICAL)
        self.sizer.Add(self.modenumericalpanel, 1, wx.EXPAND)
        self.SetSizer(self.sizer)
        self.sensors, self.port = self.getvalues()
        self.modenumericalpanel.setPort(self.port)
        self.modenumericalpanel.setSensors(self.sensors)
        self.modenumericalpanel.setEcoMode(self.ecomode)
        self.modenumericalpanel.showModeNumericalPanel()
        self.modenumericalpanel.ShowSensors()
        self.modenumericalpanel.SetFocus()
        self.Layout()

    def OnSensorList(self, event):
        self.statusbar.SetStatusText('Sensor list selected')
        self.DestroyActivePanel()

        self.modelistpanel = ModeListPanel(self)
        self.sizer = wx.BoxSizer(wx.VERTICAL)
        self.sizer.Add(self.modelistpanel, 1, wx.EXPAND)
        self.SetSizer(self.sizer)
        self.sensors, self.port = self.getvalues()
        self.modelistpanel.setRecordFile(self.record_file)
        self.modelistpanel.setPort(self.port)
        self.modelistpanel.setEcoMode(self.ecomode)
        self.modelistpanel.showModeListPanel()
        self.modelistpanel.ShowSensors()
        self.modelistpanel.SetFocus()
        self.Layout()

    def OnAbout(self, event):
        # A message dialoge box with an OK button. wx.OK is a sandard ID in wxWidgets u"PFC Desarrollo de Sistema Electrónico de Información y Diagnosis con Pantalla Táctil para Vehículos con EOBD \n\nAuthor: Bernardo Plaza\nVersion: 1.0", wx.DefaultPosition, wx.DefaultSize, 0 )
        dialog = wx.MessageDialog(
            self,
            u"PFC Desarrollo de Sistema Electrónico de Información y Diagnosis con Pantalla Táctil para Vehículos con EOBD \n\nAuthor: Bernardo Plaza\nVersion: 1.0"
        )
        dialog.ShowModal()  # show it
        dialog.Destroy()  # finally destroy it when finished
        self.statusbar.SetStatusText('About selected')

    def DestroyActivePanel(self):
        if self.panelLoading:
            self.panelLoading.Destroy()
        if self.settingsesorpanel:
            self.settingsesorpanel.Destroy()
        if self.settingrecordpanel:
            self.settingrecordpanel.Destroy()
        if self.settingalarmpanel:
            self.settingalarmpanel.Destroy()
        if self.settingserialpanel:
            self.settingserialpanel.Destroy()
        if self.recordspanel:
            self.recordspanel.Destroy()
            autodtc = 0
        if self.dtcpanel:
            self.dtcpanel.Destroy()
            if self.cfg.Exists(
                    'refresh'):  #port baudrate databits parity stop bits
                refreshtime = self.cfg.ReadInt('refresh')
                autodtc = self.cfg.ReadInt('autodtc')

            if autodtc == 1:
                self.timerDTC.Start(refreshtime * 1000)

            else:
                self.timerDTC.Stop()

        if self.modegraphicalpanel:
            self.modegraphicalpanel.Destroy()
        if self.modenumericalpanel:
            self.modenumericalpanel.Destroy()
        if self.modelistpanel:
            self.modelistpanel.Destroy()

    def UpdateTime(self, event):
        self.statusbar.SetStatusText(
            datetime.now().strftime("%d-%m-%Y %H:%M:%S"), 1)

    def UpdateDTC(self, event):
        print 'DTC timer'
        getclass = self.getClass()
        self.DTCCodes = getclass.get_dtc()
        if self.DTCCodes:
            wx.MessageBox('List of DTCs' + str(self.DTCCodes), 'DTC Codes',
                          wx.OK | wx.ICON_INFORMATION)

    def ToggleStatusBar(self, e):

        if self.shst.IsChecked():
            self.statusbar.Show()
        else:
            self.statusbar.Hide()

    def OnQuit(self, e):
        self.Close()

    def __del__(self):
        pass
Ejemplo n.º 6
0
class PFCFrame(wx.Frame):
    """
    OBD frame.
    """

    def __init__(self):
        """
        Constructor.
        """        
        wx.Frame.__init__ ( self, None, id = wx.ID_ANY, title = u"Bernardo Plaza Project", pos = wx.DefaultPosition, size = wx.Size( 320,240 ), style = wx.DEFAULT_FRAME_STYLE|wx.TAB_TRAVERSAL )
        self.SetSizeHintsSz( wx.Size( 320,240 ), wx.Size( 320,240 ) )
        self.SetFont( wx.Font( 8, 74, 90, 90, False, "Calibri" ) )
        
        self.statusbar = self.CreateStatusBar( 2, wx.ST_SIZEGRIP, wx.ID_ANY )       
        self.statusbar.SetStatusWidths([-1, 80])
        self.statusbar.SetFont( wx.Font( 6, 74, 90, 91, False, "Calibri Light" ) )
        statusbar_fields = ['Ready','Time']
        for i in range(len(statusbar_fields)):
            self.statusbar.SetStatusText(statusbar_fields[i], i)
        self.timer = wx.Timer(self)   
        self.timer.Start(1000)
        
        self.menubar = wx.MenuBar( 0 )
        self.menuFile = wx.Menu()
        self.menuSettings = wx.Menu()
        self.menuSensors = wx.MenuItem( self.menuSettings, wx.ID_ANY, u"Sensors", wx.EmptyString, wx.ITEM_NORMAL )
        self.menuSensors.SetBitmap( wx.Bitmap( u"./icons/Industry-Electrical-Sensor-icon.png", wx.BITMAP_TYPE_ANY ) )
        self.menuSettings.AppendItem( self.menuSensors )
        
        self.menuRecordsSettings = wx.MenuItem( self.menuSettings, wx.ID_ANY, u"Records", wx.EmptyString, wx.ITEM_NORMAL )
        self.menuRecordsSettings.SetBitmap( wx.Bitmap( u"./icons/Actions-office-chart-line-stacked-icon.png", wx.BITMAP_TYPE_ANY ) )
        self.menuSettings.AppendItem( self.menuRecordsSettings )
        
        self.menuAlarm = wx.MenuItem( self.menuSettings, wx.ID_ANY, u"Alarms", wx.EmptyString, wx.ITEM_NORMAL )
        self.menuAlarm.SetBitmap( wx.Bitmap( u"./icons/megaphone-icon.png", wx.BITMAP_TYPE_ANY ) )
        self.menuSettings.AppendItem( self.menuAlarm )
        
        self.menuSerial = wx.MenuItem( self.menuSettings, wx.ID_ANY, u"Serial port", wx.EmptyString, wx.ITEM_NORMAL )
        self.menuSerial.SetBitmap( wx.Bitmap( u"./icons/port-icon.png", wx.BITMAP_TYPE_ANY ) )
        self.menuSettings.AppendItem( self.menuSerial )
        
        self.menuEcoMode = wx.MenuItem( self.menuSettings, wx.ID_ANY, u"Enable Eco Mode", wx.EmptyString, wx.ITEM_CHECK )
        self.menuEcoMode.SetBitmap( wx.Bitmap( u"./icons/Heart-green-icon.png", wx.BITMAP_TYPE_ANY ) )
        self.menuSettings.AppendItem( self.menuEcoMode )       
        
        self.menuFile.AppendSubMenu( self.menuSettings, u"Settings" )
        
        self.menuRecords = wx.MenuItem( self.menuFile, wx.ID_ANY, u"Records", wx.EmptyString, wx.ITEM_NORMAL )
        self.menuRecords.SetBitmap( wx.Bitmap( u"./icons/Folder-Chart-icon.png", wx.BITMAP_TYPE_ANY ) )
        self.menuFile.AppendItem( self.menuRecords )
        
        self.menuDTC = wx.MenuItem( self.menuFile, wx.ID_ANY, u"Diganostic Trouble Code", wx.EmptyString, wx.ITEM_NORMAL )
        self.menuDTC.SetBitmap( wx.Bitmap( u"./icons/Transport-Engine-icon.png", wx.BITMAP_TYPE_ANY ) )
        self.menuFile.AppendItem( self.menuDTC )
        
        self.menuFile.AppendSeparator()
        
        self.menuModes = wx.Menu()
        self.menuGraphical = wx.MenuItem( self.menuModes, wx.ID_ANY, u"Graphical", wx.EmptyString, wx.ITEM_NORMAL )
        self.menuGraphical.SetBitmap( wx.Bitmap( u"./icons/speedometer-icon.png", wx.BITMAP_TYPE_ANY ) )
        self.menuModes.AppendItem( self.menuGraphical )
        
        self.menuNumerical = wx.MenuItem( self.menuModes, wx.ID_ANY, u"Numerical", wx.EmptyString, wx.ITEM_NORMAL )
        self.menuNumerical.SetBitmap( wx.Bitmap( u"./icons/Industry-Display-icon.png", wx.BITMAP_TYPE_ANY ) )
        self.menuModes.AppendItem( self.menuNumerical )
        
        self.menuSensorList = wx.MenuItem( self.menuModes, wx.ID_ANY, u"Sensor List", wx.EmptyString, wx.ITEM_NORMAL )
        self.menuSensorList.SetBitmap( wx.Bitmap( u"./icons/Data-List-icon.png", wx.BITMAP_TYPE_ANY ) )
        self.menuModes.AppendItem( self.menuSensorList )
        
        self.menuFile.AppendSubMenu( self.menuModes, u"Modes" )
        
        self.menuQuit = wx.MenuItem( self.menuFile, wx.ID_ANY, u"Quit", wx.EmptyString, wx.ITEM_NORMAL )
        self.menuQuit.SetBitmap( wx.Bitmap( u"./icons/Actions-dialog-cancel-icon.png", wx.BITMAP_TYPE_ANY ) )
        self.menuFile.AppendItem( self.menuQuit )
        
        self.menubar.Append( self.menuFile, u"File" ) 
        
        menuView = wx.Menu()
        self.menuStatus = wx.MenuItem( menuView, wx.ID_ANY, u"Show Status Bar", wx.EmptyString, wx.ITEM_CHECK )
        self.shst = menuView.AppendItem( self.menuStatus )
        
        menuView.Check(self.shst.GetId(), True) 
        
        
        self.menubar.Append( menuView, u"View" ) 
        
        self.menuHelp = wx.Menu()
        self.menuAbout = wx.MenuItem( self.menuHelp, wx.ID_ANY, u"About", wx.EmptyString, wx.ITEM_NORMAL )
        self.menuAbout.SetBitmap( wx.Bitmap( u"./icons/Actions-help-about-icon.png", wx.BITMAP_TYPE_ANY ) )
        self.menuHelp.AppendItem( self.menuAbout )
        
        self.menubar.Append( self.menuHelp, u"Help" ) 
        
        self.SetMenuBar( self.menubar )
        


        self.panelLoading = OBDLoadingPanel(self)
        self.sizer = wx.BoxSizer(wx.VERTICAL)
        self.sizer.Add(self.panelLoading, 1, wx.EXPAND)
        self.SetSizer(self.sizer)

        self.panelLoading.showLoadingScreen()
        self.panelLoading.SetFocus()
        #OBDLoadingPanel.gif.Play(False)
        
         # Connect Events
        self.Bind( wx.EVT_MENU, self.OnSensors, id = self.menuSensors.GetId() )
        self.Bind( wx.EVT_MENU, self.OnRecords, id = self.menuRecords.GetId() )
        self.Bind( wx.EVT_MENU, self.OnAlarms, id = self.menuAlarm.GetId() )
        self.Bind( wx.EVT_MENU, self.OnEcoMode, id = self.menuEcoMode.GetId() )
        self.Bind( wx.EVT_MENU, self.OnRecordsSettings, id = self.menuRecordsSettings.GetId() )
        self.Bind( wx.EVT_MENU, self.OnDTC, id = self.menuDTC.GetId() )
        self.Bind( wx.EVT_MENU, self.OnGraphical, id = self.menuGraphical.GetId() )
        self.Bind( wx.EVT_MENU, self.OnNumerical, id = self.menuNumerical.GetId() )
        self.Bind( wx.EVT_MENU, self.OnSensorList, id = self.menuSensorList.GetId() )
        self.Bind( wx.EVT_MENU, self.OnQuit, id = self.menuQuit.GetId() )
        self.Bind( wx.EVT_MENU, self.ToggleStatusBar, id = self.menuStatus.GetId() )
        self.Bind( wx.EVT_MENU, self.OnAbout, id = self.menuAbout.GetId() )
        self.Bind( wx.EVT_MENU, self.OnSerial, id = self.menuSerial.GetId() )
        self.Bind(wx.EVT_TIMER, self.UpdateTime, self.timer)
        
        #panels
        self.settingsesorpanel = SettitingSensorPanel(self)
        self.settingalarmpanel = SettingAlarmsPanel(self)
        self.settingserialpanel = SettingSerialPanel(self)
        self.settingrecordpanel = SettingRecordPanel(self)
        self.modegraphicalpanel = ModeGraphicalPanel(self)
        self.dtcpanel = DTCsPanel(self)
        self.modelistpanel = ModeListPanel(self)


        #eventes
    def OnSensors(self,event):
        self.DestroyActivePanel()    
                
        self.statusbar.SetStatusText('sensors selected')
        self.settingsesorpanel = SettitingSensorPanel(self)
        self.sizer = wx.BoxSizer(wx.VERTICAL)
        self.sizer.Add(self.settingsesorpanel, 1, wx.EXPAND)
        self.SetSizer(self.sizer)
        self.settingsesorpanel.showSettingSensorPanel()
        self.settingsesorpanel.SetFocus()
        self.Layout()
        
        
    
    def OnAlarms(self,event):
        self.DestroyActivePanel() 
                    
        self.statusbar.SetStatusText('alarms selected')
        self.settingalarmpanel = SettingAlarmsPanel(self)
        self.sizer = wx.BoxSizer(wx.VERTICAL)
        self.sizer.Add(self.settingalarmpanel, 1, wx.EXPAND)
        self.SetSizer(self.sizer)
        self.settingalarmpanel.showAlarmPPanel()
        self.settingalarmpanel.SetFocus()
        self.Layout()
    
    def OnRecords(self,event):
        self.statusbar.SetStatusText('recors selected')
        
    def OnEcoMode(self, e):        
        if self.menuEcoMode.IsChecked():
            self.statusbar.SetStatusText('Eco Mode On')
            #self.menuEcoMode.SetBitmap( wx.Bitmap( u"./icons/Heart-green-icon.png", wx.BITMAP_TYPE_ANY ) )
        else:
            self.statusbar.SetStatusText('Eco Mode Off')
            self.menuEcoMode.SetBitmap( wx.Bitmap( u"./icons/Heart-gray-icon.png", wx.BITMAP_TYPE_ANY ) )   
        
    def update(self,event):
        if self.panelLoading:
            self.panelLoading.Destroy()   
            
        self.panelmain = PanelMain(self)
        self.sizer = wx.BoxSizer(wx.VERTICAL)
        self.sizer.Add(self.panelmain, 1, wx.EXPAND)
        self.SetSizer(self.sizer)
        self.panelmain.SetFocus()
        self.Layout()
    
    def OnSerial(self, etent):
        self.DestroyActivePanel() 
             
        self.statusbar.SetStatusText('Serial Setting selected')    
        self.settingserialpanel = SettingSerialPanel(self)
        self.sizer = wx.BoxSizer(wx.VERTICAL)
        self.sizer.Add(self.settingserialpanel, 1, wx.EXPAND)
        self.SetSizer(self.sizer)
        self.settingserialpanel.showSerialPanel()
        self.settingserialpanel.SetFocus()
        self.Layout()
        
    def OnSettings (self, event):
        self.statusbar.SetStatusText('settings selected')      
    
    def OnRecordsSettings (self, event):
        self.DestroyActivePanel() 
                
        self.statusbar.SetStatusText('records selected')
        self.settingrecordpanel = SettingRecordPanel(self)
        self.sizer = wx.BoxSizer(wx.VERTICAL)
        self.sizer.Add(self.settingrecordpanel, 1, wx.EXPAND)
        self.SetSizer(self.sizer)
        self.settingrecordpanel.showSettingRecordPanel()
        self.settingrecordpanel.SetFocus()
        self.Layout()
        
    def OnDTC (self, event):
        self.DestroyActivePanel() 
            
        self.statusbar.SetStatusText('DTC selected')
        self.dtcpanel = DTCsPanel(self)
        self.sizer = wx.BoxSizer(wx.VERTICAL)
        self.sizer.Add(self.dtcpanel, 1, wx.EXPAND)
        self.SetSizer(self.sizer)
        self.dtcpanel.showDTCsPanel()
        self.dtcpanel.SetFocus()
        self.Layout()
        
    def OnGraphical (self, event):
        self.DestroyActivePanel() 
            
        self.statusbar.SetStatusText('Graphical selected')
        self.modegraphicalpanel = ModeGraphicalPanel(self)
        self.sizer = wx.BoxSizer(wx.VERTICAL)
        self.sizer.Add(self.modegraphicalpanel, 1, wx.EXPAND)
        self.SetSizer(self.sizer)
        self.modegraphicalpanel.showGraphicalPanel()
        self.modegraphicalpanel.SetFocus()
        self.Layout()
        
        
    def OnNumerical (self, event):
        self.statusbar.SetStatusText('Numerical selected')
        
    def OnSensorList (self, event):
        self.statusbar.SetStatusText('Sensor list selected')
        self.DestroyActivePanel() 
            
        self.modelistpanel = ModeListPanel(self)
        self.sizer = wx.BoxSizer(wx.VERTICAL)
        self.sizer.Add(self.modelistpanel, 1, wx.EXPAND)
        self.SetSizer(self.sizer)
        self.modelistpanel.showModeListPanel()
        self.modelistpanel.SetFocus()
        self.Layout()
    
    
    
    def OnAbout (self, event):
        # A message dialoge box with an OK button. wx.OK is a sandard ID in wxWidgets u"PFC Desarrollo de Sistema Electrónico de Información y Diagnosis con Pantalla Táctil para Vehículos con EOBD \n\nAuthor: Bernardo Plaza\nVersion: 1.0", wx.DefaultPosition, wx.DefaultSize, 0 )
        dialog = wx.MessageDialog(self, u"PFC Desarrollo de Sistema Electrónico de Información y Diagnosis con Pantalla Táctil para Vehículos con EOBD \n\nAuthor: Bernardo Plaza\nVersion: 1.0")
        dialog.ShowModal()  # show it
        dialog.Destroy()  # finally destroy it when finished
        self.statusbar.SetStatusText('About selected')
        
    def DestroyActivePanel(self):
        if self.panelLoading:
            self.panelLoading.Destroy()
        if self.panelmain:
            self.panelmain.Destroy()
        if  self.settingsesorpanel:
            self.settingsesorpanel.Destroy()         
        if self.settingrecordpanel:
            self.settingrecordpanel.Destroy() 
        if self.settingalarmpanel:
            self.settingalarmpanel.Destroy()
        if self.settingserialpanel:
            self.settingserialpanel.Destroy()     
        
        #if panelID == PANEL_RECORDS:
            #print 'destroy record panel'
        if self.dtcpanel:
            self.dtcpanel.Destroy() 
       
        if self.modegraphicalpanel:
            self.modegraphicalpanel.Destroy()   
        #if panelID == PANEL_MODE_NUMERICAL :
            #print 'destroy numerical panel'   
        if self.modelistpanel:
            self.modelistpanel.Destroy()      
             
    def UpdateTime(self,event):
        self.statusbar.SetStatusText(datetime.now().strftime("%d-%m-%Y %H:%M:%S"),1)
    
    def ToggleStatusBar(self, e):
        
        if self.shst.IsChecked():
            self.statusbar.Show()
        else:
            self.statusbar.Hide()
           
    def OnQuit(self, e):
        self.Close()
 
 
    def __del__(self):
        pass