summaryrefslogtreecommitdiff
path: root/cad/src/ne1_ui/prefs/Preferences.py
blob: 59b164ebecd0e835f145a2f399b6bdaee6d5f23b (plain)
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
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
2056
2057
2058
2059
2060
2061
2062
2063
2064
2065
2066
2067
2068
2069
2070
2071
2072
2073
2074
2075
2076
2077
2078
2079
2080
2081
2082
2083
2084
2085
2086
2087
2088
2089
2090
2091
2092
2093
2094
2095
2096
2097
2098
2099
2100
2101
2102
2103
2104
2105
2106
2107
2108
2109
2110
2111
2112
2113
2114
2115
2116
2117
2118
2119
2120
2121
2122
2123
2124
2125
2126
2127
2128
2129
2130
2131
2132
2133
2134
2135
2136
2137
2138
2139
2140
2141
2142
2143
2144
2145
2146
2147
2148
2149
2150
2151
2152
2153
2154
2155
2156
2157
2158
2159
2160
2161
2162
2163
2164
2165
2166
2167
2168
2169
2170
2171
2172
2173
2174
2175
2176
2177
2178
2179
2180
2181
2182
2183
2184
2185
2186
2187
2188
2189
2190
2191
2192
2193
2194
2195
2196
2197
2198
2199
2200
2201
2202
2203
2204
2205
2206
2207
2208
2209
2210
2211
2212
2213
2214
2215
2216
2217
2218
2219
2220
2221
2222
2223
2224
2225
2226
2227
2228
2229
2230
2231
2232
2233
2234
2235
2236
2237
2238
2239
2240
2241
2242
2243
2244
2245
2246
2247
2248
2249
2250
2251
2252
2253
2254
2255
2256
2257
2258
2259
2260
2261
2262
2263
2264
2265
2266
2267
2268
2269
2270
2271
2272
2273
2274
2275
2276
2277
2278
2279
2280
2281
2282
2283
2284
2285
2286
2287
2288
2289
2290
2291
2292
2293
2294
2295
2296
2297
2298
2299
2300
2301
2302
2303
2304
2305
2306
2307
2308
2309
2310
2311
2312
2313
2314
2315
2316
2317
2318
2319
2320
2321
2322
2323
2324
2325
2326
2327
2328
2329
2330
2331
2332
2333
2334
2335
2336
2337
2338
2339
2340
2341
2342
2343
2344
2345
2346
2347
2348
2349
2350
2351
2352
2353
2354
2355
2356
2357
2358
2359
2360
2361
2362
2363
2364
2365
2366
2367
2368
2369
2370
2371
2372
2373
2374
2375
2376
2377
2378
2379
2380
2381
2382
2383
2384
2385
2386
2387
2388
2389
2390
2391
2392
2393
2394
2395
2396
2397
2398
2399
2400
2401
2402
2403
2404
2405
2406
2407
2408
2409
2410
2411
2412
2413
2414
2415
2416
2417
2418
2419
2420
2421
2422
2423
2424
2425
2426
2427
2428
2429
2430
2431
2432
2433
2434
2435
2436
2437
2438
2439
2440
2441
2442
2443
2444
2445
2446
2447
2448
2449
2450
2451
2452
2453
2454
2455
2456
2457
2458
2459
2460
2461
2462
2463
2464
2465
2466
2467
2468
2469
2470
2471
2472
2473
2474
2475
2476
2477
2478
2479
2480
2481
2482
2483
2484
2485
2486
2487
2488
2489
2490
2491
2492
2493
2494
2495
2496
2497
2498
2499
2500
2501
2502
2503
2504
2505
2506
2507
2508
2509
2510
2511
2512
2513
2514
2515
2516
2517
2518
2519
2520
2521
2522
2523
2524
2525
2526
2527
2528
2529
2530
2531
2532
2533
2534
2535
2536
2537
2538
2539
2540
2541
2542
2543
2544
2545
2546
2547
2548
2549
2550
2551
2552
2553
2554
2555
2556
2557
2558
2559
2560
2561
2562
2563
2564
2565
2566
2567
2568
2569
2570
2571
2572
2573
2574
2575
2576
2577
2578
2579
2580
2581
2582
2583
2584
2585
2586
2587
2588
2589
2590
2591
2592
2593
2594
2595
2596
2597
2598
2599
2600
2601
2602
2603
2604
2605
2606
2607
2608
2609
2610
2611
2612
2613
2614
2615
2616
2617
2618
2619
2620
2621
2622
2623
2624
2625
2626
2627
2628
2629
2630
2631
2632
2633
2634
2635
2636
2637
2638
2639
2640
2641
2642
2643
2644
2645
2646
2647
2648
2649
2650
2651
2652
2653
2654
2655
2656
2657
2658
2659
2660
2661
2662
2663
2664
2665
2666
2667
2668
2669
2670
2671
2672
2673
2674
2675
2676
2677
2678
2679
2680
2681
2682
2683
2684
2685
2686
2687
2688
2689
2690
2691
2692
2693
2694
2695
2696
2697
2698
2699
2700
2701
2702
2703
2704
2705
2706
2707
2708
2709
2710
2711
2712
2713
2714
2715
2716
2717
2718
2719
2720
2721
2722
2723
2724
2725
2726
2727
2728
2729
2730
2731
2732
2733
2734
2735
2736
2737
2738
2739
2740
2741
2742
2743
2744
2745
2746
2747
2748
2749
2750
2751
2752
2753
2754
2755
2756
2757
2758
2759
2760
2761
2762
2763
2764
2765
2766
2767
2768
2769
2770
2771
2772
2773
2774
2775
2776
2777
2778
2779
2780
2781
2782
2783
2784
2785
2786
2787
2788
2789
2790
2791
2792
2793
2794
2795
2796
2797
2798
2799
2800
2801
2802
2803
2804
2805
2806
2807
2808
2809
2810
2811
2812
2813
2814
2815
2816
2817
2818
2819
2820
2821
2822
2823
2824
2825
2826
2827
2828
2829
2830
2831
2832
2833
2834
2835
2836
2837
2838
2839
2840
2841
2842
2843
2844
2845
2846
2847
2848
2849
2850
2851
2852
2853
2854
2855
2856
2857
2858
2859
2860
2861
2862
2863
2864
2865
2866
2867
2868
2869
2870
2871
2872
2873
2874
2875
2876
2877
2878
2879
2880
2881
2882
2883
2884
2885
2886
2887
2888
2889
2890
2891
2892
2893
2894
2895
2896
2897
2898
2899
2900
2901
2902
2903
2904
2905
2906
2907
2908
2909
2910
2911
2912
2913
2914
2915
2916
2917
2918
2919
2920
2921
2922
2923
2924
2925
2926
2927
2928
2929
2930
2931
2932
2933
2934
2935
2936
2937
2938
2939
2940
2941
2942
2943
2944
2945
2946
2947
2948
2949
2950
2951
2952
2953
2954
2955
2956
2957
2958
2959
2960
2961
2962
2963
2964
2965
2966
2967
2968
2969
2970
2971
2972
2973
2974
2975
2976
2977
2978
2979
2980
2981
2982
2983
2984
2985
2986
2987
2988
2989
2990
2991
2992
2993
2994
2995
2996
2997
2998
2999
3000
3001
3002
3003
3004
3005
3006
3007
3008
3009
3010
3011
3012
3013
3014
3015
3016
3017
3018
3019
3020
3021
3022
3023
3024
3025
3026
3027
3028
3029
3030
3031
3032
3033
3034
3035
3036
3037
3038
3039
3040
3041
3042
3043
3044
3045
3046
3047
3048
3049
3050
3051
3052
3053
3054
3055
3056
3057
3058
3059
3060
3061
3062
3063
3064
3065
3066
3067
3068
3069
3070
3071
3072
3073
3074
3075
3076
3077
3078
3079
3080
3081
3082
3083
3084
3085
3086
3087
3088
3089
3090
3091
3092
3093
3094
3095
3096
3097
3098
3099
3100
3101
3102
3103
3104
3105
3106
3107
3108
3109
3110
3111
3112
3113
3114
3115
3116
3117
3118
3119
3120
3121
3122
3123
3124
3125
3126
3127
3128
3129
3130
3131
3132
3133
3134
3135
3136
3137
3138
3139
3140
3141
3142
3143
3144
3145
3146
3147
3148
3149
3150
3151
3152
3153
3154
3155
3156
3157
3158
3159
3160
3161
3162
3163
3164
3165
3166
3167
3168
3169
3170
3171
3172
3173
3174
3175
3176
3177
3178
3179
3180
3181
3182
3183
3184
3185
3186
3187
3188
3189
3190
3191
3192
3193
3194
3195
3196
3197
3198
3199
3200
3201
3202
3203
3204
3205
3206
3207
3208
3209
3210
3211
3212
3213
3214
3215
3216
3217
3218
3219
3220
3221
3222
3223
3224
3225
3226
3227
3228
3229
3230
3231
3232
3233
3234
3235
3236
3237
3238
3239
3240
3241
3242
3243
3244
3245
3246
3247
3248
3249
3250
3251
3252
3253
3254
3255
3256
3257
3258
3259
3260
3261
3262
3263
3264
3265
3266
3267
3268
3269
3270
3271
3272
3273
3274
3275
3276
3277
3278
3279
3280
3281
3282
3283
3284
3285
3286
3287
3288
3289
3290
3291
3292
3293
3294
3295
3296
3297
3298
3299
3300
3301
3302
3303
3304
3305
3306
3307
3308
3309
3310
3311
3312
3313
3314
3315
3316
3317
3318
3319
3320
3321
3322
3323
3324
3325
3326
3327
3328
3329
3330
3331
3332
3333
3334
3335
3336
3337
3338
3339
3340
3341
3342
3343
3344
3345
3346
3347
3348
3349
3350
3351
3352
3353
3354
3355
3356
3357
3358
3359
3360
3361
3362
3363
3364
3365
3366
3367
3368
3369
3370
3371
3372
3373
3374
3375
3376
3377
3378
3379
3380
3381
3382
3383
3384
3385
3386
3387
3388
3389
3390
3391
3392
3393
3394
3395
3396
3397
3398
3399
3400
3401
3402
3403
3404
3405
3406
3407
3408
3409
3410
3411
3412
3413
3414
3415
3416
3417
3418
3419
3420
3421
3422
3423
3424
3425
3426
3427
3428
3429
3430
3431
3432
3433
3434
3435
3436
3437
3438
3439
3440
3441
3442
3443
3444
3445
3446
3447
3448
3449
3450
3451
3452
3453
3454
3455
3456
3457
3458
3459
3460
3461
3462
3463
3464
3465
3466
3467
3468
3469
3470
3471
3472
3473
3474
3475
3476
3477
3478
3479
3480
3481
3482
3483
3484
3485
3486
3487
3488
3489
3490
3491
3492
3493
3494
3495
3496
3497
3498
3499
3500
3501
3502
3503
3504
3505
3506
3507
3508
3509
3510
3511
3512
3513
3514
3515
3516
3517
3518
3519
3520
3521
3522
3523
3524
3525
3526
3527
3528
3529
3530
3531
3532
3533
3534
3535
3536
3537
3538
3539
3540
3541
3542
3543
3544
3545
3546
3547
3548
3549
3550
3551
3552
3553
3554
3555
3556
3557
3558
3559
3560
3561
3562
3563
3564
3565
3566
3567
3568
3569
3570
3571
3572
3573
3574
3575
3576
3577
3578
3579
3580
3581
3582
3583
3584
3585
3586
3587
3588
3589
3590
3591
3592
3593
3594
3595
3596
3597
3598
3599
3600
3601
3602
3603
3604
3605
3606
3607
3608
3609
3610
3611
3612
3613
3614
3615
3616
3617
3618
3619
3620
3621
3622
3623
3624
3625
3626
3627
3628
3629
3630
3631
3632
3633
3634
3635
3636
3637
3638
3639
3640
3641
3642
3643
3644
3645
3646
3647
3648
3649
3650
3651
3652
3653
3654
3655
3656
3657
3658
3659
3660
3661
3662
3663
3664
3665
3666
3667
3668
3669
3670
3671
3672
3673
3674
3675
3676
3677
3678
3679
3680
3681
3682
3683
3684
3685
3686
3687
3688
3689
3690
3691
3692
3693
3694
3695
3696
3697
3698
3699
3700
3701
3702
3703
3704
3705
3706
3707
3708
3709
3710
3711
3712
3713
3714
3715
3716
3717
3718
3719
3720
3721
3722
3723
3724
3725
3726
3727
3728
3729
3730
3731
3732
3733
3734
3735
3736
3737
3738
3739
3740
3741
3742
3743
3744
# Copyright 2005-2008 Nanorex, Inc.  See LICENSE file for details.
"""
Preferences.py

@author: Mark
@version: $Id$
@copyright: 2005-2008 Nanorex, Inc.  See LICENSE file for details.

History:
-Mark 2008-05-20: Created by Mark from a copy of UserPrefs.py
"""

import os, sys

from PyQt4 import QtCore, QtGui
from PyQt4.Qt import QDialog
from PyQt4.Qt import QFileDialog
from PyQt4.Qt import QMessageBox
from PyQt4.Qt import QButtonGroup
from PyQt4.Qt import QAbstractButton
from PyQt4.Qt import QDoubleValidator
from PyQt4.Qt import SIGNAL
from PyQt4.Qt import QPalette
from PyQt4.Qt import QColorDialog
from PyQt4.Qt import QString
from PyQt4.Qt import QFont
from PyQt4.Qt import Qt
from PyQt4.Qt import QWhatsThis
from PyQt4.Qt import QTreeWidget
from PyQt4.Qt import QSize

from ne1_ui.prefs.PreferencesDialog import Ui_PreferencesDialog
import foundation.preferences as preferences
from utilities.debug import print_compact_traceback
from utilities.debug_prefs import debug_pref, Choice_boolean_False
import foundation.env as env
from widgets.widget_helpers import RGBf_to_QColor, QColor_to_RGBf
from widgets.widget_helpers import double_fixup
from widgets.prefs_widgets import connect_colorpref_to_colorframe, connect_checkbox_with_boolean_pref
from utilities import debug_flags
from utilities.constants import str_or_unicode
from platform_dependent.PlatformDependent import screen_pos_size
from platform_dependent.PlatformDependent import get_rootdir
from platform_dependent.Paths import get_default_plugin_path
from utilities.icon_utilities import geticon

from utilities.prefs_constants import displayCompass_prefs_key
from utilities.prefs_constants import displayCompassLabels_prefs_key
from utilities.prefs_constants import displayPOVAxis_prefs_key
from utilities.prefs_constants import displayConfirmationCorner_prefs_key
from utilities.prefs_constants import enableAntiAliasing_prefs_key
from utilities.prefs_constants import animateStandardViews_prefs_key
from utilities.prefs_constants import displayVertRuler_prefs_key
from utilities.prefs_constants import displayHorzRuler_prefs_key
from utilities.prefs_constants import rulerPosition_prefs_key
from utilities.prefs_constants import rulerColor_prefs_key
from utilities.prefs_constants import rulerOpacity_prefs_key
from utilities.prefs_constants import showRulersInPerspectiveView_prefs_key
from utilities.prefs_constants import Adjust_watchRealtimeMinimization_prefs_key
from utilities.prefs_constants import Adjust_minimizationEngine_prefs_key
from utilities.prefs_constants import electrostaticsForDnaDuringAdjust_prefs_key
from utilities.prefs_constants import Adjust_cutoverRMS_prefs_key
from utilities.prefs_constants import qutemol_enabled_prefs_key
from utilities.prefs_constants import qutemol_path_prefs_key
from utilities.prefs_constants import nanohive_enabled_prefs_key
from utilities.prefs_constants import nanohive_path_prefs_key
from utilities.prefs_constants import povray_enabled_prefs_key
from utilities.prefs_constants import povray_path_prefs_key
from utilities.prefs_constants import megapov_enabled_prefs_key
from utilities.prefs_constants import megapov_path_prefs_key
from utilities.prefs_constants import povdir_enabled_prefs_key
from utilities.prefs_constants import gamess_enabled_prefs_key
from utilities.prefs_constants import gmspath_prefs_key
from utilities.prefs_constants import gromacs_enabled_prefs_key
from utilities.prefs_constants import gromacs_path_prefs_key
from utilities.prefs_constants import cpp_enabled_prefs_key
from utilities.prefs_constants import cpp_path_prefs_key
from utilities.prefs_constants import rosetta_enabled_prefs_key
from utilities.prefs_constants import rosetta_path_prefs_key
from utilities.prefs_constants import rosetta_database_enabled_prefs_key
from utilities.prefs_constants import rosetta_dbdir_prefs_key
from utilities.prefs_constants import nv1_enabled_prefs_key
from utilities.prefs_constants import nv1_path_prefs_key
from utilities.prefs_constants import startupGlobalDisplayStyle_prefs_key
from utilities.prefs_constants import buildModeAutobondEnabled_prefs_key
from utilities.prefs_constants import buildModeWaterEnabled_prefs_key
from utilities.prefs_constants import buildModeHighlightingEnabled_prefs_key
from utilities.prefs_constants import buildModeSelectAtomsOfDepositedObjEnabled_prefs_key
from utilities.prefs_constants import light1Color_prefs_key
from utilities.prefs_constants import light2Color_prefs_key
from utilities.prefs_constants import light3Color_prefs_key
from utilities.prefs_constants import atomHighlightColor_prefs_key
from utilities.prefs_constants import bondpointHighlightColor_prefs_key
from utilities.prefs_constants import levelOfDetail_prefs_key
from utilities.prefs_constants import diBALL_AtomRadius_prefs_key
from utilities.prefs_constants import cpkScaleFactor_prefs_key
from utilities.prefs_constants import showBondStretchIndicators_prefs_key
from utilities.prefs_constants import showValenceErrors_prefs_key

#General  page prefs - paste offset scale for chunk and dna pasting prefs key
from utilities.prefs_constants import pasteOffsetScaleFactorForChunks_prefs_key
from utilities.prefs_constants import pasteOffsetScaleFactorForDnaObjects_prefs_key

# Color (page) prefs
from utilities.prefs_constants import backgroundColor_prefs_key
from utilities.prefs_constants import backgroundGradient_prefs_key
from utilities.prefs_constants import hoverHighlightingColorStyle_prefs_key
from utilities.prefs_constants import hoverHighlightingColor_prefs_key
from utilities.prefs_constants import selectionColorStyle_prefs_key
from utilities.prefs_constants import selectionColor_prefs_key
from utilities.prefs_constants import haloWidth_prefs_key

# Mouse wheel prefs
from utilities.prefs_constants import mouseWheelDirection_prefs_key
from utilities.prefs_constants import zoomInAboutScreenCenter_prefs_key
from utilities.prefs_constants import zoomOutAboutScreenCenter_prefs_key
from utilities.prefs_constants import mouseWheelTimeoutInterval_prefs_key

# Pan settings
from utilities.prefs_constants import panArrowKeysDirection_prefs_key

# DNA prefs
from utilities.prefs_constants import bdnaBasesPerTurn_prefs_key
from utilities.prefs_constants import bdnaRise_prefs_key
from utilities.prefs_constants import dnaDefaultStrand1Color_prefs_key
from utilities.prefs_constants import dnaDefaultStrand2Color_prefs_key
from utilities.prefs_constants import dnaDefaultSegmentColor_prefs_key
from utilities.prefs_constants import dnaStrutScaleFactor_prefs_key
from utilities.prefs_constants import arrowsOnBackBones_prefs_key
from utilities.prefs_constants import arrowsOnThreePrimeEnds_prefs_key
from utilities.prefs_constants import arrowsOnFivePrimeEnds_prefs_key
from utilities.prefs_constants import useCustomColorForThreePrimeArrowheads_prefs_key
from utilities.prefs_constants import dnaStrandThreePrimeArrowheadsCustomColor_prefs_key
from utilities.prefs_constants import useCustomColorForFivePrimeArrowheads_prefs_key
from utilities.prefs_constants import dnaStrandFivePrimeArrowheadsCustomColor_prefs_key

# DNA Minor Groove Error Indicator prefs
from utilities.prefs_constants import dnaDisplayMinorGrooveErrorIndicators_prefs_key
from utilities.prefs_constants import dnaMinMinorGrooveAngle_prefs_key
from utilities.prefs_constants import dnaMaxMinorGrooveAngle_prefs_key
from utilities.prefs_constants import dnaMinorGrooveErrorIndicatorColor_prefs_key

# DNA style prefs 080310 piotr
from utilities.prefs_constants import dnaStyleStrandsShape_prefs_key
from utilities.prefs_constants import dnaStyleStrandsColor_prefs_key
from utilities.prefs_constants import dnaStyleStrandsScale_prefs_key
from utilities.prefs_constants import dnaStyleStrandsArrows_prefs_key
from utilities.prefs_constants import dnaStyleAxisShape_prefs_key
from utilities.prefs_constants import dnaStyleAxisColor_prefs_key
from utilities.prefs_constants import dnaStyleAxisScale_prefs_key
from utilities.prefs_constants import dnaStyleAxisEndingStyle_prefs_key
from utilities.prefs_constants import dnaStyleStrutsShape_prefs_key
from utilities.prefs_constants import dnaStyleStrutsColor_prefs_key
from utilities.prefs_constants import dnaStyleStrutsScale_prefs_key
from utilities.prefs_constants import dnaStyleBasesShape_prefs_key
from utilities.prefs_constants import dnaStyleBasesColor_prefs_key
from utilities.prefs_constants import dnaStyleBasesScale_prefs_key

