Exemplo n.º 1
0
 def __build_open_item(self, menu, info):
     _open = gtk.MenuItem(_('Open'))
     
     open_menu = gtk.Menu()
     
     total_urls = util.detect_urls(info['msg'])
     total_users = util.detect_mentions(info['msg'])
     total_tags = util.detect_hashtags(info['msg'])
     total_groups = util.detect_groups(info['msg'])
     
     if not self.mainwin.request_groups_url(): 
         total_groups = []
     
     for u in total_urls:
         url = u if len(u) < 30 else u[:30] + '...'
         umenu = gtk.MenuItem(url)
         umenu.connect('button-release-event', self.__open_url_with_event, u)
         open_menu.append(umenu)
         if self.mainwin.read_config_value('General', 'expand-urls') == 'on':
             def __update_umenu(text):
                 try:
                     umenu.child.set_text( text )
                 except Exception, error:
                     print error
             self.mainwin.request_expanded_url(u, __update_umenu)
Exemplo n.º 2
0
 def __highlight_mentions(self, text):
     mentions = util.detect_mentions(text)
     if len(mentions) == 0: return text
     
     for h in mentions:
         if len(h) == 1: continue
         torep = '@%s' % h
         cad = '<span foreground="#%s">@%s</span>' % (self.mainwin.link_color, h)
         text = text.replace(torep, cad)
     return text
Exemplo n.º 3
0
 def __highlight_mentions(self, text):
     mentions = util.detect_mentions(text)
     if len(mentions) == 0: return text
     
     for h in mentions:
         if len(h) == 1: continue
         torep = '@%s' % h
         cad = '<span foreground="#%s">@%s</span>' % (self.mainwin.link_color, h)
         text = text.replace(torep, cad)
     return text
Exemplo n.º 4
0
 def __build_open_item(self, menu, info):
     _open = gtk.MenuItem(_('Open'))
     
     open_menu = gtk.Menu()
     
     total_urls = util.detect_urls(info['msg'])
     total_users = util.detect_mentions(info['msg'])
     total_tags = util.detect_hashtags(info['msg'])
     total_groups = util.detect_groups(info['msg'])
     
     if not self.mainwin.request_groups_url(): 
         total_groups = []
     
     for u in total_urls:
         url = u if len(u) < 30 else u[:30] + '...'
         umenu = gtk.MenuItem(url)
         umenu.connect('button-release-event', self.__open_url_with_event, u)
         open_menu.append(umenu)
     
     if len(total_urls) > 0 and len(total_tags) > 0: 
         open_menu.append(gtk.SeparatorMenuItem())
     
     for h in total_tags:
         hashtag = self.mainwin.request_hashtags_url() + h[1:]
         hmenu = gtk.MenuItem(h)
         hmenu.connect('button-release-event',
                       self.__open_url_with_event, hashtag)
         open_menu.append(hmenu)
         
     for h in total_groups:
         hashtag = '/'.join([self.mainwin.request_groups_url(), h[1:]]) 
         hmenu = gtk.MenuItem(h)
         hmenu.connect('button-release-event',
                       self.__open_url_with_event, hashtag)
         open_menu.append(hmenu)
         
     if (len(total_urls) > 0 or len(total_tags) > 0 or 
         len(total_groups) > 0) and len(total_users) > 0: 
         open_menu.append(gtk.SeparatorMenuItem())
     
     exist = []
     for m in total_users:
         if m == info['user'] or m in exist:
             continue
         exist.append(m)
         user_prof = '/'.join([self.mainwin.request_profiles_url(), m[1:]])
         mentmenu = gtk.MenuItem(m)
         mentmenu.connect('button-release-event', self.__open_url_with_event, user_prof)
         open_menu.append(mentmenu)
         
     _open.set_submenu(open_menu)
     if ((len(total_urls) > 0) or (len(total_users) > 0) or
        (len(total_tags) > 0) or (len(total_groups) > 0)):
         menu.append(_open)
     return menu
