Пример #1
0
    def run(self):
        memory_usage = virtual_memory()

        if self.multi_colors:
            color = self.get_gradient(memory_usage.percent, self.colors)
        elif memory_usage.percent >= self.alert_percentage:
            color = self.alert_color
        elif memory_usage.percent >= self.warn_percentage:
            color = self.warn_color
        else:
            color = self.color

        if self.optional:
            self.output = {
                "full_text": self.format.format(
                    used_mem_bar=make_bar(memory_usage.percent)),
                "short_text": "",
                "color": color
            }
        else:
            self.output = {
                "full_text": self.format.format(
                    used_mem_bar=make_bar(memory_usage.percent)),
                "color": color
            }
Пример #2
0
    def extract_wireless_info(self, interface):
        info = dict(essid="", freq="", quality=0.0, quality_bar="")

        # Just return empty values if we're not using any Wifi functionality
        if not self.get_wifi_info:
            return info

        import basiciw

        try:
            iwi = basiciw.iwinfo(interface)
        except Exception:
            # Not a wireless interface
            return info

        info["essid"] = iwi["essid"]
        info["freq"] = iwi["freq"] / self.freq_divisor
        quality = iwi["quality"]
        if quality["quality_max"] > 0:
            info["quality"] = quality["quality"] / quality["quality_max"]
        else:
            info["quality"] = quality["quality"]
        info["quality"] *= 100
        info["quality_bar"] = make_bar(info["quality"])
        info["quality"] = round(info["quality"])

        return info
Пример #3
0
    def extract_wireless_info(self, interface):
        info = dict(essid="", freq="", quality=0.0, quality_bar="")

        # Just return empty values if we're not using any Wifi functionality
        if not self.get_wifi_info:
            return info

        import basiciw

        try:
            iwi = basiciw.iwinfo(interface)
        except Exception:
            # Not a wireless interface
            return info

        info["essid"] = iwi["essid"]
        info["freq"] = iwi["freq"] / self.freq_divisor
        quality = iwi["quality"]
        if quality["quality_max"] > 0:
            info["quality"] = quality["quality"] / quality["quality_max"]
        else:
            info["quality"] = quality["quality"]
        info["quality"] *= 100
        info["quality_bar"] = make_bar(info["quality"])
        info["quality"] = round(info["quality"])

        return info
Пример #4
0
    def sink_info_cb(self, context, sink_info_p, eol, _):
        """Updates self.output"""
        if sink_info_p:
            sink_info = sink_info_p.contents
            volume_percent = round(100 * sink_info.volume.values[0] / 0x10000)
            volume_db = pa_sw_volume_to_dB(sink_info.volume.values[0])
            self.currently_muted = sink_info.mute

            if volume_db == float('-Infinity'):
                volume_db = "-∞"
            else:
                volume_db = int(volume_db)

            muted = self.muted if sink_info.mute else self.unmuted

            if self.multi_colors and not sink_info.mute:
                color = self.get_gradient(volume_percent, self.colors)
            else:
                color = self.color_muted if sink_info.mute else self.color_unmuted

            if muted and self.format_muted is not None:
                output_format = self.format_muted
            else:
                output_format = self.format

            if self.bar_type == 'vertical':
                volume_bar = make_vertical_bar(volume_percent,
                                               self.vertical_bar_width,
                                               glyphs=self.vertical_bar_glyphs)
            elif self.bar_type == 'horizontal':
                volume_bar = make_bar(volume_percent)
            else:
                raise Exception("bar_type must be 'vertical' or 'horizontal'")

            selected = ""
            dump = subprocess.check_output("pacmd dump".split(),
                                           universal_newlines=True)
            for line in dump.split("\n"):
                if line.startswith("set-default-sink"):
                    default_sink = line.split()[1]
                    if default_sink == self.current_sink:
                        selected = self.format_selected

            self.output = {
                "color":
                color,
                "full_text":
                output_format.format(muted=muted,
                                     volume=volume_percent,
                                     db=volume_db,
                                     volume_bar=volume_bar,
                                     selected=selected),
            }

            self.send_output()
        elif eol < 0:
            self.output = None
            self.send_output()