# DNA labels and base indicators. 080325 piotr
from utilities.prefs_constants import dnaStrandLabelsEnabled_prefs_key
from utilities.prefs_constants import dnaStrandLabelsColor_prefs_key
from utilities.prefs_constants import dnaStrandLabelsColorMode_prefs_key
from utilities.prefs_constants import dnaBaseIndicatorsEnabled_prefs_key
from utilities.prefs_constants import dnaBaseInvIndicatorsEnabled_prefs_key
from utilities.prefs_constants import dnaBaseIndicatorsAngle_prefs_key
from utilities.prefs_constants import dnaBaseIndicatorsColor_prefs_key
from utilities.prefs_constants import dnaBaseInvIndicatorsColor_prefs_key
from utilities.prefs_constants import dnaBaseIndicatorsDistance_prefs_key
from utilities.prefs_constants import dnaStyleBasesDisplayLetters_prefs_key
from utilities.prefs_constants import dnaBaseIndicatorsPlaneNormal_prefs_key

# Undo prefs
from utilities.prefs_constants import undoRestoreView_prefs_key
from utilities.prefs_constants import undoAutomaticCheckpoints_prefs_key
from utilities.prefs_constants import undoStackMemoryLimit_prefs_key
from utilities.prefs_constants import historyMsgSerialNumber_prefs_key
from utilities.prefs_constants import historyMsgTimestamp_prefs_key
from utilities.prefs_constants import historyHeight_prefs_key
from utilities.prefs_constants import rememberWinPosSize_prefs_key
from utilities.prefs_constants import captionFullPath_prefs_key
from utilities.prefs_constants import dynamicToolTipAtomChunkInfo_prefs_key
from utilities.prefs_constants import dynamicToolTipAtomMass_prefs_key
from utilities.prefs_constants import dynamicToolTipAtomPosition_prefs_key
from utilities.prefs_constants import dynamicToolTipAtomDistanceDeltas_prefs_key
from utilities.prefs_constants import dynamicToolTipBondLength_prefs_key
from utilities.prefs_constants import dynamicToolTipBondChunkInfo_prefs_key
from utilities.prefs_constants import dynamicToolTipAtomDistancePrecision_prefs_key
from utilities.prefs_constants import captionPrefix_prefs_key
from utilities.prefs_constants import captionSuffix_prefs_key
from utilities.prefs_constants import compassPosition_prefs_key
from utilities.prefs_constants import defaultProjection_prefs_key
from utilities.prefs_constants import displayOriginAsSmallAxis_prefs_key
from utilities.prefs_constants import displayOriginAxis_prefs_key
from utilities.prefs_constants import animateMaximumTime_prefs_key
from utilities.prefs_constants import mouseSpeedDuringRotation_prefs_key
from utilities.prefs_constants import Adjust_endRMS_prefs_key
from utilities.prefs_constants import Adjust_endMax_prefs_key
from utilities.prefs_constants import Adjust_cutoverMax_prefs_key
from utilities.prefs_constants import sponsor_permanent_permission_prefs_key
from utilities.prefs_constants import sponsor_download_permission_prefs_key
from utilities.prefs_constants import bondpointHotspotColor_prefs_key
from utilities.prefs_constants import diBALL_bondcolor_prefs_key
from utilities.prefs_constants import bondHighlightColor_prefs_key
from utilities.prefs_constants import bondStretchColor_prefs_key
from utilities.prefs_constants import bondVaneColor_prefs_key
from utilities.prefs_constants import pibondStyle_prefs_key
from utilities.prefs_constants import pibondLetters_prefs_key
from utilities.prefs_constants import linesDisplayModeThickness_prefs_key
from utilities.prefs_constants import diBALL_BondCylinderRadius_prefs_key
from utilities.prefs_constants import material_specular_highlights_prefs_key
from utilities.prefs_constants import material_specular_shininess_prefs_key
from utilities.prefs_constants import material_specular_brightness_prefs_key
from utilities.prefs_constants import material_specular_finish_prefs_key
from utilities.prefs_constants import povdir_path_prefs_key
from utilities.prefs_constants import dynamicToolTipBendAnglePrecision_prefs_key
from utilities.prefs_constants import dynamicToolTipVdwRadiiInAtomDistance_prefs_key
from utilities.prefs_constants import displayFontPointSize_prefs_key
from utilities.prefs_constants import useSelectedFont_prefs_key
from utilities.prefs_constants import displayFont_prefs_key
from utilities.prefs_constants import keepBondsDuringTransmute_prefs_key
from utilities.prefs_constants import indicateOverlappingAtoms_prefs_key
from utilities.prefs_constants import fogEnabled_prefs_key

# Cursor text prefs.
from utilities.prefs_constants import cursorTextFontSize_prefs_key
from utilities.prefs_constants import cursorTextColor_prefs_key

#global display preferences
from utilities.constants import diDEFAULT ,diTrueCPK, diLINES
from utilities.constants import diBALL, diTUBES, diDNACYLINDER

from utilities.constants import black, white, gray
from widgets.prefs_widgets import connect_doubleSpinBox_with_pref
# =
# Preferences widgets constants. I suggest that these be moved to another
# file (i.e. prefs_constants.py or another file). Discuss with Bruce. -Mark

# Widget constants for the "Graphics Area" page.

BG_BLUE_SKY = 0
BG_EVENING_SKY = 1
BG_SEAGREEN = 2
BG_BLACK = 3
BG_WHITE = 4
BG_GRAY = 5
BG_CUSTOM = 6

# GDS = global display style
GDS_INDEXES = [diLINES, diTUBES, diBALL, diTrueCPK, diDNACYLINDER]
GDS_NAMES   = ["Lines", "Tubes", "Ball and Stick", "CPK", "DNA Cylinder"]
GDS_ICONS   = ["Lines", "Tubes", "Ball_and_Stick", "CPK", "DNACylinder" ]

# Widget constants for the "Colors" page.

# HHS = hover highlighting styles
from utilities.prefs_constants import HHS_HALO
from utilities.prefs_constants import HHS_SOLID
from utilities.prefs_constants import HHS_SCREENDOOR1
from utilities.prefs_constants import HHS_CROSSHATCH1
from utilities.prefs_constants import HHS_BW_PATTERN
from utilities.prefs_constants import HHS_POLYGON_EDGES
from utilities.prefs_constants import HHS_DISABLED
from utilities.prefs_constants import HHS_INDEXES
from utilities.prefs_constants import HHS_OPTIONS

# SS = selection styles
from utilities.prefs_constants import SS_HALO
from utilities.prefs_constants import SS_SOLID
from utilities.prefs_constants import SS_SCREENDOOR1
from utilities.prefs_constants import SS_CROSSHATCH1
from utilities.prefs_constants import SS_BW_PATTERN
from utilities.prefs_constants import SS_POLYGON_EDGES
from utilities.prefs_constants import SS_INDEXES
from utilities.prefs_constants import SS_OPTIONS

# = end of Preferences widgets constants.

debug_sliders = False # Do not commit as True

def debug_povdir_signals():
    return 0 and env.debug()

# This list of mode names correspond to the names listed in the modes combo box.
# [TODO: It needs to be renamed, since "modes" is too generic to search for
#  as a global name, which in theory could referenced from other modules.]
modes = ['SELECTMOLS', 'MODIFY', 'DEPOSIT', 'CRYSTAL', 'EXTRUDE', 'FUSECHUNKS', 'MOVIE']
    ### REVIEW: is this constant still used anywhere?
    # If not, it should be removed.
    # [bruce 080815 question]

def parentless_open_dialog_pref(): #bruce 060710 for Mac A8
    # see if setting this True fixes the Mac-specific bugs in draggability of this dialog, and CPU usage while it's up
    from utilities.debug_prefs import debug_pref, Choice_boolean_False
    return debug_pref("parentless open file dialogs?", Choice_boolean_False,
                      prefs_key = "A8.1 devel/parentless open file dialogs")

parentless_open_dialog_pref()

def get_filename_and_save_in_prefs(parent, prefs_key, caption=''):
    """
    Present user with the Qt file chooser to select a file.
    prefs_key is the key to save the filename in the prefs db
    caption is the string for the dialog caption.
    """
    # see also get_dirname_and_save_in_prefs, which has similar code

    if parentless_open_dialog_pref():
        parent = None

    filename = str_or_unicode(QFileDialog.getOpenFileName(
        parent,
        caption,
        get_rootdir(), # '/' on Mac or Linux, something else on Windows
    ))

    if not filename: # Cancelled.
        return None

    # Save filename in prefs db.
    prefs = preferences.prefs_context()
    prefs[prefs_key] = os.path.normpath(filename)

    return filename

def get_dirname_and_save_in_prefs(parent, prefs_key, caption=''): #bruce 060710 for Mac A8
    """
    Present user with the Qt file chooser to select an existing directory.
    If they do that, and if prefs_key is not null, save its full pathname in
    env.prefs[prefs_key].

    @param prefs_key: the pref_key to save the pathname.
    @type  prefs_key: text

    @param caption: the string for the dialog caption.
    @type  caption: text
    """
    # see also get_filename_and_save_in_prefs, which has similar code

    if parentless_open_dialog_pref():
        parent = None

    filename = str_or_unicode(QFileDialog.getExistingDirectory(
        parent,### if this was None, it might fix the Mac bug where you can't drag the dialog around [bruce 060710]
        caption,
        get_rootdir(), # '/' on Mac or Linux -- maybe not the best choice if they've chosen one before?
    ))

    if not filename: # Cancelled.
        return None

    # Save filename in prefs db.
    prefs = preferences.prefs_context()
    prefs[prefs_key] = filename

    return filename

# main window layout save/restore

def _fullkey(keyprefix, *subkeys): #e this func belongs in preferences.py
    res = keyprefix
    for subkey in subkeys:
        res += "/" + subkey
    return res

def _size_pos_keys( keyprefix):
    return _fullkey(keyprefix, "geometry", "size"), _fullkey(keyprefix, "geometry", "pos")

def _tupleFromQPoint(qpoint):
    return qpoint.x(), qpoint.y()

def _tupleFromQSize(qsize):
    return qsize.width(), qsize.height()

def _get_window_pos_size(win):
    size = _tupleFromQSize( win.size())
    pos = _tupleFromQPoint( win.pos())
    return pos, size

def save_window_pos_size( win, keyprefix): #bruce 050913 removed histmessage arg
    """
    Save the size and position of the given main window, win,
    in the preferences database, using keys based on the given keyprefix,
    which caller ought to reserve for geometry aspects of the main window.
    (#e Someday, maybe save more aspects like dock layout and splitter bar
    positions??)
    """
##    from preferences import prefs_context
##    prefs = prefs_context()
    ksize, kpos = _size_pos_keys( keyprefix)
    pos, size = _get_window_pos_size(win)
    changes = { ksize: size, kpos: pos }
    env.prefs.update( changes) # use update so it only opens/closes dbfile once
    env.history.message("saved window position %r and size %r" % (pos,size))
    return

def load_window_pos_size( win, keyprefix, defaults = None, screen = None): #bruce 050913 removed histmessage arg; 060517 revised
    """
    Load the last-saved size and position of the given main window, win,
    from the preferences database, using keys based on the given keyprefix,
    which caller ought to reserve for geometry aspects of the main window.
    (If no prefs have been stored, return reasonable or given defaults.)
       Then set win's actual position and size (using supplied defaults, and
    limited by supplied screen size, both given as ((pos_x,pos_y),(size_x,size_y)).
    (#e Someday, maybe restore more aspects like dock layout and splitter bar
    positions??)
    """
    if screen is None:
        screen = screen_pos_size()
    ((x0, y0), (w, h)) = screen
    x1 = x0 + w
    y1 = y0 + h

    pos, size = _get_prefs_for_window_pos_size( win, keyprefix, defaults)
    # now use pos and size, within limits set by screen
    px, py = pos
    sx, sy = size
    if sx > w: sx = w
    if sy > h: sy = h
    if px < x0: px = x0
    if py < y0: py = y0
    if px > x1 - sx: px = x1 - sx
    if py > y1 - sy: py = y1 - sy
    env.history.message("restoring last-saved window position %r and size %r" \
                        % ((px, py),(sx, sy)))
    win.resize(sx, sy)
    win.move(px, py)
    return

def _get_prefs_for_window_pos_size( win, keyprefix, defaults = None):
    """
    Load and return the last-saved size and position of the given main window, win,
    from the preferences database, using keys based on the given keyprefix,
    which caller ought to reserve for geometry aspects of the main window.
    (If no prefs have been stored, return reasonable or given defaults.)
    """
    #bruce 060517 split this out of load_window_pos_size
    if defaults is None:
        defaults = _get_window_pos_size(win)
    dpos, dsize = defaults
    px, py = dpos # check correctness of args, even if not used later
    sx, sy = dsize
    import foundation.preferences as preferences
    prefs = preferences.prefs_context()
    ksize, kpos = _size_pos_keys( keyprefix)
    pos = prefs.get(kpos, dpos)
    size = prefs.get(ksize, dsize)
    return pos, size

def validate_gamess_path(parent, gmspath):
    """
    Checks that gmspath (GAMESS executable) exists.  If not, the user is asked
    if they want to use the File Chooser to select the GAMESS executable.
    This function does not check whether the GAMESS path is actually GAMESS
    or if it is the correct version of GAMESS for this platform (i.e. PC GAMESS
    for Windows).

    @return:  "gmspath" if it is validated or if the user does not want to
              change it for any reason, or
              "new_gmspath" if gmspath is invalid and the user selected a new
              GAMESS executable. Return value might be "".
    """

    if not gmspath: # It is OK if gmspath is empty.
        return ""
    elif os.path.exists(gmspath):
        return gmspath
    else:
        ret = QMessageBox.warning( parent, "GAMESS Executable Path",
                                   gmspath + " does not exist.\nDo you want to use the File Chooser to browse for the GAMESS executable?",
                                   "&Yes", "&No", "",
                                   0, 1 )

        if ret == 0: # Yes
            new_gmspath = get_gamess_path(parent)
            if not new_gmspath:
                return gmspath # Cancelled from file chooser.  Just return the original gmspath.
            else:
                return new_gmspath

        else: # No
            return gmspath

def get_pref_or_optval(key, val, optval):
    """
    Return <key>'s value. If <val> is equal to <key>'s value, return <optval>
    instead.
    """
    if env.prefs[key] == val:
        return optval
    else:
        return env.prefs[key]

