Ejemplo n.º 1
0
    def on_new_cmd(self, event):
        # Ask for a command prototype
        dlg = newcmddlg.NewCommandDialog(self)
        result_ok = dlg.ShowModal() == wx.ID_OK
        if result_ok:
            cmd_proto = dlg.get_command_prototype()
        dlg.Destroy()

        # Create and add the new command to the selected class
        if result_ok:
            # Get the class name for the new command
            class_name = self.tree_classes.get_selected_class_name()
            if class_name is None:
                cjr.show_error_message(
                    "Cannot add commands to the selected class")
                return

            # Create an empty command for the selected class from a template
            self.__add_command(class_name, 'command', cmd_proto)

            # Add the new command to the command list
            self.list_cmds.Append(cmd_proto)
            servers.get_script_server().refreshclass(str(class_name))

            # Open for editing the new command script
            cmd_unpath = self.__get_cmd_path(class_name, cmd_proto, True)
            win = scripteditordlg.create_window(app.get_top_window(),
                                                cmd_unpath)
            win.display()
Ejemplo n.º 2
0
    def on_delete_cmd(self, event):
        # Ask for delete confirmation
        cmd_name = self.list_cmds.GetStringSelection()
        if cmd_name == "":
            return
        msg = "Deleting a command cannot be undone.\n\n" \
                    "Are you sure that you want to delete the " \
                    "command '%s'?" % cmd_name
        should_delete = cjr.warn_yes_no(self, msg)
        # Delete the command if the user has confirmed they want to
        if should_delete == wx.ID_YES:
            # Delete the script file
            class_name = self.tree_classes.get_selected_class_name()
            cmd_path = self.__get_cmd_path(class_name, cmd_name)
            os.remove(cmd_path)

            # Delete the class directory if there's no commmands left
            class_path = self.__get_class_path(class_name)
            if len(filedlg.get_file_list(class_path, ['lua'])) == 0:
                try:
                    os.rmdir(class_path)
                except:
                    cjr.show_error_message(
                        "Unable to delete the class commands directory '" + class_path + "'.\n" \
                        "Maybe is it not empty or is another application using it?\n" \
                        "Please, remove it manually."
                        )

            # Delete the command from the nclass in memory
            servers.get_script_server().refreshclass(str(class_name))

            # Remove the command from the commands list
            self.list_cmds.Delete(self.list_cmds.GetSelection())
            self.__update_buttons()
Ejemplo n.º 3
0
    def on_delete_cmd(self, event):
        # Ask for delete confirmation
        cmd_name = self.list_cmds.GetStringSelection()
        if cmd_name == "":
            return
        msg = "Deleting a command cannot be undone.\n\n" \
                    "Are you sure that you want to delete the " \
                    "command '%s'?" % cmd_name
        should_delete = cjr.warn_yes_no(self, msg)
        # Delete the command if the user has confirmed they want to
        if should_delete == wx.ID_YES:
            # Delete the script file
            class_name = self.tree_classes.get_selected_class_name()
            cmd_path = self.__get_cmd_path(class_name, cmd_name)
            os.remove( cmd_path )

            # Delete the class directory if there's no commmands left
            class_path = self.__get_class_path(class_name)
            if len( filedlg.get_file_list( class_path, ['lua'] ) ) == 0:
                try:
                    os.rmdir( class_path )
                except:
                    cjr.show_error_message(
                        "Unable to delete the class commands directory '" + class_path + "'.\n" \
                        "Maybe is it not empty or is another application using it?\n" \
                        "Please, remove it manually."
                        )

            # Delete the command from the nclass in memory
            servers.get_script_server().refreshclass( str(class_name) )

            # Remove the command from the commands list
            self.list_cmds.Delete( self.list_cmds.GetSelection() )
            self.__update_buttons()
Ejemplo n.º 4
0
    def on_new_cmd(self, event):
        # Ask for a command prototype
        dlg = newcmddlg.NewCommandDialog(self)
        result_ok = dlg.ShowModal() == wx.ID_OK
        if result_ok:
            cmd_proto = dlg.get_command_prototype()
        dlg.Destroy()

        # Create and add the new command to the selected class
        if result_ok:
            # Get the class name for the new command
            class_name = self.tree_classes.get_selected_class_name()
            if class_name is None:
                cjr.show_error_message(
                    "Cannot add commands to the selected class"
                    )
                return

            # Create an empty command for the selected class from a template
            self.__add_command( class_name, 'command', cmd_proto )

            # Add the new command to the command list
            self.list_cmds.Append( cmd_proto )
            servers.get_script_server().refreshclass( str(class_name) )

            # Open for editing the new command script
            cmd_unpath = self.__get_cmd_path(class_name, cmd_proto, True)
            win = scripteditordlg.create_window(
                        app.get_top_window(), 
                        cmd_unpath 
                        )
            win.display()
Ejemplo n.º 5
0
 def on_new_class(self, event):
     # Ask for a class name
     dlg = wx.TextEntryDialog(
                 None, 
                 "Enter the class name", 
                 "New class"
                 )
     result_ok = dlg.ShowModal() == wx.ID_OK
     if result_ok:
         class_name = dlg.GetValue().capitalize()
     dlg.Destroy()
     
     # Create the new class
     if result_ok:
         # Do some name validations
         ec_server = servers.get_entity_class_server()
         if not ec_server.checkclassname( str(class_name) ):
             cjr.show_error_message(
                 "Invalid class name"
                 )
             return
         k_server = servers.get_kernel_server()
         if k_server.findclass( str(class_name) ) != "":
             cjr.show_error_message(
                 "There is already another class called '%s'" % class_name
                 )
             return
         
         # Finally create the class
         parent_name = self.tree_classes.get_selected_class_name()
         if not ec_server.newclass( str(parent_name), str(class_name) ):
             msg = "Unknown error.\n\n" \
                         "Unable to create the class '%s'." % class_name
             cjr.show_error_message(msg)
             return
         set_nclass_dirty_flag(True)
         servers.get_script_server().addclass( str(class_name) )
         
         # For some classes, add commands and implementation by default
         class_group = self.tree_classes.get_current_class_group()
         if class_group is not None:
             add_cmds_func_name = '_CommandManagerDialog__add_commands_of_' + class_group
             if CommandManagerDialog.__dict__.has_key( add_cmds_func_name ):
                 CommandManagerDialog.__dict__[add_cmds_func_name](
                     self, 
                     class_name 
                     )
                 servers.get_script_server().refreshclass( str(class_name) )
         
         # Refresh the branch of the currently selected class
         self.tree_classes.on_new_class( class_name )
Ejemplo n.º 6
0
    def on_new_class(self, event):
        # Ask for a class name
        dlg = wx.TextEntryDialog(None, "Enter the class name", "New class")
        result_ok = dlg.ShowModal() == wx.ID_OK
        if result_ok:
            class_name = dlg.GetValue().capitalize()
        dlg.Destroy()

        # Create the new class
        if result_ok:
            # Do some name validations
            ec_server = servers.get_entity_class_server()
            if not ec_server.checkclassname(str(class_name)):
                cjr.show_error_message("Invalid class name")
                return
            k_server = servers.get_kernel_server()
            if k_server.findclass(str(class_name)) != "":
                cjr.show_error_message(
                    "There is already another class called '%s'" % class_name)
                return

            # Finally create the class
            parent_name = self.tree_classes.get_selected_class_name()
            if not ec_server.newclass(str(parent_name), str(class_name)):
                msg = "Unknown error.\n\n" \
                            "Unable to create the class '%s'." % class_name
                cjr.show_error_message(msg)
                return
            set_nclass_dirty_flag(True)
            servers.get_script_server().addclass(str(class_name))

            # For some classes, add commands and implementation by default
            class_group = self.tree_classes.get_current_class_group()
            if class_group is not None:
                add_cmds_func_name = '_CommandManagerDialog__add_commands_of_' + class_group
                if CommandManagerDialog.__dict__.has_key(add_cmds_func_name):
                    CommandManagerDialog.__dict__[add_cmds_func_name](
                        self, class_name)
                    servers.get_script_server().refreshclass(str(class_name))

            # Refresh the branch of the currently selected class
            self.tree_classes.on_new_class(class_name)
