Skip to content

Commit 55019bb

Browse files
committed
Add file input instead of text field
- The previous text field in the GUI toolbar was replaced by a VFileInput object, which enables searching for the files locally. Thus, a validation of the entered .dat path is not required anymore. Moreover, the VFileInput object is currently designed to only search for .dat files. - The corresponding file objects do not contain the full local path (not possible due to security reasons). Therefore, we now store the .dat file name, its file lines, its size and the last modified data as state variables to match the new file input structure. Nonetheless, the user can see the full file path when clicking on the VFileInput object. - Improved docstring documentation of several functions.
1 parent 6eb07e0 commit 55019bb

File tree

5 files changed

+798
-613
lines changed

5 files changed

+798
-613
lines changed

src/fourc_webviewer/gui_utils.py

Lines changed: 91 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,104 @@
66
if CLIENT_TYPE == "vue2":
77
from trame.widgets import vuetify2 as vuetify
88
from trame.ui.vuetify2 import SinglePageWithDrawerLayout
9+
from trame_vuetify.widgets.vuetify import HtmlElement
910
else:
1011
from trame.widgets import vuetify3 as vuetify
1112
from trame.ui.vuetify3 import SinglePageWithDrawerLayout
13+
from trame_vuetify.widgets.vuetify3 import HtmlElement
1214
from trame.widgets import html, plotly, vtk
1315

1416

17+
class VFileInput(HtmlElement):
18+
"""Custom VFileInput element, since the one provided by trame does not currently support all relevant attributes, such as e.g. 'accept'.
19+
"""
20+
21+
22+
def __init__(self, children=None, **kwargs):
23+
super().__init__("v-file-input", children, **kwargs)
24+
self._attr_names += [
25+
"accept",
26+
"append_icon",
27+
"append_outer_icon",
28+
"autofocus",
29+
"background_color",
30+
"chips",
31+
"clear_icon",
32+
"clearable",
33+
"color",
34+
"counter",
35+
"counter_size_string",
36+
"counter_string",
37+
"counter_value", # JS functions unimplemented
38+
"dark",
39+
"dense",
40+
"disabled",
41+
"error",
42+
"error_count",
43+
"error_messages",
44+
"filled",
45+
"flat",
46+
"full_width",
47+
"height",
48+
"hide_details",
49+
"hide_input",
50+
"hide_spin_buttons",
51+
"hint",
52+
"id",
53+
"label",
54+
"light",
55+
"loader_height",
56+
"loading",
57+
"messages",
58+
"multiple",
59+
"outlined",
60+
"persistent_hint",
61+
"persistent_placeholder",
62+
"placeholder",
63+
"prefix",
64+
"prepend_icon",
65+
"prepend_inner_icon",
66+
"reverse",
67+
"rounded",
68+
"rules",
69+
"shaped",
70+
"show_size",
71+
"single_line",
72+
"small_chips",
73+
"solo",
74+
"solo_inverted",
75+
"success",
76+
"success_messages",
77+
"suffix",
78+
"truncate_length",
79+
"type",
80+
"validate_on_blur",
81+
"value",
82+
]
83+
self._event_names += [
84+
"blur",
85+
"change",
86+
"click",
87+
("click_append", "click:append"),
88+
("click_append_outer", "click:append-outer"),
89+
("click_clear", "click:clear"),
90+
("click_prepend", "click:prepend"),
91+
("click_prepend_inner", "click:prepend-inner"),
92+
"focus",
93+
"input",
94+
"keydown",
95+
"mousedown",
96+
"mouseup",
97+
("update_error", "update:error"),
98+
]
99+
15100
def _toolbar(server_controller):
16-
vuetify.VTextField(label=".dat file", v_model=("DAT_PATH",))
101+
VFileInput(
102+
label=".dat file",
103+
v_model=("INPUT_FILE",),
104+
update_modelValue="flushState('INPUT_FILE')",
105+
accept = ".dat"
106+
)
17107
vuetify.VBtn(
18108
text="CONVERT",
19109
v_show=("VTU_PATH == ''",),

src/fourc_webviewer/input_file_utils/dat_file_visualization.py

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88

99
from fourc_webviewer.input_file_utils.read_dat_file import (
1010
add_dat_file_data_to_dis,
11-
validate_dat_file_path,
1211
)
1312
from pathlib import Path
1413

@@ -28,9 +27,6 @@ def convert_to_vtu(dat_file_path, temp_dir):
2827
Path(temp_dir) / f"{os.path.splitext(os.path.basename(dat_file_path))[0]}.vtu"
2928
)
3029

31-
# validate the provided .dat file path
32-
validate_dat_file_path(dat_file_path)
33-
3430
# convert dat file to vtu file and return the path to the vtu file
3531
try:
3632
dis = lnmmeshio.read(dat_file_path)

0 commit comments

Comments
 (0)