def loadListOfIncidents_controller(self): (error, list) = self.app.Incident.read_all() if error: msg= "Error reading the list of Detrimental Events: \n" + list wx.MessageBox(msg) else: #Create a list of incidents with the countermeasures assigned to it # The Incident.read_all() method will return a list of tuples. Each tuple has the following values: # (idIncident, Name, Description, Risk_Level) #Clear the Filter text self.txtFilter.SetValue("") countermeasure = Countermeasure() IncHasCou = IncidentHasCountermeasure() inc_list = [] for inc in list: idInc = inc[0] nameInc = inc[1] descInc = inc[2] riskLevelInc = inc[3] # Select all the countermeasure assigned to the current incident IncHasCou.FK_Incident = idInc (IHC_error, IHC_list) = IncHasCou.readByIncident() if IHC_error: msg= "Error reading the list of Mitigation Actions assigned to the Detrimental Event: \n" + IHC_list wx.MessageBox(msg) self.onExit(True) else: couNameList = [] #list to save the names of the countermeasures assigned to the Incident # The IncHasCou.readByIncident() method returns a list of tuples with the Countermeasures ID # assigned to the current Incident for IHC in IHC_list: # For each Countermeasure assigned to the Incident, read its values countermeasure.id = IHC[0] (cou_error, cou_value) = countermeasure.read() if cou_error: msg= "Error reading the values of the Mitigation Action assigned to the Detrimental Event: \n" + cou_value wx.MessageBox(msg) self.onExit(True) else: # Add the name of the countermeasure to the list of the countermeasures assigned to the incident couNameList.append(cou_value[0][1]) #Risk Level's Full Description if inc[3] == 'L': riskLevelInc = "Low" elif inc[3] == 'M': riskLevelInc = "Medium" elif inc[3] == 'H': riskLevelInc = "High" inc_list.append([idInc, nameInc, descInc, riskLevelInc, ','.join(couNameList)]) self.GUIincidents = inc_list self.incident_view.loadListOfIncidents(inc_list)
def __init__(self, app, parent): self.app = app self.IncidentView = parent self.incCou_view = IncidentCountermeasureEditorView(self.IncidentView.frame, self.app) #When Close the window destroy the wx instance self.incCou_view.Dialog.Bind(wx.EVT_CLOSE, self.onCancel) #Load the buttons of the view self.btnOK = xrc.XRCCTRL(self.incCou_view.Dialog, 'incCou_btnok') btnCancel = xrc.XRCCTRL(self.incCou_view.Dialog, 'incCou_btncancel') #Bind events to the buttons self.incCou_view.Dialog.Bind(wx.EVT_BUTTON, self.onAssignIncidentCountermeasure, self.btnOK) self.incCou_view.Dialog.Bind(wx.EVT_BUTTON, self.onCancel, btnCancel) #Bind Events to the items in the ToolBar self.incCou_view.Dialog.Bind(wx.EVT_TOOL, self.onDelete, id=xrc.XRCID('incCou_tooldelete')) #Subscribe to the messages given by the model. In case of any change, # the list of elements will be updated in the GUI Publisher.subscribe(self.incCouModified, 'IncidentHasCountermeasure_created') Publisher.subscribe(self.incCouModified, 'IncidentHasCountermeasure_deleted') #ID of the Incident selected self.idIncident = self.IncidentView.getIDItemSelected() #Instance of the Countermeasure and IncidentHasCountermeasure model self.IncHasCou = IncidentHasCountermeasure() self.countermeasure = Countermeasure() #Filters self.GUIcountermeasures = [] self.GUIinc_countermeasures = [] self.txtFilter1 = xrc.XRCCTRL(self.incCou_view.Dialog, 'incCou_txtfilter1') self.btnFilter1 = xrc.XRCCTRL(self.incCou_view.Dialog, 'incCou_btnfilter1') self.txtFilter2 = xrc.XRCCTRL(self.incCou_view.Dialog, 'incCou_txtfilter2') self.btnFilter2 = xrc.XRCCTRL(self.incCou_view.Dialog, 'incCou_btnfilter2') self.incCou_view.Dialog.Bind(wx.EVT_BUTTON, self.onFilter1, self.btnFilter1) self.incCou_view.Dialog.Bind(wx.EVT_TEXT_ENTER, self.onFilter1, self.txtFilter1) self.incCou_view.Dialog.Bind(wx.EVT_BUTTON, self.onFilter2, self.btnFilter2) self.incCou_view.Dialog.Bind(wx.EVT_TEXT_ENTER, self.onFilter2, self.txtFilter2) #Load the list of all available countermeasures and countermeasures of the selected incident in the view self.loadListOfCountermeasures() self.loadListOfIncCou() #Display the view self.incCou_view.Show()
def onClickCountermeasures(self, evt): #Check if the frame was already created frame = self.main_frame.FindWindowByName("CountermeasureFrame") if not frame: self.Countermeasure = Countermeasure() self.CountermeasureController = CountermeasureController(self) else: frame.Raise() return
def loadListOfEquipments_controller(self): (error, list) = self.app.Equipment.read_all() if error: msg = "Error reading the list of PEPs: \n" + list wx.MessageBox(msg) else: #Create a list of equipments with the countermeasures assigned to it # The Equipment.read_all() method will return a list of tuples. Each tuple has the following values: # (idEquipment, Name, Type, IDRef) #Clear the Filter text self.txtFilter.SetValue("") countermeasure = Countermeasure() equ_list = [] for equ in list: idEqu = equ[0] nameEqu = equ[1] descEqu = equ[2] # Select all the countermeasure assigned to the current equipment countermeasure.FK_Equipment = idEqu (cou_error, cou_list) = countermeasure.readByEquipment() if cou_error: msg = "Error reading the list of Mitigation Actions: \n" + cou_list wx.MessageBox(msg) self.onCancel() else: # The countermeasure.readByEquipment() method will return a list of tuples. Each tuple has the following values: # (idCountermeasure, Name, Description, Totally_Restrictive, FK_Equipment) nameList = [] for cou in cou_list: nameList.append(cou[1]) equ_list.append( [idEqu, nameEqu, descEqu, ','.join(nameList)]) self.GUIequipments = equ_list self.equipment_view.loadListOfEquipments(equ_list)
class IncidentCountermeasureEditorController: def __init__(self, app, parent): self.app = app self.IncidentView = parent self.incCou_view = IncidentCountermeasureEditorView(self.IncidentView.frame, self.app) #When Close the window destroy the wx instance self.incCou_view.Dialog.Bind(wx.EVT_CLOSE, self.onCancel) #Load the buttons of the view self.btnOK = xrc.XRCCTRL(self.incCou_view.Dialog, 'incCou_btnok') btnCancel = xrc.XRCCTRL(self.incCou_view.Dialog, 'incCou_btncancel') #Bind events to the buttons self.incCou_view.Dialog.Bind(wx.EVT_BUTTON, self.onAssignIncidentCountermeasure, self.btnOK) self.incCou_view.Dialog.Bind(wx.EVT_BUTTON, self.onCancel, btnCancel) #Bind Events to the items in the ToolBar self.incCou_view.Dialog.Bind(wx.EVT_TOOL, self.onDelete, id=xrc.XRCID('incCou_tooldelete')) #Subscribe to the messages given by the model. In case of any change, # the list of elements will be updated in the GUI Publisher.subscribe(self.incCouModified, 'IncidentHasCountermeasure_created') Publisher.subscribe(self.incCouModified, 'IncidentHasCountermeasure_deleted') #ID of the Incident selected self.idIncident = self.IncidentView.getIDItemSelected() #Instance of the Countermeasure and IncidentHasCountermeasure model self.IncHasCou = IncidentHasCountermeasure() self.countermeasure = Countermeasure() #Filters self.GUIcountermeasures = [] self.GUIinc_countermeasures = [] self.txtFilter1 = xrc.XRCCTRL(self.incCou_view.Dialog, 'incCou_txtfilter1') self.btnFilter1 = xrc.XRCCTRL(self.incCou_view.Dialog, 'incCou_btnfilter1') self.txtFilter2 = xrc.XRCCTRL(self.incCou_view.Dialog, 'incCou_txtfilter2') self.btnFilter2 = xrc.XRCCTRL(self.incCou_view.Dialog, 'incCou_btnfilter2') self.incCou_view.Dialog.Bind(wx.EVT_BUTTON, self.onFilter1, self.btnFilter1) self.incCou_view.Dialog.Bind(wx.EVT_TEXT_ENTER, self.onFilter1, self.txtFilter1) self.incCou_view.Dialog.Bind(wx.EVT_BUTTON, self.onFilter2, self.btnFilter2) self.incCou_view.Dialog.Bind(wx.EVT_TEXT_ENTER, self.onFilter2, self.txtFilter2) #Load the list of all available countermeasures and countermeasures of the selected incident in the view self.loadListOfCountermeasures() self.loadListOfIncCou() #Display the view self.incCou_view.Show() #------------------------------------------------------------------------------------------------------- def incCouModified(self, msg): self.loadListOfCountermeasures() self.loadListOfIncCou() #------------------------------------------------------------------------------------------------------- def loadListOfCountermeasures(self): (error, list) = self.countermeasure.read_all() if error: msg= "Error reading the list of Mitigation Actions: \n" + list wx.MessageBox(msg) self.onCancel(True) else: self.IncHasCou.FK_Incident = self.idIncident (IHC_error, IHC_list) = self.IncHasCou.readByIncident() #IncHasCou.readByIncident() will return a list of all the Countermeasures assigned to a given Incident if IHC_error: msg= "Error reading the list of Mitigation Actions assigned to the Detrimental Event: \n" + list wx.MessageBox(msg) self.onCancel(True) else: cou_list = [] IHC = [] #Convert the returned sequence of sequences from IncHasCou.readByIncident() into a single list of #countermeasures IDs for ihc in IHC_list: IHC.append(ihc[0]) for cou in list: # The countermeasure.read_all() method will return a list of tuples. Each tuple has the following values: # (idCountermeasure, Name, Description, Totally_Restrictive, FK_Equipment) if not cou[0] in IHC: #Exclude from the list the countermeasures already assigned to an incident cou_list.append(cou) self.GUIcountermeasures = cou_list self.incCou_view.loadListOfCountermeasures(cou_list) #------------------------------------------------------------------------------------------------------- def loadListOfIncCou(self): (error, list) = self.countermeasure.read_all() if error: msg= "Error reading the list of Mitigation Actions: \n" + list wx.MessageBox(msg) self.onCancel() else: self.IncHasCou.FK_Incident = self.idIncident (IHC_error, IHC_list) = self.IncHasCou.readByIncident() #IncHasCou.readByIncident() will return a list of all the Countermeasures assigned to a given Incident if IHC_error: msg= "Error reading the list of Mitigation Actions assigned to the Detrimental Event: \n" + IHC_list wx.MessageBox(msg) self.onCancel(True) else: cou_list = [] IHC = [] #Convert the returned sequence of sequences from IncHasCou.readByIncident() into a single list of #countermeasures IDs for ihc in IHC_list: IHC.append(ihc[0]) for cou in list: # The countermeasure.read_all() method will return a list of tuples. Each tuple has the following values: # (idCountermeasure, Name, Description, Totally_Restrictive, FK_Equipment) if cou[0] in IHC: #Exclude from the list the countermeasures not assigned to the current incident cou_list.append(cou) self.GUIinc_countermeasures = cou_list self.incCou_view.loadListOfIncCou(cou_list) return #------------------------------------------------------------------------------------------------------- def onFilter1(self,event): new_list = [] string = self.txtFilter1.GetValue().upper() if string !="": for item in self.GUIcountermeasures: for sub_item in item: if type(sub_item) is str: if any([string in sub_item.upper()]): new_list.append(item) break self.incCou_view.loadListOfCountermeasures(new_list) else: self.incCou_view.loadListOfCountermeasures(self.GUIcountermeasures) #------------------------------------------------------------------------------------------------------- def onFilter2(self,event): new_list = [] string = self.txtFilter2.GetValue().upper() if string !="": for item in self.GUIinc_countermeasures: for sub_item in item: if type(sub_item) is str: if any([string in sub_item.upper()]): new_list.append(item) break self.incCou_view.loadListOfIncCou(new_list) else: self.incCou_view.loadListOfIncCou(self.GUIinc_countermeasures) #------------------------------------------------------------------------------------------------------- def onAssignIncidentCountermeasure(self, evt): #Check if there is selected any item in the countermeasure list count = self.incCou_view.getItemCount(self.incCou_view.countermeasureList) if (count == 0): wx.MessageBox("Please select a Mitigation Action to be assigned to the Detrimental Event!") elif (count > 1): wx.MessageBox("Please select just one Mitigation Action be assigned to the Detrimental Event!") else: #Grab the id of the selected Countermeasure idCountermeasure = self.incCou_view.getIDItemSelected(self.incCou_view.countermeasureList) self.IncHasCou.FK_Countermeasure = idCountermeasure self.IncHasCou.FK_Incident = self.idIncident #Check if the Incident is already assigned to the Countermeasure (error_read, value_read) = self.IncHasCou.read() if error_read: msg= "Error reading the Mitigation Actions assigned to the Detrimental Event: \n" + value_read wx.MessageBox(msg) self.onCancel(True) else: if not value_read: #The Countermeasure is not assigned to the Incident error = self.IncHasCou.create() if error: msg= "Error assigning the Mitigation Action to the Detrimental Event: \n" + value_read wx.MessageBox(msg) self.onCancel(True) else: msg= "The Mitigation Action has already been assigned to the Detrimental Event!" wx.MessageBox(msg) return #------------------------------------------------------------------------------------------------------- def onDelete(self, evt): count = self.incCou_view.getItemCount(self.incCou_view.incCouList) if (count == 0): wx.MessageBox("Please select a Mitigation Action assigned to the Detrimental Event to be deleted!") else: msg = "Proceed to delete "+str(count)+" elements?" del_confirm = wx.MessageDialog(None, msg, 'Delete Confirmation', wx.YES_NO | wx.ICON_QUESTION) if del_confirm.ShowModal() == wx.ID_NO: return item_list = self.incCou_view.getSetItemsSelected(self.incCou_view.incCouList) for id_cou in item_list: self.IncHasCou.FK_Countermeasure = id_cou self.IncHasCou.FK_Incident = self.idIncident (error, values) = self.IncHasCou.delete() if error: msg= "There was an error deleting the Mitigation Actions assigned to the Detrimental Event: \n" + values wx.MessageBox(msg) self.onCancel(True) return #------------------------------------------------------------------------------------------------------- def onCancel(self,evt): self.incCou_view.Dialog.Destroy()
def __init__(self, app, parent): self.app = app self.CountermeasureView = parent self.restriction_view = RestrictionView(self.CountermeasureView.frame, self.app) #When Close the window destroy the wx instance self.restriction_view.Dialog.Bind(wx.EVT_CLOSE, self.onCancel) #Load the buttons of the view self.btnOK = xrc.XRCCTRL(self.restriction_view.Dialog, 'restriction_btnok') btnCancel = xrc.XRCCTRL(self.restriction_view.Dialog, 'restriction_btncancel') #Bind events to the buttons self.restriction_view.Dialog.Bind( wx.EVT_BUTTON, self.onAssignCountermeasureRestriction, self.btnOK) self.restriction_view.Dialog.Bind(wx.EVT_BUTTON, self.onCancel, btnCancel) #Bind Events to the items in the ToolBar self.restriction_view.Dialog.Bind( wx.EVT_TOOL, self.onDelete, id=xrc.XRCID('restriction_tooldelete')) #Subscribe to the messages given by the model. In case of any change, the list of elements will be updated Publisher.subscribe(self.restrictionModified, 'restriction_created') Publisher.subscribe(self.restrictionModified, 'restriction_updated') Publisher.subscribe(self.restrictionModified, 'restriction_deleted') #ID of the Countermeasure selected self.idCountermeasure = self.CountermeasureView.getIDItemSelected() #Instance of the Restriction, Countermeasure model self.restriction = Restriction() self.countermeasure = Countermeasure() #Filters self.GUIcountermeasures = [] self.GUIrestrictions = [] self.txtFilter1 = xrc.XRCCTRL(self.restriction_view.Dialog, 'restriction_txtfilter1') self.btnFilter1 = xrc.XRCCTRL(self.restriction_view.Dialog, 'restriction_btnfilter1') self.txtFilter2 = xrc.XRCCTRL(self.restriction_view.Dialog, 'restriction_txtfilter2') self.btnFilter2 = xrc.XRCCTRL(self.restriction_view.Dialog, 'restriction_btnfilter2') self.restriction_view.Dialog.Bind(wx.EVT_BUTTON, self.onFilter1, self.btnFilter1) self.restriction_view.Dialog.Bind(wx.EVT_TEXT_ENTER, self.onFilter1, self.txtFilter1) self.restriction_view.Dialog.Bind(wx.EVT_BUTTON, self.onFilter2, self.btnFilter2) self.restriction_view.Dialog.Bind(wx.EVT_TEXT_ENTER, self.onFilter2, self.txtFilter2) #Load the list of countermeasures and restrictions of the selected countermeasure in the view self.loadListOfCountermeasures() self.loadListOfRestrictions() #Display the view self.restriction_view.Show()
class RestrictionController: def __init__(self, app, parent): self.app = app self.CountermeasureView = parent self.restriction_view = RestrictionView(self.CountermeasureView.frame, self.app) #When Close the window destroy the wx instance self.restriction_view.Dialog.Bind(wx.EVT_CLOSE, self.onCancel) #Load the buttons of the view self.btnOK = xrc.XRCCTRL(self.restriction_view.Dialog, 'restriction_btnok') btnCancel = xrc.XRCCTRL(self.restriction_view.Dialog, 'restriction_btncancel') #Bind events to the buttons self.restriction_view.Dialog.Bind( wx.EVT_BUTTON, self.onAssignCountermeasureRestriction, self.btnOK) self.restriction_view.Dialog.Bind(wx.EVT_BUTTON, self.onCancel, btnCancel) #Bind Events to the items in the ToolBar self.restriction_view.Dialog.Bind( wx.EVT_TOOL, self.onDelete, id=xrc.XRCID('restriction_tooldelete')) #Subscribe to the messages given by the model. In case of any change, the list of elements will be updated Publisher.subscribe(self.restrictionModified, 'restriction_created') Publisher.subscribe(self.restrictionModified, 'restriction_updated') Publisher.subscribe(self.restrictionModified, 'restriction_deleted') #ID of the Countermeasure selected self.idCountermeasure = self.CountermeasureView.getIDItemSelected() #Instance of the Restriction, Countermeasure model self.restriction = Restriction() self.countermeasure = Countermeasure() #Filters self.GUIcountermeasures = [] self.GUIrestrictions = [] self.txtFilter1 = xrc.XRCCTRL(self.restriction_view.Dialog, 'restriction_txtfilter1') self.btnFilter1 = xrc.XRCCTRL(self.restriction_view.Dialog, 'restriction_btnfilter1') self.txtFilter2 = xrc.XRCCTRL(self.restriction_view.Dialog, 'restriction_txtfilter2') self.btnFilter2 = xrc.XRCCTRL(self.restriction_view.Dialog, 'restriction_btnfilter2') self.restriction_view.Dialog.Bind(wx.EVT_BUTTON, self.onFilter1, self.btnFilter1) self.restriction_view.Dialog.Bind(wx.EVT_TEXT_ENTER, self.onFilter1, self.txtFilter1) self.restriction_view.Dialog.Bind(wx.EVT_BUTTON, self.onFilter2, self.btnFilter2) self.restriction_view.Dialog.Bind(wx.EVT_TEXT_ENTER, self.onFilter2, self.txtFilter2) #Load the list of countermeasures and restrictions of the selected countermeasure in the view self.loadListOfCountermeasures() self.loadListOfRestrictions() #Display the view self.restriction_view.Show() #------------------------------------------------------------------------------------------------------- def restrictionModified(self, msg): self.loadListOfRestrictions() #------------------------------------------------------------------------------------------------------- def loadListOfCountermeasures(self): (error, list) = self.countermeasure.read_all() if error: msg = "Error reading the list of Mitigation Actions: \n" + list wx.MessageBox(msg) self.onCancel() else: # The countermeasure.read_all() method will return a list of tuples. Each tuple has the following values: # (idCountermeasure, Name, Description, Totally_Restrictive) #Exclude from the returned list the current countermeasure cou_list = [] for cou in list: if cou[0] != self.idCountermeasure: cou_list.append(cou) self.GUIcountermeasures = cou_list self.restriction_view.loadListOfCountermeasures(cou_list) #------------------------------------------------------------------------------------------------------- def loadListOfRestrictions(self): self.restriction.FK_Countermeasure = self.idCountermeasure (error, list) = self.restriction.read_by_countermeasure() if error: msg = "Error reading the list of Restrictions of the Mitigation Action: \n" + list wx.MessageBox(msg) self.onCancel(True) else: # The restriction.read_by_countermeasure() method will return a list of tuples. Each tuple has the following values: # (idRestriction, Restriction, FK_Countermeasure) # The GUI should display the information related to the restricted countermeasures, such as name and description: # not only the ids. It's necessary to create a list with the right values res_list = [] for res in list: idRestriction = res[0] #Read the name and description values of the restriction: self.countermeasure.id = res[ 1] #res[1] is the id of the countermeasure that will have a conflict (error, value) = self.countermeasure.read() # The countermeasure.read() method will return a tuple with following values: # (idCountermeasure, Name, Description, Totally_Restrictive) if error: msg = "Error reading the list of Mitigation Actions: \n" + list wx.MessageBox(msg) self.onCancel(True) else: res_name = value[0][1] res_desc = value[0][2] # Append the values to the list to be displayed on the GUI res_list.append([idRestriction, res_name, res_desc]) self.GUIrestrictions = res_list self.restriction_view.loadListOfRestrictions(res_list) return #------------------------------------------------------------------------------------------------------- def onFilter1(self, event): new_list = [] string = self.txtFilter1.GetValue().upper() if string != "": for item in self.GUIcountermeasures: for sub_item in item: if type(sub_item) is str: if any([string in sub_item.upper()]): new_list.append(item) break self.restriction_view.loadListOfCountermeasures(new_list) else: self.restriction_view.loadListOfCountermeasures( self.GUIcountermeasures) #------------------------------------------------------------------------------------------------------- def onFilter2(self, event): new_list = [] string = self.txtFilter2.GetValue().upper() if string != "": for item in self.GUIrestrictions: for sub_item in item: if type(sub_item) is str: if any([string in sub_item.upper()]): new_list.append(item) break self.restriction_view.loadListOfRestrictions(new_list) else: self.restriction_view.loadListOfRestrictions(self.GUIrestrictions) #------------------------------------------------------------------------------------------------------- def onAssignCountermeasureRestriction(self, evt): #Check if there is selected any item in the countermeasure list count = self.restriction_view.getItemCount( self.restriction_view.countermeasureList) if (count == 0): wx.MessageBox( "Please select a Mitigation Action to assign a Restriction!") elif (count > 1): wx.MessageBox( "Please select just one Mitigation Action to assign a Restriction!" ) else: #Grab the id of the selected Countermeasure idRestriction = self.restriction_view.getIDItemSelected( self.restriction_view.countermeasureList) self.restriction.Restriction = idRestriction self.restriction.FK_Countermeasure = self.idCountermeasure #Check if the Restriction is already assigned to the Countermeasure (error, value) = self.restriction.read_by_restriction_countermeasure() if error: msg = "Error reading the Restriction value of the Mitigation Action: \n" + value wx.MessageBox(msg) self.onCancel(True) else: if not value: self.restriction.create() else: wx.MessageBox( "Restriction already assigned to the Mitigation Action!" ) return #------------------------------------------------------------------------------------------------------- def onDelete(self, evt): count = self.restriction_view.getItemCount( self.restriction_view.restrictionList) if (count == 0): wx.MessageBox( "Please select a Restriction in the list to be deleted!") else: msg = "Proceed to delete " + str(count) + " elements?" del_confirm = wx.MessageDialog(None, msg, 'Delete Confirmation', wx.YES_NO | wx.ICON_QUESTION) if del_confirm.ShowModal() == wx.ID_NO: return item_list = self.restriction_view.getSetItemsSelected( self.restriction_view.restrictionList) for id_restriction in item_list: self.restriction.id = id_restriction (error, values) = self.restriction.delete() if error: msg = "There was an error deleting the restriction of the Mitigation Action: \n" + values wx.MessageBox(msg) self.onCancel(True) return #------------------------------------------------------------------------------------------------------- def onCancel(self, evt): self.restriction_view.Dialog.Destroy()
class EquipmentCountermeasureEditorController: def __init__(self, app, parent): self.app = app self.EquipmentView = parent self.equCou_view = EquipmentCountermeasureEditorView( self.EquipmentView.frame, self.app) #When Close the window destroy the wx instance self.equCou_view.Dialog.Bind(wx.EVT_CLOSE, self.onCancel) #Load the buttons of the view self.btnOK = xrc.XRCCTRL(self.equCou_view.Dialog, 'equCou_btnok') btnCancel = xrc.XRCCTRL(self.equCou_view.Dialog, 'equCou_btncancel') #Bind events to the buttons self.equCou_view.Dialog.Bind(wx.EVT_BUTTON, self.onAssignEquipmentCountermeasure, self.btnOK) self.equCou_view.Dialog.Bind(wx.EVT_BUTTON, self.onCancel, btnCancel) #Bind Events to the items in the ToolBar self.equCou_view.Dialog.Bind(wx.EVT_TOOL, self.onDelete, id=xrc.XRCID('equCou_tooldelete')) #Subscribe to the messages given by the model. In case of any change, # the list of elements will be updated in the GUI Publisher.subscribe(self.equCouModified, 'countermeasure_equipment_added') Publisher.subscribe(self.equCouModified, 'countermeasure_equipment_removed') #ID of the Equipment selected self.idEquipment = self.EquipmentView.getIDItemSelected() #Instance of the Countermeasure model #self.restriction = Restriction() self.countermeasure = Countermeasure() #Filters self.GUIcountermeasures = [] self.GUIequ_countermeasures = [] self.txtFilter1 = xrc.XRCCTRL(self.equCou_view.Dialog, 'equCou_txtfilter1') self.btnFilter1 = xrc.XRCCTRL(self.equCou_view.Dialog, 'equCou_btnfilter1') self.txtFilter2 = xrc.XRCCTRL(self.equCou_view.Dialog, 'equCou_txtfilter2') self.btnFilter2 = xrc.XRCCTRL(self.equCou_view.Dialog, 'equCou_btnfilter2') self.equCou_view.Dialog.Bind(wx.EVT_BUTTON, self.onFilter1, self.btnFilter1) self.equCou_view.Dialog.Bind(wx.EVT_TEXT_ENTER, self.onFilter1, self.txtFilter1) self.equCou_view.Dialog.Bind(wx.EVT_BUTTON, self.onFilter2, self.btnFilter2) self.equCou_view.Dialog.Bind(wx.EVT_TEXT_ENTER, self.onFilter2, self.txtFilter2) #Load the list of all available countermeasures and countermeasures of the selected equipment in the view self.loadListOfCountermeasures() self.loadListOfEquCou() #Display the view self.equCou_view.Show() return #------------------------------------------------------------------------------------------------------- def equCouModified(self, msg): self.loadListOfCountermeasures() self.loadListOfEquCou() return #------------------------------------------------------------------------------------------------------- def loadListOfCountermeasures(self): (error, list) = self.countermeasure.read_all() if error: msg = "Error reading the list of Mitigation Actions: \n" + list wx.MessageBox(msg) self.onCancel() else: # The countermeasure.read_all() method will return a list of tuples. Each tuple has the following values: # (idCountermeasure, Name, Description, Totally_Restrictive, FK_Equipment) #Exclude from the returned list the countermeasures already assigned to an equipment (FK_Equipment != Null) cou_list = [] for cou in list: if not cou[4]: cou_list.append(cou) self.GUIcountermeasures = cou_list self.equCou_view.loadListOfCountermeasures(cou_list) return #------------------------------------------------------------------------------------------------------- def loadListOfEquCou(self): (error, list) = self.countermeasure.read_all() if error: msg = "Error reading the list of Mitigation Actions: \n" + list wx.MessageBox(msg) self.onCancel() else: # The countermeasure.read_all() method will return a list of tuples. Each tuple has the following values: # (idCountermeasure, Name, Description, Totally_Restrictive, FK_Equipment) #Exclude from the returned list the countermeasures that aren't assigned to the # current equipment (FK_Equipment == idEquipment) cou_list = [] for cou in list: if cou[4] == self.idEquipment: cou_list.append(cou) self.GUIequ_countermeasures = cou_list self.equCou_view.loadListOfEquCou(cou_list) return #------------------------------------------------------------------------------------------------------- def onFilter1(self, event): new_list = [] string = self.txtFilter1.GetValue().upper() if string != "": for item in self.GUIcountermeasures: for sub_item in item: if type(sub_item) is str: if any([string in sub_item.upper()]): new_list.append(item) break self.equCou_view.loadListOfCountermeasures(new_list) else: self.equCou_view.loadListOfCountermeasures(self.GUIcountermeasures) return #------------------------------------------------------------------------------------------------------- def onFilter2(self, event): new_list = [] string = self.txtFilter2.GetValue().upper() if string != "": for item in self.GUIequ_countermeasures: for sub_item in item: if type(sub_item) is str: if any([string in sub_item.upper()]): new_list.append(item) break self.equCou_view.loadListOfEquCou(new_list) else: self.equCou_view.loadListOfEquCou(self.GUIequ_countermeasures) return #------------------------------------------------------------------------------------------------------- def onAssignEquipmentCountermeasure(self, evt): #Check if there is selected any item in the countermeasure list count = self.equCou_view.getItemCount( self.equCou_view.countermeasureList) if (count == 0): wx.MessageBox( "Please select a Mitigation Action to be assigned to the PEP!") elif (count > 1): wx.MessageBox( "Please select just one Mitigation Action be assigned to the PEP!" ) else: #Grab the id of the selected Countermeasure idCountermeasure = self.equCou_view.getIDItemSelected( self.equCou_view.countermeasureList) self.countermeasure.id = idCountermeasure self.countermeasure.FK_Equipment = self.idEquipment (error, value) = self.countermeasure.assignEquipment() if error: msg = "Error updating the PEP value of the Mitigation Action: \n" + value wx.MessageBox(msg) self.onCancel(True) Publisher.sendMessage("equipment_updated", None) return #------------------------------------------------------------------------------------------------------- def onDelete(self, evt): count = self.equCou_view.getItemCount(self.equCou_view.equCouList) if (count == 0): wx.MessageBox( "Please select a Mitigation Action assigned to the PEP to be deleted!" ) else: msg = "Proceed to delete " + str(count) + " elements?" del_confirm = wx.MessageDialog(None, msg, 'Delete Confirmation', wx.YES_NO | wx.ICON_QUESTION) if del_confirm.ShowModal() == wx.ID_NO: return item_list = self.equCou_view.getSetItemsSelected( self.equCou_view.equCouList) for id_cou in item_list: self.countermeasure.id = id_cou self.countermeasure.FK_Equipment = self.idEquipment (error, values) = self.countermeasure.removeEquipment() if error: msg = "There was an error deleting the Mitigation Actions assigned to the PEP: \n" + values wx.MessageBox(msg) self.onCancel(True) Publisher.sendMessage("equipment_updated", None) return #------------------------------------------------------------------------------------------------------- def onCancel(self, evt): self.equCou_view.Dialog.Destroy() return