#!/usr/bin/python3 # -*- coding: utf-8 -*- app_svnid = '$HeadURL$ $LastChangedRevision$' # Modules import sys import subprocess sys.path.append(subprocess.Popen(["ade-config", "ade_share_prefix"], stdout=subprocess.PIPE, universal_newlines=True).communicate()[0][:-1] + '/include') import ade import os # Errors lxadepy_defined_errors = { "lxadepy_err_misc":{"fmt":"%s"}, } # Options opt_force = None; opt_labelwhat = None; # Other globals # The next line is extracted by 'adegmt -l'. After adegmt has been used to get this template the line can be removed. # ADEGMT-LIST-HINT: ADE-based python script implementing lx(1) def lxadepy(errstack): global opt_force, opt_labelwhat # Defaults for options opt_force = 0 opt_labelwhat = 0 # Register errors, options and callbacks ade.register_error_types(lxadepy_defined_errors) rc = ade.register_options(errstack, "wibF", "window,icon,both,force", globals(), "handle_option_%s") if rc != ade.ok: return rc rc = ade.set_callbacks(errstack, lxadepy_usage_help, lxadepy_version, lxadepy_paths) if rc != ade.ok: return rc # Process options rc = ade.process_options(errstack) if rc != ade.ok: return rc # Process arguments len(sys.argv) != 1 and ade.show_bad_usage(errstack) label = sys.argv[0] # Sanity checks and derivations if not opt_force and not is_relabelable_term(errstack, os.getenv('TERM'))[1]: ade.error(errstack, "lxadepy_err_misc", "the title of this sort of terminal cannot be changed by this program (is 'TERM' set correctly?)") return ade.fail # Guts sys.stdout.write("\033]%d;%s\007" % (opt_labelwhat, label)) return ade.ok # Option handlers def handle_option_w(errstack): global opt_labelwhat opt_labelwhat = 2 return ade.ok def handle_option_window(*args): return handle_option_w(*args) def handle_option_i(errstack): global opt_labelwhat opt_labelwhat = 1 return ade.ok def handle_option_icon(*args): return handle_option_i(*args) def handle_option_b(errstack): global opt_labelwhat opt_labelwhat = 0 return ade.ok def handle_option_both(*args): return handle_option_b(*args) def handle_option_F(errstack): global opt_force opt_force = 1 return ade.ok def handle_option_force(*args): return handle_option_F(*args) # Callbacks def lxadepy_usage_help(errstack): return ade.ok, "", " -w | --window label the window only\n" + \ " -i | --icon label the icon only\n" + \ " -b | --both label both (default)\n" + \ " -F | --force ignore 'TERM' and force labelling\n" def lxadepy_version(errstack): return ade.extract_version(errstack, app_svnid) def lxadepy_paths(errstack): return ade.ok, None # Other functions def is_relabelable_term(errstack, term): if term is not None and term in "rxvt xterm xterm-debian cygwin".split(): isrelabelable_flag = 1 elif term is not None and "xterm" in term: ade.warning(errstack, "lxadepy_err_misc", "guessing this is some sort of xterm") isrelabelable_flag = 1 elif term == "vt100" and "XSC|" in os.getenv('TERMCAP'): isrelabelable_flag = 1 else: isrelabelable_flag = 0 # pass up and return return ade.ok, isrelabelable_flag # Entry point ade.main(lxadepy)