예제 #1
0
 def save(self, overwrite=True):
     """Save the fsm being edited by this dialog"""
     if not overwrite:
         cjr.show_information_message(
             "Saving a FSM with another name isn't allowed.\n" \
             "Use the duplicate option in the FSMs library instead."
             )
         return False
     servers.get_fsm_server().savefsm( self.get_fsm() )
     self.get_fsm().setdirty( False )
     self.__update_title()
     return True
예제 #2
0
def get_script_conditions():
    """Return a sequence with all the script conditions paths"""
    # Generate a singleton for each condition class
    classes = servers.get_kernel_server().getsubclasslist('nscriptcondition')
    for class_name in classes:
        servers.get_fsm_server().getscriptcondition( str(class_name) )
    
    paths = []
    conds_path = get_script_conditions_lib()
    cond = pynebula.lookup( conds_path ).gethead()
    while cond != None:
        paths.append( cond.getfullname() )
        cond = cond.getsucc()
    return paths
예제 #3
0
 def _save_fsms(self):
     msg = "Deleting a %s will save any modified finite state machine.\n\n" % self.caption
     msg = msg + "Continue anyway?"
     result = cjr.confirm_yes_no(self, msg)
     delete = (result == wx.ID_YES)
     if delete:
         # Save modified FSMs
         fsm_paths = fsm.get_fsms()
         for fsm_path in fsm_paths:
             sm = pynebula.lookup( fsm_path )
             if sm.isdirty():
                 servers.get_fsm_server().savefsm( sm )
                 sm.setdirty( False )
                 app.get_top_window(self).emit_app_event(
                     events.FSMSaved( fsm_path )
                     )
     return delete
예제 #4
0
def get_root_dir(noh = True):
    """Return the root directory of all fsm related objects"""
    if noh:
        path = "/fsm"
        __safe_new(path)
    else:
        path = servers.get_fsm_server().getstoragepath()
    return path
예제 #5
0
 def __save_fsms(self, caption):
     msg = "Deleting a %s will save any modified " \
                 "finite state machine.\n\n" \
                 "Continue anyway?" % caption
     result = cjr.confirm_yes_no(self, msg)
     delete = (result == wx.ID_YES)
     if delete:
         # Save modified FSMs
         fsm_paths = fsm.get_fsms()
         for fsm_path in fsm_paths:
             state_machine = pynebula.lookup(fsm_path)
             if state_machine.isdirty():
                 servers.get_fsm_server().savefsm(state_machine)
                 state_machine.setdirty(False)
                 app.get_top_window().emit_app_event(
                     events.FSMSaved(fsm_path))
     return delete
예제 #6
0
 def __on_select_script(self, event):
     transition = pynebula.lookup(self.transition_path)
     state_path = fsm.get_state_of_transition(self.transition_path)
     state = pynebula.lookup(state_path)
     state.removetransition(transition)
     condition = servers.get_fsm_server().getscriptcondition(
         str(self.choice_script.GetStringSelection()))
     transition.setcondition(condition)
     state.addtransition(transition)
     fsmevents.signal_fsm_change(self, self.transition_path)
예제 #7
0
 def __on_select_script(self, event):
     transition = pynebula.lookup( self.transition_path )
     state_path = fsm.get_state_of_transition( self.transition_path )
     state = pynebula.lookup( state_path )
     state.removetransition( transition )
     condition = servers.get_fsm_server().getscriptcondition(
         str(self.choice_script.GetStringSelection()) )
     transition.setcondition( condition )
     state.addtransition( transition )
     fsmevents.signal_fsm_change( self, self.transition_path )
예제 #8
0
    def __on_change_name(self, event):
        # Change the FSM file and object names
        fsm = pynebula.lookup( self.fsm_path )
        old_name = str( format.get_name( self.fsm_path ) )
        new_name = str( self.text_name.get_value() )
        fsm.setname( new_name )
        servers.get_fsm_server().savefsm( fsm )
        fsm.setname( old_name )
        servers.get_fsm_server().erasefsm( fsm )
        fsm.setname( new_name )
        # Update the controls
        self.fsm_path = fsm.getfullname()
        self.ctrl_states.set_fsm( self.fsm_path )
        self.ctrl_statetype.set_state(None)
        self.ctrl_transitions.set_state(None)
