class AbstractMugshotStock(Stock): """An abstract class for stocks which use Mugshot..""" def __init__(self, *args, **kwargs): super(AbstractMugshotStock, self).__init__(*args, **kwargs) self._model = DataModel(globals.server_name) # There is a minor danger of calling on_ready twice if we start up and then get a # ready notification before going idle; this could be protected with a flag variable self._model.add_ready_handler(self._on_ready) if self._model.ready: call_idle(self.__invoke_on_ready) self.__cursize = None self.__box = hippo.CanvasBox() def __sync_content(self): self.__box.remove_all() if self._model.self_resource: content = self.get_authed_content(self.__cursize) if not content: return None self.__box.append(content) return self.__box else: unauthed = self.get_unauthed_content(self.__cursize) if unauthed: self.__box.append(unauthed) return self.__box return None def get_unauthed_content(self, size): return None def get_content(self, size): if size == self.__cursize: return self.__box self.__cursize = size return self.__sync_content() @log_except(_logger) def __invoke_on_ready(self): if self._model.ready: self._on_ready() def _on_ready(self): """Should be overridden by subclasses to handle the state where we have connected to the data model (or tried to connected an failed.""" pass @log_except(_logger) def __handle_mugshot_connection_status(self, auth, xmpp, contacts): if auth != self._auth: _logger.debug("emitting visibility: %s", auth) self.emit("visible", auth) self._auth = auth self.__sync_content() self.__have_contacts = contacts self.__check_ready()
def __init__(self, *args, **kwargs): super(AbstractMugshotStock, self).__init__(*args, **kwargs) self._model = DataModel(globals.server_name) # There is a minor danger of calling on_ready twice if we start up and then get a # ready notification before going idle; this could be protected with a flag variable self._model.add_ready_handler(self._on_ready) if self._model.ready: call_idle(self.__invoke_on_ready) self.__cursize = None self.__box = hippo.CanvasBox()
def __init__(self, person, themed=False, **kwargs): kwargs['orientation'] = hippo.ORIENTATION_VERTICAL hippo.CanvasBox.__init__(self, **kwargs) self.person = person self.__themed = themed if themed: self.__header = Header(topborder=False) else: self.__header = hippo.CanvasGradient(orientation=hippo.ORIENTATION_HORIZONTAL, start_color=0xf2f2f2f2, end_color=0xc8c8c8ff) self.append(self.__header) textklass = themed and ThemedText or hippo.CanvasText linkklass = themed and ThemedLink or ActionLink name_vbox = hippo.CanvasBox(padding=6) self.__name = textklass(font="22px") name_vbox.append(self.__name) rename_link = linkklass(text='rename', font="10px", xalign=hippo.ALIGNMENT_END) name_vbox.append(rename_link) rename_link.connect('activated', self.__on_rename_activated) self.__header.append(name_vbox) if person.is_contact: try: user = person.resource.user except AttributeError: user = None if user: mugshot_link = linkklass(text="Mugshot", padding=6) self.__header.append(mugshot_link, flags=hippo.PACK_END) mugshot_link.connect("activated", self.__on_activate_web) self.__top_box = hippo.CanvasBox(orientation=hippo.ORIENTATION_HORIZONTAL) self.append(self.__top_box) self.__photo = CanvasMugshotURLImage(scale_width=60, scale_height=60, border=5) if person.is_contact: try: user = person.resource.user except AttributeError: user = None if user: self.__photo.set_clickable(True) self.__photo.connect("activated", self.__on_activate_web) self.__top_box.append(self.__photo) self.__address_box = hippo.CanvasBox(orientation=hippo.ORIENTATION_VERTICAL) self.__top_box.append(self.__address_box) self.__contact_status_box = hippo.CanvasBox(orientation=hippo.ORIENTATION_HORIZONTAL, spacing=4, border=4) self.append(self.__contact_status_box) if person.is_contact: self.__add_link = None self.__remove_link = linkklass() self.__remove_link.connect('activated', self.__remove_from_network_clicked) self.append(self.__remove_link) else: self.__remove_link = None self.__add_link = linkklass(text=('Add %s to network' % self.person.display_name)) self.__add_link.connect('activated', self.__add_to_network_clicked) self.append(self.__add_link) # self.__online = hippo.CanvasText(text='Offline') # self.append(self.__online) separator = hippo.CanvasBox(box_height=1, background_color=0xAAAAAAFF) self.append(separator) self.__ribbon_bar = hippo.CanvasBox(orientation=hippo.ORIENTATION_HORIZONTAL, spacing=2, border=4) self.append(self.__ribbon_bar) self.__link_box = hippo.CanvasBox(orientation=hippo.ORIENTATION_HORIZONTAL, spacing=2, border=4) self.append(self.__link_box) self.__local_files_link = None self.person.connect('display-name-changed', self.__update) self.person.connect('icon-url-changed', self.__update) self.person.connect('aim-changed', self.__update) self.person.connect('local-buddy-changed', self.__update_local_buddy) self.person.connect('xmpp-changed', self.__update) if person.is_contact: self.person.resource.connect(lambda *args: self.__update(self.person), 'emails') self.person.resource.connect(self.__update_contact_status, "status") try: user = person.resource.user except AttributeError: user = None if user: user.connect(self.__update_loved_accounts, "lovedAccounts") query = DataModel(bigboard.globals.server_name).query_resource(self.person.resource, "lovedAccounts +") query.add_handler(self.__update_loved_accounts) query.execute() self.__update(self.person) self.__update_local_buddy(self.person) if self.person.is_contact: self.__update_contact_status(self.person.resource) try: user = person.resource.user except AttributeError: user = None if user: self.__update_loved_accounts(user)
def __init__(self, person, themed=False, **kwargs): PhotoContentItem.__init__(self, **kwargs) self.person = person self.__themed = themed if themed: self.set_themed() model = DataModel(bigboard.globals.server_name) self.set_clickable(True) self.__photo = CanvasMugshotURLImage(scale_width=45, scale_height=45, border=1, border_color=0x000000ff) self.set_photo(self.__photo) self.__details_box = CanvasVBox() self.set_child(self.__details_box) nameklass = themed and ThemedText or hippo.CanvasText self.__name = nameklass(xalign=hippo.ALIGNMENT_START, yalign=hippo.ALIGNMENT_START, size_mode=hippo.CANVAS_SIZE_ELLIPSIZE_END) self.__details_box.append(self.__name) self.__presence_box = CanvasHBox(spacing=4) self.__details_box.append(self.__presence_box) self.__statuses = [] self.__status_box = CanvasHBox() self.__details_box.append(self.__status_box) self.connect('button-press-event', self.__handle_button_press) self.connect('button-release-event', self.__handle_button_release) self.__pressed = False self.__aim_icon = None self.__xmpp_icon = None self.__current_track = None self.__current_track_timeout = None if self.person.is_contact: try: user = self.person.resource.user except AttributeError: user = None if user: query = model.query_resource(user, "currentTrack +;currentTrackPlayTime") query.execute() user.connect(self.__update_current_track, 'currentTrack') user.connect(self.__update_current_track, 'currentTrackPlayTime') self.__update_current_track(user) self.person.connect('display-name-changed', self.__update) self.person.connect('icon-url-changed', self.__update) self.person.connect('aim-buddy-changed', self.__update_aim_buddy) self.person.connect('xmpp-buddy-changed', self.__update_xmpp_buddy) self.__update(self.person) self.__update_aim_buddy(self.person) self.__update_xmpp_buddy(self.person)
def get_data_model(): global __the_data_model if not __the_data_model: __the_data_model = DataModel(server_name) __the_data_model.add_ready_handler(on_data_model_ready) return __the_data_model