Skip to content

Commit 7fcc5fc

Browse files
author
Jon Vegard Venås
authored
Enhance/description of dict fields (#26)
For fields of elements of Dict type with keys of Resource type, only require description of the super-field (and set the resource in parentheses). Also remove redundant code.
1 parent df82dfe commit 7fcc5fc

2 files changed

Lines changed: 37 additions & 30 deletions

File tree

src/utils_GUI/GUI_utils.jl

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -403,7 +403,8 @@ function initialize_available_data!(gui)
403403
structure = String(nameof(typeof(element)))
404404
name = "$field_name"
405405
key_str = "structures.$structure.$name"
406-
add_description!(field, name, key_str, "", element, available_data, gui)
406+
selection = Vector{Any}([element])
407+
add_description!(field, name, key_str, "", selection, available_data, gui)
407408
end
408409
append!(get_available_data(gui)[element], available_data)
409410
end
@@ -539,10 +540,10 @@ function update_descriptive_names!(gui::GUI)
539540

540541
# Search through EMX packages if icons are available there
541542
for package emx_packages
542-
package_path::Union{String,Nothing} = Base.find_package(package)
543+
package_path::Union{String,Nothing} = dirname(dirname(Base.find_package(package)))
543544
if !isnothing(package_path)
544545
path_to_descriptive_names_ext = joinpath(
545-
package_path, "..", "..", "ext", "EMGUIExt", "descriptive_names.yml",
546+
package_path, "ext", "EMGUIExt", "descriptive_names.yml",
546547
)
547548
if isfile(path_to_descriptive_names_ext)
548549
descriptive_names_dict_ext_file = YAML.load_file(

src/utils_GUI/results_axis_utils.jl

Lines changed: 33 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ end
2727
name::String,
2828
key_str::String,
2929
pre_desc::String,
30-
element,
30+
selection::Vector,
3131
available_data::Vector{Dict},
3232
gui::GUI,
3333
)
@@ -39,14 +39,14 @@ function add_description!(
3939
name::String,
4040
key_str::String,
4141
pre_desc::String,
42-
element,
42+
selection::Vector,
4343
available_data::Vector{Dict},
4444
gui::GUI,
4545
)
4646
container = Dict(
4747
:name => name,
4848
:is_jump_data => false,
49-
:selection => [element],
49+
:selection => selection,
5050
:field_data => field,
5151
:description => create_description(gui, key_str; pre_desc),
5252
)
@@ -59,7 +59,7 @@ end
5959
name::String,
6060
key_str::String,
6161
pre_desc::String,
62-
element,
62+
selection::Vector,
6363
available_data::Vector{Dict},
6464
gui::GUI,
6565
)
@@ -72,15 +72,23 @@ function add_description!(
7272
name::String,
7373
key_str::String,
7474
pre_desc::String,
75-
element,
75+
selection::Vector,
7676
available_data::Vector{Dict},
7777
gui::GUI,
7878
)
7979
for (dictname, dictvalue) field
80-
name_field = "$name.$dictname"
81-
key_str_field = "$key_str.$dictname"
80+
name_field = "$name"
81+
key_str_field = "$key_str"
82+
ext_selection = deepcopy(selection)
83+
if isa(dictname, Resource)
84+
push!(ext_selection, dictname)
85+
else
86+
name_field *= ".$dictname"
87+
key_str_field *= ".$dictname"
88+
end
8289
add_description!(
83-
dictvalue, name_field, key_str_field, pre_desc, element, available_data, gui,
90+
dictvalue, name_field, key_str_field, pre_desc, ext_selection, available_data,
91+
gui,
8492
)
8593
end
8694
end
@@ -91,7 +99,7 @@ end
9199
name::String,
92100
key_str::String,
93101
pre_desc::String,
94-
element,
102+
selection::Vector,
95103
available_data::Vector{Dict},
96104
gui::GUI,
97105
)
@@ -104,7 +112,7 @@ function add_description!(
104112
name::String,
105113
key_str::String,
106114
pre_desc::String,
107-
element,
115+
selection::Vector,
108116
available_data::Vector{Dict},
109117
gui::GUI,
110118
)
@@ -113,7 +121,7 @@ function add_description!(
113121
name_field = "$name.$data_type"
114122
key_str_field = "$key_str.$data_type"
115123
add_description!(
116-
data, name_field, key_str_field, pre_desc, element, available_data, gui,
124+
data, name_field, key_str_field, pre_desc, selection, available_data, gui,
117125
)
118126
end
119127
end
@@ -137,7 +145,7 @@ function add_description!(
137145
name::String,
138146
key_str::String,
139147
pre_desc::String,
140-
element,
148+
selection::Vector,
141149
available_data::Vector{Dict},
142150
gui::GUI,
143151
)
@@ -153,7 +161,7 @@ function add_description!(
153161
pre_desc_sub = "$pre_desc$name_field_type: "
154162
key_str = "structures.$name_field_type.$sub_field_name"
155163
add_description!(
156-
sub_field, name_field, key_str, pre_desc_sub, element, available_data, gui,
164+
sub_field, name_field, key_str, pre_desc_sub, selection, available_data, gui,
157165
)
158166
end
159167
end
@@ -305,22 +313,20 @@ function create_label(selection::Dict{Symbol,Any})
305313
label *= selection[:name]
306314
end
307315
otherRes::Bool = false
308-
if length(selection) > 1
309-
for select selection[:selection]
310-
if isa(select, Resource)
311-
if !otherRes
312-
label *= " ("
313-
otherRes = true
314-
end
315-
label *= "$(select)"
316-
if select != selection[:selection][end]
317-
label *= ", "
318-
end
316+
for select selection[:selection]
317+
if isa(select, Resource)
318+
if !otherRes
319+
label *= " ("
320+
otherRes = true
321+
end
322+
label *= "$(select)"
323+
if select != selection[:selection][end]
324+
label *= ", "
319325
end
320326
end
321-
if otherRes
322-
label *= ")"
323-
end
327+
end
328+
if otherRes
329+
label *= ")"
324330
end
325331
return label
326332
end

0 commit comments

Comments
 (0)