Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #! /usr/bin/env python
- ### Suggested usage: display the legend on the (root window) desktop,
- ### by installing debian pkg "xrootconsole" and adding a line within session autostart file:
- ### xrootconsole ~/.icewm/icekeys-legend.txt
- ### (read the xrootconsole manpage! fontsize, color, x/y offset are configurable)
- ### -or-
- ### add a conky bit which monitors, and dynamically updates the legend
- ### ${execi watch -n 30 | cat ~/.icewm/icekeys-legend.txt | sort -r}
- ### (can run multiple conky instances, but each adds 20MB? session overhead)
- ###
- ### another utility, "root-tail" is similar/equivalent to "xrootconsole"
- import os
- lefty = []; righty = []; maxwidleft = 0; mydescription = ''; outtext = ''
- ### terse statement, but it works (presuming the file exists and is readable)
- dalist = [line for line in open(os.path.expanduser('~/.icewm/keys'), "r").read().splitlines() if line]
- for line in dalist:
- line = line.strip()
- pieces = line.split()
- if line.startswith('### v--- desc: '): ### chars0--17
- ''' TO DISPLAY A FRIENDLY DESCRIPTION IN PLACE OF EXECSTRING,
- THE keys FILE WOULD CONTAIN, FOR EXAMPLE:
- ### v--- desc: decrease volume 5%
- key "Alt+Ctrl+KP_Divide" amixer -c 0 set Master 5-# lower volume
- '''
- mydescription = " " + str(line)[18:]
- continue
- ### a valid line must contain elements[0,1,2] and begin with "key"
- elif line.startswith('key') and line.split()[2]:
- if pieces[1].startswith('"') and pieces[1].endswith('"'):
- lefty.append( str(pieces[1])[1:-1].replace('+',' + ') )
- maxwidleft = max( len(str(pieces[1])) + 3, maxwidleft )
- else:
- continue ### malformed line, so skip
- if mydescription != '':
- righty.append(mydescription)
- else:
- ### How long is a piece of string?
- skip = len(str(pieces[0])) + len(str(pieces[1])) + 1
- ### discard any end-of-line comments
- righty.append( str(str(line[skip:]).partition('#')[0]) )
- mydescription = '' # reset to blank after using
- for i in range(len(righty)):
- myline = str(lefty[i]).rjust(maxwidleft) + " :" + str(righty[i])
- outtext = outtext + myline + "\n"
- f = open(os.path.expanduser('~/.icewm/icekeys-legend.txt'), "w")
- f.write(outtext) ### creates, or overwrites existing
- f.close()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement