Exemplo n.º 1
0
 def removeRulebook(self, rulebook):
     if isinstance(rulebook, Rulebook):
         # if rule in editor window is in this rulebook, clear the editor window
         if self.filename is not None:
             dir, rule = os.path.split(self.filename)
             if rulebook.containsRule(rule):
                 if self.rule.textIsDirty:
                     # First give user a chance to save rule
                     msg = "Closing this rulebook will also close the\ncurrently open rule. Save rule first?"
                     dlg = CougaarMessageDialog(self, "close", msg)
                     disposition = dlg.getUserInput()
                     if disposition == wxID_CANCEL:
                         return
                     elif disposition == wxID_YES:
                         self.save_rule()
                 self.clearRule()
         for rule in rulebook.each_rule():
             item = self.lb.FindString(rule)
             if item >= 0:
                 self.lb.Delete(item)
         self.ruleBooks.remove(rulebook)
         removeRulebook = False
         self.frame.updateCloseRulebookMenuItem(removeRulebook)
     else:  # must be a rulebook name (String)
         aRulebook = self.getRulebook(rulebook)
         if aRulebook is not None:
             self.removeRulebook(aRulebook)
Exemplo n.º 2
0
    def OnDeleteRule(self, event):
        ruleIdToDelete = self.lb.GetSelection()
        if ruleIdToDelete < 0:
            self.log.WriteText("Unable to delete rule: no rule selected\n")
            return
        ruleNameToDelete = self.lb.GetString(ruleIdToDelete)
        rulebook = self.ruleIndex[ruleNameToDelete]  # get this rule's associated rulebook
        msg = """Are you sure you want to delete this rule?
Doing so will permanently delete it from disk."""
        dlg = CougaarMessageDialog(self, "delete", msg)
        response = dlg.getUserInput()
        if response == wxID_YES:
            self.lb.Delete(ruleIdToDelete)  # remove it from the list box
            os.remove(os.path.join(rulebook.getPath(), ruleNameToDelete))  # delete from disk
            self.clearRule()  # clear the rule text
        self.frame.enableRuleMenuItems(False)
        rulebook.removeRule(ruleNameToDelete)
        if rulebook.size() == 0:
            self.removeRulebook(rulebook)
Exemplo n.º 3
0
    def closeSociety(self, societyId):
        societyToClose = None
        currentViewer = None
        saveAgents = True
        if societyId != "agentSociety":
            if societyId == "mappedSociety":
                societyToClose = self.mappedSociety
                currentViewer = self.laydownViewer
            elif societyId == "society":
                societyToClose = self.society
                currentViewer = self.societyViewer
                saveAgents = False
            if societyToClose.isDirty:
                # First give user a chance to save the society
                dlg = CougaarMessageDialog(self, "confirm")
                disposition = dlg.getUserInput()
                if disposition == wxID_CANCEL:
                    return
                if disposition == wxID_YES:
                    self.saveSociety(societyId)

            # Now delete the tree display
            currentViewer.DeleteAllItems()
            # Finally, delete the society object in memory
            if societyToClose is not None:  # shouldn't ever be None...but it sometimes is!
                societyToClose.close(saveAgents)
                societyToClose = None
            if societyId == "mappedSociety":
                self.mappedSociety = None
                self.mappedSocietyOpen = 0
                self.societyHnaFile = None
                self.enableHnaSaveMenuItems(false)
                if not self.agentSocietyOpen:
                    self.editMenu.Enable(AWB.SORT, false)
            elif societyId == "society":
                self.society = None
                self.societyOpen = 0
                self.societyFile = None
                self.ruleEditor.societyName.SetValue("")
                self.nameServer = None
                self.enableSocietySaveMenuItems(false)
                if not self.mappedSocietyOpen:
                    self.editMenu.Enable(AWB.SORT, false)
            elif societyId == "controller":
                print "Controller File"

        else:  # societyId == "agentSociety"
            if self.agentViewer is not None:
                self.agentViewer.DeleteAllItems()  # delete the tree
            if self.agentSociety is not None:  # shouldn't ever be None...but it sometimes is!
                # Delete the society object in memory
                self.agentSociety.close()
                self.agentSociety = None
            self.agentSocietyOpen = 0
            self.agentSocietyFile = None
            if len(self.undoBuffer) > 0:
                self.undoBuffer.pop()  # empty it out
            self.mainmenu.Enable(AWB.UNDO, false)
            self.enableAgentSocietySaveMenuItems(false)
            if not self.mappedSocietyOpen:
                self.editMenu.Enable(AWB.SORT, false)