-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDGUI.tcl
More file actions
2786 lines (2427 loc) · 115 KB
/
DGUI.tcl
File metadata and controls
2786 lines (2427 loc) · 115 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#######################################################################################################################
### A Decent DE1 app plugin that provides a skin-independent, themable, page-oriented GUI "mini framework".
#######################################################################################################################
namespace eval ::plugins::DGUI {
variable author "Enrique Bengoechea"
variable contact "enri.bengoechea@gmail.com"
variable version 1.02
variable name [translate "Describe GUI"]
variable github_repo ebengoechea/de1app_plugin_DGUI
variable description [translate "A skin-independent, \"themable\", GUI \"mini framework\" for skin and plugin writters.
Simplify page creation, auto-adapt aspect to current skin/theme, ready-made widget combos and full-page field editors."]
variable pages {}
# Aspect variables. Initialized here to default (Insight light theme), which is used if there's not a
# ::plugins::DGUI::setup_aspect_<skin> proc available.
variable page_bg_image {}
# button 1 is medium-size button for done/cancel actions
variable button1_img {}
variable button1_width 220
variable button1_height 140
# button 2 is big-size button for icon+explanation actions (such as "Calc EY from TDS")
variable button2_img {}
variable button2_width 384
variable button2_height 192
# button 3 is usual Ok button in Insight (245 x 65)
variable button3_img {}
variable button3_width 490
variable button3_height 120
variable button_font "font"
variable button_font_fill "#ffffff"
variable button_fill "#c0c5e3"
variable bg_color {}
variable font_color {}
variable default_shot_desc_font_color {#206ad4}
variable page_title_color {}
variable remark_color {}
variable error_color {}
variable disabled_color {}
variable highlight_color {}
variable insert_bg_color {}
variable font {}
variable font_size 7
variable header_font "font"
variable header_font_size 11
variable section_font_size 10
variable button_font "font"
variable button_font_fill "#ffffff"
variable button_fill white
variable entry_relief sunken
variable entry_bg_color "#ffffff"
variable listbox_relief sunken
variable listbox_bwidth 1
variable listbox_fg "#ffffff"
variable listbox_sfg ""
variable listbox_bg ""
variable listbox_sbg "#ffffff"
variable listbox_sbwidth 1
variable listbox_hthickness 1
variable listbox_hcolor "#ffffff"
variable scrollbar_bwidth 0
variable scrollbar_relief flat
variable scrollbar_bg $font_color
variable scrollbar_fg "#FFFFFF"
variable scrollbar_troughcolor $bg_color
variable scrollbar_hthickness 0
# Symbols in Fontawesome regular, see https://fontawesome.com/icons?d=gallery
variable symbols
array set symbols {
square "\uf0c8"
square_check "\uf14a"
sort_down "\uf0dd"
star "\uf005"
half_star "\uf089"
chevron_left "\uf053"
chevron_double_left "\uf323"
arrow_to_left "\uf33e"
chevron_right "\uf054"
chevron_double_right "\uf324"
arrow_to_right "\uf340"
eraser "\uf12d"
eye "\uf06e"
}
# Used to map booleans to their checkbox representation (square/square_check) in fontawesome.
variable checkbox_symbols_map {"\uf0c8" "\uf14a"}
# DATA DICTIONARY CONVENTIONS:
# * The column name in the shot table or the lookup table must be identical to the array item key.
# * The shot_field is the variable name in the shot file, settings section. May not match the array item key in
# cases like 'other_equipment'.
# * desc_section has to be one of bean, bean_batch, equipment, extraction or people.
# * data_type has to be one of text, long_text, category, numeric or date.
variable field_lookup_whats {name name_plural short_name short_name_plural \
desc_section db_table lookup_table db_type_column1 db_type_column2 shot_field data_type \
min_value max_value n_decimals default_value small_increment big_increment
}
variable data_dictionary
array set data_dictionary {
profile_title {"Profile" "Profiles" "Profile" "Profiles" \
"" shot "" "" "" profile_title category 0 0 0}
bean_desc {"Beans" "Beans" "Beans" "Beans" \
bean V_shot "" "" "" bean_brand||bean_type category 0 0 0}
bean_brand {"Beans roaster" "Beans roasters" "Roaster" "Roasters" \
bean shot "" "" "" bean_brand category 0 0 0}
bean_type {"Beans type" "Beans types" "Name" "Names" \
bean shot "" "" "" bean_type category 0 50 0}
bean_notes {"Beans notes" "Beans notes" "Note" "Notes" \
bean_batch shot "" "" "" bean_notes long_text 0 1000 0}
roast_date {"Roast date" "Roast dates" "Date" "Dates" \
bean_batch shot "" "" "" roast_date date 0 0 0}
roast_level {"Roast level" "Roast levels" "Level" "Levels" \
bean_batch shot "" "" "" roast_level category 0 50 0}
grinder_model {"Grinder name" "Grinder names" "Grinder" "Grinders" \
equipment shot "" "" "" grinder_model category 0 100 0}
grinder_setting {"Grinder setting" "Grinder settings" "Setting" "Settings" \
equipment shot "" "" "" grinder_setting category 0 100 0}
grinder_dose_weight {"Dose weight" "Dose weights" "Dose" "Doses" \
extraction shot "" "" "" grinder_dose_weight numeric 0 30 1 18 0.1 1.0}
drink_weight {"Drink weight" "Drink weights" "Weight" "Weights" \
extraction shot "" "" "" drink_weight numeric 0 500 1 36 1.0 10.0}
drink_tds {"Total Dissolved Solids (TDS %)" "Total Dissolved Solids %" "TDS" "TDS" \
extraction shot "" "" "" drink_tds numeric 0 15 2 8 0.01 0.1}
drink_ey {"Extraction Yield (EY %)" "Extraction Yields %" "EY" "EYs" \
extraction shot "" "" "" drink_ey numeric 0 30 2 20 0.1 1.0}
espresso_enjoyment {"Enjoyment (0-100)" "Enjoyments" "Enjoyment" "Enjoyment" \
extraction shot "" "" "" espresso_enjoyment numeric 0 100 0 50 1 10}
espresso_notes {"Notes" "Notes" "Notes" "Notes" \
extraction shot "" "" "" espresso_notes long_text 0 1000 0}
my_name {"Barista" "Baristas" "Barista" "Baristas" \
people shot "" "" "" my_name category 0 100 0 people}
drinker_name {"Drinker" "Drinkers" "Drinker" "Drinkers" \
people shot "" "" "" drinker_name category 0 100 0}
skin {"Skin" "Skins" "Skin" "Skins" \
"" shot "" "" "" skin category 0 0 0}
beverage_type {"Beverage type" "Beverage types" "Bev type" "Bev types" \
"" shot "" "" "" beverage_type category 0 0 0}
repository_links {"Repository link" "Repository links" "Repo link" "Repo links" \
"" "" "" "" "" repository_links "array" 0 0 0}
}
namespace export field_lookup field_names get_font set_symbols value_or_default \
args_add_option_if_not_exists args_remove_option args_has_option args_get_option args_get_prefixed \
set_previous_page enable_or_disable_widgets enable_widgets disable_widgets \
show_or_hide_widgets show_widgets hide_widgets add_page add_cancel_button add_button1 add_button2 \
add_button add_text add_symbol add_variable add_entry add_select_entry add_multiline_entry \
relocate_dropdown_arrows set_scrollbars_dims relocate_text_wrt ensure_size \
add_listbox listbox_get_sellection listbox_set_sellection add_checkbox add_rating draw_rating horizontal
}
proc ::plugins::DGUI::main {} {
msg "Starting the 'Describe GUI' plugin"
foreach ns {IS NUME TXT} { ::plugins::DGUI::${ns}::setup_ui }
}
proc ::plugins::DGUI::preload {} {
if { ![info exists ::debugging] } { set ::debugging 0 }
set skin $::settings(skin)
set skin_src_fn "[plugin_directory]/DGUI/setup_${skin}.tcl"
if { [file exists $skin_src_fn] } {
source $skin_src_fn
} else {
source "[plugin_directory]/DGUI/setup_Insight.tcl"
}
setup_aspect
# No settings page for this plugin
return ""
}
proc ::plugins::DGUI::msg { {flag ""} args } {
if { [string range $flag 0 0] eq "-" && [llength $args] > 0 } {
::logging::default_logger $flag "::plugins::DGUI" {*}$args
} else {
::logging::default_logger "::plugins::DGUI" $flag {*}$args
}
}
# Setup the general aspect parameters (colors, fonts etc.) depending on the skin used.
proc ::plugins::DGUI::setup_aspect { } {
load_font fontawesome_reg_big "[homedir]/fonts/Font Awesome 5 Pro-Regular-400.otf" 55
load_font fontawesome_reg_medium "[homedir]/fonts/Font Awesome 5 Pro-Regular-400.otf" 40
load_font fontawesome_reg_small "[homedir]/fonts/Font Awesome 5 Pro-Regular-400.otf" 24
set skin $::settings(skin)
if { [namespace which -command "::plugins::DGUI::setup_aspect_$skin"] ne "" } {
::plugins::DGUI::setup_aspect_$skin
} else {
::plugins::DGUI::setup_aspect_Insight
}
}
# Skin-independent font selection. A wrapper to either ::get_font in utils.tcl, or a skin-specific font management
# function.
proc ::plugins::DGUI::get_font { {font_name {}} {size {}} } {
variable font
variable font_size
if { $font_name eq "" } { set font_name $font }
if { $size eq "" } { set size $font_size }
if { $::settings(skin) eq "DSx" } {
return [::DSx_font $font_name $size]
} elseif { $::settings(skin) eq "Insight" } {
if { [string range $font_name end-4 end] eq "_bold" } {
set fontn "[string range $font_name 0 end-4]${size}_bold"
} else {
set fontn "${font_name}_$size"
}
# if { [lsearch -exact [font names] $font] == -1 } {
# load_font
# }
return $fontn
} else {
return [::get_font $font_name $size]
}
}
# Define Fontawesome symbols by name. If a symbol name is already defined and the value differs, it is not changed
# and a warning added to the log.
proc ::plugins::DGUI::set_symbols { args } {
variable symbols
set n [expr {[llength $args]-1}]
for { set i 0 } { $i < $n } { incr i 2 } {
set sn [lindex $args $i]
set sv [lindex $args [expr {$i+1}]]
set idx [lsearch [array names symbols] $sn]
if { $idx == -1 } {
msg "add symbol $sn='$sv'"
set symbols($sn) $sv
} elseif { $symbols($sn) ne $sv } {
msg -WARN "symbol '$sn' already defined with a different value"
}
}
}
# A one-liner to return a default if a variable is undefined.
# Similar to ifexists in updater.tcl but does not set var (only returns the new value), and assigns empty values
proc ::plugins::DGUI::value_or_default { var default } {
upvar $var thevar
if {[info exists thevar] == 1} {
return [subst "\$thevar"]
} else {
return $default
}
}
# Adds a named option "-option_name option_value" to a named argument list if the option doesn't exist in the list.
# Returns the option value.
proc ::plugins::DGUI::args_add_option_if_not_exists { proc_args option_name option_value } {
upvar $proc_args largs
if { [string range $option_name 0 0] ne "-" } { set option_name "-$option_name" }
set opt_idx [lsearch -exact $largs $option_name]
if { $opt_idx == -1 } {
lappend largs $option_name $option_value
} else {
set option_value [lindex $largs [expr {$opt_idx+1}]]
}
return $option_value
}
# Removes the named option "-option_name" from the named argument list, if it exists.
proc ::plugins::DGUI::args_remove_option { proc_args option_name } {
upvar $proc_args largs
if { [string range $option_name 0 0] ne "-" } { set option_name "-$option_name" }
set option_idx [lsearch -exact $largs $option_name]
if { $option_idx > -1 } {
if { $option_idx == [expr {[llength $largs]-1}] } {
set value_idx $option_idx
} else {
set value_idx [expr {$option_idx+1}]
}
set largs [lreplace $largs $option_idx $value_idx]
}
}
# Returns 1 if the named arguments list has a named option "-option_name".
proc ::plugins::DGUI::args_has_option { proc_args option_name } {
if { [string range $option_name 0 0] ne "-" } { set option_name "-$option_name" }
set n [llength $proc_args]
set option_idx [lsearch -exact $proc_args $option_name]
return [expr {$option_idx > -1 && $option_idx < [expr {$n-1}]}]
}
# Returns the value of the named option in the named argument list
proc ::plugins::DGUI::args_get_option { proc_args option_name {default_value {}} {rm_option 0} } {
upvar $proc_args largs
if { [string range $option_name 0 0] ne "-" } { set option_name "-$option_name" }
set n [llength $largs]
set option_idx [lsearch -exact $largs $option_name]
if { $option_idx > -1 && $option_idx < [expr {$n-1}] } {
set result [lindex $largs [expr {$option_idx+1}]]
if { $rm_option == 1 } {
set largs [lreplace $largs $option_idx [expr {$option_idx+1}]]
}
} else {
set result $default_value
}
return $result
}
# Extracts from args all pairs whose key start by the prefix. And returns the extracted named options in a new
# args list that contains the pairs, with the prefix stripped from the keys.
# For example, "-label_fill X" will return "-fill X" if prefix="-label_", and args will be emptied.
proc ::plugins::DGUI::args_extract_prefixed { proc_args prefix } {
upvar $proc_args largs
set new_args {}
set n [expr {[string length $prefix]-1}]
set i 0
while { $i < [llength $largs] } {
if { [string range [lindex $largs $i] 0 $n] eq $prefix } {
lappend new_args "-[string range [lindex $largs $i] 7 9999]"
lappend new_args [lindex $largs [expr {$i+1}]]
set largs [lreplace $largs $i [expr {$i+1}]]
} else {
incr i 2
}
}
return $new_args
}
# Looks up fields metadata in the data dictionary. 'what' can be a list with multiple items, then a list is returned.
proc ::plugins::DGUI::field_lookup { field {what name} } {
variable data_dictionary
variable field_lookup_whats
if { $field eq "" } return
if { ![info exists data_dictionary($field)] } {
msg "WARNING data field '$field' unmatched in proc field_lookup"
return {}
}
set result {}
foreach whatpart $what {
set match_idx [lsearch -all $field_lookup_whats $whatpart]
if { $match_idx == -1 } {
msg "WARNING what item '$whatpart' unmatched in proc field_lookup"
lappend result {}
} else {
lappend result [lindex $data_dictionary($field) $match_idx]
}
}
if { [llength $result] == 1 } { set result [lindex $result 0] }
return $result
}
proc ::plugins::DGUI::field_names { {data_types {} } {db_tables {}} } {
variable data_dictionary
variable field_lookup_whats
if { $data_types eq "" && $db_tables eq "" } {
return [array names data_dictionary]
}
if { $data_types eq "" } {
set dt_idx -1
} else {
set dt_idx [lsearch -all $field_lookup_whats "data_type"]
}
if { $db_tables eq "" } {
set tab_idx -1
} else {
set tab_idx [lsearch -all $field_lookup_whats "db_table"]
}
set fields {}
foreach fn [array names data_dictionary] {
set data_type [lindex $data_dictionary($fn) $dt_idx]
set db_table [lindex $data_dictionary($fn) $tab_idx]
set matches_dt [expr {$dt_idx == -1 || [lsearch -all $data_types $data_type] > -1 }]
set matches_tab [expr {$tab_idx == -1 || [lsearch -all $db_tables $db_table] > -1 }]
if { $matches_dt && $matches_tab } { lappend fields $fn }
}
return $fields
}
# TODO: USE A MEANINGFUL VALIDATION FUNCTION INSTEAD!
proc ::plugins::DGUI::keypress_is_number_or_dot {keyvalue} {
# set ::DYE::debug_text "PRESSED \"$keyvalue\""
return [expr { [string is integer $keyvalue] || $keyvalue eq "period" } ]
}
# TODO: USE A MEANINGFUL VALIDATION FUNCTION INSTEAD!
proc ::plugins::DGUI::keypress_is_number_or_slash {keyvalue} {
#set ::DYE::debug_text "PRESSED \"$keyvalue\""
return [expr { [string is integer $keyvalue] || $keyvalue eq "slash" } ]
}
proc ::plugins::DGUI::page_name_is_namespace { page_name } {
return [expr {[string range $page_name 0 1] eq "::" && [info exists ${page_name}::widgets]}]
}
# Call this on the page "load_page" namespace proc, before the actual page_show call, to store the page from which
# the new one was called.
proc ::plugins::DGUI::set_previous_page { ns } {
if { ! [page_name_is_namespace $ns] } return
set prev_page $::de1(current_context)
if { $prev_page eq "::plugins::DYE::MENU" } {
set prev_page $::plugins::DYE::MENU::data(previous_page)
}
set "${ns}::data(previous_page)" $prev_page
}
# "Smart" widget names selector. If 'ns' is specified, looks for the widgets in <ns>::widgets(<widget_name>),
# otherwise assumes 'widgets' directly references the widgets names.
# If a namespace 'ns' is provided, and a widget_name final character is a "*", tries to find all "related" widgets
# with that name, namely those with suffix "_label", "_state", "_symbol", "_img" and "_button".
# Also, if the widget_name ends in "_rating*", tries to find _rating_button, _rating1, _rating_half1, etc.
proc ::plugins::DGUI::select_widgets { widgets {ns {}} } {
set result {}
if { $ns eq "" } {
foreach wn $widgets {
if { $wn ne "" && [info exists $wn] } {
lappend result $wn
} else {
msg "ERROR: select_widgets - can't find widget '$wn'"
}
}
} else {
foreach wn $widgets {
if { [string range $wn end end] eq "*" } {
set some_found 0
if { [string range $wn end-7 end] eq "_rating*"} {
set wn [string range $wn 0 end-1]
if { [info exists "${ns}::widgets(${wn}_button)"] } {
lappend result [subst \$${ns}::widgets(${wn}_button)]
set some_found 1
set i 1
while { [info exists "${ns}::widgets(${wn}$i)"] } {
lappend result [subst \$${ns}::widgets(${wn}$i)]
if { [info exists "${ns}::widgets(${wn}_half$i)"] } {
lappend result [subst \$${ns}::widgets(${wn}_half$i)]
}
incr i
}
}
} elseif { [string range $wn end-8 end] eq "_clicker*"} {
set wn [string range $wn 0 end-1]
foreach subtype "{} _dec_small_inc _dec_big_inc _inc_small_inc _inc_big_inc _button" {
if { [info exists "${ns}::widgets(${wn}$subtype)"] } {
lappend result [subst \$${ns}::widgets(${wn}$subtype)]
set some_found 1
}
}
} else {
set wn [string range $wn 0 end-1]
foreach subtype "{} _label _symbol _img _button _state _clicker _rating" {
if { $subtype eq "_clicker" } {
foreach subsubtype "{} _dec_small_inc _dec_big_inc _inc_small_inc _inc_big_inc _button" {
if { [info exists "${ns}::widgets(${wn}_clicker${subsubtype})"] } {
lappend result [subst \$${ns}::widgets(${wn}_clicker${subsubtype})]
set some_found 1
}
}
} elseif { $subtype eq "_rating " } {
set i 1
while { [info exists "${ns}::widgets(${wn}_rating$i)"] } {
lappend result [subst \$${ns}::widgets(${wn}_rating$i)]
if { [info exists "${ns}::widgets(${wn}_rating_half$i)"] } {
lappend result [subst \$${ns}::widgets(${wn}_rating_half$i)]
}
incr i
}
} else {
if { [info exists "${ns}::widgets(${wn}$subtype)"] } {
lappend result [subst \$${ns}::widgets(${wn}$subtype)]
set some_found 1
}
}
}
}
if { $some_found == 0 } {
msg "ERROR: select_widgets - can't find any widget variable ${ns}::widgets($wn)"
}
} else {
if { [info exists "${ns}::widgets($wn)"] } {
lappend result [subst \$${ns}::widgets($wn)]
} else {
msg "ERROR: select_widgets - can't find widget variable ${ns}::widgets($wn)"
}
}
}
}
return $result
}
# "Smart" widgets enabler or disabler. 'enabled' can take any value equivalent to boolean (1, true, yes, etc.)
# For text, changes its fill color to the default or provided font or disabled color.
# For other widgets like rectangle "clickable" button areas, enables or disables them.
# Does nothing if the widget is hidden.
# If 'ns' is given, takes the widgets spec accepted by 'select_widgets'.
proc ::plugins::DGUI::enable_or_disable_widgets { enabled widgets {ns {}} { enabled_color {}} { disabled_color {} } } {
if { $enabled_color eq "" } { set enabled_color $::plugins::DGUI::font_color }
if { $disabled_color eq "" } { set disabled_color $::plugins::DGUI::disabled_color }
if { [string is true $enabled] } {
set color $enabled_color
set state normal
} else {
set color $disabled_color
set state disabled
}
foreach wn [::plugins::DGUI::select_widgets $widgets $ns] {
# set wc ""; catch { append wc [winfo class widget] }
# msg "DYE disabling widget $wn - class $wc"
# DE1 prefixes: text / image / .btn
if { [string range $wn 0 3] eq "text" } {
if { [.can itemconfig $wn -state] ne "hidden" } { .can itemconfig $wn -fill $color }
} elseif { [string range $wn 0 3] eq ".btn" } {
if { [.can itemconfig $wn -state] ne "hidden" } { .can itemconfig $wn -state $state }
} elseif { [string range $wn 0 5] eq ".can.w"} {
if { [$wn cget -state] ne "hidden" } { $wn configure -state $state }
}
}
update
}
# "Smart" widgets disabler.
# For text, changes its fill color to the default or provided disabled color.
# For other widgets like rectangle "clickable" button areas, disables them.
# Does nothing if the widget is hidden.
proc ::plugins::DGUI::disable_widgets { widgets {ns {}} { disabled_color {}} } {
::plugins::DGUI::enable_or_disable_widgets 0 $widgets $ns {} $disabled_color
}
proc ::plugins::DGUI::enable_widgets { widgets {ns {}} { enabled_color {} } } {
::plugins::DGUI::enable_or_disable_widgets 1 $widgets $ns $enabled_color {}
}
# "Smart" widgets shower or hider. 'show' can take any value equivalent to boolean (1, true, yes, etc.)
# If 'contex' is provided, only hides or shows if that context is currently active. For example, if you're showing
# after a delay, the page/context may not be currently shown.
# If 'ns' is given, takes the widgets spec accepted by 'select_widgets'.
proc ::plugins::DGUI::show_or_hide_widgets { show widgets {ns {}} { context {}} } {
if { $context ne "" && $context ne $::de1(current_context) } return
if { [string is true $show] } {
set state normal
} else {
set state hidden
}
foreach wn [::plugins::DGUI::select_widgets $widgets $ns] {
.can itemconfig $wn -state $state
}
update
}
proc ::plugins::DGUI::show_widgets { widgets {ns {}} { context {} } } {
show_or_hide_widgets 1 $widgets $ns $context
}
proc ::plugins::DGUI::hide_widgets { widgets {ns {}} { context {}} } {
show_or_hide_widgets 0 $widgets $ns $context
}
# Adds a standard DYE dialog page to the DE1 GUI.
# New named options:
# * -title: The page title. If not defined, uses variable <namespace>::data(page_title). A widget named "page_title"
# is added to the namespace widgets array.
# * -add_bg_img: Whether to add the background image, default 1. Use 0 if the page needs to be initialized in some
# other way, like for DSx configuration pages carousel.
# * -done_button: 0 or 1 (default), to include a "done" button. This will call a "<namespace>::page_done" command
# * -cancel_button: 0 or 1 (default), to include a "cancel" button. This will call a "<namespace>::page_cancel" command
# * -buttons_loc: one of "left", "center" or "right" (default).
proc ::plugins::DGUI::add_page { page args } {
array set opts $args
set has_ns [page_name_is_namespace $page]
if { [ifexists opts(-add_bg_img) 1] == 1 && $::plugins::DGUI::page_bg_image ne "" } {
add_de1_image $page 0 0 $::plugins::DGUI::page_bg_image
} else {
set background_id [.can create rect 0 0 [rescale_x_skin 2560] [rescale_y_skin 1600] \
-fill $::plugins::DGUI::bg_color -width 0 -state "hidden"]
add_visual_item_to_context $page $background_id
}
if { $has_ns } {
set "${page}::data(page_name)" $page
lappend ::plugins::DGUI::pages $page
}
if { [info exists opts(-title)] } {
set w [::add_de1_text $page 1280 60 \
-font [::plugins::DGUI::get_font $::plugins::DGUI::header_font $::plugins::DGUI::header_font_size] \
-fill $::plugins::DGUI::page_title_color -anchor "center" -text $opts(-title)]
if { $has_ns } { set "${page}::widgets(page_title)" $w }
} elseif { $has_ns && [info exists ${page}::data(page_title)] } {
set "${page}::widgets(page_title)" [::add_de1_variable $page 1280 60 \
-font [::plugins::DGUI::get_font $::plugins::DGUI::header_font $::plugins::DGUI::header_font_size] \
-fill $::plugins::DGUI::page_title_color -anchor "center" -textvariable [subst {\$${page}::data(page_title)}] ]
}
set done_button 1
if { [info exists opts(-done_button)] && $opts(-done_button) == 0 } { set done_button 0 }
set cancel_button 1
if { [info exists opts(-cancel_button)] && $opts(-cancel_button) == 0 } { set cancel_button 0 }
if { !$done_button && !$cancel_button } return
set y 1425
if { [info exists opts(-buttons_loc)] && $opts(-buttons_loc) eq "center" } {
if { $done_button && $cancel_button } {
set x_cancel [expr {1280-[rescale_x_skin $::plugins::DGUI::button2_width]-75}]
set x_done [expr {1280+75}]
} elseif { $done_button } {
set x_done [expr {1280-[rescale_x_skin $::plugins::DGUI::button2_width]/2}]
} elseif { $cancel_button } {
set x_cancel [expr {1280-[rescale_x_skin $::plugins::DGUI::button2_width]/2}]
}
} elseif { [info exists opts(-buttons_loc)] && $opts(-buttons_loc) eq "left" } {
if { $done_button && $cancel_button } {
set x_cancel 100
set x_done 400
} elseif { $done_button } {
set x_done 100
} elseif { $cancel_button } {
set x_cancel 100
}
} else {
if { $done_button && $cancel_button } {
set x_cancel 1900
set x_done 2200
} elseif { $done_button } {
set x_done 2200
} elseif { $cancel_button } {
set x_cancel 2200
}
}
if { $cancel_button } {
::plugins::DGUI::add_cancel_button $page $x_cancel $y ${page}::page_cancel
}
if { $done_button } {
::plugins::DGUI::add_done_button $page $x_done $y ${page}::page_done
}
}
# Adds a Cancel button to a page. Two widgets called "cancel_text" and "cancel_button" are added to the namespace
# widgets array, and the "cancel_button" widget is returned.
proc ::plugins::DGUI::add_cancel_button { page x y { command {} } { text {Cancel} } } {
return [add_button1 $page page_cancel $x $y $text $command]
}
# Adds an Ok / Done button to a page. Two widgets called "done_text" and "done_button" are added to the namespace
# widgets array, and the "done_button" widget is returned.
proc ::plugins::DGUI::add_done_button { page x y { command {} } { text {Done} } } {
return [add_button1 $page page_done $x $y $text $command]
}
# Adds a button1 (the same as used for the Done/Cancel)
proc ::plugins::DGUI::add_button1 { page widget_name x y label command args } {
set has_ns [page_name_is_namespace $page]
set width $::plugins::DGUI::button1_width
set height $::plugins::DGUI::button1_height
args_add_option_if_not_exists args -font [::plugins::DGUI::get_font $::plugins::DGUI::button_font 10]
#[::plugins::DGUI::get_font $::plugins::DGUI::button_font 10]
args_add_option_if_not_exists args -fill $::plugins::DGUI::button_font_fill
args_add_option_if_not_exists args -anchor "center"
# variable button_font "font"
# variable button_font_fill "#ffffff"
# variable button_fill "#c0c5e3"
if { $::plugins::DGUI::button1_img eq "" } {
if { $::settings(skin) eq "DSx" } {
set w [::plugins::DGUI::rounded_rectangle_outline $page $x $y [expr {$x+$width}] [expr {$y+$height}] \
[rescale_x_skin 50] $::plugins::DGUI::button_fill 5]
} else {
set w [::plugins::DGUI::rounded_rectangle $page $x $y [expr {$x+$width}] [expr {$y+$height}] \
[rescale_x_skin 40] $::plugins::DGUI::button_fill]
}
} else {
#set w [::add_de1_image $page $x $y $::plugins::DGUI::button1_img]
}
if { $has_ns } { set "${page}::widgets(${widget_name}_img)" $w }
if { $label ne "" } {
set w [::add_de1_text $page [expr {$x + ($width / 2)}] [expr {$y + ($height / 2) - 4}] \
-text [translate $label] {*}$args ]
if { $has_ns } { set "${page}::widgets(${widget_name}_label)" $w }
}
set widget [::add_de1_button $page $command $x $y [expr {$x + $width}] [expr {$y + $height}]]
if { $has_ns } { set "${page}::widgets(${widget_name}_button)" $widget }
return $widget
}
# Adds a button2 (the big buttons on DSx History Viewer).
# The button can have any of the following 3 components:
# * label: Main text
# * state_variable: Variable with the status text, which is shown in a smaller size, below the label.
# For showing states like on/off. If the value is.
# * symbol: A fontawesome symbol shown on the left third of the button
# Adds to the namespace widgets array <widget_name> (clickable button area, returned by the function),
# <widget_name>_symbol, <widget_name>_label and <widget_name>_state.
# New named options_
# -label_fill, -symbol_fill, -state_fill the font color of each element.
proc ::plugins::DGUI::add_button2 { page widget_name x y label state_variable symbol {command {}} args } {
set has_ns [page_name_is_namespace $page]
set width $::plugins::DGUI::button2_width
set height $::plugins::DGUI::button2_height
set label_fill [args_get_option args -label_fill $::plugins::DGUI::button_font_fill 1]
set symbol_fill [args_get_option args -symbol_fill $::plugins::DGUI::button_font_fill 1]
set state_fill [args_get_option args -state_fill $::plugins::DGUI::button_font_fill 1]
set fill [args_get_option args -state_fill $::plugins::DGUI::button_fill 1]
if { $::plugins::DGUI::button2_img eq "" } {
if { $::settings(skin) eq "DSx" } {
set w [::plugins::DGUI::rounded_rectangle_outline $page $x $y [expr {$x+$width}] [expr {$y+$height}] \
[rescale_x_skin 60] $fill 3]
} else {
set w [::plugins::DGUI::rounded_rectangle $page $x $y [expr {$x+$width}] [expr {$y+$height}] \
[rescale_x_skin 40] $fill]
}
} else {
#set w [::add_de1_image $page $x $y $::plugins::DGUI::button2_img ]
}
if { $has_ns } { set "${page}::widgets(${widget_name}_img)" $w }
if { $symbol eq "" } {
set x_label [expr {$x+$width/2}]
set x_state [expr {$x+$width/2}]
} else {
set x_label [expr {$x+$width*2/3}]
set x_state [expr {$x+$width*2/3}]
}
if { $state_variable eq "" } {
set y_label [expr {$y+$height/2}]
set label_size 8
} else {
if { [regexp {[\r\n]} $label] } {
set y_label [expr {$y+$height/3}]
set y_state [expr {$y+$height*4/5}]
set label_size 8
set state_size 7
} else {
set y_label [expr {$y+$height/3}]
set y_state [expr {$y+$height*2/3}]
set label_size 8
set state_size 8
}
}
if { $symbol ne "" } {
set w [::add_de1_text $page [expr {$x+$width/5}] [expr {$y+$height/2}] \
-text [subst \$::plugins::DGUI::symbols($symbol)] \
-fill $symbol_fill -font fontawesome_reg_medium -justify "center" -anchor "center"]
if { $has_ns } { set "${page}::widgets(${widget_name}_symbol)" $w }
}
if { $label eq "" && [info exists "${page}::data(${widget_name}_label)"] } {
set w [::add_de1_variable $page $x_label [expr {$y_label+3}] \
-font [::plugins::DGUI::get_font $::plugins::DGUI::button_font $label_size] -fill $label_fill \
-justify "center" -anchor "center" \
-textvariable "\$${page}::data(${widget_name}_label)" ]
if { $has_ns } { set "${page}::widgets(${widget_name}_label)" $w }
} else {
set w [::add_de1_text $page $x_label $y_label \
-text $label -font [::plugins::DGUI::get_font $::plugins::DGUI::button_font $label_size] -fill $label_fill \
-justify "center" -anchor "center"]
if { $has_ns } { set "${page}::widgets(${widget_name}_label)" $w }
}
if { $state_variable ne "" } {
if { $state_variable eq "auto" || $state_variable eq "1" } {
set state_variable "\$${page}::data(${widget_name}_state)"
}
set w [::add_de1_variable $page $x_state $y_state \
-font [::plugins::DGUI::get_font $::plugins::DGUI::button_font $state_size] -fill $state_fill \
-justify "center" -anchor "center" -textvariable $state_variable]
if { $has_ns } { set "${page}::widgets(${widget_name}_state)" $w }
}
set w [::add_de1_button $page $command [expr {$x-14}] [expr {$y-12}] \
[expr {$x+$width+10}] [expr {$y+$height+10}]]
if { $has_ns } { set "${page}::widgets(${widget_name})" $w }
return $w
}
# Adds a button3 (the standard "Ok" wide short button in DSx).
# The button can have any of the following 3 components:
# * label: Main text
# * symbol: A fontawesome symbol shown on the left third of the button
# Adds to the namespace widgets array <widget_name> (clickable button area, returned by the function),
# <widget_name>_symbol, <widget_name>_label and <widget_name>_state.
# New named options_
# -label_fill, -symbol_fill, -state_fill the font color of each element.
proc ::plugins::DGUI::add_button3 { page widget_name x y label symbol {command {}} args } {
set has_ns [page_name_is_namespace $page]
set width [args_get_option args -width $::plugins::DGUI::button3_width 1]
set height [args_get_option args -width $::plugins::DGUI::button3_height 1]
set label_fill [args_get_option args -label_fill $::plugins::DGUI::button_font_fill 1]
set symbol_fill [args_get_option args -symbol_fill $::plugins::DGUI::button_font_fill 1]
set fill [args_get_option args -state_fill $::plugins::DGUI::button_fill 1]
if { $::settings(skin) eq "DSx" } {
set w [::plugins::DGUI::rounded_rectangle_outline $page $x $y [expr {$x+$width}] [expr {$y+$height}] \
[rescale_x_skin 60] $fill 3]
} else {
set w [::plugins::DGUI::rounded_rectangle $page $x $y [expr {$x+$width}] [expr {$y+$height}] \
[rescale_x_skin 40] $fill]
}
if { $has_ns } { set "${page}::widgets(${widget_name}_img)" $w }
if { $symbol eq "" } {
set x_label [expr {$x+$width/2}]
} else {
set x_label [expr {$x+$width*2/3}]
}
set y_label [expr {$y+$height/2}]
set label_size 8
if { $symbol ne "" } {
set w [::add_de1_text $page [expr {$x+$width/5}] [expr {$y+$height/2}] \
-text [subst \$::plugins::DGUI::symbols($symbol)] \
-fill $symbol_fill -font fontawesome_reg_small -justify "center" -anchor "center"]
if { $has_ns } { set "${page}::widgets(${widget_name}_symbol)" $w }
}
if { $label eq "" && [info exists "${page}::data(${widget_name}_label)"] } {
set w [::add_de1_variable $page $x_label [expr {$y_label+3}] \
-font [::plugins::DGUI::get_font $::plugins::DGUI::button_font $label_size] -fill $label_fill \
-justify "center" -anchor "center" \
-textvariable "\$${page}::data(${widget_name}_label)" ]
if { $has_ns } { set "${page}::widgets(${widget_name}_label)" $w }
} else {
set w [::add_de1_text $page $x_label $y_label \
-text $label -font [::plugins::DGUI::get_font $::plugins::DGUI::button_font $label_size] -fill $label_fill \
-justify "center" -anchor "center"]
if { $has_ns } { set "${page}::widgets(${widget_name}_label)" $w }
}
set w [::add_de1_button $page $command [expr {$x-14}] [expr {$y-12}] \
[expr {$x+$width+10}] [expr {$y+$height+10}]]
if { $has_ns } { set "${page}::widgets(${widget_name})" $w }
return $w
}
# Adapted from gui.tcl "proc add_de1_button", but allowing user-defined options like fill, outline, width etc.,
# as there is not base proc to do that.
# Use -label_* to pass named options to the label.
proc ::plugins::DGUI::add_button { page widget_name x0 y0 x1 y1 label command args } {
set has_ns [page_name_is_namespace $page]
global button_cnt
incr button_cnt
set btn_name ".btn_$button_cnt"
incr button_cnt
set btn2_name ".btn_$button_cnt"
set rx0 [rescale_x_skin $x0]
set rx1 [rescale_x_skin $x1]
set ry0 [rescale_y_skin $y0]
set ry1 [rescale_y_skin $y1]
args_add_option_if_not_exists args -fill $::plugins::DGUI::entry_bg_color
args_add_option_if_not_exists args -outline $::plugins::DGUI::font_color
args_add_option_if_not_exists args -disabledoutline $::plugins::DGUI::disabled_color
args_add_option_if_not_exists args -activeoutline $::plugins::DGUI::remark_color
args_add_option_if_not_exists args -width 3
set label_args {}
set label_args [args_extract_prefixed args -label_]
set font_size [args_get_option label_args -font_size $::plugins::DGUI::font_size 1]
args_add_option_if_not_exists label_args -font [::plugins::DGUI::get_font $::plugins::DGUI::font $font_size]
args_add_option_if_not_exists label_args -fill $::plugins::DGUI::font_color
.can create rect $rx0 $ry0 $rx1 $ry1 -tag $btn_name -state hidden {*}$args
if { $has_ns && $widget_name ne "" } { set "${page}::widgets(${widget_name}_button)" $btn_name }
if { $label ne "" || [info exists "${page}::data(${widget_name}_label)"] } {
set x_label [expr {$x0+($x1-$x0)/2}]
set y_label [expr {$y0+($y1-$y0)/2}]
if { $label ne "" } {
set w [::add_de1_text $page $x_label $y_label \
-anchor center -justify center -text $label {*}$label_args ]
if { $has_ns } { set "${page}::widgets(${widget_name}_label)" $w }
} elseif { [info exists "${page}::data(${widget_name}_label)"] } {
set w [::add_de1_variable $page $x_label $y_label \
-anchor center -justify center {*}$label_args -textvariable "\$${page}::data(${widget_name}_label)" ]
if { $has_ns } { set "${page}::widgets(${widget_name}_label)" $w }
}
}
.can create rect $rx0 $ry0 $rx1 $ry1 -fill {} -outline black -width 0 -tag $btn2_name -state hidden
if { $has_ns && $widget_name ne "" } { set "${page}::widgets(${widget_name})" $btn2_name }
if { $command ne "" } {
regsub {%x0} $command $rx0 command
regsub {%x1} $command $rx1 command
regsub {%y0} $command $ry0 command
regsub {%y1} $command $ry1 command
.can bind $btn2_name [platform_button_press] $command
}
add_visual_item_to_context $page $btn_name
add_visual_item_to_context $page $btn2_name
return $btn2_name
}
# Discovered through Johanna's MimojaCafe skin code, attributed to Barney.
proc ::plugins::DGUI::rounded_rectangle {context x1 y1 x2 y2 radius colour } {
set x1 [rescale_x_skin $x1]
set y1 [rescale_y_skin $y1]
set x2 [rescale_x_skin $x2]
set y2 [rescale_y_skin $y2]
if { [info exists ::_rect_id] != 1 } { set ::_rect_id 0 }
set tag "rect_$::_rect_id"
.can create oval $x1 $y1 [expr $x1 + $radius] [expr $y1 + $radius] -fill $colour -outline $colour -width 0 \
-tag $tag -state "hidden"
.can create oval [expr $x2-$radius] $y1 $x2 [expr $y1 + $radius] -fill $colour -outline $colour -width 0 \
-tag $tag -state "hidden"
.can create oval $x1 [expr $y2-$radius] [expr $x1+$radius] $y2 -fill $colour -outline $colour -width 0 \
-tag $tag -state "hidden"
.can create oval [expr $x2-$radius] [expr $y2-$radius] $x2 $y2 -fill $colour -outline $colour -width 0 \
-tag $tag -state "hidden"
.can create rectangle [expr $x1 + ($radius/2.0)] $y1 [expr $x2-($radius/2.0)] $y2 -fill $colour -outline $colour \
-width 0 -tag $tag -state "hidden"
.can create rectangle $x1 [expr $y1 + ($radius/2.0)] $x2 [expr $y2-($radius/2.0)] -fill $colour -outline $colour \
-width 0 -tag $tag -state "hidden"
::add_visual_item_to_context $context $tag
incr ::_rect_id
return $tag
}
# Inspired by Barney's rounded_rectangle, mimic DSx buttons showing a button outline without a fill.
proc ::plugins::DGUI::rounded_rectangle_outline {context x1 y1 x2 y2 arc_offset colour width } {
set x1 [rescale_x_skin $x1]
set y1 [rescale_y_skin $y1]
set x2 [rescale_x_skin $x2]
set y2 [rescale_y_skin $y2]
if { [info exists ::_rect_id] != 1 } { set ::_rect_id 0 }
set tag "rect_$::_rect_id"
.can create arc [expr $x1] [expr $y1+$arc_offset] [expr $x1+$arc_offset] [expr $y1] -style arc -outline $colour \
-width [expr $width-1] -tag $tag -start 90 -disabledoutline $::plugins::DGUI::disabled_color -state "hidden"
.can create arc [expr $x1] [expr $y2-$arc_offset] [expr $x1+$arc_offset] [expr $y2] -style arc -outline $colour \
-width [expr $width-1] -tag $tag -start 180 -disabledoutline $::plugins::DGUI::disabled_color -state "hidden"
.can create arc [expr $x2-$arc_offset] [expr $y1] [expr $x2] [expr $y1+$arc_offset] -style arc -outline $colour \
-width [expr $width-1] -tag $tag -start 0 -disabledoutline $::plugins::DGUI::disabled_color -state "hidden"
.can create arc [expr $x2-$arc_offset] [expr $y2] [expr $x2] [expr $y2-$arc_offset] -style arc -outline $colour \
-width [expr $width-1] -tag $tag -start -90 -disabledoutline $::plugins::DGUI::disabled_color -state "hidden"
.can create line [expr $x1+$arc_offset/2] [expr $y1] [expr $x2-$arc_offset/2] [expr $y1] -fill $colour \
-width $width -tag $tag -disabledfill $::plugins::DGUI::disabled_color -state "hidden"
.can create line [expr $x2] [expr $y1+$arc_offset/2] [expr $x2] [expr $y2-$arc_offset/2] -fill $colour \
-width $width -tag $tag -disabledfill $::plugins::DGUI::disabled_color -state "hidden"
.can create line [expr $x1+$arc_offset/2] [expr $y2] [expr $x2-$arc_offset/2] [expr $y2] -fill $colour \
-width $width -tag $tag -disabledfill $::plugins::DGUI::disabled_color -state "hidden"
.can create line [expr $x1] [expr $y1+$arc_offset/2] [expr $x1] [expr $y2-$arc_offset/2] -fill $colour \
-width $width -tag $tag -disabledfill $::plugins::DGUI::disabled_color -state "hidden"
::add_visual_item_to_context $context $tag
incr ::_rect_id
return $tag
}
# Calls add_de1_text but with the DYE GUI aspect by default. Returns the created widget.
# Named options (except the new ones described below) are passed through to add_de1_text.
# New named options:
# -widget_name, if specified the widget is saved into the widgets array of the namespace, with name "widget_name".
# -has_button: if 1, makes a clickable rectangular area around the symbol, with action given by -button_cmd
proc ::plugins::DGUI::add_text { page x y text args } {
set has_ns [page_name_is_namespace $page]
set widget_name [args_get_option args -widget_name {} 1]
set has_button [args_get_option args -has_button 0 1]
set button_cmd [args_get_option args -button_cmd {} 1]
set button_width [args_get_option args -button_width 200 1]
set button_height [args_get_option args -button_height 40 1]
set font_size [args_get_option args -font_size $::plugins::DGUI::font_size 1]
args_add_option_if_not_exists args -font [::plugins::DGUI::get_font $::plugins::DGUI::font $font_size]
args_add_option_if_not_exists args -fill $::plugins::DGUI::font_color
set anchor [args_add_option_if_not_exists args -anchor nw]
set widget [::add_de1_text $page $x $y {*}$args -text $text]
if { $has_ns && $widget_name ne "" } { set "${page}::widgets($widget_name)" $widget }