def initialize_members_page(self): hbox = gtk.HBox() if self.list_view: # Display as a list self.itemview = gtk.TreeView(self.itemlist) self.itemview.connect('row-activated', self.handle_item_clicked) self.itemview.set_headers_visible(False) cr_icon = gtk.CellRendererPixbuf() cr_name = gtk.CellRendererText() cr_status = gtk.CellRendererText() column = gtk.TreeViewColumn('') column.pack_start(cr_icon, False) column.pack_start(cr_name) column.add_attribute(cr_icon, 'pixbuf', self.COL_ICON) column.add_attribute(cr_name, 'markup', self.COL_TITLE) self.itemview.append_column(column) column = gtk.TreeViewColumn('Status') column.pack_start(cr_status) column.add_attribute(cr_status, 'text', self.COL_STATUS) column.set_expand(True) self.itemview.append_column(column) else: # Icon display self.itemview = gtk.IconView(self.itemlist) self.itemview.set_spacing(6) self.itemview.set_row_spacing(9) self.itemview.connect('item-activated', self.handle_item_clicked) self.itemview.connect('button-press-event', self.view_clicked, None) self.itemview.set_pixbuf_column(self.COL_ICON) self.itemview.set_markup_column(self.COL_TITLE) swindow = new_scrollarea() swindow.add_with_viewport(self.itemview) hbox.pack_start(swindow) self.action_list = User_Action_List(self.community_gui, self.get_selected) hbox.pack_start(self.action_list.get_widget(), False, True) self.notebook.append_page(hbox, gtk.Label('Members'))
class Community_Page(GUI_Page): COL_ICON = 0 COL_USER = 1 COL_TITLE = 2 COL_STATUS = 3 def __init__(self, community_gui, gui, com): GUI_Page.__init__(self, com.get('name')) self.notification = get_plugin_by_type(PLUGIN_TYPE_NOTIFICATION) self.community = get_plugin_by_type(PLUGIN_TYPE_COMMUNITY) self.item_double_clicking = None self.community_gui = community_gui self.main_gui = gui self.com = com self.list_view = community_gui.list_view_setting.value self.profile_widgets = {} # model (icon, item, text) self.itemlist = gtk.ListStore(gtk.gdk.Pixbuf, gobject.TYPE_PYOBJECT, str, str) self.update_members() self.pic_dialog = Picture_Choose_Dialog(gui, self.got_picture) self.notebook = gtk.Notebook() self.notebook.set_show_tabs(True) self.notebook.set_show_border(False) self.initialize_members_page() self.initialize_profile_page() self.initialize_modify_page() self.pack_start(self.notebook) def initialize_members_page(self): hbox = gtk.HBox() if self.list_view: # Display as a list self.itemview = gtk.TreeView(self.itemlist) self.itemview.connect('row-activated', self.handle_item_clicked) self.itemview.set_headers_visible(False) cr_icon = gtk.CellRendererPixbuf() cr_name = gtk.CellRendererText() cr_status = gtk.CellRendererText() column = gtk.TreeViewColumn('') column.pack_start(cr_icon, False) column.pack_start(cr_name) column.add_attribute(cr_icon, 'pixbuf', self.COL_ICON) column.add_attribute(cr_name, 'markup', self.COL_TITLE) self.itemview.append_column(column) column = gtk.TreeViewColumn('Status') column.pack_start(cr_status) column.add_attribute(cr_status, 'text', self.COL_STATUS) column.set_expand(True) self.itemview.append_column(column) else: # Icon display self.itemview = gtk.IconView(self.itemlist) self.itemview.set_spacing(6) self.itemview.set_row_spacing(9) self.itemview.connect('item-activated', self.handle_item_clicked) self.itemview.connect('button-press-event', self.view_clicked, None) self.itemview.set_pixbuf_column(self.COL_ICON) self.itemview.set_markup_column(self.COL_TITLE) swindow = new_scrollarea() swindow.add_with_viewport(self.itemview) hbox.pack_start(swindow) self.action_list = User_Action_List(self.community_gui, self.get_selected) hbox.pack_start(self.action_list.get_widget(), False, True) self.notebook.append_page(hbox, gtk.Label('Members')) def back_action(self): self.community_gui.com_pages.pop(self.com) self.main_gui.remove_page(self) self.destroy() return True def get_community(self): return self.com def update_community_page(self): self.update_profile_entries() self.update_profile_widgets() def update_members(self): users = self.community.get_community_members(self.com) myself = self.community.get_myself() # myself is not in active users list, so add separately here if self.com.get('peer') == True and \ self.com in self.community.get_user_communities(myself): users.append(myself) for row in self.itemlist: user = row[self.COL_USER] if user not in users: self.itemlist.remove(row.iter) else: users.remove(user) # add new users to the end for user in users: icon = self.get_user_icon(user) title = self.get_user_display_name(user) if user == myself: self.itemlist.prepend([icon, user, title, user.get('status')]) else: self.itemlist.append([icon, user, title, user.get('status')]) def get_user_icon(self, user): icon = get_user_profile_picture(user) if self.list_view: return icon.scale_simple(48, 48, gtk.gdk.INTERP_BILINEAR) return icon def user_changes(self, user): self.update_members() self.update_profile_widgets() for row in self.itemlist: if user == row[self.COL_USER]: row[self.COL_ICON] = self.get_user_icon(user) row[self.COL_TITLE] = self.get_user_display_name(user) row[self.COL_STATUS] = user.get('status') break def get_user_display_name(self, user): nick = pango_escape(user.get('nick')) if user == self.community.get_myself(): nick = '<b>%s</b> (me)' % nick return nick def handle_item_clicked(self, view, path, view_column=None): row = self.itemlist[path] user = row[self.COL_USER] self.community_gui.show_user_page(user) def view_clicked(self, iconview, event, param): if event.type == gtk.gdk.BUTTON_PRESS and event.button == 1: coords = event.get_coords() if coords == (): return (x,y) = coords # simulate double click with a timeout variable if not self.item_double_clicking: self.set_item_double_clicking(True) timeout_id = gobject.timeout_add(500, self.set_item_double_clicking, False) return path = iconview.get_path_at_pos(int(x), int(y)) if path != None: # is the item already selected selected = iconview.path_is_selected(path) if selected: self.handle_item_clicked(iconview, path) def set_item_double_clicking(self, doubleclick): self.item_double_clicking = doubleclick return False # timeout shouldn't call this again def get_selected(self): if self.list_view: model, selected = self.itemview.get_selection().get_selected_rows() else: selected = self.itemview.get_selected_items() if len(selected) > 0: path = selected[0] # there should be 0 or 1 selected items row = self.itemlist[path] value = row[self.COL_USER] else: value = self.com return value def initialize_profile_page(self): profile_hbox = gtk.HBox() vbox = gtk.VBox() myself = self.community.get_myself() is_member = (self.com in self.community.get_user_communities(myself)) picture_vbox = gtk.VBox() self.profile_image = gtk.Image() self.profile_image.set_size_request(MAX_FACE_DIMENSION+10, MAX_FACE_DIMENSION+10) if is_member: eventbox = gtk.EventBox() eventbox.connect("button-press-event", self.image_clicked) eventbox.add(self.profile_image) picture_vbox.pack_start(gtk.Label('Click picture to change')) picture_vbox.pack_start(eventbox, True, True) else: picture_vbox.pack_start(self.profile_image, True, True) picture_hbox = gtk.HBox() picture_hbox.pack_start(picture_vbox, False, True) self.status_label = gtk.Label() self.status_label.set_line_wrap(True) picture_hbox.pack_start(self.status_label) vbox.pack_start(picture_hbox) self.profile_info_label = gtk.Label() self.profile_info_label.set_alignment(0.1, 0.01) # 0.01 on purpose self.profile_info_label.set_line_wrap(True) vbox.pack_start(self.profile_info_label) profile_hbox.pack_start(vbox) self.com_action_list = Community_Action_List(self.community_gui, self.get_community) profile_hbox.pack_start(self.com_action_list.action_view) swindow = new_scrollarea() swindow.set_border_width(0) swindow.add_with_viewport(profile_hbox) self.update_profile_widgets() self.notebook.append_page(swindow, gtk.Label('Profile')) def initialize_modify_page(self): vbox = gtk.VBox() # List of modifiable fields profile_components = [('Location: ', 'location'), ('WWW: ', 'www'), ('Description: ', 'description'), ] for header, key in profile_components: hbox = gtk.HBox() label = gtk.Label(header) label.set_size_request(130, -1) label.set_alignment(0, 0) value = self.com.get(key) if value == None: value = '' if key == 'description': # create description widget separately entry = gtk.TextView() entry.get_buffer().set_text(str(value)) entry.set_property("wrap-mode", gtk.WRAP_CHAR) entry.set_size_request(-1, 100) else: entry = gtk.Entry() entry.set_text(str(value)) entry.connect("focus-out-event", self.entry_focus_out, key) hbox.pack_start(label, False) hbox.pack_start(entry) self.profile_widgets[key] = entry vbox.pack_start(hbox, False) self.locked_checkbox = gtk.CheckButton('Do not allow changes to the community icon from other users') vbox.pack_start(self.locked_checkbox, False, False) self.locked_checkbox.set_active(self.com.get('iconlocked')) self.locked_checkbox.connect('toggled', self.set_locked) myself = self.community.get_myself() if self.com in self.community.get_user_communities(myself): self.notebook.append_page(vbox, gtk.Label('Modify')) self.update_profile_entries() def set_locked(self, widget): self.com.set('iconlocked', widget.get_active()) def update_profile_entries(self): for key, entry in self.profile_widgets.items(): value = self.com.get(key) if value == None: value = '' if key == 'description': entry.get_buffer().set_text(str(value)) else: entry.set_text(str(value)) def update_profile_widgets(self): image = get_community_icon(self.com) self.profile_image.set_from_pixbuf(image) n = len(self.community.get_community_members(self.com)) myself = self.community.get_myself() if self.com in self.community.get_user_communities(myself): n += 1 status = '%d member' % n if n != 1: status += 's' self.status_label.set_text(status) self.profile_info_label.set_markup(self.construct_profile_info_str()) def image_clicked(self, widget, event): self.pic_dialog.set_picture(seek_community_icon_name(self.com)) self.pic_dialog.show() def got_picture(self, fname): myself = self.community.get_myself() if self.com in self.community.get_user_communities(myself): self.community.set_community_icon(self.com, fname) # increase profile version to indicate new community profile self.community.get_myself().update_attributes([]) def construct_profile_info_str(self): def heading(s): # Returns a heading string s formatted with pango markup and # a new-line return '<span color="slategray" weight="bold" size="large">%s</span>\n' % pango_escape(s) def field(s): value = self.com.get(s) if value != None: return '%s: %s\n' % (field_descriptions[s], pango_escape(str(value))) else: return '' def join_list(l): out = [] for s in l: value = self.com.get(s) if value != None: out.append(pango_escape(str(value))) if len(out) > 0: return ', '.join(out) + '\n' else: return '' s = heading(self.com.get('name')) s += field('location') s += field('www') s += field('description') if get_debug_mode(): s += heading('Debug information') s += field('v') s += field('iconversion') s += field('myiconversion') return s def entry_focus_out(self, entry, event, key): if key == 'description': buf = entry.get_buffer() value = buf.get_text(buf.get_start_iter(), buf.get_end_iter()) else: value = entry.get_text() if value == '': value = None if value != self.com.get(key): if self.com.set(key, value): # increase profile version to indicate new community profile self.community.get_myself().update_attributes([]) else: # re-insert old value if set fails value = self.com.get(key) if value == None: value = '' entry.set_text(str(value))