Пример #5
0
    def run(self):
        urgent = False
        color = self.color

        try:
            battery = Battery.create(self.path)
        except FileNotFoundError:
            self.output = {
                "full_text": self.not_present_text,
                "color": self.not_present_color,
            }
            return

        fdict = {
            "battery_ident": self.battery_ident,
            "percentage": battery.percentage(),
            "percentage_design": battery.percentage(design=True),
            "consumption": battery.consumption(),
            "remaining": TimeWrapper(0, "%E%h:%M"),
            "bar": make_bar(battery.percentage()),
        }

        status = battery.status()
        if status in ["Charging", "Discharging"]:
            remaining = battery.remaining()
            fdict["remaining"] = TimeWrapper(remaining * 60, "%E%h:%M")
            if status == "Discharging":
                fdict["status"] = "DIS"
                if battery.percentage() <= self.alert_percentage:
                    urgent = True
                    color = self.critical_color
            else:
                fdict["status"] = "CHR"
                color = self.charging_color
        else:
            fdict["status"] = "FULL"
            color = self.full_color

        if self.alert and fdict["status"] == "DIS" and fdict[
                "percentage"] <= self.alert_percentage:
            DesktopNotification(
                title=formatp(self.alert_format_title, **fdict),
                body=formatp(self.alert_format_body, **fdict),
                icon="battery-caution",
                urgency=2,
                timeout=60,
            ).display()

        fdict["status"] = self.status[fdict["status"]]

        self.output = {
            "full_text": formatp(self.format, **fdict),
            "instance": self.battery_ident,
            "urgent": urgent,
            "color": color,
        }
Пример #6
0
    def run(self):
        urgent = False
        color = self.color

        try:
            battery = Battery.create(self.path)
        except FileNotFoundError:
            self.output = {
                "full_text": self.not_present_text,
                "color": self.not_present_color,
            }
            return

        fdict = {
            "battery_ident": self.battery_ident,
            "percentage": battery.percentage(),
            "percentage_design": battery.percentage(design=True),
            "consumption": battery.consumption(),
            "remaining": TimeWrapper(0, "%E%h:%M"),
            "bar": make_bar(battery.percentage()),
        }

        status = battery.status()
        if status in ["Charging", "Discharging"]:
            remaining = battery.remaining()
            fdict["remaining"] = TimeWrapper(remaining * 60, "%E%h:%M")
            if status == "Discharging":
                fdict["status"] = "DIS"
                if battery.percentage() <= self.alert_percentage:
                    urgent = True
                    color = self.critical_color
            else:
                fdict["status"] = "CHR"
                color = self.charging_color
        else:
            fdict["status"] = "FULL"
            color = self.full_color

        if self.alert and fdict["status"] == "DIS" and fdict["percentage"] <= self.alert_percentage:
            DesktopNotification(
                title=formatp(self.alert_format_title, **fdict),
                body=formatp(self.alert_format_body, **fdict),
                icon="battery-caution",
                urgency=2,
                timeout=60,
            ).display()

        fdict["status"] = self.status[fdict["status"]]

        self.output = {
            "full_text": formatp(self.format, **fdict),
            "instance": self.battery_ident,
            "urgent": urgent,
            "color": color,
        }
Пример #7
0
    def sink_info_cb(self, context, sink_info_p, _, __):
        """Updates self.output"""
        if sink_info_p:
            sink_info = sink_info_p.contents
            volume_percent = round(100 * sink_info.volume.values[0] / 0x10000)
            volume_db = pa_sw_volume_to_dB(sink_info.volume.values[0])
            self.currently_muted = sink_info.mute

            if volume_db == float('-Infinity'):
                volume_db = "-∞"
            else:
                volume_db = int(volume_db)

            muted = self.muted if sink_info.mute else self.unmuted

            if self.multi_colors and not sink_info.mute:
                color = self.get_gradient(volume_percent, self.colors)
            else:
                color = self.color_muted if sink_info.mute else self.color_unmuted

            if muted and self.format_muted is not None:
                output_format = self.format_muted
            else:
                output_format = self.format

            if self.bar_type == 'vertical':
                volume_bar = make_vertical_bar(volume_percent, self.vertical_bar_width)
            elif self.bar_type == 'horizontal':
                volume_bar = make_bar(volume_percent)
            else:
                raise Exception("bar_type must be 'vertical' or 'horizontal'")

            selected = ""
            dump = subprocess.check_output("pacmd dump".split(), universal_newlines=True)
            for line in dump.split("\n"):
                if line.startswith("set-default-sink"):
                    default_sink = line.split()[1]
                    if default_sink == self.current_sink:
                        selected = self.format_selected

            self.output = {
                "color": color,
                "full_text": output_format.format(
                    muted=muted,
                    volume=volume_percent,
                    db=volume_db,
                    volume_bar=volume_bar,
                    selected=selected),
            }

            self.send_output()
