home *** CD-ROM | disk | FTP | other *** search
Wrap
# Source Generated with Decompyle++ # File: in.pyo (Python 2.5) from __future__ import with_statement import wx from wx import EVT_BUTTON, MessageBox, PyTimer from operator import attrgetter from traceback import print_exc from logging import getLogger log = getLogger('imwinctrl') info = log.info info_s = getattr(log, 'info_s', log.info) from util import Storage as traceguard from common import profile, prefprop from common.message import Message from gui.infobox.htmlgeneration import GetInfo from gui.imwin.imwin_tofrom import IMControl, EmailControl, SMSControl from gui.toolbox import check_destroyed, calllimit from common.sms import SMS_MAX_LENGTH class ImWinCtrl(object): def __init__(self): self.IMControl = IMControl(self.capsbar, self.To, self.From) self.IMControl.OnSelection += self.FocusTextCtrl (self.IMControl.OnSwitchContact,) += (lambda c: self.set_conversation(c.protocol.convo_for(c))) self.EmailControl = EmailControl(self.To, self.From) (self.EmailControl.OnLoseFocus,) += (lambda : self._emailpanel.subject_input.SetFocus()) self.SMSControl = SMSControl(self.To, self.From) self.SMSControl.OnLoseFocus += self.FocusTextCtrl self.controllers = { 'im': self.IMControl, 'email': self.EmailControl, 'sms': self.SMSControl } self.mode = None self.convo = None self.typing = None self.typing_status = None self.typing_timer = None self.GetButton('im').Bind((EVT_BUTTON,), (lambda e: self.set_mode('im', toggle_tofrom = True))) for mode in ('email', 'sms', 'info'): self.GetButton(mode).Bind(EVT_BUTTON, (lambda e, mode = (mode,): self.set_mode(mode))) self.GetButton('video').Bind((EVT_BUTTON,), (lambda e: self.on_video())) send_typing = prefprop('privacy.send_typing_notifications', True) typed_delay = prefprop('messaging.typed_delay', 5) def message(self, messageobj, convo = None, mode = 'im', meta = None): info('%r', self) info_s(' messageobj: %r', messageobj) info(' convo: %r', convo) info(' mode: %r', mode) info(' meta: %r', meta) if messageobj is None: self.set_conversation(convo) self.set_mode(mode) self.IMControl.SetConvo(convo) elif (messageobj.get('sms', False) or convo.buddy.sms) and not profile.blist.on_buddylist(convo.buddy): if self.convo is None: self.set_conversation(convo) if self.mode != 'sms': self.set_mode('sms') self.show_message(messageobj) else: convo = messageobj.conversation if self.mode is None: self.set_mode(mode) self.show_message(messageobj) self.set_conversation(convo) self.IMControl.SetConvo(convo) def set_mode(self, mode, toggle_tofrom = False): self.Frozen().__enter__() try: oldmode = getattr(self, 'mode', None) self.on_mode_change(oldmode, mode, toggle_tofrom) self.show_controls(mode) self.on_mode_changed(mode) finally: pass Mode = property(attrgetter('mode'), set_mode) def on_mode_change(self, oldmode, mode, toggle_tofrom = False): if oldmode != mode and mode in ('email', 'sms'): self.ShowToFrom(True) elif mode == 'info': self.ShowToFrom(False) if mode == 'sms' and oldmode != 'sms': (wx.CallAfter,)((lambda : self.input_area.tc.SetMaxLength(SMS_MAX_LENGTH))) elif oldmode == 'sms' and mode != 'sms': (wx.CallAfter,)((lambda : self.input_area.tc.SetMaxLength(0))) for m in ('im', 'email', 'sms'): if mode == m and oldmode != m: wx.CallAfter(self.controllers[mode].Apply) break continue if mode == 'im': if oldmode != 'im': self.ShowToFrom(self.IMControl.HasChoices) elif toggle_tofrom: self.ShowToFrom(not (self.capsbar.ToFromShown)) if oldmode is not None: self.GetButton(oldmode).Active(False) self.GetButton(mode).Active(True) def on_mode_changed(self, mode): if mode in ('im', 'sms'): self.on_message_area_shown() if self.IsActive(): self.FocusTextCtrl() elif mode == 'info': self.set_profile_html(self.Buddy) self.profile_html.SetFocus() elif mode == 'email': self._emailpanel.subject_input.SetFocus() def on_send_message(self): getattr(self, 'on_send_message_' + self.mode, (lambda a: pass))() def on_send_message_im(self, message = None): val = None if message is not None else self.input_area.Value if not val: return None self.history.commit(val) if self.set_conversation_from_combos(): self.convo.send_message(val, format = self.input_area.Format) self.ClearAndFocus() def on_send_email(self, *a): to = self.EmailControl.ToEmail frm = self.EmailControl.FromAccount if to is None: return wx.MessageBox(_('Please add an email address for this buddy by clicking the "To:" box.'), _('Compose email to %s') % self.Buddy.name) epanel = self._emailpanel def success(*a): log.info('Email send success') profile.blist.add_tofrom('email', to, frm) epanel.Clear() epanel.SetStatusMessage(_('Message Sent')) epanel.send_button.Enable(True) epanel.openin.Enable(True) def error(*a): log.info('Email send error') epanel.SetStatusMessage(_('Failed to Send Email')) epanel.send_button.Enable(True) epanel.openin.Enable(True) epanel.SetStatusMessage(_('Sending...')) epanel.send_button.Enable(False) epanel.openin.Enable(False) frm.OnClickSend(to = to, subject = self._emailpanel.subject_input.Value, body = self._emailpanel.email_input_area.Value, success = success, error = error) def on_send_message_sms(self): if not self.input_area.Value: return None to = self.SMSControl.ToSMS frm = self.SMSControl.FromAccount if to is None: MessageBox(_('Please add an SMS number first.'), _('Send SMS Message')) elif frm is None: MessageBox(_('You are not signed in to any accounts which can send SMS messages.'), _('Send SMS Message')) else: message = self.input_area.Value def on_success(): self.show_message(Message(buddy = frm.self_buddy, message = message[:SMS_MAX_LENGTH], conversation = self.convo, type = 'outgoing')) self.ClearAndFocus() def on_error(errstr = None): if errstr is not None: more = _('\nThe error message received was:\n\t%s') % errstr else: more = '' MessageBox(_('There was an error in sending your SMS message.') + more, _('Send SMS Message Error'), style = wx.ICON_ERROR) if len(message) > SMS_MAX_LENGTH: if wx.NO == wx.MessageBox(_('Only the first %d characters of your message can be sent over SMS:\n\n"%s"\n\nDo you want to send this message now?') % (SMS_MAX_LENGTH, message), _('Send SMS - Character Limit'), style = wx.YES_NO): return None frm.send_sms(to, message[:SMS_MAX_LENGTH], success = on_success, error = on_error) def on_edit_email(self): to = self.EmailControl.ToEmail frm = self.EmailControl.FromAccount if to is not None and frm is not None: frm.OnComposeEmail(to = to, subject = self._emailpanel.subject_input.Value, body = self._emailpanel.email_input_area.Value) def set_conversation_from_combos(self): to = self.IMControl.Buddy frm = self.IMControl.Account if frm is None: return False convo = self.convo if convo.protocol is not frm or convo.buddy is not to: self.set_conversation(frm.convo_for(to)) return True def on_close(self): if getattr(self, '_closed', False): log.warning('FIXME: imwin_ctrl.on_close was called more than once!!!') return None self._closed = True del self.capsbar.buddy_callback del self.capsbar plugin_hub = plugin_hub import plugin_manager plugin_hub.act('digsby.im.conversation.close.async', self.convo) self.unlink_observers() if self.convo is not None: self.unwatch_conversation(self.convo) try: self.convo.exit() except Exception: print_exc() except: None<EXCEPTION MATCH>Exception None<EXCEPTION MATCH>Exception def current_buddy_items(self): items = [ buddy_menu_item(contact) for contact in self.contacts ] i = self.contacts.index(self.Buddy) return (items, items[i]) def Conversation(self): return self.convo Conversation = property(Conversation) def Buddy(self): return self.IMControl.Buddy Buddy = property(Buddy) def SMS(self): return self.SMSControl.get_contact_sms() SMS = property(SMS) def set_conversation(self, convo, meta = None): if convo is self.convo: return None shouldShowToFrom = False if self.convo is not None: self.unwatch_conversation(self.convo) self.convo.exit() shouldShowToFrom = True self.convo = convo self.watch_conversation(convo) contact = None if meta is not None else convo.buddy self.capsbar.ApplyCaps(convo.buddy) self.IMControl.SetConvo(convo, meta) if shouldShowToFrom: self.ShowToFrom(shouldShowToFrom) self.EmailControl.SetContact(contact) self.SMSControl.SetContact(contact) self.update_icon() self.update_title() self.choose_message_formatting() def watch_conversation(self, convo): plugin_hub = plugin_hub import plugin_manager plugin_hub.act('digsby.im.conversation.open.async', convo) convo.typing_status.add_observer(self.typing_status_changed) buddy = convo.buddy buddy.add_observer(self.buddy_status_changed, 'status') buddy.add_observer(self.buddy_info_changed) def unwatch_conversation(self, convo = None): if convo is None: convo = self.convo if convo is not None: buddy = convo.buddy convo.typing_status.remove_observer(self.typing_status_changed) buddy.remove_observer(self.buddy_status_changed, 'status') buddy.remove_observer(self.buddy_info_changed) def show_status(self, update, ondone = None): try: self._statustimer.notify = lambda u = (None, update): self.show_message(u, ondone) except AttributeError: self._statustimer = None((lambda u = (wx.PyTimer, update): self.show_message(u, ondone))) if not self._statustimer.IsRunning(): self._statustimer.Start(250, True) def buddy_info_changed(self, *a): if self.mode == 'info': self.set_profile_html(self.Buddy) buddy_info_changed = calllimit(1)(buddy_info_changed) def buddy_status_changed(self, *a): wx.CallAfter(self._buddy_status_changed) def _buddy_status_changed(self): if check_destroyed(self): return None self.capsbar.ApplyCaps(self.Buddy) if self.icontype == 'status': self.update_icon() def typing_status_changed(self, *a): self.typing = self.convo.typing_status.get(self.convo.buddy, None) self.update_title() self.update_icon() def choose_message_formatting(self): plain = False conv = self.convo try: plain = conv.message_formatting == 'plaintext' except AttributeError: try: plain = conv.protocol.message_formatting == 'plaintext' except AttributeError: pass except: None<EXCEPTION MATCH>AttributeError None<EXCEPTION MATCH>AttributeError self.plainttext = plain def show_message(self, messageobj, ondone = None): c = messageobj.conversation b = messageobj.buddy t = messageobj.type buddyid = None if b is not None else None if buddyid is None: next = False else: next = getattr(self, 'last_buddy', None) == buddyid self.last_buddy = buddyid self.message_area.format_message(t, messageobj, next = next) if ondone is not None: pass def set_profile_html(self, buddy): profilewindow = self.profile_html try: html = GetInfo(self.Buddy, showprofile = True, showhide = False) except Exception: print_exc() html = buddy.name self.Frozen().__enter__() try: profilewindow.SetPage(html) finally: pass def on_text_changed(self, e): e.Skip() oldConvo = self.convo if not (self.send_typing) and self.Mode != 'im' or not self.set_conversation_from_combos(): return None if oldConvo is not None and oldConvo is not self.convo: traceguard.__enter__() try: oldConvo.send_typing_status(None) finally: pass txt = self.input_area.Value if len(txt) == 0: self.convo.send_typing_status(None) if self.typing_timer: self.typing_timer.Stop() self.typing_timer = None self.typing_status = None elif self.typing_status != 'typing': self.typing_status = 'typing' self.convo.send_typing_status(self.typing_status) self.cancel_timer() self.typing_timer = PyTimer(self.send_typed) self.typing_timer.Start(self.typed_delay * 1000, True) def send_typed(self, *e): self.typing_status = 'typed' self.convo.send_typing_status(self.typing_status) def cancel_timer(self): if self.typing_timer: self.typing_timer.Stop() self.typing_timer = None def on_message_area_shown(self): if hasattr(self, 'message_area') and not (self.message_area.inited): if hasattr(self, 'convo'): self.init_message_area(self.convo.name, self.convo.buddy) else: self.init_message_area('', None) self.input_area.tc.Bind(wx.EVT_TEXT, self.on_text_changed) ImWinDropTarget = ImWinDropTarget import gui.imwin.imwindnd self.SetDropTarget(ImWinDropTarget(self)) def on_video(self): buddy = self.Buddy VideoChatWindow = VideoChatWindow import gui.video.webvideo if VideoChatWindow.RaiseExisting(): self.convo.system_message(_('You can only have one audio/video call at a time.')) log.info('video window already up') else: log.info('requesting video chat') VideoChat = VideoChat import digsby.videochat VideoChat(buddy)