/usr/lib/gpsman/gendials.tcl is in gpsman 6.4.4.2-2.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
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 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 1598 1599 1600 1601 1602 1603 1604 1605 1606 1607 1608 1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 1619 1620 1621 1622 1623 1624 1625 1626 1627 1628 1629 1630 1631 1632 1633 1634 1635 1636 1637 1638 1639 1640 1641 1642 1643 1644 1645 1646 1647 1648 1649 1650 1651 1652 1653 1654 1655 1656 1657 1658 1659 1660 1661 1662 1663 1664 1665 1666 1667 1668 1669 1670 1671 1672 1673 1674 1675 1676 1677 1678 1679 1680 1681 1682 1683 1684 1685 1686 1687 1688 1689 1690 1691 1692 1693 1694 1695 1696 1697 1698 1699 1700 1701 1702 1703 1704 1705 1706 1707 1708 1709 1710 1711 1712 1713 1714 1715 1716 1717 1718 1719 1720 1721 1722 1723 1724 1725 1726 1727 1728 1729 1730 1731 1732 1733 1734 1735 1736 1737 | #
# This file is part of:
#
# gpsman --- GPS Manager: a manager for GPS receiver data
#
# Copyright (c) 1998-2013 Miguel Filgueiras migfilg@t-online.de
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program.
#
# File: gendials.tcl
# Last change: 6 October 2013
#
# Includes contributions by
# - Brian Baulch (baulchb_AT_onthenet.com.au) marked "BSB contribution"
# - Stefan Heinen (stefan.heinen_AT_djh-freeweb.de) marked "SH contribution"
#
# creating toplevels
proc GMToplevel {w title geom trans prots binds} {
# create a toplevel with given geometry
# $w window path
# $title if not empty title given as either "==TITLE" for TITLE,
# or as an index in TXT array
# $trans if not void is path of window of which $w is a transient
# $prots list with in sequence a wm protocol and a command
# $binds list with in sequence an event and a command
# return $w
global TXT
if { $title != "" && ! [regsub {^==} $title "" title] } {
set title $TXT($title)
}
toplevel $w
if { $title != "" } { wm title $w "$title/GPSMan" }
wm geometry $w $geom
if { $trans != {} } { wm transient $w $trans }
wm group $w .
foreach {p c} $prots { wm protocol $w $p $c }
foreach {e c} $binds { bind $w $e $c }
return $w
}
# modal dialogs
proc GMMessage {mess args} {
# create modal dialog for displaying message
# if $args=="wait" return only when user acknowledges message
# except in command-line mode or if using the slow op window
# single button: OK; binding: return
global COLOUR EPOSX EPOSY TXT UNIX CMDLINE
if { $CMDLINE } {
puts stderr $mess
flush stderr
return
}
if { [winfo exists .slowop] } {
SlowOpMessage $mess
return
}
if { [winfo exists .mess] } {
# add new message
foreach s [pack slaves .mess.fr] {
if { $s == ".mess.fr.ok" } { break }
set last $s
}
if { ! [regexp {^\.mess\.fr\.text(.*)$} $last x n] } {
BUG bad last message field in .mess
return
}
if { $n == "" } {
set n 1
} else {
if { $n == 4 } {
.mess.fr.text4 configure -text $mess
update idletasks
return
}
incr n
}
label .mess.fr.text$n -text $mess
pack .mess.fr.text$n -side top -pady 5 -before .mess.fr.ok
update idletasks
return
}
# this avoids bugs but may create havoc with grabs
set gs [grab current]
GMToplevel .mess message +$EPOSX+$EPOSY . \
[list WM_DELETE_WINDOW [list DestroyRGrabs .mess $gs]] \
[list <Key-Return> [list DestroyRGrabs .mess $gs]]
if { ! $UNIX } {
# SH contribution
focus .mess
}
frame .mess.fr -borderwidth 5 -bg $COLOUR(messbg)
label .mess.fr.title -text "!!!" -relief sunken
label .mess.fr.text -text $mess
button .mess.fr.ok -text $TXT(ok) -command [list DestroyRGrabs .mess $gs]
pack .mess.fr -side top
# changes in packing order must be reflected above when adding
# new messages to existing window
pack .mess.fr.title .mess.fr.text .mess.fr.ok -side top -pady 5
RaiseWindow .mess
update idletasks
grab .mess
if { $args == "wait" } {
while 1 {
after 500
update
if { ! [winfo exists .mess] } { return }
}
}
return
}
proc GMConfirm {mess} {
# create modal dialog for asking for confirmation
# buttons: OK, Cancel; bindings: return, delete
global GMResConf COLOUR EPOSX EPOSY TXT CMDLINE
if { $CMDLINE } { return 1 }
destroy .messres
GMToplevel .messres message +$EPOSX+$EPOSY . \
{WM_DELETE_WINDOW {set GMResConf 0}} \
[list <Key-Return> {set GMResConf 1} \
<Key-Delete> {set GMResConf 0}]
frame .messres.fr -borderwidth 5 -bg $COLOUR(confbg)
label .messres.fr.title -text "???" -relief sunken
label .messres.fr.text -text $mess
frame .messres.fr.bs
button .messres.fr.bs.ok -text $TXT(ok) -command { set GMResConf 1 }
button .messres.fr.bs.cancel -text $TXT(no) -command { set GMResConf 0 }
pack .messres.fr.bs.ok .messres.fr.bs.cancel -side left -pady 5
pack .messres.fr.title .messres.fr.text .messres.fr.bs -side top -pady 5
pack .messres.fr -side top
update idletasks
set gs [grab current]
grab .messres
RaiseWindow .messres
tkwait variable GMResConf
DestroyRGrabs .messres $gs
update idletasks
return $GMResConf
}
proc GMSelect {mess blist vlist} {
# create modal dialog for selecting values from $vlist under names in
# $blist; if an element in $blist has the form @LIST then the
# corresponding $vlist element is a list with one less element than LIST
# menubuttons are created for each @LIST element whose label is the
# first element of LIST, buttons being used for the other elements
# bindings: return for first, delete for last element, or their
# first elements in case of @LIST
# (see proc GMChooseFrom for selection using a listbox)
global GMResSel COLOUR EPOSX EPOSY TXT
# assumes first and last elements of vlist are return values for
# Return and Delete keys, respectively
destroy .messres
set e [lindex $blist 0]
if { [string first "@" $e] == 0 } {
set e [lindex [lindex $vlist 0] 0]
} else { set e [lindex $vlist 0] }
GMToplevel .messres selection +$EPOSX+$EPOSY . \
[list WM_DELETE_WINDOW "set GMResSel [lindex $vlist 0]"] \
[list <Key-Return> "set GMResSel $e"]
frame .messres.fr -borderwidth 5 -bg $COLOUR(selbg)
label .messres.fr.title -text "???" -relief sunken
label .messres.fr.text -text $mess
frame .messres.fr.frsel
set max 4 ; set c 0 ; set r 0 ; set lval "" ; set menus 0
foreach e $blist v $vlist {
set b .messres.fr.frsel.b$r$c
if { [regexp {^@(.+)$} $e x e] } {
if { [llength $e] != [llength $v]+1 } {
BUG GMSelect bad lengths of @LIST lists
}
incr menus
set lval [lindex $v 0]
menubutton $b -text [lindex $e 0] -menu $b.m
menu $b.m
foreach x [lreplace $e 0 0] y $v {
$b.m add command -label $x -command "set GMResSel $y"
}
} else {
set lval $v
button $b -text $e -command "set GMResSel $v"
}
grid $b -column $c -row $r -sticky ew
if { [incr c] >= $max } {
set c 0 ; incr r
}
}
bind .messres <Key-Delete> "set GMResSel $lval"
pack .messres.fr -side top
pack .messres.fr.title .messres.fr.text .messres.fr.frsel -side top -pady 5
set gs [grab current]
update idletasks
grab .messres
if { $menus } {
Raise .messres
} else { RaiseWindow .messres }
tkwait variable GMResSel
DestroyRGrabs .messres $gs
update idletasks
return $GMResSel
}
proc GMChooseFrom {how mess wd blist vlist args} {
# create modal dialog for selecting elements from list $blist
# with associated return values in $vlist
# $how in {single, many, many_0} defines number of elements that can
# be selected, many_0 meaning that 0 is an alternative
# a listbox is used with width $wd
# $args if present is a pair with $vars $descs, suitable for use
# with proc GMSetupParams, so that parameters may be selected
# buttons: OK, Cancel
# bindings: return for commit, extended select mode on listbox,
# make visible by initial char on listbox
# return list with selected values upon normal termination, and
# an empty list or -1 if $how==many_0
# (see also proc GMSelect for selection of only one element with buttons)
global GMResult DPOSX DPOSY COLOUR TXT UNIX
set w .gmchoosefr
if { [winfo exists $w] } { Raise $w ; bell ; return }
GMToplevel $w "==$mess" +$DPOSX+$DPOSY . \
{WM_DELETE_WINDOW {set GMResult cnc}} \
[list <Key-Return> {set GMResult ok}]
frame $w.fr -borderwidth 5 -bg $COLOUR(dialbg)
label $w.fr.text -text $mess
# adjust list height according to number of parameters
set lh [expr 15-[llength [lindex $args 0]]]
if { [set ll [llength $blist]] > $lh } {
set ll $lh
}
frame $w.fr.frbx
if { $how == "single" } {
set mode single
} else { set mode extended }
listbox $w.fr.frbx.bx -height $ll -width $wd -relief flat \
-selectmode $mode -yscrollcommand "$w.fr.frbx.bscr set" \
-exportselection 0
# SH contribution: no such bindings in non-unix systems
if { $UNIX } {
bind $w.fr.frbx.bx <Enter> { focus %W }
bind $w.fr.frbx.bx <Leave> "focus $w.fr.frbx"
}
bind $w.fr.frbx.bx <Key> { ScrollListIndex %W %A }
scrollbar $w.fr.frbx.bscr -command "$w.fr.frbx.bx yview"
foreach i $blist { $w.fr.frbx.bx insert end $i }
if { $ll == 1 } { $w.fr.frbx.bx selection set 0 }
if { $args != "" } {
set opts 1
frame $w.fr.fopt
foreach "menus es" \
[GMSetupParams $w.fr.fopt [lindex $args 0] [lindex $args 1]] {}
} else { set opts 0 ; set menus 0 }
frame $w.fr.frbt
button $w.fr.frbt.ok -text $TXT(ok) -command { set GMResult ok }
button $w.fr.frbt.cnc -text $TXT(cancel) -command { set GMResult cnc }
pack $w.fr.frbt.ok $w.fr.frbt.cnc -side left -pady 5
pack $w.fr.frbx.bx $w.fr.frbx.bscr -side left -fill y
if { $opts } {
pack $w.fr.text $w.fr.frbx $w.fr.fopt $w.fr.frbt -side top -pady 5
} else {
pack $w.fr.text $w.fr.frbx $w.fr.frbt -side top -pady 5
}
pack $w.fr
update idletasks
set gs [grab current]
grab $w
if { $menus } {
Raise .fdlg
} else { RaiseWindow .fdlg }
while 1 {
tkwait variable GMResult
switch $GMResult {
"" { }
cnc {
if { $how == "many_0" } { set res -1 } else { set res "" }
break
}
ok {
set ss [$w.fr.frbx.bx curselection]
if { $ss == "" && $how != "many_0" } {
bell
continue
}
set res ""
foreach i $ss {
lappend res [lindex $vlist $i]
}
if { $opts } {
GMUseEntries $w.fr.fopt $es
}
break
}
}
}
DestroyRGrabs $w $gs
update idletasks
return $res
}
proc GMChooseParams {mess vars descs} {
# create modal dialog for choosing parameters
# $vars and $descs are as described in GMSetupParams
# buttons: OK, Cancel
# bindings: return for commit
# return 0 if cancelled
global GMResult DPOSX DPOSY COLOUR TXT
set w .gmchooseprsr
if { [winfo exists $w] } { Raise $w ; bell ; return }
GMToplevel $w "==$mess" +$DPOSX+$DPOSY . \
{WM_DELETE_WINDOW {set GMResult cnc}} \
[list <Key-Return> {set GMResult ok}]
frame $w.fr -borderwidth 5 -bg $COLOUR(dialbg)
label $w.fr.text -text $mess
frame $w.fr.fopt
foreach "menus es" [GMSetupParams $w.fr.fopt $vars $descs] {}
frame $w.fr.frbt
button $w.fr.frbt.ok -text $TXT(ok) -command { set GMResult ok }
button $w.fr.frbt.cnc -text $TXT(cancel) -command { set GMResult cnc }
pack $w.fr.frbt.ok $w.fr.frbt.cnc -side left -pady 5
pack $w.fr.text $w.fr.fopt $w.fr.frbt -side top -pady 5
pack $w.fr
update idletasks
set gs [grab current]
grab $w
if { $menus } {
Raise .fdlg
} else { RaiseWindow .fdlg }
while 1 {
tkwait variable GMResult
switch $GMResult {
"" { }
cnc {
set res 0 ; break
}
ok {
GMUseEntries $w.fr.fopt $es
set res 1 ; break
}
}
}
DestroyRGrabs $w $gs
update idletasks
return $res
}
proc GMLogin {service} {
# get or retrieve login information for accessing a given service
# $service is a unique name for the service, needed for displaying
# a message and indexing saved login information
# save the login information for use in the current session if the user
# asks for it
# return list with user name and password or an empty list if cancelled
global MESS TXT GMPInfo
if { ! [catch {set up $GMPInfo($service)}] } { return $up }
if { [GMChooseParams [format $MESS(loginto) $service] \
{GMPInfo(__tmp,u) GMPInfo(__tmp,p) GMPInfo(__tmp,s)} \
[list =$TXT(uname) =@$TXT(pword) @$TXT(remember)]] \
== 0 } { return {} }
set up [list $GMPInfo(__tmp,u) $GMPInfo(__tmp,p)]
unset GMPInfo(__tmp,p)
if { $GMPInfo(__tmp,s) } { set GMPInfo($service) $up }
return $up
}
##### information window
proc DisplayInfo {mess args} {
# display information on a dialog
# the dialog is created if it not exists, otherwise the message
# will be added to it
# $args may be "" or "tabs" followed by tabs list (man 3tk text) in
# which negative numbers are to be converted from chars to screen
# distances
global CMDLINE COLOUR EPOSX EPOSY TXT FixedFont DInfo
if { $CMDLINE } { return }
set frt .gminfo.fr.frt
if { ! [winfo exists .gminfo] } {
GMToplevel .gminfo info +$EPOSX+$EPOSY {} \
{WM_DELETE_WINDOW {destroy .gminfo}} {}
frame .gminfo.fr -borderwidth 5 -bg $COLOUR(messbg)
label .gminfo.fr.title -text $TXT(info) -relief sunken
frame $frt -relief flat -borderwidth 0
text $frt.txt -width 80 -font $FixedFont -wrap word \
-exportselection 1 -yscrollcommand "$frt.tscrl set"
bind $frt.txt <space> "$frt.txt yview scroll 1 pages ; break"
bind $frt.txt <Key-Delete> "$frt.txt yview scroll -1 pages ; break"
bind $frt.txt <Any-Key> break
bind $frt.txt <Button-2> break
scrollbar $frt.tscrl -command "$frt.txt yview"
set frb .gminfo.fr.frb
frame $frb -relief flat -borderwidth 0
button $frb.save -text $TXT(save) \
-command "SaveDisplayInfo $frt.txt"
button $frb.ok -text $TXT(ok) -command { destroy .gminfo }
grid config $frt.txt -column 0 -row 1 -sticky nesw
grid config $frt.tscrl -column 1 -row 1 -sticky nesw
grid config $frb.save -column 0 -row 0
grid config $frb.ok -column 1 -row 0
pack .gminfo.fr.title $frt $frb -side top -pady 5
pack .gminfo.fr
# info on this window
catch {unset DInfo}
# to help setting tabs, make public the "ex" in pixels
set x20 "xxxxxxxxxxxxxxxxxxxx"
set DInfo(ex) [expr round([font measure $FixedFont $x20]/20.0)]
# number of next free tag; tags will have names started by "itg"
set DInfo(nxttag) 1
}
if { $args != "" } {
set tags ""
switch -- [lindex $args 0] {
tabs {
set tlst ""
foreach x [lindex $args 1] {
if { [regexp {^-([0-9]+)$} $x m n] } {
# to pixels
set x [expr $n*$DInfo(ex)]
}
lappend tlst $x
}
if { [catch {set tgname $DInfo($tlst)}] } {
set tgname itg$DInfo(nxttag)
incr DInfo(nxttag)
$frt.txt tag configure $tgname -tabs $tlst
set DInfo($tlst) $tgname
}
lappend tags $tgname
}
default {
BUG bad args to DisplayInfo
return
}
}
$frt.txt insert end "$mess\n" $tags
} else { $frt.txt insert end "$mess\n" }
$frt.txt see end
update idletasks
return
}
proc SaveDisplayInfo {wtxt} {
# save text in $wtxt text widget to file
global TXT
if { [set txt [$wtxt get 1.0 end]] == "" || \
[set f [GMOpenFile $TXT(saveto) Info wapp]] == ".." } { return }
puts $f $txt
close $f
return
}
### dialog window for controlling slow operations
proc SlowOpWindow {mess} {
# create dialog for controlling slow operation
# to be called by application before entering the main loop of the slow
# operation
# within the loop there should be calls to proc SlowOpAborted that
# returns 1 if the operation is to be aborted, or updates the interface
# and returns 0 otherwise
# any call within the loop to GMMessage will be diverted to this dialog
# after the main loop there should be a call to proc SlowOpFinish with
# the unique identifier that is returned by proc SlowOpWindow
# returns a unique identifier to be used when calling proc SlowOpWindow
global SlowOp COLOUR MAPCOLOUR EPOSX EPOSY TXT CMDLINE USESLOWOPWINDOW \
FixedFont
if { $CMDLINE || ! $USESLOWOPWINDOW } { return }
if { [winfo exists .slowop] } {
set SlowOp(id) [clock seconds]
set SlowOp(ids) [linsert $SlowOp(ids) 0 $SlowOp(id)]
.slowop.fr.title configure -text $mess
return $SlowOp(id)
}
set id [clock seconds]
array set SlowOp [list aborting 0 id $id ids $id \
status "$TXT(working)..." grabs [grab current]]
# avoid completely covering other dialogs
set pos [expr $EPOSX+150]
GMToplevel .slowop opinprogr +$pos+$EPOSY {} \
{WM_DELETE_WINDOW {set SlowOp(aborting) 1}} {}
frame .slowop.fr -borderwidth 5 -bg $COLOUR(messbg)
label .slowop.fr.title -text $mess -relief sunken
set frs .slowop.fr.frs
frame $frs -relief flat -borderwidth 0
label $frs.st -textvariable SlowOp(status) -fg $MAPCOLOUR(trvwrnimportant)
checkbutton $frs.light -disabledforeground $COLOUR(check) -state disabled
set frt .slowop.fr.frt
frame $frt -relief flat -borderwidth 0
text $frt.txt -width 50 -font $FixedFont -wrap word \
-yscrollcommand "$frt.tscrl set"
bind $frt.txt <space> "$frt.txt yview scroll 1 pages ; break"
bind $frt.txt <Key-Delete> "$frt.txt yview scroll -1 pages ; break"
bind $frt.txt <Any-Key> break
scrollbar $frt.tscrl -command "$frt.txt yview"
set frb .slowop.fr.frb
frame $frb -relief flat -borderwidth 0
button $frb.abort -text $TXT(abort) -command SlowOpAbort
button $frb.ok -text $TXT(ok) -state disabled \
-command [list DestroyRGrabs .slowop $SlowOp(grabs)]
pack $frs.st $frs.light -side left
grid config $frt.txt -column 0 -row 1 -sticky nesw
grid config $frt.tscrl -column 1 -row 1 -sticky nesw
grid config $frb.abort -column 0 -row 0
grid config $frb.ok -column 1 -row 0
pack .slowop.fr.title $frs $frt $frb -side top -pady 5
pack .slowop.fr
update idletasks
grab .slowop
RaiseWindow .slowop
return $id
}
proc SlowOpFinish {id mess} {
# to be called by application when the operation ends (either normally
# or not)
# $id is unique identifier that was returned by proc SlowOpWindow
# if $id is not in the $SlowOp(ids) stack the message is displayed
# and nothing else happens
# $mess will be displayed if not empty
# the dialog window will be closed only when the stack of calls to
# proc SlowOpWindow is empty
# the dialog window is closed silently if there were no messages,
# otherwise the Ok button is activated and the user must acknowledge it
global SlowOp TXT
if { ! [winfo exists .slowop] } {
if { $mess != "" } { GMMessage $mess }
return
}
if { $mess != "" } { SlowOpMessage $mess }
if { [set ix [lsearch -exact $SlowOp(ids) $id]] == -1 || \
[set SlowOp(ids) [lreplace $SlowOp(ids) 0 $ix]] != {} } {
return
}
if { ! $SlowOp(aborting) } { set SlowOp(status) $TXT(errwarn) }
set SlowOp(aborting) 0
set txt .slowop.fr.frt.txt
if { [$txt index end] == 2.0 } {
DestroyRGrabs .slowop $SlowOp(grabs)
return
}
set frb .slowop.fr.frb
foreach b "abort ok" st "disabled normal" {
$frb.$b configure -state $st
}
return
}
proc SlowOpAbort {} {
# the user aborted the operation
# not to be called directly from the application
global SlowOp TXT
set SlowOp(aborting) 1
set SlowOp(status) $TXT(aborted)
return
}
proc SlowOpMessage {mess} {
# show message in slow operation dialog window
# not to be called directly from the application
set txt .slowop.fr.frt.txt
$txt insert end "$mess\n"
$txt see end
update idletasks
return
}
proc SlowOpAborted {} {
# to be called by the application to test if the operation was aborted
# if not a call to update is made to ensure that the window is usable
# return 1 if yes
global SlowOp TXT
if { ! [winfo exists .slowop] } { return 0 }
if { $SlowOp(aborting) } {
set SlowOp(status) $TXT(aborted)
return 1
}
set frs .slowop.fr.frs
$frs.light toggle
update
return 0
}
### opening files
proc GMOpenFile {act wh mode} {
# create modal dialog for selecting and opening a file
# $act is string describing the action to do on the file
# $wh in $filetypes (see proc GMStart, setup.tcl)
# $mode in {r, w, wapp} with wapp meaning write or possibly append
# buttons: OK, Cancel
# binding: return and double-left for commit, left-click for select
global GMResult COLOUR DPOSX DPOSY LISTHEIGHT File TXT MESS UNIX
if { [set f $File($wh)] == "" || [catch {cd [file dirname $f]}] } {
set currfile ""
} else { set currfile [file tail $f] }
if { $mode == "wapp" } { set mode a }
GMToplevel .fdlg file +$DPOSX+$DPOSY . \
{WM_DELETE_WINDOW {set GMResult cnc}} \
[list <Key-Return> {set GMResult ok}]
frame .fdlg.fr -borderwidth 5 -bg $COLOUR(selbg)
label .fdlg.fr.title -text [format $MESS(fileact) $act $TXT(name$wh)] \
-relief sunken
if { ! $UNIX } {
menubutton .fdlg.fr.vols -text $TXT(volume) -menu .fdlg.fr.vols.m
menu .fdlg.fr.vols.m
bind .fdlg.fr.vols <Button-1> {
FillMenuExec .fdlg.fr.vols.m {ChangeVolume .fdlg} file volume
}
}
entry .fdlg.fr.wdir -width 30
ShowTEdit .fdlg.fr.wdir [pwd] 0
frame .fdlg.fr.frbx
listbox .fdlg.fr.frbx.box -height $LISTHEIGHT -width 30 \
-yscrollcommand ".fdlg.fr.frbx.bscr set" \
-selectmode single -exportselection 1
bind .fdlg.fr.frbx.box <Double-1> {
global GMResult
set GMResult [%W nearest %y]
}
bind .fdlg.fr.frbx.box <Button-1> {
.fdlg.fr.fn delete 0 end
.fdlg.fr.fn insert 0 [%W get [%W nearest %y]]
}
scrollbar .fdlg.fr.frbx.bscr -command ".fdlg.fr.frbx.box yview"
FillDir .fdlg.fr.frbx.box
entry .fdlg.fr.fn -width 30
.fdlg.fr.fn insert 0 $currfile
TextBindings .fdlg.fr.fn
frame .fdlg.fr.bs
button .fdlg.fr.bs.ok -text $TXT(ok) -command { set GMResult ok }
button .fdlg.fr.bs.cnc -text $TXT(cancel) \
-command { set GMResult cnc }
pack .fdlg.fr.bs.ok .fdlg.fr.bs.cnc -side left -pady 5
pack .fdlg.fr.frbx.box .fdlg.fr.frbx.bscr -side left -fill y
if { $UNIX } {
pack .fdlg.fr.title .fdlg.fr.wdir .fdlg.fr.frbx .fdlg.fr.fn \
.fdlg.fr.bs -side top -pady 5
} else {
pack .fdlg.fr.title .fdlg.fr.vols .fdlg.fr.wdir .fdlg.fr.frbx \
.fdlg.fr.fn .fdlg.fr.bs -side top -pady 5
}
pack .fdlg.fr -side top
update idletasks
set gs [grab current]
grab .fdlg
RaiseWindow .fdlg
while 1 {
tkwait variable GMResult
switch $GMResult {
"" { }
cnc {
set res ".."
break
}
ok {
set fn [.fdlg.fr.fn get]
set f [GMCheckFile open $fn $mode]
if { $f != ".." } {
set File($wh) [file join [pwd] $fn]
set res $f
break
}
}
0 {
cd ..
ShowTEdit .fdlg.fr.wdir [pwd] 0
.fdlg.fr.frbx.box delete 0 end ; FillDir .fdlg.fr.frbx.box
.fdlg.fr.fn delete 0 end
}
default {
set fn [.fdlg.fr.frbx.box get $GMResult]
set f [GMCheckFile open $fn $mode]
if { $f != ".." } {
set File($wh) [file join [pwd] $fn]
set res $f
break
}
}
}
}
DestroyRGrabs .fdlg $gs
update idletasks
return $res
}
proc GMOpenFileParms {act wh mode vars vals} {
# create modal dialog for selecting and opening a file and parameters
# see arguments of proc GMGetFileName
set fname [GMGetFileName $act $wh $mode $vars $vals]
if { $fname == ".." } { return ".." }
if { $mode == "wapp" } { set mode a }
return [open $fname $mode]
}
proc GMGetFileName {act wh mode vars vals} {
# create modal dialog for selecting a file name and parameters
# $act is string describing the action to do on the file
# $wh in $filetypes (see proc GMStart, setup.tcl)
# $mode in {r, w, wapp} with wapp meaning write or possibly append
# $vars is list of (global) vars to set
# $vals is associated list of value descriptions (see proc GMSetupParams)
# buttons: OK, Cancel
# binding: return and double-left for commit, left-click for select
global GMResult COLOUR DPOSX DPOSY LISTHEIGHT File TXT MESS UNIX
if { [set f $File($wh)] == "" || [catch {cd [file dirname $f]}] } {
set currfile ""
} else { set currfile [file tail $f] }
GMToplevel .fdlg file +$DPOSX+$DPOSY . \
{WM_DELETE_WINDOW {set GMResult cnc}} \
[list <Key-Return> {set GMResult ok}]
frame .fdlg.fr -borderwidth 5 -bg $COLOUR(selbg)
label .fdlg.fr.title -text [format $MESS(fileact) $act $TXT(name$wh)] \
-relief sunken
if { ! $UNIX } {
menubutton .fdlg.fr.vols -text $TXT(volume) -menu .fdlg.fr.vols.m
menu .fdlg.fr.vols.m
bind .fdlg.fr.vols <Button-1> {
FillMenuExec .fdlg.fr.vols.m {ChangeVolume .fdlg} file volume
}
}
entry .fdlg.fr.wdir -width 30
ShowTEdit .fdlg.fr.wdir [pwd] 0
# adjust list height according to number of parameters
set lh [expr $LISTHEIGHT-[llength $vars]]
frame .fdlg.fr.frbx
listbox .fdlg.fr.frbx.box -height $lh -width 30 \
-yscrollcommand ".fdlg.fr.frbx.bscr set" \
-selectmode single -exportselection 1
bind .fdlg.fr.frbx.box <Double-1> {
global GMResult
set GMResult [%W nearest %y]
}
bind .fdlg.fr.frbx.box <Button-1> {
.fdlg.fr.fn delete 0 end
.fdlg.fr.fn insert 0 [%W get [%W nearest %y]]
}
scrollbar .fdlg.fr.frbx.bscr -command ".fdlg.fr.frbx.box yview"
FillDir .fdlg.fr.frbx.box
# BSB contribution: wheelmouse scrolling
Mscroll .fdlg.fr.frbx.box
entry .fdlg.fr.fn -width 30
.fdlg.fr.fn insert 0 $currfile
TextBindings .fdlg.fr.fn
frame .fdlg.fr.fopt
foreach "menus es" [GMSetupParams .fdlg.fr.fopt $vars $vals] {}
frame .fdlg.fr.bs
button .fdlg.fr.bs.ok -text $TXT(ok) -command { set GMResult ok }
button .fdlg.fr.bs.cnc -text $TXT(cancel) \
-command { set GMResult cnc }
pack .fdlg.fr.bs.ok .fdlg.fr.bs.cnc -side left -pady 5
pack .fdlg.fr.frbx.box .fdlg.fr.frbx.bscr -side left -fill y
if { $UNIX } {
pack .fdlg.fr.title .fdlg.fr.wdir .fdlg.fr.frbx .fdlg.fr.fn \
.fdlg.fr.fopt .fdlg.fr.bs -side top -pady 5
} else {
pack .fdlg.fr.title .fdlg.fr.vols .fdlg.fr.wdir .fdlg.fr.frbx \
.fdlg.fr.fn .fdlg.fr.fopt .fdlg.fr.bs -side top -pady 5
}
pack .fdlg.fr -side top
update idletasks
set gs [grab current]
grab .fdlg
if { $menus } {
Raise .fdlg
} else { RaiseWindow .fdlg }
while 1 {
tkwait variable GMResult
switch $GMResult {
"" { }
cnc {
set res ".." ; break
}
ok {
set fn [.fdlg.fr.fn get]
set f [GMCheckFile check $fn $mode]
if { $f != ".." } {
set File($wh) [file join [pwd] $fn]
GMUseEntries .fdlg.fr.fopt $es
set res $fn
break
}
}
0 {
cd ..
ShowTEdit .fdlg.fr.wdir [pwd] 0
.fdlg.fr.frbx.box delete 0 end ; FillDir .fdlg.fr.frbx.box
.fdlg.fr.fn delete 0 end
}
default {
set fn [.fdlg.fr.frbx.box get $GMResult]
set f [GMCheckFile check $fn $mode]
if { $f != ".." } {
set File($wh) [file join [pwd] $fn]
GMUseEntries .fdlg.fr.fopt $es
set res $fn
break
}
}
}
}
DestroyRGrabs .fdlg $gs
update idletasks
return $res
}
proc GMCheckFile {how f mode} {
# check name of file $f and if ok either open it and return file descriptor
# or return file name; otherwise return ".."
# $how in {open check}
# $mode in {r, w, wapp}
global PERMS TXT MESS
if { $f == "" } { bell ; return ".." }
if { [file isdirectory $f] } {
if { [file executable $f] } {
cd $f
ShowTEdit .fdlg.fr.wdir [pwd] 0
.fdlg.fr.frbx.box delete 0 end
FillDir .fdlg.fr.frbx.box
.fdlg.fr.fn delete 0 end
} else {
bell
}
} elseif { $mode == "r" } {
if { [file readable $f] } {
switch $how {
open { return [open $f r] }
check { return $f }
}
} else { bell }
} elseif { [file exists $f] } {
if { [file writable $f] } {
if { $mode == "w" } {
set l [list $TXT(ovwrt) $TXT(cancel)]
set r {w 0}
} else {
# appending is an option
set l [list $TXT(ovwrt) $TXT(app) $TXT(cancel)]
set r {w a 0}
}
if { [set m [GMSelect $MESS(filexists) $l $r]] != 0 } {
switch $how {
open { return [open $f $m $PERMS] }
check { return $f }
}
}
} else { bell }
} elseif { [file writable [pwd]] } {
switch $how {
open {
if { $mode == "wapp" } { set mode a }
return [open $f $mode $PERMS]
}
check { return $f }
}
} else {
bell
}
return ".."
}
proc ChangeVolume {w vol} {
# file volume has changed $vol in file-selection dialog $w
if { ! [file isdirectory $vol] } { bell ; return }
cd $vol
ShowTEdit .fdlg.fr.wdir [pwd] 0
.fdlg.fr.frbx.box delete 0 end ; FillDir .fdlg.fr.frbx.box
.fdlg.fr.fn delete 0 end
return
}
### font selection
proc GMSelectFont {args} {
# dialog for selecting a font
# $args may contain the font description to return if the
# default is selected; if empty "default" is returned
# a font is defined by giving
# one of [font families] and
# the size in points or pixels, an integer > 0
# the weight, one of {normal bold}
# the slant, one of {roman italic}
# whether to use underline
# whether to use overstrike
# return empty list if cancelled, "default" or the description
# in $args, or list with family, size, and other style
# indicators in {normal bold roman italic underline overstrike}
# where size follows the Tk convention (negative if in pixels)
global GMFtDial TXT MESS LISTHEIGHT EPOSX EPOSY COLOUR
array set GMFtDial {
size 12
units points
weight normal
slant roman
underline 0
overstrike 0
}
if { [winfo exists .gmselfont] } { destroy .gmselfont }
set w [GMToplevel .gmselfont selfont +$EPOSX+$EPOSY . \
{WM_DELETE_WINDOW {set GMFtDial(act) cancel}} \
[list <Key-Return> {set GMFtDial(act) ok}]]
frame $w.fr -borderwidth 5 -bg $COLOUR(selbg)
label $w.fr.tit -text $TXT(selfont)
set frbx $w.fr.frbx
frame $frbx
listbox $frbx.box -height $LISTHEIGHT -width 40 -selectmode single \
-yscrollcommand "$frbx.bscr set" -exportselection 1
scrollbar $frbx.bscr -command "$frbx.box yview"
grid $frbx.box -row 0 -column 0
grid $frbx.bscr -row 0 -column 1 -sticky ns
grid rowconfigure $frbx 0 -weight 1
grid columnconfigure $frbx 0 -weight 1
foreach fam [lsort -dictionary [font families]] {
$frbx.box insert end $fam
}
frame $w.fr.frp
set vars {} ; set descs {}
foreach v {size units weight slant underline overstrike} {
lappend vars GMFtDial($v)
}
set descs [list "=$TXT(size)" \
"~$TXT(units)/[list points pixels]" \
"~$TXT(weight)/[list normal bold]" \
"~$TXT(slant)/[list roman italic]" \
"@$TXT(underline)" "@$TXT(overstrike)"]
set pes [lindex [GMSetupParams $w.fr.frp $vars $descs] 1]
set frbs $w.fr.frbs
frame $frbs
foreach x {ok default cancel} {
button $frbs.$x -text $TXT($x) -command "set GMFtDial(act) $x"
pack $frbs.$x -side left
}
pack $w.fr.tit
pack $frbs -side bottom -pady 5
pack $w.fr.frp -side bottom -pady 5
# must be the last one
pack $w.fr.frbx -fill both -expand 1 -pady 5
grid $w.fr
grid rowconfigure $w.fr 0 -weight 1
grid columnconfigure $w.fr 0 -weight 1
grid rowconfigure $w 0 -weight 1
grid columnconfigure $w 0 -weight 1
update idletasks
# cannot use RaiseWindow because of menus
set grabs [grab current]
grab $w
while 1 {
tkwait variable GMFtDial(act)
switch $GMFtDial(act) {
cancel {
set res {} ; break
}
default {
if { [set res [lindex $args 0]] == {} } {
set res default
}
break
}
ok {
if { [set ix [$frbx.box curselection]] == {} } {
GMMessage $MESS(mustselftfam)
continue
}
GMUseEntries $w.fr.frp $pes
set n [string trim $GMFtDial(size)]
if { ! [CheckNumber GMMessage $n] } { continue }
if { $n < 1 } {
GMMessage [format $MESS(xcantbey) $TXT(size) 0]
continue
}
if { $GMFtDial(units) == "pixels" } {
set n [expr -$n]
}
set res [list [$frbx.box get $ix]]
lappend res $n
foreach x {weight slant} { lappend res $GMFtDial($x) }
foreach x {underline overstrike} {
if { $GMFtDial($x) } { lappend res $x }
}
break
}
}
}
DestroyRGrabs $w $grabs
destroy $w
return $res
}
### utilities for dealing with parameters in a dialog
proc GMSetupParams {w vars descs} {
# set-up widgets for setting parameters in a dialog
# $w is window parent
# $vars is list of (global) vars to set; they must have a value
# except those associated to entries which will be initialised to ""
# and to menubuttons that if undefined will be initialised to "";
# array elements may also be given instead of normal variables but
# the indices must be alphanumeric
# $descs is associated list of value descriptions as:
# @@TEXT button creating a balloon help with $TXT(TEXT), associated
# variable declared as global but not used nor set
# @TEXT checkbutton with label TEXT, values 0 1
# =@TEXT non-echo entry with label TEXT
# =TEXT entry with label TEXT
# !TEXT=MENUPROC/ARGS menubutton with label TEXT and menu filled by
# proc MENUPROC; the arguments to the MENUPROC call are:
# - the menu window
# - the command to be associated with final entries, whose
# arguments are the selected value and the menu window
# - the elements of the list ARGS
# |TEXT/LIST label TEXT and menubutton with text-variable for values
# in LIST
# +TEXT/LIST radiobuttons with possible values in LIST, label TEXT
# /TEXT|LIST radiobuttons with possible values in LIST, label TEXT
# ~TEXT/LIST radiobuttons with possible values in LIST but their
# names are in the array TXT, label TEXT
# LIST radiobutton with possible values in LIST
# LISTs above cannot have repeated elements
# return pair with flag set if there are menubuttons, and list of entries,
# each as a triple, usually with path from $w to entry, the name of
# global (array or normal) variable to be used in "global" and complete
# name of variable to be used in "set"; for non-echo entries the
# path is prefixed by a "@"; the list can be processed by proc GMUseEntries
global COLOUR TXT NEEntry
set i 0 ; set es "" ; set menus 0
foreach v $vars os $descs {
if { [regexp {^([^(]+)[(]([^)]+)[)]$} $v x vname el] } {
set vid "${vname}___ARR_$el"
} else { set vid $v ; set vname $v }
global $vname
frame $w.f$i
switch -glob -- $os {
@@* {
set os [string replace $os 0 1]
set bh $w.f$i.bh$vid
BalloonButton $bh $os
pack $bh
}
@* {
set os [string replace $os 0 0]
set cb $w.f$i.c$vid
checkbutton $cb -text $os -variable $v -anchor w \
-onvalue 1 -offvalue 0 -selectcolor $COLOUR(check)
if { [set $v] } {
$cb select
} else { $cb deselect }
pack $cb
}
=* {
if { [string index $os 1] == "@" } {
set z 1
} else { set z 0 }
set os [string replace $os 0 $z]
set wl [label $w.f$i.l$vid -text $os]
set ppath f$i.e$vid
set we [entry $w.f$i.e$vid -width 30]
TextBindings $we
if { $z } {
set NEEntry($we) ""
bind $we <Delete> "GMNEEntry $we _ BackSpace ; break"
bind $we <Any-Key> "GMNEEntry $we %A %K ; break"
set ppath "@$ppath"
}
if { [catch {set $v}] } {
set $v ""
} elseif { $z == 0 } { $we insert 0 [set $v] }
pack $wl $we -side left
lappend es [list $ppath $vname $v]
}
!* {
set menus 1
if { ! [regexp {^!([^=]+)=([^/]+)/(.*)$} $os \
m lab menuproc mpargs] } {
BUG Bad argument to GMSetupParams !
}
set mb $w.f$i.mb$vid
menubutton $mb -text $lab -relief raised \
-direction below -menu $mb.m
menu $mb.m
eval $menuproc $mb.m GMChangeParam $mpargs
if { [catch {set $v}] } {
set $v ""
}
set wl [label $w.f$i.l$vid -textvariable $v]
pack $mb $wl -side left
}
|* {
set menus 1
if { ! [regexp {^[|]([^/]+)/(.*)$} $os \
m lab lst] } {
BUG Bad argument to GMSetupParams |
}
set wl [label $w.f$i.t$vid -text $lab -width 16]
set mb $w.f$i.mb$vid
menubutton $mb -textvariable $v -relief raised \
-direction below -menu $mb.m
menu $mb.m
foreach x $lst {
$mb.m add command -label $x -command "set $v $x"
}
pack $wl $mb -side left
}
+* - /* - ~* {
set labval [string first "~" $os]
if { ! [regexp {^.([^/]+)/(.+)$} $os m lab lst] } {
BUG Bad argument to GMSetupParams +/~
continue
}
pack [label $w.f$i.l$vid -text $lab] -side left
set k 0
set wrb $w.f$i.r_${vid}_0
foreach o $lst {
if { $labval } {
set lv $o
} else { set lv $TXT($o) }
set rb $w.f$i.r_${vid}_$k
radiobutton $rb -text $lv -variable $v \
-value $o -anchor w -selectcolor $COLOUR(check)
pack $rb -side left -padx 2
if { [set $v] == $o } { set wrb $rb }
incr k
}
$wrb invoke
}
default {
set k 0
set wrb $w.f$i.rd_${vid}_0
foreach o $os {
set rb $w.f$i.rd_${vid}_$k
radiobutton $rb -text $o -variable $v \
-value $o -anchor w -selectcolor $COLOUR(check)
pack $rb -side left -padx 2
if { [set $v] == $o } { set wrb $rb }
incr k
}
$wrb invoke
}
}
pack $w.f$i -side top -fill x -expand 1
incr i
}
return [list $menus $es]
}
proc GMNEEntry {e char ksym} {
# keep track of characters typed in a non-echo entry $e
# current contents are kept on global NEEntry($e) that should be unset
# after use
global NEEntry PASSWDECHO
if { $PASSWDECHO == "none" } {
echo 0
$e delete 0 end
} else { set echo 1 }
if { $ksym == "BackSpace" } {
set NEEntry($e) [string replace $NEEntry($e) end end]
if { $echo } { $e delete 0 }
return
}
if { $ksym == $char || $ksym == "??" || [regexp {^[a-z]} $ksym] } {
append NEEntry($e) $char
if { $echo } { $e insert end $PASSWDECHO }
}
return
}
proc GMChangeParam {val varmenu args} {
# parameter value changed by a selection in a menu
# $varmenu is either the menu path assumed to have a single occurrence
# of .mbVARID. or has the form =VARID where VARID either is the name
# of the global simple variable to set, or has is the string
# concatenation of a global array identifier, "___ARR_" and
# an array index
# $args may be TXT to force value to be $TXT($val)
global TXT
if { ! [regexp {^=(.+)$} $varmenu x v] } {
regexp {\.mb([^.]+)\.} $varmenu x v
}
if { [regexp {^(.+)___ARR_(.+)$} $v x v ix] } {
global $v
append v "(" $ix ")"
} else { global $v }
if { $args == "TXT" } {
set val $TXT($val)
}
set $v $val
return
}
proc GMUseEntries {w es} {
# set global variables according to entries set-up by proc GMSetupParams
# $w is window parent
# $es is list of triples usually with path from $w to entry,
# name of global (array or normal) variable to be used in "global" and
# complete name of variable to be used in "set"; for non-echo entries
# the path is prefixed with a "@"
# current contents of non-echo entries are kept on global array NEEntry
# (see proc GMNEEntry) and corresponding elements are unset here
global NEEntry
foreach e $es {
global [lindex $e 1]
if { [string index [set ppath [lindex $e 0]] 0] == "@" } {
set ppath $w.[string replace $ppath 0 0]
set v $NEEntry($ppath)
unset NEEntry($ppath)
} else { set v [$w.$ppath get] }
set [lindex $e 2] $v
}
return
}
### image listbox widget
proc ImageListbox {act path args} {
# implements a new widget whose model is a listbox but has entries
# with an image and possibly a text label
# $act is the action to perform and determines $args
# create SIZE WIDTH EHEIGHT SELECTMODE ?SCROLLBAR?
# insert INDEX IMAGE TEXT ?TAGS?; return either index or -1 if entry
# can not be inserted because IMAGE cannot be displayed and TEXT
# is empty
# delete INDEX ?INDEX?
# get INDEX ?INDEX? ; return list of texts in entries
# gettags INDEX ?INDEX? ; return list of tags in entries
# selclr INDEX ?INDEX? ; clear selected
# selset INDEX ?INDEX? ; set as selected (irrespective of SELECTMODE)
# cursel "" ; return list of indices of currently selected entries
# getsel "" ; return list of texts in currently selected entries
# getseltags "" ; return list of lists each with the tags in currently
# selected entries
# seldel "" ; delete selected entries
# index Y ; return index of entry at y-coordinate (inside listbox)
# destroyall "" ; destroy all image listboxes under window $path
# where
# SELECTMODE is one of {single, extended}
# EHEIGHT is the height for the entries in pixels (minimum used: 5)
# INDEX is either a numeric index from 0 or "end"
# TAGS is a list
# the widget should be packed or grided by caller after being created
# images that have more than EHEIGHT-4 in width or height are either
# truncated to that size if they are of type photo, or not displayed
# information related to these widgets is stored in global array GMIBox
# auxiliary images are created but never deleted; their names can be
# retrieved from GMIBox(img,*) entries
# bindings on entries:
# <Button-1> deselects everything, selects entry
# if SELECTMODE=="extended":
# <Control-Button-1> toggles selection state of entry
# <Shift-Button-1> selects range from last selected entry to entry
global GMIBox COLOUR
if { $act == "destroyall" } {
foreach n [array names GMIBox $path*,csize] {
regsub {,csize$} $n "" lbox
destroy $lbox
}
array unset GMIBox $path*
return
}
if { [set nargs [llength $args]] != 0 } {
foreach "a1 a2 a3 a4 a5" $args { break }
}
if { $act != "create" } {
if { [catch {set csize $GMIBox($path,csize)}] } {
BUG trying to use non-existing ImageListbox
}
set end $csize
if { $end > 0 } { incr end -1 }
foreach x "sel eh ew mode" {
set $x $GMIBox($path,$x)
}
}
set res ""
switch $act {
create {
# SIZE WIDTH EHEIGHT MODE ?SCROLLBAR?
if { $nargs < 4 } { BUG missing args to ImageListbox create }
if { $a3 < 5 } { set a3 5 }
set height [expr $a1*$a3]
foreach x "csize sel eh ew mode anchor base height" \
v "0 {} $a3 $a2 $a4 {} 0 $height" {
set GMIBox($path,$x) $v
}
canvas $path -height $height -width $a2 -confine 1 \
-borderwidth 2 -relief sunken
if { $a5 != "" } {
$path configure -yscrollincrement $a3 \
-yscrollcommand "ImageListboxScroll $path $a5" \
-scrollregion "0 0 $a2 $height"
trace variable GMIBox($path,csize) w ImageListboxResize
}
$path bind entry <Shift-Button-1> \
"ImageListboxESButton $path %y ; break"
$path bind entry <Control-Button-1> \
"ImageListboxECButton $path %y ; break"
$path bind entry <Button-1> "ImageListboxEButton $path %y"
}
insert {
# INDEX IMAGE TEXT ?TAGS?
if { $nargs < 3 } { BUG missing args to ImageListbox insert }
set ih [expr $eh-2]
if { $a2 != "" && \
([image width $a2] > $ih || [image height $a2] > $ih) } {
if { [image type $a2] != "photo" } {
if { $a3 == "" } { return -1 }
set a2 ""
} else {
if { [catch {set im $GMIBox(img,for,$a2)}] } {
set im [image create photo -width $ih -height $ih]
$im copy $a2 -from 0 0 $ih $ih
set GMIBox(img,for,$a2) $im
}
set a2 $im
}
}
if { $a1 != "end" } {
set na1 [ImageListboxIndices $path $end $a1]
if { $a1 > $na1 } {
# assuming given index must be an integer
set na1 $csize
}
# update selection
set s ""
foreach e $GMIBox($path,sel) {
if { $e >= $na1 } { incr e }
lappend s $e
}
set GMIBox($path,sel) $s
# move lower entries down
set y0 [expr $na1*$eh]
if { $csize > 0 && $na1 < $csize } {
foreach it [$path find withtag entry] {
if { [lindex [$path coords $it] 1] >= $y0 } {
$path move $it 0 $eh
}
}
}
} else { set y0 [expr $csize*$eh] }
$path create rectangle 1 [expr $y0+1] $ew [expr $y0+$eh] \
-fill $COLOUR(bg) -outline $COLOUR(bg) \
-tags [list txt entry bg "tgs=$a4"]
# texts are created even if empty so that they can be retrieved
$path create text [expr $eh+8] [expr $y0+$eh/2] -anchor w \
-text $a3 -fill $COLOUR(fg) \
-tags [list txt entry "txt=$a3"]
if { $a2 != "" } {
$path create image 5 [expr $y0+2] -anchor nw -image $a2 \
-tags "img entry"
}
incr GMIBox($path,csize)
update idletasks
}
delete {
# INDEX ?INDEX?
if { $nargs < 1 } { BUG missing args to ImageListbox delete }
foreach "a1 a2" [ImageListboxIndices $path $end [list $a1 $a2]] {}
if { $a2 == "" } { set a2 $a1 }
if { [set ndel [expr $a2-$a1+1]] == $csize } {
$path delete all
set GMIBox($path,sel) ""
} else {
# update selection
set s ""
foreach e $GMIBox($path,sel) {
if { $e < $a1 } {
lappend s $e
} elseif { $e > $a2 } {
lappend s [expr $e-$ndel]
}
}
set GMIBox($path,sel) $s
# move lower entries up
set y0 [expr $a1*$eh] ; set yn [expr ($a2+1)*$eh]
set dy [expr -$ndel*$eh]
foreach it [$path find withtag entry] {
if { [set y [lindex [$path coords $it] 1]] >= $y0 } {
if { $y >= $yn } {
$path move $it 0 $dy
} else { $path delete $it }
}
}
}
set GMIBox($path,csize) [expr $csize-$ndel]
update idletasks
}
get {
# INDEX ?INDEX?
if { $nargs < 1 } { BUG missing args to ImageListbox get }
foreach "a1 a2" [ImageListboxIndices $path $end [list $a1 $a2]] {}
if { $a2 == "" } { set a2 $a1 }
set y0 [expr $a1*$eh] ; set yn [expr ($a2+1)*$eh]
set r ""
foreach it [$path find withtag txt] {
if { [set y [lindex [$path coords $it] 1]] >= $y0 && \
$y < $yn } {
foreach t [$path gettags $it] {
if { [regsub {^txt=} $t "" tx] } {
lappend r [list [expr round($y)] $tx]
break
}
}
}
}
foreach p [lsort -integer -index 0 $r] {
lappend res [lindex $p 1]
}
}
gettags {
# INDEX ?INDEX?
if { $nargs < 1 } { BUG missing args to ImageListbox gettags }
foreach "a1 a2" [ImageListboxIndices $path $end [list $a1 $a2]] {}
if { $a2 == "" } { set a2 $a1 }
set y0 [expr $a1*$eh] ; set yn [expr ($a2+1)*$eh]
set r ""
foreach it [$path find withtag txt] {
if { [set y [lindex [$path coords $it] 1]] >= $y0 && \
$y < $yn } {
foreach t [$path gettags $it] {
if { [regsub {^tgs=} $t "" tgs] } {
lappend r [list [expr round($y)] $tgs]
break
}
}
}
}
foreach p [lsort -integer -index 0 $r] {
lappend res [lindex $p 1]
}
}
selset {
# INDEX ?INDEX?
# add to selection, irrespective of $mode
# keep selection list ordered
if { $nargs < 1 } { BUG missing args to ImageListbox selset }
foreach "a1 a2" [ImageListboxIndices $path $end [list $a1 $a2]] {}
if { $a2 == "" } { set a2 $a1 }
set y0 [expr $a1*$eh+2]
set s ""
foreach ix $sel {
if { $ix == $a1 } {
if { [incr a1] > $a2 } {
set a1 1e10
} else { set y0 [expr $y0+$eh] }
} else {
while { $a1 < $ix } {
ImageListboxSelect sel $path $y0
lappend s $a1
if { [incr a1] > $a2 } {
set a1 1e10
} else { set y0 [expr $y0+$eh] }
}
}
lappend s $ix
}
while { $a1 <= $a2 } {
ImageListboxSelect sel $path $y0
lappend s $a1
incr a1 ; set y0 [expr $y0+$eh]
}
set GMIBox($path,sel) $s
update idletasks
}
selclr {
# INDEX ?INDEX?
# keep selection list ordered
if { $nargs < 1 } { BUG missing args to ImageListbox selclr }
foreach "a1 a2" [ImageListboxIndices $path $end [list $a1 $a2]] {}
if { $a2 == "" } { set a2 $a1 }
set s ""
foreach ix $sel {
if { $ix >= $a1 && $ix <= $a2 } {
ImageListboxSelect clear $path [expr $ix*$eh+2]
} else { lappend s $ix }
}
set GMIBox($path,sel) $s
update idletasks
}
cursel {
set res $sel
}
getsel {
set dy [expr $eh-1]
foreach ix $sel {
set y0 [expr $ix*$eh]
foreach it [$path find overlapping 0 $y0 100 [expr $y0+$dy]] {
foreach t [$path gettags $it] {
if { [regsub {^txt=} $t "" tx] } {
lappend res $tx
break
}
}
}
}
}
getseltags {
foreach ix $sel {
set y0 [expr ($ix+0.5)*$eh]
foreach it [$path find overlapping 0 $y0 100 [expr $y0+4]] {
foreach t [$path gettags $it] {
if { [regsub {^tgs=} $t "" tgs] } {
lappend res $tgs
break
}
}
}
}
}
seldel {
set dy [expr -$eh]
foreach ix [lsort -integer -decreasing $sel] {
# move lower entries up
set y0 [expr $ix*$eh] ; set yn [expr $y0+$eh]
foreach it [$path find withtag entry] {
if { [set y [lindex [$path coords $it] 1]] >= $yn } {
$path move $it 0 $dy
} elseif { $y >= $y0 } { $path delete $it }
}
}
set GMIBox($path,csize) [expr $csize-[llength $sel]]
set GMIBox($path,sel) ""
update idletasks
}
index {
# Y (coordinates inside listbox)
if { $nargs < 1 } { BUG missing args to ImageListbox index }
set res [expr int($a1/$GMIBox($path,eh))+$GMIBox($path,base)]
if { $res > $end } { set res $end }
}
default { BUG calling ImageListbox with wrong action }
}
return $res
}
proc ImageListboxScroll {path scr pos0 posf} {
# scrolling image listbox
# $scr is scrollbar
# $pos0, $posf are the arguments to the scrolling command
# percentage of vertical dimension for top and bottom positions
global GMIBox
set s $GMIBox($path,csize)
set GMIBox($path,base) [expr round($s*$pos0)]
$scr set $pos0 $posf
return
}
proc ImageListboxResize {a aix op} {
# called by trace when $GMIBox($path,csize) has been changed
# resize scroll region after a change of size in image listbox
global GMIBox
regsub {,csize} $aix "" path
if { ! [winfo exists $path] } { return }
if { [set nh [expr $GMIBox($path,csize)*$GMIBox($path,eh)]] < \
[set max $GMIBox($path,height)] } {
set nh $max
}
$path configure -scrollregion "0 0 $GMIBox($path,ew) $nh"
return
}
proc ImageListboxSelect {act path y0} {
# change aspect of entry when selection state changes
# $act in {sel, clear}
global GMIBox COLOUR
if { $act != "sel" } { set act "" }
foreach it [$path find overlapping 0 $y0 100 [expr $y0+4]]] {
if { [lsearch -exact [$path gettags $it] bg] != -1 } {
$path itemconfigure $it -fill $COLOUR(${act}bg)
break
}
}
return
}
proc ImageListboxIndices {path end ixs} {
# check indices of image-listbox widget that must be in (non-strict)
# increasing order
# $ixs is list of non-negative integers, "end", or "" (discarded)
# $end is either 0 or current size-1
# return list of integers in the 0..$end range
set r "" ; set min 0
foreach ix $ixs {
if { $ix == "" } { continue }
if { $ix == "end" } {
set ix $end
} elseif { ! [regexp {^[1-9]*[0-9]+$} $ix] } {
if { $ix != "end" } { BUG bad index for ImageListbox }
set ix $end
} elseif { $ix > $end } {
set ix $end
}
if { $ix < $min } { BUG bad index for ImageListbox }
set min $ix
lappend r $ix
}
return $r
}
proc ImageListboxEButton {path y} {
# mouse button-1 on ImageListbox entry
global GMIBox
if { $GMIBox($path,sel) != "" } { ImageListbox selclr $path 0 end }
set ix [expr int($y/$GMIBox($path,eh))+$GMIBox($path,base)]
ImageListbox selset $path $ix
set GMIBox($path,anchor) $ix
return
}
proc ImageListboxECButton {path y} {
# mouse control-button-1 on ImageListbox entry
global GMIBox
if { $GMIBox($path,mode) != "extended" } { return }
set ix [expr int($y/$GMIBox($path,eh))+$GMIBox($path,base)]
if { [lsearch -exact $GMIBox($path,sel) $ix] != -1 } {
ImageListbox selclr $path $ix
set GMIBox($path,anchor) ""
} else {
ImageListbox selset $path $ix
set GMIBox($path,anchor) $ix
}
return
}
proc ImageListboxESButton {path y} {
# mouse shift-button-1 on ImageListbox entry
global GMIBox
if { $GMIBox($path,mode) != "extended" } { return }
if { [set a $GMIBox($path,anchor)] == "" } {
ImageListboxEButton $path $y
return
}
if { [set ix [expr int($y/$GMIBox($path,eh))+$GMIBox($path,base)]] \
!= $a } {
if { $ix > $a } {
ImageListbox selset $path $a $ix
} else { ImageListbox selset $path $ix $a }
}
set GMIBox($path,anchor) $ix
return
}
|