Пример #8
0
    def run(self):
        cpu_usage = self.get_usage()

        cpu_usage_bar = {}

        for core, usage in cpu_usage.items():
            core = core.replace('usage', 'usage_bar')
            cpu_usage_bar[core] = make_bar(usage)

        cpu_usage.update(cpu_usage_bar)

        # for backward compatibility
        cpu_usage['usage_bar'] = cpu_usage['usage_bar_cpu']

        self.output = {"full_text": self.format.format_map(cpu_usage)}
Пример #9
0
    def run(self):
        memory_usage = virtual_memory()

        if memory_usage.percent >= self.alert_percentage:
            color = self.alert_color

        elif memory_usage.percent >= self.warn_percentage:
            color = self.warn_color
        else:
            color = self.color

        self.output = {
            "full_text": self.format.format(
                used_mem_bar=make_bar(memory_usage.percent)),
            "color": color
        }
Пример #10
0
    def run(self):
        cpu_usage = self.get_usage()

        cpu_usage_bar = {}

        for core, usage in cpu_usage.items():
            core = core.replace('usage', 'usage_bar')
            cpu_usage_bar[core] = make_bar(usage)

        cpu_usage.update(cpu_usage_bar)

        # for backward compatibility
        cpu_usage['usage_bar'] = cpu_usage['usage_bar_cpu']

        self.output = {
            "full_text": self.format.format_map(cpu_usage)
        }
Пример #11
0
    def run(self):
        cpu_total, cpu_busy = self.get_usage()

        diff_cpu_total = cpu_total - self.prev_idle
        diff_cpu_busy = cpu_busy - self.prev_busy

        self.prev_idle = cpu_total
        self.prev_busy = cpu_busy

        cpu_busy_percentage = diff_cpu_busy / diff_cpu_total * 100
        cpu_busy_bar = make_bar(cpu_busy_percentage)

        self.output = {
            "full_text": self.format.format(
                usage_bar=cpu_busy_bar
            )
        }
Пример #12
0
    def run(self):
        memory_usage = virtual_memory()

        if memory_usage.percent >= self.alert_percentage:
            color = self.alert_color

        elif memory_usage.percent >= self.warn_percentage:
            color = self.warn_color
        else:
            color = self.color

        self.output = {
            "full_text":
            self.format.format(used_mem_bar=make_bar(memory_usage.percent)),
            "color":
            color
        }
Пример #13
0
    def sink_info_cb(self, context, sink_info_p, _, __):
        """Updates self.output"""
        if sink_info_p:
            sink_info = sink_info_p.contents
            volume_percent = round(100 * sink_info.volume.values[0] / 0x10000)
            volume_db = pa_sw_volume_to_dB(sink_info.volume.values[0])
            self.currently_muted = sink_info.mute

            if volume_db == float('-Infinity'):
                volume_db = "-∞"
            else:
                volume_db = int(volume_db)

            muted = self.muted if sink_info.mute else self.unmuted

            if self.multi_colors and not sink_info.mute:
                color = self.get_gradient(volume_percent, self.colors)
            else:
                color = self.color_muted if sink_info.mute else self.color_unmuted

            if muted and self.format_muted is not None:
                output_format = self.format_muted
            else:
                output_format = self.format

            if self.bar_type == 'vertical':
                volume_bar = make_vertical_bar(volume_percent,
                                               self.vertical_bar_width)
            elif self.bar_type == 'horizontal':
                volume_bar = make_bar(volume_percent)
            else:
                raise Exception("bar_type must be 'vertical' or 'horizontal'")

            self.output = {
                "color":
                color,
                "full_text":
                output_format.format(muted=muted,
                                     volume=volume_percent,
                                     db=volume_db,
                                     volume_bar=volume_bar),
            }

            self.send_output()
