def on_run(self, event):
        # ask for save before run if script has been modified
        if self.stc.GetModify():
            answer = cjr.confirm_yes_no(
                            self,
                            "Save changes to '%s' ?" % self.filename
                            )
            if answer == wx.ID_YES:
                self.save(True)
            elif answer == wx.ID_CANCEL:
                return

        if self.filename == "":
            cjr.show_information_message(
                "I'm quite stupid, so please you Supreme Intelligence\n" \
                "save the file so I can look at its extension and know\n" \
                "which file type this script is."
                )
        if self.filename.endswith('.lua'):
            servers.get_lua_server().runscript(
                str( format.mangle_path(self.filename) )
                )
        elif self.filename.endswith('.py'):
            servers.get_python_server().runscript(
                str( format.mangle_path(self.filename) )
                )
Example #2
0
 def on_save_preset(self, event):
     """Save the current preset with the name chosen by the user"""
     # Ask for the preset's name
     if self.__prepresets_process():
         path = format.append_to_path(
                     get_presets_path(), 
                     "lib" 
                     )
         dlg = dirdlg.DirDialog(
                     self.get_frame(), 
                     dirdlg.SAVE,
                     'preset', 
                     'Preset', 
                     path
                     )
         if dlg.ShowModal() == wx.ID_OK:
             if dlg.dir_exists():
                 msg = "Overwrite the '%s' preset?" % dlg.get_dirname()
                 result = cjr.confirm_yes_no(
                                 self.get_frame(), 
                                 msg
                                 )
                 if result == wx.ID_YES:
                     save_preset( dlg.get_path() )
             else:
                 save_preset( dlg.get_path() )
         dlg.Destroy()
Example #3
0
def copy_file(source_file, target_directory):
    """
    Copy a file into a directory.
    
    If there's already another file with the same name in the target directory
    the user is asked to enter a new file name, overwrite the existing one or
    just cancel the operation.
    
    Return true if the file has been copied, false otherwise.
    """
    src = servers.get_file_server().manglepath(str(source_file))
    dir_name = servers.get_file_server().manglepath(str(target_directory))
    target = format.append_to_path(dir_name, format.get_name(src))
    while os.path.exists(target):
        result = cjr.confirm_yes_no(
                        None,
                        "A file called '%s' already exists.\n\n" \
                            "Do you want to rename the new file?\n" \
                            "(answering 'no' will overwrite the old one)"\
                            % format.get_name(src)
                        )
        if result == wx.ID_YES:
            dlg = wx.TextEntryDialog(None, "New file name:", "Conjurer",
                                     format.get_name(target))
            if dlg.ShowModal() == wx.ID_OK and dlg.GetValue() != "":
                target = format.append_to_path(dir, dlg.GetValue())
        elif result == wx.ID_NO:
            break
        else:
            return False
    shutil.copy(src, target)
    return True
Example #4
0
 def on_delete_layer(self, event):
     if self.layer_selected is None:
         cjr.show_error_message("Please select a layer to delete.")
     else:
         msg = "Are you sure that you want to delete " \
                     "the '%s' layer?" % self.get_name_for_selected_layer()
         result = cjr.confirm_yes_no(self, msg)
         if result == wx.ID_YES:
             self.delete_selected_layer()
Example #5
0
 def on_select_objects(self, event):
     """Set the selection objects mode"""
     enabled = event.Checked()
     self.Check(ID_SelectObjects, enabled)
     msg = "Do you want to save subentity changes?"
     result = cjr.confirm_yes_no(app.get_top_window(), msg)
     save = (result == wx.ID_YES)
     succeed = app.get_object_state().setselectionmode(0, save)
     if succeed:
         self.__get_toolbar().select_selection_mode(0)