Exemplo n.º 5
0
 def __build_open_menu(self, user, msg):
     open = gtk.MenuItem(_('Open'))
     
     open_menu = gtk.Menu()
     
     total_urls = util.detect_urls(msg)
     total_users = util.detect_mentions(msg)
     total_tags = util.detect_hashtags(msg)
     
     for u in total_urls:
         url = u if len(u) < 30 else u[:30] + '...'
         umenu = gtk.MenuItem(url)
         umenu.connect('button-release-event', self.__open_url_with_event, u)
         open_menu.append(umenu)
     
     if len(total_urls) > 0 and len(total_tags) > 0: 
         open_menu.append(gtk.SeparatorMenuItem())
     
     for h in total_tags:
         ht = "#search?q=%23" + h[1:]
         hashtag = '/'.join(['http://twitter.com', ht])
         hmenu = gtk.MenuItem(h)
         hmenu.connect('button-release-event',
                       self.__open_url_with_event, hashtag)
         open_menu.append(hmenu)
         
     if (len(total_urls) > 0 or len(total_tags) > 0) and \
        len(total_users) > 0: 
         open_menu.append(gtk.SeparatorMenuItem())
     
     exist = []
     for m in total_users:
         if m == user or m in exist:
             continue
         exist.append(m)
         user_prof = '/'.join(['http://www.twitter.com', m[1:]])
         mentmenu = gtk.MenuItem(m)
         mentmenu.connect('button-release-event', self.__open_url_with_event, user_prof)
         open_menu.append(mentmenu)
         
     open.set_submenu(open_menu)
     if (len(total_urls) > 0) or (len(total_users) > 0) or \
        (len(total_tags) > 0): 
         return open
     else:
         return None
Exemplo n.º 6
0
 def __popup_menu(self, widget, event):
     model, row = widget.get_selection().get_selected()
     if (row is None):
         return False
     
     if (event.button == 3):
         user = model.get_value(row, 1)
         msg = model.get_value(row, 5)
         id = model.get_value(row, 6)
         in_reply_to_id = model.get_value(row, 8)
          
         menu = gtk.Menu()
         
         rtn = self.mainwin.request_popup_info(id, user)
         
         if rtn.has_key('busy'):
             busymenu = gtk.MenuItem(rtn['busy'])
             busymenu.set_sensitive(False)
             menu.append(busymenu)
         else:
             re = "@%s " % user
             rt = "RT @%s %s" % (user, msg)
             dm = "D @%s " % user
             
             re_all = re
             mentions = util.detect_mentions(msg)
             for h in mentions:
                 re_all += '%s ' % h
             
             reply = gtk.MenuItem(_('Reply'))
             reply_all = gtk.MenuItem(_('Reply All'))
             retweet_old = gtk.MenuItem(_('Retweet (Old)'))
             retweet = gtk.MenuItem(_('Retweet'))
             save = gtk.MenuItem(_('+ Fav'))
             unsave = gtk.MenuItem(_('- Fav'))
             delete = gtk.MenuItem(_('Delete'))
             direct = gtk.MenuItem(_('DM'))
             follow = gtk.MenuItem(_('Follow'))
             unfollow = gtk.MenuItem(_('Unfollow'))
             loading = gtk.MenuItem(_('Loading friends...'))
             loading.set_sensitive(False)
             usermenu = gtk.MenuItem('@' + user)
             inreplymenu = gtk.MenuItem(_('In reply to'))
             mutemenu = gtk.MenuItem(_('Mute'))
             
             open = self.__build_open_menu(user, msg)
             
             if not rtn['own']:
                 menu.append(reply)
                 if len(mentions) > 0:
                     menu.append(reply_all)
                 menu.append(retweet_old)
                 menu.append(retweet)
                 menu.append(direct)
                 
                 if not rtn.has_key('friend'):
                     item = loading
                 elif rtn['friend'] is True:
                     item = unfollow
                 elif rtn['friend'] is False:
                     item = follow
             else:
                 menu.append(delete)
                 
             if rtn['fav']:
                 menu.append(unsave)
             else:
                 menu.append(save)
                 
             if open:
                 menu.append(open)
             
             if in_reply_to_id:
                 menu.append(inreplymenu)
             
             menu.append(gtk.SeparatorMenuItem())
             menu.append(usermenu)
             if not rtn['own']: 
                 if item != loading and item != follow:
                     menu.append(mutemenu)
                 menu.append(item)
             
             user_profile = '/'.join(['http://www.twitter.com', user])
             usermenu.connect('activate', self.__open_url, user_profile)
             reply.connect('activate', self.__show_update_box, re, id, user)
             reply_all.connect('activate', self.__show_update_box, re_all, 
                 id, user)
             retweet_old.connect('activate', self.__show_update_box, rt)
             retweet.connect('activate', self.__retweet, id)
             direct.connect('activate', self.__show_update_box, dm)
             save.connect('activate', self.__fav, True, id)
             unsave.connect('activate', self.__fav, False, id)
             delete.connect('activate', self.__delete, id)
             follow.connect('activate', self.__follow, True, user)
             unfollow.connect('activate', self.__follow, False, user)
             inreplymenu.connect('activate', self.__in_reply_to,
                                 user, in_reply_to_id)
             mutemenu.connect('activate', self.__mute, user)
         
         menu.show_all()
         menu.popup(None, None, None, event.button , event.time)