def change_gtk_theme(self): """ Changes gtk theme with help of gsd-xsettings """ theme_dirs = [] gtk_theme_path = pathlib.Path('~/.local/share/themes').expanduser() for theme in gtk_theme_path.glob('*/*/gtk.css'): if theme: theme_dirs += [pathlib.PurePath(theme).parent.parent.name] menu_params = self.menu_params(len(theme_dirs), 'gtk theme') selection = '' if not theme_dirs: return if len(theme_dirs) == 1: selection = theme_dirs[0] else: try: selection = subprocess.run( self.menu.args(menu_params), stdout=subprocess.PIPE, input=bytes('\n'.join(theme_dirs), 'UTF-8'), check=True ).stdout except subprocess.CalledProcessError as proc_err: Misc.print_run_exception_info(proc_err) if selection: self.apply_settings(selection, '-a')
def change_icon_theme(self): """ Changes icon theme with help of gsd-xsettings """ icon_dirs = [] icons_path = pathlib.Path('~/.local/share/icons').expanduser() for icon in icons_path.glob('*'): if icon: icon_dirs += [pathlib.Path(icon).name] menu_params = self.menu_params(len(icon_dirs), 'icon theme') selection = '' if not icon_dirs: return if len(icon_dirs) == 1: selection = icon_dirs[0] else: try: selection = subprocess.run( self.menu.args(menu_params), stdout=subprocess.PIPE, input=bytes('\n'.join(icon_dirs), 'UTF-8'), check=True ).stdout except subprocess.CalledProcessError as proc_err: Misc.print_run_exception_info(proc_err) if selection: self.apply_settings(selection, '-i')
def apply_settings(self, selection, *cmd_opts): """ Apply selected gnome settings """ ret = "" if selection is not None: ret = selection.decode('UTF-8').strip() if ret is not None and ret != '': try: subprocess.call([self.gsettings_script, *cmd_opts, ret]) except subprocess.CalledProcessError as proc_err: Misc.print_run_exception_info(proc_err)
def xprop(self) -> None: """ Menu to show X11 atom attributes for current window. """ xprops = [] target_win = self.menu.i3ipc.get_tree().find_focused() try: xprop_ret = subprocess.run( ['xprop', '-id', str(target_win.window)] + self.menu.xprops_list, stdout=subprocess.PIPE, check=True).stdout if xprop_ret is not None: xprop_ret = xprop_ret.decode().split('\n') for line in xprop_ret: if 'not found' not in line: xprops.append(line) except subprocess.CalledProcessError as proc_err: Misc.print_run_exception_info(proc_err) menu_params = { 'cnum': 1, 'lnum': len(xprops), 'width': int(self.menu.screen_width * 0.75), 'prompt': f'{self.menu.wrap_str("xprop")} {self.menu.conf("prompt")}' } ret = "" try: xprop_sel = subprocess.run(self.menu.args(menu_params), stdout=subprocess.PIPE, input=bytes('\n'.join(xprops), 'UTF-8'), check=True).stdout if xprop_sel is not None: ret = xprop_sel.decode('UTF-8').strip() except subprocess.CalledProcessError as proc_err: Misc.print_run_exception_info(proc_err) # Copy to the clipboard if ret is not None and ret != '': try: subprocess.run(['xsel', '-i'], input=bytes(ret.strip(), 'UTF-8'), check=True) except subprocess.CalledProcessError as proc_err: Misc.print_run_exception_info(proc_err)
def set_screen_size(cls, size_id=0) -> None: try: subprocess.run(['xrandr', '-s', str(size_id)], check=True) except subprocess.CalledProcessError as proc_err: Misc.print_run_exception_info(proc_err)
def apply_settings(self): """ Apply selected gnome settings """ try: subprocess.Popen([self.gsettings_script]) except subprocess.CalledProcessError as proc_err: Misc.print_run_exception_info(proc_err)