Example #6
0
 def on_delete_layer(self, event):
     if self.layer_selected is None:
         cjr.show_error_message(
             "Please select a layer to delete."
             )
     else:
         msg = "Are you sure that you want to delete " \
                     "the '%s' layer?" % self.get_name_for_selected_layer()
         result = cjr.confirm_yes_no(self, msg)
         if result == wx.ID_YES:
             self.delete_selected_layer()
    def on_close(self, event):
        # If there are some changes ask to save the script
        if self.stc.GetModify():
            answer = cjr.confirm_yes_no(
                self, "Save changes to '%s' ?" % self.filename)
            if answer == wx.ID_YES:
                if not self.save(True):
                    return
            elif answer == wx.ID_CANCEL:
                return

        self.Destroy()
Example #8
0
 def on_select_objects(self, event):
     """Set the selection objects mode"""
     enabled = event.Checked()
     self.Check( ID_SelectObjects, enabled )
     msg = "Do you want to save subentity changes?"
     result = cjr.confirm_yes_no(
                     app.get_top_window(),
                     msg
                     )
     save = (result == wx.ID_YES)
     succeed = app.get_object_state().setselectionmode( 0, save )
     if succeed:
         self.__get_toolbar().select_selection_mode( 0 )
Example #9
0
def validate_fsm_name(name):
    path = format.append_to_path(fsm.get_fsms_lib(), name)
    try:
        # Lookup will fail if it's a new name (name not found)
        pynebula.lookup(path)
        msg = "Another finite state machine called '%s' already exists." % name
        cjr.show_error_message(msg)
        return False
    except:
        msg = "Renaming this FSM will invalidate any references to it that " \
            "any agent has.\nAre you sure that you want to rename it?"
        result = cjr.confirm_yes_no(None, msg)
        return result == wx.ID_YES
Example #10
0
def validate_fsm_name(name):
    path = format.append_to_path( fsm.get_fsms_lib(), name )
    try:
        # Lookup will fail if it's a new name (name not found)
        pynebula.lookup( path )
        msg = "Another finite state machine called '%s' already exists." % name
        cjr.show_error_message(msg)
        return False
    except:
        msg = "Renaming this FSM will invalidate any references to it that " \
            "any agent has.\nAre you sure that you want to rename it?"
        result = cjr.confirm_yes_no(None, msg)
        return result == wx.ID_YES
    def on_close(self, event):
        # If there are some changes ask to save the script
        if self.stc.GetModify():
            answer = cjr.confirm_yes_no(
                            self,
                            "Save changes to '%s' ?" % self.filename
                            )
            if answer == wx.ID_YES:
                if not self.save(True):
                    return
            elif answer == wx.ID_CANCEL:
                return

        self.Destroy()
Example #12
0
 def on_delete_material(self, event):
     material_id = self.__get_id_for_selected_material()
     # don't allow the user to delete the default material
     if material_id > 0: 
         # Ask for confirmation
         name = self.__get_name_of_selected_material()
         msg = "Are you sure you want to delete the '%s' grass material?" \
                     % name
         result = cjr.confirm_yes_no(self, msg)
         if result == wx.ID_YES:
             # Delete material
             terrain = app.get_outdoor()
             terrain.deletegrowthmaterial( material_id )
             self.__build_material_list()
Example #13
0
 def on_delete_material(self, event):
     material_id = self.__get_id_for_selected_material()
     # don't allow the user to delete the default material
     if material_id > 0:
         # Ask for confirmation
         name = self.__get_name_of_selected_material()
         msg = "Are you sure you want to delete the '%s' grass material?" \
                     % name
         result = cjr.confirm_yes_no(self, msg)
         if result == wx.ID_YES:
             # Delete material
             terrain = app.get_outdoor()
             terrain.deletegrowthmaterial(material_id)
             self.__build_material_list()
Example #14
0
 def on_delete_layer(self, event):
     if self.layer_selected is not None:
         msg = "Are you sure that you want to delete the '%s' layer?"\
                     % self.layer_selected.get_layer_name()
         result = cjr.confirm_yes_no(self, msg)
         if result == wx.ID_YES:
             # delete selected layer
             app.get_outdoor().removelayer(
                 self.layer_selected.get_layer_id()
                 )
             # delete layer control
             self.Freeze()
             self.__delete_layer_ctrl(self.layer_selected)
             self.__refresh_layers()
             self.Thaw()
