working slider

This commit is contained in:
2023-12-24 00:34:46 +01:00
parent 6d502ea67e
commit 7c3cd04c1b
2 changed files with 56 additions and 9 deletions

View File

@@ -277,8 +277,14 @@ class Slider(Div):
self.wtype = 'slider' # slider (atm the only option) self.wtype = 'slider' # slider (atm the only option)
self.name = '' # id name self.name = '' # id name
self.description = '' # badge name self.description = '' # badge name
self.command = '' # command to run on click
self.state_command = '' # command to check the current state
self.min = float(kwargs.pop('min', 0))
self.max = float(kwargs.pop('max', 100))
self.step = float(kwargs.pop('step', 1))
super().__init__(**kwargs) super().__init__(**kwargs)
self.icon = self.icon if self.icon else 'tune'
self.style = "width:286px;" # three buttons and the two spaces self.style = "width:286px;" # three buttons and the two spaces
self.cmdl_toggle = '' # cmd for the button left self.cmdl_toggle = '' # cmd for the button left
@@ -286,8 +292,11 @@ class Slider(Div):
# local vars # local vars
badge_name = self.description if self.description else self.name badge_name = self.description if self.description else self.name
value = 0 value = self.min
if self.state_command:
value = float(process(self.state_command, shell=True))
# 1st row; badge
badge = QBadge( badge = QBadge(
text=badge_name, text=badge_name,
outline=True, outline=True,
@@ -300,24 +309,40 @@ class Slider(Div):
a=badge, text=badge_name, delay=500, anchor='center left', a=badge, text=badge_name, delay=500, anchor='center left',
offset=[0, 14], transition_show='jump-right', transition_hide='jump-left') offset=[0, 14], transition_show='jump-right', transition_hide='jump-left')
tt.self='center left' tt.self='center left'
# 2nd row; icon and slider
item = QItem( item = QItem(
a=self, a=self,
dense=True, # dense: less spacing: vertical little higher dense=True, # dense: less spacing: vertical little higher
) )
# left icon
item_section = QItemSection( item_section = QItemSection(
side=True, # side=True unstreched btn side=True, # side=True unstreched btn
a=item, a=item,
) )
QIcon(
name=self.icon,
color=COLOR_PRIME_TEXT,
left=True,
a=item_section,
)
# right slider
item_section2 = QItemSection(a=item) item_section2 = QItemSection(a=item)
def handle_slider(widget_self, msg): def handle_slider(widget_self, msg):
# process(cmdl_value.format(name=self.name,value=msg.value), shell=True, output=False) if '{value}' in self.command:
pass if DEBUG:
print("[sld] command:", self.command.format(value=msg.value))
process(self.command.format(value=msg.value), shell=True, output=False)
else:
if DEBUG:
print("[sld] command:", self.command)
self.slider = QSlider( self.slider = QSlider(
value=value, value=value,
min=0, min=self.min,
max=100, max=self.max,
step=5, step=self.step,
label=True, label=True,
a=item_section2, a=item_section2,
input=handle_slider, input=handle_slider,
@@ -327,7 +352,7 @@ class Slider(Div):
# TODO: toggle? # TODO: toggle?
def is_toggled(self): def is_toggled(self):
self.toggled = not self.toggled # self.toggled = not self.toggled
return self.toggled return self.toggled
class Volume(Div): class Volume(Div):
@@ -382,6 +407,7 @@ class Volume(Div):
volume_level = float(self.pa_state['volume']['mono']['value_percent'][:-1]) # remove the % sign volume_level = float(self.pa_state['volume']['mono']['value_percent'][:-1]) # remove the % sign
# TODO: ? indicator if stream is stereo or mono ? # TODO: ? indicator if stream is stereo or mono ?
# 1st row; badge
badge = QBadge( badge = QBadge(
text=badge_name, text=badge_name,
outline=True, outline=True,
@@ -394,16 +420,19 @@ class Volume(Div):
a=badge, text=badge_name, delay=500, anchor='center left', a=badge, text=badge_name, delay=500, anchor='center left',
offset=[0, 14], transition_show='jump-right', transition_hide='jump-left') offset=[0, 14], transition_show='jump-right', transition_hide='jump-left')
tt.self='center left' tt.self='center left'
# 2nd row; icon and slider
item = QItem( item = QItem(
a=self, a=self,
dense=True, # dense: less spacing: vertical little higher dense=True, # dense: less spacing: vertical little higher
) )
# left icon
item_section = QItemSection( item_section = QItemSection(
side=True, # side=True unstreched btn, side=True, # side=True unstreched btn,
#avatar=True, # more spacing than side #avatar=True, # more spacing than side
a=item, a=item,
) )
# QIcon(name="volume_up", a=item_section)
def handle_btn(widget_self, msg): def handle_btn(widget_self, msg):
# not checking the current state # not checking the current state
process(cmdl_toggle.format(name=self.name), shell=True, output=False) process(cmdl_toggle.format(name=self.name), shell=True, output=False)
@@ -424,6 +453,8 @@ class Volume(Div):
color=COLOR_PRIME_TEXT, color=COLOR_PRIME_TEXT,
click=handle_btn, click=handle_btn,
) )
# right slider
item_section2 = QItemSection(a=item) item_section2 = QItemSection(a=item)
def handle_slider(widget_self, msg): def handle_slider(widget_self, msg):
process(cmdl_value.format(name=self.name,value=msg.value), shell=True, output=False) process(cmdl_value.format(name=self.name,value=msg.value), shell=True, output=False)
@@ -597,6 +628,12 @@ def widget_load(config) -> dict:
'type': wid_type, 'type': wid_type,
'name': wid_name, 'name': wid_name,
'description': config.get(i, 'description', fallback=''), 'description': config.get(i, 'description', fallback=''),
'icon': config.get(i, 'icon', fallback=''),
'command': config.get(i, 'command', fallback=''),
'state-command': config.get(i, 'state-command', fallback=''),
'min': config.get(i, 'min', fallback=''),
'max': config.get(i, 'max', fallback=''),
'step': config.get(i, 'step', fallback=''),
}] }]
elif wid_type == 'sink': elif wid_type == 'sink':
# volume sliders # volume sliders
@@ -994,6 +1031,9 @@ async def application(request):
j['widget-class']( j['widget-class'](
name=j['name'], description=j['description'], name=j['name'], description=j['description'],
wtype=j['type'], wtype=j['type'],
icon=j['icon'],
command=j['command'], state_command=j['state-command'],
min=j['min'], max=j['max'], step=j['step'],
a=eval(var)) a=eval(var))
elif j['widget-class'] == Volume: elif j['widget-class'] == Volume:
j['widget-class']( j['widget-class'](

View File

@@ -42,7 +42,7 @@
# command-alt = optinal back-switch command(s) to run: shell command ... # command-alt = optinal back-switch command(s) to run: shell command ...
# state-alt = string to define the alternative state (pressed) # state-alt = string to define the alternative state (pressed)
# state-command = command to get the state: shell command ... # state-command = command to get the state: shell command ...
# icon = add icon in front of NAME (Font Awesome), e.g. fas fa-play # icon = add icon in front of NAME, e.g. fas fa-play
# icon-alt = optional alternative icon # icon-alt = optional alternative icon
# image = absolte path to image file (svg, png) # image = absolte path to image file (svg, png)
# image-alt = optional alternative absolue path to image file # image-alt = optional alternative absolue path to image file
@@ -52,6 +52,13 @@
# : N. optional group/row specification # : N. optional group/row specification
# : NAME id, name of the button # : NAME id, name of the button
# description = text for the slider # description = text for the slider
# icon = add icon in front of slider, e.g. tune
# min = minimum int value, e.g. 0
# max = maximum int value, e.g. 100
# step = step size, e.g. 1
# state-command = command to get the state: shell command
# command = command to run to get the value, using {value} in the command to
# interpolate the value: shell command
[default] [default]
host = 0.0.0.0 host = 0.0.0.0