def find_sockfile(display: str = None): """Finds the appropriate socket file for the given display""" display = display or os.environ.get("DISPLAY") or ":0.0" if "." not in display: display += ".0" cache_directory = get_cache_dir() return os.path.join(cache_directory, SOCKBASE % display)
def find_sockfile(display: str = None): """Finds the appropriate socket file for the given display""" display = display or os.environ.get('DISPLAY') or ':0.0' if '.' not in display: display += '.0' cache_directory = get_cache_dir() return os.path.join(cache_directory, SOCKBASE % display)
def __init__(self, name="prompt", **config) -> None: base._TextBox.__init__(self, "", bar.CALCULATED, **config) self.add_defaults(Prompt.defaults) self.name = name self.active = False self.completer = None # type: Optional[AbstractCompleter] # Define key handlers (action to do when hit an specific key) self.keyhandlers = { keysyms['Tab']: self._trigger_complete, keysyms['BackSpace']: self._delete_char(), keysyms['Delete']: self._delete_char(False), keysyms['KP_Delete']: self._delete_char(False), keysyms['Escape']: self._unfocus, keysyms['Return']: self._send_cmd, keysyms['KP_Enter']: self._send_cmd, keysyms['Up']: self._get_prev_cmd, keysyms['KP_Up']: self._get_prev_cmd, keysyms['Down']: self._get_next_cmd, keysyms['KP_Down']: self._get_next_cmd, keysyms['Left']: self._move_cursor(), keysyms['KP_Left']: self._move_cursor(), keysyms['Right']: self._move_cursor("right"), keysyms['KP_Right']: self._move_cursor("right"), } printables = {x: self._write_char for x in range(127) if chr(x) in string.printable} self.keyhandlers.update(printables) if self.bell_style == "visual": self.original_background = self.background # If history record is on, get saved history or create history record if self.record_history: self.history_path = os.path.join(utils.get_cache_dir(), 'prompt_history') if os.path.exists(self.history_path): with open(self.history_path, 'rb') as f: try: self.history = pickle.load(f) if self.ignore_dups_history: self._dedup_history() except: # noqa: E722 # unfortunately, pickle doesn't wrap its errors, so we # can't detect what's a pickle error and what's not. logger.exception("failed to load prompt history") self.history = {x: deque(maxlen=self.max_history) for x in self.completers} # self.history of size does not match. if len(self.history) != len(self.completers): self.history = {x: deque(maxlen=self.max_history) for x in self.completers} if self.max_history != \ self.history[list(self.history)[0]].maxlen: self.history = {x: deque(self.history[x], self.max_history) for x in self.completers} else: self.history = {x: deque(maxlen=self.max_history) for x in self.completers}
def cmd_tracemalloc_dump(self): """Dump tracemalloc snapshot""" import tracemalloc if not tracemalloc.is_tracing(): return [False, "Trace not started"] cache_directory = get_cache_dir() malloc_dump = os.path.join(cache_directory, "qtile_tracemalloc.dump") tracemalloc.take_snapshot().dump(malloc_dump) return [True, malloc_dump]
def _play_audio(text): """Sends the text to the text to speech engine and plays it. The TTS engine can be swapped out for any other engine. """ if ENGINE == "gtts": try: folder = get_cache_dir() gTTS(text).save(folder + "/gtts.mp3") # NOTE put audio player here subprocess.Popen(["mpv", folder + "/gtts.mp3"]) except Exception as e: log_test(e) logger.warning(f"gTTS failed: {e}") elif ENGINE == "espeak": # NOTE see espeak --help for more options subprocess.Popen(["espeak", "-s", "180", "-v", "en-german-5", text])
def __init__(self, name="prompt", **config) -> None: base._TextBox.__init__(self, "", bar.CALCULATED, **config) self.add_defaults(Prompt.defaults) self.name = name self.active = False self.completer = None # type: Optional[AbstractCompleter] # If history record is on, get saved history or create history record if self.record_history: self.history_path = os.path.join(utils.get_cache_dir(), "prompt_history") if os.path.exists(self.history_path): with open(self.history_path, "rb") as f: try: self.history = pickle.load(f) if self.ignore_dups_history: self._dedup_history() except: # noqa: E722 # unfortunately, pickle doesn't wrap its errors, so we # can't detect what's a pickle error and what's not. logger.exception("failed to load prompt history") self.history = { x: deque(maxlen=self.max_history) for x in self.completers } # self.history of size does not match. if len(self.history) != len(self.completers): self.history = { x: deque(maxlen=self.max_history) for x in self.completers } if self.max_history != self.history[list( self.history)[0]].maxlen: self.history = { x: deque(self.history[x], self.max_history) for x in self.completers } else: self.history = { x: deque(maxlen=self.max_history) for x in self.completers }
def find_sockfile(display: str = None): """ Finds the appropriate socket file for the given display. If unspecified, the socket file is determined as follows: - If WAYLAND_DISPLAY is set, use it. - else if DISPLAY is set, use that. - else check for the existence of a socket file for WAYLAND_DISPLAY=wayland-0 and if it exists, use it. - else check for the existence of a socket file for DISPLAY=:0.0 and if it exists, use it. - else raise an IPCError. """ cache_directory = get_cache_dir() if display: return os.path.join(cache_directory, SOCKBASE % display) display = os.environ.get("WAYLAND_DISPLAY") if display: return os.path.join(cache_directory, SOCKBASE % display) display = os.environ.get("DISPLAY") if display: if "." not in display: display += ".0" return os.path.join(cache_directory, SOCKBASE % display) sockfile = os.path.join(cache_directory, SOCKBASE % "wayland-0") if os.path.exists(sockfile): return sockfile sockfile = os.path.join(cache_directory, SOCKBASE % ":0.0") if os.path.exists(sockfile): return sockfile raise IPCError("Could not find socket file.")
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE # SOFTWARE. import json import os from datetime import datetime, timedelta from libqtile import bar from libqtile.log_utils import logger from libqtile.utils import get_cache_dir from libqtile.widget import base _CACHE = os.path.join(get_cache_dir(), 'habit_tracker_count.json') class HabitTracker(base._Widget): """ A don't-break-the-chain style habit tracker widget. The current chain lengths are stored in a JSON file containing a dictionary where each key is the name of a habit. This habit can be passed to the widget to identify a chain. The chain can be drawn in different styles: - "chain": A simple chain of connected squares that grows through the grid as it increases in length. - "base": A grid of squares where each column represents one digit in a counting