Changeset 1439

Show
Ignore:
Timestamp:
07/01/08 21:49:42 (5 months ago)
Author:
rob
Message:

Fixed #469: added output_log classpref to JobControlMixin? to choose where output goes: minor mode or sidebar
* changed ErrorLogSidebar? to only print output to the requested frame
* added sidebar controller to wrap the JobOutputMixin? interface and send the output to the Information sidebar

Location:
trunk
Files:
4 modified

Legend:

Unmodified
Added
Removed
  • trunk/peppy/major.py

    r1429 r1439  
    4242from peppy.debug import * 
    4343from peppy.minor import * 
     44from peppy.sidebar import * 
    4445from peppy.yapsy.plugins import * 
    4546from peppy.editra import * 
     
    949950        PathParam('interpreter_exe', '', 'Program that can interpret this text and return results on standard output', fullwidth=True), 
    950951        BoolParam('autosave_before_run', True, 'Automatically save without prompting before running script'), 
     952        IndexChoiceParam('output_log', 
     953                         ['use minor mode', 'use sidebar'], 
     954                         1, 'Does the output stay in the tab (minor mode) or visible to all tabs in the frame (major mode)'), 
    951955        ) 
    952956 
     
    10521056        else: 
    10531057            cmd = self.getCommandLine(bangpath) 
    1054             ProcessManager().run(cmd, self.buffer.cwd(), self) 
    1055  
     1058            if self.classprefs.output_log == 0: 
     1059                output = self 
     1060            else: 
     1061                output = JobOutputSidebarController(self.frame, self.registerProcess, self.deregisterProcess) 
     1062            ProcessManager().run(cmd, self.buffer.cwd(), output) 
     1063 
     1064    def registerProcess(self, job): 
     1065        self.process = job 
     1066     
     1067    def deregisterProcess(self, job): 
     1068        del self.process 
     1069     
    10561070    def stopInterpreter(self): 
    10571071        """Interface used by actions to kill the currently running job. 
     
    10711085        self.log = self.findMinorMode("OutputLog") 
    10721086        if self.log: 
    1073             self.log.showMessage("\n" + _("Started %s on %s") % 
    1074                                  (job.cmd, 
    1075                                   time.asctime(time.localtime(time.time()))) + 
    1076                                  "\n") 
     1087            text = "\n" + _("Started %s on %s") % (job.cmd, time.asctime(time.localtime(time.time()))) + "\n" 
     1088            self.log.showMessage(text) 
    10771089 
    10781090    def stdoutCallback(self, job, text): 
     
    10911103        del self.process 
    10921104        if self.log: 
    1093             self.log.showMessage(_("Finished %s on %s") % 
    1094                                  (job.cmd, 
    1095                                   time.asctime(time.localtime(time.time()))) + 
    1096                                  "\n") 
     1105            text = "\n" + _("Finished %s on %s") % (job.cmd, time.asctime(time.localtime(time.time()))) + "\n" 
     1106            self.log.showMessage(text) 
    10971107 
    10981108 
  • trunk/peppy/plugins/error_log.py

    r1393 r1439  
    140140 
    141141    def showError(self, message=None): 
    142         if self.frame == wx.GetApp().GetTopWindow(): 
    143             paneinfo = self.frame._mgr.GetPane(self) 
     142        data = message.data 
     143        if isinstance(data, tuple) or isinstance(data, list): 
     144            frame = data[0] 
     145            text = data[1] 
     146        else: 
     147            frame = wx.GetApp().GetTopWindow() 
     148            text = data 
     149        if self.frame == frame: 
     150            paneinfo = frame._mgr.GetPane(self) 
    144151            if self.classprefs.unhide_on_message: 
    145152                if not paneinfo.IsShown(): 
    146153                    paneinfo.Show(True) 
    147                     self.frame._mgr.Update() 
    148             text = message.data 
     154                    frame._mgr.Update() 
    149155            if message.topic[-1] == 'wrap': 
    150156                columns = 72 
     
    177183        IntParam('min_height', 20), 
    178184    ) 
    179      
     185 
     186 
    180187class OutputLogMinorMode(MinorMode, LoggingSTC): 
    181188    """An error log using message passing. 
  • trunk/peppy/sidebar.py

    r1049 r1439  
    2121from peppy.debug import * 
    2222from peppy.lib.userparams import * 
    23  
     23from peppy.lib.processmanager import * 
    2424 
    2525class Sidebar(ClassPrefs, debugmixin): 
     
    8585        """ 
    8686        pass 
     87 
     88 
     89class JobOutputSidebarController(JobOutputMixin): 
     90    """Simple wrapper around the JobOutputMixin interface to direct all output 
     91    to the Information sidebar. 
     92    """ 
     93    def __init__(self, frame, startCallback, finishCallback): 
     94        self.frame = frame 
     95        self.startCallback = startCallback 
     96        self.finishCallback = finishCallback 
     97         
     98    def startupCallback(self, job): 
     99        """Callback from the JobOutputMixin when a job is successfully 
     100        started. 
     101        """ 
     102        self.startCallback(job) 
     103        text = "\n" + _("Started %s on %s") % (job.cmd, time.asctime(time.localtime(time.time()))) + "\n" 
     104        Publisher().sendMessage('peppy.log.info', (self.frame, text)) 
     105 
     106    def stdoutCallback(self, job, text): 
     107        """Callback from the JobOutputMixin for a block of text on stdout.""" 
     108        Publisher().sendMessage('peppy.log.info', (self.frame, text)) 
     109 
     110    def stderrCallback(self, job, text): 
     111        """Callback from the JobOutputMixin for a block of text on stderr.""" 
     112        Publisher().sendMessage('peppy.log.info', (self.frame, text)) 
     113 
     114    def finishedCallback(self, job): 
     115        """Callback from the JobOutputMixin when the job terminates.""" 
     116        self.finishCallback(job) 
     117        text = "\n" + _("Finished %s on %s") % (job.cmd, time.asctime(time.localtime(time.time()))) + "\n" 
     118        Publisher().sendMessage('peppy.log.info', (self.frame, text)) 
  • trunk/tests/samples/job-control.py

    r1393 r1439  
    33import time 
    44 
    5 import euaoeu 
     5#import euaoeu 
    66 
    77for x in range(100):