def cmd_validate_config(self): try: self.config.load() except Exception as error: send_notification("Configuration check", str(error.__context__)) else: send_notification("Configuration check", "No error found!")
def poll(self) -> str: """Determine the text to display Function returning a string with battery information to display on the status bar. Should only use the public interface in _Battery to get necessary information for constructing the string. """ try: status = self._battery.update_status() except RuntimeError as e: return "Error: {}".format(e) if self.notify_below: percent = int(status.percent * 100) if percent < self.notify_below: if not self._has_notified: send_notification( "Warning", "Battery at {0}%".format(percent), urgent=True, timeout=self.timeout, ) self._has_notified = True elif self._has_notified: self._has_notified = False return self.build_string(status)
def cmd_restart(self): """Restart qtile""" try: self.config.load() except Exception as error: logger.error("Preventing restart because of a configuration error: {}".format(error)) send_notification("Configuration error", str(error.__context__)) return self.restart()
def toggle_microphone(qtile: Qtile) -> None: """Run the toggle command and then send notification to report status of microphone""" try: subprocess.call(["amixer set Capture toggle"], shell=True) message = subprocess.check_output(["amixer sget Capture"], shell=True).decode( "utf-8" ) if "off" in message: message = "Muted" elif "on" in message: message = "Unmuted" title = "Microphone" send_notification(title, message, timeout=2500, urgent=False) except subprocess.CalledProcessError as err: logger.warning(f"Failed to mute microphone: {err}")
def notification(qtile: Qtile, request: str) -> None: """Used for mouse callbacks and keybinds to send notifications""" title: str = "" message: str = "" try: if request == "wifi": try: iface = iwlib.get_iwconfig(WIFI_INTERFACE) quality = iface["stats"]["quality"] quality = round((quality / 70) * 100) ssid = str(iface["ESSID"], encoding="utf-8") title = "Wifi" message = f"{ssid}\nSignal strength: {quality}%" except KeyError: title = "Disconnected" message = "" elif request == "date": today = datetime.today() todaysdate = today.strftime("%-d %B") weekday = today.strftime("%A") week = datetime.today().isocalendar()[1] title = f"{todaysdate} ({weekday})" message = f"Week {week}" elif request == "battery": if HAS_BATTERY: battery = psutil.sensors_battery() assert battery is not None, "Battery must be found by psutil" title = "Battery" message = f"{round(battery.percent)}%" else: return send_notification(title, message, timeout=2500, urgent=False) except Exception as err: logger.warning(f"Failed to send notification: {err}")
def _send_notification(self, urgent, message): send_notification("Pomodoro", message, urgent=None)