Example #15
0
 def on_save_preset(self, event):
     """Save the current preset with the name chosen by the user"""
     # Ask for the preset's name
     if self.__prepresets_process():
         path = format.append_to_path(get_presets_path(), "lib")
         dlg = dirdlg.DirDialog(self.get_frame(), dirdlg.SAVE, 'preset',
                                'Preset', path)
         if dlg.ShowModal() == wx.ID_OK:
             if dlg.dir_exists():
                 msg = "Overwrite the '%s' preset?" % dlg.get_dirname()
                 result = cjr.confirm_yes_no(self.get_frame(), msg)
                 if result == wx.ID_YES:
                     save_preset(dlg.get_path())
             else:
                 save_preset(dlg.get_path())
         dlg.Destroy()
Example #16
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
Example #17
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
Example #18
0
 def on_delete_anim(self, event):
     index = self.list.GetSelection()
     if index != wx.NOT_FOUND:
         name = self.list.GetStringSelection()
         msg = "Deleting an animation cannot be undone.\n\n" \
             "Are you sure you want to delete the animation %s'?" % name
         delete = cjr.confirm_yes_no(None, msg)
         if delete == wx.ID_YES:
             anim_index = self.anim_indices[index]
             deleted = self.character.removeanimstate(
                 anim_index[1], anim_index[0])
             if not deleted:
                 cjr.show_error_message(
                     "Cannot delete the '%s' animation.\n" \
                     "Maybe is it active on some character?" % name
                     )
             else:
                 self.deleted_anim_index = anim_index
                 self.EndModal(wx.ID_OK)
Example #19
0
 def on_delete_brush(self, event):
     index = self.list_brushes.GetSelection()
     if index == wx.NOT_FOUND:
         cjr.show_error_message(
             "No brush selected. Please choose a brush from the list."
             )
     else:
         # Ask for confirmation
         name = self.list_brushes.GetString(index)
         msg = "Are you sure you want to delete the '%s' grass brush?" \
                     % name
         result = cjr.confirm_yes_no(self, msg)
         if result == wx.ID_YES:
             # Delete brush
             brush_id = self.list_brushes.GetClientData(index)
             self.material.deletegrowthbrush(brush_id)
             # We need to update the brush list 
             # since the indexing may have changed
             self.__update_brushes_list()
Example #20
0
    def __on_selection_mode(self, event):
        mode = self.choice_selection_mode.GetSelection()
        menu = self.GetParent().get_menubar().get_menu('&View')
        succeed = False
        if mode == 0 and app.is_subentity_mode_active():
            result = cjr.confirm_yes_no(
                app.get_top_window(), "Do you want to save subentity changes?")
            save = (result == wx.ID_YES)
            succeed = app.get_object_state().setselectionmode(mode, save)
        else:
            succeed = app.get_object_state().setselectionmode(mode, False)

        if succeed:
            if mode == 0:
                id_selection = viewcmds.ID_SelectObjects
            elif mode == 1:
                id_selection = viewcmds.ID_SelectWaypoints
            else:
                id_selection = viewcmds.ID_SelectTerrainCells
            menu.Check(id_selection, True)
Example #21
0
 def __prepresets_process(self):
     # Ask for presets directory creation if it doesn't exist yet
     path = get_presets_path()
     if not os.path.exists(path):
         msg = "The presets directory '%s' doesn't exist.\n" \
                     "A presets directory is needed to continue.\n\n" \
                     "Do you want to create it?" % path
         result = cjr.confirm_yes_no(self.get_frame(), msg)
         if result == wx.ID_YES:
             os.makedirs(path)
     # Create subpaths if doesn't exist yet
     lib_path = format.append_to_path(path, "lib")
     levels_path = format.append_to_path(path, "levels")
     if os.path.exists(path):
         # Create subpaths only if root path has been created
         if not os.path.exists(lib_path):
             os.mkdir(lib_path)
         if not os.path.exists(levels_path):
             os.mkdir(levels_path)
     # Return true only if all the presets subpaths finally exists
     return os.path.exists(lib_path) and os.path.exists(levels_path)
