Пример #1
0
def set_nclass_dirty_flag(is_dirty):
    if is_dirty:
        if not get_nclass_dirty_flag():
            pynebula.new('nroot', '/editor/nclass_dirty')
    else:
        if get_nclass_dirty_flag():
            pynebula.delete('/editor/nclass_dirty')
Пример #2
0
 def on_close_window(self, evt):
     """Takes care to close and persist the application state."""
     result_ok = self.__check_ok_to_exit_application()
     if not result_ok:
         #need to veto the close event, otherwise ingui left inconsistent
         evt.Veto()
         return
     if self.quit_without_saving:
         # Needs to have the focus to exit gracefully
         self.SetFocus()
         try:
             pynebula.delete('/editor/outguiisopened')
         except:
             pass
         evt.Skip()
         return
     dlg = filecmds.SaveAllDialog(self, exiting=True)
     result = dlg.ShowModal()
     dlg.Destroy()
     if result == wx.ID_NO or result == wx.ID_YES:
         self.__persist()
         nebulaguisettings.Repository.persist()
         # Make the InGUI know that the OutGUI is closed
         pynebula.delete('/editor/outguiisopened')
         try:
             del shared.object
             del shared.result
         except:
             pass
         evt.Skip()
     else:
         evt.Veto()
Пример #3
0
 def on_close_window(self, evt):
     """Takes care to close and persist the application state."""
     result_ok = self.__check_ok_to_exit_application()
     if not result_ok:
         #need to veto the close event, otherwise ingui left inconsistent
         evt.Veto()
         return
     if self.quit_without_saving:
         # Needs to have the focus to exit gracefully
         self.SetFocus()
         try:
             pynebula.delete('/editor/outguiisopened')
         except:
             pass
         evt.Skip()
         return
     dlg = filecmds.SaveAllDialog(self, exiting=True)
     result = dlg.ShowModal()
     dlg.Destroy()
     if result == wx.ID_NO or result == wx.ID_YES:
         self.__persist()
         nebulaguisettings.Repository.persist()
         # Make the InGUI know that the OutGUI is closed
         pynebula.delete('/editor/outguiisopened')
         try:
             del shared.object
             del shared.result
         except:
             pass
         evt.Skip()
     else:
         evt.Veto()
Пример #4
0
    def __can_delete_selector(self, class_name):
        usage_log = usagelog.find_fsm_selector( class_name )
        if len( usage_log[1] ) > 0:
            dlg = usagelog.DeleteErrorDialog(
                app.get_top_window(),
                "FSM selector '" + class_name + "'",
                usage_log
                )
            dlg.Show()
            return False

        # Save FSMs to avoid inconsistences between memory and persisted states
        # (and make the previous check valid)
        delete = self.__save_fsms('FSM selector')
        
        # Delete the singleton selector instance so the class can be deleted
        if delete:
            selector_path = format.append_to_path(
                                    fsm.get_fsm_selectors_lib(), 
                                    class_name 
                                    )
            try:
                pynebula.delete( str(selector_path) )
            except:
                pass
        return delete
Пример #5
0
 def __on_change_type(self, event):
     if self.transition_path != None and not self.skip_change_type_event:
         # Remove transition from state
         transition = self.__get_transition()
         state = self.__get_state()
         state.removetransition( transition )
         # Get free conditions for the selected transition type
         state_path = fsm.get_state_of_transition( self.transition_path )
         conds_paths = get_free_conditions( event.GetSelection(), state_path )
         # Delete condition if it's an event condition with filter
         cond_path = fsm.get_filteredcondition_of_transition( self.transition_path )
         try:
             pynebula.lookup( cond_path )
             pynebula.delete( cond_path )
         except:
             pass
         # Set first free condition for the selected transition type
         transition.setcondition( pynebula.lookup(conds_paths[0]) )
         # Add transition to state
         state.addtransition( transition )
         # Refresh condition parameters panel
         if self.GetSelection() == 0:
             self.panel_event.set_transition( self.transition_path )
         else:
             self.panel_script.set_transition( self.transition_path )
         # Signal change
         fsmevents.signal_fsm_change( self, self.transition_path )
Пример #6
0
 def on_ok_button_clicked(self, event):
     result_list = self.get_selected_entities()
     if result_list:
         if self.has_valid_path_name():
             #we need to save the entity id counter to avoid conflicts
             servers.get_entity_object_server().saveconfig()
             object_instancer = pynebula.new('nobjectinstancer')
             object_instancer.init(
                 len(result_list), 
                 len(result_list) 
                 )
             object_instancer.setentityobjecttype(
                 CJR_NORMAL_ENTITY_TYPE
                 )
             for each_entity in result_list:
                 entity_id_as_string = str( each_entity.getid() )
                 object_instancer.appendwithname(
                     each_entity, 
                     entity_id_as_string
                     )
             object_instancer.saveas(
                 self.get_path_name() 
                 )
             pynebula.delete(object_instancer)
             self.Close()
         else: 
             cjr.show_error_message(
                 "Please enter a valid path name"
                 )
     else:
         cjr.show_error_message(
             "Please select at least one entity to export"
             )
Пример #7
0
def set_nclass_dirty_flag(is_dirty):
    if is_dirty:
        if not get_nclass_dirty_flag():
            pynebula.new('nroot', '/editor/nclass_dirty')
    else:
        if get_nclass_dirty_flag():
            pynebula.delete('/editor/nclass_dirty')
Пример #8
0
 def __on_change_type(self, event):
     if self.transition_path != None and not self.skip_change_type_event:
         # Remove transition from state
         transition = self.__get_transition()
         state = self.__get_state()
         state.removetransition(transition)
         # Get free conditions for the selected transition type
         state_path = fsm.get_state_of_transition(self.transition_path)
         conds_paths = get_free_conditions(event.GetSelection(), state_path)
         # Delete condition if it's an event condition with filter
         cond_path = fsm.get_filteredcondition_of_transition(
             self.transition_path)
         try:
             pynebula.lookup(cond_path)
             pynebula.delete(cond_path)
         except:
             pass
         # Set first free condition for the selected transition type
         transition.setcondition(pynebula.lookup(conds_paths[0]))
         # Add transition to state
         state.addtransition(transition)
         # Refresh condition parameters panel
         if self.GetSelection() == 0:
             self.panel_event.set_transition(self.transition_path)
         else:
             self.panel_script.set_transition(self.transition_path)
         # Signal change
         fsmevents.signal_fsm_change(self, self.transition_path)
Пример #9
0
def create_default_state(path, type='nleafstate'):
    """Create a state with default parameters"""
    state = pynebula.new(type, path)
    if type == 'nleafstate':
        action_path = fsm.get_behaction_of_state(path)
        action = fsmaction.create_default_action(action_path)
        if action != None:
            state.setbehaviouralaction(action)
        else:
            state = None
            pynebula.delete(path)
            cjr.show_error_message(
                "There isn't any action available.\n" \
                "Couldn't create a default leaf state."
                )
    elif type == 'nnodestate':
        selector_list = fsm.get_fsm_selectors()
        if len(selector_list) > 0:
            state.setfsmselectorbyname(str(selector_list[0]))
        else:
            state = None
            pynebula.delete(path)
            cjr.show_error_message(
                "There isn't any FSM selection script available.\n" \
                "Couldn't create a default node state."
                )
    return state
Пример #10
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)
Пример #11
0
 def on_cancel( self, evt ):
     self.singlecheck.Enable()
     self.servercheck.Enable()
     self.button_search.Enable()
     for each_button in self.connectbtn:
         each_button.Disable()
         each_button.SetLabel( "Connect to < empty >" )
         
     self.button_cancel.Disable()
     
     self.searching = False
     
     if self.network is not None:
         pynebula.delete( "/sys/servers/network" )
         self.network = None
Пример #12
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 )
Пример #13
0
    def create_new_lib (self, position):
        wildcard = "Library files (*.n2)|*.n2"

        # Show file dialog
        dlg = wx.FileDialog(
            self.GetGrandParent(), 
            message="Create library", 
            wildcard=wildcard,
            style=wx.SAVE|wx.CHANGE_DIR|wx.OVERWRITE_PROMPT, 
            pos=position
            )

        # get the selected file
        if dlg.ShowModal() == wx.ID_OK:
            root = app.get_libraries()
            new_library_path = root.getfullname() + "/" + dlg.GetFilename()
            new_library_path, ext = os.path.splitext(new_library_path)

            # test extension
            if ext != ".n2":
                cjr.show_error_message(
                    "Bad extension: must be .n2. Try again."
                )
            else:
                # create object and save to disk
                save = True

                if pynebula.exists(str(new_library_path)):
                    dlg2_result = cjr.warn_yes_no(
                                "You are using a library with the same name."\
                                "\n\n Are you sure you want to delete it?"
                                )

                    if dlg2_result == wx.ID_NO:
                        save = False
                    else:
                        pynebula.delete( str(new_library_path) )

                if save:
                    library = pynebula.new("nstringlist", new_library_path)
                    path_string = str( dlg.GetPath() )
                    library.saveas(path_string)
                    foo, lib_name = os.path.split(new_library_path)
                    self.files[lib_name] = [path_string, False]
                    self.expand_tree(new_library_path.replace('/editor/',''))

        dlg.Destroy()
Пример #14
0
    def create_new_lib(self, position):
        wildcard = "Library files (*.n2)|*.n2"

        # Show file dialog
        dlg = wx.FileDialog(self.GetGrandParent(),
                            message="Create library",
                            wildcard=wildcard,
                            style=wx.SAVE | wx.CHANGE_DIR
                            | wx.OVERWRITE_PROMPT,
                            pos=position)

        # get the selected file
        if dlg.ShowModal() == wx.ID_OK:
            root = app.get_libraries()
            new_library_path = root.getfullname() + "/" + dlg.GetFilename()
            new_library_path, ext = os.path.splitext(new_library_path)

            # test extension
            if ext != ".n2":
                cjr.show_error_message(
                    "Bad extension: must be .n2. Try again.")
            else:
                # create object and save to disk
                save = True

                if pynebula.exists(str(new_library_path)):
                    dlg2_result = cjr.warn_yes_no(
                                "You are using a library with the same name."\
                                "\n\n Are you sure you want to delete it?"
                                )

                    if dlg2_result == wx.ID_NO:
                        save = False
                    else:
                        pynebula.delete(str(new_library_path))

                if save:
                    library = pynebula.new("nstringlist", new_library_path)
                    path_string = str(dlg.GetPath())
                    library.saveas(path_string)
                    foo, lib_name = os.path.split(new_library_path)
                    self.files[lib_name] = [path_string, False]
                    self.expand_tree(new_library_path.replace('/editor/', ''))

        dlg.Destroy()
