add filename tooltip

This commit is contained in:
Daniel Weschke
2026-05-04 11:50:37 +02:00
parent 91b707a1ff
commit 874a8563d5
2 changed files with 23 additions and 13 deletions

34
app.py
View File

@@ -8,7 +8,7 @@ import datetime
try: try:
from nicegui import app, ui, events, Client, run from nicegui import app, ui, events, Client, run
except ModuleNotFoundError as e: except ModuleNotFoundError as e:
print('Module `nicegui` not found.') print(f'Error: {e}')
exit(1) exit(1)
try: try:
import plotly.graph_objects as pgo import plotly.graph_objects as pgo
@@ -18,7 +18,7 @@ try:
import local_file_picker import local_file_picker
import plotly_resampler as prs import plotly_resampler as prs
except ModuleNotFoundError as e: except ModuleNotFoundError as e:
print('Module `plotly` not found.') print(f'Error: {e}')
exit(1) exit(1)
pio.templates["plotly_light"] = pgo.layout.Template( pio.templates["plotly_light"] = pgo.layout.Template(
@@ -87,6 +87,19 @@ def np2pgo(x, y, label=None):
res.update({'name': label}) res.update({'name': label})
return res return res
def fntl():
if ELM['filename'] is not None:
return os.path.relpath(ELM['filename'], ELM['filedir'])
def fnttt():
res = None
if ELM['filename'] is not None:
fn = os.path.basename(ELM['filename'])
n = len(fn)
if n == 18:
res = f'{fn[:4]}-{fn[4:6]}-{fn[6:8]} {fn[8:10]}:{fn[10:12]}:{fn[12:14]}'
return res
async def pick_file() -> None: async def pick_file() -> None:
result = await local_file_picker.local_file_picker(ELM['filedir'], multiple=False) result = await local_file_picker.local_file_picker(ELM['filedir'], multiple=False)
# ui.notify(f'You chose {result}') # ui.notify(f'You chose {result}')
@@ -96,11 +109,6 @@ async def pick_file() -> None:
# see timer below, but still here active b/c the time might be inactive # see timer below, but still here active b/c the time might be inactive
ui.timer(0, lambda: update_data(), once=True) ui.timer(0, lambda: update_data(), once=True)
if filename is not None:
filename = os.path.relpath(filename, ELM['filedir'])
# filename = os.path.basename(filename)
ELM['label_file'].set_text(ELM['label_file_fmt'].format(filename=filename))
def get_data(filename=ELM['filename']): def get_data(filename=ELM['filename']):
data = None data = None
if filename is not None and os.path.isfile(filename): if filename is not None and os.path.isfile(filename):
@@ -238,11 +246,13 @@ def index():
).bind_value(app.storage.user, 'dark_mode').props('icon="dark_mode"') ).bind_value(app.storage.user, 'dark_mode').props('icon="dark_mode"')
with ui.row(): with ui.row():
filename = ELM['filename'] ELM['label_file'] = ui.label(ELM['label_file_fmt'].format(filename=fntl())) \
if filename is not None: .bind_text_from(ELM, 'filename',
filename = os.path.relpath(filename, ELM['filedir']) lambda filename: ELM['label_file_fmt'].format(filename=fntl()))
# filename = os.path.basename(filename) ELM['label_file_tt'] = ui.tooltip(None) \
ELM['label_file'] = ui.label(ELM['label_file_fmt'].format(filename=filename)) .bind_text_from(ELM, 'filename', lambda filename: fnttt()) \
.bind_visibility_from(ELM, 'filename', bool) \
.move(ELM['label_file'])
ELM['label_data_len'] = ui.label(ELM['label_data_len_fmt'].format(num=0, numa=0)) ELM['label_data_len'] = ui.label(ELM['label_data_len_fmt'].format(num=0, numa=0))
ELM['label_data_temp'] = ui.label(ELM['label_data_temp_fmt'].format(min=0, max=0)) ELM['label_data_temp'] = ui.label(ELM['label_data_temp_fmt'].format(min=0, max=0))
ELM['label_data_heat'] = ui.label(ELM['label_data_heat_fmt'].format(min=0, max=0)) ELM['label_data_heat'] = ui.label(ELM['label_data_heat_fmt'].format(min=0, max=0))

2
notes
View File

@@ -1,2 +1,2 @@
pip install numpy nicegui plotly kaleido pip install numpy nicegui plotly kaleido plotly-resampler pytz