class Preferences(QDialog, Ui_PreferencesDialog):
    """
    The Preferences dialog used for accessing and changing user
    preferences.
    """
    pagenameList = [] # List of page names in prefsStackedWidget.

    def __init__(self, assy):
        QDialog.__init__(self)
        self.setupUi(self)

        # Some important attrs.
        self.glpane = assy.o
        self.w = assy.w
        self.assy = assy
        self.pagenameList = self.getPagenameList()

        # Start of dialog setup.
        self._setupDialog_TopLevelWidgets()
        self._setupPage_General()
        self._setupPage_Color()
        self._setupPage_GraphicsArea()
        self._setupPage_ZoomPanRotate()
        self._setupPage_Rulers()
        self._setupPage_Atoms()
        self._setupPage_Bonds()
        self._setupPage_Dna()
        self._setupPage_DnaMinorGrooveErrorIndicator()
        self._setupPage_DnaBaseOrientationIndicators()
        self._setupPage_Adjust()
        self._setupPage_Lighting()
        self._setupPage_Plugins()
        self._setupPage_Undo()
        self._setupPage_Window()
        self._setupPage_Reports()
        self._setupPage_Tooltips()

        # Assign "What's This" text for all widgets.
        from ne1_ui.prefs.WhatsThisText_for_PreferencesDialog import whatsThis_PreferencesDialog
        whatsThis_PreferencesDialog(self)

        self._hideOrShowWidgets()
        return
    # End of _init_()

    def _setupDialog_TopLevelWidgets(self):
        """
        Setup all the main dialog widgets and their signal-slot connection(s).
        """

        self.setWindowIcon(geticon("ui/actions/Tools/Options.png"))

        # This connects the "itemSelectedChanged" signal generated when the
        # user selects an item in the "Category" QTreeWidget on the left
        # side of the Preferences dialog (inside the "Systems Option" tab)
        # to the slot for turning to the correct page in the QStackedWidget
        # on the right side.
        self.connect(self.categoryTreeWidget, SIGNAL("itemSelectionChanged()"), self.showPage)

        # Connections for OK and What's This buttons at the bottom of the dialog.
        self.connect(self.okButton, SIGNAL("clicked()"), self.accept)
        self.connect(self.whatsThisToolButton, SIGNAL("clicked()"),QWhatsThis.enterWhatsThisMode)

        self.whatsThisToolButton.setIcon(
            geticon("ui/actions/Properties Manager/WhatsThis.png"))
        self.whatsThisToolButton.setIconSize(QSize(22, 22))
        self.whatsThisToolButton.setToolTip('Enter "What\'s This?" help mode')

        # Set the margin and spacing for these two gridlayouts:
        # gridlayout  = grid layout for the Preference dialog
        # gridlayout1 = grid layout for the System Options tab
        self.gridlayout.setMargin(2)
        self.gridlayout.setSpacing(2)

        self.gridlayout1.setMargin(4)
        self.gridlayout1.setSpacing(0)
        return

    def _setupPage_General(self):
        """
        Setup the "General" page.
        """
        # Sponsor logos download permission options in General tab
        self.logosDownloadPermissionBtnGroup = QButtonGroup()
        self.logosDownloadPermissionBtnGroup.setExclusive(True)
        for button in self.sponsorLogosGroupBox.children():
            if isinstance(button, QAbstractButton):
                self.logosDownloadPermissionBtnGroup.addButton(button)
                buttonId = 0
                if button.text().startsWith("Never ask"):
                    buttonId = 1
                elif button.text().startsWith("Never download"):
                    buttonId = 2
                self.logosDownloadPermissionBtnGroup.setId(button, buttonId)

        # Check the correct permission radio button.
        if env.prefs[sponsor_permanent_permission_prefs_key]:
            if env.prefs[sponsor_download_permission_prefs_key]:
                self.logoNeverAskRadioBtn.setChecked(True)
            else:
                self.logoNeverDownLoadRadioBtn.setChecked(True)
        else:
            self.logoAlwaysAskRadioBtn.setChecked(True)

        self.connect(self.logosDownloadPermissionBtnGroup, SIGNAL("buttonClicked(int)"), self.setPrefsLogoDownloadPermissions)

        # Build Atoms option connections.
        connect_checkbox_with_boolean_pref( self.autobond_checkbox, buildModeAutobondEnabled_prefs_key )
        connect_checkbox_with_boolean_pref( self.water_checkbox, buildModeWaterEnabled_prefs_key )
        connect_checkbox_with_boolean_pref( self.buildmode_highlighting_checkbox, buildModeHighlightingEnabled_prefs_key )
        connect_checkbox_with_boolean_pref( self.buildmode_select_atoms_checkbox, buildModeSelectAtomsOfDepositedObjEnabled_prefs_key )

        #Scale factor for copy-paste operation (see ops_copy_Mixin._pasteGroup())

        self.pasteOffsetScaleFactorForChunks_doubleSpinBox.setValue(
            env.prefs[pasteOffsetScaleFactorForChunks_prefs_key])

        self.pasteOffsetScaleFactorForDnaObjects_doubleSpinBox.setValue(
            env.prefs[pasteOffsetScaleFactorForDnaObjects_prefs_key])



        self.connect(self.pasteOffsetScaleFactorForChunks_doubleSpinBox,
                     SIGNAL("valueChanged(double)"),
                     self.change_pasteOffsetScaleFactorForChunks)
        self.connect(self.pasteOffsetScaleFactorForDnaObjects_doubleSpinBox,
                     SIGNAL("valueChanged(double)"),
                     self.change_pasteOffsetScaleFactorForDnaObjects)
        return

    def _setupPage_Color(self):
        """
        Setup the "Color" page.
        """
        # Background color widgets and connection(s).
        self._loadBackgroundColorItems()
        self.connect(self.backgroundColorComboBox, SIGNAL("activated(int)"), self.changeBackgroundColor)

        # Fog checkbox
        connect_checkbox_with_boolean_pref( self.enableFogCheckBox, fogEnabled_prefs_key )
        self.connect(self.enableFogCheckBox, SIGNAL("toggled(bool)"), self.enable_fog)

        # Hover highlighting color style widgets and connection(s).
        self._loadHoverHighlightingColorStylesItems()
        self.hoverHighlightingStyleComboBox.setCurrentIndex(HHS_INDEXES.index(env.prefs[hoverHighlightingColorStyle_prefs_key]))
        self.connect(self.hoverHighlightingStyleComboBox, SIGNAL("activated(int)"), self._change_hhStyle)
        connect_colorpref_to_colorframe( hoverHighlightingColor_prefs_key, self.hoverHighlightingColorFrame)
        self.connect(self.hoverHighlightingColorButton, SIGNAL("clicked()"), self._change_hhColor)

        # Selection color style widgets and connection(s).
        self._loadSelectionColorStylesItems()
        self.selectionStyleComboBox.setCurrentIndex(SS_INDEXES.index(env.prefs[selectionColorStyle_prefs_key]))
        self.connect(self.selectionStyleComboBox, SIGNAL("activated(int)"), self._change_selectionStyle)
        connect_colorpref_to_colorframe( selectionColor_prefs_key, self.selectionColorFrame)
        self.connect(self.selectionColorButton, SIGNAL("clicked()"), self._change_selectionColor)

        # Halo width spinbox.
        self.connect(self.haloWidthSpinBox, SIGNAL("valueChanged(int)"), self.change_haloWidth)
        self.connect(self.haloWidthResetButton, SIGNAL("clicked()"), self.reset_haloWidth)

        self.haloWidthResetButton.setIcon(geticon('ui/dialogs/Reset.png'))
        self.haloWidthSpinBox.setValue(env.prefs[haloWidth_prefs_key])
        self.change_haloWidth(env.prefs[haloWidth_prefs_key]) # Needed to update the reset button.

        return

    def _setupPage_GraphicsArea(self):
        """
        Setup widgets to initial (default or defined) values on the
        'Graphics Area' page.
        """
        # Setup the Global Display Style at start-up combobox
        self._setupGlobalDisplayStyleAtStartup_ComboBox()


        self.connect(self.compassGroupBox, SIGNAL("stateChanged(int)"), self.display_compass)
        self.connect(self.compass_position_combox, SIGNAL("activated(int)"), self.set_compass_position)

        connect_checkbox_with_boolean_pref( self.compassGroupBox, displayCompass_prefs_key )
        connect_checkbox_with_boolean_pref( self.display_compass_labels_checkbox, displayCompassLabels_prefs_key )
        connect_checkbox_with_boolean_pref( self.display_origin_axis_checkbox, displayOriginAxis_prefs_key )
        connect_checkbox_with_boolean_pref( self.display_pov_axis_checkbox, displayPOVAxis_prefs_key )
        self.compass_position_combox.setCurrentIndex(self.glpane.compassPosition)

        connect_checkbox_with_boolean_pref( self.display_confirmation_corner_checkbox, displayConfirmationCorner_prefs_key )
        connect_checkbox_with_boolean_pref( self.enable_antialiasing_checkbox, enableAntiAliasing_prefs_key )

        # Cursor text font point size spinbox
        self.connect(self.cursorTextFontSizeSpinBox, SIGNAL("valueChanged(int)"), self.change_cursorTextFontSize)

        # Cursor text font size reset button.
        self.connect(self.cursorTextFontSizeResetButton, SIGNAL("clicked()"), self.reset_cursorTextFontSize)
        self.cursorTextFontSizeResetButton.setIcon(geticon('ui/dialogs/Reset.png'))
        self.cursorTextFontSizeSpinBox.setValue(env.prefs[ cursorTextFontSize_prefs_key ] )
        self.change_cursorTextFontSize(env.prefs[cursorTextFontSize_prefs_key]) # Needed to update the reset button.

        # Cursor text color
        connect_colorpref_to_colorframe(cursorTextColor_prefs_key, self.cursorTextColorFrame)
        self.connect(self.cursorTextColorButton, SIGNAL("clicked()"), self.change_cursorTextColor)
        return

    def _setupPage_ZoomPanRotate(self):
        """
        Setup widgets to initial (default or defined) values on the
        'Zoom, Pan Rotate' page.
        """

        # Animation speed checkbox and slider.
        connect_checkbox_with_boolean_pref( self.animate_views_checkbox, animateStandardViews_prefs_key )

        self.resetAnimationSpeed_btn.setIcon(
            geticon('ui/dialogs/Reset.png'))

        self.connect(self.animation_speed_slider, SIGNAL("sliderReleased()"), self.change_view_animation_speed)
        self.connect(self.resetAnimationSpeed_btn, SIGNAL("clicked()"), self.reset_animationSpeed)

        speed = int (env.prefs[animateMaximumTime_prefs_key] * -100)
        self.animation_speed_slider.setValue(speed)
        self._updateResetButton(self.resetAnimationSpeed_btn, animateMaximumTime_prefs_key)

        #mouse speed during rotation slider - ninad060906
        self.resetMouseSpeedDuringRotation_btn.setIcon(
            geticon('ui/dialogs/Reset.png'))

        self.connect(self.mouseSpeedDuringRotation_slider, SIGNAL("sliderReleased()"), self.change_mouseSpeedDuringRotation)
        self.connect(self.resetMouseSpeedDuringRotation_btn, SIGNAL("clicked()"), self.reset_mouseSpeedDuringRotation)

        mouseSpeedDuringRotation = int(env.prefs[mouseSpeedDuringRotation_prefs_key] * 100)
        self.mouseSpeedDuringRotation_slider.setValue(mouseSpeedDuringRotation)
        self._updateResetButton(self.resetMouseSpeedDuringRotation_btn, mouseSpeedDuringRotation_prefs_key)

        # Mouse wheel zoom settings combo boxes
        self.mouseWheelDirectionComboBox.setCurrentIndex(
            env.prefs[mouseWheelDirection_prefs_key])
        self.mouseWheelZoomInPointComboBox.setCurrentIndex(
            env.prefs[zoomInAboutScreenCenter_prefs_key])
        self.mouseWheelZoomOutPointComboBox.setCurrentIndex(
            env.prefs[zoomOutAboutScreenCenter_prefs_key])

        self.hhTimeoutIntervalDoubleSpinBox.setValue(env.prefs[mouseWheelTimeoutInterval_prefs_key])

        # Pan settings
        direction = env.prefs[panArrowKeysDirection_prefs_key]
        #  1 = View direcgion (default)
        # -1 = Camera direction
        if direction == 1:
            self.panArrowKeysDirectionComboBox.setCurrentIndex(0)
        else:
            self.panArrowKeysDirectionComboBox.setCurrentIndex(1)

        # Connections for "Mouse controls" page.
        self.connect(self.mouseWheelDirectionComboBox, SIGNAL("currentIndexChanged(int)"), self.set_mouse_wheel_direction)
        self.connect(self.mouseWheelZoomInPointComboBox, SIGNAL("currentIndexChanged(int)"), self.set_mouse_wheel_zoom_in_position)
        self.connect(self.mouseWheelZoomOutPointComboBox, SIGNAL("currentIndexChanged(int)"), self.set_mouse_wheel_zoom_out_position)
        self.connect(self.hhTimeoutIntervalDoubleSpinBox, SIGNAL("valueChanged(double)"), self.set_mouse_wheel_timeout_interval)
        self.connect(self.panArrowKeysDirectionComboBox, SIGNAL("currentIndexChanged(int)"), self.set_pan_arrow_keys_direction)
        return

    def _setupPage_Rulers(self):
        """
        Setup the "Rulers" page.
        """

        self.connect(self.rulerDisplayComboBox, SIGNAL("currentIndexChanged(int)"), self.set_ruler_display)
        self.connect(self.rulerPositionComboBox, SIGNAL("currentIndexChanged(int)"), self.set_ruler_position)
        self.connect(self.ruler_color_btn, SIGNAL("clicked()"), self.change_ruler_color)
        self.connect(self.rulerOpacitySpinBox, SIGNAL("valueChanged(int)"), self.change_ruler_opacity)

        if env.prefs[displayVertRuler_prefs_key] and env.prefs[displayHorzRuler_prefs_key]:
            self.rulerDisplayComboBox.setCurrentIndex(0)
        elif not env.prefs[displayHorzRuler_prefs_key]:
            self.rulerDisplayComboBox.setCurrentIndex(1)
        elif not env.prefs[displayVertRuler_prefs_key]:
            self.rulerDisplayComboBox.setCurrentIndex(2)

        self.rulerPositionComboBox.setCurrentIndex(env.prefs[rulerPosition_prefs_key])
        connect_colorpref_to_colorframe( rulerColor_prefs_key, self.ruler_color_frame)
        self.rulerOpacitySpinBox.setValue(int(env.prefs[rulerOpacity_prefs_key] * 100))
        connect_checkbox_with_boolean_pref( self.showRulersInPerspectiveViewCheckBox, showRulersInPerspectiveView_prefs_key )
        return

    def _setupPage_Atoms(self):
        """
        Setup the "Atoms" page.
        """

        # "Change Element Colors" button.
        self.connect(self.change_element_colors_btn, SIGNAL("clicked()"), self.change_element_colors)

        # Atom colors
        connect_colorpref_to_colorframe( atomHighlightColor_prefs_key, self.atom_hilite_color_frame)
        connect_colorpref_to_colorframe( bondpointHighlightColor_prefs_key, self.bondpoint_hilite_color_frame)
        connect_colorpref_to_colorframe( bondpointHotspotColor_prefs_key, self.hotspot_color_frame)
        self.connect(self.atom_hilite_color_btn, SIGNAL("clicked()"), self.change_atom_hilite_color)
        self.connect(self.bondpoint_hilite_color_btn, SIGNAL("clicked()"), self.change_bondpoint_hilite_color)
        self.connect(self.hotspot_color_btn, SIGNAL("clicked()"), self.change_hotspot_color)
        self.connect(self.reset_atom_colors_btn, SIGNAL("clicked()"), self.reset_atom_colors)

        # Level of detail.
        self.connect(self.level_of_detail_combox, SIGNAL("activated(int)"), self.change_level_of_detail)

        lod = env.prefs[ levelOfDetail_prefs_key ]
        lod = int(lod)
        loditem = lod # index of corresponding spinbox item -- this is only correct for 0,1,2; other cases handled below
        if lod <= -1: # 'variable' (only -1 is used now, but other negative values might be used in future)
            # [bruce 060215 changed prefs value for 'variable' from 3 to -1, in case we have more LOD levels in the future]
            # [bruce 060317 fixed bug 1551 (in two files) by removing lod == 3 case from if/elif statement.]
            loditem = 3 # index of the spinbox item that says "variable"
        elif lod > 2:
            loditem = 2
        self.level_of_detail_combox.setCurrentIndex(loditem)

        # Ball and Stick atom scale factor.
        self.connect(self.ballStickAtomScaleFactorSpinBox, SIGNAL("valueChanged(int)"), self.change_ballStickAtomScaleFactor)
        self.connect(self.reset_ballstick_scale_factor_btn, SIGNAL("clicked()"), self.reset_ballStickAtomScaleFactor)

        self.reset_ballstick_scale_factor_btn.setIcon(
            geticon('ui/dialogs/Reset.png'))
        _sf = int (env.prefs[diBALL_AtomRadius_prefs_key] * 100.0)
        self.ballStickAtomScaleFactorSpinBox.setValue(_sf)
        self.change_ballStickAtomScaleFactor(_sf) # Needed to update the reset button.

        # CPK atom scale factor.
        self.connect(self.cpkAtomScaleFactorDoubleSpinBox, SIGNAL("valueChanged(double)"), self.change_cpkAtomScaleFactor)
        self.connect(self.reset_cpk_scale_factor_btn, SIGNAL("clicked()"), self.reset_cpkAtomScaleFactor)

        self.reset_cpk_scale_factor_btn.setIcon(
            geticon('ui/dialogs/Reset.png'))
        self.cpkAtomScaleFactorDoubleSpinBox.setValue(env.prefs[cpkScaleFactor_prefs_key])
        self.change_cpkAtomScaleFactor(env.prefs[cpkScaleFactor_prefs_key]) # Needed to update the reset button.

        # Checkboxes.
        connect_checkbox_with_boolean_pref( self.overlappingAtomIndicatorsCheckBox, indicateOverlappingAtoms_prefs_key )
        connect_checkbox_with_boolean_pref( self.keepBondsTransmuteCheckBox, keepBondsDuringTransmute_prefs_key)
        return

    def _setupPage_Bonds(self):
        """
        Setup the "Bonds" page.
        """

        # Create "High order bond display" button group, which lives inside
        # of self.high_order_bond_display_groupbox (a QGroupBox).
        self.high_order_bond_display_btngrp = QButtonGroup()
        self.high_order_bond_display_btngrp.setExclusive(True)

        objId = 0
        for obj in [self.multCyl_radioButton, self.vanes_radioButton,
                    self.ribbons_radioButton]:
            self.high_order_bond_display_btngrp.addButton(obj)
            self.high_order_bond_display_btngrp.setId(obj, objId)
            objId +=1

        self.connect(self.high_order_bond_display_btngrp, SIGNAL("buttonClicked(int)"), self.change_high_order_bond_display)
        self.connect(self.reset_bond_colors_btn, SIGNAL("clicked()"), self.reset_bond_colors)
        self.connect(self.show_bond_labels_checkbox, SIGNAL("toggled(bool)"), self.change_bond_labels)
        self.connect(self.show_valence_errors_checkbox, SIGNAL("toggled(bool)"), self.change_show_valence_errors)
        self.connect(self.ballstick_bondcolor_btn, SIGNAL("clicked()"), self.change_ballstick_bondcolor)
        self.connect(self.bond_hilite_color_btn, SIGNAL("clicked()"), self.change_bond_hilite_color)
        self.connect(self.bond_line_thickness_spinbox, SIGNAL("valueChanged(int)"), self.change_bond_line_thickness)
        self.connect(self.bond_stretch_color_btn, SIGNAL("clicked()"), self.change_bond_stretch_color)
        self.connect(self.bond_vane_color_btn, SIGNAL("clicked()"), self.change_bond_vane_color)


        self.connect(self.cpk_cylinder_rad_spinbox, SIGNAL("valueChanged(int)"), self.change_ballstick_cylinder_radius)

        #bruce 050805 here's the new way: subscribe to the preference value,
        # but make sure to only have one such subs (for one widget's bgcolor) at a time.
        # The colors in these frames will now automatically update whenever the prefs value changes.
        ##e (should modify this code to share its prefskey list with the one for restore_defaults)
        connect_colorpref_to_colorframe(
            bondHighlightColor_prefs_key, self.bond_hilite_color_frame)
        connect_colorpref_to_colorframe(
            bondStretchColor_prefs_key, self.bond_stretch_color_frame)
        connect_colorpref_to_colorframe(
            bondVaneColor_prefs_key, self.bond_vane_color_frame)
        connect_colorpref_to_colorframe(
            diBALL_bondcolor_prefs_key, self.ballstick_bondcolor_frame)
        connect_checkbox_with_boolean_pref(
            self.showBondStretchIndicators_checkBox,
            showBondStretchIndicators_prefs_key)

        # also handle the non-color prefs on this page:
        #  ('pi_bond_style',   ['multicyl','vane','ribbon'],  pibondStyle_prefs_key,   'multicyl' ),
        pibondstyle_sym = env.prefs[ pibondStyle_prefs_key]
        button_code = { 'multicyl':0,'vane':1, 'ribbon':2 }.get( pibondstyle_sym, 0)
            # Errors in prefs db are not detected -- we just use the first button because (we happen to know) it's the default.
            # This int encoding is specific to this buttongroup.
            # The prefs db and the rest of the code uses the symbolic strings listed above.
        if button_code == 0:
            self.multCyl_radioButton.setChecked(True)
        elif button_code ==1:
            self.vanes_radioButton.setChecked(True)
        else:
            self.ribbons_radioButton.setChecked(True)

        #  ('pi_bond_letters', 'boolean',                     pibondLetters_prefs_key, False ),
        self.show_bond_labels_checkbox.setChecked( env.prefs[ pibondLetters_prefs_key] )
            # I don't know whether this sends the signal as if the user changed it
            # (and even if Qt doc says no, this needs testing since I've seen it be wrong about those things before),
            # but in the present code it doesn't matter unless it causes storing default value explicitly into prefs db
            # (I can't recall whether or not it does). Later this might matter more, e.g. if we have prefs-value modtimes.
            # [bruce 050806]

        # ('show_valence_errors',        'boolean', showValenceErrors_prefs_key,   True ),
        # (This is a per-atom warning, but I decided to put it on the Bonds page since you need it when
        #  working on high order bonds. And, since I could fit that into the UI more easily.)

        if hasattr(self, 'show_valence_errors_checkbox'):
            self.show_valence_errors_checkbox.setChecked( env.prefs[ showValenceErrors_prefs_key] )
            # note: this does cause the checkbox to send its "toggled(bool)" signal to our slot method.

        # Set Lines Dislplay Mode line thickness.  Mark 050831.
        self.update_bond_line_thickness_suffix()
        self.bond_line_thickness_spinbox.setValue( env.prefs[linesDisplayModeThickness_prefs_key] )

        # Set CPK Cylinder radius (percentage).  Mark 051003.
        self.cpk_cylinder_rad_spinbox.setValue(int (env.prefs[diBALL_BondCylinderRadius_prefs_key] * 100.0))
        return


    def _setupPage_Dna(self):
        """
        Setup the "DNA" page.
        """
        # Connections for "DNA defaults" groupbox widgets.

        connect_doubleSpinBox_with_pref(self.dnaBasesPerTurnDoubleSpinBox,
                                        bdnaBasesPerTurn_prefs_key
                                        )

        connect_doubleSpinBox_with_pref(self.dnaRiseDoubleSpinBox,
                                        bdnaRise_prefs_key)



        self.connect(self.dnaRestoreFactoryDefaultsPushButton, SIGNAL("clicked()"), self.dnaRestoreFactoryDefaults)

        connect_colorpref_to_colorframe(dnaDefaultStrand1Color_prefs_key, self.dnaDefaultStrand1ColorFrame)
        self.connect(self.dnaDefaultStrand1ColorPushButton, SIGNAL("clicked()"), self.changeDnaDefaultStrand1Color)

        connect_colorpref_to_colorframe(dnaDefaultStrand2Color_prefs_key, self.dnaDefaultStrand2ColorFrame)
        self.connect(self.dnaDefaultStrand2ColorPushButton, SIGNAL("clicked()"), self.changeDnaDefaultStrand2Color)

        connect_colorpref_to_colorframe(dnaDefaultSegmentColor_prefs_key, self.dnaDefaultSegmentColorFrame)
        self.connect(self.dnaDefaultSegmentColorPushButton, SIGNAL("clicked()"), self.changeDnaDefaultSegmentColor)

        self.dnaBasesPerTurnDoubleSpinBox.setValue(env.prefs[bdnaBasesPerTurn_prefs_key])
        self.dnaRiseDoubleSpinBox.setValue(env.prefs[bdnaRise_prefs_key])

        # Connections for "DNA Strand Arrowheads" groupbox widgets.
        self.connect(self.strandThreePrimeArrowheadsCustomColorPushButton, SIGNAL("clicked()"), self.change_dnaStrandThreePrimeArrowheadCustomColor)
        self.connect(self.strandFivePrimeArrowheadsCustomColorPushButton, SIGNAL("clicked()"), self.change_dnaStrandFivePrimeArrowheadCustomColor)
        self.connect(self.strandThreePrimeArrowheadsCustomColorCheckBox, SIGNAL("toggled(bool)"), self.update_dnaStrandThreePrimeArrowheadCustomColorWidgets)
        self.connect(self.strandFivePrimeArrowheadsCustomColorCheckBox, SIGNAL("toggled(bool)"), self.update_dnaStrandFivePrimeArrowheadCustomColorWidgets)

        # DNA strand arrowheads preferences
        connect_checkbox_with_boolean_pref(self.arrowsOnBackBones_checkBox, arrowsOnBackBones_prefs_key)
        connect_checkbox_with_boolean_pref(self.arrowsOnThreePrimeEnds_checkBox, arrowsOnThreePrimeEnds_prefs_key)

        connect_checkbox_with_boolean_pref(
            self.arrowsOnFivePrimeEnds_checkBox,
            arrowsOnFivePrimeEnds_prefs_key)

        connect_checkbox_with_boolean_pref(
            self.strandThreePrimeArrowheadsCustomColorCheckBox,
            useCustomColorForThreePrimeArrowheads_prefs_key)

        connect_checkbox_with_boolean_pref(
            self.strandFivePrimeArrowheadsCustomColorCheckBox,
            useCustomColorForFivePrimeArrowheads_prefs_key)

        #Join strands command may override global strand arrow head options

        connect_colorpref_to_colorframe(
            dnaStrandThreePrimeArrowheadsCustomColor_prefs_key,
            self.strandThreePrimeArrowheadsCustomColorFrame)

        connect_colorpref_to_colorframe(
            dnaStrandFivePrimeArrowheadsCustomColor_prefs_key,
            self.strandFivePrimeArrowheadsCustomColorFrame)


        self.update_dnaStrandThreePrimeArrowheadCustomColorWidgets(
            env.prefs[useCustomColorForThreePrimeArrowheads_prefs_key])

        self.update_dnaStrandFivePrimeArrowheadCustomColorWidgets(
            env.prefs[useCustomColorForFivePrimeArrowheads_prefs_key])

    def _setupPage_DnaMinorGrooveErrorIndicator(self):
        """
        Setup the "DNA Minor Groove Error Indicator" page.
        """
        # Connections for "DNA Minor Groove Error Indicator" groupbox widgets.
        self.connect(self.dnaMinGrooveAngleSpinBox, SIGNAL("valueChanged(int)"), self.save_dnaMinMinorGrooveAngles)
        self.connect(self.dnaMaxGrooveAngleSpinBox, SIGNAL("valueChanged(int)"), self.save_dnaMaxMinorGrooveAngles)
        self.connect(self.dnaGrooveIndicatorColorButton, SIGNAL("clicked()"), self.change_dnaMinorGrooveErrorIndicatorColor)
        self.connect(self.dnaMinorGrooveRestoreFactoryDefaultsPushButton, SIGNAL("clicked()"), self._restore_dnaMinorGrooveFactoryDefaults)

        # Display Minor Groove Error Indicator groupbox widgets.

        connect_checkbox_with_boolean_pref(
            self.dnaDisplayMinorGrooveErrorGroupBox,
            dnaDisplayMinorGrooveErrorIndicators_prefs_key)

        self.dnaMinGrooveAngleSpinBox.setValue(
            env.prefs[dnaMinMinorGrooveAngle_prefs_key])

        self.dnaMaxGrooveAngleSpinBox.setValue(
            env.prefs[dnaMaxMinorGrooveAngle_prefs_key])

        connect_colorpref_to_colorframe(
            dnaMinorGrooveErrorIndicatorColor_prefs_key,
            self.dnaGrooveIndicatorColorFrame)

    def _setupPage_DnaBaseOrientationIndicators(self):
        """
        Setup the "DNA Base Orientation Indicators" page.
        """
        # Connections for "DNA base orientation indicator" groupbox widgets.
        self.connect(self.dnaDisplayBaseOrientationIndicatorsGroupBox, SIGNAL("toggled(bool)"), self.toggle_dnaDisplayBaseOrientationIndicatorsGroupBox)
        self.connect(self.dnaBaseOrientationIndicatorsInverseCheckBox, SIGNAL("toggled(bool)"), self.toggle_dnaDisplayBaseOrientationInvIndicatorsCheckBox)
        self.connect(self.dnaBaseOrientationIndicatorsThresholdSpinBox, SIGNAL("valueChanged(double)"), self.change_dnaBaseIndicatorsAngle)
        self.connect(self.dnaBaseOrientationIndicatorsTerminalDistanceSpinBox, SIGNAL("valueChanged(double)"), self.change_dnaBaseIndicatorsDistance)
        self.connect(self.dnaChooseBaseOrientationIndicatorsColorButton, SIGNAL("clicked()"), self.change_dnaBaseIndicatorsColor)
        self.connect(self.dnaChooseBaseOrientationIndicatorsInvColorButton, SIGNAL("clicked()"), self.change_dnaBaseInvIndicatorsColor)
        self.connect(self.dnaBaseIndicatorsPlaneNormalComboBox, SIGNAL("activated(int)"), self.change_dnaBaseOrientIndicatorsPlane)

        # DNA Base Orientation Indicator stuff.
        self.dnaDisplayBaseOrientationIndicatorsGroupBox.setChecked(
            env.prefs[dnaBaseIndicatorsEnabled_prefs_key])
        self.dnaBaseIndicatorsPlaneNormalComboBox.setCurrentIndex(
            env.prefs[dnaBaseIndicatorsPlaneNormal_prefs_key])
        self.dnaBaseOrientationIndicatorsInverseCheckBox.setChecked(
            env.prefs[dnaBaseInvIndicatorsEnabled_prefs_key])
        self.update_dnaBaseIndicatorsAngle()
        self.update_dnaBaseIndicatorsDistance()
        connect_colorpref_to_colorframe(dnaBaseIndicatorsColor_prefs_key,
                                        self.dnaBaseOrientationIndicatorsColorFrame)
        connect_colorpref_to_colorframe(dnaBaseInvIndicatorsColor_prefs_key,
                                        self.dnaBaseOrientationIndicatorsInvColorFrame)

    def _setupPage_Adjust(self):
        """
        Setup the "Adjust" page.
        """
        self.connect(self.adjustEngineCombobox, SIGNAL("activated(int)"), self.set_adjust_minimization_engine)
        self.connect(self.endRmsDoubleSpinBox, SIGNAL("valueChanged(double)"), self.changeEndRms)
        self.connect(self.endMaxDoubleSpinBox, SIGNAL("valueChanged(double)"), self.changeEndMax)
        self.connect(self.cutoverRmsDoubleSpinBox, SIGNAL("valueChanged(double)"), self.changeCutoverRms)
        self.connect(self.cutoverMaxDoubleSpinBox, SIGNAL("valueChanged(double)"), self.changeCutoverMax)

        self.endRmsDoubleSpinBox.setSpecialValueText("Automatic")
        self.endMaxDoubleSpinBox.setSpecialValueText("Automatic")
        self.cutoverRmsDoubleSpinBox.setSpecialValueText("Automatic")
        self.cutoverMaxDoubleSpinBox.setSpecialValueText("Automatic")

        # "Settings for Adjust" groupbox. ###########################

        # Adjust Engine combobox.
        self.adjustEngineCombobox.setCurrentIndex(
            env.prefs[Adjust_minimizationEngine_prefs_key])

        # Watch motion in real time checkbox.
        connect_checkbox_with_boolean_pref(
            self.watch_motion_groupbox,
            Adjust_watchRealtimeMinimization_prefs_key )

        self.watch_motion_groupbox.setEnabled(
            env.prefs[Adjust_watchRealtimeMinimization_prefs_key])

        # "Watch motion..." radio btngroup
        self.watch_motion_buttongroup = QButtonGroup()
        self.watch_motion_buttongroup.setExclusive(True)
        for obj in self.watch_motion_groupbox.children():
            if isinstance(obj, QAbstractButton):
                self.watch_motion_buttongroup.addButton(obj)

        #Preference for enabling/disabling electrostatics during Adjustment
        #for the DNA reduced model. Ninad 20070809
        connect_checkbox_with_boolean_pref(
            self.electrostaticsForDnaDuringAdjust_checkBox,
            electrostaticsForDnaDuringAdjust_prefs_key)

        # Convergence Criteria groupbox
        # [WARNING: bruce 060705 copied this into MinimizeEnergyProp.py]
        self.endrms = get_pref_or_optval(Adjust_endRMS_prefs_key, -1.0, 0.0)
        self.endRmsDoubleSpinBox.setValue(self.endrms)

        self.endmax = get_pref_or_optval(Adjust_endMax_prefs_key, -1.0, 0.0)
        self.endMaxDoubleSpinBox.setValue(self.endmax)

        self.cutoverrms = get_pref_or_optval(Adjust_cutoverRMS_prefs_key, -1.0, 0.0)
        self.cutoverRmsDoubleSpinBox.setValue(self.cutoverrms)

        self.cutovermax = get_pref_or_optval(Adjust_cutoverMax_prefs_key, -1.0, 0.0)
        self.cutoverMaxDoubleSpinBox.setValue(self.cutovermax)

        return

    def _setupPage_Lighting(self):
        """
        Setup the "Lighting" page.
        """
        # Connections for "Lighting" page.
        self.connect(self.light_ambient_slider, SIGNAL("valueChanged(int)"), self.change_lighting)
        self.connect(self.light_ambient_slider, SIGNAL("sliderReleased()"), self.save_lighting)
        self.connect(self.light_checkbox, SIGNAL("toggled(bool)"), self.toggle_light)
        self.connect(self.light_color_btn, SIGNAL("clicked()"), self.change_light_color)
        self.connect(self.light_combobox, SIGNAL("activated(int)"), self.change_active_light)
        self.connect(self.light_diffuse_slider, SIGNAL("sliderReleased()"), self.save_lighting)
        self.connect(self.light_diffuse_slider, SIGNAL("valueChanged(int)"), self.change_lighting)
        self.connect(self.light_specularity_slider, SIGNAL("valueChanged(int)"), self.change_lighting)
        self.connect(self.light_specularity_slider, SIGNAL("sliderReleased()"), self.save_lighting)
        self.connect(self.light_x_linedit, SIGNAL("returnPressed()"), self.save_lighting)
        self.connect(self.light_y_linedit, SIGNAL("returnPressed()"), self.save_lighting)
        self.connect(self.light_z_linedit, SIGNAL("returnPressed()"), self.save_lighting)
        self.connect(self.lighting_restore_defaults_btn, SIGNAL("clicked()"), self.restore_default_lighting)
        self.connect(self.ms_brightness_slider, SIGNAL("sliderReleased()"), self.change_material_brightness_stop)
        self.connect(self.ms_brightness_slider, SIGNAL("valueChanged(int)"), self.change_material_brightness)
        self.connect(self.ms_brightness_slider, SIGNAL("sliderPressed()"), self.change_material_brightness_start)
        self.connect(self.ms_finish_slider, SIGNAL("valueChanged(int)"), self.change_material_finish)
        self.connect(self.ms_finish_slider, SIGNAL("sliderReleased()"), self.change_material_finish_stop)
        self.connect(self.ms_finish_slider, SIGNAL("sliderPressed()"), self.change_material_finish_start)
        self.connect(self.ms_on_checkbox, SIGNAL("toggled(bool)"), self.toggle_material_specularity)
        self.connect(self.ms_shininess_slider, SIGNAL("sliderReleased()"), self.change_material_shininess_stop)
        self.connect(self.ms_shininess_slider, SIGNAL("sliderPressed()"), self.change_material_shininess_start)
        self.connect(self.ms_shininess_slider, SIGNAL("valueChanged(int)"), self.change_material_shininess)

        self._updatePage_Lighting()
        return

    def _updatePage_Lighting(self, lights = None): #mark 051124
        """
        Setup widgets to initial (default or defined) values on the Lighting page.
        """
        if not lights:
            self.lights = self.original_lights = self.glpane.getLighting()
        else:
            self.lights = lights

        light_num = self.light_combobox.currentIndex()

        self.update_light_combobox_items()

        # Move lc_prefs_keys upstairs.  Mark.
        lc_prefs_keys = [light1Color_prefs_key, light2Color_prefs_key, light3Color_prefs_key]
        self.current_light_key = lc_prefs_keys[light_num] # Get prefs key for current light color.
        connect_colorpref_to_colorframe(self.current_light_key, self.light_color_frame)
        self.light_color = env.prefs[self.current_light_key]

        # These sliders generate signals whenever their 'setValue()' slot is called (below).
        # This creates problems (bugs) for us, so we disconnect them temporarily.
        self.disconnect(self.light_ambient_slider, SIGNAL("valueChanged(int)"), self.change_lighting)
        self.disconnect(self.light_diffuse_slider, SIGNAL("valueChanged(int)"), self.change_lighting)
        self.disconnect(self.light_specularity_slider, SIGNAL("valueChanged(int)"), self.change_lighting)

        # self.lights[light_num][0] contains 'color' attribute.
        # We already have it (self.light_color) from the prefs key (above).
        a = self.lights[light_num][1] # ambient intensity
        d = self.lights[light_num][2] # diffuse intensity
        s = self.lights[light_num][3] # specular intensity

        self.light_ambient_slider.setValue(int (a * 100)) # generates signal
        self.light_diffuse_slider.setValue(int (d * 100)) # generates signal
        self.light_specularity_slider.setValue(int (s * 100)) # generates signal

        self.light_ambient_linedit.setText(str(a))
        self.light_diffuse_linedit.setText(str(d))
        self.light_specularity_linedit.setText(str(s))

        self.light_x_linedit.setText(str (self.lights[light_num][4]))
        self.light_y_linedit.setText(str (self.lights[light_num][5]))
        self.light_z_linedit.setText(str (self.lights[light_num][6]))
        self.light_checkbox.setChecked(self.lights[light_num][7])

        # Reconnect the slots to the light sliders.
        self.connect(self.light_ambient_slider, SIGNAL("valueChanged(int)"), self.change_lighting)
        self.connect(self.light_diffuse_slider, SIGNAL("valueChanged(int)"), self.change_lighting)
        self.connect(self.light_specularity_slider, SIGNAL("valueChanged(int)"), self.change_lighting)

        self._setup_material_group()
        return

    # _setup_material_group() should be folded back into _updatePage_Lighting(). Mark 051204.
    def _setup_material_group(self, reset = False):
        """
        Setup Material Specularity widgets to initial (default or defined) values on the Lighting page.
        If reset = False, widgets are reset from the prefs db.
        If reset = True, widgets are reset from their previous values.
        """

        if reset:
            self.material_specularity = self.original_material_specularity
            self.whiteness = self.original_whiteness
            self.shininess = self.original_shininess
            self.brightness = self.original_brightness
        else:
            self.material_specularity = self.original_material_specularity = \
                env.prefs[material_specular_highlights_prefs_key]
            self.whiteness = self.original_whiteness = \
                int(env.prefs[material_specular_finish_prefs_key] * 100)
            self.shininess = self.original_shininess = \
                int(env.prefs[material_specular_shininess_prefs_key])
            self.brightness = self.original_brightness= \
                int(env.prefs[material_specular_brightness_prefs_key] * 100)

        # Enable/disable specular highlights.
        self.ms_on_checkbox.setChecked(self.material_specularity )

        # For whiteness, the stored range is 0.0 (Plastic) to 1.0 (Metal).  The Qt slider range
        # is 0 - 100, so we multiply by 100 (above) to set the slider.  Mark. 051129.
        self.ms_finish_slider.setValue(self.whiteness) # generates signal
        self.ms_finish_linedit.setText(str(self.whiteness * .01))

        # For shininess, the range is 15 (low) to 60 (high).  Mark. 051129.
        self.ms_shininess_slider.setValue(self.shininess) # generates signal
        self.ms_shininess_linedit.setText(str(self.shininess))

        # For brightness, the range is 0.0 (low) to 1.0 (high).  Mark. 051203.
        self.ms_brightness_slider.setValue(self.brightness) # generates signal
        self.ms_brightness_linedit.setText(str(self.brightness * .01))
        return

    def _setupPage_Plugins(self):
        """
        Setup the "Plug-ins" page.
        """
        # QuteMolX signal-slot connections.
        self.connect(self.qutemol_checkbox, SIGNAL("toggled(bool)"), self.enable_qutemol)
        self.connect( self.qutemol_path_lineedit, SIGNAL("textEdited (const QString&) "), self.set_qutemol_path)
        self.connect(self.qutemol_choose_btn, SIGNAL("clicked()"), self.choose_qutemol_path)

        # NanoHive-1 signal-slot connections.
        self.connect(self.nanohive_checkbox, SIGNAL("toggled(bool)"), self.enable_nanohive)
        self.connect( self.nanohive_path_lineedit, SIGNAL("textEdited (const QString&) "), self.set_nanohive_path)
        self.connect(self.nanohive_choose_btn, SIGNAL("clicked()"), self.choose_nanohive_path)

        # POV-Ray signal-slot connections.
        self.connect(self.povray_checkbox, SIGNAL("toggled(bool)"), self.enable_povray)
        self.connect( self.povray_path_lineedit, SIGNAL("textEdited (const QString&) "), self.set_povray_path)
        self.connect(self.povray_choose_btn, SIGNAL("clicked()"), self.choose_povray_path)

        # POV dir signal-slot connections.
        self.connect(self.povdir_checkbox, SIGNAL("toggled(bool)"), self.enable_povdir)
        self.connect( self.povdir_lineedit, SIGNAL("textEdited (const QString&) "), self.povdir_lineedit_textChanged )
        self.connect(self.povdir_choose_btn, SIGNAL("clicked()"), self.set_povdir)
        self.connect( self.povdir_lineedit, SIGNAL("returnPressed()"), self.povdir_lineedit_returnPressed )

        # MegaPOV signal-slot connections.
        self.connect(self.megapov_checkbox, SIGNAL("toggled(bool)"), self.enable_megapov)
        self.connect( self.megapov_path_lineedit, SIGNAL("textEdited (const QString&) "), self.set_megapov_path )
        self.connect(self.megapov_choose_btn, SIGNAL("clicked()"), self.choose_megapov_path)

        # GAMESS signal-slot connections.
        self.connect(self.gamess_checkbox, SIGNAL("toggled(bool)"), self.enable_gamess)
        self.connect(self.gamess_path_lineedit, SIGNAL("textEdited(const QString&)"), self.set_gamess_path)
        self.connect(self.gamess_choose_btn, SIGNAL("clicked()"), self.choose_gamess_path)

        # GROMACS signal-slot connections.
        self.connect(self.gromacs_checkbox, SIGNAL("toggled(bool)"), self.enable_gromacs)
        self.connect(self.gromacs_path_lineedit, SIGNAL("textEdited(const QString&)"), self.set_gromacs_path)
        self.connect(self.gromacs_choose_btn, SIGNAL("clicked()"), self.choose_gromacs_path)

        # cpp signal-slot connections.
        self.connect(self.cpp_checkbox, SIGNAL("toggled(bool)"), self.enable_cpp)
        self.connect(self.cpp_path_lineedit, SIGNAL("textEdited(const QString&)"), self.set_cpp_path)
        self.connect(self.cpp_choose_btn, SIGNAL("clicked()"), self.choose_cpp_path)

        # Rosetta signal-slots connections.
        self.connect(self.rosetta_checkbox, SIGNAL("toggled(bool)"), self.enable_rosetta)
        self.connect(self.rosetta_path_lineedit, SIGNAL("textEdited(const QString&)"), self.set_rosetta_path)
        self.connect(self.rosetta_choose_btn, SIGNAL("clicked()"), self.choose_rosetta_path)

        # Rosetta database signal-slots connections.
        self.connect(self.rosetta_db_checkbox, SIGNAL("toggled(bool)"), self.enable_rosetta_db)
        self.connect(self.rosetta_db_path_lineedit, SIGNAL("textEdited(const QString&)"), self.set_rosetta_db_path)
        self.connect(self.rosetta_db_choose_btn, SIGNAL("clicked()"), self.choose_rosetta_db_path)

        # NanoVision-1 signal-slots connections.
        self.connect(self.nv1_checkbox, SIGNAL("toggled(bool)"), self.enable_nv1)
        self.connect(self.nv1_path_lineedit, SIGNAL("textEdited(const QString&)"), self.set_nv1_path)
        self.connect(self.nv1_choose_btn, SIGNAL("clicked()"), self.choose_nv1_path)
        return

    def _setupPage_Undo(self):
        """
        Setup the "Undo" page.
        """
        # Connections for "Undo" page.
        self.connect(self.undo_stack_memory_limit_spinbox, SIGNAL("valueChanged(int)"), self.change_undo_stack_memory_limit)
        self.connect(self.update_number_spinbox, SIGNAL("valueChanged(int)"), self.update_number_spinbox_valueChanged)
        return

    def _setupPage_Window(self):
        """
        Setup the "Window" page.
        """
        # Connections for "Window" page.
        self.connect(self.caption_fullpath_checkbox, SIGNAL("stateChanged(int)"), self.set_caption_fullpath)
        self.connect(self.current_height_spinbox, SIGNAL("valueChanged(int)"), self.change_window_size)
        self.connect(self.current_width_spinbox, SIGNAL("valueChanged(int)"), self.change_window_size)
        self.connect(self.restore_saved_size_btn, SIGNAL("clicked()"), self.restore_saved_size)
        self.connect(self.save_current_btn, SIGNAL("clicked()"), self.save_current_win_pos_and_size)

        # Connections for font widgets (in "Windows" page). Mark 2007-05-27.
        self.connect(self.selectedFontGroupBox, SIGNAL("toggled(bool)"), self.change_use_selected_font)
        self.connect(self.fontComboBox, SIGNAL("currentFontChanged (const QFont &)"), self.change_font)
        self.connect(self.fontSizeSpinBox, SIGNAL("valueChanged(int)"), self.change_fontsize)
        self.connect(self.makeDefaultFontPushButton, SIGNAL("clicked()"), self.change_selected_font_to_default_font)

        # Update the max value of the Current Size spinboxes
        screen = screen_pos_size()
        ((x0, y0), (w, h)) = screen
        self.current_width_spinbox.setRange(1, w)
        self.current_height_spinbox.setRange(1, h)

        # Set value of the Current Size Spinboxes
        pos, size = _get_window_pos_size(self.w)
        self.current_width_spinbox.setValue(size[0])
        self.current_height_spinbox.setValue(size[1])

        # Set string of Saved Size Lineedits
        from utilities.prefs_constants import mainwindow_geometry_prefs_key_prefix
        keyprefix = mainwindow_geometry_prefs_key_prefix
        pos, size = _get_prefs_for_window_pos_size( self.w, keyprefix)
        self.update_saved_size(size[0], size[1])

        connect_checkbox_with_boolean_pref( self.remember_win_pos_and_size_checkbox, rememberWinPosSize_prefs_key )

        self.caption_prefix_linedit.setText(env.prefs[captionPrefix_prefs_key])
        self.caption_suffix_linedit.setText(env.prefs[captionSuffix_prefs_key])
            ##e someday we should make a 2-way connector function for LineEdits too
        connect_checkbox_with_boolean_pref( self.caption_fullpath_checkbox, captionFullPath_prefs_key )

        # Update Display Font widgets
        self.set_font_widgets(setFontFromPrefs = True) # Also sets the current display font.

        # Connect all QLineEdit widgets last. Otherwise they'll generate signals.
        self.connect( self.caption_prefix_linedit, SIGNAL("textChanged ( const QString & ) "), self.caption_prefix_linedit_textChanged )
        self.connect( self.caption_prefix_linedit, SIGNAL("returnPressed()"), self.caption_prefix_linedit_returnPressed )
        self.connect( self.caption_suffix_linedit, SIGNAL("textChanged ( const QString & ) "), self.caption_suffix_linedit_textChanged )
        self.connect( self.caption_suffix_linedit, SIGNAL("returnPressed()"), self.caption_suffix_linedit_returnPressed )
        return

    def _setupPage_Reports(self):
        """
        Setup the "Reports" page.
        """
        connect_checkbox_with_boolean_pref( self.msg_serial_number_checkbox, historyMsgSerialNumber_prefs_key )
        connect_checkbox_with_boolean_pref( self.msg_timestamp_checkbox, historyMsgTimestamp_prefs_key )
        return

    def _setupPage_Tooltips(self):
        """
        Setup the "Tooltips" page.
        """
        # Connections for "Tooltips" page.
        self.connect(self.dynamicToolTipAtomDistancePrecision_spinbox, SIGNAL("valueChanged(int)"), self.change_dynamicToolTipAtomDistancePrecision)
        self.connect(self.dynamicToolTipBendAnglePrecision_spinbox, SIGNAL("valueChanged(int)"), self.change_dynamicToolTipBendAnglePrecision)

        #Atom related Dynamic tooltip preferences
        connect_checkbox_with_boolean_pref(self.dynamicToolTipAtomChunkInfo_checkbox, dynamicToolTipAtomChunkInfo_prefs_key)
        connect_checkbox_with_boolean_pref(self.dynamicToolTipAtomMass_checkbox, dynamicToolTipAtomMass_prefs_key)
        connect_checkbox_with_boolean_pref(self.dynamicToolTipAtomPosition_checkbox, dynamicToolTipAtomPosition_prefs_key)
        connect_checkbox_with_boolean_pref(self.dynamicToolTipAtomDistanceDeltas_checkbox, dynamicToolTipAtomDistanceDeltas_prefs_key)
        connect_checkbox_with_boolean_pref(
            self.includeVdwRadiiInAtomDistanceInfo,
            dynamicToolTipVdwRadiiInAtomDistance_prefs_key)

        #Bond related dynamic tool tip preferences
        connect_checkbox_with_boolean_pref(self.dynamicToolTipBondLength_checkbox, dynamicToolTipBondLength_prefs_key)
        connect_checkbox_with_boolean_pref(self.dynamicToolTipBondChunkInfo_checkbox, dynamicToolTipBondChunkInfo_prefs_key)

        self.dynamicToolTipAtomDistancePrecision_spinbox.setValue(env.prefs[ dynamicToolTipAtomDistancePrecision_prefs_key ] )
        self.dynamicToolTipBendAnglePrecision_spinbox.setValue(env.prefs[ dynamicToolTipBendAnglePrecision_prefs_key ] )
        return

    def _hideOrShowWidgets(self):
        """
        Permanently hides some widgets in the Preferences dialog.
        This provides an easy and convenient way of hiding widgets that have
        been added but not fully implemented. It is also possible to
        show hidden widgets that have a debug pref set to enable them.
        """
        gms_and_esp_widgetList = [self.nanohive_lbl,
                                  self.nanohive_checkbox,
                                  self.nanohive_path_lineedit,
                                  self.nanohive_choose_btn,
                                  self.gamess_checkbox,
                                  self.gamess_lbl,
                                  self.gamess_path_lineedit,
                                  self.gamess_choose_btn]

        for widget in gms_and_esp_widgetList:
            if debug_pref("Show GAMESS and ESP Image UI options",
                          Choice_boolean_False,
                          prefs_key = True):
                widget.show()
            else:
                widget.hide()

        # NanoVision-1
        nv1_widgetList = [self.nv1_checkbox,
                          self.nv1_label,
                          self.nv1_path_lineedit,
                          self.nv1_choose_btn]

        for widget in nv1_widgetList:
            widget.hide()

        # Rosetta
        rosetta_widgetList = [self.rosetta_checkbox,
                              self.rosetta_label,
                              self.rosetta_path_lineedit,
                              self.rosetta_choose_btn,
                              self.rosetta_db_checkbox,
                              self.rosetta_db_label,
                              self.rosetta_db_path_lineedit,
                              self.rosetta_db_choose_btn]

        from utilities.GlobalPreferences import ENABLE_PROTEINS
        for widget in rosetta_widgetList:
            if ENABLE_PROTEINS:
                widget.show()
            else:
                widget.hide()
        return

    # caption_prefix slot methods [#e should probably refile these with other slot methods?]
    def caption_prefix_linedit_textChanged(self, qstring):
        ## print "caption_prefix_linedit_textChanged: %r" % str(qstring) # this works
        self.any_caption_text_changed()

    def caption_prefix_linedit_returnPressed(self):
        ## print "caption_prefix_linedit_returnPressed"
            # This works, but the Return press also closes the dialog!
            # [later, bruce 060710 -- probably due to a Qt Designer property on the button, fixable by .setAutoDefault(0) ###@@@]
            # (Both for the lineedit whose signal we're catching, and the one whose signal catching is initially nim.)
            # Certainly that makes it a good idea to catch it, though it'd be better to somehow "capture" it
            # so it would not close the dialog.
        self.any_caption_text_changed()

    # caption_suffix slot methods can be equivalent to the ones for caption_prefix
    caption_suffix_linedit_textChanged = caption_prefix_linedit_textChanged
    caption_suffix_linedit_returnPressed = caption_prefix_linedit_returnPressed

    ###### Private methods ###############################

    def _loadBackgroundColorItems(self):
        """
        Load the background color combobox with all the color options and sets
        the current background color
        """
        backgroundIndexes = [BG_BLUE_SKY, BG_EVENING_SKY, BG_SEAGREEN,
                             BG_BLACK, BG_WHITE, BG_GRAY, BG_CUSTOM]

        backgroundNames   = ["Blue Sky (default)", "Evening Sky", "Sea Green",
                             "Black", "White", "Gray", "Custom..."]

        backgroundIcons   = ["Background_BlueSky", "Background_EveningSky",
                             "Background_SeaGreen",
                             "Background_Black",   "Background_White",
                             "Background_Gray",    "Background_Custom"]

        backgroundIconsDict = dict(zip(backgroundNames, backgroundIcons))
        backgroundNamesDict = dict(zip(backgroundIndexes, backgroundNames))

        for backgroundName in backgroundNames:

            basename = backgroundIconsDict[backgroundName] + ".png"
            iconPath = os.path.join("ui/dialogs/Preferences/",
                                    basename)
            self.backgroundColorComboBox.addItem(geticon(iconPath),
                                                 backgroundName)

        self._updateBackgroundColorComboBoxIndex()
        return

    def _updateBackgroundColorComboBoxIndex(self):
        """
        Set current index in the background color combobox.
        """
        if self.glpane.backgroundGradient:
            self.backgroundColorComboBox.setCurrentIndex(self.glpane.backgroundGradient - 1)
        else:
            if (env.prefs[ backgroundColor_prefs_key ] == black):
                self.backgroundColorComboBox.setCurrentIndex(BG_BLACK)
            elif (env.prefs[ backgroundColor_prefs_key ] == white):
                self.backgroundColorComboBox.setCurrentIndex(BG_WHITE)
            elif (env.prefs[ backgroundColor_prefs_key ] == gray):
                self.backgroundColorComboBox.setCurrentIndex(BG_GRAY)
            else:
                self.backgroundColorComboBox.setCurrentIndex(BG_CUSTOM)
        return

    def _loadHoverHighlightingColorStylesItems(self):
        """
        Load the hover highlighting style combobox with items.
        """
        for hoverHighlightingStyle in HHS_OPTIONS:
            self.hoverHighlightingStyleComboBox.addItem(hoverHighlightingStyle)
        return

    def _loadSelectionColorStylesItems(self):
        """
        Load the selection color style combobox with items.
        """
        for selectionStyle in SS_OPTIONS:
            self.selectionStyleComboBox.addItem(selectionStyle)
        return

    # = Methods for the "Graphics Area" page.

    def _setupGlobalDisplayStyleAtStartup_ComboBox(self):
        """
        Loads the global display style combobox with all the display options
        and sets the current display style
        """
        gdsIconDist = dict(zip(GDS_NAMES, GDS_ICONS))

        for gdsName in GDS_NAMES: # gds = global display style
            basename = gdsIconDist[gdsName] + ".png"
            iconPath = os.path.join("ui/actions/View/Display/",
                                    basename)
            self.globalDisplayStyleStartupComboBox.addItem(geticon(iconPath), gdsName)

        display_style = env.prefs[ startupGlobalDisplayStyle_prefs_key ]
        self.globalDisplayStyleStartupComboBox.setCurrentIndex(GDS_INDEXES.index(display_style))

        self.connect(self.globalDisplayStyleStartupComboBox, SIGNAL("activated(int)"), self.setGlobalDisplayStyleAtStartUp)

    def setGlobalDisplayStyleAtStartUp(self, gdsIndexUnused):
        """
        Slot method for the "Global Display Style at Start-up" combo box in
        the Preferences dialog (and not the combobox in the status bar of
        the main window).

        @param gdsIndexUnused: The current index of the combobox. It is unused.
        @type  gdsIndexUnused: int

        @note: This changes the global display style of the glpane.
        """

        # Get the GDS index from the current combox box index.
        display_style = GDS_INDEXES[self.globalDisplayStyleStartupComboBox.currentIndex()]

        if display_style == env.prefs[startupGlobalDisplayStyle_prefs_key]:
            return

        # set the pref
        env.prefs[startupGlobalDisplayStyle_prefs_key] = display_style

        # Set the current display style in the glpane.
        # (This will be noticed later by chunk.draw of affected chunks.)
        self.glpane.setGlobalDisplayStyle(display_style)
        self.glpane.gl_update()
        return

    #e this is really a slot method -- should refile it
    def any_caption_text_changed(self):
        # Update Caption prefs
        # The prefix and suffix updates should be done via slots [bruce 050811 doing that now] and include a validator.
        # Will do later.  Mark 050716.

        # (in theory, only one of these has changed, and even though we resave prefs for both,
        #  only the changed one will trigger any formulas watching the prefs value for changes. [bruce 050811])
        #bruce 070503 Qt4 bugfix (prefix and suffix): str().strip() rather than QString().stripWhiteSpace()
        # (but, like the old code, still only allows one space char on the side that can have one,
        #  in order to most easily require at least one on that side; if mot for that, we'd use rstrip and lstrip)
        prefix = str_or_unicode(self.caption_prefix_linedit.text())
        prefix = prefix.strip()
        if prefix:
            prefix = prefix + ' '
        env.prefs[captionPrefix_prefs_key] = prefix

        suffix = str_or_unicode(self.caption_suffix_linedit.text())
        suffix = suffix.strip()
        if suffix:
            suffix = ' ' + suffix
        env.prefs[captionSuffix_prefs_key] = suffix
        return

    ###### End of private methods. ########################

    ########## Slot methods for "General" page widgets ################

    def display_compass(self, val):
        """
        Slot for the Display Compass checkbox, which enables/disables the
        Display Compass Labels checkbox.
        """
        self.display_compass_labels_checkbox.setEnabled(val)

    def set_compass_position(self, val):
        """
        Set position of compass.

        @param val: The position, where:
                    - 0 = upper right
                    - 1 = upper left
                    - 2 = lower left
                    - 3 = lower right
        @type  val: int
        """
        # set the pref
        env.prefs[compassPosition_prefs_key] = val
        # update the glpane
        self.glpane.compassPosition = val
        self.glpane.gl_update()
        return

    # "Cursor text" slots (on Graphics Area page)

    def change_cursorTextColor(self):
        """
        Change the cursor text color.
        """
        self.usual_change_color( cursorTextColor_prefs_key)
        return

    def change_cursorTextFontSize(self, ptSize):
        """
        Change the cursor text font size.
        """
        env.prefs[ cursorTextFontSize_prefs_key ] = ptSize
        self._updateResetButton(self.cursorTextFontSizeResetButton, cursorTextFontSize_prefs_key)
        return

    def reset_cursorTextFontSize(self):
        """
        Slot called when pressing the Font size reset button.
        Restores the default value.
        """
        env.prefs.restore_defaults([cursorTextFontSize_prefs_key])
        self.cursorTextFontSizeSpinBox.setValue(env.prefs[cursorTextFontSize_prefs_key])

    # End "Cursor text" slots.

    def change_pasteOffsetScaleFactorForChunks(self, val):
        """
        Slot method for the I{Paste offset scale for chunks} doublespinbox.
        @param val: The timeout interval in seconds.
        @type  val: double
        @see ops_copy_Mixin._pasteGroup()
        """
        env.prefs[pasteOffsetScaleFactorForChunks_prefs_key] = val

    def change_pasteOffsetScaleFactorForDnaObjects(self, val):
        """
        Slot method for the I{Paste offset scale for dna objects} doublespinbox.
        @param val: The timeout interval in seconds.
        @type  val: double
        """
        env.prefs[pasteOffsetScaleFactorForDnaObjects_prefs_key] = val

    def enable_fog(self, val):
        """
        Switches fog.
        """
        self.glpane.gl_update()

    def set_default_projection_OBSOLETE(self, projection):
        """
        Set the projection.

        @param projection: The projection, where:
                           - 0 = Perspective
                           - 1 = Orthographic
        @type  projection: int

        @deprecated: I'm removing this from the Preferences dialog.
        The defaultProjection_prefs_key will be set instead by the
        main window UI (View > Display menu). -Mark 2008-05-20
        """
        # set the pref
        env.prefs[defaultProjection_prefs_key] = projection
        self.glpane.setViewProjection(projection)

    def change_displayOriginAsSmallAxis(self, value):
        """"
        This sets the preference to view origin as small axis so that it is
        sticky across sessions.
        """
        #set the preference
        env.prefs[displayOriginAsSmallAxis_prefs_key] = value
            #niand060920 This condition might not be necessary as we are disabling the btn_grp
            #for the oridin axis radiobuttons
        if env.prefs[displayOriginAxis_prefs_key]:
            self.glpane.gl_update()

    def change_high_quality_graphics(self, state): #mark 060315.
        """
        Enable/disable high quality graphics during view animations.

        @attention: This has never been implemented. The checkbox has been
                    removed from the UI file for A9. Mark 060815.
        """
        # Let the user know this is NIY. Addresses bug 1249 for A7. mark 060314.
        msg = "High Quality Graphics is not implemented yet."
        from utilities.Log import orangemsg
        env.history.message(orangemsg(msg))

    def change_view_animation_speed(self):
        """
        Sets the view animation speed between .25 (fast) and 3.0 (slow) seconds.
        """
        # To change the range, edit the maxValue and minValue attr for the slider.
        # For example, if you want the fastest animation time to be .1 seconds,
        # change maxValue to -10.  If you want the slowest time to be 4.0 seconds,
        # change minValue to -400.  mark 060124.
        env.prefs[animateMaximumTime_prefs_key] = \
           self.animation_speed_slider.value() / -100.0

        self._updateResetButton(self.resetAnimationSpeed_btn, animateMaximumTime_prefs_key)
        return

    def _updateResetButton(self, resetButton, key):
        """
        Enables/disables I{resetButton} if I{key} is not equal/equal to its
        default value.
        """
        if env.prefs.has_default_value(key):
            resetButton.setEnabled(0)
        else:
            resetButton.setEnabled(1)
        return

    def reset_animationSpeed(self):
        """
        Slot called when pressing the Animation speed reset button.
        Restores the default value of the animation speed.
        """
        env.prefs.restore_defaults([animateMaximumTime_prefs_key])
        self.animation_speed_slider.setValue(int (env.prefs[animateMaximumTime_prefs_key] * -100))
        self.resetAnimationSpeed_btn.setEnabled(0)
        return

    def change_mouseSpeedDuringRotation(self):
        """
        Slot that sets the speed factor controlling rotation speed during mouse button drags.
        0.3 = slow and 1.0 = fast.
        """
        env.prefs[mouseSpeedDuringRotation_prefs_key] = \
           self.mouseSpeedDuringRotation_slider.value() / 100.0

        self._updateResetButton(self.resetMouseSpeedDuringRotation_btn, mouseSpeedDuringRotation_prefs_key)
        return

    def reset_mouseSpeedDuringRotation(self):
        """
        Slot called when pressing the Mouse speed during rotation reset button.
        Restores the default value of the mouse speed.
        """
        env.prefs.restore_defaults([mouseSpeedDuringRotation_prefs_key])
        self.mouseSpeedDuringRotation_slider.setValue(int (env.prefs[mouseSpeedDuringRotation_prefs_key] * 100.0))
        self.resetMouseSpeedDuringRotation_btn.setEnabled(0)

    def changeEndRms(self, endRms):
        """
        Slot for EndRMS.
        """
        if endRms:
            env.prefs[Adjust_endRMS_prefs_key] = endRms
        else:
            env.prefs[Adjust_endRMS_prefs_key] = -1.0

    def changeEndMax(self, endMax):
        """
        Slot for EndMax.
        """
        if endMax:
            env.prefs[Adjust_endMax_prefs_key] = endMax
        else:
            env.prefs[Adjust_endMax_prefs_key] = -1.0

    def changeCutoverRms(self, cutoverRms):
        """
        Slot for CutoverRMS.
        """
        if cutoverRms:
            env.prefs[Adjust_cutoverRMS_prefs_key] = cutoverRms
        else:
            env.prefs[Adjust_cutoverRMS_prefs_key] = -1.0

    def changeCutoverMax(self, cutoverMax):
        """
        Slot for CutoverMax.
        """
        if cutoverMax:
            env.prefs[Adjust_cutoverMax_prefs_key] = cutoverMax
        else:
            env.prefs[Adjust_cutoverMax_prefs_key] = -1.0

    def set_adjust_minimization_engine(self, engine):
        """
        Combobox action, sets Adjust_minimizationEngine preference
        """
        env.prefs[Adjust_minimizationEngine_prefs_key] = engine

    def setPrefsLogoDownloadPermissions(self, permission):
        """
        Set the sponsor logos download permissions in the persistent user
        preferences database.

        @param permission: The permission, where:
                        0 = Always ask before downloading
                        1 = Never ask before downloading
                        2 = Never download
        @type  permission: int
        """
        if permission == 1:
            env.prefs[sponsor_permanent_permission_prefs_key] = True
            env.prefs[sponsor_download_permission_prefs_key] = True

        elif permission == 2:
            env.prefs[sponsor_permanent_permission_prefs_key] = True
            env.prefs[sponsor_download_permission_prefs_key] = False

        else:
            env.prefs[sponsor_permanent_permission_prefs_key] = False

    # = BG color slot methods

    def changeBackgroundColor(self, idx):
        """
        Slot method for the background color combobox.

        @note: the pref_keys are set in setBackgroundGradient()
               and setBackgroundColor().
        """
        #print "changeBackgroundColor(): Slot method called. Idx =", idx

        if idx == BG_BLUE_SKY:
            self.glpane.setBackgroundGradient(idx + 1)
        elif idx == BG_EVENING_SKY:
            self.glpane.setBackgroundGradient(idx + 1)
        elif idx == BG_SEAGREEN:
            self.glpane.setBackgroundGradient(idx + 1)
        elif idx == BG_BLACK:
            self.glpane.setBackgroundColor(black)
        elif idx == BG_WHITE:
            self.glpane.setBackgroundColor(white)
        elif idx == BG_GRAY:
            self.glpane.setBackgroundColor(gray)
        elif idx == BG_CUSTOM:
            #change background color to Custom Color
            self.chooseCustomBackgroundColor()
        else:
            msg = "Unknown color idx=", idx
            print_compact_traceback(msg)

        self.glpane.gl_update() # Needed!
        return

    def chooseCustomBackgroundColor(self):
        """
        Choose a custom background color.
        """
        c = QColorDialog.getColor(RGBf_to_QColor(self.glpane.getBackgroundColor()), self)
        if c.isValid():
            self.glpane.setBackgroundColor(QColor_to_RGBf(c))
        else:
            # User cancelled. Reset the combobox to the previous item.
            self._updateBackgroundColorComboBoxIndex()

    def _change_hhStyle(self, idx):
        """
        Slot method for Hover Highlighting combobox.
        Change the (3D) hover highlighting style.
        """
        env.prefs[hoverHighlightingColorStyle_prefs_key] = HHS_INDEXES[idx]

    def _change_hhColor(self):
        """
        Change the 3D hover highlighting color.
        """
        self.usual_change_color(hoverHighlightingColor_prefs_key)

    def _change_selectionStyle(self, idx):
        """
        Slot method for Selection Style combobox used to
        Change the (3D) selection color style.
        """
        env.prefs[selectionColorStyle_prefs_key] = SS_INDEXES[idx]

    def _change_selectionColor(self):
        """
        Change the 3D selection color.
        """
        self.usual_change_color(selectionColor_prefs_key)

    def change_haloWidth(self, width):
        """
        Change the halo style width.

        @param width: The width in pixels.
        @type  width: int
        """
        env.prefs[haloWidth_prefs_key] = width
        self._updateResetButton(self.haloWidthResetButton, haloWidth_prefs_key)

        return

    def reset_haloWidth(self):
        """
        Slot called when pressing the Halo width reset button.
        Restores the default value of the halo width.
        """
        env.prefs.restore_defaults([haloWidth_prefs_key])
        self.haloWidthSpinBox.setValue(env.prefs[haloWidth_prefs_key])

    def set_mouse_wheel_direction(self, direction):
        """
        Slot for Mouse Wheel Direction combo box.

        @param direction: The mouse wheel direction for zooming in.
                          0 = Pull (default), 1 = Push
        @type  direction: int
        """
        env.prefs[mouseWheelDirection_prefs_key] = direction
        self.w.updateMouseWheelSettings()
        return

    def set_mouse_wheel_zoom_in_position(self, position):
        """
        Slot for Mouse Wheel "Zoom In Position" combo box.

        @param position: The mouse wheel zoom in position, where:
                        0 = Cursor position (default)
                        1 = Graphics area center
        @type  position: int
        """
        env.prefs[zoomInAboutScreenCenter_prefs_key] = position
        self.w.updateMouseWheelSettings()
        return

    def set_mouse_wheel_zoom_out_position(self, position):
        """
        Slot for Mouse Wheel "Zoom Out Position" combo box.

        @param position: The mouse wheel zoom out position, where:
                        0 = Cursor position (default)
                        1 = Graphics area center
        @type  position: int
        """
        env.prefs[zoomOutAboutScreenCenter_prefs_key] = position
        self.w.updateMouseWheelSettings()
        return

    def set_mouse_wheel_timeout_interval(self, interval):
        """
        Slot method for the I{Hover highlighting timeout interval} spinbox.
        @param interval: The timeout interval in seconds.
        @type  interval: double
        """
        env.prefs[mouseWheelTimeoutInterval_prefs_key] = interval
        return

    def set_pan_arrow_keys_direction(self, direction):
        """
        Slot for Pan setting "Arrow Keys Direction" combo box.

        @param direction: The arrow keys direction for pan control, where:
                        0 = View direction (default)
                        1 = Camera direction
        @type  direction: int
        """
        if direction == 0:
            env.prefs[panArrowKeysDirection_prefs_key] =  1
        else:
            env.prefs[panArrowKeysDirection_prefs_key] = -1
        return


    # = Ruler slot methods

    def set_ruler_display(self, display):
        """
        Set display of individual rulers.

        @param display: The ruler display, where:
                    - 0 = display both rulers
                    - 1 = display vertical ruler only
                    - 2 = display horizontal ruler only

        @type  display: int
        """
        env.prefs[displayVertRuler_prefs_key] = True
        env.prefs[displayHorzRuler_prefs_key] = True

        if display == 1:
            env.prefs[displayHorzRuler_prefs_key] = False

        elif display == 2:
            env.prefs[displayVertRuler_prefs_key] = False

        # update the glpane
        self.glpane.gl_update()

    def set_ruler_position(self, position):
        """
        Set position of ruler(s).

        @param position: The ruler position, where:
                    - 0 = lower left
                    - 1 = upper left
                    - 2 = lower right
                    - 3 = upper right

        @type  position: int
        """
        # set the pref
        env.prefs[rulerPosition_prefs_key] = position

        # update the glpane
        self.glpane.gl_update()

    def change_ruler_color(self):
        """
        Change the ruler color.
        """
        self.usual_change_color( rulerColor_prefs_key)

    def change_ruler_opacity(self, opacity):
        """
        Change the ruler opacity.
        """
        env.prefs[rulerOpacity_prefs_key] = opacity * 0.01

    ########## End of slot methods for "General" page widgets ###########

    ########## Slot methods for "Atoms" page widgets ################

    def change_element_colors(self):
        """
        Display the Element Color Settings Dialog.
        """
        # Since the prefs dialog is modal, the element color settings dialog must be modal.
        self.w.showElementColorSettings(self)

    def usual_change_color(self, prefs_key, caption = "choose"): #bruce 050805
        from widgets.prefs_widgets import colorpref_edit_dialog
        colorpref_edit_dialog( self, prefs_key, caption = caption)

    def change_atom_hilite_color(self):
        """
        Change the atom highlight color.
        """
        self.usual_change_color( atomHighlightColor_prefs_key)

    def change_bondpoint_hilite_color(self):
        """
        Change the bondpoint highlight color.
        """
        self.usual_change_color( bondpointHighlightColor_prefs_key)

    def change_hotspot_color(self): #bruce 050808 implement new slot which Mark recently added to .ui file
        """
        Change the free valence hotspot color.
        """
        #e fyi, we might rename hotspot to something like "bonding point" someday...
        self.usual_change_color( bondpointHotspotColor_prefs_key)

    def reset_atom_colors(self):
        #bruce 050805 let's try it like this:
        env.prefs.restore_defaults([ #e this list should be defined in a more central place.
                                     atomHighlightColor_prefs_key,
                                     bondpointHighlightColor_prefs_key,
                                     bondpointHotspotColor_prefs_key
                                     ])

    def change_level_of_detail(self, level_of_detail_item): #bruce 060215 revised this
        """
        Change the level of detail, where <level_of_detail_item> is a value
        between 0 and 3 where:
            - 0 = low
            - 1 = medium
            - 2 = high
            - 3 = variable (based on number of atoms in the part)

        @note: the prefs db value for 'variable' is -1, to allow for higher LOD
               levels in the future.
        """
        lod = level_of_detail_item
        if level_of_detail_item == 3:
            lod = -1
        env.prefs[levelOfDetail_prefs_key] = lod
        self.glpane.gl_update()
        # the redraw this causes will (as of tonight) always recompute the correct drawLevel (in Part._recompute_drawLevel),
        # and chunks will invalidate their display lists as needed to accomodate the change. [bruce 060215]
        return

    def change_ballStickAtomScaleFactor(self, scaleFactor):
        """
        Change the Ball and Stick atom scale factor.

        @param scaleFactor: The scale factor (%).
        @type  scaleFactor: int
        """

        env.prefs[diBALL_AtomRadius_prefs_key] = scaleFactor * .01
        self._updateResetButton(self.reset_ballstick_scale_factor_btn, diBALL_AtomRadius_prefs_key)
        return

    def reset_ballStickAtomScaleFactor(self):
        """
        Slot called when pressing the CPK Atom Scale Factor reset button.
        Restores the default value of the CPK Atom Scale Factor.
        """
        env.prefs.restore_defaults([diBALL_AtomRadius_prefs_key])
        self.ballStickAtomScaleFactorSpinBox.setValue(int (env.prefs[diBALL_AtomRadius_prefs_key] * 100.0))
        return

    def change_cpkAtomScaleFactor(self, scaleFactor):
        """
        Change the atom scale factor for CPK display style.

        @param scaleFactor: The scale factor (between 0.5 and 1.0).
        @type  scaleFactor: float
        """
        env.prefs[cpkScaleFactor_prefs_key] = scaleFactor
        self._updateResetButton(self.reset_cpk_scale_factor_btn, cpkScaleFactor_prefs_key)
        return

    def reset_cpkAtomScaleFactor(self):
        """
        Slot called when pressing the CPK Atom Scale Factor reset button.
        Restores the default value of the CPK Atom Scale Factor.
        """
        env.prefs.restore_defaults([cpkScaleFactor_prefs_key])
        self.cpkAtomScaleFactorDoubleSpinBox.setValue(env.prefs[cpkScaleFactor_prefs_key])

    ########## End of slot methods for "Atoms" page widgets ###########

    ########## Slot methods for "Bonds" page widgets ################

    def change_bond_hilite_color(self):
        """
        Change the bond highlight color.
        """
        self.usual_change_color( bondHighlightColor_prefs_key)

    def change_bond_stretch_color(self):
        """
        Change the bond stretch color.
        """
        self.usual_change_color( bondStretchColor_prefs_key)

    def change_bond_vane_color(self):
        """
        Change the bond vane color for pi orbitals.
        """
        self.usual_change_color( bondVaneColor_prefs_key)

    def change_ballstick_bondcolor(self): #bruce 060607 renamed this in this file and .ui/.py dialog files
        """
        Change the bond cylinder color used in Ball & Stick display mode.
        """
        self.usual_change_color( diBALL_bondcolor_prefs_key)

    def reset_bond_colors(self):
        #bruce 050805 let's try it like this:
        env.prefs.restore_defaults([ #e this list should be defined in a more central place.
                                     bondHighlightColor_prefs_key,
                                     bondStretchColor_prefs_key,
                                     bondVaneColor_prefs_key,
                                     diBALL_bondcolor_prefs_key,
                                     ])

    def change_high_order_bond_display(self, val): #bruce 050806 filled this in
        """
        Slot for the button group that sets the high order bond display.
        """
        #  ('pi_bond_style',   ['multicyl','vane','ribbon'],  pibondStyle_prefs_key,   'multicyl' ),
        try:
            symbol = {0:'multicyl', 1:'vane', 2:'ribbon'}[val]
            # note: this decoding must use the same (arbitrary) int->symbol mapping as the button group does.
            # It's just a coincidence that the order is the same as in the prefs-type listed above.
        except KeyError: #bruce 060627 added specific exception class (untested)
            print "bug in change_high_order_bond_display: unknown val ignored:", val
        else:
            env.prefs[ pibondStyle_prefs_key ] = symbol
        return

    def change_bond_labels(self, val): #bruce 050806 filled this in
        """
        Slot for the checkbox that turns Pi Bond Letters on/off.
        """
        # (BTW, these are not "labels" -- someday we might add user-settable longer bond labels,
        #  and the term "labels" should refer to that. These are just letters indicating the bond type. [bruce 050806])
        env.prefs[ pibondLetters_prefs_key ] = not not val
        # See also the other use of pibondLetters_prefs_key, where the checkbox is kept current when first shown.
        return

    def change_show_valence_errors(self, val): #bruce 050806 made this up
        """
        Slot for the checkbox that turns Show Valence Errors on/off.
        """
        env.prefs[ showValenceErrors_prefs_key ] = not not val
