181 lines
5 KiB
Python
181 lines
5 KiB
Python
#!/usr/bin/env python
|
|
# -*- coding: UTF-8 -*-
|
|
#
|
|
# generated by wxGlade 0.9.5 on Fri Feb 7 20:10:41 2020
|
|
#
|
|
|
|
import wx
|
|
import wx.grid
|
|
|
|
import gettext
|
|
gettext.install(None)
|
|
|
|
from pubsub import pub
|
|
|
|
print('pubsub API version', pub.VERSION_API)
|
|
|
|
from pubsub.utils.notification import useNotifyByWriteFile
|
|
import sys
|
|
|
|
useNotifyByWriteFile(sys.stdout)
|
|
|
|
import pprint
|
|
|
|
from stabiliti import StabilitiController as SC
|
|
from faults import faultInfo
|
|
from FaultView import FaultFrame
|
|
|
|
class Controller:
|
|
def __init__(self, view):
|
|
self.sc = None
|
|
self.view = view
|
|
self.timer = wx.Timer()
|
|
self.timer.Bind(wx.EVT_TIMER, self.OnTimer)
|
|
self.mode = False
|
|
|
|
pub.subscribe(self.getFaultInfo, 'fault_selected')
|
|
pub.subscribe(self.startTimer, 'monitoring_started')
|
|
pub.subscribe(self.stopTimer, 'monitoring_stopped')
|
|
pub.subscribe(self.applyNetworkConfigs, 'apply_network_configs')
|
|
pub.subscribe(self.resetNetworkConfigs, 'reset_network_configs')
|
|
pub.subscribe(self.resetPcsRemote, 'reset_pcs_remote')
|
|
pub.subscribe(self.checkSysOpMode, 'check_system_op_mode')
|
|
|
|
def startTimer(self):
|
|
self.timer.Start(2000)
|
|
|
|
def stopTimer(self):
|
|
self.timer.Stop()
|
|
|
|
def applyNetworkConfigs(self, ncDict):
|
|
if self.sc:
|
|
self.sc.checkClose()
|
|
self.sc = SC(**ncDict)
|
|
|
|
def resetNetworkConfigs(self):
|
|
if self.sc:
|
|
self.sc.checkClose()
|
|
self.sc = None
|
|
|
|
def resetPcsRemote(self):
|
|
if self.sc:
|
|
self.sc.resetPcs()
|
|
|
|
def checkSysOpMode(self):
|
|
if self.sc:
|
|
self.mode = self.sc.checkOpMode()
|
|
a = "Auto" if self.mode else "Manual"
|
|
self.view.text_op_mode.SetValue(a)
|
|
|
|
def getFaultInfo(self, pos):
|
|
y, x = pos
|
|
fid = x + y*8
|
|
if 0 <= fid <= 63:
|
|
try:
|
|
info_text = faultInfo[fid]
|
|
except IndexError:
|
|
info_text = "Fault Number: {} (Reserved)".format(fid)
|
|
self.view.text_fault_doc.SetValue(info_text)
|
|
|
|
status_text = "Not Connected"
|
|
if self.sc:
|
|
fDict = self.sc.readFaultDetail(fid)
|
|
status_text = pprint.pformat(fDict)
|
|
self.view.text_fault_status.SetValue(status_text)
|
|
|
|
def OnTimer(self, event):
|
|
factivity = self.sc.readFaultActivity()
|
|
foccurence = self.sc.readFaultOccurence()
|
|
self.view.SetFaultGrid(factivity, foccurence)
|
|
event.Skip()
|
|
|
|
class MyFrame(FaultFrame):
|
|
def __init__(self, *args, **kwds):
|
|
FaultFrame.__init__(self, *args, **kwds)
|
|
|
|
def OnFaultSelect(self, event): # wxGlade: MyFrame.<event_handler>
|
|
pub.sendMessage("fault_selected", pos=(event.GetRow(), event.GetCol()))
|
|
event.Skip()
|
|
|
|
def SetFaultGrid(self, fActivity, fOccurence):
|
|
if len(fActivity) == len(fOccurence) == 64:
|
|
for i in range(8):
|
|
for j in range(8):
|
|
if fActivity[i*8+j] == '1':
|
|
self.fault_grid.SetCellBackgroundColour(i, j, wx.LIGHT_GREY)
|
|
if fOccurence[i*8+j] == '1':
|
|
self.fault_grid.SetCellValue(i, j, "O")
|
|
|
|
def ToggleMonitoring(self, event): # wxGlade: MyFrame.<event_handler>
|
|
btnLabel = self.button_1.GetLabel()
|
|
if self.button_1.Value:
|
|
pub.sendMessage("monitoring_started")
|
|
self.button_1.SetLabel("Stop")
|
|
else:
|
|
pub.sendMessage("monitoring_stopped")
|
|
self.button_1.SetLabel("Start")
|
|
|
|
if event:
|
|
event.Skip()
|
|
|
|
def OnApply(self, event):
|
|
|
|
if self.button_1.Enabled:
|
|
return
|
|
|
|
self.input_uid.Disable()
|
|
self.input_port.Disable()
|
|
self.input_ip.Disable()
|
|
self.input_refresh.Disable()
|
|
|
|
ncDict = {
|
|
"ipaddr": self.input_ip.GetValue(),
|
|
"port": int(self.input_port.GetValue()),
|
|
"uid": int(self.input_uid.GetValue()),
|
|
}
|
|
|
|
pub.sendMessage("apply_network_configs", ncDict=ncDict)
|
|
|
|
self.button_1.Enable()
|
|
|
|
def OnReset(self, event=None):
|
|
|
|
if not self.button_1.Enabled:
|
|
return
|
|
|
|
pub.sendMessage("reset_network_configs")
|
|
self.button_1.SetValue(False)
|
|
self.ToggleMonitoring(None)
|
|
|
|
self.button_1.Disable()
|
|
|
|
self.input_uid.Enable()
|
|
self.input_port.Enable()
|
|
self.input_ip.Enable()
|
|
self.input_refresh.Enable()
|
|
|
|
def OnButtonRemoteReset(self, event):
|
|
pub.sendMessage("reset_pcs_remote")
|
|
self.OnReset()
|
|
|
|
def OnCheckSysOpMode(self, event):
|
|
pub.sendMessage("check_system_op_mode")
|
|
|
|
# end of class MyFrame
|
|
|
|
class MyApp(wx.App):
|
|
def OnInit(self):
|
|
self.frame = MyFrame(None, wx.ID_ANY, "")
|
|
self.c = Controller(self.frame)
|
|
self.SetTopWindow(self.frame)
|
|
self.frame.Show()
|
|
return True
|
|
|
|
# end of class MyApp
|
|
|
|
if __name__ == "__main__":
|
|
app = MyApp(0)
|
|
app.MainLoop()
|
|
|
|
if app.c.sc:
|
|
app.c.sc.checkClose()
|