You are not logged in.
UPDATED obkb.py now saves rc.xml keybinds to file, and displays them in a zenity dialog, so it is easy to run from a keybind or menu item
----------------------------------------------------------------------------------------------------------------------------------------------
I came across some handy bits and pieces while looking for conky/lua info, including a script to extract keyboard and mouse bindings from rc.xml and display them in Conkys. The blog site belongs to wlourf of these parts - the page is here:How to display openbox shortcuts
(The link to the file is only for registered ubuntu-ers, but you can download it from my Dropbox here)
Anyway, I hacked at the python to make a script that parses the xml to display the shortcuts in the terminal, or pipe it to a file.
#!/usr/bin/env python
# coding=utf-8
#
#########################################################################
# This script reads the keybinds configuration file #
# (".config/openbox/rc.xml") #
# and writes them to a text file (".config/openbox/kbinds.txt"). #
# This file is read and displayed on screen in a zenity text-info dialog#
# #
# Keyboard shorcuts without commands are not displayed #
# #
# Based on a script by wlourf 07/03/2010 #
# <http://u-stripts.blogspot.com/2010/03/how-to-display- #
# openboxs-shortcuts.html> #
# #
# The original script parsed the keyboard and mouse commands from #
# rc.xml, and passed them to Conkys to display on screen #
# #
# March 2014 by damo <damo.linux^at^gmail.com> #
# #
#########################################################################
# #
# USAGE: Output formatted keyboard shortcuts to the terminal with #
# "python path/to/obkb.py" #
# (or make executable and put in $PATH) #
# #
# If run in a terminal the keybinds are also echoed to screen #
# #
# #
# ****If Openbox xml version changes then the xml root will need #
# changing as well (line 55)******** #
# #
#########################################################################
import sys,os
import datetime
import subprocess
try:
from lxml import etree
except ImportError:
import xml.etree.ElementTree as etree
# path and name of the rc.xml and saved keybinds files
rc_fpath = os.environ["HOME"] + "/.config/openbox/rc.xml"
kb_fpath = os.environ["HOME"] + "/.config/openbox/kbinds.txt"
arrShortcut=[]
def keyboard():
"""read keyboard shorcuts"""
# Parse xml
strRoot="{http://openbox.org/3.4/rc}"
tree = etree.parse(rc_fpath)
root = tree.getroot()
for k in root.findall(strRoot+"keyboard/" + strRoot + "keybind"):
key = k.get("key")
action_element = k.find(strRoot+"action")
strTxt=""
if action_element!=None:
arrShortcut.append((key,"",""))
if action_element.get("name")=="Execute":
name_element=action_element.find(strRoot + "name")
command_element=action_element.find(strRoot + "command")
exec_element=action_element.find(strRoot + "execute")
if name_element != None:
strTxt=name_element.text
elif command_element != None:
strTxt=command_element.text
elif exec_element != None:
strTxt=exec_element.text
elif action_element.get("name")=="ShowMenu":
menu_element=action_element.find(strRoot + "menu")
if menu_element != None: strTxt=menu_element.text
else:
action_name=action_element.get("name")
if action_name!=None:
strTxt=action_name
arrShortcut[len(arrShortcut)-1]=(key,strTxt)
def output_keybinds(arrShortcut):
"""loop through array, and format output
then write to file"""
print str(datetime.date.today()) + "\trc.xml KEYBINDS"
print "-------------------------------\n"
for i in range(0,len(arrShortcut)):
keybinding=str(arrShortcut[i][0])
execute=str(arrShortcut[i][1])
if len(execute)>80 :
execute=execute[:75]+"....."
line = "{:2}".format(i) + "\t" + "{:<15}".format(keybinding)\
+ "\t" + execute
print(line)
write_file(line)
def check_rcfile(fpath,mode):
"""Check if rc.xml exists, and is accessible"""
try:
f = open(fpath,mode)
except IOError as e:
return False
return True
def write_file(line):
"""Text file to store keybinds"""
f = open(kb_fpath,'a')
f.write(line + "\n")
f.close()
def check_txtfile(kb_fpath):
"""Create Text file to store keybinds
write date/time heading"""
try:
f = open(kb_fpath,'w')
except IOError as e:
return False
return True
def prep_file(kb_fpath):
title = datetime.date.today()
f = open(kb_fpath,'a')
f.write(str(title) + "\trc.xml KEYBINDS\n------------------------------------\n")
f.close()
if __name__ == "__main__":
check_txtfile(kb_fpath)
if check_rcfile(rc_fpath,"r"):
prep_file(kb_fpath)
keyboard()
output_keybinds(arrShortcut)
else:
msg = "\nCan't open rc.xml for parsing\n\
Check the filepath given: " + rc_fpath + "\n"
print msg
sys.exit(1)
# The following command can be commented out if obkb.py is only being
# run in a terminal.
# Change it to whatever you need to display it
# eg change "zenity" to "yad"
# or use eg os.system("geany ~/.config/openbox/kbinds.txt")
os.system("zenity --text-info --filename=.config/openbox/kbinds.txt --width=700 --height=700")
or you can download it here obkb.py
**NB if you C&P the code make sure the indenting is all spaces or all tabs in your text editor
**NNB wlourf's script had some typos, some of which I may probably missed, and is missing a crucial import. You need to add
import os
Output is like this:
2013-12-11 rc.xml KEYBINDS
----------------------------------------
0 W-F12 Reconfigure
1 Menu root-menu
2 A-space client-list-combined-menu
3 W-space root-menu
.
.
etc
Last edited by damo (2014-03-06 16:55:15)
BunsenLabs Group on deviantArt
damo's gallery on deviantArt
Openbox themes
Forum Moderator
Offline
wlourf makes some nice conky stuff ... and this is excellent. Thanks!
I see now I have to edit a few.
· ↓ ↓ ↓ ↓ ↓ ↓ ·
BunsenLabs Forums now Open for Registration
· ↑ ↑ ↑ ↑ ↑ ↑ · BL ModSquad
Offline
UPDATED obkb.py now saves rc.xml keybinds to file, and displays them in a zenity dialog, so it is easy to run from a keybind or menu item
BunsenLabs Group on deviantArt
damo's gallery on deviantArt
Openbox themes
Forum Moderator
Offline
UPDATED obkb.py now saves rc.xml keybinds to file, and displays them in a zenity dialog, so it is easy to run from a keybind or menu item
That is G*R*E*A*T! Thank you!
When on SID I change the bottom line:
## os.system("zenity --text-info --filename=.config/openbox/kbinds.txt --width=700 --height=700")
os.system("yad --text-info --filename=.config/openbox/kbinds.txt --width=700 --height=800")
· ↓ ↓ ↓ ↓ ↓ ↓ ·
BunsenLabs Forums now Open for Registration
· ↑ ↑ ↑ ↑ ↑ ↑ · BL ModSquad
Offline
There's a few ways to do it - the joys of FOSS!
The dialog line could be commented completely and the script run in a terminal, or piped to whatever you like. I'll put some comments in the script there for those unfamiliar with script hacking
Last edited by damo (2014-03-06 15:42:10)
BunsenLabs Group on deviantArt
damo's gallery on deviantArt
Openbox themes
Forum Moderator
Offline
There's a few ways to do it - the joys of FOSS!
The dialog line could be commented completely and the script run in a terminal, or piped to whatever you like. I'll put some comments in the script there for those unfamiliar with script hacking
Yup FOSS - 101
... that's; FOSS 101 ways to do the same thing!
I've been playing with it ... testing ... and I have the terminal option as well:
OB Menu:
terminator --geometry=800x850+20+20 -b -x /home/sector11/bin/thelp /home/sector11/bin/obkbt
or directly in a terminal:
obkbt
Renamed the second version obkbt "t" for terminal output (commented out the last line) and .py isn't needed.
And since the text file is created every time the script is run, which makes perfect sense, I've abandoned the idea of a text editor - editing it is usless. So zenity (yad) or terminal output is perfect.
For us who tend to forget things - this is as I said before - perfect!
· ↓ ↓ ↓ ↓ ↓ ↓ ·
BunsenLabs Forums now Open for Registration
· ↑ ↑ ↑ ↑ ↑ ↑ · BL ModSquad
Offline
.....snip
And since the text file is created every time the script is run, which makes perfect sense, I've abandoned the idea of a text editor - editing it is usless. So zenity (yad) or terminal output is perfect.
For us who tend to forget things - this is as I said before - perfect!
:8 {)
Let's hope daddy includes it in the default menu in jessie!
----------------edit
...and I fixed a syntax error so that the date/title displays in the dialog as was intended
Last edited by damo (2014-03-06 16:54:09)
BunsenLabs Group on deviantArt
damo's gallery on deviantArt
Openbox themes
Forum Moderator
Offline
Sector11 wrote:.....snip
And since the text file is created every time the script is run, which makes perfect sense, I've abandoned the idea of a text editor - editing it is usless. So zenity (yad) or terminal output is perfect.
For us who tend to forget things - this is as I said before - perfect!
:8 {)
Let's hope daddy includes it in the default menu in jessie!
ummm ... PM him and point it out maybe?
Menu entry or an alias in the bashrc:
alias obkeys='obkbt.py'
----------------edit
...and I fixed a syntax error so that the date/title displays in the dialog as was intended
Error? What error? 8o
06 Mar 14 | 14:18:37 ~
$ obkeys
2014-03-06 rc.xml KEYBINDS
-------------------------------
0 C-A-Left GoToDesktop
1 C-A-Right GoToDesktop
2 C-A-Up GoToDesktop
{snip}
44 W-Down GrowToEdgeSouth
45 W-Up GrowToEdgeNorth
46 Print scrot '%F_%T_$wx$h_Sector11.jpg' -e 'mv $f ~/images/ & mirage ~/images/$f'
47 A-Print scrot '%F_%T_$wx$h_Sector11.png' -e 'mv $f ~/images/ & mirage ~/images/$f'
06 Mar 14 | 14:18:39 ~
$
Last edited by Sector11 (2014-03-06 17:19:41)
· ↓ ↓ ↓ ↓ ↓ ↓ ·
BunsenLabs Forums now Open for Registration
· ↑ ↑ ↑ ↑ ↑ ↑ · BL ModSquad
Offline
The header displayed in terminal, but I forgot to convert datetime to string so it didn't print to the text file
BunsenLabs Group on deviantArt
damo's gallery on deviantArt
Openbox themes
Forum Moderator
Offline
The header displayed in terminal, but I forgot to convert datetime to string so it didn't print to the text file
OH ... OK I never even noticed in yad that it wasn't there. Will grab the new one.
· ↓ ↓ ↓ ↓ ↓ ↓ ·
BunsenLabs Forums now Open for Registration
· ↑ ↑ ↑ ↑ ↑ ↑ · BL ModSquad
Offline
Just saw you pushing this little gem and had to pop in once again. To talk about the helper bash script I mentioned in the code here but never shared.
The helper bash script that allows an OB Menu command (launcher) to open a terminal run a command and have the terminal stay open.
I call it thelp - not mine, I just copied and pasted it to my ~/bin
#! /bin/bash
#
# THIS PROGRAM WILL: Open the terminal, execute a command, and keep the terminal open.
# The intention is that you call this script from a menu launcher and include an argument in your command. (SEE BELOW)
#
# Darrin Goodman (http://www.hilltopyodeler.com/blog) > hilltopyodeler@gmail.com
# Credit is due to 13u11fr09 through his/her thread at http://ubuntuforums.org/archive/index.php/t-296628.html
# Go to the link above for more ideas and philosophies on this subject.
#
# This script should be called from your panel/menu launcher using a command structure
# that will launch your terminal emulator, then call on this shell script, and then provide
# an argument that is taken in by this script ("$1" or $@); this argument tells the script
# which command to run (for instance: nmap --help).
# SYNTAX: [command] [path/to/helperScript.sh] [argument]
#
# PLEASE NOTE THAT:
# - "USER" SHOULD BE CHANGED TO YOUR OWN USERNAME BELOW
# - CHANGE "nmap --help" TO WHATEVER IS SPECIFIC TO YOUR NEEDS.
# - MAKE SURE THAT helperScript.sh IS EXECUTABLE (chmod 755 helperScript.sh)
#
# The command you should use in your panel/menu launcher is as follows.
# For gnome-terminal, use: gnome-terminal -x /home/USER/helperScript.sh nmap --help
# For xterm, use: xterm -e /home/USER/helperScript.sh nmap --help
# For Terminator, use: terminator -x /home/USER/helperScript.sh nmap --help
# [-x] and [-e] are the flags for "execute".
# Note: for some reason, "terminator -x" will launch some things in Terminator,
# but not others; not sure why at this time.
#
# The reference below to /bin/bash tells the terminal to keep a bash shell open and running.
$@
/bin/bash
So I as mentioned, I copied obkb.py to obkbt.py - commenting the line at the end starting zenity and in OpenBox I have a menu entry:
terminator --geometry=800x870+20+20 -b -x /home/sector11/bin/thelp /home/sector11/bin/obkbt
· ↓ ↓ ↓ ↓ ↓ ↓ ·
BunsenLabs Forums now Open for Registration
· ↑ ↑ ↑ ↑ ↑ ↑ · BL ModSquad
Offline
Neat script
Weird wallpaper btw
BunsenLabs Group on deviantArt
damo's gallery on deviantArt
Openbox themes
Forum Moderator
Offline
Neat script
Weird wallpaper btw
Yea, I use that 'thelp' for a few things.
Wallpaper - made by a #! buddy. Good artist, maybe I'll introduce you some day.
· ↓ ↓ ↓ ↓ ↓ ↓ ·
BunsenLabs Forums now Open for Registration
· ↑ ↑ ↑ ↑ ↑ ↑ · BL ModSquad
Offline
Copyright © 2012 CrunchBang Linux.
Proudly powered by Debian. Hosted by Linode.
Debian is a registered trademark of Software in the Public Interest, Inc.
Server: acrobat