Advertisement
Guest User

Untitled

a guest
May 1st, 2018
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.39 KB | None | 0 0
  1. #! /usr/bin/env python
  2. ### Suggested usage: display the legend on the (root window) desktop,
  3. ### by installing debian pkg "xrootconsole" and adding a line within session autostart file:
  4. ### xrootconsole ~/.icewm/icekeys-legend.txt
  5. ### (read the xrootconsole manpage! fontsize, color, x/y offset are configurable)
  6. ### -or-
  7. ### add a conky bit which monitors, and dynamically updates the legend
  8. ### ${execi watch -n 30 | cat ~/.icewm/icekeys-legend.txt | sort -r}
  9. ### (can run multiple conky instances, but each adds 20MB? session overhead)
  10. ###
  11. ### another utility, "root-tail" is similar/equivalent to "xrootconsole"
  12.  
  13. import os
  14.  
  15. lefty = []; righty = []; maxwidleft = 0; mydescription = ''; outtext = ''
  16.  
  17. ### terse statement, but it works (presuming the file exists and is readable)
  18. dalist = [line for line in open(os.path.expanduser('~/.icewm/keys'), "r").read().splitlines() if line]
  19.  
  20. for line in dalist:
  21. line = line.strip()
  22. pieces = line.split()
  23. if line.startswith('### v--- desc: '): ### chars0--17
  24. ''' TO DISPLAY A FRIENDLY DESCRIPTION IN PLACE OF EXECSTRING,
  25. THE keys FILE WOULD CONTAIN, FOR EXAMPLE:
  26. ### v--- desc: decrease volume 5%
  27. key "Alt+Ctrl+KP_Divide" amixer -c 0 set Master 5-# lower volume
  28. '''
  29. mydescription = " " + str(line)[18:]
  30. continue
  31.  
  32. ### a valid line must contain elements[0,1,2] and begin with "key"
  33. elif line.startswith('key') and line.split()[2]:
  34. if pieces[1].startswith('"') and pieces[1].endswith('"'):
  35. lefty.append( str(pieces[1])[1:-1].replace('+',' + ') )
  36. maxwidleft = max( len(str(pieces[1])) + 3, maxwidleft )
  37. else:
  38. continue ### malformed line, so skip
  39.  
  40. if mydescription != '':
  41. righty.append(mydescription)
  42. else:
  43. ### How long is a piece of string?
  44. skip = len(str(pieces[0])) + len(str(pieces[1])) + 1
  45. ### discard any end-of-line comments
  46. righty.append( str(str(line[skip:]).partition('#')[0]) )
  47.  
  48. mydescription = '' # reset to blank after using
  49.  
  50. for i in range(len(righty)):
  51. myline = str(lefty[i]).rjust(maxwidleft) + " :" + str(righty[i])
  52. outtext = outtext + myline + "\n"
  53.  
  54. f = open(os.path.expanduser('~/.icewm/icekeys-legend.txt'), "w")
  55. f.write(outtext) ### creates, or overwrites existing
  56. f.close()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement