1 # -*- coding: utf-8 -*-
2 # sced (SuperCollider mode for gedit)
4 # Copyright 2012 Jakob Leben
5 # Copyright 2009 Artem Popov and other contributors (see AUTHORS)
7 # sced is free software:
8 # you can redistribute it and/or modify
9 # it under the terms of the GNU General Public License as published by
10 # the Free Software Foundation, either version 3 of the License, or
11 # (at your option) any later version.
13 # This program is distributed in the hope that it will be useful,
14 # but WITHOUT ANY WARRANTY; without even the implied warranty of
15 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 # GNU General Public License for more details.
18 # You should have received a copy of the GNU General Public License
19 # along with this program. If not, see <http://www.gnu.org/licenses/>.
28 def __init__(self
, pipe
, log_view
):
30 self
.__log
_view
= log_view
32 tag_table
= log_view
.buffer.get_tag_table()
33 self
.__tag
= gtk
.TextTag()
35 self
.__good
_tag
= gobject
.new(gtk
.TextTag
,
36 weight
= pango
.WEIGHT_BOLD
,
37 foreground
= "darkgreen",
38 paragraph_background
= "lightgreen")
40 self
.__bad
_tag
= gobject
.new(gtk
.TextTag
,
41 weight
= pango
.WEIGHT_BOLD
,
42 foreground
= "darkred",
43 paragraph_background
= "pink")
46 self
.__ugly
_tag
= gobject
.new(gtk
.TextTag
,
47 #weight = pango.WEIGHT_BOLD,
50 tag_table
.add(self
.__tag
)
51 tag_table
.add(self
.__good
_tag
)
52 tag_table
.add(self
.__bad
_tag
)
53 tag_table
.add(self
.__ugly
_tag
)
55 pipe_util
.start_reader(pipe
)
56 self
.__reader
_task
= gobject
.timeout_add(20, self
.__reader
_tick
)
58 def __reader_tick(self
):
59 res
= pipe_util
.get_buffer()
64 self
.__append
_to
_buffer
(unicode(res
, 'mac_latin2'))
67 def __append_to_buffer(self
, text
):
68 # FIXME: coloring the text is broken, so don't try to do it
70 buffer = self
.__log
_view
.buffer
72 buffer.insert(buffer.get_end_iter(), text
)
74 buffer.place_cursor(buffer.get_end_iter())
75 self
.__log
_view
.view
.scroll_mark_onscreen(buffer.get_insert())
79 if text
.startswith("ERROR"):
82 elif text
.startswith("WARNING") or text
.startswith("FAILURE"):
83 tags
= self
.__ugly
_tag
85 elif text
.startswith("StartUp done."):
86 tags
= self
.__good
_tag
90 buffer.insert_with_tags(buffer.get_end_iter(), text
.rstrip(), tags
)
91 buffer.insert(buffer.get_end_iter(), "\n")
93 buffer.place_cursor(buffer.get_end_iter())
94 self
.__log
_view
.view
.scroll_mark_onscreen(buffer.get_insert())
96 # only required for thread-based implementation
100 if not self
.__pipe
.closed
:
101 pipe_util
.stop_reader()
103 gobject
.source_remove(self
.__reader
_task
)