Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/scottkirkwood/key-mon
Browse files Browse the repository at this point in the history
Really delete the files
  • Loading branch information
scottkirkwood committed Aug 6, 2020
2 parents 95d5cf3 + 458a8a5 commit 11a4d19
Show file tree
Hide file tree
Showing 12 changed files with 118 additions and 125 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
__pycache__
*pyc
*~
2 changes: 1 addition & 1 deletion INSTALL.rst
Original file line number Diff line number Diff line change
Expand Up @@ -44,4 +44,4 @@ This program requires::
* python-gtk2 - Python bindings for the GTK+ widget set
(http://www.pygtk.org/)

-- file generated by `pybdist`.
-- file generated by `pybdist`.
4 changes: 2 additions & 2 deletions build.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@

def build_screen_shots():
"""Build the screenshots for key-mon."""
prog = '%s/%s' % (setup.DIR, setup.PY_SRC)
prog = f'{setup.DIR}/{setup.PY_SRC}'
destdir = 'docs'
all_buttons = ['KEY_A', 'KEY_CONTROL_L', 'KEY_ALT_L', 'KEY_SHIFT_L']
todos = [
Expand Down Expand Up @@ -75,7 +75,7 @@ def main():
if options.png:
build_screen_shots()
elif not pybdist.handle_standard_options(options, setup):
print 'Doing nothing. --help for commands.'
print('Doing nothing. --help for commands.')

if __name__ == '__main__':
main()
20 changes: 10 additions & 10 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@
PY_NAME = 'key_mon'
DEB_NAME = NAME.replace('-', '')
RELEASE_FILE = 'RELEASE.rst'
VCS = 'http://%s.code.google.com/hg' % NAME
VCS = f'http://{NAME}.code.google.com/hg'

PY_SRC = '%s.py' % PY_NAME
PY_SRC = f'{PY_NAME}.py'
DEPENDS = ['python-xlib', 'python-gtk2']
DEPENDS_STR = ' '.join(DEPENDS)

Expand All @@ -37,10 +37,10 @@
GOOGLE_CODE_EMAIL = 'scott@forusers.com'
MAILING_LIST = 'key-mon-discuss@googlegroups.com'
KEYWORDS = ['keyboard', 'status', 'monitor', 'education']
MAN_FILE = 'man/%s.1' % NAME
DESKTOP_FILE = 'icons/%s.desktop' % NAME
ICON = 'icons/%s.xpm' % NAME
COMMAND = '/usr/bin/%s' % NAME
MAN_FILE = f'man/{NAME}.1'
DESKTOP_FILE = f'icons/{NAME}.desktop'
ICON = f'icons/{NAME}.xpm'
COMMAND = f'/usr/bin/{NAME}'
LANGS = ['pt_BR']
HICOLOR_PNG_SIZES = [16, 24, 32, 48, 64, 128]

Expand All @@ -57,17 +57,17 @@
},
data_files = [
('share/pixmaps', [ICON]),
('share/icons/hicolor', ['icons/hicolor/%dx%d/apps/%s.png' % (x, x, NAME) for x in HICOLOR_PNG_SIZES]),
('share/icons/hicolor', ['icons/hicolor/scalable/apps/%s.svg' % NAME]),
('share/icons/hicolor', [f'icons/hicolor/{x}x{x}/apps/{NAME}.png' for x in HICOLOR_PNG_SIZES]),
('share/icons/hicolor', [f'icons/hicolor/scalable/apps/{NAME}.svg']),
],
scripts=['src/key-mon'],
author=AUTHOR_NAME,
author_email='scott+keymon@forusers.com',
platforms=['POSIX'],
license='Apache 2.0',
keywords=' '.join(KEYWORDS),
url='http://code.google.com/p/%s' % NAME,
download_url='http://%s.googlecode.com/files/%s-%s.zip' % (NAME, NAME, VER),
url=f'http://code.google.com/p/{NAME}',
download_url=f'http://{NAME}.googlecode.com/files/{NAME}-{VER}.zip',
description=_('A screencast utility that displays your keyboard and mouse status'),
long_description=_("""Key-mon is useful for teaching since it shows the current status of your
keyboard and mouse and you use them in another application. No longer do you need to say
Expand Down
61 changes: 30 additions & 31 deletions src/keymon/key_mon.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ def fix_svg_key_closure(fname, from_tos):

def fix_svg_key():
"""Given an SVG file return the SVG text fixed."""
logging.debug('Read file %r', fname)
logging.debug(f'Read file {fname!r}')
fin = open(fname)
fbytes = fin.read()
fin.close()
Expand Down Expand Up @@ -149,7 +149,7 @@ def do_screenshot(self):
if key.startswith('KEY_'):
key_info = self.modmap.get_from_name(key)
if not key_info:
print('Key %s not found' % key)
print(f'Key {key} not found')
self.destroy(None)
return
scancode = key_info[0]
Expand All @@ -174,7 +174,7 @@ def do_screenshot(self):

fname = 'screenshot.png'
screenshot.savev(fname, 'png')
print('Saved screenshot %r' % fname)
print(f'Saved screenshot {fname!r}')
self.destroy(None)

def create_names_to_fnames(self):
Expand Down Expand Up @@ -221,15 +221,15 @@ def create_names_to_fnames(self):

ftn.update({
'BTN_RIGHT': [self.svg_name('mouse'),
self.svg_name('%s-mouse' % right_str)],
self.svg_name(f'{right_str}-mouse')],
'BTN_LEFT': [self.svg_name('mouse'),
self.svg_name('%s-mouse' % left_str)],
self.svg_name(f'{left_str}-mouse')],
'BTN_LEFTMIDDLE': [
self.svg_name('mouse'), self.svg_name('%s-mouse' % left_str),
self.svg_name('mouse'), self.svg_name(f'{left_str}-mouse'),
self.svg_name('middle-mouse')],
'BTN_MIDDLERIGHT': [
self.svg_name('mouse'), self.svg_name('middle-mouse'),
self.svg_name('%s-mouse' % right_str)],
self.svg_name(f'{right_str}-mouse')],
})

if self.options.scale >= 1.0:
Expand All @@ -239,13 +239,13 @@ def create_names_to_fnames(self):
[('TOP', 'Space'), ('BOTTOM', '')])],
'KEY_TAB': [
fix_svg_key_closure(self.svg_name('two-line-wide'),
[('TOP', 'Tab'), ('BOTTOM', '\u21B9')])],
[('TOP', 'Tab'), ('BOTTOM', '\N{Leftwards arrow to bar over rightwards arrow to bar}')])],
'KEY_BACKSPACE': [
fix_svg_key_closure(self.svg_name('two-line-wide'),
[('TOP', 'Back'), ('BOTTOM', '\u21fd')])],
[('TOP', 'Back'), ('BOTTOM', '\N{Leftwards open-headed arrow}')])],
'KEY_RETURN': [
fix_svg_key_closure(self.svg_name('two-line-wide'),
[('TOP', 'Enter'), ('BOTTOM', '\u23CE')])],
[('TOP', 'Enter'), ('BOTTOM', '\N{Return symbol}')])],
'KEY_CAPS_LOCK': [
fix_svg_key_closure(self.svg_name('two-line-wide'),
[('TOP', 'Capslock'), ('BOTTOM', '')])],
Expand Down Expand Up @@ -398,10 +398,10 @@ def layout_boxes(self):
def svg_name(self, fname):
"""Return an svg filename given the theme, system."""
themepath = self.options.themes[self.options.theme][1]
fullname = os.path.join(themepath, '%s%s.svg' % (fname, self.svg_size))
fullname = os.path.join(themepath, f'{fname}{self.svg_size}.svg')
if self.svg_size and not os.path.exists(fullname):
# Small not found, defaulting to large size
fullname = os.path.join(themepath, '%s.svg' % fname)
fullname = os.path.join(themepath, f'{fname}.svg')
return fullname

def add_events(self):
Expand Down Expand Up @@ -466,7 +466,7 @@ def _window_moved(self):
x, y = x + new_p[0] - old_p[0], y + new_p[1] - old_p[1]
self.window.move(x, y)

logging.info('Moved window to %d, %d' % (x, y))
logging.info(f'Moved window to {x}, {y}')
self.options.x_pos = x
self.options.y_pos = y

Expand Down Expand Up @@ -529,8 +529,8 @@ def no_press_fadeout(self, begin=True):
"""
opacity = self.window.get_opacity() - self.options.opacity / 10.0
if opacity < 0.0:
opacity = 0.0;
logging.debug('Set opacity = %f' % opacity)
opacity = 0.0
logging.debug(f'Set opacity = {opacity}')
self.window.set_opacity(opacity)
if opacity == 0.0:
self.window.hide()
Expand Down Expand Up @@ -566,7 +566,7 @@ def _handle_event(self, image, name, code):
image.really_pressed = code == 1
if code == 1:
if self._show_down_key(name):
logging.debug('Switch to %s, code %s' % (name, code))
logging.debug(f'Switch to {name}, code {code}')
image.switch_to(name)
return

Expand All @@ -591,12 +591,11 @@ def handle_key(self, scan_code, xlib_name, value):
code, medium_name, short_name = self.modmap.get_and_check(scan_code,
xlib_name)
if not code:
logging.info('No mapping for scan_code %s', scan_code)
logging.info(f'No mapping for scan_code {scan_code}')
return
if self.options.scale < 1.0 and short_name:
medium_name = short_name
logging.debug('Scan code %s, Key %s pressed = %r', scan_code,
code, medium_name)
logging.debug(f'Scan code {scan_code}, Key {code} pressed = {medium_name!r}')
if code in self.name_fnames:
self._handle_event(self.key_image, code, value)
return
Expand All @@ -622,15 +621,15 @@ def handle_key(self, scan_code, xlib_name, value):
if code.startswith('KEY_'):
letter = medium_name
if code not in self.name_fnames:
logging.debug('code not in %s', code)
logging.debug(f'code not in {code}')
if len(letter) == 1:
template = 'one-char-template'
else:
template = 'multi-char-template'
self.name_fnames[code] = [
fix_svg_key_closure(self.svg_name(template), [('&amp;', letter)])]
else:
logging.debug('code in %s', code)
logging.debug(f'code in {code}')
self._handle_event(self.key_image, code, value)
return

Expand Down Expand Up @@ -835,8 +834,8 @@ def show_about_dlg(self, *_):

def show_version():
"""Show the version number and author, used by help2man."""
print(_('Keymon version %s.') % __version__)
print(_('Written by %s') % __author__)
print(_(f'Keymon version {__version__}.'))
print(_(f'Written by {__author__}'))

def create_options():
opts = options.Options()
Expand Down Expand Up @@ -975,14 +974,14 @@ def main():
loglevel = sys.argv[idx + 1]
level = getattr(logging, loglevel.upper(), None)
if level is None:
raise ValueError('Invalid log level: %s' % loglevel)
raise ValueError(f'Invalid log level: {loglevel}')
loglevel = level
else:
if '--debug' in sys.argv or '-d' in sys.argv:
loglevel = logging.DEBUG
logging.basicConfig(
level=loglevel,
format='%(filename)s [%(lineno)d]: %(levelname)s %(message)s')
level=loglevel, style='{',
format='{filename} [{lineno}]: {levelname} {message}')
if loglevel is None:
# Disabling warning, info, debug messages
logging.disable(logging.WARNING)
Expand All @@ -1007,16 +1006,16 @@ def main():
theme_names = sorted(opts.themes)
name_len = max(len(name) for name in theme_names)
for theme in theme_names:
print((' - %%-%ds: %%s' % name_len) % (theme, opts.themes[theme][0]))
print(f' - {theme:<{name_len}}: {opts.themes[theme][0]}')
raise SystemExit()
elif opts.theme and opts.theme not in opts.themes:
print(_('Theme %r does not exist') % opts.theme)
print(_(f'Theme {opts.theme!r} does not exist'))
print()
print(_('Please make sure %r can be found in '
'one of the following directories:') % opts.theme)
print(_(f'Please make sure {opts.theme!r} can be found in '
'one of the following directories:'))
print()
for theme_dir in settings.get_config_dirs('themes'):
print(' - %s' % theme_dir)
print(f' - {theme_dir}')
sys.exit(-1)
if opts.reset:
print(_('Resetting to defaults.'))
Expand Down
16 changes: 8 additions & 8 deletions src/keymon/lazy_pixbuf_creator.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,12 +71,12 @@ def create_pixbuf(self, name):
The name given or EMPTY if error.
"""
if name not in self.name_fnames:
logging.error('Don\'t understand the name %r', name)
logging.error(f'Don\'t understand the name {name!r}')
return 'KEY_EMPTY'
ops = self.name_fnames[name]
img = None
for operation in ops:
if isinstance(operation, (str,)):
if isinstance(operation, str):
img = self._composite(img, self._read_from_file(operation))
else:
image_bytes = operation()
Expand Down Expand Up @@ -104,7 +104,7 @@ def _composite(self, img, img2):

def _read_from_file(self, fname):
"""Read in the file in from fname."""
logging.debug('Read file %s', fname)
logging.debug(f'Read file {fname}')
if self.resize == 1.0:
return GdkPixbuf.Pixbuf.new_from_file(fname)
fin = open(fname)
Expand All @@ -120,7 +120,7 @@ def _read_from_bytes(self, image_bytes):
try:
img = GdkPixbuf.Pixbuf.new_from_file(fname)
except:
logging.error('Unable to read %r: %s', fname, image_bytes)
logging.error(f'Unable to read {fname!r}: {image_bytes}')
sys.exit(-1)

try:
Expand All @@ -133,11 +133,11 @@ def _resize(self, image_bytes):
"""Resize the image by manipulating the svg."""
if self.resize == 1.0:
return image_bytes
template = r'(<svg[^<]+)(%s=")(\d+\.?\d*)'
image_bytes = self._resize_text(image_bytes, template % 'width')
image_bytes = self._resize_text(image_bytes, template % 'height')
template = r'(<svg[^<]+)({}=")(\d+\.?\d*)'
image_bytes = self._resize_text(image_bytes, template.format('width'))
image_bytes = self._resize_text(image_bytes, template.format('height'))
image_bytes = image_bytes.replace('<g',
'<g transform="scale(%f, %f)"' % (self.resize, self.resize), 1)
f'<g transform="scale({self.resize}, {self.resize})"', 1)
return image_bytes

def _resize_text(self, image_bytes, regular_exp):
Expand Down
Loading

0 comments on commit 11a4d19

Please sign in to comment.