Example #22
0
 def unpackEntitiesAndAddToWorld(self):
     entity_server = servers.get_entity_object_server()
     world_server = servers.get_world_interface()
     number_of_elements = self.containerObject.size()
     for index in range(number_of_elements):
         entity = self.containerObject.at(index)
         original_id = self.containerObject.getobjectnameatindex(index)
         #check if the entity already exists
         match = entity_server.getentityobject( int(original_id) )
         if not match == None:
             result = cjr.confirm_yes_no(
                             self.parentView, 
                             "This entity already exists. "\
                             "Do you want to overwrite it?"
                             )
             wantsToOverwrite = (result == wx.ID_YES)
             if wantsToOverwrite:
                 entity_server.swapentityobjectids(match, entity)
                 entity_server.removeentityobject(match)
         entity.setlayerid(self.targetLayerId)
         world_server.addtoworld(entity)
Example #23
0
 def on_delete_anim(self, event):
     index = self.list.GetSelection()
     if index != wx.NOT_FOUND:
         name = self.list.GetStringSelection()
         msg = "Deleting an animation cannot be undone.\n\n" \
             "Are you sure you want to delete the animation %s'?" % name
         delete = cjr.confirm_yes_no(None, msg)
         if delete == wx.ID_YES:
             anim_index = self.anim_indices[index]
             deleted = self.character.removeanimstate(
                             anim_index[1], 
                             anim_index[0] 
                             )
             if not deleted:
                 cjr.show_error_message(
                     "Cannot delete the '%s' animation.\n" \
                     "Maybe is it active on some character?" % name
                     )
             else:
                 self.deleted_anim_index = anim_index
                 self.EndModal(wx.ID_OK)
Example #24
0
    def on_delete_entity(self, event):
        index = self.__get_selected_attach_index()
        if index == -1:
            return

        # Ask for confirmation
        slot = self.__get_selected_list_item(self.ID_Slot)
        if slot == "":
            return
        msg = "Are you sure that you want to delete the " \
                    "the entity attached to the '%s' slot?" % slot
        delete = cjr.confirm_yes_no(self, msg)
        if delete != wx.ID_YES:
            return

        # Dettach the entity from the selected slot
        p_index = self.attach_indices[index]
        entity_id = self.character.getattachedentity(p_index)
        if entity_id == 0:
            return
        self.on_dettach_entity(None)

        # Store selected entities
        obj_state = app.get_object_state()
        selection_ids = []
        for i in range(obj_state.getselectioncount()):
            id = obj_state.getselectedentity(i).getid()
            if entity_id != id:
                selection_ids.append(id)

        # Delete the entity
        obj_state.resetselection()
        obj_state.addentitytoselection(entity_id)
        obj_state.delentities()

        # Restore the selection
        for id in selection_ids:
            obj_state.addentitytoselection(id)

        self.__update_attach_params_ctrls()
Example #25
0
    def on_delete_entity(self, event):
        index = self.__get_selected_attach_index()
        if index == -1:
            return

        # Ask for confirmation
        slot = self.__get_selected_list_item(self.ID_Slot)
        if slot == "":
            return
        msg = "Are you sure that you want to delete the " \
                    "the entity attached to the '%s' slot?" % slot
        delete = cjr.confirm_yes_no(self, msg)
        if delete != wx.ID_YES:
            return
        
        # Dettach the entity from the selected slot
        p_index = self.attach_indices[index]
        entity_id = self.character.getattachedentity( p_index )
        if entity_id == 0:
            return
        self.on_dettach_entity(None)
        
        # Store selected entities
        obj_state = app.get_object_state()
        selection_ids = []
        for i in range( obj_state.getselectioncount() ):
            id = obj_state.getselectedentity(i).getid()
            if entity_id != id:
                selection_ids.append( id )
        
        # Delete the entity
        obj_state.resetselection()
        obj_state.addentitytoselection( entity_id )
        obj_state.delentities()
        
        # Restore the selection
        for id in selection_ids:
            obj_state.addentitytoselection( id )
        
        self.__update_attach_params_ctrls()