Пример #15
0
    def on_end_drag (self, event):
        self.SetCursor(wx.STANDARD_CURSOR)  # restore cursor
        test_object = self.HitTest( event.GetPoint() )

        if test_object[1] != wx.TREE_HITTEST_TORIGHT:
            # get nebula objects
            dest_object = self.GetPyData(test_object[0])
            orig_object = self.GetPyData(self.drag_object)
            # check if we are trying to move a parent to a child
            dest = test_object[0]
            is_parent = False
            while dest != self.GetRootItem() and not is_parent:
                if dest == self.drag_object:
                    is_parent = True
                dest = self.GetItemParent(dest)
            # destination must be valid
            if self.is_valid(test_object[0]) and dest_object != orig_object \
                and not is_parent and dest_object != orig_object.getparent():
                
                new_obj = '/'.join(
                                ( dest_object.getfullname(), orig_object.getname() )
                                )
                orig_object.clone( str(new_obj) )

                # delete item if is a move operation
                if self.drag_type == 'move':
                    if not self.is_library(self.drag_object):
                        self.dirt_file(self.drag_object)
                    else:
                        self.files.pop(self.GetItemText(self.drag_object))

                    pynebula.delete(orig_object.getfullname())

                self.dirt_file(test_object[0])

                # expand tree to the target library
                self.expand_tree( new_obj.replace('/editor/','') )

            else:
                wx.Bell()
                cjr.show_warning_message(
                    "Operation not allowed"
                    )
        else:
            wx.Bell()
Пример #16
0
 def on_delete(self, event):
     """Ask to confirm the object deletion and delete it if so"""
     name = self.list.GetStringSelection()
     if name != "":
         msg = "Deleting a %s cannot be undone.\n\n" \
                     "Are you sure you want to delete " \
                     "the '%s' %s?" % ( (self.caption, name, self.caption) )
         delete = cjr.warn_yes_no(self, msg)
         if delete == wx.ID_YES:
             obj_path = format.append_to_path( self.lib_path, name )
             if self.erase_object( pynebula.lookup(obj_path) ):
                 # Close the editor for this object if it's opened
                 editor = self._get_editor( obj_path )
                 if editor != None:
                     editor.Close()
                 # Delete the object
                 pynebula.delete( str(obj_path) )
                 self.list.Delete( self.list.GetSelection() )
                 self.__refresh_editors()
Пример #17
0
    def on_end_drag(self, event):
        self.SetCursor(wx.STANDARD_CURSOR)  # restore cursor
        test_object = self.HitTest(event.GetPoint())

        if test_object[1] != wx.TREE_HITTEST_TORIGHT:
            # get nebula objects
            dest_object = self.GetPyData(test_object[0])
            orig_object = self.GetPyData(self.drag_object)
            # check if we are trying to move a parent to a child
            dest = test_object[0]
            is_parent = False
            while dest != self.GetRootItem() and not is_parent:
                if dest == self.drag_object:
                    is_parent = True
                dest = self.GetItemParent(dest)
            # destination must be valid
            if self.is_valid(test_object[0]) and dest_object != orig_object \
                and not is_parent and dest_object != orig_object.getparent():

                new_obj = '/'.join(
                    (dest_object.getfullname(), orig_object.getname()))
                orig_object.clone(str(new_obj))

                # delete item if is a move operation
                if self.drag_type == 'move':
                    if not self.is_library(self.drag_object):
                        self.dirt_file(self.drag_object)
                    else:
                        self.files.pop(self.GetItemText(self.drag_object))

                    pynebula.delete(orig_object.getfullname())

                self.dirt_file(test_object[0])

                # expand tree to the target library
                self.expand_tree(new_obj.replace('/editor/', ''))

            else:
                wx.Bell()
                cjr.show_warning_message("Operation not allowed")
        else:
            wx.Bell()
Пример #18
0
    def on_delete_from_disk(self, event):
        obj = self.GetPyData(self.current)
        lib_name = obj.getname()

        # delete only files avilable in the file list, files that are not
        # in this list are supossed read-only
        root_lib_name = self.GetItemText(self.get_root_library(self.current))
        if self.files.has_key(root_lib_name):
            position = self.__get_cursor_position()
            dlg_result = cjr.confirm_yes_no_at_position(
                self, "Are you sure?", position)
            if dlg_result == wx.ID_YES:
                parent = obj.getparent()
                dir_to_expand = parent.getfullname()
                os.remove(self.files[lib_name][0])  # delete file from disk!
                self.files.pop(lib_name)
                pynebula.delete(obj.getfullname())
                self.expand_tree(dir_to_expand.replace('/editor/', ''))
        else:
            cjr.show_warning_message("Element is read-only")
