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()
def format_sensor_bar(self, sensor): """ Build and format a sensor bar. If pango is enabled bar color is per sensor.""" percentage = self.percentage(sensor.current, sensor.critical) bar = make_vertical_bar(int(percentage)) if self.pango_enabled: if self.dynamic_color: color = self.colors[int(percentage)] return self.format_pango(color, bar) return bar
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()
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()
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()
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) }
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, }
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) 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 self.notification is None: 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) 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, }