Пример #14
0
    def collect(self):
        color, format, fdict, up = super().collect()

        if up:
            iwi = basiciw.iwinfo(self.interface)
            fdict["essid"] = iwi["essid"]
            fdict["freq"] = iwi["freq"]
            quality = iwi["quality"]
            if quality["quality_max"] > 0:
                fdict["quality"] = quality["quality"] / quality["quality_max"]
            else:
                fdict["quality"] = quality["quality"]
            fdict["quality"] *= 100
            fdict["quality_bar"] = make_bar(fdict["quality"])
        else:
            fdict["essid"] = ""
            fdict["freq"] = fdict["quality"] = 0.0

        return color, format, fdict, up
Пример #15
0
    def sink_info_cb(self, context, sink_info_p, _, __):
        """Updates self.output"""
        if sink_info_p:
            sink_info = sink_info_p.contents
            volume_percent = round(100 * sink_info.volume.values[0] / 0x10000)
            volume_db = pa_sw_volume_to_dB(sink_info.volume.values[0])
            self.currently_muted = sink_info.mute

            if volume_db == float('-Infinity'):
                volume_db = "-∞"
            else:
                volume_db = int(volume_db)

            muted = self.muted if sink_info.mute else self.unmuted

            if self.multi_colors and not sink_info.mute:
                color = self.get_gradient(volume_percent, self.colors)
            else:
                color = self.color_muted if sink_info.mute else self.color_unmuted

            if muted and self.format_muted is not None:
                output_format = self.format_muted
            else:
                output_format = self.format

            if self.bar_type == 'vertical':
                volume_bar = make_vertical_bar(volume_percent, self.vertical_bar_width)
            elif self.bar_type == 'horizontal':
                volume_bar = make_bar(volume_percent)
            else:
                raise Exception("bar_type must be 'vertical' or 'horizontal'")

            self.output = {
                "color": color,
                "full_text": output_format.format(
                    muted=muted,
                    volume=volume_percent,
                    db=volume_db,
                    volume_bar=volume_bar),
            }

            self.send_output()
Пример #16
0
    def run(self):
        cpu_total, cpu_busy = self.get_usage()

        diff_cpu_total = cpu_total - self.prev_idle
        diff_cpu_busy = cpu_busy - self.prev_busy

        self.prev_idle = cpu_total
        self.prev_busy = cpu_busy

        cpu_busy_percentage = int(diff_cpu_busy / diff_cpu_total * 100)
        cpu_busy_bar = make_bar(cpu_busy_percentage)

        colorkey = max([val for val in self.colormap if val<=cpu_busy_percentage])
        

        self.output = {
            "full_text": self.format.format(
                usage=cpu_busy_percentage,
                usage_bar=cpu_busy_bar),
            "color": self.colormap[colorkey],
        }
Пример #17
0
    def run(self):
        cpu_usage = self.get_usage()

        cpu_usage_bar = {}

        for core, usage in cpu_usage.items():
            core = core.replace('usage', 'usage_bar')
            if self.bar_type == 'horizontal':
                cpu_usage_bar[core] = make_bar(usage)
            elif self.bar_type == 'vertical':
                cpu_usage_bar[core] = make_vertical_bar(usage)
            else:
                raise Exception("bar_type must be 'horizontal' or 'vertical'!")

        cpu_usage.update(cpu_usage_bar)

        # for backward compatibility
        cpu_usage['usage_bar'] = cpu_usage['usage_bar_cpu']

        self.output = {
            "full_text": self.format.format_map(cpu_usage),
            'color': self.get_gradient(cpu_usage[self.cpu], self.colors, 100)
        }
