"Fossies" - the Fresh Open Source Software Archive

Member "screenkey-1.1/screenkey" (19 May 2020, 4572 Bytes) of package /linux/privat/screenkey-1.1.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) Python source code syntax highlighting (style: standard) with prefixed line numbers. Alternatively you can here view or download the uninterpreted source code file. See also the last Fossies "Diffs" side-by-side code changes report for "screenkey": 0.9_vs_1.0.

    1 #!/usr/bin/env python3
    2 # -*- coding: utf-8 -*-
    3 # "screenkey" is distributed under GNU GPLv3+, WITHOUT ANY WARRANTY.
    4 # Copyright(c) 2010-2012: Pablo Seminario <pabluk@gmail.com>
    5 # Copyright(c) 2015-2020: wave++ "Yuri D'Elia" <wavexx@thregr.org>.
    6 
    7 from Screenkey import *
    8 
    9 import logging
   10 import os
   11 import re
   12 from argparse import ArgumentParser
   13 
   14 
   15 def parse_geom_fract(buf):
   16     if len(buf) == 0:
   17         return 0
   18     if buf[-1] == '%':
   19         v = int(buf[:-1])
   20         if v == 0:
   21             return 0
   22         return v / 100
   23     return int(buf)
   24 
   25 
   26 def geometry(string):
   27     size = re.match(r'^(\d+%?)x(\d+%?)(?:([+-]\d+%?)([+-]\d+%?))?$', string)
   28     if size is None:
   29         raise TypeError
   30     w = parse_geom_fract(size.group(1))
   31     h = parse_geom_fract(size.group(2))
   32     if w == 0 or h == 0:
   33         raise TypeError
   34     x = parse_geom_fract(size.group(3)) if size.group(3) else 0
   35     y = parse_geom_fract(size.group(4)) if size.group(4) else 0
   36     return [x, y, w, h]
   37 
   38 
   39 def main():
   40     ap = ArgumentParser(description=APP_DESC)
   41     ap.add_argument("-d", "--debug", action="store_true",
   42                     help=_("enable debugging"))
   43     ap.add_argument("--no-systray", action="store_true",
   44                     help=_("do not create system tray icon"))
   45     ap.add_argument("-t", "--timeout", type=float, help=_("timeout in seconds"))
   46     ap.add_argument("-p", "--position", choices=POSITIONS,
   47                     help=_("set vertical position"))
   48     ap.add_argument("--persist", action='store_true', default=None,
   49                     help=_("make window persistent"))
   50     ap.add_argument("-s", "--font-size", choices=FONT_SIZES,
   51                     help=_("set font size"))
   52     ap.add_argument("-g", "--geometry", type=geometry,
   53                     help=_("set fixed area/window geometry"))
   54     ap.add_argument("--key-mode", choices=KEY_MODES,
   55                     help=_("set key processing mode"))
   56     ap.add_argument("--bak-mode", choices=BAK_MODES,
   57                     help=_("backspace processing mode"))
   58     ap.add_argument("--mods-mode", choices=MODS_MODES,
   59                     help=_("modifiers visualization mode"))
   60     ap.add_argument("-m", "--mods-only", action="store_true", default=None,
   61                     help=_("show only keys with modifiers pressed"))
   62     ap.add_argument("--multiline", action="store_true", default=None,
   63                     help=_("span text over multiple lines"))
   64     ap.add_argument("--vis-shift", action="store_true", default=None,
   65                     help=_("always show Shift when modifiers are pressed"))
   66     ap.add_argument("--no-whitespace", dest='vis_space', action="store_false", default=None,
   67                     help=_("disable visualization of whitespace"))
   68     ap.add_argument("--show-settings", action="store_true",
   69                     help=_("show settings dialog on start"))
   70     ap.add_argument("--scr", dest='screen', type=int,
   71                     help=_("show on the specified screen number"))
   72     ap.add_argument("-f", "--font", dest='font_desc',
   73                     help=_("set font family/weight"))
   74     ap.add_argument("--font-color", dest='font_color',
   75                     help=_("set font color"))
   76     ap.add_argument("--bg-color", dest='bg_color',
   77                     help=_("background color"))
   78     ap.add_argument("--opacity", dest='opacity', type=float,
   79                     help=_("window opacity (in range 0.0-1.0)"))
   80     ap.add_argument("--ignore", action='append', metavar='KeySym', default=[],
   81                     help=_("Ignore the specified KeySym"))
   82     ap.add_argument("--compr-cnt", type=int, metavar='COUNT',
   83                     help=_("Compress key repeats after the specified count"))
   84     args = ap.parse_args()
   85 
   86     # Set options
   87     options = Options()
   88     for arg in ['timeout', 'position', 'persist', 'font_desc', 'font_color', 'bg_color',
   89                 'font_size', 'geometry', 'key_mode', 'bak_mode', 'mods_mode', 'mods_only',
   90                 'multiline', 'vis_shift', 'vis_space', 'screen', 'no_systray',
   91                 'opacity', 'ignore', 'compr_cnt']:
   92         if getattr(args, arg) is not None:
   93             options[arg] = getattr(args, arg)
   94 
   95     # Initialize logger
   96     if args.debug:
   97         logging.basicConfig(level=logging.DEBUG)
   98     else:
   99         logging.basicConfig(level=logging.INFO)
  100     logger = logging.getLogger(APP_NAME)
  101 
  102     import Screenkey.screenkey as sc
  103     app = sc.Screenkey(logger=logger, options=options, show_settings=args.show_settings)
  104     try:
  105         exit(app.run())
  106     except KeyboardInterrupt:
  107         os._exit(0)
  108 
  109 
  110 if __name__ == "__main__":
  111     main()