def getHtml(self): href = self.url if self.url[:4] == "www.": href = "http://" + self.url elif self.url[:4] == "ftp.": href = "ftp://" + self.url return '<a href="%s">%s</a>' % (escape(href), escape(self.url))
def get( self, urls=True, smileys=True ): data = '' cePattern='' if self.ink: return '<object type="application/x-emesene-ink" class="%s">' \ '</object>' % (self.text,) if smileys == True and self.conversation != None: if self.username == self.conversation.switchboard.user: sub = self.subOCE msnOM = self.conversation.switchboard.msn.getMsnObjectsManager() for ce in msnOM.getIds(): cePattern += re.escape(escape(ce)) + '|' else: sub = self.subICE customEmoticons = self.conversation.customEmoticons\ .get( self.username ) for ce in customEmoticons: cePattern += re.escape(escape(ce)) + '|' text = self.text for item in self.parser.parse( self, text ): if type( item ) in (str, unicode): if cePattern!= '': item = re.sub( '('+cePattern[:-1]+')', sub, item ) data += item elif type(item) == Url: if urls: data += item.getHtml() else: data += str( item ) elif type(item) == Smiley: if smileys: data += item.getHtml() else: data += str( item ) return data
def getHtml( self ): href = self.url if self.url[:4] == 'www.': href = 'http://'+self.url elif self.url[:4] == 'ftp.': href = 'ftp://'+self.url return '<a href="%s">%s</a>' % (escape(href), escape(self.url))
def getGroupLabel(self, group): '''return the pango string to format the group''' if self.showCountContact: return '<b>%s ( %d/%d )</b>' % (escape(group.name), \ group.getOnlineUsersNumber(), group.getSize()) else: return '<b>%s</b>' % escape(group.name)
def getHtml( self ): if self.theme.getSmileyPath( self.smiley ) == None: print 'Can\'t find the smiley %s'%self.smiley return escape( self.smiley ) path = self.theme.getSmileyPath( self.smiley ).replace("%", "%25") if path.startswith('/'): url = 'file://' + path else: url = 'file:///' + path # Windows return '<img src="%s" alt="%s"/>' % (url, escape(self.smiley))
def getHtml( self ): if self.theme.getSmileyPath( self.smiley ) == None: print 'Can\'t find the smiley %s'%self.smiley return escape( self.smiley ) path = self.theme.getSmileyPath( self.smiley ).replace("%", "%25") if path.startswith('/'): url = 'file://' + path else: url = 'file://localhost/' + path # Windows return '<img src="%s" alt="%s"/>' % (url, escape(self.smiley))
def getGroupLabel(self, group): '''return the pango string to format the group''' if self.showCountContact: if group.id == 'nogroup': return '<b>%s ( %d/%d )</b>' % (_('No group'), \ group.getOnlineUsersNumber(), group.getSize()) return '<b>%s ( %d/%d )</b>' % (escape(group.name), \ group.getOnlineUsersNumber(), group.getSize()) else: return '<b>%s</b>' % escape(group.name)
def change_alias(proxy, contactID, alias, callback, *args): alias = str(common.escape(alias)) soap.manager.do_request(proxy, 'http://www.msn.com/webservices/AddressBook/ABContactUpdate', 'contacts.msn.com', 443, '/abservice/abservice.asmx', soap.templates.renameContact % (str(contactID), alias), callback, args)
def change_alias(proxy, contactID, alias, callback, *args): alias = str(common.escape(alias)) soap.manager.do_request(proxy, 'http://www.msn.com/webservices/AddressBook/ABContactUpdate', 'local-bay.contacts.msn.com', 443, '/abservice/abservice.asmx', soap.templates.renameContact % (str(contactID), alias), callback, args)
def newMail(self, msnp, From, FromAddr, Subject, MessageURL, PostURL, id): """ called when receiving mail """ if not (self.notifyNewMail and self.notifyEnabled(FromAddr)): return contact = self.msn.contactManager.getContact(FromAddr) if contact == None: text = _("From: ") + From + " <" + FromAddr + ">" userPixbuf = None else: text = _("From: ") + unescape( self.controller.unifiedParser.getParser(self.msn.getUserDisplayName(FromAddr)).get() ) userPixbuf = self.theme.getUserDisplayPicture(contact) text += "\n" + _("Subj: ") + escape(Subject) self.notificationManager.newNotification( _("New email") + "\n" + text, self.position, self.scroll, self.pixmap, self.close, self.openMail, (MessageURL, PostURL, id), userPixbuf, self.fontname, self.fontcolor, )
def get( self, urls=True, smileys=True ): data = '' cePattern='' if self.ink: return '<object type="application/x-emesene-ink" class="%s">' \ '</object>' % (self.text,) if smileys == True and self.conversation: if self.username == self.conversation.switchboard.user: sub = self.subOCE msnOM = self.conversation.switchboard.msn.getMsnObjectsManager() for ce in msnOM.getIds(): cePattern += re.escape(escape(ce)) + '|' else: sub = self.subICE customEmoticons = self.conversation.customEmoticons\ .get( self.username ) for ce in customEmoticons: cePattern += re.escape(escape(ce)) + '|' text = self.text for item in self.parser.parse( self, text ): if type( item ) in (str, unicode): if cePattern!= '': # this hack to the regexp fixes the empty messages bug. # thanks to dx for pointing out the line where shit happened # and to me (c10ud) for having the revelation (!) from # python re manuals. # p.s. currently handled: " ' softhyphen & > < # XOXO RegExp Girl item = re.sub(\ '(?<!")(?<!&apos)(?<!­)(?<!&)(?<!>)(?<!<)(' \ + cePattern[:-1] + ')', sub, item ) data += item elif type(item) == Url: if urls: data += item.getHtml() else: data += str( item ) elif type(item) == Smiley: if smileys: data += item.getHtml() else: data += str( item ) return data
def newMail(self, msnp, From, FromAddr, Subject, MessageURL, PostURL, id): ''' called when receiving mail ''' if not (self.notifyNewMail and self.notifyEnabled(FromAddr)): return contact, text = self.getNickPM(FromAddr, From) text = _('From: ') + text + '\n' + _('Subj: ') + escape(Subject) \ + '\n\n<span foreground="#AAAAAA">emesene</span>' self.notify(contact, _('New email'), text, 'mail', \ (MessageURL, PostURL, id))
def handler( data ): group = data.groupdict() if group['smiley']: list.append( Smiley(group['smiley'], self.theme) ) elif group['url']: list.append( Url( group['url'] ) ) elif group['other']: other = escape(str(group['other'])) if len(list)>0 and isinstance(list[-1], str): list[-1] += other else: list.append(other)
def handler( data ): group = data.groupdict() if group['smiley'] != None: list.append( Smiley(group['smiley'], self.theme) ) elif group['url'] != None: list.append( Url( group['url'] ) ) elif group['other'] != None: other = escape(str(group['other'])) if len(list)>0 and type( list[-1] ) == str: list[-1] += other else: list.append(other)
def newMail(self, msnp, From, FromAddr, Subject, MessageURL, PostURL, id): ''' called when receiving mail ''' if not (self.notifyNewMail and self.notifyEnabled(FromAddr)): return contact = self.msn.contactManager.getContact(FromAddr) if contact == None: text = _('From: ') + From +' <' + FromAddr + '>' userPixbuf = None else: text = _('From: ') + unescape(self.controller.unifiedParser.\ getParser(self.msn.getUserDisplayName(FromAddr)).get()) userPixbuf = self.theme.getUserDisplayPicture(contact) text += '\n' + _('Subj: ') + escape(Subject) self.notificationManager.newNotification(_('New email') \ + "\n" + text, self.position, self.scroll, self.pixmap, \ self.close, self.openMail, (MessageURL, PostURL, id), \ userPixbuf, self.fontname, self.fontcolor)
def newMail(self, msnp, From, FromAddr, Subject, MessageURL, PostURL, id): ''' called when receiving mail ''' if not (self.notifyNewMail and self.notifyEnabled(FromAddr)): return contact = self.msn.contactManager.getContact(FromAddr) if contact == None: text = _('From: ') + From + ' <' + FromAddr + '>' userPixbuf = None else: text = _('From: ') + unescape(self.controller.unifiedParser.\ getParser(self.msn.getUserDisplayName(FromAddr)).get()) userPixbuf = self.theme.getUserDisplayPicture(contact) text += '\n' + _('Subj: ') + escape(Subject) self.notificationManager.newNotification(_('New email') \ + "\n" + text, self.position, self.scroll, self.pixmap, \ self.close, self.openMail, (MessageURL, PostURL, id), \ userPixbuf, self.fontname, self.fontcolor)
def __init__(self, corner, scroll, offset, string, height = 128, \ width = 200, pixmap = None, closePixmap = None, \ callback = None, params = None, userPixbuf = None, \ font = None, color = None): gtk.Window.__init__(self) if corner == 0: self.set_gravity(gtk.gdk.GRAVITY_NORTH_WEST) elif corner == 1: self.set_gravity(gtk.gdk.GRAVITY_NORTH_EAST) elif corner == 2: self.set_gravity(gtk.gdk.GRAVITY_SOUTH_WEST) else: self.set_gravity(gtk.gdk.GRAVITY_SOUTH_EAST) self.set_property('can-focus', False) self.set_property('accept-focus', False) self.corner = corner self.scroll = scroll if scroll == 0: self.height = height self.max = width self.width = 1 else: self.width = width self.max = height self.height = 1 self.callback = callback self.set_geometry_hints(None, min_width=-1, min_height=-1, \ max_width=width, max_height=height) self.set_accept_focus(False) self.set_decorated(False) self.set_keep_above(True) self.set_skip_taskbar_hint(True) self.set_skip_pager_hint(True) if pixmap != None: self.set_app_paintable(True) self.realize() self.window.set_back_pixmap(pixmap, False) messageLabel = gtk.Label('<span foreground="' + color +'">' \ + escape(str(string)) + '</span>') messageLabel.set_use_markup(True) messageLabel.set_justify(gtk.JUSTIFY_CENTER) #messageLabel.set_line_wrap(True) messageLabel.set_ellipsize(pango.ELLIPSIZE_END) try: messageLabel.modify_font(pango.FontDescription(font)) except e: print e if closePixmap == None: close = gtk.Label() close.set_label("<span background=\"#cc0000\" foreground=" \ + color + "\"> X </span>") close.set_use_markup(True) else: close = gtk.Image() close.set_from_pixbuf(closePixmap) closeEventBox = gtk.EventBox() closeEventBox.set_visible_window(False) closeEventBox.set_events(gtk.gdk.BUTTON_PRESS_MASK) closeEventBox.connect("button_press_event", self.close) closeEventBox.add(close) hbox = gtk.HBox() vbox = gtk.VBox() lbox = gtk.HBox() title = gtk.Label("") title.set_use_markup(True) avatarImage = gtk.Image() if userPixbuf != None: userPixbuf = resizePixbuf(userPixbuf, 48, 48) avatarImage.set_from_pixbuf(userPixbuf) lboxEventBox = gtk.EventBox() lboxEventBox.set_visible_window(False) lboxEventBox.set_events(gtk.gdk.BUTTON_PRESS_MASK) lboxEventBox.connect("button_press_event", self.onClick, params) lboxEventBox.add(lbox) hbox.pack_start(title, True, True) hbox.pack_end(closeEventBox, False, False) lbox.pack_start(avatarImage, False, False, 10) lbox.pack_start(messageLabel, True, True, 5) vbox.pack_start(hbox, False, False) vbox.pack_start(lboxEventBox, True, True) self.grow(offset, False) self.add(vbox) vbox.show_all()
def __str__( self ): return escape(self.smiley)
def __init__(self, corner, scroll, offset, string, height = 128, \ width = 200, pixmap = None, closePixmap = None, \ callback = None, params = None, userPixbuf = None, \ font = None, color = None): gtk.Window.__init__(self, type=gtk.gdk.WINDOW_TOPLEVEL) if corner == 0: self.set_gravity(gtk.gdk.GRAVITY_NORTH_WEST) elif corner == 1: self.set_gravity(gtk.gdk.GRAVITY_NORTH_EAST) elif corner == 2: self.set_gravity(gtk.gdk.GRAVITY_SOUTH_WEST) else: self.set_gravity(gtk.gdk.GRAVITY_SOUTH_EAST) self.set_accept_focus(False) self.set_decorated(False) self.set_type_hint(gtk.gdk.WINDOW_TYPE_HINT_SPLASHSCREEN) self.corner = corner self.scroll = scroll if scroll == 0: self.height = height self.max = width self.width = 1 else: self.width = width self.max = height self.height = 1 self.callback = callback self.set_geometry_hints(None, min_width=-1, min_height=-1, \ max_width=width, max_height=height) if pixmap != None: self.set_app_paintable(True) self.realize() self.window.set_back_pixmap(pixmap, False) messageLabel = gtk.Label('<span foreground="' + color +'">' \ + escape(str(string)) + '</span>') messageLabel.set_use_markup(True) messageLabel.set_justify(gtk.JUSTIFY_CENTER) messageLabel.set_ellipsize(pango.ELLIPSIZE_END) try: messageLabel.modify_font(pango.FontDescription(font)) except e: print e if closePixmap == None: close = gtk.Label() close.set_label("<span background=\"#cc0000\" foreground=" \ + color + "\"> X </span>") close.set_use_markup(True) else: close = gtk.Image() close.set_from_pixbuf(closePixmap) closeEventBox = gtk.EventBox() closeEventBox.set_visible_window(False) closeEventBox.set_events(gtk.gdk.BUTTON_PRESS_MASK) closeEventBox.connect("button_press_event", self.close) closeEventBox.add(close) hbox = gtk.HBox() vbox = gtk.VBox() lbox = gtk.HBox() title = gtk.Label("") title.set_use_markup(True) avatarImage = gtk.Image() if userPixbuf != None: userPixbuf = resizePixbuf(userPixbuf, 48, 48) avatarImage.set_from_pixbuf(userPixbuf) lboxEventBox = gtk.EventBox() lboxEventBox.set_visible_window(False) lboxEventBox.set_events(gtk.gdk.BUTTON_PRESS_MASK) lboxEventBox.connect("button_press_event", self.onClick, params) lboxEventBox.add(lbox) self.connect("button_press_event", self.onClick, params) hbox.pack_start(title, True, True) hbox.pack_end(closeEventBox, False, False) lbox.pack_start(avatarImage, False, False, 10) lbox.pack_start(messageLabel, True, True, 5) vbox.pack_start(hbox, False, False) vbox.pack_start(lboxEventBox, True, True) self.grow(offset, False) self.add(vbox) vbox.show_all()