Пример #19
0
 def __get_inputs_formats(self):
     # create a temporary object so the model can know about its init command
     action = self.__get_action()
     class_name = action.getactionclass()
     model_obj = pynebula.new( str(class_name) )
     model = scriptingmodelsingleobject.new_scripting_model_for_object( model_obj )
     
     # get the init command inputs' format
     try:
         inputs = model.get_command('init')['input']
     except:
         inputs = []
     
     # destroy the temporary model object
     pynebula.delete( model_obj )
     model_obj = None
     
     # return the inputs' format, discarding the first one, which is
     # reserved for internal usage (the entity owning the action)
     return inputs[1:]
Пример #20
0
    def on_class_select(self, evt):
        try:
            wx.BeginBusyCursor()
            class_name = evt.GetString()
            # Clear GUI
            self.cmds.Clear()
            self.cmds_pg.Clear()

            # Temporary object to get the commands, must be deleted!!
            inspector = pynebula.new(
                                "nobjinspector",
                                "/editor/inspector"
                                )

            # I can call the init function several times to get the 
            # signals for all the  classes I want
            if class_name == "All":
                for name in self.object.getclasses():
                    inspector.initsignalsclass( str(name) )
            else:
                inspector.initsignalsclass( str(class_name) )

            # Add the commands to the combox list
            num_cmds = inspector.getcmdscount()
            self.cmds_protos = list()
            self.get_dict = dict()
            for index in xrange(num_cmds):            
                self.cmds.Append(
                    inspector.getcmdname(index) 
                    )
                if re.compile("get.*").match( inspector.getcmdname(index) ):
                    self.get_dict[inspector.getcmdname(index)] = \
                                                    inspector.getcmdprotoname(index)

            # Delete the inspector
            pynebula.delete("/editor/inspector")

            self.cmds.SetValue("Choose command")
            self.btn_send.Disable()
        finally:
            wx.EndBusyCursor()
Пример #21
0
def remove_emitter(particle_system, emitter):
    # force particle instances to release resources before
    # adding new emiiter
    emitter_name = emitter.getname()
    particle_system.refresh()
    pynebula.delete(emitter)
    # check if the emitter has been deleted ok by
    # looking for it (delete doesn't return success
    # or failure)
    root_node = particle_system.getrootnode()
    match = False
    for each_child in root_node.getchildren():
        if each_child.getname() == emitter_name:
            match = True
            break
    if match:
        # not deleted
        return False
    else:
        particle_system.setobjectdirty(True)
        return True
Пример #22
0
 def on_ok_button_clicked(self, event):
     result_list = self.get_selected_entities()
     if result_list:
         if self.has_valid_path_name():
             #we need to save the entity id counter to avoid conflicts
             servers.get_entity_object_server().saveconfig()
             object_instancer = pynebula.new('nobjectinstancer')
             object_instancer.init(len(result_list), len(result_list))
             object_instancer.setentityobjecttype(CJR_NORMAL_ENTITY_TYPE)
             for each_entity in result_list:
                 entity_id_as_string = str(each_entity.getid())
                 object_instancer.appendwithname(each_entity,
                                                 entity_id_as_string)
             object_instancer.saveas(self.get_path_name())
             pynebula.delete(object_instancer)
             self.Close()
         else:
             cjr.show_error_message("Please enter a valid path name")
     else:
         cjr.show_error_message(
             "Please select at least one entity to export")
Пример #23
0
def remove_emitter(particle_system, emitter):
    # force particle instances to release resources before 
    # adding new emiiter
    emitter_name = emitter.getname()
    particle_system.refresh()
    pynebula.delete(emitter)
    # check if the emitter has been deleted ok by 
    # looking for it (delete doesn't return success 
    # or failure)
    root_node = particle_system.getrootnode()
    match = False
    for each_child in root_node.getchildren():
        if each_child.getname() == emitter_name:
            match = True
            break
    if match:
        # not deleted
        return False
    else:
        particle_system.setobjectdirty(True)
        return True
Пример #24
0
def class_select(inspector_win, class_name):
    try:
        wx.BeginBusyCursor()
        # Temporary object for get the commands, must be deleted!!
        inspector = pynebula.new(
                            "nobjinspector",
                            "/editor/inspector"
                            )
    
        # I can call the init function multipletimes to get the 
        # commands for all classes I want
        if class_name == "All":
            for name in inspector_win.object.getclasses():
                inspector.initcmdsclass( str(name) )
        else:
            inspector.initcmdsclass( str(class_name) )
            doc_string = "Class %s not found in xml database.\n"\
                                "Doc and custom controls deactivated" % class_name
            inspector_win.doc_text.SetLabel(doc_string)
            inspector_win.Layout()

        # Add the commands to the combox list
        num_cmds = inspector.getcmdscount()
        inspector_win.cmds_protos = list()
        inspector_win.get_dict = dict()
        for index in xrange(num_cmds):            
            inspector_win.cmds.Append(
                inspector.getcmdname(index) 
                )
            if re.compile("get.*").match( inspector.getcmdname(index) ):
                inspector_win.get_dict[inspector.getcmdname(index)] = \
                                                inspector.getcmdprotoname(index)

        # Delete the inspector
        pynebula.delete("/editor/inspector")
    
        inspector_win.cmds.SetValue("Choose command")
        inspector_win.btn_exec.Disable()
    finally:
        wx.EndBusyCursor()
Пример #25
0
    def delete (self, library, type='dir'):
        element_name = self.GetItemText(library)

        if self.is_valid(library):
            if 'lib' == type:
                msg1 = "This will unload the %s library from memory.\n\n"\
                                "Are you sure?" % (element_name)
            elif 'dir' == type:
                msg1 = "This will delete the %s directory.\n\n"\
                                "Are you sure?" % (element_name)
        
            position = self.__get_cursor_position()
            dlg_result = cjr.confirm_yes_no_at_position(
                                self,
                                msg1,
                                position
                                )
            if dlg_result == wx.ID_YES:
                # get full nebula path
                library_data = self.GetPyData(library)
                full_path = library_data.getfullname()

                # the same with the parent for expand the tree after delete
                parent = library_data.getparent()
                parent_name = parent.getfullname()

                pynebula.delete(full_path)  # delete nebula object
                self.Delete(self.current)   # delete object from tree
    
                # update state
                if 'lib' == type:
                    self.files.pop(element_name)
                elif 'dir' == type:
                    self.dirt_file(self.get_root_library(self.current))
        
                # expand the parent
                self.expand_tree(parent_name.replace('/editor/', ''))

        else:
            cjr.show_warning_message("Element is read-only")
Пример #26
0
    def __can_delete_selector(self, class_name):
        usage_log = usagelog.find_fsm_selector(class_name)
        if len(usage_log[1]) > 0:
            dlg = usagelog.DeleteErrorDialog(
                app.get_top_window(), "FSM selector '" + class_name + "'",
                usage_log)
            dlg.Show()
            return False

        # Save FSMs to avoid inconsistences between memory and persisted states
        # (and make the previous check valid)
        delete = self.__save_fsms('FSM selector')

        # Delete the singleton selector instance so the class can be deleted
        if delete:
            selector_path = format.append_to_path(fsm.get_fsm_selectors_lib(),
                                                  class_name)
            try:
                pynebula.delete(str(selector_path))
            except:
                pass
        return delete
Пример #27
0
def create_default_state(path, type="nleafstate"):
    """Create a state with default parameters"""
    state = pynebula.new(type, path)
    if type == "nleafstate":
        action_path = fsm.get_behaction_of_state(path)
        action = fsmaction.create_default_action(action_path)
        if action != None:
            state.setbehaviouralaction(action)
        else:
            state = None
            pynebula.delete(path)
            cjr.show_error_message("There isn't any action available.\n" "Couldn't create a default leaf state.")
    elif type == "nnodestate":
        selector_list = fsm.get_fsm_selectors()
        if len(selector_list) > 0:
            state.setfsmselectorbyname(str(selector_list[0]))
        else:
            state = None
            pynebula.delete(path)
            cjr.show_error_message(
                "There isn't any FSM selection script available.\n" "Couldn't create a default node state."
            )
    return state
Пример #28
0
    def on_delete_from_disk (self, event):
        obj = self.GetPyData(self.current)
        lib_name = obj.getname()

        # delete only files avilable in the file list, files that are not
        # in this list are supossed read-only
        root_lib_name = self.GetItemText(self.get_root_library(self.current))
        if self.files.has_key(root_lib_name):
            position = self.__get_cursor_position()
            dlg_result = cjr.confirm_yes_no_at_position(
                                self,
                                "Are you sure?", 
                                position
                                )
            if dlg_result == wx.ID_YES:
                parent = obj.getparent() 
                dir_to_expand = parent.getfullname()
                os.remove(self.files[lib_name][0]) # delete file from disk!
                self.files.pop(lib_name)
                pynebula.delete(obj.getfullname())
                self.expand_tree(dir_to_expand.replace('/editor/', '') )
        else:
            cjr.show_warning_message("Element is read-only")
Пример #29
0
    def delete(self, library, type='dir'):
        element_name = self.GetItemText(library)

        if self.is_valid(library):
            if 'lib' == type:
                msg1 = "This will unload the %s library from memory.\n\n"\
                                "Are you sure?" % (element_name)
            elif 'dir' == type:
                msg1 = "This will delete the %s directory.\n\n"\
                                "Are you sure?" % (element_name)

            position = self.__get_cursor_position()
            dlg_result = cjr.confirm_yes_no_at_position(self, msg1, position)
            if dlg_result == wx.ID_YES:
                # get full nebula path
                library_data = self.GetPyData(library)
                full_path = library_data.getfullname()

                # the same with the parent for expand the tree after delete
                parent = library_data.getparent()
                parent_name = parent.getfullname()

                pynebula.delete(full_path)  # delete nebula object
                self.Delete(self.current)  # delete object from tree

                # update state
                if 'lib' == type:
                    self.files.pop(element_name)
                elif 'dir' == type:
                    self.dirt_file(self.get_root_library(self.current))

                # expand the parent
                self.expand_tree(parent_name.replace('/editor/', ''))

        else:
            cjr.show_warning_message("Element is read-only")
Пример #30
0
    def draw_state_commands(self, obj):
        self.cmds_pg.Clear()

        if obj is None:
            self.Disable()
            return
        else:
            self.Enable()

        # Get the commands

        inspector = pynebula.new("nobjinspector", "/editor/inspector")
        inspector.initcmdsstate(obj)

        # Navigate over the commands and build the interface. We need
        # the command definition to put it in the category. So first create
        # the grid properties  but do not append them until the category
        # is placed with the full description.

        cmds_count = inspector.getcmdscount()
        self.cmd_list = list()  # Command list
        self.cmd_name_list = list()  # Store the categories
        self.undo_list = list()

        if cmds_count == 0:
            self.cmds_pg.Append(
                pg.wxPropertyCategory(str("State is EMPTY"), str("nostate")))

        self.prev_state = list()  # Storage state when the inspector is call
        for num_cmd in xrange(cmds_count):
            cmds_name_desc = inspector.getcmdname(num_cmd) + str(" (")
            undo_cmd = inspector.getcmdname(num_cmd) + str("(")
            args_count = inspector.getinargscount(num_cmd)
            self.element = list()  # Start argument list

            for num_arg in xrange(args_count):
                label = "label_in" + str(num_cmd) + "-" + str(num_arg + 1)
                arg_type = inspector.gettype(num_cmd, num_arg + 1)

                # Type is Int

                if arg_type == 1:
                    value = inspector.geti(num_cmd, num_arg + 1)
                    self.element.append(pg.wxIntProperty('Integer', label))
                    value_as_string = str(value)
                    self.element[num_arg].SetValueFromString(
                        value_as_string, 0)
                    self.prev_state.append(value_as_string)
                    cmds_name_desc = cmds_name_desc + value_as_string + ", "
                    undo_cmd = undo_cmd + value_as_string + ","

                # Type is Float

                elif arg_type == 2:
                    value = inspector.getf(num_cmd, num_arg + 1)
                    self.element.append(pg.wxFloatProperty('Float', label))
                    value_as_string = str(value)
                    self.element[num_arg].SetValueFromString(
                        value_as_string, 0)
                    self.prev_state.append(value_as_string)
                    undo_cmd = undo_cmd + value_as_string + ","
                    temp = value_as_string.rsplit('.')
                    value = temp[0] + '.' + temp[1][:2]
                    cmds_name_desc = cmds_name_desc + value_as_string + ", "

                # Type if String

                elif arg_type == 3:
                    value = inspector.gets(num_cmd, num_arg + 1)
                    self.element.append(
                        pg.wxStringProperty('String', label, ''))
                    value_as_string = str(value)
                    self.element[num_arg].SetValueFromString(
                        value_as_string, 0)
                    self.prev_state.append(value_as_string)
                    cmds_name_desc = cmds_name_desc +\
                                   '"' + value_as_string + '"' + ", "
                    undo_cmd = undo_cmd + '"' + value_as_string + '"' + ","

                # Type is Boolean

                elif arg_type == 4:
                    value = inspector.getb(num_cmd, num_arg + 1)
                    self.element.append(
                        pg.wxEnumProperty('Boolean', label, ['True', 'False'],
                                          [1, 0], 2))
                    if value == 1:
                        self.element[num_arg].SetValueFromString(
                            str("True"), 0)
                        cmds_name_desc = cmds_name_desc + str('True') + ", "
                        self.prev_state.append('True')
                    else:
                        self.element[num_arg].SetValueFromString(
                            str("False"), 0)
                        cmds_name_desc = cmds_name_desc + str('False') + ", "
                        self.prev_state.append('False')
                    undo_cmd = undo_cmd + str(value) + ","

                # Type is Object

                elif arg_type == 5:
                    value = inspector.geto(num_cmd, num_arg + 1)
                    self.element.append(
                        pg.wxStringProperty('Object', label, ''))
                    full_name_as_string = str(value.getfullname())
                    self.element[num_arg].SetValueFromString(
                        full_name_as_string, 0)
                    self.prev_state.append(full_name_as_string)
                    cmds_name_desc = cmds_name_desc +\
                                   str(value.getname()) + ", "
                    undo_cmd = undo_cmd + "lookup(" + \
                                            full_name_as_string + "),"

                # Type not implemented

                else:
                    cjr.show_error_message("Unknown type!!!")

            # Write the command definition into the category and attach it

            if args_count > 0:
                cmds_name_desc = cmds_name_desc[:-2] + ")"
                undo_cmd = undo_cmd[:-1] + ")"
            else:
                cmds_name_desc = cmds_name_desc + ")"
                undo_cmd = undo_cmd + ")"

            category = pg.wxPropertyCategory(cmds_name_desc,
                                             "cmdLabel%d" % num_cmd)
            self.cmds_pg.Append(category)
            self.cmd_name_list.append(inspector.getcmdprotoname(num_cmd))

            # Show the arguments (append to grid) recently created
            # and append them to a command list

            for num_arg in xrange(args_count):
                self.cmds_pg.Append(self.element[num_arg])

            self.cmd_list.append(self.element)

            self.undo_list.append(undo_cmd)

        pynebula.delete("/editor/inspector")

        # Make de object the current

        nebulagui.nebula_object = obj
        self.object = obj

        # Refresh control
        self.cmds_pg.Refresh()