Пример #18
0
    def run(self):
        cpu_usage = self.get_usage()

        cpu_usage_bar = {}

        for core, usage in cpu_usage.items():
            core = core.replace('usage', 'usage_bar')
            if self.bar_type == 'horizontal':
                cpu_usage_bar[core] = make_bar(usage)
            elif self.bar_type == 'vertical':
                cpu_usage_bar[core] = make_vertical_bar(usage)
            else:
                raise Exception("bar_type must be 'horizontal' or 'vertical'!")

        cpu_usage.update(cpu_usage_bar)

        # for backward compatibility
        cpu_usage['usage_bar'] = cpu_usage['usage_bar_cpu']

        self.output = {
            "full_text": self.format.format_map(cpu_usage),
            'color': self.get_gradient(cpu_usage[self.cpu], self.colors, 100)
        }
Пример #19
0
    def run(self):
        urgent = False
        color = self.color
        batteries = []

        for path in self.paths:
            if self.battery_ident == 'ALL' or path.find(
                    self.battery_ident) >= 0:
                try:
                    batteries.append(Battery.create(path))
                except FileNotFoundError:
                    pass

        if not batteries:
            format_dict = {'battery_ident': self.battery_ident}
            self.output = {
                "full_text": formatp(self.not_present_text, **format_dict),
                "color": self.not_present_color,
            }
            return
        if self.no_text_full:
            if self.battery_status(batteries) == "Full":
                self.output = {"full_text": ""}
                return

        fdict = {
            "battery_ident":
            self.battery_ident,
            "no_of_batteries":
            len(batteries),
            "percentage":
            self.percentage(batteries),
            "percentage_design":
            self.percentage(batteries, design=True),
            "consumption":
            self.consumption(batteries),
            "remaining":
            TimeWrapper(0, "%E%h:%M"),
            "glyph":
            make_glyph(self.percentage(batteries), self.glyphs),
            "bar":
            make_bar(self.percentage(batteries)),
            "bar_design":
            make_bar(self.percentage(batteries, design=True)),
            "vertical_bar":
            make_vertical_bar(self.percentage(batteries)),
            "vertical_bar_design":
            make_vertical_bar(self.percentage(batteries, design=True)),
        }

        status = self.battery_status(batteries)
        if status in ["Charging", "Discharging"]:
            remaining = self.remaining(batteries)
            fdict["remaining"] = TimeWrapper(remaining * 60, "%E%h:%M")
            if status == "Discharging":
                fdict["status"] = "DIS"
                if self.percentage(batteries) <= self.alert_percentage:
                    urgent = True
                    color = self.critical_color
            else:
                fdict["status"] = "CHR"
                color = self.charging_color
        elif status == 'Depleted':
            fdict["status"] = "DPL"
            color = self.critical_color
        else:
            fdict["status"] = "FULL"
            color = self.full_color
        if self.critical_level_command and fdict["status"] == "DIS" and fdict[
                "percentage"] <= self.critical_level_percentage:
            run_through_shell(self.critical_level_command, enable_shell=True)

        self.alert_if_low_battery(fdict)

        if self.levels and fdict['status'] == 'DIS':
            self.levels.setdefault(0, self.status.get('DPL', 'DPL'))
            self.levels.setdefault(100, self.status.get('FULL', 'FULL'))
            keys = sorted(self.levels.keys())
            index = bisect.bisect_left(keys, int(fdict['percentage']))
            fdict["status"] = self.levels[keys[index]]
        else:
            fdict["status"] = self.status[fdict["status"]]

        self.data = fdict
        self.output = {
            "full_text": formatp(self.format, **fdict),
            "instance": self.battery_ident,
            "urgent": urgent,
            "color": color,
        }
