edit menu file

This commit is contained in:
2019-01-30 10:45:10 +02:00
parent 1274f814e8
commit 4e9c703ce0

View File

@@ -1,19 +1,22 @@
#!/usr/bin/env python
import os
import sys
import subprocess
import termios
import tty
import readline
import math
import os
import readline
import subprocess
import sys
import termios
import time
import tty
readline.parse_and_bind('tab: complete')
readline.parse_and_bind('set editing-mode vi')
MENUFILE = '.foldermenu'
DEFAULTFILE = os.path.expanduser(os.path.join('~','.config','foldermenu','default'))
VERSION="0.4"
VERSION = "0.5"
DEBUG = False
def setup_options():
''' Setup the command line options '''
@@ -23,7 +26,8 @@ def setup_options():
"' file, and in addition the executables in the current folder. " +
"Menufile format for each line: 'description:command'. " +
"If the command ends in '&' it is run in the background. " +
"If the command ends in '/' it is a folder, and selecting will enter.")
"If the command ends in '/' it is a folder, and selecting will enter. " +
"Extra keyboard shortcuts: / Edit ")
parser.add_argument("-1","--one-shot",action = 'store_true', dest = 'once', default = False,
help = "Launch only once, then exit")
parser.add_argument("-b","--no-banner", action='store_false', dest='banner', default=True,
@@ -143,6 +147,7 @@ class entry_collection:
self.entries = []
self.dirs = []
self.banner = []
self.selected = -1
if self.options.defaults:
self.read_menu(DEFAULTFILE)
self.read_menu()
@@ -476,6 +481,21 @@ class entry_collection:
return
self.selected = new_value
def edit_menu(self):
subprocess.call(
"vim %s"%( MENUFILE, ),
stderr = subprocess.STDOUT,
shell = True,
executable = "/bin/bash"
)
self.initialize()
def debug_code_print(c):
print("- code: %d, str: %s -"%(
c,
str(c)
))
time.sleep(1)
def start_engines():
@@ -498,11 +518,16 @@ def start_engines():
while True:
entries.menu()
inkey = ord(ch.get())
#print('-'+str((inkey))+'-')
if DEBUG:
debug_code_print(inkey)
if inkey == 27:
inkey2 = ord(ch.get())
if DEBUG:
debug_code_print(inkey2)
if inkey2 == 91:
inkey3 = ord(ch.get())
if DEBUG:
debug_code_print(inkey3)
if inkey3 == 66:
entries.select_move(1)
if inkey3 == 65:
@@ -532,7 +557,9 @@ def start_engines():
readline.set_startup_hook(None)
if inkey == 46: # .
entries.flip_mode()
if inkey == 13:
if inkey == 47: # /
entries.edit_menu()
if inkey == 13: # enter
inkey = ord(entries.menu_keys[entries.selected])
found, message = entries.is_key(chr(inkey))
if found: