Changeset 3025

Show
Ignore:
Timestamp:
06/22/08 19:10:55 (5 years ago)
Author:
nopper
Message:

New Console implementation

Location:
branch/UmitPlugins/source-plugins/umit-console/sources
Files:
2 modified

Legend:

Unmodified
Added
Removed
  • branch/UmitPlugins/source-plugins/umit-console/sources/console/pyconsole.py

    r3022 r3025  
    4747    return prefix 
    4848 
     49class VirtualStdIn(object): 
     50    def __init__(self): 
     51        self.buffer = str() 
     52     
     53    def feed(self, txt): 
     54        if txt: 
     55            self.buffer += txt 
     56     
     57    def read(self, size): 
     58        t = self.buffer[0:size] 
     59        self.buffer = self.buffer[size + 1:] 
     60        return t 
     61     
     62    def readline(self): 
     63        t = self.buffer.split('\n') 
     64        self.buffer = "\n".join(t[1:]) 
     65        return t[0] 
     66     
     67    def readlines(self): 
     68        t = self.buffer.split('\n') 
     69        self.buffer = "" 
     70        return t 
     71 
    4972class _ReadLine(object): 
    5073 
     
    108131        self.history = _ReadLine.History() 
    109132        self.nonword_re = re.compile("[^\w\._]") 
     133        self.my_stdin = VirtualStdIn() 
    110134 
    111135    def freeze_undo(self): 
     
    212236        self.tab_pressed = 0 
    213237        handled = True 
     238         
     239        self.my_stdin.feed(event.string) 
    214240 
    215241        state = event.state & (gdk.SHIFT_MASK | 
     
    406432 
    407433    def do_raw_input(self, text): 
    408         pass 
    409  
    410     def write(self,whatever): 
     434        print "HERE" 
     435 
     436    def write(self, whatever): 
    411437        self.buffer.insert_at_cursor(whatever) 
    412  
     438     
     439    def readline(self): 
     440        self.my_stdin.readline() 
    413441 
    414442class _Console(_ReadLine, code.InteractiveInterpreter): 
     
    437465        self.run_on_raw_input = start_script 
    438466        self.raw_input(self.ps1) 
    439  
     467     
    440468    def __start(self): 
    441469        self.cmd_buffer = "" 
     
    474502 
    475503    def runcode(self, code): 
    476         saved = sys.stdout 
     504        savedo = sys.stdout 
     505        savedi = sys.stdin 
     506         
    477507        sys.stdout = self 
     508        sys.stdin = self 
     509         
    478510        try: 
    479511            eval(code, self.locals) 
     
    482514        except: 
    483515            self.showtraceback() 
    484         sys.stdout = saved 
     516             
     517        sys.stdout = savedo 
     518        sys.stdin = savedi 
    485519 
    486520    def complete_attr(self, start, end): 
     
    545579        return completions 
    546580 
    547  
    548581def ReadLineType(t=gtk.TextView): 
    549582    class readline(t, _ReadLine): 
  • branch/UmitPlugins/source-plugins/umit-console/sources/main.py

    r3022 r3025  
    2222import sys 
    2323 
    24 import console.pyconsole as pyconsole 
     24import console.console as console 
    2525 
    2626# yes we can do it 
     
    3232class ConsoleView(UmitView): 
    3333    def create_ui(self): 
    34         sw = gtk.ScrolledWindow() 
    35         sw.set_shadow_type(gtk.SHADOW_ETCHED_IN) 
    36         sw.set_policy(gtk.POLICY_AUTOMATIC, gtk.POLICY_AUTOMATIC) 
     34        con = console.Console(globals()) 
     35        con.banner() 
    3736 
    38         sw.add(pyconsole.Console(banner="UMIT Python Shell")) 
    39         self._main_widget.add(sw) 
     37        self._main_widget.add(con) 
    4038        self._main_widget.show_all() 
    4139