Nice! Some minor comments fooling around with it for a few minutes.
- view.set_editable(False)
- I don't see much of a reason to use named tags in PyGTK ... instead of
text.create_tag("match", background="green")
text.apply_tag_by_name("match",
text.get_iter_at_offset(start),
text.get_iter_at_offset(end))
I would generally do:
match_tag = text.create_tag(background="green")
text.apply_tag(match_tag, ...)
- Some internationalization issues ... if typeof(string) == str, then
m.span() gives you bytes not characters. GtkTextBuffer, sadly, doesn't
have get_iter_at_index() . So, the simpliest thing is to probably
string.decode("UTF-8") in that case and the same for pattern.
- it would be nice if the highlighting gave some idea of what the
divisions were between different matches and different groups within
matches. The simple way to do this would be to alternate between
different colors as you go between matches and alternate between
different underline styles, maybe single and double, as you go between
matches.
More ambitiously, I think it would be neat to have tooltip-like popups
to show the matched portion of the pattern string.
- Owen
Hmm, it's going to be hard to use colors for groups and matches ...
you might be able to do something with shades of blue for the first
match, shades of red for the second match, etc, but the result might
not be at all comprehensible. Another idea ... what if you highlighted
one match in full color with the group alternation, then highlighted
the other matches with a gray background, and had next/prev buttons
underneath the whole thing to move the highlighted group. (I'm can
come up with all sorts of ideas. That doesn't mean they are any good
;-)
> > More ambitiously, I think it would be neat to have tooltip-like popups
> > to show the matched portion of the pattern string.
>
> Something like
>
> ---------------
> "Foo Bar"
> Match 2 / 6
> Group 1 / 2
> ---------------
>
> perhaps?
I was thinking that the tooltip would actually show the regular
expression with the group highlighted, but that obviously is a bit of
a pain to implement, since you'd have to parse the regular expression
and figure out where the match groups are. Which is probably not worth
the effort.
- Owen