Пример #31
0
    def on_signal_select(self, evt):
        cmd_name = self.cmds.GetStringSelection()

        self.cmds_pg.Clear()        
        class_name = self.classes.GetStringSelection()

        # Temporary object to get the commands: must be deleted after use!!
        inspector = pynebula.new(
                            "nobjinspector",
                            "/editor/inspector"
                            )
        if class_name == "All":
            for name in self.object.getclasses():
                inspector.initsignalsclass( str(name) )
        else:
            inspector.initsignalsclass( str(class_name) )

        # Build a dictionary with the cmd name and its
        # position in the array: this way I can list the cmds
        # alphabetically
        self.cmd_dict = dict()
        for index in xrange( inspector.getcmdscount() ):
            self.cmd_dict[inspector.getcmdname(index)] = index

        num_cmd = self.cmd_dict[cmd_name]
        num_args = inspector.getinargscount(num_cmd)

        # Build the properties depending of the argument type
        self.cmd_proto_name = inspector.getcmdprotoname(num_cmd)

        arg = self.cmd_proto_name.rsplit('_')

        # Draw In properties
        self.in_elements = list()
        if num_args > 0:
            self.cmds_pg.Append(
                pg.wxPropertyCategory(
                    "In Args", 
                    "InValues" 
                    )
                )
            self.__draw_input_fields(
                arg[2], 
                self.in_elements, 
                "in"
                )

        # Draw Out properties
        self.out_elements = list()
        if inspector.getoutargscount(num_cmd) > 0:
            self.cmds_pg.Append(
                pg.wxPropertyCategory(
                    "Out Args", 
                    "OutValues"
                    )
                )
            self.__draw_input_fields(
                arg[0], 
                self.out_elements, 
                "out"
                )

        # Delete the inspector
        pynebula.delete("/editor/inspector")

        self.btn_send.Enable()
Пример #32
0
def cmds_select(inspector_win):
    cmd_name = inspector_win.cmds.GetStringSelection()

    inspector_win.cmds_pg.Clear()        
    class_name = str( inspector_win.classes.GetStringSelection() )

    # Temporary object to get the commands: must be deleted after use!!
    inspector = pynebula.new(
                        "nobjinspector",
                        "/editor/inspector"
                        )

    if class_name == "All":
        for name in inspector_win.object.getclasses():
            inspector.initcmdsclass( str(name) )
    else:
        inspector.initcmdsclass(class_name)

    # Build a dictionary with the cmd name and its
    # position in the array: this way I can list the cmds
    # alphabetically
    inspector_win.cmd_dict = dict()
    for index in xrange( inspector.getcmdscount() ):
        inspector_win.cmd_dict[inspector.getcmdname(index)] = index

    num_cmd = inspector_win.cmd_dict[cmd_name]
    num_args = inspector.getinargscount(num_cmd)        

    # Enable the get button if the command has a get counterpart
    if re.compile("set.*").match(cmd_name):
        name = cmd_name[3:]
        try:
            num_getcmd = inspector_win.cmd_dict[str("get"+name)]
            num_get_out_args = inspector.getoutargscount(num_getcmd)
            if num_args != num_get_out_args:
                inspector_win.btn_get.Disable()
            else:
                inspector_win.btn_get.Enable()                
        except:           
            inspector_win.btn_get.Disable()
    else:
        inspector_win.btn_get.Disable()
    
    # Build the properties depending on the argument type
    inspector_win.cmd_proto_name = inspector.getcmdprotoname(num_cmd)

    arg = inspector_win.cmd_proto_name.rsplit('_')              

    # Draw In properties
    inspector_win.in_elements = list()  
    if num_args > 0:
        inspector_win.cmds_pg.Append(
            pg.wxPropertyCategory(
                "In Args", 
                "InValues" 
                )
            )
        draw_input_fields(
            inspector_win, 
            arg[2], 
            inspector_win.in_elements, 
            "in"
            )
        
    # Draw Out properties
    inspector_win.out_elements = list()
    if inspector.getoutargscount(num_cmd) > 0:
        inspector_win.cmds_pg.Append(
            pg.wxPropertyCategory(
                "Out Args", 
                "OutValues"
                )
            )
        draw_input_fields(
            inspector_win, 
            arg[0], 
            inspector_win.out_elements, 
            "out"
            )

    # Delete the inspector
    pynebula.delete("/editor/inspector")

    inspector_win.btn_exec.Enable()
    inspector_win.cmds_pg.Refresh()
