def check_desktop(args: argparse.Namespace, desktop_count: int): if args.desktop is not None: if args.desktop < 0 or args.desktop >= desktop_count: msg = "Desktop '{}' is invalid! Choose between 0 and {}".format( args.desktop, desktop_count - 1) print(msg, file=sys.stderr) if args.gui: gui.show_error(msg) exit(-1) else: args.desktop = wmctrl.current_desktop()
def main(): parser = argparse.ArgumentParser(description='Restore virtual desktops (workspaces)') parser.add_argument("-g", "--gui", action="store_true", help="gui mode") parser.add_argument("-p", "--profile", default="default", help="profile name") parser.add_argument("-d", "--desktop", type=int, default=None, help="target desktop number from 0 to n") parser.add_argument("--version", action="version", version="0.1.1") args = parser.parse_args() c.check_dependencies(args) try: restore(args) except Exception as e: traceback.print_exc() if args.gui: gui.show_error("{}: {}".format(type(e).__name__, str(e))) exit(-1)
def restore(args: argparse.Namespace): desktop_list = wmctrl.list_desktop() c.check_desktop(args, len(desktop_list)) if args.gui: gui.show_restore_desktop(args, desktop_list, p.list_profiles()) print("Restoring profile: {}".format(args.profile)) try: window_list = p.read_profile(args.profile) except FileNotFoundError as e: msg = "profile '{0}' not found".format(e.filename) print(msg, file=sys.stderr) if args.gui: gui.show_error(msg) exit(-1) wmctrl.switch_desktop(args.desktop) for props in window_list: open_window(args.desktop, props)
def check_dependencies(args: argparse.Namespace): if not check_wmctrl_installation(): print("wmctrl is not installed", file=sys.stderr) if args.gui: gui.show_error("wmctrl is not installed") exit(-1) if not check_xwininfo_installation(): print("xwininfo is not installed", file=sys.stderr) if args.gui: gui.show_error("xwininfo is not installed") exit(-1) if not check_xdotool_installation(): print("xdotool is not installed", file=sys.stderr) if args.gui: gui.show_error("xdotool is not installed") exit(-1)