~jconti/ubuntu/precise/emesene/fix-956422

« back to all changes in this revision

Viewing changes to htmltextview.py

  • Committer: Bazaar Package Importer
  • Author(s): Devid Antonio Filoni
  • Date: 2010-04-14 01:33:51 UTC
  • mfrom: (1.1.6 upstream)
  • Revision ID: james.westby@ubuntu.com-20100414013351-r2icbt5gs4ai71j8
Tags: 1.6.1-0ubuntu1
* New upstream release (LP: #562646).
* Fix missing-debian-source-format lintian warning.
* Refresh 20_dont_build_own_libmimic.patch patch.
* Bump Standards-Version to 3.8.4.

Show diffs side-by-side

added added

removed removed

Lines of Context:
429
429
                ## hackable ;)
430
430
                loader = gtk.gdk.PixbufLoader()
431
431
                loader.write(mem); loader.close()
432
 
                
 
432
 
433
433
                anchor = self.textbuf.create_child_anchor(self.iter)
434
434
                img = AnimatedResizableImage(100, 100, self.canResize)
435
435
                img.set_tooltip(attrs['alt'])
437
437
                img.show()
438
438
                self.textview.add_child_at_anchor(img, anchor)
439
439
                self.textview.scrollLater()
 
440
                self.textview.emotes[anchor] = img
440
441
            
441
442
            except Exception, ex:
442
443
                pixbuf = None
666
667
        self._changed_cursor = False
667
668
        self.linkColor = "#0000FF"
668
669
 
 
670
        self.connect('copy-clipboard', self._on_copy_clipboard)
 
671
        self.clipboard = gtk.Clipboard(selection=gtk.gdk.atom_intern("CLIPBOARD"))
 
672
        self.get_buffer().add_selection_clipboard(self.clipboard)
 
673
        self.emotes = {}
 
674
 
669
675
        self.connect("motion-notify-event", self.__motion_notify_event)
670
676
        self.connect("leave-notify-event", self.__leave_event)
671
677
        self.connect("enter-notify-event", self.__motion_notify_event)
845
851
        if not self.isScrollLocked():
846
852
            # very ugly but quite effective.
847
853
            gobject.timeout_add(200, self.scrollToBottom, True)
 
854
 
 
855
    def _on_copy_clipboard(self, textview):
 
856
        ''' replaces the copied text with a new text with the
 
857
        alt text of the images selected at copying '''
 
858
        buffer = textview.get_buffer()
 
859
        if buffer.get_has_selection():
 
860
            iterStart, iterEnd = buffer.get_selection_bounds()
 
861
            if iterStart.get_offset() > iterEnd.get_offset():
 
862
                temp = start.copy()
 
863
                iterStart = iterEnd.copy()
 
864
                iterEnd = temp.copy() #set the right begining
 
865
 
 
866
            text = buffer.get_slice(iterStart, iterEnd)
 
867
 
 
868
            #TODO: magic string '\xef\xbf\xbc', object replacement special char
 
869
            while iterStart.forward_search('\xef\xbf\xbc', \
 
870
                             gtk.TEXT_SEARCH_VISIBLE_ONLY):
 
871
 
 
872
                iterPos, iterEnd = iterStart.forward_search('\xef\xbf\xbc', \
 
873
                                  gtk.TEXT_SEARCH_VISIBLE_ONLY)
 
874
                anchor = iterPos.get_child_anchor()
 
875
                if anchor and anchor.get_widgets():
 
876
                    widget = anchor.get_widgets()[0]
 
877
                    if isinstance(widget, gtk.EventBox):
 
878
                        alt = anchor.get_widgets()[0].child.get_tooltip_text()
 
879
                    else:
 
880
                        alt = anchor.get_widgets()[0].get_tooltip_text()
 
881
                elif anchor is None:
 
882
                    alt = ''
 
883
                
 
884
                text = text.replace('\xef\xbf\xbc', alt, 1)
 
885
 
 
886
                iterStart = iterEnd
 
887
 
 
888
            self.clipboard.set_text(text)
 
889
            self.clipboard.store()
 
890
 
 
891
    def clear(self):
 
892
        self.get_buffer().set_text('')
 
893
        self.emotes = {}
848
894
            
849
895
if __name__ == '__main__':
850
896
    sw = gtk.ScrolledWindow()