Ejemplo n.º 7
0
    def on_delete_class(self, event):
        # Ask for delete confirmation
        class_name = self.tree_classes.get_selected_class_name()
        if class_name is None:
            return
        msg = "Deleting a class cannot be undone.\n\n" \
                    "Are you sure that you want to delete " \
                    "the class '%s'?" % class_name
        should_delete = cjr.warn_yes_no(
                                self, 
                                msg
                                )
        # Delete the class if the user has said they want to go ahead
        if should_delete == wx.ID_YES:
            class_group = self.tree_classes.get_current_top_class_group()
            # Forbid deleting some classes in some situations
            if class_group is not None:
                can_delete_func_name = '_CommandManagerDialog__can_delete_' + class_group
                if CommandManagerDialog.__dict__.has_key(can_delete_func_name):
                    if not CommandManagerDialog.__dict__[can_delete_func_name](self, class_name):
                        return

            # Delete the class
            servers.get_script_server().deleteclass( str(class_name) )
            if not servers.get_entity_class_server().removeclass( str(class_name) ):
                msg = "Couldn't delete the class '" + class_name + "'.\n" \
                      "Causes may be an instantiated object of that class, " \
                      "a class with children or a native class."
                cjr.show_error_message(msg)
                return
            set_nclass_dirty_flag( True )

            # Delete the class directory
            class_path = self.__get_class_path( class_name )
            if os.path.exists( class_path ):
                remove_class_dir( class_path )

            # Refresh the class tree (and indirectly the command list)
            self.tree_classes.on_delete_class()
Ejemplo n.º 8
0
    def on_delete_class(self, event):
        # Ask for delete confirmation
        class_name = self.tree_classes.get_selected_class_name()
        if class_name is None:
            return
        msg = "Deleting a class cannot be undone.\n\n" \
                    "Are you sure that you want to delete " \
                    "the class '%s'?" % class_name
        should_delete = cjr.warn_yes_no(self, msg)
        # Delete the class if the user has said they want to go ahead
        if should_delete == wx.ID_YES:
            class_group = self.tree_classes.get_current_top_class_group()
            # Forbid deleting some classes in some situations
            if class_group is not None:
                can_delete_func_name = '_CommandManagerDialog__can_delete_' + class_group
                if CommandManagerDialog.__dict__.has_key(can_delete_func_name):
                    if not CommandManagerDialog.__dict__[can_delete_func_name](
                            self, class_name):
                        return

            # Delete the class
            servers.get_script_server().deleteclass(str(class_name))
            if not servers.get_entity_class_server().removeclass(
                    str(class_name)):
                msg = "Couldn't delete the class '" + class_name + "'.\n" \
                      "Causes may be an instantiated object of that class, " \
                      "a class with children or a native class."
                cjr.show_error_message(msg)
                return
            set_nclass_dirty_flag(True)

            # Delete the class directory
            class_path = self.__get_class_path(class_name)
            if os.path.exists(class_path):
                remove_class_dir(class_path)

            # Refresh the class tree (and indirectly the command list)
            self.tree_classes.on_delete_class()
Ejemplo n.º 9
0
 def on_refresh_class(self, event):
     class_name = self.tree_classes.get_selected_class_name()
     servers.get_script_server().refreshclass(str(class_name))
Ejemplo n.º 10
0
 def on_refresh_class(self, event):
     class_name = self.tree_classes.get_selected_class_name()
     servers.get_script_server().refreshclass( str(class_name) )
Ejemplo n.º 11
0
 def on_refresh_commands(self, event):
     """Reload all the command so any change is refreshed in memory"""
     servers.get_script_server().refreshclasses()