# Path: wimpiggy/pseudoclient.py
# class PseudoclientWindow(gtk.Window):
#     """A gtk.Window that acts like an ordinary client.
# 
#     All the wm-magic that would normally accrue to a window created within our
#     process is removed.
# 
#     Keyword arguments (notably 'type') are forwarded to
#     gtk.Window.__init__.
# 
#     The reason this is a separate class, as opposed to say a gtk.Window
#     factory method on wm, is that this way allows for subclassing."""
#     
#     def __init__(self, wm, **kwargs):
#         gtk.Window.__init__(self, **kwargs)
#         wm._make_window_pseudoclient(self)
# 
# Path: parti/addons/ipython_view.py
# class IPythonView(ConsoleView, IterableIPShell):
#   def __init__(self):
#     ConsoleView.__init__(self)
#     self.cout = StringIO()
#     IterableIPShell.__init__(self, cout=self.cout,cerr=self.cout,
#                              input_func=self.raw_input)
#     self.connect('key_press_event', self.keyPress)
#     self.execute()
#     self.cout.truncate(0)
#     self.showPrompt(self.prompt)
#     self.interrupt = False
# 
#   def raw_input(self, prompt=''):
#     if self.interrupt:
#       self.interrupt = False
#       raise KeyboardInterrupt
#     return self.getCurrentLine()
# 
#   def keyPress(self, widget, event):
#     if event.state & gtk.gdk.CONTROL_MASK and event.keyval == 99:
#       self.interrupt = True
#       self._processLine()
#       return True
#     elif event.keyval == gtk.keysyms.Return:
#       self._processLine()
#       return True
#     elif event.keyval == gtk.keysyms.Up:
#       self.changeLine(self.historyBack())
#       return True
#     elif event.keyval == gtk.keysyms.Down:
#       self.changeLine(self.historyForward())
#       return True
#     elif event.keyval == gtk.keysyms.Tab:
#       if not self.getCurrentLine().strip():
#         return False
#       completed, possibilities = self.complete(self.getCurrentLine())
#       if len(possibilities) > 1:
#         slice = self.getCurrentLine()
#         self.write('\n')
#         for symbol in possibilities:
#           self.write(symbol+'\n')
#         self.showPrompt(self.prompt)
#       self.changeLine(completed or slice)
#       return True
# 
#   def _processLine(self):
#     self.history_pos = 0
#     self.execute()
#     rv = self.cout.getvalue()
#     if rv: rv = rv.strip('\n')
#     self.showReturned(rv)
#     self.cout.truncate(0)


import gtk
from wimpiggy.pseudoclient import PseudoclientWindow
from parti.addons.ipython_view import IPythonView
# This file is part of Parti.
# Copyright (C) 2008, 2009 Nathaniel Smith <njs@pobox.com>
# Parti is released under the terms of the GNU GPL v2, or, at your option, any
# later version. See the file COPYING for details.


def spawn_repl_window(wm, namespace):
    window = PseudoclientWindow(wm)
    window.set_resizable(True)
    window.set_title("Parti REPL")
    scroll = gtk.ScrolledWindow()
    scroll.set_policy(gtk.POLICY_AUTOMATIC,gtk.POLICY_AUTOMATIC)

# Path: wimpiggy/pseudoclient.py
# class PseudoclientWindow(gtk.Window):
#     """A gtk.Window that acts like an ordinary client.
# 
#     All the wm-magic that would normally accrue to a window created within our
#     process is removed.
# 
#     Keyword arguments (notably 'type') are forwarded to
#     gtk.Window.__init__.
# 
#     The reason this is a separate class, as opposed to say a gtk.Window
#     factory method on wm, is that this way allows for subclassing."""
#     
#     def __init__(self, wm, **kwargs):
#         gtk.Window.__init__(self, **kwargs)
#         wm._make_window_pseudoclient(self)
# 
# Path: parti/addons/ipython_view.py
# class IPythonView(ConsoleView, IterableIPShell):
#   def __init__(self):
#     ConsoleView.__init__(self)
#     self.cout = StringIO()
#     IterableIPShell.__init__(self, cout=self.cout,cerr=self.cout,
#                              input_func=self.raw_input)
#     self.connect('key_press_event', self.keyPress)
#     self.execute()
#     self.cout.truncate(0)
#     self.showPrompt(self.prompt)
#     self.interrupt = False
# 
#   def raw_input(self, prompt=''):
#     if self.interrupt:
#       self.interrupt = False
#       raise KeyboardInterrupt
#     return self.getCurrentLine()
# 
#   def keyPress(self, widget, event):
#     if event.state & gtk.gdk.CONTROL_MASK and event.keyval == 99:
#       self.interrupt = True
#       self._processLine()
#       return True
#     elif event.keyval == gtk.keysyms.Return:
#       self._processLine()
#       return True
#     elif event.keyval == gtk.keysyms.Up:
#       self.changeLine(self.historyBack())
#       return True
#     elif event.keyval == gtk.keysyms.Down:
#       self.changeLine(self.historyForward())
#       return True
#     elif event.keyval == gtk.keysyms.Tab:
#       if not self.getCurrentLine().strip():
#         return False
#       completed, possibilities = self.complete(self.getCurrentLine())
#       if len(possibilities) > 1:
#         slice = self.getCurrentLine()
#         self.write('\n')
#         for symbol in possibilities:
#           self.write(symbol+'\n')
#         self.showPrompt(self.prompt)
#       self.changeLine(completed or slice)
#       return True
# 
#   def _processLine(self):
#     self.history_pos = 0
#     self.execute()
#     rv = self.cout.getvalue()
#     if rv: rv = rv.strip('\n')
#     self.showReturned(rv)
#     self.cout.truncate(0)


# Path: parti/addons/ipython_embed.py
import gtk
from wimpiggy.pseudoclient import PseudoclientWindow
from parti.addons.ipython_view import IPythonView

# This file is part of Parti.
# Copyright (C) 2008, 2009 Nathaniel Smith <njs@pobox.com>
# Parti is released under the terms of the GNU GPL v2, or, at your option, any
# later version. See the file COPYING for details.


def spawn_repl_window(wm, namespace):
    window = PseudoclientWindow(wm)
    window.set_resizable(True)
    window.set_title("Parti REPL")
    scroll = gtk.ScrolledWindow()
    scroll.set_policy(gtk.POLICY_AUTOMATIC,gtk.POLICY_AUTOMATIC)

    view = IPythonView()