def buildControls(self,parameters): mainSizer = wx.BoxSizer(wx.VERTICAL) self.panel = AttackerPanel(self) self.panel.buildControls(parameters.createFlag()) mainSizer.Add(self.panel,1,wx.EXPAND) self.SetSizer(mainSizer) wx.EVT_BUTTON(self,ATTACKER_BUTTONCOMMIT_ID,self.onCommit)
class AttackerDialog(wx.Dialog): def __init__(self,parent,parameters): wx.Dialog.__init__(self,parent,parameters.id(),parameters.label(),style=wx.DEFAULT_DIALOG_STYLE|wx.MAXIMIZE_BOX|wx.THICK_FRAME|wx.RESIZE_BORDER,size=(600,600)) self.theAttackerId = -1 self.theAttackerName = '' self.theAttackerDescription = '' self.theAttackerImage = '' self.theTags = [] self.theEnvironmentProperties = [] self.panel = 0 self.buildControls(parameters) self.theCommitVerb = 'Create' def load(self,attacker): self.theAttackerId = attacker.id() imageFile = attacker.image() if ((imageFile != None) and (imageFile != '')): if (os.path.exists(imageFile) == False): attacker.theImage = '' errorText = 'Attacker image ' + imageFile + ' does not exist.' dlg = wx.MessageDialog(self,errorText,'Load Attacker Image',wx.OK | wx.ICON_ERROR) dlg.ShowModal() dlg.Destroy() self.panel.loadControls(attacker) self.theCommitVerb = 'Edit' def buildControls(self,parameters): mainSizer = wx.BoxSizer(wx.VERTICAL) self.panel = AttackerPanel(self) self.panel.buildControls(parameters.createFlag()) mainSizer.Add(self.panel,1,wx.EXPAND) self.SetSizer(mainSizer) wx.EVT_BUTTON(self,ATTACKER_BUTTONCOMMIT_ID,self.onCommit) def onCommit(self,evt): nameCtrl = self.FindWindowById(ATTACKER_TEXTNAME_ID) tagCtrl = self.FindWindowById(ATTACKER_TAGS_ID) descriptionCtrl = self.FindWindowById(ATTACKER_TEXTDESCRIPTION_ID) imageCtrl = self.FindWindowById(ATTACKER_IMAGEATTACKERIMAGE_ID) environmentCtrl = self.FindWindowById(ATTACKER_PANELENVIRONMENT_ID) self.theAttackerName = nameCtrl.GetValue() if (self.theCommitVerb == 'Create'): b = Borg() try: b.dbProxy.nameCheck(self.theAttackerName,'attacker') except ARMException,errorText: dlg = wx.MessageDialog(self,str(errorText),'Add attacker',wx.OK | wx.ICON_ERROR) dlg.ShowModal() dlg.Destroy() return self.theAttackerDescription = descriptionCtrl.GetValue() self.theAttackerImage = imageCtrl.personaImage() self.theTags = tagCtrl.tags() self.theEnvironmentProperties = environmentCtrl.environmentProperties() commitLabel = self.theCommitVerb + ' attacker' if len(self.theAttackerName) == 0: dlg = wx.MessageDialog(self,'Attacker name cannot be empty',commitLabel,wx.OK) dlg.ShowModal() dlg.Destroy() return elif (len(self.theEnvironmentProperties) == 0): dlg = wx.MessageDialog(self,'No environments have been associated with this attacker',commitLabel,wx.OK) dlg.ShowModal() dlg.Destroy() return else: for environmentProperties in self.theEnvironmentProperties: if len(environmentProperties.roles()) == 0: errorTxt = 'No roles associated with environment ' + environmentProperties.name() dlg = wx.MessageDialog(self,errorTxt,commitLabel,wx.OK) dlg.ShowModal() dlg.Destroy() return if len(environmentProperties.motives()) == 0: errorTxt = 'No motives associated with environment ' + environmentProperties.name() dlg = wx.MessageDialog(self,errorTxt,commitLabel,wx.OK) dlg.ShowModal() dlg.Destroy() return if len(environmentProperties.capabilities()) == 0: errorTxt = 'No capabilities associated with environment ' + environmentProperties.name() dlg = wx.MessageDialog(self,errorTxt,commitLabel,wx.OK) dlg.ShowModal() dlg.Destroy() return self.EndModal(ATTACKER_BUTTONCOMMIT_ID)