def __get_contact_pixbuf_or_default(self, contact): '''try to return a pixbuf of the user picture or the default picture ''' if contact.picture: try: animation = gtk.gdk.PixbufAnimation(contact.picture) except gobject.GError: pix = utils.safe_gtk_pixbuf_load(gui.theme.image_theme.user, (self.avatar_size, self.avatar_size)) picture = gtk.image_new_from_pixbuf(pix) return picture if animation.is_static_image(): pix = utils.safe_gtk_pixbuf_load(contact.picture, (self.avatar_size, self.avatar_size)) picture = gtk.image_new_from_pixbuf(pix) else: picture = gtk.image_new_from_animation(animation) else: pix = utils.safe_gtk_pixbuf_load(gui.theme.image_theme.user, (self.avatar_size, self.avatar_size)) picture = gtk.image_new_from_pixbuf(pix) return picture
def __get_contact_pixbuf_or_default(self, path): '''try to return a pixbuf of the user picture or the default picture ''' pixbuf = utils.safe_gtk_pixbuf_load( path, (self.avatar_size, self.avatar_size)) if not pixbuf: pixbuf = utils.safe_gtk_pixbuf_load( gui.theme.image_theme.user, (self.avatar_size, self.avatar_size)) picture = gtk.image_new_from_pixbuf(pixbuf) return picture
def _on_contact_change_something(self, *args): """ update the menu when contacts change something """ if len(args) == 3: account, type_change, value_change = args elif len(args) == 4: account, type_change, value_change, do_notify = args if type_change == 'status': contact = self.main_window.session.contacts.get(account) if not contact: return time = strftime('[%H:%M:%S]', localtime()) stat = e3.status.STATUS[contact.status] if hasattr(gui.theme, "image_theme"): status = gui.theme.image_theme.status_icons[contact.status] else: status = gui.theme.status_icons[contact.status] pixbuf = utils.safe_gtk_pixbuf_load(status) pixbuf.scale_simple(20, 20, gtk.gdk.INTERP_BILINEAR) display_name = Renderers.msnplus_to_plain_text(contact.display_name) self.model.prepend([time, pixbuf, contact.status, display_name]) self.set_active(0)
def _on_contact_change_something(self, *args): """ update the menu when contacts change something """ if len(args) == 3: account, type_change, value_change = args elif len(args) == 4: account, type_change, value_change, do_notify = args if type_change == 'status': contact = self.main_window.session.contacts.get(account) if not contact: return time = strftime('[%H:%M:%S]', localtime()) stat = e3.status.STATUS[contact.status] if hasattr(gui.theme, "image_theme"): status = gui.theme.image_theme.status_icons[contact.status] else: status = gui.theme.status_icons[contact.status] pixbuf = utils.safe_gtk_pixbuf_load(status) pixbuf.scale_simple(20, 20, gtk.gdk.INTERP_BILINEAR) display_name = Plus.msnplus_strip(contact.display_name) self.model.prepend([time, pixbuf, contact.status, display_name]) self.set_active(0)
def __init__(self, main_window): """constructor""" self.model = gtk.ListStore(gtk.gdk.Pixbuf, \ gobject.TYPE_INT, gobject.TYPE_STRING) gtk.ComboBox.__init__(self, self.model) self.main_window = main_window self.status = None status_pixbuf_cell = gtk.CellRendererPixbuf() status_text_cell = gtk.CellRendererText() self.pack_start(status_pixbuf_cell, False) self.pack_start(status_text_cell, False) status_pixbuf_cell.set_property('xalign', 0.0) status_pixbuf_cell.set_property('xpad', 5) status_text_cell.set_property('xalign', 0.0) status_text_cell.set_property('xpad', 5) status_text_cell.set_property('width', 158) self.add_attribute(status_pixbuf_cell, 'pixbuf', 0) self.add_attribute(status_text_cell, 'text', 2) self.set_resize_mode(0) self.set_wrap_width(1) current_status = main_window.session.account.status active = 0 count = 0 for stat in e3.status.ORDERED: status_name = e3.status.STATUS[stat] if stat == current_status: active = count if hasattr(gui.theme, "image_theme"): status = gui.theme.image_theme.status_icons[stat] else: status = gui.theme.status_icons[stat] pixbuf = utils.safe_gtk_pixbuf_load( gui.theme.image_theme.status_icons[stat]) pixbuf.scale_simple(20, 20, gtk.gdk.INTERP_BILINEAR) self.model.append([pixbuf, stat, status_name]) # re-gettext-it count += 1 self.set_active(active) self.connect('scroll-event', self.on_scroll_event) self.connect('changed', self.on_status_changed) main_window.session.signals.status_change_succeed.subscribe( self.on_status_change_succeed)
def PyNotification(title, text, picture_path=None, const=None, callback=None, tooltip=None): if const == 'message-im': #In this case title is contact nick if title is None: title = "" title = Plus.msnplus_strip(title) notification = pynotify.Notification(title, text, picture_path) notification.set_icon_from_pixbuf( utils.safe_gtk_pixbuf_load(picture_path[7:], (96, 96))) notification.set_hint_string("append", "allowed") notification.show()
def __init__(self, main_window): """constructor""" self.model = gtk.ListStore(gtk.gdk.Pixbuf, \ gobject.TYPE_INT, gobject.TYPE_STRING) gtk.ComboBox.__init__(self, self.model) self.main_window = main_window self.status = None status_pixbuf_cell = gtk.CellRendererPixbuf() status_text_cell = gtk.CellRendererText() self.pack_start(status_pixbuf_cell, False) self.pack_start(status_text_cell, False) status_pixbuf_cell.set_property('xalign', 0.0) status_pixbuf_cell.set_property('xpad', 5) status_text_cell.set_property('xalign', 0.0) status_text_cell.set_property('xpad', 5) status_text_cell.set_property('width', 158) self.add_attribute(status_pixbuf_cell, 'pixbuf', 0) self.add_attribute(status_text_cell, 'text', 2) self.set_resize_mode(0) self.set_wrap_width(1) current_status = main_window.session.account.status active = 0 count = 0 for stat in e3.status.ORDERED: status_name = e3.status.STATUS[stat] if stat == current_status: active = count if hasattr(gui.theme, "image_theme"): status = gui.theme.image_theme.status_icons[stat] else: status = gui.theme.status_icons[stat] pixbuf = utils.safe_gtk_pixbuf_load(gui.theme.image_theme.status_icons[stat]) pixbuf.scale_simple(20, 20, gtk.gdk.INTERP_BILINEAR) self.model.append([pixbuf, stat, status_name]) # re-gettext-it count += 1 self.set_active(active) self.connect('scroll-event', self.on_scroll_event) self.connect('changed', self.on_status_changed) main_window.session.signals.status_change_succeed.subscribe( self.on_status_change_succeed)
def __get_contact_pixbuf_or_default(self, path): '''try to return a pixbuf of the user picture or the default picture ''' if path is not None and path != '': pixbuf = utils.simple_animation_scale(path, self.avatar_size, self.avatar_size) picture = gtk.image_new_from_animation(pixbuf) else: pix = utils.safe_gtk_pixbuf_load(gui.theme.image_theme.user, (self.avatar_size, self.avatar_size)) picture = gtk.image_new_from_pixbuf(pix) return picture
def _create_indicator(self, subtype, sender, body, extra_text='', icid=None): """ This creates a new indicator item, called by on_message, online & offline. """ if indicate: try: # Ubuntu 9.10+ ind = indicate.Indicator() except Exception: # Ubuntu 9.04 ind = indicate.IndicatorMessage() #Get user icon. contact = self.handler.session.contacts.safe_get(body) pixbuf = utils.safe_gtk_pixbuf_load(contact.picture or '', (48, 48)) if pixbuf is not None: ind.set_property_icon("icon", pixbuf) ind.set_property("subtype", subtype) ind.set_property("sender", sender + extra_text) if icid is not None: ind.set_property("body", str(icid)) else: ind.set_property("body", body) ind.set_property_time("time", time.time()) ind.set_property("draw-attention", "true") ind.connect("user-display", self._display) ind.show() # Add indicator to the dictionary if subtype == "im": self.indicator_dict[ind] = icid self.r_indicator_dict[icid] = ind for old_icid in self.indicator_dict.values(): if old_icid not in self.handler.session.conversations.keys(): # workaround: kill the orphan indicator ind = self.r_indicator_dict[old_icid] del self.indicator_dict[ind] del self.r_indicator_dict[old_icid] else: return
def PyNotification(title, text, picture_path=None, const=None, callback=None, tooltip=None): if const == 'message-im': #In this case title is contact nick if title is None: title = "" title = Plus.msnplus_strip(title) notification = pynotify.Notification(title, text, picture_path) pix = utils.safe_gtk_pixbuf_load(picture_path[7:], (96, 96)) if pix is not None: notification.set_icon_from_pixbuf(pix) notification.set_hint_string("append", "allowed") try: notification.show() except Exception, err: log.warning('An error occurred while showing a notification: %s' % str(err))
def _create_indicator(self, subtype, sender, body, extra_text = '', icid=None): """ This creates a new indicator item, called by on_message, online & offline. """ if indicate: try: # Ubuntu 9.10+ ind = indicate.Indicator() except Exception: # Ubuntu 9.04 ind = indicate.IndicatorMessage() #Get user icon. contact = self.handler.session.contacts.safe_get(body) pixbuf = utils.safe_gtk_pixbuf_load(contact.picture or '', (48, 48)) if pixbuf is not None: ind.set_property_icon("icon", pixbuf) ind.set_property("subtype", subtype) ind.set_property("sender", sender + extra_text) if icid is not None: ind.set_property("body", str(icid)) else: ind.set_property("body", body) ind.set_property_time("time", time.time()) ind.set_property("draw-attention", "true") ind.connect("user-display", self._display) ind.show() # Add indicator to the dictionary if subtype == "im": self.indicator_dict[ind] = icid self.r_indicator_dict[icid] = ind for old_icid in self.indicator_dict.values(): if old_icid not in self.handler.session.conversations.keys(): # workaround: kill the orphan indicator ind = self.r_indicator_dict[old_icid] del self.indicator_dict[ind] del self.r_indicator_dict[old_icid] else: return
def __init__(self, title, text, picture_path, callback, tooltip): gtk.Window.__init__(self, type=gtk.WINDOW_POPUP) # constants self.FColor = "white" BColor = gtk.gdk.Color() avatar_size = 48 max_width = 300 self.callback = callback # window attributes self.set_border_width(10) # labels self._title = title #nick markup1 = '<span foreground="%s" weight="ultrabold">%s</span>' titleLabel = gtk.Label(markup1 % (self.FColor, \ MarkupParser.escape(self._title))) titleLabel.set_use_markup(True) titleLabel.set_justify(gtk.JUSTIFY_CENTER) titleLabel.set_ellipsize(pango.ELLIPSIZE_END) self.text = text #status, message, etc... self.markup2 = '<span foreground="%s">%s</span>' self.messageLabel = gtk.Label( self.markup2 % (self.FColor, MarkupParser.escape(self.text))) self.messageLabel.set_use_markup(True) self.messageLabel.set_justify(gtk.JUSTIFY_CENTER) self.messageLabel.set_ellipsize(pango.ELLIPSIZE_END) # image avatarImage = gtk.Image() try: userPixbuf = gtk.gdk.pixbuf_new_from_file_at_size( picture_path[7:], avatar_size, avatar_size) except: userPixbuf = utils.safe_gtk_pixbuf_load(gui.theme.image_theme.user, (avatar_size, avatar_size)) avatarImage.set_from_pixbuf(userPixbuf) # boxes hbox = gtk.HBox() # main box self.messageVbox = gtk.VBox() # title + message lbox = gtk.HBox() # avatar + title/message lbox.set_spacing(10) lboxEventBox = gtk.EventBox() # detects mouse events lboxEventBox.set_visible_window(False) lboxEventBox.set_events(gtk.gdk.BUTTON_PRESS_MASK) lboxEventBox.connect("button_press_event", self.onClick) lboxEventBox.add(lbox) self.connect("button_press_event", self.onClick) if tooltip is not None: lboxEventBox.set_tooltip_text(tooltip) # pack everything self.messageVbox.pack_start(titleLabel, False, False) self.messageVbox.pack_start(self.messageLabel, True, True) lbox.pack_start(avatarImage, False, False) lbox.pack_start(self.messageVbox, True, True) hbox.pack_start(lboxEventBox, True, True) self.add(hbox) # change background color self.set_app_paintable(True) self.realize() self.window.set_background(BColor) # A bit of transparency to be less intrusive self.set_opacity(0.85) self.timerId = None self.set_default_size(max_width, -1) self.connect("size-allocate", self.relocate) self.show_all()
def __init__(self, title, text, picture_path, callback, tooltip): gtk.Window.__init__(self, type=gtk.WINDOW_POPUP) # constants self.FColor = "white" BColor = gtk.gdk.Color() avatar_size = 48 max_width = 300 self.callback = callback # window attributes self.set_border_width(10) # labels self._title = title #nick markup1 = '<span foreground="%s" weight="ultrabold">%s</span>' titleLabel = gtk.Label(markup1 % (self.FColor, \ MarkupParser.escape(self._title))) titleLabel.set_use_markup(True) titleLabel.set_justify(gtk.JUSTIFY_CENTER) titleLabel.set_ellipsize(pango.ELLIPSIZE_END) self.text = text #status, message, etc... self.markup2 = '<span foreground="%s">%s</span>' self.messageLabel = gtk.Label(self.markup2 % (self.FColor, MarkupParser.escape(self.text))) self.messageLabel.set_use_markup(True) self.messageLabel.set_justify(gtk.JUSTIFY_CENTER) self.messageLabel.set_ellipsize(pango.ELLIPSIZE_END) # image avatarImage = gtk.Image() try: userPixbuf = gtk.gdk.pixbuf_new_from_file_at_size( picture_path[7:], avatar_size, avatar_size) except: userPixbuf = utils.safe_gtk_pixbuf_load(gui.theme.image_theme.user, (avatar_size, avatar_size)) avatarImage.set_from_pixbuf(userPixbuf) # boxes hbox = gtk.HBox() # main box self.messageVbox = gtk.VBox() # title + message lbox = gtk.HBox() # avatar + title/message lbox.set_spacing(10) lboxEventBox = gtk.EventBox() # detects mouse events lboxEventBox.set_visible_window(False) lboxEventBox.set_events(gtk.gdk.BUTTON_PRESS_MASK) lboxEventBox.connect("button_press_event", self.onClick) lboxEventBox.add(lbox) self.connect("button_press_event", self.onClick) if tooltip is not None: lboxEventBox.set_tooltip_text(tooltip) # pack everything self.messageVbox.pack_start(titleLabel, False, False) self.messageVbox.pack_start(self.messageLabel, True, True) lbox.pack_start(avatarImage, False, False) lbox.pack_start(self.messageVbox, True, True) hbox.pack_start(lboxEventBox, True, True) self.add(hbox) # change background color self.set_app_paintable(True) self.realize() self.window.set_background(BColor) # A bit of transparency to be less intrusive self.set_opacity(0.85) self.timerId = None self.set_default_size(max_width,-1) self.connect("size-allocate", self.relocate) self.show_all()