Пример #33
0
    def draw_state_commands(self, obj):
        self.cmds_pg.Clear()

        if obj is None:
            self.Disable()
            return
        else:
            self.Enable()

        # Get the commands

        inspector = pynebula.new(
                            "nobjinspector",
                            "/editor/inspector"
                            )
        inspector.initcmdsstate(obj)

        # Navigate over the commands and build the interface. We need
        # the command definition to put it in the category. So first create
        # the grid properties  but do not append them until the category
        # is placed with the full description.

        cmds_count = inspector.getcmdscount() 
        self.cmd_list = list()       # Command list
        self.cmd_name_list = list()  # Store the categories
        self.undo_list = list()

        if cmds_count == 0:
            self.cmds_pg.Append(
                pg.wxPropertyCategory(
                    str("State is EMPTY"), 
                    str("nostate")
                    )
                )

        self.prev_state = list() # Storage state when the inspector is call
        for num_cmd in xrange(cmds_count):
            cmds_name_desc = inspector.getcmdname(num_cmd) + str(" (")
            undo_cmd = inspector.getcmdname(num_cmd) + str("(")
            args_count = inspector.getinargscount(num_cmd)
            self.element = list()   # Start argument list            

            for num_arg in xrange(args_count):                
                label = "label_in" + str(num_cmd) + "-" + str(num_arg+1)
                arg_type = inspector.gettype(num_cmd, num_arg+1)

                # Type is Int

                if arg_type == 1:
                    value = inspector.geti(num_cmd, num_arg+1)
                    self.element.append(
                        pg.wxIntProperty(
                            'Integer', 
                            label
                            )
                        )
                    value_as_string = str(value)
                    self.element[num_arg].SetValueFromString(
                        value_as_string, 
                        0
                        )
                    self.prev_state.append(value_as_string)
                    cmds_name_desc = cmds_name_desc + value_as_string + ", "
                    undo_cmd = undo_cmd + value_as_string + ","

                # Type is Float

                elif arg_type == 2:
                    value = inspector.getf(num_cmd, num_arg+1)
                    self.element.append(
                        pg.wxFloatProperty(
                            'Float', 
                            label
                            )
                        )
                    value_as_string = str(value)    
                    self.element[num_arg].SetValueFromString(
                        value_as_string,
                        0
                        )
                    self.prev_state.append(value_as_string)
                    undo_cmd = undo_cmd + value_as_string + ","
                    temp = value_as_string.rsplit('.')
                    value = temp[0] + '.' + temp[1][:2]
                    cmds_name_desc = cmds_name_desc + value_as_string + ", "

                # Type if String

                elif arg_type == 3:
                    value = inspector.gets(num_cmd, num_arg+1)
                    self.element.append(
                        pg.wxStringProperty(
                            'String',
                            label, 
                            ''
                            )
                        )
                    value_as_string = str(value)
                    self.element[num_arg].SetValueFromString(
                        value_as_string,
                        0
                        )
                    self.prev_state.append(value_as_string)
                    cmds_name_desc = cmds_name_desc +\
                                   '"' + value_as_string + '"' + ", "
                    undo_cmd = undo_cmd + '"' + value_as_string + '"' + ","

                # Type is Boolean

                elif arg_type == 4:
                    value = inspector.getb(num_cmd, num_arg+1)
                    self.element.append(
                        pg.wxEnumProperty(
                            'Boolean', 
                            label,
                            ['True','False'],
                            [1,0],
                            2 
                            )
                        )
                    if value == 1:
                        self.element[num_arg].SetValueFromString(
                            str("True"), 
                            0
                            )
                        cmds_name_desc = cmds_name_desc + str('True') + ", "
                        self.prev_state.append('True')
                    else:
                        self.element[num_arg].SetValueFromString(
                            str("False"), 
                            0
                            )
                        cmds_name_desc = cmds_name_desc + str('False') + ", "
                        self.prev_state.append('False')
                    undo_cmd = undo_cmd + str(value) + ","

                # Type is Object

                elif arg_type == 5:
                    value = inspector.geto(num_cmd, num_arg+1)             
                    self.element.append(
                        pg.wxStringProperty(
                            'Object', 
                            label, 
                            ''
                            )
                        )
                    full_name_as_string = str( value.getfullname() )
                    self.element[num_arg].SetValueFromString(
                        full_name_as_string,
                        0
                        )
                    self.prev_state.append(full_name_as_string)
                    cmds_name_desc = cmds_name_desc +\
                                   str(value.getname()) + ", "
                    undo_cmd = undo_cmd + "lookup(" + \
                                            full_name_as_string + "),"

                # Type not implemented

                else:
                    cjr.show_error_message("Unknown type!!!")

            # Write the command definition into the category and attach it

            if args_count > 0:
                cmds_name_desc = cmds_name_desc[:-2] + ")"
                undo_cmd = undo_cmd[:-1] + ")"
            else:
                cmds_name_desc = cmds_name_desc + ")"
                undo_cmd = undo_cmd + ")"

            category = pg.wxPropertyCategory(
                                cmds_name_desc, 
                                "cmdLabel%d" % num_cmd
                                )
            self.cmds_pg.Append(category)
            self.cmd_name_list.append(
                inspector.getcmdprotoname(num_cmd)
                )

            # Show the arguments (append to grid) recently created 
            # and append them to a command list

            for num_arg in xrange(args_count):
                self.cmds_pg.Append(self.element[num_arg])
            
            self.cmd_list.append(self.element)

            self.undo_list.append(undo_cmd)

        pynebula.delete("/editor/inspector")

        # Make de object the current

        nebulagui.nebula_object = obj
        self.object = obj

        # Refresh control
        self.cmds_pg.Refresh()
Пример #34
0
def clear_temp():
    """Delete all objects in the temp directory (not recursive)"""
    temp_dir = pynebula.lookup( get_temp_dir() )
    while temp_dir.gethead() != None:
        pynebula.delete( temp_dir.gethead().getfullname() )
Пример #35
0
 def __del__( self ):
     if ( self.network is not None ) and self.searching :
         pynebula.delete( "/sys/servers/network" )
         self.network = None