[Sugar-devel] Bug No. #398

Dipankar Patro dipankar at seeta.in
Thu Sep 30 10:31:20 EDT 2010


Shan,

I think we should get back to the original format and try to implement the
search with the existing functions. For the first target, since the hilite
word function is nowhere to be found so far for gtk2viewer, try to implement
a system in which you can hilite the line of the search text, like I said
that day. Try your best.

About git diff, do as Tomeu instructed. run git diff inside jhbuild.
Sorry about that day, on which I hurriedly explained you how to create a gut
diff file in a source dir itself.

Regards,
Dipankar

On Thu, Sep 30, 2010 at 3:08 PM, Tomeu Vizoso <tomeu at sugarlabs.org> wrote:

> On Wed, Sep 29, 2010 at 17:49, Shanjit Singh Jajmann
> <shanjit at dev.seeta.in> wrote:
> > Hi,
> >
> > I have changed a few things in viewsource.py, and i am posting the diff
> > file,
>
> You should be making changes in sugar-jhbuild/source/sugar and use
> "git diff" to generate the diff. Ask your colleagues in Seeta if you
> have doubts.
>
> > the issue still remains the same although i have changed view type from
> > gtksourceview2 to gtk.textview.
>
> I have no idea why you think changing that may have helped with
> whatever problems you have found.
>
> Regards,
>
> Tomeu
>
> > --------------------------- git diff file.------------------------
> >
> > diff --git
> a/install/lib/python2.6/site-packages/jarabe/view/viewsource.py
> > b/install/lib/python2.6/site-packages/jarabe/view/viewsource.py
> > index 524db9e..24e361c 100644
> > --- a/install/lib/python2.6/site-packages/jarabe/view/viewsource.py
> > +++ b/install/lib/python2.6/site-packages/jarabe/view/viewsource.py
> > @@ -321,18 +321,18 @@ class Toolbar(gtk.Toolbar):
> >          search_item.show()
> >          search_entry.show()
> >
> > -        _search_prev = ToolButton('go-previous-paired')
> > -        _search_prev.set_tooltip(_('Previous'))
> > -    #    self._search_prev.connect('clicked', self._search_prev_cb)
> > -        self.insert(_search_prev, -1)
> > -        _search_prev.show()
> > +        self._search_prev = ToolButton('go-previous-paired')
> > +        self._search_prev.set_tooltip(_('Previous'))
> > +        self._search_prev.connect('clicked', self._search_prev_cb)
> > +        self.insert(self._search_prev, -1)
> > +        self._search_prev.show()
> >
> > -        _search_next = ToolButton('go-next-paired')
> > -        _search_next.set_tooltip(_('Next'))
> > -        #self._search_next.connect('clicked', self._search_next_cb)
> > -        self.insert(_search_next, -1)
> > -        _search_next.show()
> > -        #self._update_search_buttons()
> > +        self._search_next = ToolButton('go-next-paired')
> > +        self._search_next.set_tooltip(_('Next'))
> > +        self._search_next.connect('clicked', self._search_next_cb)
> > +        self.insert(self._search_next, -1)
> > +        self._search_next.show()
> > +        self._update_search_buttons()
> >
> >
> >          stop = ToolButton(icon_name='dialog-cancel')
> > @@ -343,10 +343,30 @@ class Toolbar(gtk.Toolbar):
> >
> >      def _search_entry_activate_cb(self, entry):
> >          self.viewer.set_search_text(entry.props.text)
> > +        self._update_search_buttons()
> >
> >      def _search_entry_changed_cb(self, entry):
> >          self.viewer.set_search_text(entry.props.text)
> > -
> > +        self._update_search_buttons()
> > +
> > +    def _search_prev_cb(self, button):
> > +        self.viewer.search_next('backward')
> > +        self._update_search_buttons()
> > +
> > +    def _search_next_cb(self, button):
> > +        self.viewer.search_next('forward')
> > +        self._update_search_buttons()
> > +
> > +    def _update_search_buttons(self,):
> > +        if len(self.viewer.search_text) == 0:
> > +            self._search_prev.props.sensitive = False
> > +            self._search_next.props.sensitive = False
> > +        else:
> > +            prev = self.viewer.get_next_result('backward')
> > +            next = self.viewer.get_next_result('forward')
> > +            self._search_prev.props.sensitive = prev != None
> > +            self._search_next.props.sensitive = next != None
> > +
> >      def _add_separator(self, expand=False):
> >          separator = gtk.SeparatorToolItem()
> >          separator.props.draw = False
> > @@ -452,22 +472,88 @@ class SourceDisplay(gtk.ScrolledWindow):
> >          self._buffer = gtksourceview2.Buffer()
> >          self._buffer.set_highlight_syntax(True)
> >
> > -        self._source_view = gtksourceview2.View(self._buffer)
> > -        self._source_view.set_editable(False)
> > -        self._source_view.set_cursor_visible(True)
> > -        self._source_view.set_show_line_numbers(True)
> > -        self._source_view.set_show_right_margin(True)
> > -        self._source_view.set_right_margin_position(80)
> > +        self.search_text = ' '
> > +
> > +        #self._source_view = gtksourceview2.View(self._buffer)
> > +        #self._source_view.set_editable(False)
> > +        #self._source_view.set_cursor_visible(True)
> > +        #self._source_view.set_show_line_numbers(True)
> > +        #self._source_view.set_show_right_margin(True)
> > +        #self._source_view.set_right_margin_position(80)
> >          #self._source_view.set_highlight_current_line(True) #FIXME: Ugly
> > color
> > -        self._source_view.modify_font(_SOURCE_FONT)
> > -        self.add(self._source_view)
> > -        self._source_view.show()
> > +        #self._source_view.modify_font(_SOURCE_FONT)
> > +       # self.add(self._source_view)
> > +       # self._source_view.show()
> > +
> > +        self._textview = gtk.TextView(self._buffer)
> > +        self.add(self._textview)
> > +        self._tagtable = gtk.TextTagTable()
> > +        hilite_tag = gtk.TextTag('search-hilite')
> > +        hilite_tag.props.background = '#FFFFB0'
> > +        self._tagtable.add(hilite_tag)
> > +        select_tag = gtk.TextTag('search-select')
> > +        select_tag.props.background = '#B0B0FF'
> > +        self._tagtable.add(select_tag)
> > +
> > +        scroll = gtk.ScrolledWindow()
> > +        scroll.set_policy(gtk.POLICY_AUTOMATIC, gtk.POLICY_AUTOMATIC)
> > +        scroll.add(self._textview)
> >
> > +        self._textview.show()
> > +
> >          self._file_path = None
> >
> >      def set_search_text(self, text):
> >          self.search_text = text
> > +        buffer = self._textview.get_buffer()
> >
> > +        start, end = buffer.get_bounds()
> > +       # buffer.remove_tag_by_name('search-hilite', start, end)
> > +       # buffer.remove_tag_by_name('search-select', start, end)
> > +
> > +        iter = buffer.get_start_iter()
> > +        while True:
> > +            next = iter.forward_search(text, 0)
> > +            if next is None: break
> > +            start, end = next
> > +            buffer.apply_tag_by_name('search-hilite', start, end)
> > +            iter = end
> > +
> > +        if self.get_next_result('current'):
> > +            self.search_next('current')
> > +        elif self.get_next_result('backward'):
> > +            self.search_next('backward')
> > +
> > +    def get_next_result(self, dir):
> > +        buffer = self._textview.get_buffer()
> > +
> > +        if dir == 'forward':
> > +            iter = buffer.get_iter_at_mark(buffer.get_insert())
> > +            iter.forward_char()
> > +        else:
> > +            iter = buffer.get_iter_at_mark(buffer.get_insert())
> > +
> > +        if dir == 'backward':
> > +            return iter.backward_search(self.search_text, 0)
> > +        else:
> > +            return iter.forward_search(self.search_text, 0)
> > +
> > +    def search_next(self, dir):
> > +        next = self.get_next_result(dir)
> > +        if next:
> > +            buffer = self._textview.get_buffer()
> > +
> > +            start, end = buffer.get_bounds()
> > +            buffer.remove_tag_by_name('search-select', start, end)
> > +
> > +            start, end = next
> > +            buffer.apply_tag_by_name('search-select', start, end)
> > +
> > +            buffer.place_cursor(start)
> > +
> > +            self._textview.scroll_to_iter(start, 0.1)
> > +            self._textview.scroll_to_iter(end, 0.1)
> > +
> >
> >
> >
> >
> > ----------------------------------
> >
> > Regards
> >
> > Shan
> >
> >
> >
> >
> > On Mon, Sep 27, 2010 at 8:25 PM, Tomeu Vizoso <tomeu at sugarlabs.org>
> wrote:
> >>
> >> On Mon, Sep 27, 2010 at 16:36, Shanjit Singh Jajmann
> >> <shanjit at dev.seeta.in> wrote:
> >> > Team,
> >> >
> >> > I am working on http://bugs.sugarlabs.org/ticket/398  : Regarding the
> >> > search
> >> > box, i have tried to introduce the same functionality as in the 'Log'
> >> > activity, in the toolbar of viewsource (jarabe/view/viewscreen.py),
> >> > however
> >> > i have run into some searching and highlighting issues regarding
> working
> >>
> >> Without knowing which are the issues is a bit hard to know how to
> >> help. Can you be more explicit and also post the patch?
> >>
> >> Regards,
> >>
> >> Tomeu
> >>
> >> > with gtksourceview used in the sourceview function of the same file.
> >> > Could
> >> > you please provide some pointers on how to achieve the searching and
> >> > highlighting ? (i could not get the bounds of the buffer created,
> >> > start,end
> >> > . The highlight function has me confused as it isn't working) or any
> >> > other
> >> > approach if possible.
> >> >
> >> > Regards
> >> > Shan
> >> >
> >> > _______________________________________________
> >> > Sugar-devel mailing list
> >> > Sugar-devel at lists.sugarlabs.org
> >> > http://lists.sugarlabs.org/listinfo/sugar-devel
> >> >
> >> >
> >
> >
> _______________________________________________
> Sugar-devel mailing list
> Sugar-devel at lists.sugarlabs.org
> http://lists.sugarlabs.org/listinfo/sugar-devel
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.sugarlabs.org/archive/sugar-devel/attachments/20100930/3e16bd6d/attachment-0001.htm 


More information about the Sugar-devel mailing list