43
45
terminal, kw = make_terminal(term_type, **kw)
44
46
self.widget.pack_start(terminal.widget)
45
47
self.set_long_title(' '.join(command_args))
46
terminal.configure(self.service.opt('fonts_and_colours',
48
self.service.opt('fonts_and_colours',
50
self.service.opt('fonts_and_colours',
48
opts = self.service.options.fonts_and_colours
50
terminal.configure(opts.foreground_colour, opts.background_colour,
51
opts.font, opts.use_bold)
53
terminal.service = self.service
52
54
terminal.connect_child_exit(self.cb_exited)
53
55
terminal.connect_title(self.set_long_title)
54
56
terminal.execute(command_args, **kw)
55
57
self.grab_focus = terminal.widget.grab_focus
58
self.config = terminal.configure
57
60
def cb_exited(self):
60
63
view_location_map = {'View Pane':'view',
61
64
'Quick Pane':'content',
64
class terminal_manager(service.service):
66
display_name = 'Terminals'
68
multi_view_type = terminal_view
70
def get_multi_view_book_type(self):
71
opt = self.opt('general', 'terminal_location')
72
return view_location_map[opt]
73
multi_view_book = property(get_multi_view_book_type)
69
__order__ = ['general', 'shell', 'fonts_and_colours']
75
70
class shell(defs.optiongroup):
71
"""Options relating to the shell run in terminals"""
72
__order__ = ['command']
73
label = 'Shell Options'
77
74
class command(defs.option):
78
"""The command used for the shell."""
79
default = os.environ['SHELL'] or 'bash'
75
"""The command used for the shell"""
76
default = os.environ.get('SHELL', '')
80
77
rtype = types.string
78
label = 'Shell command'
82
79
class general(defs.optiongroup):
83
"""Terminal options."""
80
"""General options relating to the terminal emulator"""
81
__order__ = ['terminal_type', 'terminal_location']
82
label = 'General Options'
84
83
class terminal_type(defs.option):
85
"""The default terminal type used."""
84
"""The default terminal type used"""
87
rtype = types.stringlist('Vte')#, 'Moo')
86
rtype = types.stringlist('Vte', 'Moo')
87
label = 'Terminal Type'
88
88
class terminal_location(defs.option):
89
"""Where newly started terminals will appear by default"""
89
"""The pane where newly started terminals will appear by default"""
90
90
rtype = types.stringlist(*view_location_map.keys())
91
91
default = 'View Pane'
92
label = 'Terminal Location'
93
93
class fonts_and_colours(defs.optiongroup):
94
"""Fonts and colours for the terminal"""
94
"""Font and colour options for the terminal emulator"""
95
label = 'Fonts & Colours'
96
__order__ = ['background_colour', 'foreground_colour', 'font',
95
98
class background_colour(defs.option):
96
99
"""The background colour to be used"""
97
100
default = '#000000'
98
101
rtype = types.color
102
label = 'Background colour'
99
103
class foreground_colour(defs.option):
100
"""The background colour to be used"""
104
"""The foreground colour to be used"""
101
105
default = '#c0c0c0'
102
106
rtype = types.color
107
label = 'Foreground colour'
103
108
class font(defs.option):
104
109
"""The font to be used in terminals"""
105
110
default = 'Monospace 8'
106
111
rtype = types.font
113
class use_bold(defs.option):
114
"""Whether the terminal will display bold characters"""
115
rtype = types.boolean
117
label = 'Allow bold characters'
118
__markup__ = lambda self: 'Terminal Emulator'
121
class terminal_manager(service.service):
123
config_definition = TerminalConfig
125
class TerminalView(defs.View):
126
view_type = terminal_view
133
fmanager = self.boss.get_service("filemanager")
134
self._termact = gtk.Action('Terminal', 'Terminal',
135
'Open a terminal in this directory',
137
self._termact.connect('activate', self.on_act_terminal)
139
fmanager.cmd_register_toolbar_action(self._termact)
142
def on_act_terminal(self, action):
143
cwd = self.boss.call_command('filemanager', 'get_current_directory')
144
self.cmd_execute_shell(kwdict={'directory': cwd})
146
def cb_fonts_and_colours__foreground_colour(self, val):
147
self._update_view_config()
149
def cb_fonts_and_colours__background_colour(self, val):
150
self._update_view_config()
152
def cb_fonts_and_colours__font(self, val):
153
self._update_view_config()
155
def cb_fonts_and_colours__use_bold(self, val):
156
self._update_view_config()
160
def _update_view_config(self):
161
for view in self.views:
162
view.config(self.opts.fonts_and_colours__foreground_colour,
163
self.opts.fonts_and_colours__background_colour,
164
self.opts.fonts_and_colours__font,
165
self.opts.fonts_and_colours__use_bold)
167
def get_multi_view_book_type(self):
168
opt = self.opts.general__terminal_location
169
return view_location_map[opt]
170
multi_view_book = property(get_multi_view_book_type)
108
172
def cmd_execute(self, command_args=[], command_line='',
109
173
term_type=None, icon_name='terminal',
110
174
short_title='Terminal', kwdict={}):
111
175
if term_type == None:
112
term_type = self.opt('general', 'terminal_type').lower()
113
self.create_multi_view(term_type=term_type,
114
command_args=command_args,
116
short_title=short_title,
176
term_type = self.opts.general__terminal_type.lower()
177
view = self.create_view('TerminalView',
179
command_args=command_args,
181
short_title=short_title,
183
self.show_view(view=view)
184
self.views.append(view)
119
186
def cmd_execute_shell(self, term_type=None, kwdict={}):
120
shellcommand = self.opt('shell', 'command')
121
self.call('execute', command_args=[shellcommand],
187
shellcommand = self.opts.shell__command
188
self.cmd_execute(command_args=[shellcommand],
122
189
term_type=term_type, kwdict=kwdict)
124
191
@actions.action(stock_id='gtk-terminal',
243
311
title = term.get_window_title()
245
313
self.__term.connect('window-title-changed', title_changed)
317
fre = re.compile(r'(/.+):([0-9]+):')
318
pre = re.compile(r'File \"(/.+)\"\, line ([0-9]+)\,')
248
320
class moo_terminal(pida_terminal):
252
324
self.__term = moo.term.Term()
325
self.__term.connect('child-died', self.cb_exited)
327
self.it = self.__term.create_tag('a')
328
self.it.set_attributes(moo.term.TEXT_FOREGROUND, moo.term.BLUE)
329
self.pt = self.__term.create_tag('b')
330
self.pt.set_attributes(moo.term.TEXT_FOREGROUND, moo.term.RED)
332
self.__term.connect('new-line', self.cb_newline)
334
self.__term.connect('populate-popup', self.cb_popup)
336
def cb_popup(self, t, menu):
337
if not t.get_selection():
338
menu.get_children()[0].set_sensitive(False)
339
x, y = t.window_to_buffer_coords(*t.get_pointer())
340
i = t.get_iter_at_location(x, y)
341
if i.has_tag(self.it) or i.has_tag(self.pt):
343
if i.has_tag(self.it):
344
i.get_tag_start(self.it)
345
e.get_tag_end(self.it)
346
string = i.get_text(e)
347
filename, ln, empty = string.split(':')
348
elif i.has_tag(self.pt):
349
i.get_tag_start(self.pt)
350
e.get_tag_end(self.pt)
351
string = i.get_text(e)
352
filename, ln = pre.search(string).groups()
355
menu.add(gtk.SeparatorMenuItem())
356
a = gtk.Action('goto-line', 'Goto line', 'Goto the line',
358
mi = a.create_menu_item()
361
a.connect('activate', self.act_gotoline, filename, int(ln) - 1)
363
def cb_newline(self, t):
364
cursor_i = t.get_iter_at_cursor()
365
line_n = cursor_i.row - 1
366
startline_i = t.get_iter_at_line(line_n)
367
endline_i = startline_i.copy()
368
endline_i.forward_to_line_end()
369
line = startline_i.get_text(endline_i)
370
self._line_received(line, line_n)
372
def _line_received(self, line, line_n):
373
for r, tag in [(fre, self.it), (pre, self.pt)]:
374
match = r.search(line)
377
msl = t.get_iter_at_line_offset(line_n, match.start())
378
esl = t.get_iter_at_line_offset(line_n, match.end())
379
t.apply_tag(tag, msl, esl)
381
def act_gotoline(self, action, file, line):
382
self.service.boss.call_command('buffermanager', 'open_file_line',
383
filename=file, linenumber=line)
385
def get_line_at_click(self, x, y):
388
def get_word_at_click(self, x, y):
391
def cb_exited(self, term):
392
self.feed('Child exited\r\n', '1;34')
393
self.feed('Press any key to close.')
394
self.__term.add_events(gtk.gdk.KEY_PRESS_MASK)
395
self.__term.connect('key-press-event', self.cb_press_any_key)
397
def feed(self, text, color=None):
398
""" Feed text to the terminal, optionally coloured."""
399
if color is not None:
400
text = '\x1b[%sm%s\x1b[0m' % (color, text)
401
self.__term.feed(text)
403
def cb_press_any_key(self, term, event):
254
406
def execute(self, command_args, **kw):
255
407
self.__term.fork_argv(command_args, **kw)
409
def configure(self, fg, bg, font, use_bold):
410
self.__term.set_font_from_string(font)
411
self.__term.modify_text(gtk.STATE_NORMAL, gtk.gdk.color_parse(fg))
412
self.__term.modify_base(gtk.STATE_NORMAL, gtk.gdk.color_parse(bg))
257
414
def get_widget(self):
258
415
return self.__term
259
416
widget = property(get_widget)
261
def connect_child_exit(self):
264
418
def translate_kwargs(self, **kw):
266
420
if 'directory' in kw:
277
434
self.__sw = gtk.ScrolledWindow()
278
435
self.__sw.set_policy(gtk.POLICY_AUTOMATIC, gtk.POLICY_AUTOMATIC)
279
self.__view = gtk.TextView()
438
self.__view = moo.edit.TextView()
441
self.__view = gtk.TextView()
442
self.__is_moo = False
280
443
self.__sw.add(self.__view)
282
def configure(self, fg, bg, font):
445
def configure(self, fg, bg, font, use_bold):
283
446
model = self.__view.get_buffer()
284
self.__tag = model.create_tag('fixed', editable=False,
447
self.__view.modify_font(pango.FontDescription(font))
288
448
#bgcol = gtk.gdk.color_parse(bg)
289
449
#self.__view.modify_bg(gtk.STATE_NORMAL, bgcol)
290
450
#self.__view.modify_base(gtk.STATE_NORMAL, bgcol)
293
452
def translate_kwargs(self, **kw):
295
454
if 'directory' in kw:
296
455
kwdict['cwd'] = kw['directory']
457
kwdict['lang'] = kw['lang']
299
461
def execute(self, command_args, **kw):
462
if kw.has_key('lang'):
467
self.__view.set_lang_by_id(lang)
300
468
proc = popen(command_args, self.cb_completed, kw)
302
470
def get_widget(self):