def __init__(self, metainfo, env, pymodule=None, is_notitle=False, panel=None): hippo.CanvasBox.__init__(self, orientation=hippo.ORIENTATION_VERTICAL, spacing=4) self.__size = None self.__metainfo = metainfo self.__env = env self.__pymodule = pymodule self.__panel = panel self.__ticker_text = None self.__ticker_container = None self.__mini_more_button = None self.__sep = Separator() self.append(self.__sep) self.__expanded = True if not is_notitle: self.__ticker_container = Header() self.__ticker_text = ThemedText(theme_hints=['header'], text=metainfo.title, font="14px Bold", xalign=hippo.ALIGNMENT_START) self.__ticker_text.connect("button-press-event", lambda text, event: self.__toggle_expanded()) self.__ticker_container.append(self.__ticker_text, hippo.PACK_EXPAND) if pymodule and pymodule.has_more_button(): more_button = HeaderButton() more_button.connect("activated", lambda l: pymodule.on_more_clicked()) self.__ticker_container.append(more_button) self.append(self.__ticker_container) self.__stockbox = hippo.CanvasBox() self.append(self.__stockbox) if pymodule: pymodule.connect('visible', self.__render_pymodule) self.__render_pymodule() else: self.__render_google_gadget()
def __init__(self, app_location, app=None, **kwargs): if app_location == AppLocation.STOCK: kwargs['enable_theme'] = True PhotoContentItem.__init__(self, border_right=6, **kwargs) self.__app = None self.__description_mode = False self._logger = logging.getLogger('bigboard.AppDisplay') self.__photo = CanvasMugshotURLImage(scale_width=30, scale_height=30) self.set_photo(self.__photo) self.__box = CanvasVBox(spacing=2, border_right=4) sub_kwargs = {} if kwargs.has_key('color'): sub_kwargs['color'] = kwargs['color'] title_kwargs = dict(sub_kwargs) title_kwargs.update({'font': '14px', 'xalign': hippo.ALIGNMENT_START, 'size-mode': hippo.CANVAS_SIZE_ELLIPSIZE_END }) if app_location == AppLocation.STOCK: self.__title = ThemedLink(**title_kwargs) else: self.__title = ActionLink(**title_kwargs) self.__title.connect("activated", lambda t: self.emit("title-clicked")) subtitle_kwargs = {'font': '10px', 'xalign': hippo.ALIGNMENT_START, 'size-mode': hippo.CANVAS_SIZE_ELLIPSIZE_END } if app_location == AppLocation.STOCK: self.__subtitle = ThemedText(theme_hints=['subforeground'], **subtitle_kwargs) else: self.__subtitle = hippo.CanvasText(**subtitle_kwargs) self.__box.append(self.__title) self.__box.append(self.__subtitle) self.set_child(self.__box) self.__description = hippo.CanvasText(size_mode=hippo.CANVAS_SIZE_WRAP_WORD, **sub_kwargs) self.__box.append(self.__description) self.__photo.set_clickable(True) self.__box.set_clickable(True) self.__app_location = app_location if app: self.set_app(app)
class Exchange(hippo.CanvasBox, ThemedWidgetMixin): """A renderer for stocks.""" def __init__(self, metainfo, env, pymodule=None, is_notitle=False, panel=None): hippo.CanvasBox.__init__(self, orientation=hippo.ORIENTATION_VERTICAL, spacing=4) self.__size = None self.__metainfo = metainfo self.__env = env self.__pymodule = pymodule self.__panel = panel self.__ticker_text = None self.__ticker_container = None self.__mini_more_button = None self.__sep = Separator() self.append(self.__sep) self.__expanded = True if not is_notitle: self.__ticker_container = Header() self.__ticker_text = ThemedText(theme_hints=['header'], text=metainfo.title, font="14px Bold", xalign=hippo.ALIGNMENT_START) self.__ticker_text.connect("button-press-event", lambda text, event: self.__toggle_expanded()) self.__ticker_container.append(self.__ticker_text, hippo.PACK_EXPAND) if pymodule and pymodule.has_more_button(): more_button = HeaderButton() more_button.connect("activated", lambda l: pymodule.on_more_clicked()) self.__ticker_container.append(more_button) self.append(self.__ticker_container) self.__stockbox = hippo.CanvasBox() self.append(self.__stockbox) if pymodule: pymodule.connect('visible', self.__render_pymodule) self.__render_pymodule() else: self.__render_google_gadget() def on_delisted(self): _logger.debug("on_delisted exchange %s" % (str(self))) self.__unrender_pymodule() def on_popped_out_changed(self, popped_out): self.__pymodule.on_popped_out_changed(popped_out) def __toggle_expanded(self): self.__expanded = not self.__expanded self.set_child_visible(self.__stockbox, self.__expanded) def get_metainfo(self): return self.__metainfo def get_pymodule(self): return self.__pymodule def __render_google_gadget(self): rendered = GoogleGadgetContainer(self.__metainfo, self.__env) self.__stockbox.append(rendered) def __render_pymodule(self, *args): self.__size = size = Stock.SIZE_BULL self.__stockbox.remove_all() self.__pymodule.set_size(size) content = self.__pymodule.get_content(size) if self.__ticker_container: self.set_child_visible(self.__ticker_container, not not content) self.set_child_visible(self.__sep, (not not content) and \ ((self.__ticker_container and size == Stock.SIZE_BEAR) \ or (size == Stock.SIZE_BULL and ((not self.__ticker_container) or (self.__pymodule.get_ticker() == "-"))))) if self.__mini_more_button: self.set_child_visible(self.__mini_more_button, size == Stock.SIZE_BEAR) self.set_child_visible(self.__stockbox, not not content) if not content: _logger.debug("no content for stock %s", self.__pymodule) return self.__stockbox.append(content) padding = 4 self.__stockbox.set_property("padding_left", padding) self.__stockbox.set_property("padding_right", padding) if self.__ticker_text: self.set_child_visible(self.__ticker_container, size == Stock.SIZE_BULL) def __unrender_pymodule(self): if not self.__pymodule: _logger.debug("Not a pymodule exchange") return _logger.debug("delisting pymodule %s" % (str(self.__pymodule))) self.__pymodule.on_delisted() self.__pymodule = None
class AppDisplay(PhotoContentItem): __gsignals__ = { "title-clicked" : (gobject.SIGNAL_RUN_LAST, gobject.TYPE_NONE, ()), } def __init__(self, app_location, app=None, **kwargs): if app_location == AppLocation.STOCK: kwargs['enable_theme'] = True PhotoContentItem.__init__(self, border_right=6, **kwargs) self.__app = None self.__description_mode = False self._logger = logging.getLogger('bigboard.AppDisplay') self.__photo = CanvasMugshotURLImage(scale_width=30, scale_height=30) self.set_photo(self.__photo) self.__box = CanvasVBox(spacing=2, border_right=4) sub_kwargs = {} if kwargs.has_key('color'): sub_kwargs['color'] = kwargs['color'] title_kwargs = dict(sub_kwargs) title_kwargs.update({'font': '14px', 'xalign': hippo.ALIGNMENT_START, 'size-mode': hippo.CANVAS_SIZE_ELLIPSIZE_END }) if app_location == AppLocation.STOCK: self.__title = ThemedLink(**title_kwargs) else: self.__title = ActionLink(**title_kwargs) self.__title.connect("activated", lambda t: self.emit("title-clicked")) subtitle_kwargs = {'font': '10px', 'xalign': hippo.ALIGNMENT_START, 'size-mode': hippo.CANVAS_SIZE_ELLIPSIZE_END } if app_location == AppLocation.STOCK: self.__subtitle = ThemedText(theme_hints=['subforeground'], **subtitle_kwargs) else: self.__subtitle = hippo.CanvasText(**subtitle_kwargs) self.__box.append(self.__title) self.__box.append(self.__subtitle) self.set_child(self.__box) self.__description = hippo.CanvasText(size_mode=hippo.CANVAS_SIZE_WRAP_WORD, **sub_kwargs) self.__box.append(self.__description) self.__photo.set_clickable(True) self.__box.set_clickable(True) self.__app_location = app_location if app: self.set_app(app) def set_description_mode(self, mode): self.__description_mode = mode self.__app_display_sync() def get_app(self): return self.__app def set_app(self, app): self.__app = app self.__app_display_sync() def __get_name(self): if self.__app is None: return "unknown" return self.__app.get_name() def __str__(self): return '<AppDisplay name="%s">' % (self.__get_name()) def __app_display_sync(self): if not self.__app: return self.__box.set_child_visible(self.__subtitle, not self.__description_mode) self.__box.set_child_visible(self.__description, self.__description_mode) self.__title.set_property("text", self.__app.get_name()) if self.__app.is_installed() or self.__app_location == AppLocation.DESCRIPTION_HEADER: self.__subtitle.set_property("text", self.__app.get_generic_name() or self.__app.get_tooltip() or self.__app.get_comment()) ## for now, install won't work if not connected elif self.__app_location == AppLocation.STOCK and globals.get_data_model().ready and globals.get_data_model().global_resource.online: self.__subtitle.set_property('text', "(Click to Install)") else: self.__subtitle.set_property('text', "(Not Installed)") self.__description.set_property("text", self.__app.get_description()) if self.__app.get_icon_url(): self.__photo.set_url(self.__app.get_icon_url()) else: pixbuf = self.__app.get_local_pixbuf() if pixbuf: self.__photo.set_property("image", hippo.cairo_surface_from_gdk_pixbuf(pixbuf)) def launch(self): self._logger.debug("launching app %s", self) self.__app.launch()