#        self.ctrl_emotactions.set_state(None)
        # Notify change to update the name in the FSM library
        app.get_top_window(self).emit_app_event( events.FSMNameChanged(
            new_name=new_name, old_name=old_name ) )
        fsmevents.signal_fsm_change( self, fsmevents.ID_FSMNameChanged, self.fsm_path )
예제 #9
0
 def __on_update_condition(self, event):
     # Remove transition from state
     transition = self.__get_transition()
     state_path = fsm.get_state_of_transition(self.transition_path)
     state = pynebula.lookup(state_path)
     state.removetransition(transition)
     # Get old event and filter
     old_cond_obj = transition.getcondition()
     old_event_id = old_cond_obj.getevent()
     old_filter_obj = old_cond_obj.getfiltercondition()
     # Get new event and filter
     #        new_event_name = self.choice_event.GetStringSelection()
     #        new_event_id = servers.get_fsm_server().geteventcondition( str(new_event_name) ).getevent()
     new_event_id = self.event_ids[self.choice_event.GetSelection()]
     new_filter_name = self.choice_filter.GetStringSelection()
     new_filter_obj = None
     if new_filter_name != "<none>":
         new_filter_obj = servers.get_fsm_server().getscriptcondition(
             str(new_filter_name))
     # Act depending on filter condition existance and selection
     local_cond_path = fsm.get_filteredcondition_of_transition(
         self.transition_path)
     if old_filter_obj == None:
         if new_filter_obj == None:
             # Neither the old or the new conditions have a filter
             # Just select a shared condition
             new_cond_obj = get_event_condition(
                 new_event_id
             )  #servers.get_fsm_server().geteventcondition( str(new_event_name) )
         else:
             # The old condition doesn't have a filter, but the new one does
             # Create a local condition, with the same event and new filter
             new_cond_obj = pynebula.new('neventcondition', local_cond_path)
             new_cond_obj.setevent(new_event_id)
             new_cond_obj.setfiltercondition(new_filter_obj)
     else:
         if new_filter_obj == None:
             # The old condition has a filter, but the new one doesn't
             # Remove the local condition and select a shared condition
             old_cond_obj = None
             pynebula.delete(str(local_cond_path))
             new_cond_obj = get_event_condition(
                 new_event_id
             )  #servers.get_fsm_server().geteventcondition( str(new_event_name) )
         else:
             # Both the old and the new conditions have a filter
             # Update the local condition with the new event
             new_cond_obj = old_cond_obj
             new_cond_obj.setevent(new_event_id)
     # Reinsert the transition into the state
     transition.setcondition(new_cond_obj)
     state.addtransition(transition)
     # Signal the change
     fsmevents.signal_fsm_change(self, self.transition_path)
예제 #10
0
 def __on_change_name(self, event):
     # Change the FSM file and object names
     fsm = pynebula.lookup(self.fsm_path)
     old_name = str(format.get_name(self.fsm_path))
     new_name = str(self.text_name.get_value())
     fsm.setname(new_name)
     servers.get_fsm_server().savefsm(fsm)
     fsm.setname(old_name)
     servers.get_fsm_server().erasefsm(fsm)
     fsm.setname(new_name)
     # Update the controls
     self.fsm_path = fsm.getfullname()
     self.ctrl_states.set_fsm(self.fsm_path)
     self.ctrl_statetype.set_state(None)
     self.ctrl_transitions.set_state(None)
     #        self.ctrl_emotactions.set_state(None)
     # Notify change to update the name in the FSM library
     app.get_top_window(self).emit_app_event(
         events.FSMNameChanged(new_name=new_name, old_name=old_name))
     fsmevents.signal_fsm_change(self, fsmevents.ID_FSMNameChanged,
                                 self.fsm_path)
예제 #11
0
def restore():
    """Load the whole FSM library"""
    fs = servers.get_fsm_server()
    fs.loadall()
    
    # Create event conditions for all the new events handled by a FSM
    ts = servers.get_trigger_server()
    for i in range( ts.geteventtypesnumber() ):
        if ts.isafsminevent( i ):
            # This creates the event if it doesn't exist yet
            id_name = ts.geteventpersistentid( i )
#            return
            fs.geteventcondition( str(id_name) )
