def prev(self): val = self.get() clip = self.clip if self.index == 0 and val: self.history.add(val) self.index -= 1 if not self.index and clip and clip != val: self.set(clip) elif self.history and abs(self.index) < len(self.history): self.index -= 1 self.set(self.history[self.index]) elif self.backlog is not None: try: messageobj = self.backlog.next() message = getattr(messageobj, 'message', None) if message is not None: message = strip_html2(message) except StopIteration: self.backlog = None else: if message is not None: self.history.insert(0, message) self.prev()
def setup_string_substitution(self): # TODO: this should probably be done once, at the class level...not in a function icon = get_buddy_icon_url def strf(t, fmt=None): if not self.show_tstamp and not self.should_always_show_timestamp: return ' ' fmt = self.tstamp_fmt if fmt is None else fmt for s, repl in strftime_replacements: fmt = fmt.replace(s, repl) return strftime_u(fromutc(t), fmt) def time(m, b, fmt=None): # %a %B %e %H:%M:%S %Y return strf(m.timestamp, fmt) def timeOpened(m, b, fmt=None): # TODO: this is wrong. have convos track their opened datetime return strf(datetime.utcnow(), fmt) def xml_or_None(s): if s is None: return None return s.encode('xml') self.magicattrs = dict( # # magic name = lambda: message, buddy: "template substitution" # chatName=lambda m, b: xml_or_None(self.options.get('chatName')), incomingIconPath=lambda m, b: icon(b), userIconPath=lambda m, b: icon(b), senderScreenName=lambda m, b: xml_or_None(b.name ), # service screenname senderDisplayName=lambda m, b: xml_or_None(b.remote_alias or b. alias), sender=lambda m, b: xml_or_None(getattr(b, 'alias', b.name)), time=time, timeOpened=timeOpened, message=lambda m, b: m.message, service=lambda m, b: protocols[b.service].name if b is not None else '', messageDirection=lambda m, b: 'rtl' if isRTL(strip_html2(m.message)[0]) else 'ltr', )
def setup_string_substitution(self): # TODO: this should probably be done once, at the class level...not in a function icon = get_buddy_icon_url def strf(t, fmt = None): if not self.show_tstamp and not self.should_always_show_timestamp: return ' ' fmt = self.tstamp_fmt if fmt is None else fmt for s, repl in strftime_replacements: fmt = fmt.replace(s, repl) return strftime_u(fromutc(t), fmt) def time(m, b, fmt = None): # %a %B %e %H:%M:%S %Y return strf(m.timestamp, fmt) def timeOpened(m, b, fmt = None): # TODO: this is wrong. have convos track their opened datetime return strf(datetime.utcnow(), fmt) def xml_or_None(s): if s is None: return None return s.encode('xml') self.magicattrs = dict( # # magic name = lambda: message, buddy: "template substitution" # chatName = lambda m, b: xml_or_None(self.options.get('chatName')), incomingIconPath = lambda m, b: icon(b), userIconPath = lambda m, b: icon(b), senderScreenName = lambda m, b: xml_or_None(b.name), # service screenname senderDisplayName = lambda m, b: xml_or_None(b.remote_alias or b.alias), sender = lambda m, b: xml_or_None(getattr(b, 'alias', b.name)), time = time, timeOpened = timeOpened, message = lambda m, b: m.message, service = lambda m, b: protocols[b.service].name if b is not None else '', messageDirection = lambda m, b: 'rtl' if isRTL(strip_html2(m.message)[0]) else 'ltr', )
def stripped_msg(self): from util import strip_html2 return strip_html2(self.status_message)
def fire_notifications(msg, win, isnew, mode, hidden=False): ''' Relays message information to the notifications system, for things like popups and sound effects. msg a message object storage win the ImWin about to show this message isnew a bool indicating if the ImWin is "new" ''' if msg is None or msg.buddy is None: return [] convo = msg.conversation bud = msg.buddy def stop_notify(win=win): if win: try: win.Unnotify() except wx.PyDeadObjectError: pass else: if not win.Top.AnyNotified and pref('conversation_window.notify_flash'): win.Top.StopFlashing() if hidden and pref('messaging.popups.close_dismisses_hidden', False): _remove_hidden_message(bud, msg) if msg.get('content_type', 'text/html') in ('text/html', 'text/xhtml'): try: popup_message = strip_html2(msg.message).decode('xml') except Exception: print_exc() popup_message = msg.message else: popup_message = msg.message # decide on options to pass to the popup fire_opts = dict(buddy = bud, onuserclose = stop_notify) ischat = convo is not None and convo.ischat if ischat: from gui import skin fire_opts.update(header = _('Group Chat ({chat.chat_member_count:d})').format(chat=convo), msg = _('{alias:s}: {message:s}').format(alias=bud.alias, message=popup_message), icon = skin.get('ActionsBar.Icons.RoomList', None), popupid = 'chat!!!%r!!!%r' % (convo.protocol.name, convo.chat_room_name)) else: fire_opts.update(msg = popup_message, icon = bud.buddy_icon if bud is not None else convo.icon, popupid = msg.buddy.idstr()) # Clicking on the popup should open that buddy's message window. # - if there is text entered in the popup and not the IM window, # copy it there if bud is not None: def click_popup(text): if pop_any_hidden(bud): return if convo.ischat: on_message(convo = convo, raisenow = True) else: begin_conversation(bud) if win: try: val = win.input_area.Value except wx.PyDeadObjectError: pass else: if not val: win.input_area.Value = text wx.CallAfter(win.TextCtrl.SetInsertionPointEnd) fire_opts.update(onclick = click_popup) notification = _get_notification_types(bud, convo, win, hidden, isnew) def send_from_popup(text, options, convo = convo, win = win, opts = fire_opts.copy()): if not text: return CallLater(200, stop_notify) # if the window's still around, use its formatting convo.send_message(fmtstr.singleformat(text, format=_get_format(win))) if not wx.GetKeyState(wx.WXK_CONTROL): # returning a string appends it to the popup's content. return '> ' + text # returning None results in the popup closing fire_opts['input'] = send_from_popup return fire(notification, **fire_opts)