add empty buttons
This commit is contained in:
@@ -65,9 +65,13 @@ def config_load():
|
|||||||
|
|
||||||
class Button(Div):
|
class Button(Div):
|
||||||
command = None
|
command = None
|
||||||
|
empty = None
|
||||||
def __init__(self, **kwargs):
|
def __init__(self, **kwargs):
|
||||||
super().__init__(**kwargs)
|
super().__init__(**kwargs)
|
||||||
self.classes = "bg-gray-800 hover:bg-gray-700 text-gray-500 w-20 h-20 m-2 p-1 rounded-lg font-bold flex items-center text-center justify-center select-none"
|
if self.empty:
|
||||||
|
self.classes = "w-20 h-20 m-2 p-1 flex select-none"
|
||||||
|
else:
|
||||||
|
self.classes = "bg-gray-800 hover:bg-gray-700 text-gray-500 w-20 h-20 m-2 p-1 rounded-lg font-bold flex items-center text-center justify-center select-none"
|
||||||
if self.command is not None:
|
if self.command is not None:
|
||||||
def click(self, msg):
|
def click(self, msg):
|
||||||
print(self.command)
|
print(self.command)
|
||||||
@@ -142,6 +146,7 @@ def application(request):
|
|||||||
button_dict = {}
|
button_dict = {}
|
||||||
for i in config.sections():
|
for i in config.sections():
|
||||||
iname = None
|
iname = None
|
||||||
|
# volume buttons
|
||||||
iname = search("^([0-9]*.?)volume", i, flags=IGNORECASE)
|
iname = search("^([0-9]*.?)volume", i, flags=IGNORECASE)
|
||||||
if iname is not None:
|
if iname is not None:
|
||||||
id = iname.group(1)[:-1] # remove dot
|
id = iname.group(1)[:-1] # remove dot
|
||||||
@@ -153,10 +158,11 @@ def application(request):
|
|||||||
volume_dict[id] += tmp
|
volume_dict[id] += tmp
|
||||||
except KeyError:
|
except KeyError:
|
||||||
volume_dict[id] = tmp
|
volume_dict[id] = tmp
|
||||||
|
# button
|
||||||
iname = search("^([0-9]*.?)button", i, flags=IGNORECASE)
|
iname = search("^([0-9]*.?)button", i, flags=IGNORECASE)
|
||||||
if iname is not None:
|
if iname is not None:
|
||||||
id = iname.group(1)[:-1] # remove dot
|
id = iname.group(1)[:-1] # remove dot
|
||||||
tmp = [{'text': i[iname.end(0)+1:],
|
tmp = [{'type': 'normal', 'text': i[iname.end(0)+1:],
|
||||||
'color-bg': config.get(i, 'color-bg', fallback=''),
|
'color-bg': config.get(i, 'color-bg', fallback=''),
|
||||||
'color-fg': config.get(i, 'color-fg', fallback=''),
|
'color-fg': config.get(i, 'color-fg', fallback=''),
|
||||||
'command': config.get(i, 'command', fallback=None),
|
'command': config.get(i, 'command', fallback=None),
|
||||||
@@ -165,6 +171,15 @@ def application(request):
|
|||||||
button_dict[id] += tmp
|
button_dict[id] += tmp
|
||||||
except KeyError:
|
except KeyError:
|
||||||
button_dict[id] = tmp
|
button_dict[id] = tmp
|
||||||
|
# empty
|
||||||
|
iname = search("^([0-9]*.?)empty", i, flags=IGNORECASE)
|
||||||
|
if iname is not None:
|
||||||
|
id = iname.group(1)[:-1] # remove dot
|
||||||
|
tmp = [{'type': 'empty', 'text': i[iname.end(0)+1:]}]
|
||||||
|
try:
|
||||||
|
button_dict[id] += tmp
|
||||||
|
except KeyError:
|
||||||
|
button_dict[id] = tmp
|
||||||
var_prefix = "_div"
|
var_prefix = "_div"
|
||||||
for i in volume_dict:
|
for i in volume_dict:
|
||||||
var = var_prefix+i
|
var = var_prefix+i
|
||||||
@@ -178,11 +193,14 @@ def application(request):
|
|||||||
for i in button_dict:
|
for i in button_dict:
|
||||||
var = var_prefix+i
|
var = var_prefix+i
|
||||||
for j in button_dict[i]:
|
for j in button_dict[i]:
|
||||||
color_bg = f"background-color:{j['color-bg']};" if ishexcolor(j['color-bg']) else ''
|
if j['type'] == 'normal':
|
||||||
color_fg = f"color:{j['color-fg']};" if ishexcolor(j['color-fg']) else ''
|
color_bg = f"background-color:{j['color-bg']};" if ishexcolor(j['color-bg']) else ''
|
||||||
|
color_fg = f"color:{j['color-fg']};" if ishexcolor(j['color-fg']) else ''
|
||||||
if var not in vars():
|
if var not in vars():
|
||||||
vars()[var] = Div(classes="flex flex-wrap", a=wp)
|
vars()[var] = Div(classes="flex flex-wrap", a=wp)
|
||||||
if j['icon'] is not None:
|
if j['type'] == 'empty':
|
||||||
|
Button(empty=True, a=eval(var))
|
||||||
|
elif 'icon' in j and j['icon'] is not None:
|
||||||
Button(inner_html=f"<i class='fa-2x {j['icon']}'><i>",
|
Button(inner_html=f"<i class='fa-2x {j['icon']}'><i>",
|
||||||
style = color_bg + color_fg,
|
style = color_bg + color_fg,
|
||||||
command=j['command'], a=eval(var))
|
command=j['command'], a=eval(var))
|
||||||
|
|||||||
Reference in New Issue
Block a user