mb-kb update,icons
202
bin/mb-kb
@@ -3,149 +3,161 @@
|
||||
|
||||
# This script reads the keybinds configuration file ("$HOME/.config/openbox/rc.xml")
|
||||
# and writes them to a text file ("$HOME/.config/openbox/kbinds.txt").
|
||||
# The script is used by mb-kb-pipemenu to pipe the output to the Openbox menu, or to display keybinds in a separate window
|
||||
# The script is used by mb-kb-pipemenu to pipe the output to the Openbox menu,
|
||||
# or to display keybinds in a separate window.
|
||||
#
|
||||
# Based on a script by wlourf 07/03/2010
|
||||
# <http://u-scripts.blogspot.com/2010/03/how-to-display-openboxs-shortcuts.html>
|
||||
# http://u-scripts.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
|
||||
#
|
||||
# April 2015
|
||||
# : This script outputs the keyboard keybinds to terminal or, with
|
||||
# a "--gui" argument will display the output in a text window as well
|
||||
#
|
||||
# Written by damo <damo@bunsenlabs.org> for BunsenLabs Linux, April 2015
|
||||
#
|
||||
# Ported to Manjaro by napcok <napcok@gmail.com> March 2016
|
||||
#
|
||||
########################################################################
|
||||
#
|
||||
# ****If Openbox xml version changes then the xml root will need
|
||||
# changing as well (line 58)********
|
||||
#
|
||||
########################################################################
|
||||
import sys,os
|
||||
# Written by damo <damo@bunsenlabs.org> for BunsenLabs Linux, April 2015
|
||||
# Ported to Manjaro by napcok <napcok@gmail.com> March 2016
|
||||
# Fix (multi-action keybinds): prefer Execute over first action — musqz
|
||||
|
||||
import sys
|
||||
import 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=[]
|
||||
gui=False
|
||||
arrShortcut = []
|
||||
gui = False
|
||||
|
||||
|
||||
def cmdargs():
|
||||
"""get command arguments"""
|
||||
if len(sys.argv) > 1:
|
||||
if len(sys.argv) > 1:
|
||||
if sys.argv[1] == "--gui":
|
||||
gui=True
|
||||
return gui
|
||||
return True
|
||||
else:
|
||||
msg = "\n\n\tUSAGE: to display keybinds in a text window use 'mb-kb --gui &>/dev/null'\n\n"
|
||||
msg = msg + "\tRunning the script without args will send output to the terminal\n\n"
|
||||
msg = "\n\n\tUSAGE: to display keybinds in a text window use 'mb-kb --gui &>/dev/null'\n\n"
|
||||
msg += "\tRunning the script without args will send output to the terminal\n\n"
|
||||
print(msg)
|
||||
sys.exit()
|
||||
return False
|
||||
|
||||
|
||||
def keyboard():
|
||||
"""read keyboard shorcuts"""
|
||||
# Parse xml
|
||||
strRoot="{http://openbox.org/3.4/rc}"
|
||||
strRoot = "{http://openbox.org/3.4/rc}"
|
||||
tree = etree.parse(rc_fpath)
|
||||
root = tree.getroot()
|
||||
|
||||
for k in root.findall(strRoot+"keyboard/" + strRoot + "keybind"):
|
||||
for k in root.findall(strRoot + "keyboard/" + strRoot + "keybind"):
|
||||
key = k.get("key")
|
||||
action_element = k.find(strRoot+"action")
|
||||
strTxt=""
|
||||
strType="o " # flag for pipemenu: Openbox window command
|
||||
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")
|
||||
strType="x " # flag for pipemenu: Run command
|
||||
|
||||
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]=(strType,key,strTxt)
|
||||
# Collect ALL actions for this keybind (fixes multi-action entries like
|
||||
# Unmaximize + Execute where the old k.find() only saw the first one).
|
||||
actions = k.findall(strRoot + "action")
|
||||
if not actions:
|
||||
continue
|
||||
|
||||
def output_keybinds(arrShortcut,gui):
|
||||
"""loop through array, and format output then write to file"""
|
||||
for i in range(0,len(arrShortcut)):
|
||||
exe=str(arrShortcut[i][0])
|
||||
keybinding=str(arrShortcut[i][1])
|
||||
execute=str(arrShortcut[i][2])
|
||||
if gui: #format output for text window
|
||||
if len(execute)>80 :
|
||||
execute=execute[:75]+"....."
|
||||
line = "{:2}".format(i) + "\t" + "{:<16}".format(keybinding)\
|
||||
+ "\t" + execute
|
||||
else: #format text for pipemenu
|
||||
# Priority: Execute > MoveResizeTo > first action
|
||||
# This ensures tiling keybinds (Unmaximize + MoveResizeTo) show geometry
|
||||
# instead of the preceding window-state action.
|
||||
action_element = next(
|
||||
(a for a in actions if a.get("name") == "Execute"),
|
||||
next(
|
||||
(a for a in actions if a.get("name") == "MoveResizeTo"),
|
||||
actions[0]
|
||||
)
|
||||
)
|
||||
|
||||
strTxt = ""
|
||||
strType = "o "
|
||||
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")
|
||||
strType = "x "
|
||||
if name_element is not None:
|
||||
strTxt = name_element.text
|
||||
elif command_element is not None:
|
||||
strTxt = command_element.text
|
||||
elif exec_element is not None:
|
||||
strTxt = exec_element.text
|
||||
elif action_element.get("name") == "MoveResizeTo":
|
||||
parts = []
|
||||
for tag in ("x", "y", "width", "height"):
|
||||
el = action_element.find(strRoot + tag)
|
||||
if el is None:
|
||||
el = action_element.find(tag) # fallback: no namespace
|
||||
if el is not None and el.text:
|
||||
parts.append(tag + ":" + el.text.strip())
|
||||
strTxt = "MoveResizeTo " + " ".join(parts) if parts else "MoveResizeTo"
|
||||
elif action_element.get("name") == "ShowMenu":
|
||||
menu_element = action_element.find(strRoot + "menu")
|
||||
if menu_element is not None:
|
||||
strTxt = menu_element.text
|
||||
else:
|
||||
action_name = action_element.get("name")
|
||||
if action_name is not None:
|
||||
strTxt = action_name
|
||||
|
||||
arrShortcut[len(arrShortcut) - 1] = (strType, key, strTxt)
|
||||
|
||||
|
||||
def output_keybinds(arrShortcut, gui):
|
||||
for i in range(len(arrShortcut)):
|
||||
exe = str(arrShortcut[i][0])
|
||||
keybinding = str(arrShortcut[i][1])
|
||||
execute = str(arrShortcut[i][2])
|
||||
if gui:
|
||||
if len(execute) > 80:
|
||||
execute = execute[:75] + "....."
|
||||
line = "{:2}".format(i) + "\t" + "{:<16}".format(keybinding) \
|
||||
+ "\t" + execute
|
||||
else:
|
||||
line = exe + "{:<16}".format(keybinding) + "\t" + execute
|
||||
print(line)
|
||||
write_file(line)
|
||||
|
||||
def check_rcfile(fpath,mode):
|
||||
"""Check if rc.xml exists, and is accessible"""
|
||||
|
||||
def check_rcfile(fpath, mode):
|
||||
try:
|
||||
f = open(fpath,mode)
|
||||
except IOError as e:
|
||||
open(fpath, mode).close()
|
||||
except IOError:
|
||||
return False
|
||||
return True
|
||||
|
||||
|
||||
def write_file(line):
|
||||
"""Text file to store keybinds"""
|
||||
f = open(kb_fpath,'a')
|
||||
f.write(line + "\n")
|
||||
f.close()
|
||||
with open(kb_fpath, 'a') as f:
|
||||
f.write(line + "\n")
|
||||
|
||||
|
||||
def check_txtfile(kb_fpath):
|
||||
"""Create Text file to store keybinds"""
|
||||
try:
|
||||
f = open(kb_fpath,'w')
|
||||
except IOError as e:
|
||||
open(kb_fpath, 'w').close()
|
||||
except IOError:
|
||||
return False
|
||||
return True
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
gui=cmdargs()
|
||||
gui = cmdargs()
|
||||
check_txtfile(kb_fpath)
|
||||
if gui: # output formatted keybinds text in text window
|
||||
|
||||
if gui:
|
||||
write_file(str(datetime.date.today()) + "\trc.xml KEYBINDS")
|
||||
write_file("-------------------------------\n")
|
||||
|
||||
if check_rcfile(rc_fpath,"r"):
|
||||
if check_rcfile(rc_fpath, "r"):
|
||||
keyboard()
|
||||
output_keybinds(arrShortcut,gui)
|
||||
output_keybinds(arrShortcut, gui)
|
||||
else:
|
||||
msg = "\nCan't open rc.xml for parsing\n\
|
||||
Check the filepath given: " + rc_fpath + "\n"
|
||||
print(msg)
|
||||
print("\nCan't open rc.xml for parsing\n\tCheck the filepath: " + rc_fpath + "\n")
|
||||
sys.exit(1)
|
||||
|
||||
if gui: # output formatted keybinds text in text window
|
||||
dlg = "yad --text-info --title='Openbox Keybinds' "
|
||||
dlg = dlg + "--window-icon=distributor-logo-mabox "
|
||||
dlg = dlg + "--filename=$HOME/.config/openbox/kbinds.txt "
|
||||
dlg = dlg + "--width=700 --height=700 --fontname=Monospace "
|
||||
dlg = dlg + "--button=Close"
|
||||
if gui:
|
||||
dlg = "yad --text-info --title='Mabox Openbox Keybinds' "
|
||||
dlg += "--window-icon=distributor-logo-mabox --image=/usr/share/icons/mabox_trans_64.png "
|
||||
dlg += "--text '\n<b>Key bindings</b> are confugured in your <i>~/.config/openbox/rc.xml</i> file. <a href=\"http://openbox.org/help/Bindings\">docs</a>\n\t\t\t\t<b>S</b> - Shift key\n\t\t\t\t<b>C</b> - Control key\n\t\t\t\t<b>A</b> - Alt key\n\t\t\t\t<b>W</b> - Super key (usually bound to the Windows key)' "
|
||||
dlg += "--filename=$HOME/.config/openbox/kbinds.txt "
|
||||
dlg += "--width=640 --height=560 --fontname=Monospace "
|
||||
dlg += "--button='Edit rc.xml:geany " + rc_fpath + "' --button='Reload Openbox configuration:openbox --reconfigure' --button=Close"
|
||||
os.system(dlg)
|
||||
|
||||
|
||||
BIN
icons/hicolor/128x128/apps/mabox-logo-3d.png
Normal file
|
After Width: | Height: | Size: 9.6 KiB |
BIN
icons/hicolor/128x128/apps/mabox-logo-circle.png
Normal file
|
After Width: | Height: | Size: 3.7 KiB |
BIN
icons/hicolor/128x128/apps/mabox-logo-square.png
Normal file
|
After Width: | Height: | Size: 174 B |
BIN
icons/hicolor/16x16/apps/mabox-logo-3d.png
Normal file
|
After Width: | Height: | Size: 904 B |
BIN
icons/hicolor/16x16/apps/mabox-logo-circle.png
Normal file
|
After Width: | Height: | Size: 513 B |
BIN
icons/hicolor/16x16/apps/mabox-logo-square.png
Normal file
|
After Width: | Height: | Size: 154 B |
BIN
icons/hicolor/22x22/apps/mabox-logo-3d.png
Normal file
|
After Width: | Height: | Size: 1.4 KiB |
BIN
icons/hicolor/22x22/apps/mabox-logo-circle.png
Normal file
|
After Width: | Height: | Size: 714 B |
BIN
icons/hicolor/22x22/apps/mabox-logo-square.png
Normal file
|
After Width: | Height: | Size: 228 B |
BIN
icons/hicolor/24x24/apps/mabox-logo-3d.png
Normal file
|
After Width: | Height: | Size: 1.4 KiB |
BIN
icons/hicolor/24x24/apps/mabox-logo-circle.png
Normal file
|
After Width: | Height: | Size: 789 B |
BIN
icons/hicolor/24x24/apps/mabox-logo-square.png
Normal file
|
After Width: | Height: | Size: 211 B |
BIN
icons/hicolor/32x32/apps/mabox-logo-3d.png
Normal file
|
After Width: | Height: | Size: 2.0 KiB |
BIN
icons/hicolor/32x32/apps/mabox-logo-circle.png
Normal file
|
After Width: | Height: | Size: 942 B |
BIN
icons/hicolor/32x32/apps/mabox-logo-square.png
Normal file
|
After Width: | Height: | Size: 159 B |
BIN
icons/hicolor/48x48/apps/mabox-logo-3d.png
Normal file
|
After Width: | Height: | Size: 3.2 KiB |
BIN
icons/hicolor/48x48/apps/mabox-logo-circle.png
Normal file
|
After Width: | Height: | Size: 1.3 KiB |
BIN
icons/hicolor/48x48/apps/mabox-logo-square.png
Normal file
|
After Width: | Height: | Size: 163 B |
BIN
icons/hicolor/64x64/apps/mabox-logo-3d.png
Normal file
|
After Width: | Height: | Size: 4.5 KiB |
BIN
icons/hicolor/64x64/apps/mabox-logo-circle.png
Normal file
|
After Width: | Height: | Size: 1.8 KiB |
BIN
icons/hicolor/64x64/apps/mabox-logo-square.png
Normal file
|
After Width: | Height: | Size: 165 B |
BIN
icons/hicolor/96x96/apps/mabox-logo-3d.png
Normal file
|
After Width: | Height: | Size: 7.0 KiB |
BIN
icons/hicolor/96x96/apps/mabox-logo-circle.png
Normal file
|
After Width: | Height: | Size: 2.8 KiB |
BIN
icons/hicolor/96x96/apps/mabox-logo-square.png
Normal file
|
After Width: | Height: | Size: 172 B |
4
icons/hicolor/scalable/apps/mabox-logo-3d.svg
Normal file
@@ -0,0 +1,4 @@
|
||||
<svg xmlns="http://www.w3.org/2000/svg" width="1350" height="1350">
|
||||
<path fill="#F8F8FF" fill-opacity="1" d="m675.469 35.245-581.09 189.03 573.45 260.3 592.67-257.6Zm-213.776 133.16 426.42 8.963 18.258 174.98-474.193-.484zm12.086 12.408-22.95 159.87 438.91.56-16.76-153.299zm21.08 11.274 358.641 4.838 13.082 132.39-105.23-.058-3.8-99.654-31.413-.43 2.537 99.586-105.367-.024 4.232-99.35-30.318.237-9.194 99.297-113.021.037zM65.098 253.454s43.103 463.121 65.154 694.621c175.89 115.17 351.351 231.05 526.951 346.68l-8.725-774.42c-3.242-2.767-582.7-267.85-583.38-266.88Zm1215.804 5.781c0-.03-588.8 263.04-588.8 263.04s-2.279 771.42.445 772.48l523.742-344.43ZM101.086 323.19l503.76 235.5s4.76 663.97 4.056 663.58l-134.884-88.175s-12.32-302.85-17.327-453.86l-39.154-17.644 13.867 443.039c-1.841-.542-123.63-79.893-123.63-79.893l-28.112-427.64-31.494-14.84 23.963 415.01c.133 2.314-112.08-69.5-112.15-70.137zm1141.713 3.334s-33.266 401.952-51.188 602.782c-39.452 21.937-116.5 70.802-116.5 70.802l24.7-426.73-33.282 17.209s-18.493 291.631-28.556 437.361l-125.27 76.008 14.895-440.77-38.659 20.077-17.689 451.68-140.31 87.831c-1.678-139.65 9.001-663.87 9.001-663.87l-.004-.009z"/>
|
||||
<path fill="#32B557" fill-opacity="1" d="M122.026 956.98C105.255 801.33 102.813 778.14 50 228.92L676.71 22.64 1300 225.42l-69.336 733.18-557.89 368.76zm526.96-437.21c-3.242-2.767-582.7-267.85-583.38-266.88 0 0 43.103 463.12 65.154 694.62 175.89 115.17 351.35 231.05 526.95 346.68zm-174.46 613.76s-12.32-302.85-17.326-453.86l-39.155-17.644 13.867 443.04c-1.842-.541-123.63-79.894-123.63-79.894l-28.113-427.64-31.494-14.84 23.964 415.01c.134 2.314-112.08-69.499-112.15-70.137l-58.895-604.94 503.76 235.5s4.758 663.97 4.055 663.58zm742.27-183.77 64.614-691.09c0-.03-588.8 263.04-588.8 263.04s-2.28 771.42.444 772.48zm-476.35-391.43 502.86-232.37s-33.266 401.95-51.188 602.78c-39.452 21.937-116.5 70.803-116.5 70.803l24.7-426.73-33.281 17.21s-18.494 291.63-28.557 437.36l-125.27 76.008 14.896-440.77-38.658 20.077-17.691 451.68-140.31 87.831c-1.677-139.65 9.002-663.87 9.002-663.87zm520.56-331.92L675.976 34.68 94.886 223.71l573.45 260.3zM432.686 351.3l29.515-183.46 426.42 8.963 18.257 174.98zm440.8-163.92-399.2-7.131-22.951 159.87 438.91.559zm-249.67 140.79 4.232-99.35-30.318.238-9.194 99.296-113.02.038 19.851-136.87 358.64 4.838 13.082 132.39-105.23-.057-3.798-99.655-31.414-.43 2.536 99.585z"/>
|
||||
</svg>
|
||||
|
After Width: | Height: | Size: 2.3 KiB |
4
icons/hicolor/scalable/apps/mabox-logo-circle.svg
Normal file
@@ -0,0 +1,4 @@
|
||||
<svg width="512" height="512" viewBox="0 0 135.467 135.467">
|
||||
<path fill="#32B557" fill-opacity="1" d="M67.733.927A66.806 66.806 0 0 0 .927 67.733a66.806 66.806 0 0 0 66.806 66.807 66.806 66.806 0 0 0 66.807-66.807A66.806 66.806 0 0 0 67.733.927Zm0 12.282a54.524 54.524 0 0 1 54.525 54.524 54.524 54.524 0 0 1-54.525 54.525A54.524 54.524 0 0 1 13.21 67.733 54.524 54.524 0 0 1 67.733 13.21ZM38.1 38.1v59.267h16.933V55.033h4.234v42.334H76.2V55.033h4.233v42.334h16.934V38.1Z"/>
|
||||
<path fill="#F8F8FF" fill-opacity="1" d="M67.733 13.209A54.524 54.524 0 0 0 13.21 67.733a54.524 54.524 0 0 0 54.524 54.525 54.524 54.524 0 0 0 54.525-54.525A54.524 54.524 0 0 0 67.733 13.21ZM38.1 38.1h59.267v59.267H80.433V55.033H76.2v42.334H59.267V55.033h-4.234v42.334H38.1Z"/>
|
||||
</svg>
|
||||
|
After Width: | Height: | Size: 760 B |
4
icons/hicolor/scalable/apps/mabox-logo-square.svg
Normal file
@@ -0,0 +1,4 @@
|
||||
<svg xmlns="http://www.w3.org/2000/svg" width="256" height="256">
|
||||
<path fill="#F8F8FF" fill-opacity="1" d="M0 0v256h256V0Zm16 16h224v224h-64V80h-16v160H96V80H80v160H16Z"/>
|
||||
<path fill="#32B557" fill-opacity="1" d="M80 240H16V16h224v224h-64V80h-16v160H96V80H80z"/>
|
||||
</svg>
|
||||
|
After Width: | Height: | Size: 274 B |