lpcmanager

LPCCommand : switch to wx.Timer instead of regular python timer for the rapidfire protection. With regular python timers, some refresh order could pile eventloop when interacting with the GUI while doing initial loading of signals.
# -*- coding: utf-8 -*-
#This file is part of Beremiz, a Integrated Development Environment for
#programming IEC 61131-3 automates supporting plcopen standard and CanFestival.
#
#Copyright (C) 2015 : Yvan ROCH
#
#See COPYING file for copyrights details.
#
#This library is free software; you can redistribute it and/or
#modify it under the terms of the GNU General Public
#License as published by the Free Software Foundation; either
#version 2.1 of the License, or (at your option) any later version.
#
#This library is distributed in the hope that it will be useful,
#but WITHOUT ANY WARRANTY; without even the implied warranty of
#MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
#General Public License for more details.
#
#You should have received a copy of the GNU General Public
#License along with this library; if not, write to the Free Software
#Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
import wx
from os.path import expanduser
class FirmwareUpdateDialog(wx.Dialog):
"""
This class is the dialog for firmware update parameters selection
"""
def __init__(self, parent):
wx.Dialog.__init__(self, parent=parent, title=_('Firmware Update'))
# Widgets for the update image file selection
self.TextCtrltFirmwareUpdateImageFile = wx.TextCtrl(self)
self.ButtonFirmwareUpdateImageFile = wx.Button(label=_('Add image file'), parent=self)
self.Bind(wx.EVT_BUTTON, self.OnButtonFirmwareUpdateImageFile, id=self.ButtonFirmwareUpdateImageFile.GetId())
# Widgets for the chunks size
self.SpinCtrlFirmwareUpdateChunksSize = wx.SpinCtrl(parent=self)
self.SpinCtrlFirmwareUpdateChunksSize.SetRange(1, 1024)
self.SpinCtrlFirmwareUpdateChunksSize.SetValue(256)
# Widgets for validation
self.ButtonSizer = self.CreateButtonSizer(wx.OK|wx.CANCEL)
# Sizers
self.SizerFirmwareUpdateImageFile = wx.FlexGridSizer(cols=2, rows=1)
self.SizerFirmwareUpdateImageFile.AddGrowableCol(0)
self.SizerFirmwareUpdateImageFile.AddGrowableRow(0)
self.SizerFirmwareUpdateImageFile.Add(self.TextCtrltFirmwareUpdateImageFile,
flag=wx.LEFT|wx.EXPAND)
self.SizerFirmwareUpdateImageFile.Add(self.ButtonFirmwareUpdateImageFile,
flag=wx.RIGHT|wx.ALIGN_RIGHT)
self.SizerFirmwareUpdateImageFileBoxSizer = wx.StaticBoxSizer(wx.StaticBox(self, label=_('Update image file:')), wx.VERTICAL)
self.SizerFirmwareUpdateImageFileBoxSizer.AddSizer(self.SizerFirmwareUpdateImageFile, flag=wx.EXPAND)
self.RadioBoxFirmwareUpdateTypeChunks = wx.RadioBox(
self, -1, _('Update type:'), wx.DefaultPosition, wx.DefaultSize,
[_('Linux kernel'), _('Linux DTB'), _('Root file system')],
1, wx.RA_SPECIFY_COLS)
self.RadioBoxFirmwareUpdateTypeChunks.SetSelection(2)
self.SizerFirmwareUpdateSizeChunks = wx.StaticBoxSizer(wx.StaticBox(self, label=_('Chunks size in KiB:')), wx.VERTICAL)
self.SizerFirmwareUpdateSizeChunks.Add(self.SpinCtrlFirmwareUpdateChunksSize,
flag=wx.EXPAND|wx.ALL)
self.SizerFirmwareUpdateChunks = wx.FlexGridSizer(cols=2, rows=1)
self.SizerFirmwareUpdateChunks.AddGrowableCol(0)
self.SizerFirmwareUpdateChunks.AddGrowableCol(1)
self.SizerFirmwareUpdateChunks.Add(self.RadioBoxFirmwareUpdateTypeChunks, flag=wx.EXPAND|wx.RIGHT, border=20)
self.SizerFirmwareUpdateChunks.Add(self.SizerFirmwareUpdateSizeChunks, flag=wx.EXPAND)
self.MainSizer = wx.FlexGridSizer(cols=1, rows=3)
self.MainSizer.AddGrowableCol(0)
self.MainSizer.AddGrowableRow(1)
self.MainSizer.AddSizer(self.SizerFirmwareUpdateImageFileBoxSizer, flag=wx.EXPAND|wx.LEFT|wx.TOP|wx.RIGHT, border=20)
self.MainSizer.AddSizer(self.SizerFirmwareUpdateChunks, flag=wx.EXPAND|wx.LEFT|wx.TOP|wx.RIGHT, border=20)
self.MainSizer.AddSizer(self.ButtonSizer, flag=wx.ALIGN_RIGHT|wx.ALL, border=20)
# Set the main sizer
self.MainSizer.SetSizeHints(self)
self.SetSizer(self.MainSizer)
def OnButtonFirmwareUpdateImageFile(self, event):
dlg = wx.FileDialog(self, _("Choose a firmware image file"), expanduser("~"), "", "*", wx.OPEN)
if dlg.ShowModal() == wx.ID_OK:
path = dlg.GetPath()
self.TextCtrltFirmwareUpdateImageFile.SetValue(path)
dlg.Destroy()
def GetFirmwareImageFile(self):
return self.TextCtrltFirmwareUpdateImageFile.GetValue()
def GetFirmwareUpdateType(self):
res = self.RadioBoxFirmwareUpdateTypeChunks.GetSelection()
if res == wx.NOT_FOUND:
return 0
return res+1
def GetChunksSize(self):
return self.SpinCtrlFirmwareUpdateChunksSize.GetValue()*1024