예제 #12
0
 def erase_object(self, action_script):
     # Forbid deleting the script if some FSM references it
     log = []
     fsm_paths = fsm.get_fsms()
     for fsm_path in fsm_paths:
         self.__find_action( pynebula.lookup(fsm_path), action_script, log )
     if len(log) > 0:
         dlg = DeleteErrorDialog(
             self.GetParent(),
             "action script '%s'" % action_script.getname(),
             ['FSM', 'State'],
             log
             )
         dlg.Show()
         return False
     # Save FSMs to avoid inconsistences between memory and persisted states
     # (and make the previous check valid)
     if not self._save_fsms():
         return
     # Delete the script
     servers.get_fsm_server().eraseactionscript( action_script )
     return True
예제 #13
0
    def __on_update_condition(self, event):
        # Remove transition from state
        transition = self.__get_transition()
        state_path = fsm.get_state_of_transition( self.transition_path )
        state = pynebula.lookup( state_path )
        state.removetransition( transition )
        # Get old event and filter
        old_cond_obj = transition.getcondition()
        old_event_id = old_cond_obj.getevent()
        old_filter_obj = old_cond_obj.getfiltercondition()
        # Get new event and filter
#        new_event_name = self.choice_event.GetStringSelection()
#        new_event_id = servers.get_fsm_server().geteventcondition( str(new_event_name) ).getevent()
        new_event_id = self.event_ids[ self.choice_event.GetSelection() ]
        new_filter_name = self.choice_filter.GetStringSelection()
        new_filter_obj = None
        if new_filter_name != "<none>":
            new_filter_obj = servers.get_fsm_server().getscriptcondition( str(new_filter_name) )
        # Act depending on filter condition existance and selection
        local_cond_path = fsm.get_filteredcondition_of_transition( self.transition_path )
        if old_filter_obj == None:
            if new_filter_obj == None:
                # Neither the old or the new conditions have a filter
                # Just select a shared condition
                new_cond_obj = get_event_condition( new_event_id ) #servers.get_fsm_server().geteventcondition( str(new_event_name) )
            else:
                # The old condition doesn't have a filter, but the new one does
                # Create a local condition, with the same event and new filter
                new_cond_obj = pynebula.new( 'neventcondition', local_cond_path )
                new_cond_obj.setevent( new_event_id )
                new_cond_obj.setfiltercondition( new_filter_obj )
        else:
            if new_filter_obj == None:
                # The old condition has a filter, but the new one doesn't
                # Remove the local condition and select a shared condition
                old_cond_obj = None
                pynebula.delete( str(local_cond_path) )
                new_cond_obj = get_event_condition( new_event_id ) #servers.get_fsm_server().geteventcondition( str(new_event_name) )
            else:
                # Both the old and the new conditions have a filter
                # Update the local condition with the new event
                new_cond_obj = old_cond_obj
                new_cond_obj.setevent( new_event_id )
        # Reinsert the transition into the state
        transition.setcondition( new_cond_obj )
        state.addtransition( transition )
        # Signal the change
        fsmevents.signal_fsm_change( self, self.transition_path )
예제 #14
0
 def erase_object(self, fsm):
     servers.get_fsm_server().erasefsm( fsm )
     return True
예제 #15
0
 def save_object(self, condition):
     servers.get_fsm_server().createconditionscript( condition.getname() )
     servers.get_fsm_server().savescriptcondition( condition )
예제 #16
0
 def save_object(self, selector):
     servers.get_fsm_server().createfsmselectorscript( selector.getname() )
     servers.get_fsm_server().savefsmselector( selector )
예제 #17
0
 def save_object(self, action_script):
     servers.get_fsm_server().createactionscript( action_script.getname() )
     servers.get_fsm_server().saveactionscript( action_script )
예제 #18
0
 def save_object(self, fsm):
     servers.get_fsm_server().savefsm( fsm )
예제 #19
0
 def save(self):
     servers.get_fsm_server().savefsm(self.state_machine)
     self.state_machine.setdirty(False)
     app.get_top_window().emit_app_event(
         events.FSMSaved(self.state_machine.getfullname()))
예제 #20
0
 def save(self):
     servers.get_fsm_server().savefsm( self.state_machine )
     self.state_machine.setdirty( False )
     app.get_top_window().emit_app_event(
         events.FSMSaved( self.state_machine.getfullname() )
         )