Example #26
0
def copy_file(source_file, target_directory):
    """
    Copy a file into a directory.
    
    If there's already another file with the same name in the target directory
    the user is asked to enter a new file name, overwrite the existing one or
    just cancel the operation.
    
    Return true if the file has been copied, false otherwise.
    """
    src = servers.get_file_server().manglepath( str(source_file) )
    dir_name = servers.get_file_server().manglepath( str(target_directory) )
    target = format.append_to_path(
                    dir_name, 
                    format.get_name(src) 
                    )
    while os.path.exists( target ):
        result = cjr.confirm_yes_no(
                        None,
                        "A file called '%s' already exists.\n\n" \
                            "Do you want to rename the new file?\n" \
                            "(answering 'no' will overwrite the old one)"\
                            % format.get_name(src) 
                        )
        if result == wx.ID_YES:
            dlg = wx.TextEntryDialog(
                        None, 
                        "New file name:", 
                        "Conjurer",
                        format.get_name(target)
                        )
            if dlg.ShowModal() == wx.ID_OK and dlg.GetValue() != "":
                target = format.append_to_path( dir, dlg.GetValue() )
        elif result == wx.ID_NO:
            break
        else:
            return False
    shutil.copy(src, target)
    return True
    def on_run(self, event):
        # ask for save before run if script has been modified
        if self.stc.GetModify():
            answer = cjr.confirm_yes_no(
                self, "Save changes to '%s' ?" % self.filename)
            if answer == wx.ID_YES:
                self.save(True)
            elif answer == wx.ID_CANCEL:
                return

        if self.filename == "":
            cjr.show_information_message(
                "I'm quite stupid, so please you Supreme Intelligence\n" \
                "save the file so I can look at its extension and know\n" \
                "which file type this script is."
                )
        if self.filename.endswith('.lua'):
            servers.get_lua_server().runscript(
                str(format.mangle_path(self.filename)))
        elif self.filename.endswith('.py'):
            servers.get_python_server().runscript(
                str(format.mangle_path(self.filename)))
Example #28
0
    def __on_selection_mode(self, event):
        mode = self.choice_selection_mode.GetSelection()
        menu = self.GetParent().get_menubar().get_menu('&View')
        succeed = False
        if mode == 0 and app.is_subentity_mode_active():
            result = cjr.confirm_yes_no(
                            app.get_top_window(),
                            "Do you want to save subentity changes?"
                            )
            save = (result == wx.ID_YES)
            succeed = app.get_object_state().setselectionmode( mode, save )
        else:
            succeed = app.get_object_state().setselectionmode( mode, False )

        if succeed:
            if mode == 0:
                id_selection = viewcmds.ID_SelectObjects
            elif mode == 1:
                id_selection = viewcmds.ID_SelectWaypoints
            else:
                id_selection = viewcmds.ID_SelectTerrainCells
            menu.Check( id_selection, True )
Example #29
0
 def __prepresets_process(self):
     # Ask for presets directory creation if it doesn't exist yet
     path = get_presets_path()
     if not os.path.exists( path ):
         msg = "The presets directory '%s' doesn't exist.\n" \
                     "A presets directory is needed to continue.\n\n" \
                     "Do you want to create it?" % path
         result = cjr.confirm_yes_no(
                         self.get_frame(),
                         msg
                         )
         if result == wx.ID_YES:
             os.makedirs( path )
     # Create subpaths if doesn't exist yet
     lib_path = format.append_to_path( path, "lib" )
     levels_path = format.append_to_path( path, "levels" )
     if os.path.exists( path ):
         # Create subpaths only if root path has been created
         if not os.path.exists( lib_path ):
             os.mkdir( lib_path )
         if not os.path.exists( levels_path ):
             os.mkdir( levels_path )
     # Return true only if all the presets subpaths finally exists
     return os.path.exists( lib_path ) and os.path.exists( levels_path )