How to use the py3status.py3.Py3 function in py3status

To help you get started, we’ve selected a few py3status examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github ultrabug / py3status / tests / test_py3.py View on Github external
from pprint import pformat

from py3status.py3 import Py3


py3 = Py3()


def test_format_units():

    tests = [
        # basic unit guessing
        (dict(value=100), (100, "B")),
        (dict(value=999), (999, "B")),
        (dict(value=1000), (0.977, "KiB")),
        (dict(value=1024), (1.0, "KiB")),
        (dict(value=pow(1024, 2)), (1.0, "MiB")),
        (dict(value=pow(1024, 3)), (1.0, "GiB")),
        (dict(value=pow(1024, 4)), (1.0, "TiB")),
        (dict(value=pow(1024, 5)), (1.0, "PiB")),
        # no guessing
        (dict(value=pow(1024, 2), auto=False), (pow(1024, 2), "B")),
github ultrabug / py3status / py3status / module.py View on Github external
# update formats for placeholders if a format is not set
                    for item in update_config["update_placeholder_format"]:
                        placeholder_formats = item.get("placeholder_formats", {})
                        format_strings = item["format_strings"]
                        for format_param in format_strings:
                            format_string = getattr(class_inst, format_param, None)
                            if not format_string:
                                continue
                            format = Formatter().update_placeholder_formats(
                                format_string, placeholder_formats
                            )
                            setattr(class_inst, format_param, format)

            # Add the py3 module helper if modules self.py3 is not defined
            if not hasattr(self.module_class, "py3"):
                setattr(self.module_class, "py3", Py3(self))

            # Subscribe to udev events if on_udev_* dynamic variables are
            # configured on the module
            for param in dir(self.module_class):
                if param.startswith("on_udev_"):
                    trigger_action = getattr(self.module_class, param)
                    self.add_udev_trigger(trigger_action, param[8:])

            # allow_urgent
            param = fn(self.module_full_name, "allow_urgent")
            if hasattr(param, "none_setting"):
                param = True
            self.allow_urgent = param

            # urgent background
            urgent_background = fn(self.module_full_name, "urgent_background")
github ultrabug / py3status / py3status / autodoc.py View on Github external
constants = [(k, v) for k, v in sorted(constants.items())]

    # filter values as we only care about values defined in Py3
    values = {v: k[4:] for k, v in values.items() if k.startswith("Py3.")}

    def make_value(attr, arg, default):
        """
        If the methods parameter is defined as a constant then do a
        replacement.  Otherwise return the values representation.
        """
        if (attr, arg) in CONSTANT_PARAMS and default in values:
            return values[default]
        return repr(default)

    # inspect Py3 to find it's methods etc
    py3 = Py3()
    # no private ones
    attrs = [x for x in dir(py3) if not x.startswith("_")]
    exceptions = []
    methods = []
    for attr in attrs:
        item = getattr(py3, attr)
        if "method" in str(item):
            # a method so we need to get the call parameters
            args, vargs, kw, defaults = inspect.getargspec(item)
            args = args[1:]
            len_defaults = len(defaults) if defaults else 0
            len_args = len(args)

            sig = []
            for index, arg in enumerate(args):
                # default values set?
github ultrabug / py3status / py3status / i3status.py View on Github external
def setup_time_module(self):
        self.py3 = Py3()
        self.tz = None
        self.set_time_format()
        # we need to check the timezone this is when the check is next due
        self.time_zone_check_due = 0
        self.time_started = False

        time_format = self.time_format

        if "%f" in time_format:
            # microseconds
            time_delta = 0
        elif "%S" in time_format:
            # seconds
            time_delta = 1
        elif "%s" in time_format:
            # seconds since unix epoch start