def register_message_hook(): import hooks hooks.register('digsby.im.msg.pre', _on_message) # setup a handler for digsby://avcall links from common import urlhandler urlhandler.register('avcall/([\w@\.]+)/(\w+)', show_video_chat_window)
def get_no_icon(with_transparency = False): 'Return the icon used for buddies with no icons.' global _cached_noicon global _registered_noicon_hook if not _registered_noicon_hook: _registered_noicon_hook = True import hooks hooks.register('skin.set.pre', _on_skin_change) try: return _cached_noicon[int(with_transparency)] except TypeError: pass img = _load_noicon() imgnoalpha = img.copy() try: # Transparency is specifed in a skin value like "66%"... alpha = skin.get('BuddiesPanel.BuddyIcons.NoIconAlpha', '75%').strip().rstrip('%') alpha_opacity = float(alpha) / 100.0 except: alpha_opacity = DEFAULT_NOICON_OPACITY pil_setalpha(img, alpha_opacity) # Lighten the alpha channel somewhat _cached_noicon = (imgnoalpha, img) return _cached_noicon[int(with_transparency)]
def _register_hooks(): '''Registers all global Twitter Hooks for dealing with notifications.''' global _did_register_hooks if _did_register_hooks: return _did_register_hooks = True if False: hooks.register('digsby.notifications.get_topics', _on_get_topics) hooks.register('digsby.notifications.changed', _on_nots_changed)
def _listen_for_pref_load(self): # resort checks profile.prefs_loaded to make sure we actually have prefs # before constructing the sorter. (there are events that can happen that # trigger a resort before prefs are loaded.) make sure to rebuild once # prefs are actually in. def on_prefs(_prefs): if getattr(self, '_prefs_did_load', False): return self._prefs_did_load = True self.rebuild() hooks.register('blobs.update.prefs', on_prefs)
def __init__(self, base=DEFAULT_BASE): self.base = base self.uc = Uc(UC_ARCH_ARM, UC_MODE_ARM) self.next_alloc_base = self.base self.bin_base = self.alloc(BIN_SIZE) self.stack_base = self.alloc(STACK_SIZE) self.uc.reg_write( UC_ARM_REG_SP, self.stack_base + (STACK_SIZE // 2)) # point SP to the middle of the stack, just to be safe hooks.register(self)
def __init__(self, *args, **kwargs): AnimatedTaskBarIcon.__init__(self, id=hash('digsby_tray_icon')) BuddyListEventHandler.__init__(self) hooks.register('digsby.im.mystatuschange.async', lambda status: wx.CallAfter(self.on_status_change, status)) hooks.register('digsby.im.message_hidden', self.on_hidden_message) # regenerate icon when the pref changes profile.prefs.link(TRAY_SHOW_STATUS_PREF, self.on_show_status_pref, callnow=True) self.Bind(wx.EVT_TASKBAR_LEFT_DCLICK, self.OnShowHideBuddylist) self.Bind(wx.EVT_TASKBAR_LEFT_DOWN, self.OnLeftClick) if config.platform == 'win': # refresh the tray icon image every couple of minutes to keep it # out of Window's inactive tray icon list self.refresh_timer = wx.PyTimer(self.Refresh) self.refresh_timer.Start(TASKBAR_REFRESH_MS, False)
def register_hooks(self): if getattr(ImFrame, 'did_register_hooks', False): return ImFrame.did_register_hooks = True ImFrame.engage_is_idle = False def goidle(): ImFrame.engage_is_idle = True for win in all_imframes(): win._endengage() return True def unidle(): ImFrame.engage_is_idle = False for win in all_imframes(): if win.IsActive(): win._startengage() return True def idle_ms(ms_idle_time): if not ImFrame.engage_is_idle and ms_idle_time > IMWIN_STAT_IDLE_TIME: goidle() elif ImFrame.engage_is_idle and ms_idle_time < IMWIN_STAT_IDLE_TIME: unidle() return 15 * 1000 #request check in 15 second intervals hooks.register('digsby.app.idle', idle_ms) # win7 taskbar hook import cgui if config.platform == 'win' and cgui.isWin7OrHigher(): from gui.native.win.taskbar import set_overlay_icon, get_tab_notebook def icon_updated(imwin): get_tab_notebook(imwin.Top).InvalidateThumbnails(imwin) def later(): if wx.IsDestroyed(imwin): return set_overlay_icon(im_badge(), tlw=imwin.Top) wx.CallLater(300, later) hooks.register('digsby.overlay_icon_updated', icon_updated)
def __init__(self, conn_accts): Observable.__init__(self) self.dirty = False self.sorting_paused = True #self._listen_for_pref_load() self.rebuild_timer = wx.PyTimer(self.rebuild_later) self.rebuild_timer.StartRepeating(500) # Holds the final view that goes into the TreeList. self.view = DGroup('__root__', [], []) self.info = {} # Rootgroups are the "protocol" rootgroups with the original, # unmodified versions of the buddy list structure for each account self.rootgroups = [] self.base_attrs = frozenset([None, 'alias', 'status', 'status_message', 'icon', 'icon_hash', 'entering', 'leaving', 'idle', 'away','mobile']) self.attrs = set(self.base_attrs) # conn_accts must be an observable list of connected accounts conn_accts.add_observer(self.on_connections_changed) self.metacontacts = MetaContactManager(self) self._init_order() self.contact_info_changed = Delegate() self.dispatch = ContactDispatcher() self.caches = dict(tofrom = DiskCache('im_history.dat', validator = validate_tofrom)) self.load_local_data() # save local to/from data on exit hooks.register('digsby.app.exit', self.save_local_data) self._search_by = u'' self._search_results = (0, 0) # number of contacts found in last two searches #todo: make then_bys based on a pref self.sort_models = sort_model.build_models( then_bys = 1, obj = self) self.sbw = sort_model.SortByWatcher(self.sort_models)
def register_hooks(self): if getattr(ImFrame, 'did_register_hooks', False): return ImFrame.did_register_hooks = True ImFrame.engage_is_idle = False def goidle(): ImFrame.engage_is_idle = True for win in all_imframes(): win._endengage() return True def unidle(): ImFrame.engage_is_idle = False for win in all_imframes(): if win.IsActive(): win._startengage() return True def idle_ms(ms_idle_time): if not ImFrame.engage_is_idle and ms_idle_time > IMWIN_STAT_IDLE_TIME: goidle() elif ImFrame.engage_is_idle and ms_idle_time < IMWIN_STAT_IDLE_TIME: unidle() return 15*1000 #request check in 15 second intervals hooks.register('digsby.app.idle', idle_ms) # win7 taskbar hook import cgui if config.platform == 'win' and cgui.isWin7OrHigher(): from gui.native.win.taskbar import set_overlay_icon, get_tab_notebook def icon_updated(imwin): get_tab_notebook(imwin.Top).InvalidateThumbnails(imwin) def later(): if wx.IsDestroyed(imwin): return set_overlay_icon(im_badge(), tlw=imwin.Top) wx.CallLater(300, later) hooks.register('digsby.overlay_icon_updated', icon_updated)
def __init__(self, *args, **kwargs): AnimatedTaskBarIcon.__init__(self, id=hash('digsby_tray_icon')) BuddyListEventHandler.__init__(self) hooks.register( 'digsby.im.mystatuschange.async', lambda status: wx.CallAfter(self.on_status_change, status)) hooks.register('digsby.im.message_hidden', self.on_hidden_message) # regenerate icon when the pref changes profile.prefs.link(TRAY_SHOW_STATUS_PREF, self.on_show_status_pref, callnow=True) self.Bind(wx.EVT_TASKBAR_LEFT_DCLICK, self.OnShowHideBuddylist) self.Bind(wx.EVT_TASKBAR_LEFT_DOWN, self.OnLeftClick) if config.platform == 'win': # refresh the tray icon image every couple of minutes to keep it # out of Window's inactive tray icon list self.refresh_timer = wx.PyTimer(self.Refresh) self.refresh_timer.Start(TASKBAR_REFRESH_MS, False)
def enable_help(): import hooks hooks.register('popup.pre', on_popup)
def on_status(status, on_done=None): for imwin in ImWinPanel.all(): if imwin.Buddy == status.buddy: wx.CallAfter(imwin.show_status, status, on_done) break def show_announce_window(message): from gui.imwin.imwin_gui import AnnounceWindow announce = AnnounceWindow(wx.FindWindowByName('Buddy List')) announce.message(message) wx.CallAfter(announce.Show) def show_announce_window_After(message): wx.CallAfter(show_announce_window, message) hooks.register('digsby.server.announcement', show_announce_window_After) def pre_message_hook(message): if is_announcement(message): # only show announcement windows to users with accounts (so new users # aren't shown an update changelog on first login) if profile.account_manager.all_accounts: show_announce_window(message) # If the user is new, ignore the message. return False im_show = Delegate() def frame_show(frame, show, no_activate=False): assert isinstance(show, bool)
This also forces the class imaccount.Account for the result (instead of the provided cf argument) ''' import imaccount options = copy.deepcopy(getattr(MSP, 'info', {}).get('defaults', {})) options.update(copy.deepcopy(getattr(MSC, 'info', {}).get('defaults', {}))) options.update(SP.get_options(MSC.info.component_type)) if 'protocol' not in options: options.update(protocol = MSC.info.shortname) util.dictrecurse(dict)(options) # TODO: cf is ignored - should we have a way for it to be overridden? perhaps let it default to imaccount if not # provided. return imaccount.Account(**options) hooks.register("digsby.component.im.construct", default_component_constructor_im, impl = 'default') hooks.register("digsby.component.email.construct", default_component_constructor, impl = 'default') hooks.register("digsby.component.social.construct", default_component_constructor, impl = 'default') class ServiceProviderContainer(AddOn): ''' Used to contain all ServiceProvider data - this is essentially the user's account list. It is also responsible for maintaining order of accounts. ''' def __init__(self, subject): self.profile = subject self.existing_sps = {} self.order = None self.on_order_changed = Delegate() self.lock = threading.RLock() self.rebuild_count = 0
class OscarChatConnection(object): def __init__(self, oscar, inviting_buddy): self.oscar = oscar self.buddy = inviting_buddy def handlech2(self, message_type, data): invite_msg, chatcookie = unpack_chat_invite(data) def on_yes(): from common import netcall netcall(lambda: self.oscar.join_chat(cookie=chatcookie)) profile.on_chat_invite( protocol = self.oscar, buddy = self.buddy, message = invite_msg, room_name = chatcookie, on_yes=on_yes) def chat_invite_handler(o, screenname, cookie): return OscarChatConnection(o, o.get_buddy(screenname)) def initialize(): log.info('\tloading rendezvous handler: chat service') import oscar.rendezvous.peer as peer peer.register_rdv_factory('chat_service', chat_invite_handler) hooks.register('oscar.rdv.load', initialize)
return NotImplemented #self.remove_gui_observer(callback) import weakref weak_socialfeeds = weakref.WeakValueDictionary() def on_dirty(ctx): try: feed = weak_socialfeeds[ctx] except KeyError: log.warning('SocialFeed marked dirty but not in weak dictionary: %r', ctx) else: feed.set_dirty() hooks.register('social.feed.mark_dirty', on_dirty) class SocialFeed(object): ''' allows plugins to use social.feed.* hooks to inject things into social feeds ''' def __init__(self, id_, feed_context, get_feed_items, render_items, set_dirty=None): assert hasattr(render_items, '__call__') assert hasattr(get_feed_items, '__call__') self.id = id_ # globally unique, i.e. account_id + name + subtype. Must be hashable self.context = feed_context # for use by whatever is creating the SocialFeed self.get_feed_items = get_feed_items self.render_items = render_items
class OscarChatConnection(object): def __init__(self, oscar, inviting_buddy): self.oscar = oscar self.buddy = inviting_buddy def handlech2(self, message_type, data): invite_msg, chatcookie = unpack_chat_invite(data) def on_yes(): from common import netcall netcall(lambda: self.oscar.join_chat(cookie=chatcookie)) profile.on_chat_invite(protocol=self.oscar, buddy=self.buddy, message=invite_msg, room_name=chatcookie, on_yes=on_yes) def chat_invite_handler(o, screenname, cookie): return OscarChatConnection(o, o.get_buddy(screenname)) def initialize(): log.info('\tloading rendezvous handler: chat service') import oscar.rendezvous.peer as peer peer.register_rdv_factory('chat_service', chat_invite_handler) hooks.register('oscar.rdv.load', initialize)
import weakref weak_socialfeeds = weakref.WeakValueDictionary() def on_dirty(ctx): try: feed = weak_socialfeeds[ctx] except KeyError: log.warning('SocialFeed marked dirty but not in weak dictionary: %r', ctx) else: feed.set_dirty() hooks.register('social.feed.mark_dirty', on_dirty) class SocialFeed(object): ''' allows plugins to use social.feed.* hooks to inject things into social feeds ''' def __init__(self, id_, feed_context, get_feed_items, render_items, set_dirty=None): assert hasattr(render_items, '__call__') assert hasattr(get_feed_items, '__call__')
def register_hooks(): for hook, cb in metrics_hooks: if cb is None: cb = lambda *a, **k: event(hook) hooks.register(hook, cb)
def on_prefs_loaded(prefs): ''' for upgrading prefs ''' old_focus_pref = 'conversation_window.steal_focus' new_focus_pref = 'conversation_window.new_action' steal_focus = prefs.pop(old_focus_pref, None) if steal_focus is not None: log.info('upgraded conversation_window.steal_focus pref') prefs[new_focus_pref] = 'stealfocus' if steal_focus else 'minimize' hooks.register('blobs.update.prefs', on_prefs_loaded) def load_local_accounts(username, password): ''' Loads local accounts for a username and password. Returns tuple of (digsby.accounts.Accounts, server_hash, server_order) ''' local_info = digsbylocal.load_local(username, password) server_info = digsbylocal.load_server(username, password) from digsby.accounts import Accounts return Accounts.from_local_store(local_info), server_info['accounts_hash'], server_info['server_order']