def refresh_widget_text(widget: Gtk.Widget) -> None: if isinstance(widget, Gtk.MenuButton): if widget.get_use_popover(): refresh_widget_text(widget.get_popover()) else: refresh_widget_text(widget.get_popup()) return if isinstance(widget, Gtk.Container): childrens = Gtk.Container.get_children(widget) else: if isinstance(widget, Gtk.Label): try: cached_text = i18n.cache[i18n.new_hash(widget.get_text())] except KeyError: log.debug("it's not an i18n string: %s", widget.get_text()) return c_ = _ if widget.get_use_markup(): old_attributes = Pango.Layout.get_attributes( widget.get_layout()) widget.set_text(c_(cached_text)) widget.set_attributes(old_attributes) else: widget.set_text(c_(cached_text)) log.debug('widget refreshed: %s', widget) else: log.debug('widget not refresh: %s', widget) return for children in childrens: refresh_widget_text(children)
def _text(self, widget: Gtk.Widget, data: APP): text = round(data["cpu"], 1) widget.set_text(f"{text}%")
def _text(self, widget: Gtk.Widget, data: APP): text = to_human(data["memory"]) widget.set_text(f"{text}B")