Changeset 1459

Show
Ignore:
Timestamp:
07/06/08 16:09:42 (2 months ago)
Author:
rob
Message:

Fixed #484: Added RunFilter? command to run an arbitary program using current buffer as input

Location:
trunk/peppy
Files:
3 modified

Legend:

Unmodified
Added
Removed
  • trunk/peppy/mainmenu.py

    r1453 r1459  
    469469        self.frame.open("about:demo.txt") 
    470470 
    471 class RunScript(SelectAction): 
     471 
     472class RunMixin(object): 
     473    @classmethod 
     474    def worksWithMajorMode(cls, mode): 
     475        return hasattr(mode, 'startInterpreter') 
     476     
     477    def isEnabled(self): 
     478        return hasattr(self.mode, 'startInterpreter') and not hasattr(self.mode, 'process') 
     479 
     480class RunScript(RunMixin, SelectAction): 
    472481    alias = "run-script" 
    473482    name = "Run" 
     
    477486    key_bindings = {'default': "F5"} 
    478487 
    479     @classmethod 
    480     def worksWithMajorMode(cls, mode): 
    481         return hasattr(mode, 'startInterpreter') 
    482      
    483     def isEnabled(self): 
    484         return hasattr(self.mode, 'startInterpreter') and not hasattr(self.mode, 'process') 
    485  
    486488    def action(self, index=-1, multiplier=1): 
    487489        self.mode.startInterpreter() 
    488490 
    489  
    490 class RunScriptWithArgs(RunScript): 
     491class RunScriptWithArgs(RunMixin, SelectAction): 
    491492    alias = "run-script-with-args" 
    492493    name = "Run with Args" 
     
    494495    icon = "icons/script_edit.png" 
    495496    default_menu = ("Tools", 2) 
    496      
    497     # If subclassing another action, make sure to reset global_id, or the 
    498     # menu system will use the existing global id for the new action 
    499     global_id = None 
    500497    key_bindings = {'default': "C-F5"} 
    501498 
     
    508505        self.mode.startInterpreter(text) 
    509506 
    510  
    511 class StopScript(RunScript): 
     507class RunFilter(RunMixin, SelectAction): 
     508    """Run an external program on this file""" 
     509    alias = "run-filter" 
     510    name = "Run Filter" 
     511    default_menu = ("Tools", 3) 
     512 
     513    def action(self, index=-1, multiplier=1): 
     514        minibuffer = TextMinibuffer(self.mode, self, label="Command line:", 
     515                                    initial = self.mode.getScriptArgs()) 
     516        self.mode.setMinibuffer(minibuffer) 
     517        self.mode.setStatusText("Enter command line, %s will be replaced by full path to file") 
     518 
     519    def processMinibuffer(self, minibuffer, mode, text): 
     520        self.mode.startCommandLine(text) 
     521 
     522class StopScript(RunMixin, SelectAction): 
    512523    alias = "stop-script" 
    513524    name = "Stop" 
    514525    tooltip = "Stop the currently running script" 
    515526    icon = 'icons/stop.png' 
    516     default_menu = ("Tools", 3) 
    517     global_id = None 
     527    default_menu = ("Tools", 9) 
    518528    key_bindings = {'win': "C-CANCEL", 'emacs': "C-CANCEL", 'mac': 'C-.'} 
    519529     
     
    884894                Undo, Redo, Cut, Copy, Paste, PasteAtColumn, SelectAll, 
    885895 
    886                 RunScript, RunScriptWithArgs, StopScript, 
     896                RunScript, RunScriptWithArgs, RunFilter, StopScript, 
    887897 
    888898                MajorModeSelect, MinorModeShow, SidebarShow, 
  • trunk/peppy/major.py

    r1457 r1459  
    10341034            self.scriptArgs = argstring 
    10351035             
    1036         if self.buffer.readonly or not self.classprefs.autosave_before_run: 
    1037             msg = "You must save this file to the local filesystem\nbefore you can run it through the interpreter." 
    1038             dlg = wx.MessageDialog(wx.GetApp().GetTopWindow(), msg, "Save the file!", wx.OK | wx.ICON_ERROR ) 
    1039             retval=dlg.ShowModal() 
    1040             return 
    1041         else: 
    1042             self.save() 
    1043  
    10441036        bangpath = None 
    10451037        first = self.GetLine(0) 
     
    10631055        else: 
    10641056            cmd = self.getCommandLine(bangpath) 
     1057            self.startCommandLine(cmd) 
     1058     
     1059    def expandCommandLine(self, cmd): 
     1060        """Expand the command line to include the filename of the buffer""" 
     1061        if '%' in cmd: 
     1062            cmd = cmd % self.buffer.getFilename() 
     1063        else: 
     1064            cmd = "%s %s" % (cmd, self.buffer.getFilename()) 
     1065        return cmd 
     1066     
     1067    def startCommandLine(self, cmd): 
     1068        """Attempt to create a process using the command line""" 
     1069        if hasattr(self, 'process'): 
     1070            self.frame.setStatusText("Already running a process.") 
     1071        else: 
     1072            if self.buffer.readonly or not self.classprefs.autosave_before_run: 
     1073                msg = "You must save this file to the local filesystem\nbefore you can run it through the interpreter." 
     1074                dlg = wx.MessageDialog(wx.GetApp().GetTopWindow(), msg, "Save the file!", wx.OK | wx.ICON_ERROR ) 
     1075                retval=dlg.ShowModal() 
     1076                return 
     1077            else: 
     1078                self.save() 
     1079 
     1080            cmd = self.expandCommandLine(cmd) 
    10651081            if self.classprefs.output_log == 0: 
    10661082                output = self 
  • trunk/peppy/plugins/error_log.py

    r1451 r1459  
    2121        BoolParam('show', False), 
    2222        BoolParam('always_scroll', False), 
    23         StrParam('filename_match_regex', "  File \"(.+)\", line ([0-9]+)", 'Regular expression used to match pathnames in the output'), 
     23        StrParam('filename_match_regex', "^  File \"(.+)\", line ([0-9]+)", 'Regular expression used to match pathnames in the output'), 
    2424        ) 
    2525 
     
    3232         
    3333        self.filere = re.compile(self.classprefs.filename_match_regex) 
     34        self.stdre = re.compile("^((?:[a-zA-Z]:)?.+):([0-9]+):") 
    3435 
    3536    def addMessage(self, text): 
     
    5758        self.scanForFilenames() 
    5859     
     60    def matchLine(self, text, i=0): 
     61        match = self.filere.search(text, i) 
     62        if match: 
     63            return match 
     64        match = self.stdre.search(text, i) 
     65        if match: 
     66            return match 
     67        return None 
     68     
    5969    def scanForFilenames(self): 
    6070        if not hasattr(self, 'last_matched_filename'): 
     
    6777        i = 0 
    6878        while i < len(text): 
    69             match = self.filere.search(text, i) 
     79            match = self.matchLine(text, i) 
    7080            if not match: 
    7181                break 
     
    8797            text = self.GetLine(line) 
    8898            #dprint("text=%s" % text) 
    89             match = self.filere.search(text) 
     99            match = self.matchLine(text) 
    90100            if match: 
    91101                filename = match.group(1)