##        if debug_flags.atom_debug:
##            print showValenceErrors_prefs_key, env.prefs[ showValenceErrors_prefs_key ] #k prints true, from our initial setup of page
        return

    def change_bond_line_thickness(self, pixel_thickness): #mark 050831
        """
        Set the default bond line thickness for Lines display.
        pixel_thickness can be 1, 2 or 3.
        """
        env.prefs[linesDisplayModeThickness_prefs_key] = pixel_thickness
        self.update_bond_line_thickness_suffix()

    def update_bond_line_thickness_suffix(self):
        """
        Updates the suffix for the bond line thickness spinbox.
        """
        if env.prefs[linesDisplayModeThickness_prefs_key] == 1:
            self.bond_line_thickness_spinbox.setSuffix(' pixel')
        else:
            self.bond_line_thickness_spinbox.setSuffix(' pixels')

    def change_ballstick_cylinder_radius(self, val):
        """
        Change the CPK (Ball and Stick) cylinder radius by % value <val>.
        """
        #bruce 060607 renamed change_cpk_cylinder_radius -> change_ballstick_cylinder_radius (in this file and .ui/.py dialog files)
        env.prefs[diBALL_BondCylinderRadius_prefs_key] = val *.01

        # Bruce wrote:
        #k gl_update is probably not needed and in some cases is a slowdown [bruce 060607 comment]
        # so I tested it and confirmed that gl_update() isn't needed.
        # Mark 2008-01-31
        #self.glpane.gl_update()

    ########## End of slot methods for "Bonds" page widgets ###########

    ########## Slot methods for "DNA" page widgets ################


    def dnaRestoreFactoryDefaults(self):
        """
        Slot for I{Restore Factory Defaults} button.
        """
        env.prefs.restore_defaults([
            bdnaBasesPerTurn_prefs_key,
            bdnaRise_prefs_key,
            dnaDefaultStrand1Color_prefs_key,
            dnaDefaultStrand2Color_prefs_key,
            dnaDefaultSegmentColor_prefs_key
        ])

        # These generate signals (good), which calls slots
        # save_dnaBasesPerTurn() and save_dnaRise()
        self.dnaBasesPerTurnDoubleSpinBox.setValue(env.prefs[bdnaBasesPerTurn_prefs_key])
        self.dnaRiseDoubleSpinBox.setValue(env.prefs[bdnaRise_prefs_key])

    def changeDnaDefaultStrand1Color(self):
        """
        Slot for the I{Choose...} button for changing the
        DNA default strand1 color.
        """
        self.usual_change_color( dnaDefaultStrand1Color_prefs_key )

    def changeDnaDefaultStrand2Color(self):
        """
        Slot for the I{Choose...} button for changing the
        DNA default strand2 color.
        """
        self.usual_change_color( dnaDefaultStrand2Color_prefs_key )

    def changeDnaDefaultSegmentColor(self):
        """
        Slot for the I{Choose...} button for changing the
        DNA default segment color.
        """
        self.usual_change_color( dnaDefaultSegmentColor_prefs_key )

    def save_dnaStrutScale(self, scale_factor):
        """
        Slot for B{Strut Scale Factor} spinbox.
        @param scale_factor: The struct scale factor.
        @type  scale_factor: int
        """
        env.prefs[dnaStrutScaleFactor_prefs_key] = scale_factor * .01

    def update_dnaStrandThreePrimeArrowheadCustomColorWidgets(self, enabled_flag):
        """
        Slot for the "Custom color" checkbox,for three prime arrowhead
        used to disable/enable thecolor related widgets (frame and choose button).
        """
        self.strandThreePrimeArrowheadsCustomColorFrame.setEnabled(enabled_flag)
        self.strandThreePrimeArrowheadsCustomColorPushButton.setEnabled(enabled_flag)
        return

    def update_dnaStrandFivePrimeArrowheadCustomColorWidgets(self, enabled_flag):
        """
        Slot for the "Custom color" checkbox, used to disable/enable the
        color related widgets (frame and choose button).
        """
        self.strandFivePrimeArrowheadsCustomColorFrame.setEnabled(enabled_flag)
        self.strandFivePrimeArrowheadsCustomColorPushButton.setEnabled(enabled_flag)
        return

    def change_dnaStrandThreePrimeArrowheadCustomColor(self):
        """
        Slot for the I{Choose...} button for changing the
        DNA strand three prime arrowhead color.
        """
        self.usual_change_color( dnaStrandThreePrimeArrowheadsCustomColor_prefs_key )

    def change_dnaStrandFivePrimeArrowheadCustomColor(self):
        """
        Slot for the I{Choose...} button for changing the
        DNA strand five prime arrowhead color.
        """
        self.usual_change_color( dnaStrandFivePrimeArrowheadsCustomColor_prefs_key )

    def save_dnaMinMinorGrooveAngles(self, minAngle):
        """
        Slot for minimum minor groove angle spinboxes.

        @param minAngle: The minimum angle.
        @type  minAngle: int
        """
        env.prefs[dnaMinMinorGrooveAngle_prefs_key] = minAngle

    def save_dnaMaxMinorGrooveAngles(self, maxAngle):
        """
        Slot for maximum minor groove angle spinboxes.

        @param maxAngle: The maximum angle.
        @type  maxAngle: int
        """
        env.prefs[dnaMaxMinorGrooveAngle_prefs_key] = maxAngle

    def change_dnaMinorGrooveErrorIndicatorColor(self):
        """
        Slot for the I{Choose...} button for changing the
        DNA minor groove error indicator color.
        """
        self.usual_change_color( dnaMinorGrooveErrorIndicatorColor_prefs_key )

    def _restore_dnaMinorGrooveFactoryDefaults(self):
        """
        Slot for Minor Groove Error Indicator I{Restore Factory Defaults}
        button.
        """
        env.prefs.restore_defaults([
            dnaMinMinorGrooveAngle_prefs_key,
            dnaMaxMinorGrooveAngle_prefs_key,
            dnaMinorGrooveErrorIndicatorColor_prefs_key,
        ])

        # These generate signals!
        self.dnaMinGrooveAngleSpinBox.setValue(
            env.prefs[dnaMinMinorGrooveAngle_prefs_key])
        self.dnaMaxGrooveAngleSpinBox.setValue(
            env.prefs[dnaMaxMinorGrooveAngle_prefs_key])

    # DNA display style piotr 080310
    def change_dnaStyleStrandsColor(self, value):
        """
        Changes DNA Style strands color.

        @param color: The color mode:
                    - 0 = color same as chunk
                    - 1 = base oder
                    - 2 = strand order
        @type color: int
        """
        env.prefs[dnaStyleStrandsColor_prefs_key] = value

    def change_dnaStyleStrutsColor(self, color):
        """
        Changes DNA Style struts color.

        @param color: The color mode:
                    - 0 = color same as chunk
                    - 1 = strand order
                    - 2 = base type

        @type color: int
        """
        env.prefs[dnaStyleStrutsColor_prefs_key] = color

    def change_dnaStyleAxisColor(self, color):
        """
        Changes DNA Style axis color.

        @param color: The color mode:
                    - 0 = color same as chunk
                    - 0 = color same as chunk
                    - 1 = base oder
                    - 2 = discrete bse order
                    - 3 = base type
                    - 4 = strand order

        @type color: int
        """
        env.prefs[dnaStyleAxisColor_prefs_key] = color

    def change_dnaStyleBasesColor(self, color):
        """
        Changes DNA Style bases color.

        @param color: The color mode:
                    - 0 = color same as chunk
                    - 1 = base order
                    - 2 = strand order
                    - 3 = base type

        @type color: int
        """
        env.prefs[dnaStyleBasesColor_prefs_key] = color

    def change_dnaStyleStrandsShape(self, shape):
        """
        Changes DNA Style strands shape.

        @param shape: The shape mode:
                    - 0 = none (hidden)
                    - 1 = cylinders
                    - 2 = tube

        @type shape: int
        """
        env.prefs[dnaStyleStrandsShape_prefs_key] = shape

    def change_dnaStyleStrutsShape(self, shape):
        """
        Changes DNA Style strands shape.

        @param shape: The shape mode:
                    - 0 = none (hidden)
                    - 1 = base-axis-base
                    - 2 = straight cylinders

        @type shape: int
        """
        env.prefs[dnaStyleStrutsShape_prefs_key] = shape

    def change_dnaStyleAxisShape(self, shape):
        """
        Changes DNA Style strands shape.

        @param shape: The shape mode:
                    - 0 = none (hidden)
                    - 1 = wide tube
                    - 2 = narrow tube

        @type shape: int
        """
        env.prefs[dnaStyleAxisShape_prefs_key] = shape

    def change_dnaStyleBasesShape(self, shape):
        """
        Changes DNA Style strands shape.

        @param shape: The shape mode:
                    - 0 = none (hidden)
                    - 1 = spheres
                    - 2 = cartoon-like

        @type shape: int
        """
        env.prefs[dnaStyleBasesShape_prefs_key] = shape

    def change_dnaStyleStrandsScale(self, scale_factor):
        """
        @param scale_factor: The strands scale factor.
        @type  scale_factor: float
        """
        env.prefs[dnaStyleStrandsScale_prefs_key] = scale_factor
        #self.update_dnaStyleStrandsScale()

    def update_dnaStyleStrandsScale(self):
        """
        Updates the DNA Style Strands Scale spin box.
        """
        # Set strands scale.

        self.dnaStyleStrandsScaleSpinBox.setValue(
            float(env.prefs[dnaStyleStrandsScale_prefs_key]))

    def change_dnaStyleStrutsScale(self, scale_factor):
        """
        @param scale_factor: The struts scale factor.
        @type  scale_factor: float
        """
        env.prefs[dnaStyleStrutsScale_prefs_key] = scale_factor

    def change_dnaStyleAxisScale(self, scale_factor):
        """
        @param scale_factor: The axis scale factor.
        @type  scale_factor: float
        """
        env.prefs[dnaStyleAxisScale_prefs_key] = scale_factor

    def change_dnaStyleBasesScale(self, scale_factor):
        """
        @param scale_factor: The bases scale factor.
        @type  scale_factor: float
        """
        env.prefs[dnaStyleBasesScale_prefs_key] = scale_factor
        #self.update_dnaStyleBasesScale()

    def update_dnaStyleBasesScale(self):
        """
        Updates the DNA Style bases scale spin box.
        """
        # Set axis scale.
        self.dnaStyleBasesScaleSpinBox.setValue(
            float(env.prefs[dnaStyleBasesScale_prefs_key]))

    def change_dnaBaseIndicatorsAngle(self, angle):
        """
        @param angle: The angular threshold for DNA base indicators.
        @type  angle: double
        """
        print "angle (set) = ", angle
        env.prefs[dnaBaseIndicatorsAngle_prefs_key] = angle
        self.update_dnaBaseIndicatorsAngle()

    def update_dnaBaseIndicatorsAngle(self):
        """
        Updates the DNA base orientation indicators angular threshold spinbox.
        """
        self.dnaBaseOrientationIndicatorsThresholdSpinBox.setValue(
            float(env.prefs[dnaBaseIndicatorsAngle_prefs_key]))

    def change_dnaBaseIndicatorsDistance(self, distance):
        """
        @param distance: The distance threshold for DNA base indicators.
        @type  distance: double
        """
        env.prefs[dnaBaseIndicatorsDistance_prefs_key] = distance
        self.update_dnaBaseIndicatorsDistance()

    def update_dnaBaseIndicatorsDistance(self):
        """
        Updates the DNA base orientation indicators distance threshold spinbox.
        """
        self.dnaBaseOrientationIndicatorsTerminalDistanceSpinBox.setValue(
            int(env.prefs[dnaBaseIndicatorsDistance_prefs_key]))

    def change_dnaStyleStrandsArrows(self, shape):
        """
        Changes DNA Style strands shape.

        @param shape: The shape mode:
                    - 0 = none (hidden)

        @type shape: int
        """
        env.prefs[dnaStyleStrandsArrows_prefs_key] = shape

    def change_dnaStyleAxisEndingStyle(self, shape):
        """
        Changes DNA Style strands ends.

        @param shape: The ending style shape:
                    - 0 = flat
                    - 1 = taper beginning
                    - 2 = taper ending
                    - 3 = taper both ends
                    - 4 = spherical

        @type shape: int
        """
        env.prefs[dnaStyleAxisEndingStyle_prefs_key] = shape

    def toggle_dnaDisplayStrandLabelsGroupBox(self, state):
        """
        Toggles DNA Strand Labels GroupBox.

        @param state: Is the GroupBox enabled?
                    - True = on
                    - False = off
        @type state: boolean
        """
        env.prefs[dnaStrandLabelsEnabled_prefs_key] = state

    def toggle_dnaDisplayBaseOrientationIndicatorsGroupBox(self, state):
        """
        Toggles DNA Base Orientation Indicators GroupBox.

        @param state: Is the GroupBox enabled?
                    - True = on
                    - False = off
        @type state: boolean
        """
        env.prefs[dnaBaseIndicatorsEnabled_prefs_key] = state

    def toggle_dnaDisplayBaseOrientationInvIndicatorsCheckBox(self, state):
        """
        Toggles DNA Base Orientation Inverse Indicators CheckBox.

        @param state: Is the CheckBox enabled?
                    - True = on
                    - False = off
        @type state: boolean
        """
        env.prefs[dnaBaseInvIndicatorsEnabled_prefs_key] = state

    def toggle_dnaStyleBasesDisplayLettersCheckBox(self, state):
        """
        Toggles DNA Base Letters.

        @param state: Is the CheckBox enabled?
                    - True = on
                    - False = off
        @type state: boolean
        """
        env.prefs[dnaStyleBasesDisplayLetters_prefs_key] = state

    def change_dnaBaseOrientIndicatorsPlane(self, idx):
        """
        Slot for the "Plane" combobox for changing the
        DNA base indicators plane.
        """
        env.prefs[dnaBaseIndicatorsPlaneNormal_prefs_key] = idx

    def change_dnaBaseIndicatorsColor(self):
        """
        Slot for the I{Choose...} button for changing the
        DNA base indicators color.
        """
        self.usual_change_color( dnaBaseIndicatorsColor_prefs_key )

    def change_dnaBaseInvIndicatorsColor(self):
        """
        Slot for the I{Choose...} button for changing the
        DNA base inverse indicators color.
        """
        self.usual_change_color( dnaBaseInvIndicatorsColor_prefs_key )

    def change_dnaStrandLabelsColor(self):
        """
        Slot for the I{Choose...} button for changing the
        DNA strand labels color.
        """
        self.usual_change_color( dnaStrandLabelsColor_prefs_key )

    def change_dnaStrandLabelsColorMode(self, mode):
        """
        Changes DNA Style strand labels color mode.

        @param mode: The color mode:
                    - 0 = same as chunk
                    - 1 = black
                    - 2 = white
                    - 3 = custom

        @type mode: int
        """
        env.prefs[dnaStrandLabelsColorMode_prefs_key] = mode

    # == End of slot methods for "DNA" page widgets ==

    # == Slot methods for "Lighting" page widgets ==

    def change_lighting(self, specularityValueJunk = None):
        """
        Updates glpane lighting using the current lighting parameters from
        the light checkboxes and sliders. This is also the slot for the light
        sliders.
        @param specularityValueJunk: This value from the slider is not used
                                     We are interested in valueChanged signal
                                     only
        @type specularityValueJunk = int or None

        """

        light_num = self.light_combobox.currentIndex()

        light1, light2, light3 = self.glpane.getLighting()

        a = self.light_ambient_slider.value() * .01
        d = self.light_diffuse_slider.value() * .01
        s = self.light_specularity_slider.value()  * .01

        self.light_ambient_linedit.setText(str(a))
        self.light_diffuse_linedit.setText(str(d))
        self.light_specularity_linedit.setText(str(s))

        new_light = [  self.light_color, a, d, s, \
                       float(str(self.light_x_linedit.text())), \
                       float(str(self.light_y_linedit.text())), \
                       float(str(self.light_z_linedit.text())), \
                       self.light_checkbox.isChecked()]

        # This is a kludge.  I'm certain there is a more elegant way.  Mark 051204.
        if light_num == 0:
            self.glpane.setLighting([new_light, light2, light3])
        elif light_num == 1:
            self.glpane.setLighting([light1, new_light, light3])
        elif light_num == 2:
            self.glpane.setLighting([light1, light2, new_light])
        else:
            print "Unsupported light # ", light_num,". No lighting change made."

    def change_active_light(self, currentIndexJunk = None):
        """
        Slot for the Light number combobox.  This changes the current light.
        @param currentIndexJunk: This index value from the combobox is not used
                                 We are interested in 'activated' signal only
        @type currentIndexJunk = int or None
        """
        self._updatePage_Lighting()

    def change_light_color(self):
        """
        Slot for light color "Choose" button.  Saves the new color in the
        prefs db.

        Changes the current Light color in the graphics area and the light
        color swatch in the UI.
        """
        self.usual_change_color(self.current_light_key)
        self.light_color = env.prefs[self.current_light_key]
        self.save_lighting()

    def update_light_combobox_items(self):
        """Updates all light combobox items with '(On)' or '(Off)' label.
        """
        for i in range(3):
            if self.lights[i][7]:
                txt = "%d (On)" % (i+1)
            else:
                txt = "%d (Off)" % (i+1)
            self.light_combobox.setItemText(i, txt)

    def toggle_light(self, on):
        """
        Slot for light 'On' checkbox.
        It updates the current item in the light combobox with '(On)' or
        '(Off)' label.
        """
        if on:
            txt = "%d (On)" % (self.light_combobox.currentIndex()+1)
        else:
            txt = "%d (Off)" % (self.light_combobox.currentIndex()+1)
        self.light_combobox.setItemText(self.light_combobox.currentIndex(),txt)

        self.save_lighting()

    def save_lighting(self):
        """
        Saves lighting parameters (but not material specularity parameters)
        to pref db. This is also the slot for light sliders (only when
        released).
        """
        self.change_lighting()
        self.glpane.saveLighting()

    def toggle_material_specularity(self, val):
        """
        This is the slot for the Material Specularity Enabled checkbox.
        """
        env.prefs[material_specular_highlights_prefs_key] = val

    def change_material_finish(self, finish):
        """
        This is the slot for the Material Finish slider.
        'finish' is between 0 and 100.
        Saves finish parameter to pref db.
        """
        # For whiteness, the stored range is 0.0 (Metal) to 1.0 (Plastic).
        # The Qt slider range is 0 - 100, so we multiply by 100 to set the slider.  Mark. 051129.
        env.prefs[material_specular_finish_prefs_key] = float(finish * 0.01)
        self.ms_finish_linedit.setText(str(finish * 0.01))

    def change_material_shininess(self, shininess):
        """
        This is the slot for the Material Shininess slider.
        'shininess' is between 15 (low) and 60 (high).
        """
        env.prefs[material_specular_shininess_prefs_key] = float(shininess)
        self.ms_shininess_linedit.setText(str(shininess))

    def change_material_brightness(self, brightness):
        """
        This is the slot for the Material Brightness slider.
        'brightness' is between 0 (low) and 100 (high).
        """
        env.prefs[material_specular_brightness_prefs_key] = float(brightness * 0.01)
        self.ms_brightness_linedit.setText(str(brightness * 0.01))

    def change_material_finish_start(self):
        if debug_sliders: print "Finish slider pressed"
        env.prefs.suspend_saving_changes() #bruce 051205 new prefs feature - keep updating to glpane but not (yet) to disk

    def change_material_finish_stop(self):
        if debug_sliders: print "Finish slider released"
        env.prefs.resume_saving_changes() #bruce 051205 new prefs feature - save accumulated changes now

    def change_material_shininess_start(self):
        if debug_sliders: print "Shininess slider pressed"
        env.prefs.suspend_saving_changes()

    def change_material_shininess_stop(self):
        if debug_sliders: print "Shininess slider released"
        env.prefs.resume_saving_changes()

    def change_material_brightness_start(self):
        if debug_sliders: print "Brightness slider pressed"
        env.prefs.suspend_saving_changes()

    def change_material_brightness_stop(self):
        if debug_sliders: print "Brightness slider released"
        env.prefs.resume_saving_changes()

    def reset_lighting(self):
        """
        Slot for Reset button.
        """
        # This has issues.
        # I intend to remove the Reset button for A7.  Confirm with Bruce.  Mark 051204.
        self._setup_material_group(reset = True)
        self._updatePage_Lighting(self.original_lights)
        self.glpane.saveLighting()

    def restore_default_lighting(self):
        """
        Slot for Restore Defaults button.
        """

        self.glpane.restoreDefaultLighting()

        # Restore defaults for the Material Specularity properties
        env.prefs.restore_defaults([
            material_specular_highlights_prefs_key,
            material_specular_shininess_prefs_key,
            material_specular_finish_prefs_key,
            material_specular_brightness_prefs_key, #bruce 051203 bugfix
        ])

        self._updatePage_Lighting()
        self.save_lighting()

    ########## End of slot methods for "Lighting" page widgets ###########

    ########## Slot methods for "Plug-ins" page widgets ################

    def choose_gamess_path(self):
        """
        Slot for GAMESS path "Choose" button.
        """
        gamess_exe = get_filename_and_save_in_prefs(self,
                                                    gmspath_prefs_key,
                                                    'Choose GAMESS Executable')

        if gamess_exe:
            self.gamess_path_lineedit.setText(env.prefs[gmspath_prefs_key])

    def set_gamess_path(self, newValue):
        """
        Slot for GAMESS path line editor.
        """
        env.prefs[gamess_path_prefs_key] = str_or_unicode(newValue)

    def enable_gamess(self, enable = True):
        """
        Enables/disables GAMESS plugin.

        @param enable: Enabled when True. Disables when False.
        @type  enable: bool
        """
        if enable:
            self.gamess_path_lineedit.setEnabled(1)
            self.gamess_choose_btn.setEnabled(1)
            env.prefs[gamess_enabled_prefs_key] = True

        else:
            self.gamess_path_lineedit.setEnabled(0)
            self.gamess_choose_btn.setEnabled(0)
            #self.gamess_path_lineedit.setText("")
            #env.prefs[gmspath_prefs_key] = ''
            env.prefs[gamess_enabled_prefs_key] = False

    # GROMACS slots #######################################

    def choose_gromacs_path(self):
        """
        Slot for GROMACS path "Choose" button.
        """

        mdrun_executable = \
                         get_filename_and_save_in_prefs(self,
                                                        gromacs_path_prefs_key,
                                                        'Choose mdrun executable (GROMACS)')

        if mdrun_executable:
            self.gromacs_path_lineedit.setText(env.prefs[gromacs_path_prefs_key])

    def set_gromacs_path(self, newValue):
        """
        Slot for GROMACS path line editor.
        """
        env.prefs[gromacs_path_prefs_key] = str_or_unicode(newValue)

    def enable_gromacs(self, enable = True):
        """
        If True, GROMACS path is set in Preferences>Plug-ins

        @param enable: Is the path set?
        @type  enable: bool
        """

        state = self.gromacs_checkbox.checkState()
        if enable:
            if (state != Qt.Checked):
                self.gromacs_checkbox.setCheckState(Qt.Checked)
            self.gromacs_path_lineedit.setEnabled(True)
            self.gromacs_choose_btn.setEnabled(True)
            env.prefs[gromacs_enabled_prefs_key] = True

            # Sets the GROMACS (executable) path to the standard location, if it exists.
            if not env.prefs[gromacs_path_prefs_key]:
                env.prefs[gromacs_path_prefs_key] = get_default_plugin_path( \
                    "C:\\GROMACS_3.3.3\\bin\\mdrun.exe", \
                    "/Applications/GROMACS_3.3.3/bin/mdrun",
                    "/usr/bin/g_mdrun")

            self.gromacs_path_lineedit.setText(env.prefs[gromacs_path_prefs_key])

        else:
            if (state != Qt.Unchecked):
                self.gromacs_checkbox.setCheckState(Qt.Unchecked)
            self.gromacs_path_lineedit.setEnabled(False)
            self.gromacs_choose_btn.setEnabled(False)
            #self.gromacs_path_lineedit.setText("")
            #env.prefs[gromacs_path_prefs_key] = ''
            env.prefs[gromacs_enabled_prefs_key] = False

    # cpp slots #######################################

    def choose_cpp_path(self):
        """
        Sets the path to cpp (C pre-processor)
        """

        cpp_executable = get_filename_and_save_in_prefs(self,
                                                        cpp_path_prefs_key,
                                                        'Choose cpp Executable (used by GROMACS)')

        if cpp_executable:
            self.cpp_path_lineedit.setText(env.prefs[cpp_path_prefs_key])

    def set_cpp_path(self, newValue):
        """
        Slot for cpp path line editor.
        """
        env.prefs[cpp_path_prefs_key] = str_or_unicode(newValue)

    def enable_cpp(self, enable = True):
        """
        Enables/disables cpp plugin.

        @param enable: Enabled when True. Disables when False.
        @type  enable: bool
        """
        state = self.cpp_checkbox.checkState()
        if enable:
            if (state != Qt.Checked):
                self.cpp_checkbox.setCheckState(Qt.Checked)
            self.cpp_path_lineedit.setEnabled(True)
            self.cpp_choose_btn.setEnabled(True)
            env.prefs[cpp_enabled_prefs_key] = True

            # Sets the cpp path to the standard location, if it exists.
            if not env.prefs[cpp_path_prefs_key]:
                env.prefs[cpp_path_prefs_key] = get_default_plugin_path( \
                    "C:\\GROMACS_3.3.3\\MCPP\\bin\\mcpp.exe", \
                    "/Applications/GROMACS_3.3.3/mcpp/bin/mcpp", \
                    "/usr/bin/cpp")

            self.cpp_path_lineedit.setText(env.prefs[cpp_path_prefs_key])

        else:
            if (state != Qt.Unchecked):
                self.cpp_checkbox.setCheckState(Qt.Unchecked)
            self.cpp_path_lineedit.setEnabled(False)
            self.cpp_choose_btn.setEnabled(False)
            #self.cpp_path_lineedit.setText("")
            #env.prefs[cpp_path_prefs_key] = ''
            env.prefs[cpp_enabled_prefs_key] = False

    # NanoVision-1 slots #######################################

    def choose_nv1_path(self):
        """
        Slot for NanoVision-1 path "Choose" button.
        """

        nv1_executable = get_filename_and_save_in_prefs(self,
                                                        nv1_path_prefs_key,
                                                        'Choose NanoVision-1 Executable')

        if nv1_executable:
            self.nv1_path_lineedit.setText(env.prefs[nv1_path_prefs_key])

    def set_nv1_path(self, newValue):
        """
        Slot for NanoVision-1 path line editor.
        """
        env.prefs[nv1_path_prefs_key] = str_or_unicode(newValue)

    def enable_nv1(self, enable = True):
        """
        If True, NV1 path is set in Preferences > Plug-ins

        @param enable: Is the path set?
        @type  enable: bool
        """

        state = self.nv1_checkbox.checkState()
        if enable:
            if (state != Qt.Checked):
                self.nv1_checkbox.setCheckState(Qt.Checked)
            self.nv1_path_lineedit.setEnabled(True)
            self.nv1_choose_btn.setEnabled(True)
            env.prefs[nv1_enabled_prefs_key] = True

            # Sets the NV1 (executable) path to the standard location, if it exists.
            if not env.prefs[nv1_path_prefs_key]:
                env.prefs[nv1_path_prefs_key] = get_default_plugin_path( \
                    "C:\\Program Files\\Nanorex\\NanoVision-1\\NanoVision-1.exe", \
                    "/Applications/Nanorex/NanoVision-1 0.1.0/NanoVision-1.app", \
                    "/usr/local/Nanorex/NanoVision-1 0.1.0/NanoVision-1")

            self.nv1_path_lineedit.setText(env.prefs[nv1_path_prefs_key])

        else:
            if (state != Qt.Unchecked):
                self.nv1_checkbox.setCheckState(Qt.Unchecked)
            self.nv1_path_lineedit.setEnabled(False)
            self.nv1_choose_btn.setEnabled(False)
            #self.nv1_path_lineedit.setText("")
            #env.prefs[nv1_path_prefs_key] = ''
            env.prefs[nv1_enabled_prefs_key] = False
        return

    # Rosetta slots #######################################

    def choose_rosetta_path(self):
        """
        Slot for Rosetta path "Choose" button.
        """

        rosetta_executable = get_filename_and_save_in_prefs(self,
                                                        rosetta_path_prefs_key,
                                                        'Choose Rosetta Executable')

        if rosetta_executable:
            self.rosetta_path_lineedit.setText(env.prefs[rosetta_path_prefs_key])

    def set_rosetta_path(self, newValue):
        """
        Slot for Rosetta path line editor.
        """
        env.prefs[rosetta_path_prefs_key] = str_or_unicode(newValue)
        return

    def enable_rosetta(self, enable = True):
        """
        If True, rosetta path is set in Preferences > Plug-ins

        @param enable: Is the path set?
        @type  enable: bool
        """

        state = self.rosetta_checkbox.checkState()
        if enable:
            if (state != Qt.Checked):
                self.rosetta_checkbox.setCheckState(Qt.Checked)
            self.rosetta_path_lineedit.setEnabled(True)
            self.rosetta_choose_btn.setEnabled(True)
            env.prefs[rosetta_enabled_prefs_key] = True

            # Sets the rosetta (executable) path to the standard location, if it exists.
            if not env.prefs[rosetta_path_prefs_key]:
                env.prefs[rosetta_path_prefs_key] = get_default_plugin_path( \
                    "C:\\Rosetta\\rosetta.exe", \
                    "/Users/marksims/Nanorex/Rosetta/rosetta++/rosetta.mactel", \
                    "/usr/local/Rosetta/Rosetta")

            self.rosetta_path_lineedit.setText(env.prefs[rosetta_path_prefs_key])

        else:
            if (state != Qt.Unchecked):
                self.rosetta_checkbox.setCheckState(Qt.Unchecked)
            self.rosetta_path_lineedit.setEnabled(False)
            self.rosetta_choose_btn.setEnabled(False)
            env.prefs[rosetta_enabled_prefs_key] = False
        return

    # Rosetta DB slots #######################################

    def choose_rosetta_db_path(self):
        """
        Slot for Rosetta DB path "Choose" button.
        """

        rosetta_db_executable = get_filename_and_save_in_prefs(self,
                                                        rosetta_dbdir_prefs_key,
                                                        'Choose Rosetta database directory')

        # piotr 081908: this pref key doesn't exist
        #if rosetta_db_executable:
        #    self.rosetta_db_path_lineedit.setText(env.prefs[rosetta_db_path_prefs_key])

    def set_rosetta_db_path(self, newValue):
        """
        Slot for Rosetta db path line editor.
        """
        env.prefs[rosetta_dbdir_prefs_key] = str_or_unicode(newValue)

    def enable_rosetta_db(self, enable = True):
        """
        If True, rosetta db path is set in Preferences > Plug-ins

        @param enable: Is the path set?
        @type  enable: bool
        """

        state = self.rosetta_db_checkbox.checkState()
        if enable:
            if (state != Qt.Checked):
                self.rosetta_db_checkbox.setCheckState(Qt.Checked)
            self.rosetta_db_path_lineedit.setEnabled(True)
            self.rosetta_db_choose_btn.setEnabled(True)
            env.prefs[rosetta_database_enabled_prefs_key] = True

            # Sets the rosetta (executable) path to the standard location, if it exists.
            if not env.prefs[rosetta_dbdir_prefs_key]:
                env.prefs[rosetta_dbdir_prefs_key] = get_default_plugin_path( \
                    "C:\\Rosetta\\rosetta_database", \
                    "/Users/marksims/Nanorex/Rosetta/Rosetta_database", \
                    "/usr/local/Rosetta/Rosetta_database")

            self.rosetta_db_path_lineedit.setText(env.prefs[rosetta_dbdir_prefs_key])

        else:
            if (state != Qt.Unchecked):
                self.rosetta_db_checkbox.setCheckState(Qt.Unchecked)
            self.rosetta_db_path_lineedit.setEnabled(False)
            self.rosetta_db_choose_btn.setEnabled(False)
            env.prefs[rosetta_database_enabled_prefs_key] = False
        return

    # QuteMolX slots #######################################

    def choose_qutemol_path(self):
        """
        Slot for QuteMolX path "Choose" button.
        """
        qp = get_filename_and_save_in_prefs(self,
                                            qutemol_path_prefs_key,
                                            'Choose QuteMolX Executable')

        if qp:
            self.qutemol_path_lineedit.setText(qp)

    def set_qutemol_path(self, newValue):
        """
        Slot for QuteMol path line editor.
        """
        env.prefs[qutemol_path_prefs_key] = str_or_unicode(newValue)

    def enable_qutemol(self, enable = True):
        """
        Enables/disables QuteMolX plugin.

        @param enable: Enabled when True. Disables when False.
        @type  enable: bool
        """
        if enable:
            self.qutemol_path_lineedit.setEnabled(1)
            self.qutemol_choose_btn.setEnabled(1)
            env.prefs[qutemol_enabled_prefs_key] = True

            # Sets the QuteMolX (executable) path to the standard location, if it exists.
            if not env.prefs[qutemol_path_prefs_key]:
                env.prefs[qutemol_path_prefs_key] = get_default_plugin_path( \
                    "C:\\Program Files\\Nanorex\\QuteMolX\\QuteMolX.exe", \
                    "/Applications/Nanorex/QuteMolX 0.5.0/QuteMolX.app", \
                    "/usr/local/Nanorex/QuteMolX 0.5.0/QuteMolX")

            self.qutemol_path_lineedit.setText(env.prefs[qutemol_path_prefs_key])

        else:
            self.qutemol_path_lineedit.setEnabled(0)
            self.qutemol_choose_btn.setEnabled(0)
            #self.qutemol_path_lineedit.setText("")
            #env.prefs[qutemol_path_prefs_key] = ''
            env.prefs[qutemol_enabled_prefs_key] = False

    # NanoHive-1 slots #####################################

    def choose_nanohive_path(self):
        """
        Slot for Nano-Hive path "Choose" button.
        """

        nh = get_filename_and_save_in_prefs(self,
                                            nanohive_path_prefs_key,
                                            'Choose Nano-Hive Executable')

        if nh:
            self.nanohive_path_lineedit.setText(nh)

    def set_nanohive_path(self, newValue):
        """
        Slot for NanoHive path line editor.
        """
        env.prefs[nanohive_path_prefs_key] = str_or_unicode(newValue)

    def enable_nanohive(self, enable = True):
        """
        Enables/disables NanoHive-1 plugin.

        @param enable: Enabled when True. Disables when False.
        @type  enable: bool

        @attention: This is disabled since the NH1 plugin doesn't work yet.
        """
        if enable:
            self.nanohive_path_lineedit.setEnabled(1)
            self.nanohive_choose_btn.setEnabled(1)
            # Leave Nano-Hive action button/menu hidden for A7.  Mark 2006-01-04.
            # self.w.simNanoHiveAction.setVisible(1)

            # Sets the Nano-Hive (executable) path to the standard location, if it exists.
            if not env.prefs[nanohive_path_prefs_key]:
                env.prefs[nanohive_path_prefs_key] = get_default_plugin_path(
                    "C:\\Program Files\\Nano-Hive\\bin\\win32-x86\\NanoHive.exe", \
                    "/usr/local/bin/NanoHive", \
                    "/usr/local/bin/NanoHive")


            env.prefs[nanohive_enabled_prefs_key] = True
            self.nanohive_path_lineedit.setText(env.prefs[nanohive_path_prefs_key])

            # Create the Nano-Hive dialog widget.
            # Not needed for A7.  Mark 2006-01-05.
            #if not self.w.nanohive:
            #    from NanoHive import NanoHive
            #    self.w.nanohive = NanoHive(self.assy)

        else:
            self.nanohive_path_lineedit.setEnabled(0)
            self.nanohive_choose_btn.setEnabled(0)
            self.w.nanohive = None
            self.w.simNanoHiveAction.setVisible(0)
            #self.nanohive_path_lineedit.setText("")
            #env.prefs[nanohive_path_prefs_key] = ''
            env.prefs[nanohive_enabled_prefs_key] = False

    # POV-Ray slots #####################################

    def choose_povray_path(self):
        """
        Slot for POV-Ray path "Choose" button.
        """
        povray_exe = get_filename_and_save_in_prefs(self,
                                                    povray_path_prefs_key,
                                                    'Choose POV-Ray Executable')

        if povray_exe:
            self.povray_path_lineedit.setText(povray_exe)

    def set_povray_path(self, newValue):
        """
        Slot for POV-Ray path line editor.
        """
        env.prefs[povray_path_prefs_key] = str_or_unicode(newValue)

    def enable_povray(self, enable = True):
        """
        Enables/disables POV-Ray plugin.

        @param enable: Enabled when True. Disables when False.
        @type  enable: bool
        """
        if enable:
            self.povray_path_lineedit.setEnabled(1)
            self.povray_choose_btn.setEnabled(1)
            env.prefs[povray_enabled_prefs_key] = True

            # Sets the POV-Ray (executable) path to the standard location, if it exists.
            if not env.prefs[povray_path_prefs_key]:
                env.prefs[povray_path_prefs_key] = get_default_plugin_path( \
                    "C:\\Program Files\\POV-Ray for Windows v3.6\\bin\\pvengine.exe", \
                    "/usr/local/bin/pvengine", \
                    "/usr/local/bin/pvengine")

            self.povray_path_lineedit.setText(env.prefs[povray_path_prefs_key])

        else:
            self.povray_path_lineedit.setEnabled(0)
            self.povray_choose_btn.setEnabled(0)
            #self.povray_path_lineedit.setText("")
            #env.prefs[povray_path_prefs_key] = ''
            env.prefs[povray_enabled_prefs_key] = False
        self._update_povdir_enables() #bruce 060710

    # MegaPOV slots #####################################

    def choose_megapov_path(self):
        """
        Slot for MegaPOV path "Choose" button.
        """
        megapov_exe = get_filename_and_save_in_prefs(self, megapov_path_prefs_key, 'Choose MegaPOV Executable')

        if megapov_exe:
            self.megapov_path_lineedit.setText(megapov_exe)

    def set_megapov_path(self, newValue):
        """
        Slot for MegaPOV path line editor.
        """
        env.prefs[megapov_path_prefs_key] = str_or_unicode(newValue)

    def enable_megapov(self, enable = True):
        """
        Enables/disables MegaPOV plugin.

        @param enable: Enabled when True. Disables when False.
        @type  enable: bool
        """
        if enable:
            self.megapov_path_lineedit.setEnabled(1)
            self.megapov_choose_btn.setEnabled(1)
            env.prefs[megapov_enabled_prefs_key] = True

            # Sets the MegaPOV (executable) path to the standard location, if it exists.
            if not env.prefs[megapov_path_prefs_key]:
                env.prefs[megapov_path_prefs_key] = get_default_plugin_path( \
                    "C:\\Program Files\\POV-Ray for Windows v3.6\\bin\\megapov.exe", \
                    "/usr/local/bin/megapov", \
                    "/usr/local/bin/megapov")

            self.megapov_path_lineedit.setText(env.prefs[megapov_path_prefs_key])

        else:
            self.megapov_path_lineedit.setEnabled(0)
            self.megapov_choose_btn.setEnabled(0)
            #self.megapov_path_lineedit.setText("")
            #env.prefs[megapov_path_prefs_key] = ''
            env.prefs[megapov_enabled_prefs_key] = False
        self._update_povdir_enables() #bruce 060710

    # POV-Ray include slots #######################################

    # pov include directory [bruce 060710 for Mac A8; will be A8.1 in Windows, not sure about Linux]

    def _update_povdir_enables(self): #bruce 060710
        """
        [private method]
        Call this whenever anything changes regarding when to enable the povdir checkbox, line edit, or choose button.
        We enable the checkbox when either of the POV-Ray or MegaPOV plugins is enabled.
        We enable the line edit and choose button when that condition holds and when the checkbox is checked.
        We update this when any relevant checkbox changes, or when showing this page.
        This will work by reading prefs values, so only call it from slot methods after they have updated prefs values.
        """
        enable_checkbox = env.prefs[povray_enabled_prefs_key] or env.prefs[megapov_enabled_prefs_key]
        self.povdir_checkbox.setEnabled(enable_checkbox)
        self.povdir_lbl.setEnabled(enable_checkbox)
        enable_edits = enable_checkbox and env.prefs[povdir_enabled_prefs_key]
            # note: that prefs value should and presumably does agree with self.povdir_checkbox.isChecked()
        self.povdir_lineedit.setEnabled(enable_edits)
        self.povdir_choose_btn.setEnabled(enable_edits)
        return

    def enable_povdir(self, enable = True): #bruce 060710
        """
        Slot method for povdir checkbox.
        povdir is enabled when enable = True.
        povdir is disabled when enable = False.
        """
        env.prefs[povdir_enabled_prefs_key] = not not enable
        self._update_povdir_enables()
