129 filename=
None, size=100, user_local_ns=
None, user_global_ns=
None):
131 """ Console interface building + initialization""" 135 GObject.GObject.__init__(self)
136 self.set_policy(Gtk.PolicyType.NEVER, Gtk.PolicyType.AUTOMATIC)
137 self.set_shadow_type (Gtk.ShadowType.NONE)
138 self.set_border_width(0)
139 self.view = Gtk.TextView()
140 self.view.modify_font (Pango.FontDescription(
"Mono 10"))
141 self.view.set_editable (
True)
142 self.view.set_wrap_mode(
True)
143 self.view.set_left_margin(0)
144 self.view.set_right_margin(0)
145 self.buffer = self.view.get_buffer()
146 self.buffer.create_tag (
'title',
148 weight=Pango.Weight.BOLD,
151 self.buffer.create_tag (
'subtitle',
155 self.buffer.create_tag (
'output',
158 self.buffer.create_tag (
'error',
160 style=Pango.Style.OBLIQUE,
162 self.buffer.create_tag (
'prompt',
164 weight=Pango.Weight.BOLD,
166 self.buffer.create_tag(
'0')
167 self.color_pat = re.compile(
r'\x01?\x1b\[(.*?)m\x02?')
168 for code
in ansi_colors:
169 self.buffer.create_tag(code,
170 foreground=ansi_colors[code],
172 for text, style
in banner:
173 self.write (text, style)
174 iter = self.buffer.get_iter_at_mark(self.buffer.get_insert())
175 self.buffer.create_mark (
'linestart', iter,
True)
176 self.view.add_events(Gdk.EventMask.KEY_PRESS_MASK)
177 self.view.connect (
'key-press-event', self.key_press_event)
180 self.killbuffer =
None 184 self.history_init(filename, size)
185 self.cout = io.StringIO()
186 self.cout.truncate(0)
188 if not user_local_ns:
189 user_local_ns = locals()
190 if not user_global_ns:
191 user_global_ns = globals()
193 if shelltype==
'ipython':
194 self.shell = ishell.Shell(argv,user_local_ns, user_global_ns,
195 cout=self.cout, cerr=self.cout,
196 input_func=self.raw_input)
198 self.shell = shell.Shell(user_local_ns,user_global_ns)
199 self.interrupt =
False 200 self.input_mode =
False 202 self.stdout = ConsoleOut (self, sys.stdout.fileno(),
'output')
203 self.stderr = ConsoleOut (self, sys.stderr.fileno(),
'error')
204 self.stdin = ConsoleIn (self, sys.stdin.fileno())
207 self.fifoname = tempfile.mktemp()
208 if not os.path.exists (self.fifoname):
209 os.mkfifo (self.fifoname)
210 self.piperead = os.open (self.fifoname, os.O_RDONLY | os.O_NONBLOCK)
211 self.pipewrite = os.open (self.fifoname, os.O_WRONLY | os.O_NONBLOCK)
212 self.shell.eval(self)
213 self.cout.truncate(0)