def _get_status(self): playing = self.msg_nc try: self.status = self.client.status() self.song = self.client.currentsong() if self.status['state'] != 'stop': text = self.do_format(self.fmt_playing) if self.do_color_progress and self.status.get('time'): try: elapsed, total = self.status['time'].split(':') percent = float(elapsed) / float(total) progress = int(percent * len(text)) except (ZeroDivisionError, ValueError): playing = pangocffi.markup_escape_text(text) else: playing = '<span color="{0}">{1}</span>{2}'.format( utils.hex(self.foreground_progress), pangocffi.markup_escape_text(text[:progress]), pangocffi.markup_escape_text(text[progress:]) ) else: playing = pangocffi.markup_escape_text(text) else: playing = self.do_format(self.fmt_stopped) except Exception: logger.exception('Mpd error on update') return playing
def _status_playing(self): text = self.do_format(self.fmt_playing) if (self.do_color_progress and self.status and self.status.get( 'time', None)): elapsed, total = self.status['time'].split(':') percent = float(elapsed) / float(total) progress = int(percent * len(text)) is_pause = self.status['state'] == 'pause' if is_pause: color = self.pause_color color_progress = self.pause_progress_color else: color = self.foreground color_progress = self.foreground_progress s = '<span color="%s">%s</span>' % ( utils.hex(color_progress), pangocffi.markup_escape_text(text[:progress]) ) rest = pangocffi.markup_escape_text(text[progress:]) s += '<span color="%s">%s</span>' % ( utils.hex(color), rest ) return s else: return pangocffi.markup_escape_text(text)
def _status_playing(self): text = self.do_format(self.fmt_playing) if (self.do_color_progress and self.status and self.status.get('time', None)): elapsed, total = self.status['time'].split(':') percent = float(elapsed) / float(total) progress = int(percent * len(text)) is_pause = self.status['state'] == 'pause' if is_pause: color = self.pause_color color_progress = self.pause_progress_color else: color = self.foreground color_progress = self.foreground_progress s = '<span color="%s">%s</span>' % (utils.hex(color_progress), pangocffi.markup_escape_text( text[:progress])) rest = pangocffi.markup_escape_text(text[progress:]) s += '<span color="%s">%s</span>' % (utils.hex(color), rest) return s else: return pangocffi.markup_escape_text(text)
def set_notif_text(self, notif): self.text = pangocffi.markup_escape_text(notif.summary) urgency = getattr(notif.hints.get('urgency'), "value", 1) if urgency != 1: self.text = '<span color="%s">%s</span>' % ( utils.hex(self.foreground_urgent if urgency == 2 else self.foreground_low), self.text) if notif.body: self.text = '<span weight="bold">%s</span> - %s' % ( self.text, pangocffi.markup_escape_text(notif.body)) if self.audiofile and path.exists(self.audiofile): self.qtile.cmd_spawn("aplay -q '%s'" % self.audiofile)
def _get_text(self, notif): summary = '' body = '' app_name = '' if notif.summary: summary = pangocffi.markup_escape_text(notif.summary) if notif.body: body = pangocffi.markup_escape_text(notif.body) if notif.app_name: app_name = pangocffi.markup_escape_text(notif.app_name) return self.format.format(summary=summary, body=body, app_name=app_name)
def update(self, *args): if self.for_current_screen: w = self.qtile.current_screen.group.current_window else: w = self.bar.screen.group.current_window state = "" if self.show_state and w is not None: if w.maximized: state = "[] " elif w.minimized: state = "_ " elif w.floating: state = "V " unescaped = "%s%s" % ( state, w.name if w and w.name else self.empty_group_string, ) full_string = pangocffi.markup_escape_text(unescaped) if len(full_string) > self.max_chars > 0: try: trunc_string = full_string[: self.max_chars] + "…" self.text = trunc_string except: self.text = "" else: self.text = full_string self.bar.draw()
def now_playing(self): """Return a string with the now playing info (Artist - Song Title).""" info = self.get_info() now_playing = "" if info: status = info["status"] if self.status != status: self.status = status if self.status == "playing": self.layout.colour = self.play_color else: self.layout.colour = self.noplay_color self.local = info["file"].startswith("/") title = info["title"] if self.local: artist = info["artist"] now_playing = "{0} - {1}".format(artist, title) else: if info["stream"]: now_playing = info["stream"] else: now_playing = title if now_playing: now_playing = "♫ {0}".format(now_playing) return pangocffi.markup_escape_text(now_playing)
def hook_response(self, *args): if self.for_current_screen: w = self.qtile.current_screen.group.current_window else: w = self.bar.screen.group.current_window state = '' if w: if w.maximized: state = '[] ' elif w.minimized: state = '_ ' elif w.floating: state = 'V ' var = {} var["state"] = state var["name"] = w.name if callable(self.parse_text): try: var["name"] = self.parse_text(var["name"]) except: logger.exception("parse_text function failed:") wm_class = w.get_wm_class() var["class"] = wm_class[0] if wm_class else "" unescaped = self.format.format(**var) else: unescaped = self.empty_group_string self.update(pangocffi.markup_escape_text(unescaped))
def _update(self) -> None: if self.active: self.text = self.archived_input or self.user_input cursor = pangocffi.markup_escape_text(" ") if self.cursor_position < len(self.text): txt1 = self.text[:self.cursor_position] txt2 = self.text[self.cursor_position] txt3 = self.text[self.cursor_position + 1:] for text in (txt1, txt2, txt3): text = pangocffi.markup_escape_text(text) txt2 = self._highlight_text(txt2) self.text = "{0}{1}{2}{3}".format(txt1, txt2, txt3, cursor) else: self.text = pangocffi.markup_escape_text(self.text) self.text += self._highlight_text(cursor) self.text = self.display + self.text else: self.text = "" self.bar.draw()
def set_notif_text(self, notif): self.text = pangocffi.markup_escape_text(notif.summary) urgency = getattr(notif.hints.get("urgency"), "value", 1) if urgency != 1: self.text = '<span color="%s">%s</span>' % ( utils.hex(self.foreground_urgent if urgency == 2 else self.foreground_low), self.text, ) if notif.body: self.text = '<span weight="bold">%s</span> - %s' % ( self.text, pangocffi.markup_escape_text(notif.body), ) if callable(self.parse_text): try: self.text = self.parse_text(self.text) except: # noqa: E722 logger.exception("parse_text function failed:") if self.audiofile and path.exists(self.audiofile): self.qtile.cmd_spawn("aplay -q '%s'" % self.audiofile)
def _update(self): if self.active: self.text = self.archived_input or self.user_input self.available = [k for k in self.current_query.keys() if self.text in k] self.available.sort() cursor = pangocffi.markup_escape_text(" ") if self.cursor_position < len(self.text): self.chosen = "" txt1 = self.text[:self.cursor_position] txt2 = self.text[self.cursor_position] txt3 = self.text[self.cursor_position + 1:] for text in (txt1, txt2, txt3): text = pangocffi.markup_escape_text(text) txt2 = self._highlight_text(txt2) self.text = "{0}{1}{2}{3}".format(txt1, txt2, txt3, cursor) # Will display the alternatives as suggestions elif len(self.text) + 1 <= self.cursor_position <= len(self.text) + len(self.available): self.chosen = self.available[int(self.cursor_position-len(self.text)-1)] else: self.text = pangocffi.markup_escape_text(self.text) self.text += self._highlight_text(cursor) if self.chosen != "": self.text = self.chosen self.text = self.display + self.text if self.available: self.text += " | " + f"{self.separator}".join(self.available[:self.max_suggestions]) + " | " else: self.text = "" self.bar.draw()
def start_input(self, prompt, callback, complete=None, strict_completer=False, allow_empty_input=False) -> None: """Run the prompt Displays a prompt and starts to take one line of keyboard input from the user. When done, calls the callback with the input string as argument. If history record is enabled, also allows to browse between previous commands with ↑ and ↓, and execute them (untouched or modified). When history is exhausted, fires an alert. It tries to mimic, in some way, the shell behavior. Parameters ========== complete : Tab-completion. Can be None, "cmd", "file", "group", "qshell" or "window". prompt : text displayed at the prompt, e.g. "spawn: " callback : function to call with returned value. complete : completer to use. strict_completer : When True the return value wil be the exact completer result where available. allow_empty_input : When True, an empty value will still call the callback function """ if self.cursor and self.cursorblink and not self.active: self.timeout_add(self.cursorblink, self._blink) self.display = self.prompt.format(prompt=prompt) self.display = pangocffi.markup_escape_text(self.display) self.active = True self.user_input = "" self.archived_input = "" self.show_cursor = self.cursor self.cursor_position = 0 self.callback = callback self.completer = self.completers[complete](self.qtile) self.strict_completer = strict_completer self.allow_empty_input = allow_empty_input self._update() self.bar.widget_grab_keyboard(self) if self.record_history: self.completer_history = self.history[complete] self.position = len(self.completer_history)
def get_taskname(self, window): """ Get display name for given window. Depending on its state minimized, maximized and floating appropriate characters are prepended. """ state = '' markup_str = self.markup_normal # Enforce markup and new string format behaviour when # at least one markup_* option is used. # Mixing non markup and markup may cause problems. if self.markup_minimized or self.markup_maximized\ or self.markup_floating or self.markup_focused: enforce_markup = True else: enforce_markup = False if window is None: pass elif window.minimized: state = self.txt_minimized markup_str = self.markup_minimized elif window.maximized: state = self.txt_maximized markup_str = self.markup_maximized elif window.floating: state = self.txt_floating markup_str = self.markup_floating elif window is window.group.current_window: markup_str = self.markup_focused window_name = window.name if window and window.name else "?" if callable(self.parse_text): try: window_name = self.parse_text(window_name) except: logger.exception("parse_text function failed:") # Emulate default widget behavior if markup_str is None if enforce_markup and markup_str is None: markup_str = "%s{}" % (state) if markup_str is not None: self.markup = True window_name = pangocffi.markup_escape_text(window_name) return markup_str.format(window_name) return "%s%s" % (state, window_name)
def update(self, *args): if self.for_current_screen: w = self.qtile.current_screen.group.current_window else: w = self.bar.screen.group.current_window state = '' if self.show_state and w is not None: if w.maximized: state = '[] ' elif w.minimized: state = '_ ' elif w.floating: state = 'V ' unescaped = "%s%s" % (state, w.name if w and w.name else " ") self.text = pangocffi.markup_escape_text(unescaped) self.bar.draw()
def poll(self): text = '' try: line = subprocess.check_output( ['emacsclient', '-e', '(wcx/org-get-clocked-time)']).decode('utf-8') line = line.replace('"', '') line = line.replace('\n', '') if line != 'nil': line = markup_escape_text(line) text = '<span weight="bold" color="{label_color}">Task:</span><span> {}</span>'.format( line, label_color=self.label_color) else: text = "(No current task)" except subprocess.CalledProcessError: text = "(No current task)" return text
def hook_response(self, *args): if self.for_current_screen: w = self.qtile.current_screen.group.current_window else: w = self.bar.screen.group.current_window state = '' if w: if w.maximized: state = '[] ' elif w.minimized: state = '_ ' elif w.floating: state = 'V ' var = {} var["state"] = state var["name"] = w.name var["class"] = w.window.get_wm_class()[0] if len( w.window.get_wm_class()) > 0 else "" unescaped = self.format.format(**var) else: unescaped = self.empty_group_string self.update(pangocffi.markup_escape_text(unescaped))
def update(self, *args): if self.only_current_screen: if self.qtile.current_screen == self.bar.screen: w = self.bar.screen.group.current_window else: w = None elif self.for_current_screen: ======= def hook_response(self, *args): if self.for_current_screen: >>>>>>> upstream/master w = self.qtile.current_screen.group.current_window else: w = self.bar.screen.group.current_window state = '' if w: if w.maximized: state = '[] ' elif w.minimized: state = '_ ' elif w.floating: state = 'V ' var = {} var["state"] = state var["name"] = w.name var["class"] = w.window.get_wm_class()[0] if len(w.window.get_wm_class()) > 0 else "" unescaped = self.format.format(**var) else: unescaped = self.empty_group_string self.update(pangocffi.markup_escape_text(unescaped))