##        self.povdir_lineedit.setText(env.prefs[povdir_path_prefs_key])
        return

    def set_povdir(self): #bruce 060710
        """
        Slot for Pov include dir "Choose" button.
        """
        povdir_path = get_dirname_and_save_in_prefs(self, povdir_path_prefs_key, 'Choose Custom POV-Ray Include directory')
        # note: return value can't be ""; if user cancels, value is None;
        # to set "" you have to edit the lineedit text directly, but this doesn't work since
        # no signal is caught to save that into the prefs db!
        # ####@@@@ we ought to catch that signal... is it returnPressed?? would that be sent if they were editing it, then hit ok?
        # or if they clicked elsewhere? (currently that fails to remove focus from the lineedits, on Mac, a minor bug IMHO)
        # (or uncheck the checkbox for the same effect). (#e do we want a "clear" button, for A8.1?)

        if povdir_path:
            self.povdir_lineedit.setText(env.prefs[povdir_path_prefs_key])
            # the function above already saved it in prefs, under the same condition
        return

    def povdir_lineedit_textChanged(self, *args): #bruce 060710
        if debug_povdir_signals():
            print "povdir_lineedit_textChanged",args
            # this happens on programmatic changes, such as when the page is shown or the choose button slot sets the text
        try:
            # note: Ideally we'd only do this when return was pressed, mouse was clicked elsewhere (with that also removing keyfocus),
            # other keyfocus removals, including dialog ok or cancel. That is mostly nim,
            # so we have to do it all the time for now -- this is the only way for the user to set the text to "".
            # (This even runs on programmatic sets of the text. Hope that's ok.)
            env.prefs[povdir_path_prefs_key] = path = str_or_unicode( self.povdir_lineedit.text() ).strip()
            if debug_povdir_signals():
                print "debug fyi: set pov include dir to [%s]" % (path,)
        except:
            if env.debug():
                print_compact_traceback("bug, ignored: ")
        return

    def povdir_lineedit_returnPressed(self, *args): #bruce 060710
        if debug_povdir_signals():
            print "povdir_lineedit_returnPressed",args
            # this happens when return is pressed in the widget, but NOT when user clicks outside it
            # or presses OK on the dialog -- which means it's useless when taken alone,
            # in case user edits text and then presses ok without ever pressing return.

    ########## End of slot methods for "Plug-ins" page widgets ###########

    ########## Slot methods for "Undo" (former name "Caption") page widgets ################

    def change_undo_stack_memory_limit(self, mb_val):
        """
        Slot for 'Undo Stack Memory Limit' spinbox.
        Sets the RAM limit for the Undo Stack.
        <mb-val> can range from 0-99999 (MB).
        """
        env.prefs[undoStackMemoryLimit_prefs_key] = mb_val

    def change_historyHeight(self, value):
        """
        Slot for  history height spinbox.
        """
        env.prefs[ historyHeight_prefs_key] = value

    ########## End of slot methods for "Undo" page widgets ###########

    ########## Start slot methods for "ToolTips" page widgets ###########
    def change_dynamicToolTipAtomDistancePrecision(self, value):
        """
        Update the atom distance precision for the dynamic tool tip.
        """
        env.prefs[ dynamicToolTipAtomDistancePrecision_prefs_key ] = value

    def change_dynamicToolTipBendAnglePrecision(self, value):
        """
        Update the bend angle precision for the dynamic tool tip.
        """
        env.prefs[ dynamicToolTipBendAnglePrecision_prefs_key ] = value

    ########## End of slot methods for "ToolTips" page widgets ###########

    ########## Slot methods for "Window" (former name "Caption") page widgets ################

    #e there are some new slot methods for this in other places, which should be refiled here. [bruce 050811]

    def change_window_size(self, val = 0):
        """
        Slot for both the width and height spinboxes that change the current
        window size.

        Also called from other slots to change the window size based on new
        values in spinboxes. <val> is not used.
        """
        w = self.current_width_spinbox.value()
        h = self.current_height_spinbox.value()
        self.w.resize(w,h)

    def update_saved_size(self, w, h):
        """
        Update the saved width and height text.
        """
        self.saved_width_lineedit.setText(QString(str(w) + " pixels"))
        self.saved_height_lineedit.setText(QString(str(h) + " pixels"))

    def save_current_win_pos_and_size(self): #bruce 051218; see also debug.py's _debug_save_window_layout
        from utilities.prefs_constants import mainwindow_geometry_prefs_key_prefix
        keyprefix = mainwindow_geometry_prefs_key_prefix
        save_window_pos_size( self.w, keyprefix) # prints history message
        size = self.w.size()
        self.update_saved_size(size.width(), size.height())
        return

    def restore_saved_size(self):
        """
        Restore the window size, but not the position, from the prefs db.
        """
        from utilities.prefs_constants import mainwindow_geometry_prefs_key_prefix
        keyprefix = mainwindow_geometry_prefs_key_prefix
        pos, size = _get_prefs_for_window_pos_size( self.w, keyprefix)
        w = size[0]
        h = size[1]
        self.update_saved_size(w, h)
        self.current_width_spinbox.setValue(w)
        self.current_height_spinbox.setValue(h)
        self.change_window_size()
        return

    def change_use_selected_font(self, use_selected_font):
        """
        Slot for "Use Selected Font" checkbox on the groupbox.
        Called when the checkbox is toggled.
        """
        env.prefs[useSelectedFont_prefs_key] = use_selected_font
        self.set_font()
        return

    def change_font(self, font):
        """
        Slot for the Font combobox.
        Called whenever the font is changed.
        """
        env.prefs[displayFont_prefs_key] = str_or_unicode(font.family())
        self.set_font()
        return

    def change_fontsize(self, pointsize):
        """
        Slot for the Font size spinbox.
        """
        env.prefs[displayFontPointSize_prefs_key] = pointsize
        self.set_font()
        return

    def change_selected_font_to_default_font(self):
        """
        Slot for "Make the selected font the default font" button.
        The default font will be displayed in the Font and Size
        widgets.
        """
        font = self.w.defaultFont
        env.prefs[displayFont_prefs_key] = str_or_unicode(font.family())
        env.prefs[displayFontPointSize_prefs_key] = font.pointSize()
        self.set_font_widgets(setFontFromPrefs = True) # Also sets the current display font.

        if debug_flags.atom_debug:
            print "change_selected_font_to_default_font(): " \
                  "Button clicked. Default font: ", font.family(), \
                  ", size=", font.pointSize()
        return

    def set_font_widgets(self, setFontFromPrefs = True):
        """
        Update font widgets based on font prefs.
        Unconnects signals from slots, updates widgets, then reconnects slots.

        @param setFontFromPrefs: when True (default), sets the display font
                                (based on font prefs).
        @type  setFontFromPrefs: bool
        """

        if debug_flags.atom_debug:
            print "set_font_widgets(): Here!"


        if env.prefs[displayFont_prefs_key] == "defaultFont":
            # Set the font and point size prefs to the application's default font.
            # This code only called the first time NE1 is run (or the prefs db does not exist)
            font = self.w.defaultFont
            font_family = str_or_unicode(font.family())
                # Note: when this used str() rather than str_or_unicode(),
                # it prevented NE1 from running on some international systems
                # (when it had never run before and needed to initialize this
                #  prefs value).
                # We can now reproduce the bug (see bug 2883 for details),
                # so I am using str_or_unicode to try to fix it. [bruce 080529]
            font_size = font.pointSize()
            env.prefs[displayFont_prefs_key] = font_family
            env.prefs[displayFontPointSize_prefs_key] = font_size
            if debug_flags.atom_debug:
                print "set_font_widgets(): No prefs db. " \
                      "Using default font: ", font.family(), \
                      ", size=", font.pointSize()

        else:
            font_family = env.prefs[displayFont_prefs_key]
            font_size = env.prefs[displayFontPointSize_prefs_key]
            font = QFont(font_family, font_size)

        self.disconnect(self.selectedFontGroupBox, SIGNAL("toggled(bool)"), self.change_use_selected_font)
        self.disconnect(self.fontComboBox, SIGNAL("currentFontChanged (const QFont &)"), self.change_font)
        self.disconnect(self.fontSizeSpinBox, SIGNAL("valueChanged(int)"), self.change_fontsize)
        self.disconnect(self.makeDefaultFontPushButton, SIGNAL("clicked()"), self.change_selected_font_to_default_font)

        self.selectedFontGroupBox.setChecked(env.prefs[useSelectedFont_prefs_key]) # Generates signal!
        self.fontComboBox.setCurrentFont(font) # Generates signal!
        self.fontSizeSpinBox.setValue(font_size) # Generates signal!

        self.connect(self.selectedFontGroupBox, SIGNAL("toggled(bool)"), self.change_use_selected_font)
        self.connect(self.fontComboBox, SIGNAL("currentFontChanged (const QFont &)"), self.change_font)
        self.connect(self.fontSizeSpinBox, SIGNAL("valueChanged(int)"), self.change_fontsize)
        self.connect(self.makeDefaultFontPushButton, SIGNAL("clicked()"), self.change_selected_font_to_default_font)

        if setFontFromPrefs:
            self.set_font()
        return

    def set_font(self):
        """
        Set the current display font using the font prefs.
        """

        use_selected_font = env.prefs[useSelectedFont_prefs_key]

        if use_selected_font:
            font = self.fontComboBox.currentFont()
            font_family = str_or_unicode(font.family())
            fontsize = self.fontSizeSpinBox.value()
            font.setPointSize(fontsize)
            env.prefs[displayFont_prefs_key] = font_family
            env.prefs[displayFontPointSize_prefs_key] = fontsize
            if debug_flags.atom_debug:
                print "set_font(): Using selected font: ", font.family(), ", size=", font.pointSize()

        else: # Use default font
            font = self.w.defaultFont
            if debug_flags.atom_debug:
                print "set_font(): Using default font: ", font.family(), ", size=", font.pointSize()

        # Set font
        self.w.setFont(font)
        return

    def set_caption_fullpath(self, val): #bruce 050810 revised this
        # there is now a separate connection which sets the pref, so this is not needed:
        ## self.win.caption_fullpath = val
        # and there is now a Formula in MWsemantics which makes the following no longer needed:
        ## self.win.update_mainwindow_caption(self.win.assy.has_changed())
        pass

    def update_number_spinbox_valueChanged(self,a0):
        # some day we'll use this to set a user preferences, for now it's a no-op
        pass

    ########## End of slot methods for "Window" page widgets ###########

    ########## Slot methods for top level widgets ################

    def show(self, pagename = ""):
        """
        Display the Preferences dialog with page I{pagename}.

        @param pagename: Name of the Preferences page. Default is "General".
        @type  pagename: string
        """
        self.showPage(pagename)

        # Must use exec_() and not show() with self.modal=True. I tried it and
        # it doesn't work whenever the user is prompted by NE1 to enable
        # a plug-in via the Preferences dialog. -Mark 2008-05-22
        self.exec_()
        return

    def showPage(self, pagename = ""):
        """
        Show the current page of the Preferences dialog. If no page is
        selected from the Category tree widget, show the "General" page.

        @param pagename: Name of the Preferences page. Default is "General".
                         Only names found in self.pagenameList are allowed.
        @type  pagename: string

        @note: This is the slot method for the "Category" QTreeWidget.
        """

        if not pagename:
            selectedItemsList = self.categoryTreeWidget.selectedItems()
            if selectedItemsList:
                selectedItem = selectedItemsList[0]
                pagename = str(selectedItem.text(0))
            else:
                pagename = 'General'

        # Strip whitespaces, commas and dashes from pagename just before
        # checking for it in self.pagenameList.
        pagename = pagename.replace(" ", "")
        pagename = pagename.replace(",", "")
        pagename = pagename.replace("-", "")

        if not pagename in self.pagenameList:
            msg = 'Preferences page unknown: pagename =%s\n' \
                'pagename must be one of the following:\n%r\n' \
                % (pagename, self.pagenameList)
            print_compact_traceback(msg)

        try:
            # Show page <pagename>.
            self.prefsStackedWidget.setCurrentIndex(self.pagenameList.index(pagename))
        except:
            print_compact_traceback("Bug in showPage() ignored: ")

        self.setWindowTitle("Preferences - %s" % pagename)
        return

    def getPagenameList(self):
        """
        Returns a list of page names (i.e. the "stack of widgets") inside
        prefsStackedWidget.

        @return: List of page names.
        @rtype:  List

        @attention: Qt Designer assigns the QStackedWidget property
                    "currentPageName" (which is not a formal attr)
                    to the QWidget (page) attr "objectName".

        @see: U{B{QStackedWidget}<http://doc.trolltech.com/4/qstackedwidget.html>}.
        """
        _pagenameList = []

        for _widgetIndex in range(self.prefsStackedWidget.count()):
            _widget = self.prefsStackedWidget.widget(_widgetIndex)
            _pagename = str(_widget.objectName())
            _pagenameList.append(_pagename)

        return _pagenameList

    def accept(self):
        """
        The slot method for the 'OK' button.
        """
        QDialog.accept(self)
        return

    def reject(self):
        """
        The slot method for the "Cancel" button.
        """
        # The Cancel button has been removed, but this still gets called
        # when the user hits the dialog's "Close" button in the dialog's
        # window border (upper right X).
        # Since I've not implemented 'Cancel', it is safer to go ahead and
        # save all preferences anyway.  Otherwise, any changed preferences
        # will not be persistent (after this session).
        # This will need to be removed when we implement a true cancel function.
        # Mark 050629.
        QDialog.reject(self)
        return

    pass # end of class Preferences

# end