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.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.user, (self.avatar_size, self.avatar_size)) picture = gtk.image_new_from_pixbuf(pix) return picture
def __init__(self, callback, avatar_path): gtk.Alignment.__init__(self, xalign=0.5, yalign=0.5, xscale=1.0, yscale=1.0) self.callback = callback #for reconnecting self.reconnect_timer_id = None if avatar_path == '': self.avatar_path = gui.theme.logo else: self.avatar_path = avatar_path th_pix = utils.safe_gtk_pixbuf_load(gui.theme.throbber, None, animated=True) self.throbber = gtk.image_new_from_animation(th_pix) self.b_cancel = gtk.Button(stock=gtk.STOCK_CANCEL) self.b_cancel.connect('clicked', self._on_cancel_clicked) self.b_cancel.set_border_width(8) self.label = gtk.Label() self.label.set_markup('<b>Connecting...</b>') self.label_timer = gtk.Label() self.label_timer.set_markup('<b>Connection error!\n </b>') self.img_account = gtk.Image() self.img_account.set_from_pixbuf(utils.safe_gtk_pixbuf_load(self.avatar_path,(96,96))) al_throbber = gtk.Alignment(xalign=0.5, yalign=0.5, xscale=0.2, yscale=0.2) al_button_cancel = gtk.Alignment(xalign=0.5, yalign=0.5, xscale=0.15) al_label = gtk.Alignment(xalign=0.5, yalign=0.5, xscale=0.0, yscale=0.0) al_label_timer = gtk.Alignment(xalign=0.5, yalign=0.5, xscale=0.0, yscale=0.0) al_logo = gtk.Alignment(xalign=0.5, yalign=0.5, xscale=0.0, yscale=0.0) al_throbber.add(self.throbber) al_button_cancel.add(self.b_cancel) al_label.add(self.label) al_label_timer.add(self.label_timer) al_logo.add(self.img_account) vbox = gtk.VBox() vbox.pack_start(al_logo, True, False) vbox.pack_start(al_label, True, False) vbox.pack_start(al_label_timer, True, False) vbox.pack_start(al_throbber, True, False) vbox.pack_start(al_button_cancel, True, True) self.add(vbox) vbox.show_all() self.dim = 96 gobject.timeout_add(20, self.do_animation) self.label.hide() self.throbber.hide() self.label_timer.hide()
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.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.user, (self.avatar_size, self.avatar_size)) picture = gtk.image_new_from_pixbuf(pix) return picture
def _get_contact_pixbuf_or_default(self, contact): '''try to return a pixbuf of the user picture or the default picture ''' if contact.picture: picture = utils.safe_gtk_pixbuf_load(contact.picture, (self.avatar_size, self.avatar_size)) else: picture = utils.safe_gtk_pixbuf_load(gui.theme.user, (self.avatar_size, self.avatar_size)) return picture
def service_add_cb(self, s_name, service_name): '''Add a new service to the service combo''' if not s_name is None: image = utils.safe_gtk_pixbuf_load(s_name) else: image = None self.session_combo.get_model().append([image, service_name])
def add_new_avatar(self, filename): ''' add a new picture from filename into the avatar cache ''' def gen_filename(source): # generate a unique (?) filename for the new avatar in cache # implemented as sha224 digest infile = open(source, 'rb') data = infile.read() infile.close() return hashlib.sha224(data).hexdigest() fpath = os.path.join(self.get_avatars_dir(), gen_filename(filename)) try: #FIXME temporaney hack for animations animation = gtk.gdk.PixbufAnimation(filename) if not animation.is_static_image(): self.session.set_picture(filename) if os.path.exists(self.avatar_path): os.remove(self.avatar_path) shutil.copy(filename, self.avatar_path) return None, fpath else: if not os.path.exists(self.get_avatars_dir()): os.makedirs(self.get_avatars_dir()) # Save in 96x96 pix_96 = utils.safe_gtk_pixbuf_load(filename, (96, 96)) pix_96.save(fpath, 'png') return pix_96, fpath except OSError, error: print error return None, fpath
def update_contact(self, contact): '''update the data of contact''' try: weight = int(self.session.config.d_weights.get(contact.account, 0)) except ValueError: weight = 0 self.session.config.d_weights[contact.account] = weight offline = contact.status == e3.status.OFFLINE contact_data = (self._get_contact_pixbuf_or_default(contact), contact, self.format_nick(contact), True, utils.safe_gtk_pixbuf_load(gui.theme.status_icons[contact.status]), weight, False, offline) found = False for row in self._model: obj = row[1] if type(obj) == e3.Group: for contact_row in row.iterchildren(): con = contact_row[1] if con.account == contact.account: found = True self._model[contact_row.iter] = contact_data self.update_group(obj) elif type(obj) == e3.Contact and obj.account == contact.account: found = True self._model[row.iter] = contact_data
def update_contact(self, contact): '''update the data of contact''' try: weight = int(self.session.config.d_weights.get(contact.account, 0)) except ValueError: weight = 0 self.session.config.d_weights[contact.account] = weight offline = contact.status == e3.status.OFFLINE online = not offline contact_data = (self._get_contact_pixbuf_or_default(contact), contact, self.format_nick(contact), True, utils.safe_gtk_pixbuf_load(gui.theme.status_icons[contact.status]), weight, False, offline) found = False group_found = None for row in self._model: obj = row[1] if type(obj) == e3.Group: for contact_row in row.iterchildren(): con = contact_row[1] if con.account == contact.account: found = True group_found = obj self._model[contact_row.iter] = contact_data self.update_group(obj) elif type(obj) == e3.Contact and obj.account == contact.account: found = True self._model[row.iter] = contact_data # if we are in order by status, the contact was found and now is offline/online # delete contact from offline/online group and add to the oposite. if self.order_by_status and found: # y todavia no estoy en el grupo. if offline and group_found != self.offline_group: self.remove_contact(contact, self.online_group) self.add_contact(contact, self.offline_group) if online and group_found != self.online_group: self.remove_contact(contact, self.offline_group) self.add_contact(contact, self.online_group) if self.order_by_group and self.group_offline and found: # y todavia no estoy en el grupo. if offline and group_found != self.offline_group: self.remove_contact(contact, group_found) self.add_contact(contact, self.offline_group) if online and group_found == self.offline_group: self.remove_contact(contact, self.offline_group) if len(contact.groups) == 0: self.add_contact(contact) else: for group in contact.groups: self.add_contact(contact, self.session.groups[group])
def update_group(self, members): ''' sets the contacts list instead of a contact's avatar ''' self._contact_list.set_model(None) del self._model self._model = gtk.ListStore(gtk.gdk.Pixbuf, object, str, gtk.gdk.Pixbuf) self.members = members for member in self.members: contact = self.session.contacts.get(member) picture = contact.picture or gui.theme.image_theme.user contact_data = (utils.safe_gtk_pixbuf_load(picture,(15,15)), contact, contact.nick, utils.safe_gtk_pixbuf_load( gui.theme.image_theme.status_icons[contact.status],(15,15))) self._model.append(contact_data) self._contact_list.set_model(self._model) self._contact_list.show_all() self._first_alig.set(0.5,0.0,1.0,2.0) self.first = self._contact_list self.set_size_request(200,-1)
def add_contact(self, contact, group=None): '''add a contact to the contact list, add it to the group if group is not None''' try: weight = int(self.session.config.d_weights.get(contact.account, 0)) except ValueError: weight = 0 self.session.config.d_weights[contact.account] = weight contact_data = (self._get_contact_pixbuf_or_default(contact), contact, self.format_nick(contact), True, utils.safe_gtk_pixbuf_load(gui.theme.status_icons[contact.status]), weight) # if no group add it to the root, but check that it's not on a group # or in the root already if not group or self.order_by_status: for row in self._model: obj = row[1] # check on group if type(obj) == e3.Group: for contact_row in row.iterchildren(): con = contact_row[1] if con.account == contact.account: return contact_row.iter # check on the root elif type(obj) == e3.Contact and obj.account == contact.account: return row.iter return self._model.append(None, contact_data) for row in self._model: obj = row[1] if type(obj) == e3.Group and obj.name == group.name: # if the contact is already on the group, then dont add it for contact_row in row.iterchildren(): con = contact_row[1] if con.account == contact.account: return contact_row.iter return_iter = self._model.append(row.iter, contact_data) self.update_group(group) # search the use on the root to remove it if it's there # since we added him to a group for irow in self._model: iobj = irow[1] if type(iobj) == e3.Contact and \ iobj.account == contact.account: del self._model[irow.iter] return return_iter else: self.add_group(group) return self.add_contact(contact, group)
def do_animation(self): '''do the avatar's animation on login''' if self.dim <= 128: self.dim += 4 self.img_account.set_from_pixbuf(utils.safe_gtk_pixbuf_load( self.avatar_path,(self.dim,self.dim))) return True else: self.label.show() self.clear_connect() return False
def __init__(self, callback, avatar_path): gtk.Alignment.__init__(self, xalign=0.5, yalign=0.5, xscale=1.0, yscale=1.0) self.callback = callback #for reconnecting self.reconnect_timer_id = None Avatar = extension.get_default('avatar') th_pix = utils.safe_gtk_pixbuf_load(gui.theme.throbber, None, animated=True) self.throbber = gtk.image_new_from_animation(th_pix) self.b_cancel = gtk.Button(stock=gtk.STOCK_CANCEL) self.b_cancel.connect('clicked', self._on_cancel_clicked) self.b_cancel.set_border_width(8) self.label = gtk.Label() self.label.set_markup('<b>Connecting...</b>') self.label_timer = gtk.Label() self.label_timer.set_markup('<b>Connection error!\n </b>') self.avatar = Avatar(cellDimention=96) self.avatar.set_from_file(avatar_path) al_throbber = gtk.Alignment(xalign=0.5, yalign=0.5, xscale=0.2, yscale=0.2) al_button_cancel = gtk.Alignment(xalign=0.5, yalign=0.5, xscale=0.15) al_label = gtk.Alignment(xalign=0.5, yalign=0.5, xscale=0.0, yscale=0.0) al_label_timer = gtk.Alignment(xalign=0.5, yalign=0.5, xscale=0.0, yscale=0.0) al_logo = gtk.Alignment(xalign=0.5, yalign=0.5, xscale=0.0, yscale=0.0) al_throbber.add(self.throbber) al_button_cancel.add(self.b_cancel) al_label.add(self.label) al_label_timer.add(self.label_timer) al_logo.add(self.avatar) vbox = gtk.VBox() vbox.pack_start(al_logo, True, False) vbox.pack_start(al_label, True, False) vbox.pack_start(al_label_timer, True, False) vbox.pack_start(al_throbber, True, False) vbox.pack_start(al_button_cancel, True, True) self.add(vbox) vbox.show_all() self.label_timer.hide()
def replace_emoticons(text): '''replace emotes with pixbufs''' emote_theme = gui.theme.emote_theme shortcuts = emote_theme.shortcuts emoticon_list = [] unescaped_text = gui.base.MarkupParser.unescape(text) for shortcut in shortcuts: eshort = gui.base.MarkupParser.escape(shortcut) if shortcut in unescaped_text: if shortcut in emote_theme.shortcuts: path = emote_theme.emote_to_path(shortcut, remove_protocol=True) if path is not None: pos = unescaped_text.find(shortcut) while pos > -1: emoticon_list.append([pos, eshort, path]) pos = unescaped_text.find(shortcut, pos + 1) emoticon_list.sort() text_list = [text] for emoticon in emoticon_list: if len(text_list) == 1: temp_list = text.partition(emoticon[1]) text1, text2 = close_tags(temp_list[0], temp_list[2]) text_list = [text1] text_list.append(utils.safe_gtk_pixbuf_load(emoticon[2])) text_list.append(text2) old_emoticon = emoticon elif emoticon[0] >= old_emoticon[0] + len(old_emoticon[1]): temp_list = text_list[len(text_list) - 1].partition(emoticon[1]) text1, text2 = close_tags(temp_list[0], temp_list[2]) text_list[len(text_list) - 1] = text1 text_list.append(utils.safe_gtk_pixbuf_load(emoticon[2])) text_list.append(text2) old_emoticon = emoticon # make sure broken plus tags are parsed in the right way text1, text2 = close_tags(text_list[len(text_list) - 1]) text_list[len(text_list) - 1] = text1 return text_list
def __init__(self, callback): gtk.Alignment.__init__(self, xalign=0.5, yalign=0.5, xscale=1.0, yscale=1.0) self.callback = callback th_pix = utils.safe_gtk_pixbuf_load(gui.theme.throbber, None, animated=True) self.throbber = gtk.image_new_from_animation(th_pix) self.b_cancel = gtk.Button(stock=gtk.STOCK_CANCEL) self.b_cancel.connect('clicked', self._on_cancel_clicked) self.b_cancel.set_border_width(8) self.label = gtk.Label() self.label.set_markup('<b>Connecting... </b>') img_account = gtk.Image() img_account.set_from_pixbuf(utils.safe_gtk_pixbuf_load(gui.theme.logo)) al_throbber = gtk.Alignment(xalign=0.5, yalign=0.5, xscale=0.2, yscale=0.2) al_button_cancel = gtk.Alignment(xalign=0.5, yalign=0.5, xscale=0.15) al_label = gtk.Alignment(xalign=0.5, yalign=0.5, xscale=0.0, yscale=0.0) al_logo = gtk.Alignment(xalign=0.5, yalign=0.5, xscale=0.0, yscale=0.0) al_throbber.add(self.throbber) al_button_cancel.add(self.b_cancel) al_label.add(self.label) al_logo.add(img_account) vbox = gtk.VBox() vbox.pack_start(al_logo, True, False) vbox.pack_start(al_label, True, False) vbox.pack_start(al_throbber, True, False) vbox.pack_start(al_button_cancel, True, True) self.add(vbox) vbox.show_all()
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, (96, 96))) notification.set_hint_string("append", "allowed") notification.show()
def replace_emoticons(text): '''replace emotes with pixbufs''' emote_theme = gui.theme.emote_theme shortcuts = emote_theme.shortcuts emoticon_list = [] unescaped_text = gui.base.MarkupParser.unescape(text) for shortcut in shortcuts: eshort = gui.base.MarkupParser.escape(shortcut) if shortcut in unescaped_text: if shortcut in emote_theme.shortcuts: path = emote_theme.emote_to_path(shortcut, remove_protocol=True) if path is not None: pos = unescaped_text.find(shortcut) while pos > -1: emoticon_list.append([pos, eshort, path]) pos = unescaped_text.find(shortcut, pos + 1) emoticon_list.sort() text_list = [text] for emoticon in emoticon_list: if len(text_list) == 1: temp_list = text.partition(emoticon[1]) text1, text2 = close_tags(temp_list[0], temp_list[2]) text_list = [text1] text_list.append(utils.safe_gtk_pixbuf_load(emoticon[2])) text_list.append(text2) old_emoticon = emoticon elif emoticon[0] >= old_emoticon[0] + len(old_emoticon[1]): temp_list = text_list[len(text_list) - 1].partition(emoticon[1]) text1, text2 = close_tags(temp_list[0], temp_list[2]) text_list[len(text_list) - 1] = text1 text_list.append(utils.safe_gtk_pixbuf_load(emoticon[2])) text_list.append(text2) old_emoticon = emoticon # make sure broken plus tags are parsed in the right way text1, text2 = close_tags(text_list[len(text_list)-1]) text_list[len(text_list) - 1] = text1 return text_list
def _clear_all(self): ''' clear all login fields and checkbox ''' self.remember_account.set_active(False) self.remember_account.set_sensitive(True) self.remember_password.set_active(False) self.remember_password.set_sensitive(True) self.auto_login.set_active(False) self.forget_me.set_child_visible(False) self.btn_status.set_status(e3.status.ONLINE) self.txt_password.set_text('') self.txt_password.set_sensitive(True) self.img_account.set_from_pixbuf( utils.safe_gtk_pixbuf_load(gui.theme.logo))
def _create_indicator(self, subtype, sender, body, extra_text='', cid=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.get(body) pixbuf = utils.safe_gtk_pixbuf_load(contact.picture, (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 cid is not None: ind.set_property("body", str(cid)) 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] = cid self.r_indicator_dict[cid] = ind for old_cid in self.indicator_dict.values(): if old_cid not in self.handler.session.conversations.keys(): # workaround: kill the orphan indicator ind = self.r_indicator_dict[old_cid] del self.indicator_dict[ind] del self.r_indicator_dict[old_cid] else: return
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 pixbuf = utils.safe_gtk_pixbuf_load(gui.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 new_combo_session(self): account = self.config.get_or_set('last_logged_account', '') default_session = extension.get_default('session') count = 0 session_found = False self.session_name_to_index = {} if account in self.accounts: service = self.config.d_user_service.get( account.rpartition('|')[0], 'msn') else: service = self.config.service for ext_id, ext in extension.get_extensions('session').iteritems(): if default_session.NAME == ext.NAME: default_session_index = count for service_name, service_data in ext.SERVICES.iteritems(): if service == service_name: index = count session_found = True try: s_name = getattr(gui.theme.image_theme, "service_" + service_name) image = utils.safe_gtk_pixbuf_load(s_name) except: image = None self.session_combo.get_model().append([image, service_name]) self.session_name_to_index[service_name] = count count += 1 if session_found: self.session_combo.set_active(index) else: self.session_combo.set_active(default_session_index) self.session_combo.connect('changed', self._on_session_changed) self._combo_session_list.append(self.session_combo)
def new_combo_session(self, session_combo, on_session_changed): account = self.config.get_or_set('last_logged_account', '') default_session = extension.get_default('session') count=0 session_found = False name_to_ext = {} if account in self.accounts: service = self.config.d_user_service.get(account, 'msn') else: service = 'msn' for ext_id, ext in extension.get_extensions('session').iteritems(): if default_session.NAME == ext.NAME: default_session_index = count for service_name, service_data in ext.SERVICES.iteritems(): if service == service_name: index = count session_found = True try: # ugly eval here, is there another way? s_name = getattr(gui.theme, "service_" + service_name) image = utils.safe_gtk_pixbuf_load(s_name) except: image = None session_combo.get_model().append([image, service_name]) name_to_ext[service_name] = (ext_id, ext) count += 1 if session_found: session_combo.set_active(index) else: session_combo.set_active(default_session_index) session_combo.connect('changed', on_session_changed, name_to_ext) self.__combo_session_list.append(session_combo) return name_to_ext
def _create_indicator(self, subtype, sender, body, extra_text = '', cid=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.get(body) pixbuf = utils.safe_gtk_pixbuf_load(contact.picture, (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 cid is not None: ind.set_property("body", str(cid)) 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] = cid self.r_indicator_dict[cid] = ind for old_cid in self.indicator_dict.values(): if old_cid not in self.handler.session.conversations.keys(): # workaround: kill the orphan indicator ind = self.r_indicator_dict[old_cid] del self.indicator_dict[ind] del self.r_indicator_dict[old_cid] else: return
def set_picture_cb(response, filename): '''callback for the avatar chooser''' if response == gui.stock.ACCEPT: if self.config_dir.base_dir.replace('@', '-at-') == \ os.path.dirname(os.path.dirname(filename)): self.session.set_picture(filename) os.remove(self.avatar_path) shutil.copy2(filename, self.avatar_path) return #i save in 128*128 for the animation on connect..if somebody like it...:) try: pix_128 = utils.safe_gtk_pixbuf_load(filename, (128,128)) pix_128.save(path_dir + '_temp', 'png') self.session.set_picture(path_dir + '_temp') if os.path.exists(self.avatar_path): os.remove(self.avatar_path) pix_128.save(self.avatar_path, 'png') except OSError as e: print e
def _update_fields(self, account): ''' update the different fields according to the account that is on the account entry ''' self._clear_all() if account == '': return flag = False if account in self.accounts: attr = int(self.remembers[account]) self.remember_account.set_sensitive(False) self.forget_me.set_child_visible(True) self.btn_status.set_status(int(self.status[account])) path = self.config_dir.join(account.replace('@','-at-'), 'avatars', 'last') if self.config_dir.file_readable(path): pix = utils.safe_gtk_pixbuf_load(path, (96,96)) self.img_account.set_from_pixbuf(pix) if attr == 3:#autologin,password,account checked self.auto_login.set_active(True) flag = True elif attr == 2:#password,account checked self.remember_password.set_active(True) flag = True elif attr == 1:#only account checked self.remember_account.set_active(True) self.remember_password.set_sensitive(False) else:#if i'm here i have an error self.show_error(_( 'Error while reading user config')) self._clear_all() #for not repeating code if flag: passw = self.accounts[account] self.txt_password.set_text(base64.b64decode(passw)) self.txt_password.set_sensitive(False)
def show_tooltip(self, view, origCoords, path_array, obj): ''' shows the tooltip of an e3.Contact ''' self.tag = -1 text = xml.sax.saxutils.escape(Renderers.msnplus_to_plain_text(obj.nick)) text += '\n' + xml.sax.saxutils.escape(Renderers.msnplus_to_plain_text(obj.message)) text += '\n' + self.data_string % (\ obj.account, self.yes_no[bool(obj.blocked)]) self.label.set_markup(text) # Sets tooltip image pixbuf = utils.safe_gtk_pixbuf_load(obj.picture, (96,96)) self.image.set_from_pixbuf(pixbuf) self.image.show() # set the location of the tooltip x, y = self.computePosition(origCoords, view.window) self.move(x, y) self.show() return False
def replace_emoticons(text): '''replace emotes with pixbufs''' emote_theme = gui.theme.emote_theme shortcuts = emote_theme.shortcuts emoticon_list = [] for shortcut in shortcuts: eshort = gui.base.MarkupParser.escape(shortcut) if eshort in text: if shortcut in emote_theme.shortcuts: path = emote_theme.emote_to_path(shortcut, remove_protocol=True) if path is not None: hclist = html_code_list(text) pos = text.find(eshort) while pos > -1: if pos not in hclist: emoticon_list.append([pos, eshort, path]) pos = text.find(eshort, pos + 1) emoticon_list.sort() parsed_pos = 0 text_list = [] close_tags_index = [] for emoticon in emoticon_list: if emoticon[0] >= parsed_pos: # append non-empty string into list if emoticon[0] != parsed_pos: text_list.append(text[parsed_pos:emoticon[0]]) close_tags_index.append(len(text_list) - 1) text_list.append(utils.safe_gtk_pixbuf_load(emoticon[2])) parsed_pos = emoticon[0] + len(emoticon[1]) text_list.append(text[parsed_pos:]) close_tags_index.append(len(text_list) - 1) for idx in range(len(close_tags_index) - 1): tl_idx1 = close_tags_index[idx] tl_idx2 = close_tags_index[idx + 1] text_list[tl_idx1], text_list[tl_idx2] = close_tags(text_list[tl_idx1], text_list[tl_idx2]) return text_list
def add(self, stat, timestamp, text): '''add a row to the widget''' pix = utils.safe_gtk_pixbuf_load( gui.theme.image_theme.status_icons[stat]) date_text = time.strftime('%c', time.localtime(timestamp)) self.model.append((pix, date_text, text))
def add(self, stat, timestamp, text): """add a row to the widget""" pix = utils.safe_gtk_pixbuf_load(gui.theme.image_theme.status_icons[stat]) date_text = time.strftime("%c", time.localtime(timestamp)) self.model.append((pix, date_text, text))
def __init__(self, callback, on_preferences_changed, config, config_dir, config_path, proxy=None, use_http=None, session_id=None): gtk.Alignment.__init__(self, xalign=0.5, yalign=0.5, xscale=0.0, yscale=1.0) self.config = config self.config_dir = config_dir self.config_path = config_path self.callback = callback self.on_preferences_changed = on_preferences_changed # the id of the default extension that handles the session # used to select the default session on the preference dialog self.use_http = use_http self.session_id = session_id account = self.config.get_or_set('last_logged_account', '') self.remembers = self.config.get_or_set('d_remembers', {}) self.status = self.config.get_or_set('d_status',{}) self.accounts = self.config.d_accounts if proxy is None: self.proxy = e3.Proxy() else: self.proxy = proxy self.dialog = extension.get_default('dialog') Avatar = extension.get_default('avatar') NiceBar = extension.get_default('nice bar') if session_id is not None: for ext_id, ext in extension.get_extensions('session').iteritems(): if session_id == ext_id: self.server_host = ext.DEFAULT_HOST self.server_port = ext.DEFAULT_PORT else: self.server_host = extension.get_default('session').DEFAULT_HOST self.server_port = extension.get_default('session').DEFAULT_PORT else: self.server_host = extension.get_default('session').DEFAULT_HOST self.server_port = extension.get_default('session').DEFAULT_PORT self.liststore = gtk.ListStore(gobject.TYPE_STRING, gtk.gdk.Pixbuf) completion = gtk.EntryCompletion() completion.set_model(self.liststore) pixbufcell = gtk.CellRendererPixbuf() completion.pack_start(pixbufcell) completion.add_attribute(pixbufcell, 'pixbuf', 1) completion.set_text_column(0) completion.set_inline_selection(True) self.pixbuf = utils.safe_gtk_pixbuf_load(gui.theme.user) self._reload_account_list() self.cmb_account = gtk.ComboBoxEntry(self.liststore, 0) self.cmb_account.get_children()[0].set_completion(completion) self.cmb_account.get_children()[0].connect('key-press-event', self._on_account_key_press) self.cmb_account.connect('changed', self._on_account_changed) self.btn_status = StatusButton.StatusButton() self.btn_status.set_status(e3.status.ONLINE) self.txt_password = gtk.Entry() self.txt_password.set_visibility(False) self.txt_password.connect('key-press-event', self._on_password_key_press) self.txt_password.connect('changed', self._on_password_changed) self.txt_password.set_sensitive(False) pix_account = utils.safe_gtk_pixbuf_load(gui.theme.user) pix_password = utils.safe_gtk_pixbuf_load(gui.theme.password) self.avatar = Avatar() avatar_path = self.config_dir.join(self.server_host, account, 'avatars', 'last') self.avatar.set_from_file(avatar_path) self.remember_account = gtk.CheckButton(_('Remember me')) self.remember_password = gtk.CheckButton(_('Remember password')) self.auto_login = gtk.CheckButton(_('Auto-login')) self.remember_account.connect('toggled', self._on_remember_account_toggled) self.remember_password.connect('toggled', self._on_remember_password_toggled) self.auto_login.connect('toggled', self._on_auto_login_toggled) self.remember_account.set_sensitive(False) self.remember_password.set_sensitive(False) self.auto_login.set_sensitive(False) self.forget_me = gtk.Button() self.forget_me.set_tooltip_text(_('Delete user')) forget_img = gtk.image_new_from_stock(gtk.STOCK_CANCEL, gtk.ICON_SIZE_MENU) self.forget_me.set_image(forget_img) self.forget_me.set_relief(gtk.RELIEF_NONE) self.forget_me.set_border_width(0) self.forget_me.connect('clicked', self._on_forget_me_clicked) self.forget_me.set_sensitive(False) hboxremember = gtk.HBox(spacing=2) hboxremember.pack_start(self.remember_account, False, False) vbox_remember = gtk.VBox(spacing=4) vbox_remember.set_border_width(8) vbox_remember.pack_start(hboxremember) vbox_remember.pack_start(self.remember_password) vbox_remember.pack_start(self.auto_login) self.b_connect = gtk.Button(stock=gtk.STOCK_CONNECT) self.b_connect.connect('clicked', self._on_connect_clicked) self.b_connect.set_border_width(8) self.b_connect.set_sensitive(False) vbox = gtk.VBox() hbox_account = gtk.HBox(spacing=6) img_accountpix = gtk.Image() img_accountpix.set_from_pixbuf(utils.scale_nicely(pix_account)) hbox_account.pack_start(img_accountpix, False) hbox_account.pack_start(self.cmb_account, True, True) hbox_account.pack_start(self.forget_me, False) hbox_password = gtk.HBox(spacing=6) img_password = gtk.Image() img_password.set_from_pixbuf(utils.scale_nicely(pix_password)) hbox_password.pack_start(img_password, False) hbox_password.pack_start(self.txt_password, True, True) hbox_password.pack_start(self.btn_status, False) vbox_entries = gtk.VBox(spacing=12) vbox_entries.set_border_width(8) vbox_entries.pack_start(hbox_account) vbox_entries.pack_start(hbox_password) self.b_preferences = gtk.Button() self.img_preferences = gtk.image_new_from_stock(gtk.STOCK_PREFERENCES, gtk.ICON_SIZE_MENU) self.img_preferences.set_sensitive(False) self.b_preferences.set_image(self.img_preferences) self.b_preferences.set_relief(gtk.RELIEF_NONE) self.b_preferences.connect('enter-notify-event', self._on_preferences_enter) self.b_preferences.connect('leave-notify-event', self._on_preferences_leave) self.b_preferences.connect('clicked', self._on_preferences_selected) self.nicebar = NiceBar() al_vbox_entries = gtk.Alignment(xalign=0.5, yalign=0.5, xscale=0.2, yscale=0.0) al_vbox_remember = gtk.Alignment(xalign=0.5, yalign=0.5, xscale=0.0, yscale=0.2) al_button = gtk.Alignment(xalign=0.5, yalign=0.5, xscale=0.20) al_account = gtk.Alignment(xalign=0.5, yalign=0.5, xscale=0.0, yscale=0.0) al_preferences = gtk.Alignment(xalign=1.0, yalign=0.5) al_vbox_entries.add(vbox_entries) al_vbox_remember.add(vbox_remember) al_button.add(self.b_connect) al_account.add(self.avatar) al_preferences.add(self.b_preferences) vbox.pack_start(self.nicebar, False) vbox.pack_start(al_account, True, False) vbox.pack_start(al_vbox_entries, True, True) vbox.pack_start(al_vbox_remember, True, False) vbox.pack_start(al_button, True, True) vbox.pack_start(al_preferences, False) self.add(vbox) vbox.show_all() self.nicebar.hide() if account != '': self.cmb_account.get_children()[0].set_text(account)
def add(self, stat, timestamp, text): '''add a row to the widget''' pix = utils.safe_gtk_pixbuf_load(gui.theme.status_icons[stat]) date_text = time.strftime('%c', time.gmtime(timestamp)) self.model.append((pix, date_text, text))
def on_picture_change_succeed(self, account, path): '''callback called when the picture of an account is changed''' # out account if account == self.session.account.account: pixbuf = utils.safe_gtk_pixbuf_load(path, (32, 32)) self.image.set_from_pixbuf(pixbuf)
def __init__(self, title, text, picturePath, callback): 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( picturePath[7:], avatar_size, avatar_size) except: userPixbuf = utils.safe_gtk_pixbuf_load(gui.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) # 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, callback, args=None): gtk.Alignment.__init__(self, xalign=0.5, yalign=0.5, xscale=0.0, yscale=1.0) self.dialog = extension.get_default('dialog') Avatar = extension.get_default('avatar') NiceBar = extension.get_default('nice bar') self.liststore = gtk.ListStore(gobject.TYPE_STRING, gtk.gdk.Pixbuf) completion = gtk.EntryCompletion() completion.set_model(self.liststore) pixbufcell = gtk.CellRendererPixbuf() completion.pack_start(pixbufcell) completion.add_attribute(pixbufcell, 'pixbuf', 1) completion.set_text_column(0) completion.set_inline_selection(True) self.pixbuf = utils.safe_gtk_pixbuf_load(gui.theme.image_theme.user) self.cmb_account = gtk.ComboBoxEntry(self.liststore, 0) self.cmb_account.set_tooltip_text(_('Account')) self.cmb_account.get_children()[0].set_completion(completion) self.cmb_account.get_children()[0].connect('key-press-event', self._on_account_key_press) self.cmb_account.connect('changed', self._on_account_changed) self.acc_key_rel_handler = self.cmb_account.connect( 'key-release-event', self._on_account_key_release) self.btn_status = StatusButton.StatusButton() self.btn_status.set_tooltip_text(_('Status')) self.btn_status.set_status(e3.status.ONLINE) self.btn_status.set_size_request(34, -1) self.txt_password = gtk.Entry() self.txt_password.set_tooltip_text(_('Password')) self.txt_password.set_visibility(False) self.txt_password.connect('key-press-event', self._on_password_key_press) self.txt_password.connect('changed', self._on_password_changed) self.txt_password.set_sensitive(False) pix_account = utils.safe_gtk_pixbuf_load(gui.theme.image_theme.user) pix_password = utils.safe_gtk_pixbuf_load( gui.theme.image_theme.password) self.avatar = Avatar() self.remember_account = gtk.CheckButton(_('Remember me')) self.remember_password = gtk.CheckButton(_('Remember password')) self.auto_login = gtk.CheckButton(_('Auto-login')) self.remember_account.connect('toggled', self._on_remember_account_toggled) self.remember_password.connect('toggled', self._on_remember_password_toggled) self.auto_login.connect('toggled', self._on_auto_login_toggled) self.remember_account.set_sensitive(False) self.remember_password.set_sensitive(False) self.auto_login.set_sensitive(False) self.forget_me = gtk.Button() self.forget_me.set_tooltip_text(_('Delete user')) forget_img = gtk.image_new_from_stock(gtk.STOCK_CANCEL, gtk.ICON_SIZE_MENU) self.forget_me.set_image(forget_img) self.forget_me.set_relief(gtk.RELIEF_NONE) self.forget_me.set_border_width(0) self.forget_me.set_size_request(34, -1) self.forget_me.connect('clicked', self._on_forget_me_clicked) self.forget_me.set_sensitive(False) hboxremember = gtk.HBox(spacing=2) hboxremember.pack_start(self.remember_account, False) vbox_remember = gtk.VBox(spacing=4) vbox_remember.set_border_width(8) vbox_remember.pack_start(hboxremember) vbox_remember.pack_start(self.remember_password) vbox_remember.pack_start(self.auto_login) vbox_remember.pack_start(gtk.Label()) self.b_connect = gtk.Button(stock=gtk.STOCK_CONNECT) self.b_connect.set_sensitive(False) self.b_cancel = gtk.Button(stock=gtk.STOCK_CANCEL) self.b_cancel.connect('clicked', self._on_cancel_clicked) vbuttonbox = gtk.VButtonBox() vbuttonbox.set_spacing(8) vbuttonbox.pack_start(self.b_connect) vbuttonbox.pack_start(self.b_cancel) vbox_content = gtk.VBox() hbox_account = gtk.HBox(spacing=6) img_accountpix = gtk.Image() img_accountpix.set_from_pixbuf(utils.scale_nicely(pix_account)) hbox_account.pack_start(img_accountpix, False) hbox_account.pack_start(self.cmb_account) hbox_account.pack_start(self.forget_me, False) hbox_password = gtk.HBox(spacing=6) img_password = gtk.Image() img_password.set_from_pixbuf(utils.scale_nicely(pix_password)) hbox_password.pack_start(img_password, False) hbox_password.pack_start(self.txt_password) hbox_password.pack_start(self.btn_status, False) session_combo_store = gtk.ListStore(gtk.gdk.Pixbuf, str) crp = gtk.CellRendererPixbuf() crt = gtk.CellRendererText() crp.set_property("xalign", 0) crt.set_property("xalign", 0) self.session_combo = gtk.ComboBox() self.session_combo.set_tooltip_text(_('Choose your network')) self.session_combo.set_model(session_combo_store) self.session_combo.pack_start(crp) self.session_combo.pack_start(crt) self.session_combo.add_attribute(crp, "pixbuf", 0) self.session_combo.add_attribute(crt, "text", 1) self.b_preferences = gtk.Button() self.b_preferences.set_tooltip_text(_('Preferences')) self.img_preferences = gtk.image_new_from_stock( gtk.STOCK_PREFERENCES, gtk.ICON_SIZE_MENU) self.img_preferences.set_sensitive(False) self.b_preferences.set_image(self.img_preferences) self.b_preferences.set_relief(gtk.RELIEF_NONE) self.b_preferences.connect('enter-notify-event', self._on_preferences_enter) self.b_preferences.connect('leave-notify-event', self._on_preferences_leave) self.b_preferences.connect('clicked', self._on_preferences_selected) self.b_preferences.set_size_request(34, -1) img_sessionpix = gtk.image_new_from_stock(gtk.STOCK_CONNECT, gtk.ICON_SIZE_MENU) img_sessionpix.set_size_request(20, -1) img_sessionpix.set_sensitive(False) hbox_session = gtk.HBox(spacing=6) hbox_session.pack_start(img_sessionpix, False) hbox_session.pack_start(self.session_combo) hbox_session.pack_start(self.b_preferences, False) vbox_entries = gtk.VBox(spacing=12) vbox_entries.set_border_width(8) vbox_entries.pack_start(hbox_account) vbox_entries.pack_start(hbox_password) vbox_entries.pack_start(hbox_session) self.nicebar = NiceBar() th_pix = utils.safe_gtk_pixbuf_load(gui.theme.image_theme.throbber, None, animated=True) self.throbber = gtk.image_new_from_animation(th_pix) self.label_timer = gtk.Label() self.label_timer.set_markup(_('<b>Connection error!\n </b>')) al_label_timer = gtk.Alignment(xalign=0.5, yalign=0.5, xscale=0.0, yscale=0.0) al_throbber = gtk.Alignment(xalign=0.5, yalign=0.5, xscale=0.1, yscale=0.1) al_vbox_entries = gtk.Alignment(xalign=0.5, yalign=0.5, xscale=0.2, yscale=0.0) al_vbox_remember = gtk.Alignment(xalign=0.5, yalign=0.5, xscale=0.0, yscale=0.2) al_button = gtk.Alignment(xalign=0.5, yalign=0.5, xscale=0.2) al_account = gtk.Alignment(xalign=0.5, yalign=0.5, xscale=0.0, yscale=0.3) al_label_timer.add(self.label_timer) al_throbber.add(self.throbber) al_vbox_entries.add(vbox_entries) al_vbox_remember.add(vbox_remember) al_button.add(vbuttonbox) al_account.add(self.avatar) vbox = gtk.VBox() vbox_top = gtk.VBox() vbox_far_bottom = gtk.VBox() vbox_bottom = gtk.VBox(False) vbox_content.pack_start(gtk.Label(""), True, True) vbox_content.pack_start(al_account, True, False) vbox_content.pack_start(gtk.Label(""), True, True) vbox_content.pack_start(al_vbox_entries, False) vbox_content.pack_start(al_vbox_remember, True, False) vbox_bottom.set_size_request(-1, 100) vbox_bottom.pack_start(al_label_timer, True, False) vbox_bottom.pack_start(al_throbber, False) vbox_bottom.pack_start(gtk.Label(""), True, True) vbox_bottom.pack_start(al_button) vbox_content.pack_start(vbox_bottom) vbox_content.pack_start(gtk.Label(""), True, True) vbox.pack_start(self.nicebar, False) vbox.pack_start(vbox_top) vbox.pack_start(vbox_content) vbox.pack_start(vbox_far_bottom) self.add(vbox) vbox.show_all()
def add_contact(self, contact, group=None): '''add a contact to the contact list, add it to the group if group is not None''' try: weight = int(self.session.config.d_weights.get(contact.account, 0)) except ValueError: weight = 0 self.session.config.d_weights[contact.account] = weight offline = contact.status == e3.status.OFFLINE is_online = not offline contact_data = ( self._get_contact_pixbuf_or_default(contact), contact, self.format_nick(contact), True, utils.safe_gtk_pixbuf_load( gui.theme.image_theme.status_icons[contact.status]), weight, False, offline) # if group_offline is set and the contact is offline then put it on the # special offline group if self.group_offline and offline: duplicate = self._duplicate_check(contact) if duplicate is not None: return duplicate if not self.offline_group: self.session.config.d_weights['1'] = 0 self.offline_group = e3.Group(_("Offline"), identifier='1', type_=e3.Group.OFFLINE) self.offline_group_iter = self.add_group( self.offline_group, True) self.offline_group.contacts.append(contact.account) self.update_offline_group() return self._model.append(self.offline_group_iter, contact_data) # if we are in order by status mode and contact is online, # we add online contacts to their online group :) if self.order_by_status and is_online: duplicate = self._duplicate_check(contact) if duplicate is not None: return duplicate if not self.online_group: self.session.config.d_weights['0'] = 1 self.online_group = e3.Group(_("Online"), identifier='0', type_=e3.Group.ONLINE) self.online_group_iter = self.add_group( self.online_group, True) self.online_group.contacts.append(contact.account) self.update_online_group() return self._model.append(self.online_group_iter, contact_data) # if it has no group and we are in order by group then add it to the # special group "No group" if not group and not self.order_by_status: if self.no_group: self.no_group.contacts.append(contact.account) self.update_no_group() return self._model.append(self.no_group_iter, contact_data) else: self.no_group = e3.Group(_("No group"), identifier='0', type_=e3.Group.NONE) self.no_group_iter = self.add_group(self.no_group, True) self.no_group.contacts.append(contact.account) self.update_no_group() return self._model.append(self.no_group_iter, contact_data) # if no group add it to the root, but check that it's not on a group # or in the root already if not group or self.order_by_status: for row in self._model: obj = row[1] # check on group if isinstance(obj, e3.Group): for contact_row in row.iterchildren(): con = contact_row[1] if con.account == contact.account: return contact_row.iter # check on the root elif isinstance(obj, e3.Contact) and obj.account == contact.account: return row.iter return self._model.append(None, contact_data) for row in self._model: obj = row[1] if isinstance(obj, e3.Group) and obj.name == group.name: # if the contact is already on the group, then dont add it for contact_row in row.iterchildren(): con = contact_row[1] if con.account == contact.account: return contact_row.iter return_iter = self._model.append(row.iter, contact_data) self.update_group(group) # search the use on the root to remove it if it's there # since we added him to a group for irow in self._model: iobj = irow[1] if isinstance(iobj, e3.Contact) and \ iobj.account == contact.account: del self._model[irow.iter] return return_iter else: #######WTF??? where does this belong??? self.add_group(group) result = self.add_contact(contact, group) self.update_group(group) return result
def __init__(self, title, text, picturePath, callback): 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( picturePath[7:], avatar_size, avatar_size) except: userPixbuf = utils.safe_gtk_pixbuf_load(gui.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) # 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, callback, on_preferences_changed, config, config_dir, config_path, proxy=None, use_http=None, session_id=None): gtk.Alignment.__init__(self, xalign=0.5, yalign=0.5, xscale=1.0, yscale=1.0) self.config = config self.config_dir = config_dir self.config_path = config_path self.callback = callback self.on_preferences_changed = on_preferences_changed # the id of the default extension that handles the session # used to select the default session on the preference dialog self.use_http = use_http self.session_id = session_id account = self.config.get_or_set('last_logged_account', '') self.remembers = self.config.get_or_set('d_remembers', {}) self.status = self.config.get_or_set('d_status',{}) self.accounts = self.config.d_accounts if proxy is None: self.proxy = e3.Proxy() else: self.proxy = proxy self.dialog = extension.get_default('dialog') if session_id is not None: for ext_id, ext in extension.get_extensions('session').iteritems(): if session_id == ext_id: self.server_host = ext.DEFAULT_HOST self.server_port = ext.DEFAULT_PORT else: self.server_host = extension.get_default('session').DEFAULT_HOST self.server_port = extension.get_default('session').DEFAULT_PORT self.liststore = gtk.ListStore(gobject.TYPE_STRING, gtk.gdk.Pixbuf) completion = gtk.EntryCompletion() completion.set_model(self.liststore) pixbufcell = gtk.CellRendererPixbuf() completion.pack_start(pixbufcell) completion.add_attribute(pixbufcell, 'pixbuf', 1) completion.set_text_column(0) completion.set_inline_selection(True) self.pixbuf = utils.safe_gtk_pixbuf_load(gui.theme.user) self._reload_account_list() self.cmb_account = gtk.ComboBoxEntry(self.liststore, 0) self.cmb_account.get_children()[0].set_completion(completion) self.cmb_account.get_children()[0].connect('key-press-event', self._on_account_key_press) self.cmb_account.connect('changed', self._on_account_changed) self.btn_status = StatusButton.StatusButton() self.btn_status.set_status(e3.status.ONLINE) status_padding = gtk.Label() status_padding.set_size_request(*self.btn_status.size_request()) self.txt_password = gtk.Entry() self.txt_password.set_visibility(False) self.txt_password.connect('key-press-event', self._on_password_key_press) self.txt_password.connect('changed', self._on_password_changed) pix_account = utils.safe_gtk_pixbuf_load(gui.theme.user) pix_password = utils.safe_gtk_pixbuf_load(gui.theme.password) self.img_account = gtk.Image() path = self.config_dir.join(account.replace('@','-at-'), \ 'avatars', 'last') if self.config_dir.file_readable(path): pix = utils.safe_gtk_pixbuf_load(path, (96,96)) else: pix = utils.safe_gtk_pixbuf_load(gui.theme.logo) self.img_account.set_from_pixbuf(pix) self.remember_account = gtk.CheckButton(_('Remember me')) self.remember_password = gtk.CheckButton(_('Remember password')) self.auto_login = gtk.CheckButton(_('Auto-login')) self.remember_account.connect('toggled', self._on_remember_account_toggled) self.remember_password.connect('toggled', self._on_remember_password_toggled) self.auto_login.connect('toggled', self._on_auto_login_toggled) self.forget_me = gtk.EventBox() self.forget_me.set_events(gtk.gdk.BUTTON_PRESS_MASK) self.forget_me_label = gtk.Label('<span foreground="#0000AA">(' + \ _('Forget me') + ')</span>') self.forget_me_label.set_use_markup(True) self.forget_me.add(self.forget_me_label) self.forget_me.connect('button_press_event', self._on_forget_me_clicked) self.forget_me.set_child_visible(False) hboxremember = gtk.HBox(spacing=2) hboxremember.pack_start(self.remember_account, False, False) hboxremember.pack_start(self.forget_me, False, False) vbox_remember = gtk.VBox(spacing=4) vbox_remember.set_border_width(8) vbox_remember.pack_start(hboxremember) vbox_remember.pack_start(self.remember_password) vbox_remember.pack_start(self.auto_login) self.b_connect = gtk.Button(stock=gtk.STOCK_CONNECT) self.b_connect.connect('clicked', self._on_connect_clicked) self.b_connect.set_border_width(8) vbox = gtk.VBox() hbox_account = gtk.HBox(spacing=6) img_accountpix = gtk.Image() img_accountpix.set_from_pixbuf(utils.scale_nicely(pix_account)) hbox_account.pack_start(img_accountpix, False) hbox_account.pack_start(self.cmb_account, True, True) hbox_account.pack_start(status_padding, False) hbox_password = gtk.HBox(spacing=6) img_password = gtk.Image() img_password.set_from_pixbuf(utils.scale_nicely(pix_password)) hbox_password.pack_start(img_password, False) hbox_password.pack_start(self.txt_password, True, True) hbox_password.pack_start(self.btn_status, False) vbox_entries = gtk.VBox(spacing=12) vbox_entries.set_border_width(8) vbox_entries.pack_start(hbox_account) vbox_entries.pack_start(hbox_password) self.b_preferences = gtk.Button() self.img_preferences = gtk.image_new_from_stock(gtk.STOCK_PREFERENCES, gtk.ICON_SIZE_MENU) self.img_preferences.set_sensitive(False) self.b_preferences.set_image(self.img_preferences) self.b_preferences.set_relief(gtk.RELIEF_NONE) self.b_preferences.connect('enter-notify-event', self._on_preferences_enter) self.b_preferences.connect('leave-notify-event', self._on_preferences_leave) self.b_preferences.connect('clicked', self._on_preferences_selected) self.nicebar = NiceBar.NiceBar(default_background= \ NiceBar.ALERTBACKGROUND) al_logo = gtk.Alignment(xalign=0.5, yalign=0.5, xscale=0.0, yscale=0.0) al_vbox_entries = gtk.Alignment(xalign=0.5, yalign=0.5, xscale=0.2, yscale=0.0) al_vbox_remember = gtk.Alignment(xalign=0.55, yalign=0.5, xscale=0.05, yscale=0.2) al_button = gtk.Alignment(xalign=0.5, yalign=0.5, xscale=0.15) al_account = gtk.Alignment(xalign=0.5, yalign=0.5, xscale=0.0, yscale=0.0) al_preferences = gtk.Alignment(xalign=1.0, yalign=0.5) al_vbox_entries.add(vbox_entries) al_vbox_remember.add(vbox_remember) al_button.add(self.b_connect) al_account.add(self.img_account) al_preferences.add(self.b_preferences) vbox.pack_start(self.nicebar, False) vbox.pack_start(al_account, True, False) vbox.pack_start(al_vbox_entries, True, True) vbox.pack_start(al_vbox_remember, True, False) vbox.pack_start(al_button, True, True) vbox.pack_start(al_preferences, False) self.add(vbox) vbox.show_all() self.nicebar.hide() if account != '': self.cmb_account.get_children()[0].set_text(account)
def add_contact(self, contact, group=None): '''add a contact to the contact list, add it to the group if group is not None''' try: weight = int(self.session.config.d_weights.get(contact.account, 0)) except ValueError: weight = 0 self.session.config.d_weights[contact.account] = weight offline = contact.status == e3.status.OFFLINE is_online = not offline contact_data = (self._get_contact_pixbuf_or_default(contact), contact, self.format_nick(contact), True, utils.safe_gtk_pixbuf_load(gui.theme.status_icons[contact.status]), weight, False, offline) # if group_offline is set and the contact is offline then put it on the # special offline group if self.group_offline and offline: if not self.offline_group: self.offline_group = e3.Group(_("Offline"), type_ = e3.Group.OFFLINE) self.offline_group_iter = self.add_group(self.offline_group, True) self.offline_group.contacts.append(contact.account) self.update_offline_group() return self._model.append(self.offline_group_iter, contact_data) # if we are in order by status mode and contact is online, # we add online contacts to their online group :) if self.order_by_status and is_online: if not self.online_group: self.online_group = e3.Group(_("Online"), type_ = e3.Group.ONLINE) self.online_group_iter = self.add_group(self.online_group, True) self.online_group.contacts.append(contact.account) self.update_online_group() return self._model.append(self.online_group_iter, contact_data) # if it has no group and we are in order by group then add it to the # special group "No group" if not group and not self.order_by_status: if self.no_group: self.no_group.contacts.append(contact.account) self.update_no_group() return self._model.append(self.no_group_iter, contact_data) else: self.no_group = e3.Group(_("No group"), type_ = e3.Group.NONE) self.no_group_iter = self.add_group(self.no_group, True) self.no_group.contacts.append(contact.account) self.update_no_group() return self._model.append(self.no_group_iter, contact_data) # if no group add it to the root, but check that it's not on a group # or in the root already if not group or self.order_by_status: for row in self._model: obj = row[1] # check on group if type(obj) == e3.Group: for contact_row in row.iterchildren(): con = contact_row[1] if con.account == contact.account: return contact_row.iter # check on the root elif type(obj) == e3.Contact and obj.account == contact.account: return row.iter return self._model.append(None, contact_data) for row in self._model: obj = row[1] if type(obj) == e3.Group and obj.name == group.name: # if the contact is already on the group, then dont add it for contact_row in row.iterchildren(): con = contact_row[1] if con.account == contact.account: return contact_row.iter return_iter = self._model.append(row.iter, contact_data) self.update_group(group) # search the use on the root to remove it if it's there # since we added him to a group for irow in self._model: iobj = irow[1] if type(iobj) == e3.Contact and \ iobj.account == contact.account: del self._model[irow.iter] return return_iter else: #######WTF??? self.add_group(group) result = self.add_contact(contact, group) self.update_group(group) return result
def update_contact(self, contact): '''update the data of contact''' try: weight = int(self.session.config.d_weights.get(contact.account, 0)) except ValueError: weight = 0 self.session.config.d_weights[contact.account] = weight offline = contact.status == e3.status.OFFLINE online = not offline contact_data = ( self._get_contact_pixbuf_or_default(contact), contact, self.format_nick(contact), True, utils.safe_gtk_pixbuf_load( gui.theme.image_theme.status_icons[contact.status]), weight, False, offline) found = False group_found = None for row in self._model: obj = row[1] if isinstance(obj, e3.Group): for contact_row in row.iterchildren(): con = contact_row[1] if con.account == contact.account: found = True group_found = obj self._model[contact_row.iter] = contact_data self.update_group(obj) elif isinstance(obj, e3.Contact) and obj.account == contact.account: found = True self._model[row.iter] = contact_data # if we are in order by status, the contact was found and now is offline/online # delete contact from offline/online group and add to the oposite. if self.order_by_status and found: # y todavia no estoy en el grupo. if offline and group_found != self.offline_group: self.remove_contact(contact, self.online_group) self.add_contact(contact, self.offline_group) if online and group_found != self.online_group: self.remove_contact(contact, self.offline_group) self.add_contact(contact, self.online_group) if self.order_by_group and self.group_offline and found: # y todavia no estoy en el grupo. if offline and group_found != self.offline_group: self.remove_contact(contact, group_found) self.add_contact(contact, self.offline_group) if online and group_found == self.offline_group: self.remove_contact(contact, self.offline_group) if len(contact.groups) == 0: self.add_contact(contact) else: for group in contact.groups: self.add_contact(contact, self.session.groups[group])
def __init__(self, callback, args=None): gtk.Alignment.__init__(self, xalign=0.5, yalign=0.5, xscale=0.0, yscale=1.0) self.dialog = extension.get_default('dialog') Avatar = extension.get_default('avatar') NiceBar = extension.get_default('nice bar') default_session = extension.get_default('session') self.liststore = gtk.ListStore(gobject.TYPE_STRING, gtk.gdk.Pixbuf) completion = gtk.EntryCompletion() completion.set_model(self.liststore) pixbufcell = gtk.CellRendererPixbuf() completion.pack_start(pixbufcell) completion.add_attribute(pixbufcell, 'pixbuf', 1) completion.set_text_column(0) completion.set_inline_selection(True) self.pixbuf = utils.safe_gtk_pixbuf_load(gui.theme.user) self.cmb_account = gtk.ComboBoxEntry(self.liststore, 0) self.cmb_account.get_children()[0].set_completion(completion) self.cmb_account.get_children()[0].connect('key-press-event', self._on_account_key_press) self.cmb_account.connect('changed', self._on_account_changed) self.cmb_account.connect('key-release-event', self._on_account_key_release) self.btn_status = StatusButton.StatusButton() self.btn_status.set_status(e3.status.ONLINE) self.txt_password = gtk.Entry() self.txt_password.set_visibility(False) self.txt_password.connect('key-press-event', self._on_password_key_press) self.txt_password.connect('changed', self._on_password_changed) self.txt_password.set_sensitive(False) pix_account = utils.safe_gtk_pixbuf_load(gui.theme.user) pix_password = utils.safe_gtk_pixbuf_load(gui.theme.password) self.avatar = Avatar() self.remember_account = gtk.CheckButton(_('Remember me')) self.remember_password = gtk.CheckButton(_('Remember password')) self.auto_login = gtk.CheckButton(_('Auto-login')) self.remember_account.connect('toggled', self._on_remember_account_toggled) self.remember_password.connect('toggled', self._on_remember_password_toggled) self.auto_login.connect('toggled', self._on_auto_login_toggled) self.remember_account.set_sensitive(False) self.remember_password.set_sensitive(False) self.auto_login.set_sensitive(False) self.forget_me = gtk.Button() self.forget_me.set_tooltip_text(_('Delete user')) forget_img = gtk.image_new_from_stock(gtk.STOCK_CANCEL, gtk.ICON_SIZE_MENU) self.forget_me.set_image(forget_img) self.forget_me.set_relief(gtk.RELIEF_NONE) self.forget_me.set_border_width(0) self.forget_me.connect('clicked', self._on_forget_me_clicked) self.forget_me.set_sensitive(False) hboxremember = gtk.HBox(spacing=2) hboxremember.pack_start(self.remember_account, False, False) vbox_remember = gtk.VBox(spacing=4) vbox_remember.set_border_width(8) vbox_remember.pack_start(hboxremember) vbox_remember.pack_start(self.remember_password) vbox_remember.pack_start(self.auto_login) self.b_connect = gtk.Button(stock=gtk.STOCK_CONNECT) self.b_connect.connect('clicked', self._on_connect_clicked) self.b_connect.set_sensitive(False) self.b_cancel = gtk.Button(stock=gtk.STOCK_CANCEL) self.b_cancel.connect('clicked', self._on_cancel_clicked) vbuttonbox = gtk.VButtonBox() vbuttonbox.set_spacing(8) vbuttonbox.pack_start(self.b_connect) vbuttonbox.pack_start(self.b_cancel) vbox = gtk.VBox() hbox_account = gtk.HBox(spacing=6) img_accountpix = gtk.Image() img_accountpix.set_from_pixbuf(utils.scale_nicely(pix_account)) hbox_account.pack_start(img_accountpix, False) hbox_account.pack_start(self.cmb_account, True, True) hbox_account.pack_start(self.forget_me, False) hbox_password = gtk.HBox(spacing=6) img_password = gtk.Image() img_password.set_from_pixbuf(utils.scale_nicely(pix_password)) hbox_password.pack_start(img_password, False) hbox_password.pack_start(self.txt_password, True, True) hbox_password.pack_start(self.btn_status, False) vbox_entries = gtk.VBox(spacing=12) vbox_entries.set_border_width(8) vbox_entries.pack_start(hbox_account) vbox_entries.pack_start(hbox_password) self.b_preferences = gtk.Button() self.img_preferences = gtk.image_new_from_stock(gtk.STOCK_PREFERENCES, gtk.ICON_SIZE_MENU) self.img_preferences.set_sensitive(False) self.b_preferences.set_image(self.img_preferences) self.b_preferences.set_relief(gtk.RELIEF_NONE) self.b_preferences.connect('enter-notify-event', self._on_preferences_enter) self.b_preferences.connect('leave-notify-event', self._on_preferences_leave) self.b_preferences.connect('clicked', self._on_preferences_selected) self.nicebar = NiceBar() th_pix = utils.safe_gtk_pixbuf_load(gui.theme.throbber, None, animated=True) self.throbber = gtk.image_new_from_animation(th_pix) self.label_timer = gtk.Label() self.label_timer.set_markup(_('<b>Connection error!\n </b>')) al_label_timer = gtk.Alignment(xalign=0.5, yalign=0.5, xscale=0.0, yscale=0.0) al_throbber = gtk.Alignment(xalign=0.5, yalign=0.5, xscale=0.2, yscale=0.2) al_vbox_entries = gtk.Alignment(xalign=0.5, yalign=0.5, xscale=0.2, yscale=0.0) al_vbox_remember = gtk.Alignment(xalign=0.5, yalign=0.5, xscale=0.0, yscale=0.2) al_button = gtk.Alignment(xalign=0.5, yalign=0.5, xscale=0.2) al_account = gtk.Alignment(xalign=0.5, yalign=0.5, xscale=0.0, yscale=0.0) al_preferences = gtk.Alignment(xalign=1.0, yalign=0.5) al_label_timer.add(self.label_timer) al_throbber.add(self.throbber) al_vbox_entries.add(vbox_entries) al_vbox_remember.add(vbox_remember) al_button.add(vbuttonbox) al_account.add(self.avatar) al_preferences.add(self.b_preferences) vbox_bottom = gtk.VBox(True) vbox.pack_start(self.nicebar, False) vbox.pack_start(al_account, True, False) vbox.pack_start(al_vbox_entries, True, True) vbox.pack_start(al_vbox_remember, True, False) vbox_bottom.pack_start(al_label_timer, True, False) vbox_bottom.pack_start(al_throbber, False, False) vbox_bottom.pack_start(al_button, True, True) vbox.pack_start(vbox_bottom, True, True) vbox.pack_start(al_preferences, True, False) self.add(vbox) vbox.show_all()