def get_user_profile_picture(user, status_icons=True, center=True): """ Returns picture saved in user's profile as a GDK Pixbuf, or the default picture with a background color generated from uid. Status icons are added to the picture, if status_icons == True. """ try: icon = gtk.gdk.pixbuf_new_from_file(proximatestate.seek_face_name(user)) except gobject.GError: icon = create_default_user_picture(user) if center: # center image if it's smaller than MAX_FACE_DIMENSION smaller_dimension = min(icon.get_width(), icon.get_height()) if smaller_dimension < MAX_FACE_DIMENSION: icon = center_image(icon, MAX_FACE_DIMENSION, MAX_FACE_DIMENSION) if status_icons: # add small status icons community = get_plugin_by_type(PLUGIN_TYPE_COMMUNITY) if not user == community.get_myself(): if user.get('key_fname'): status_icon = gtk.gdk.pixbuf_new_from_file(get_path(SMALL_KEYS_ICON)) add_icon_to_image(icon, status_icon, 4) user_status = user.get('status_icon') if user_status: add_icon_to_image(icon, get_status_icon(user_status, 32), 0) return icon
def __init__(self, options): self.register_plugin(PLUGIN_TYPE_COMMUNITY) self.register_server(TP_HELLO, Hello_Server) self.fetcher = None self.fetchhandlers = { TP_HELLO: self.handle_hello, 'uprofile': self.handle_user_profile_fetch, 'iconrequest': self.handle_icon_request, 'iconpush': self.handle_icon_push, 'cprofile': self.handle_community_profile_fetch, 'cprofiles': self.handle_community_profiles_fetch, 'cinvite': self.handle_invite_community, } self.notify = None self.net = None self.community_gui = None self.req_counter = 0 self.activeport = options.activeport # Note ipactive is not dependent on udp_listen and udp_send variables self.ipactive = True self.activeusers = {} self.remoteusers = {} for user in self.get_users(False): remotes = user.get('remotes') if remotes != None and len(remotes) > 0: self.remoteusers[user] = 0 self.myself = get_myself() self.myuid = self.myself.get('uid') self.udp_listen = (options.udpmode & 1) != 0 self.udp_send = (options.udpmode & 2) != 0 if not self.udp_listen or not self.udp_send: info('UDP broadcast listen: %s send: %s\n' % (self.udp_listen, self.udp_send)) self.blacklist = {} self.blistcom = self.create_community(BLACKLIST_COMMUNITY_NAME, peer=False, public=False) self.blistcom.set('invisible', True) self.iconfetchlimiters = {'user': Rate_Limiter(ICON_PUSH_INTERVAL)} self.personal_communities = options.personal_communities # Create a community of friends, if it doesn't already exist friends = self.get_friend_community() if friends == None: friends = self.create_community(FRIENDS_COMMUNITY_NAME, peer=False, public=False, desc='My friends') self.set_community_icon(friends, get_path(FRIEND_COMMUNITY_ICON))
def create_default_user_picture(user): # list of suitable colors to pick from colors = (0x000000FF, 0x8A8A8AFF, 0x9B00AFFF, 0x5DAF00FF, 0x79AF00FF, 0xA8AF00FF, 0xAF9B00FF, 0xAF6000FF, 0xAF0016FF, 0xAF0092FF, 0xBC0086FF, 0x000FBCFF, 0x007403FF, 0x007466FF, 0xD5FFBAFF, 0xFFFFFFFF) # use default icon and color it using the first char as an index buf = gtk.gdk.pixbuf_new_from_file(get_path(DEFAULT_USER_ICON)) icon = buf.copy() color = colors[int(user.get('uid')[0], 16)] icon.fill(color) buf.composite(icon, 0, 0, buf.get_width(), buf.get_height(), 0, 0, 1.0, 1.0, gtk.gdk.INTERP_NEAREST, 255) return icon
def get_default_community_icon(com): if com == proximatestate.get_ordinary_community(DEFAULT_COMMUNITY_NAME): fname = get_path(PROXIMATE_COMMUNITY_ICON) else: fname = get_path(DEFAULT_COMMUNITY_ICON) return gtk.gdk.pixbuf_new_from_file(fname)
def initialize_widgets(self): fwindow = new_scrollarea() viewport = gtk.Viewport() self.widgets_to_hide = [] self.main_vbox = gtk.VBox() self.main_vbox.set_size_request(-1, 500) self.image_hbox = gtk.HBox() self.main_vbox.pack_start(self.image_hbox, False, False) # Community name, personal cbox, area size and image self.name_vbox = gtk.VBox() hbox = gtk.HBox() self.name_label = gtk.Label('Community\'s name:') hbox.pack_start(self.name_label, False, True) self.name_vbox.pack_start(hbox, False, True) self.name_entry = gtk.Entry() self.name_entry.set_size_request(-1, 32) self.name_vbox.pack_start(self.name_entry, False, True) hbox = gtk.HBox() self.personal_label = gtk.Label('Personal Community:') hbox.pack_start(self.personal_label, False, True) if self.community.personal_communities: self.name_vbox.pack_start(hbox, False, True) self.personal_cbutton = gtk.CheckButton() self.personal_cbutton.set_active(False) self.personal_cbutton.set_size_request(-1, 32) self.personal_cbutton.connect("clicked", self.checkbutton_clicked) hbox = gtk.HBox() hbox.pack_start(self.personal_cbutton, True, True) if self.community.personal_communities: self.name_vbox.pack_start(hbox, False, True) self.image_hbox.pack_start(self.name_vbox, False, True) self.image_eb = gtk.EventBox() self.image_eb.connect("button-press-event", self.image_clicked) self.image = gtk.Image() self.image.set_size_request(MAX_FACE_DIMENSION+10, MAX_FACE_DIMENSION+10) self.image.set_from_file(get_path(DEFAULT_COMMUNITY_ICON)) self.image_eb.add(self.image) vbox = gtk.VBox() vbox.pack_start(self.image_eb, True, True) vbox.pack_start(gtk.Label('Click community\nicon to change it'), True, False) self.image_hbox.pack_end(vbox, False, False) hbox = gtk.HBox() desc_label = gtk.Label('Description: ') desc_label.set_size_request(-1, 32) hbox.pack_start(desc_label, False, True) self.main_vbox.pack_start(hbox, False, True) self.description_tview = gtk.TextView() self.description_tview.set_property("wrap-mode", gtk.WRAP_CHAR) self.description_tbuffer = gtk.TextBuffer() self.description_tbuffer.set_text("<<Insert description>>") self.description_tview.set_buffer(self.description_tbuffer) self.description_tview.set_size_request(300, 100) self.main_vbox.pack_start(self.description_tview, False, True) self.main_vbox.show_all() viewport.add(self.main_vbox) fwindow.add(viewport) self.dialog.vbox.pack_start(fwindow)