Пример #20
0
    def run(self):
        urgent = False
        color = self.color
        batteries = []

        for path in self.paths:
            if self.battery_ident == 'ALL' or path.find(
                    self.battery_ident) >= 0:
                try:
                    batteries.append(Battery.create(path))
                except FileNotFoundError:
                    pass

        if not batteries:
            format_dict = {'battery_ident': self.battery_ident}
            self.output = {
                "full_text": formatp(self.not_present_text, **format_dict),
                "color": self.not_present_color,
            }
            return
        if self.no_text_full:
            if self.battery_status(batteries) == "Full":
                self.output = {"full_text": ""}
                return

        fdict = {
            "battery_ident": self.battery_ident,
            "no_of_batteries": len(batteries),
            "percentage": self.percentage(batteries),
            "percentage_design": self.percentage(batteries, design=True),
            "consumption": self.consumption(batteries),
            "remaining": TimeWrapper(0, "%E%h:%M"),
            "bar": make_bar(self.percentage(batteries)),
        }

        status = self.battery_status(batteries)
        if status in ["Charging", "Discharging"]:
            remaining = self.remaining(batteries)
            fdict["remaining"] = TimeWrapper(remaining * 60, "%E%h:%M")
            if status == "Discharging":
                fdict["status"] = "DIS"
                if self.percentage(batteries) <= self.alert_percentage:
                    urgent = True
                    color = self.critical_color
            else:
                fdict["status"] = "CHR"
                color = self.charging_color
        elif status == 'Depleted':
            fdict["status"] = "DPL"
            color = self.critical_color
        else:
            fdict["status"] = "FULL"
            color = self.full_color

        if self.alert and fdict["status"] == "DIS" and fdict[
                "percentage"] <= self.alert_percentage:
            DesktopNotification(
                title=formatp(self.alert_format_title, **fdict),
                body=formatp(self.alert_format_body, **fdict),
                icon="battery-caution",
                urgency=2,
                timeout=60,
            ).display()

        fdict["status"] = self.status[fdict["status"]]

        self.output = {
            "full_text": formatp(self.format, **fdict),
            "instance": self.battery_ident,
            "urgent": urgent,
            "color": color,
        }
Пример #21
0
    def run(self):
        urgent = False
        color = self.color
        batteries = []

        for path in self.paths:
            if self.battery_ident == 'ALL' or path.find(self.battery_ident) >= 0:
                try:
                    batteries.append(Battery.create(path))
                except FileNotFoundError:
                    pass

        if not batteries:
            format_dict = {'battery_ident': self.battery_ident}
            self.output = {
                "full_text": formatp(self.not_present_text, **format_dict),
                "color": self.not_present_color,
            }
            return
        if self.no_text_full:
            if self.battery_status(batteries) == "Full":
                self.output = {
                    "full_text": ""
                }
                return

        fdict = {
            "battery_ident": self.battery_ident,
            "no_of_batteries": len(batteries),
            "percentage": self.percentage(batteries),
            "percentage_design": self.percentage(batteries, design=True),
            "consumption": self.consumption(batteries),
            "remaining": TimeWrapper(0, "%E%h:%M"),
            "bar": make_bar(self.percentage(batteries)),
            "bar_design": make_bar(self.percentage(batteries, design=True)),
        }

        status = self.battery_status(batteries)
        if status in ["Charging", "Discharging"]:
            remaining = self.remaining(batteries)
            fdict["remaining"] = TimeWrapper(remaining * 60, "%E%h:%M")
            if status == "Discharging":
                fdict["status"] = "DIS"
                if self.percentage(batteries) <= self.alert_percentage:
                    urgent = True
                    color = self.critical_color
            else:
                fdict["status"] = "CHR"
                color = self.charging_color
        elif status == 'Depleted':
            fdict["status"] = "DPL"
            color = self.critical_color
        else:
            fdict["status"] = "FULL"
            color = self.full_color
        if self.critical_level_command and fdict["status"] == "DIS" and fdict["percentage"] <= self.critical_level_percentage:
            run_through_shell(self.critical_level_command, enable_shell=True)

        if self.alert and fdict["status"] == "DIS" and fdict["percentage"] <= self.alert_percentage:
            title, body = formatp(self.alert_format_title, **fdict), formatp(self.alert_format_body, **fdict)
            if not self.notification:
                self.notification = DesktopNotification(
                    title=title,
                    body=body,
                    icon="battery-caution",
                    urgency=2,
                    timeout=self.alert_timeout,
                )
                self.notification.display()
            else:
                self.notification.update(title=title,
                                         body=body)

        fdict["status"] = self.status[fdict["status"]]

        self.data = fdict
        self.output = {
            "full_text": formatp(self.format, **fdict),
            "instance": self.battery_ident,
            "urgent": urgent,
            "color": color,
        }