[de6804]: pype.py Maximize Restore History

Download this file

pype.py    4246 lines (3718 with data), 170.7 kB

   1
   2
   3
   4
   5
   6
   7
   8
   9
  10
  11
  12
  13
  14
  15
  16
  17
  18
  19
  20
  21
  22
  23
  24
  25
  26
  27
  28
  29
  30
  31
  32
  33
  34
  35
  36
  37
  38
  39
  40
  41
  42
  43
  44
  45
  46
  47
  48
  49
  50
  51
  52
  53
  54
  55
  56
  57
  58
  59
  60
  61
  62
  63
  64
  65
  66
  67
  68
  69
  70
  71
  72
  73
  74
  75
  76
  77
  78
  79
  80
  81
  82
  83
  84
  85
  86
  87
  88
  89
  90
  91
  92
  93
  94
  95
  96
  97
  98
  99
 100
 101
 102
 103
 104
 105
 106
 107
 108
 109
 110
 111
 112
 113
 114
 115
 116
 117
 118
 119
 120
 121
 122
 123
 124
 125
 126
 127
 128
 129
 130
 131
 132
 133
 134
 135
 136
 137
 138
 139
 140
 141
 142
 143
 144
 145
 146
 147
 148
 149
 150
 151
 152
 153
 154
 155
 156
 157
 158
 159
 160
 161
 162
 163
 164
 165
 166
 167
 168
 169
 170
 171
 172
 173
 174
 175
 176
 177
 178
 179
 180
 181
 182
 183
 184
 185
 186
 187
 188
 189
 190
 191
 192
 193
 194
 195
 196
 197
 198
 199
 200
 201
 202
 203
 204
 205
 206
 207
 208
 209
 210
 211
 212
 213
 214
 215
 216
 217
 218
 219
 220
 221
 222
 223
 224
 225
 226
 227
 228
 229
 230
 231
 232
 233
 234
 235
 236
 237
 238
 239
 240
 241
 242
 243
 244
 245
 246
 247
 248
 249
 250
 251
 252
 253
 254
 255
 256
 257
 258
 259
 260
 261
 262
 263
 264
 265
 266
 267
 268
 269
 270
 271
 272
 273
 274
 275
 276
 277
 278
 279
 280
 281
 282
 283
 284
 285
 286
 287
 288
 289
 290
 291
 292
 293
 294
 295
 296
 297
 298
 299
 300
 301
 302
 303
 304
 305
 306
 307
 308
 309
 310
 311
 312
 313
 314
 315
 316
 317
 318
 319
 320
 321
 322
 323
 324
 325
 326
 327
 328
 329
 330
 331
 332
 333
 334
 335
 336
 337
 338
 339
 340
 341
 342
 343
 344
 345
 346
 347
 348
 349
 350
 351
 352
 353
 354
 355
 356
 357
 358
 359
 360
 361
 362
 363
 364
 365
 366
 367
 368
 369
 370
 371
 372
 373
 374
 375
 376
 377
 378
 379
 380
 381
 382
 383
 384
 385
 386
 387
 388
 389
 390
 391
 392
 393
 394
 395
 396
 397
 398
 399
 400
 401
 402
 403
 404
 405
 406
 407
 408
 409
 410
 411
 412
 413
 414
 415
 416
 417
 418
 419
 420
 421
 422
 423
 424
 425
 426
 427
 428
 429
 430
 431
 432
 433
 434
 435
 436
 437
 438
 439
 440
 441
 442
 443
 444
 445
 446
 447
 448
 449
 450
 451
 452
 453
 454
 455
 456
 457
 458
 459
 460
 461
 462
 463
 464
 465
 466
 467
 468
 469
 470
 471
 472
 473
 474
 475
 476
 477
 478
 479
 480
 481
 482
 483
 484
 485
 486
 487
 488
 489
 490
 491
 492
 493
 494
 495
 496
 497
 498
 499
 500
 501
 502
 503
 504
 505
 506
 507
 508
 509
 510
 511
 512
 513
 514
 515
 516
 517
 518
 519
 520
 521
 522
 523
 524
 525
 526
 527
 528
 529
 530
 531
 532
 533
 534
 535
 536
 537
 538
 539
 540
 541
 542
 543
 544
 545
 546
 547
 548
 549
 550
 551
 552
 553
 554
 555
 556
 557
 558
 559
 560
 561
 562
 563
 564
 565
 566
 567
 568
 569
 570
 571
 572
 573
 574
 575
 576
 577
 578
 579
 580
 581
 582
 583
 584
 585
 586
 587
 588
 589
 590
 591
 592
 593
 594
 595
 596
 597
 598
 599
 600
 601
 602
 603
 604
 605
 606
 607
 608
 609
 610
 611
 612
 613
 614
 615
 616
 617
 618
 619
 620
 621
 622
 623
 624
 625
 626
 627
 628
 629
 630
 631
 632
 633
 634
 635
 636
 637
 638
 639
 640
 641
 642
 643
 644
 645
 646
 647
 648
 649
 650
 651
 652
 653
 654
 655
 656
 657
 658
 659
 660
 661
 662
 663
 664
 665
 666
 667
 668
 669
 670
 671
 672
 673
 674
 675
 676
 677
 678
 679
 680
 681
 682
 683
 684
 685
 686
 687
 688
 689
 690
 691
 692
 693
 694
 695
 696
 697
 698
 699
 700
 701
 702
 703
 704
 705
 706
 707
 708
 709
 710
 711
 712
 713
 714
 715
 716
 717
 718
 719
 720
 721
 722
 723
 724
 725
 726
 727
 728
 729
 730
 731
 732
 733
 734
 735
 736
 737
 738
 739
 740
 741
 742
 743
 744
 745
 746
 747
 748
 749
 750
 751
 752
 753
 754
 755
 756
 757
 758
 759
 760
 761
 762
 763
 764
 765
 766
 767
 768
 769
 770
 771
 772
 773
 774
 775
 776
 777
 778
 779
 780
 781
 782
 783
 784
 785
 786
 787
 788
 789
 790
 791
 792
 793
 794
 795
 796
 797
 798
 799
 800
 801
 802
 803
 804
 805
 806
 807
 808
 809
 810
 811
 812
 813
 814
 815
 816
 817
 818
 819
 820
 821
 822
 823
 824
 825
 826
 827
 828
 829
 830
 831
 832
 833
 834
 835
 836
 837
 838
 839
 840
 841
 842
 843
 844
 845
 846
 847
 848
 849
 850
 851
 852
 853
 854
 855
 856
 857
 858
 859
 860
 861
 862
 863
 864
 865
 866
 867
 868
 869
 870
 871
 872
 873
 874
 875
 876
 877
 878
 879
 880
 881
 882
 883
 884
 885
 886
 887
 888
 889
 890
 891
 892
 893
 894
 895
 896
 897
 898
 899
 900
 901
 902
 903
 904
 905
 906
 907
 908
 909
 910
 911
 912
 913
 914
 915
 916
 917
 918
 919
 920
 921
 922
 923
 924
 925
 926
 927
 928
 929
 930
 931
 932
 933
 934
 935
 936
 937
 938
 939
 940
 941
 942
 943
 944
 945
 946
 947
 948
 949
 950
 951
 952
 953
 954
 955
 956
 957
 958
 959
 960
 961
 962
 963
 964
 965
 966
 967
 968
 969
 970
 971
 972
 973
 974
 975
 976
 977
 978
 979
 980
 981
 982
 983
 984
 985
 986
 987
 988
 989
 990
 991
 992
 993
 994
 995
 996
 997
 998
 999
1000
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
3745
3746
3747
3748
3749
3750
3751
3752
3753
3754
3755
3756
3757
3758
3759
3760
3761
3762
3763
3764
3765
3766
3767
3768
3769
3770
3771
3772
3773
3774
3775
3776
3777
3778
3779
3780
3781
3782
3783
3784
3785
3786
3787
3788
3789
3790
3791
3792
3793
3794
3795
3796
3797
3798
3799
3800
3801
3802
3803
3804
3805
3806
3807
3808
3809
3810
3811
3812
3813
3814
3815
3816
3817
3818
3819
3820
3821
3822
3823
3824
3825
3826
3827
3828
3829
3830
3831
3832
3833
3834
3835
3836
3837
3838
3839
3840
3841
3842
3843
3844
3845
3846
3847
3848
3849
3850
3851
3852
3853
3854
3855
3856
3857
3858
3859
3860
3861
3862
3863
3864
3865
3866
3867
3868
3869
3870
3871
3872
3873
3874
3875
3876
3877
3878
3879
3880
3881
3882
3883
3884
3885
3886
3887
3888
3889
3890
3891
3892
3893
3894
3895
3896
3897
3898
3899
3900
3901
3902
3903
3904
3905
3906
3907
3908
3909
3910
3911
3912
3913
3914
3915
3916
3917
3918
3919
3920
3921
3922
3923
3924
3925
3926
3927
3928
3929
3930
3931
3932
3933
3934
3935
3936
3937
3938
3939
3940
3941
3942
3943
3944
3945
3946
3947
3948
3949
3950
3951
3952
3953
3954
3955
3956
3957
3958
3959
3960
3961
3962
3963
3964
3965
3966
3967
3968
3969
3970
3971
3972
3973
3974
3975
3976
3977
3978
3979
3980
3981
3982
3983
3984
3985
3986
3987
3988
3989
3990
3991
3992
3993
3994
3995
3996
3997
3998
3999
4000
4001
4002
4003
4004
4005
4006
4007
4008
4009
4010
4011
4012
4013
4014
4015
4016
4017
4018
4019
4020
4021
4022
4023
4024
4025
4026
4027
4028
4029
4030
4031
4032
4033
4034
4035
4036
4037
4038
4039
4040
4041
4042
4043
4044
4045
4046
4047
4048
4049
4050
4051
4052
4053
4054
4055
4056
4057
4058
4059
4060
4061
4062
4063
4064
4065
4066
4067
4068
4069
4070
4071
4072
4073
4074
4075
4076
4077
4078
4079
4080
4081
4082
4083
4084
4085
4086
4087
4088
4089
4090
4091
4092
4093
4094
4095
4096
4097
4098
4099
4100
4101
4102
4103
4104
4105
4106
4107
4108
4109
4110
4111
4112
4113
4114
4115
4116
4117
4118
4119
4120
4121
4122
4123
4124
4125
4126
4127
4128
4129
4130
4131
4132
4133
4134
4135
4136
4137
4138
4139
4140
4141
4142
4143
4144
4145
4146
4147
4148
4149
4150
4151
4152
4153
4154
4155
4156
4157
4158
4159
4160
4161
4162
4163
4164
4165
4166
4167
4168
4169
4170
4171
4172
4173
4174
4175
4176
4177
4178
4179
4180
4181
4182
4183
4184
4185
4186
4187
4188
4189
4190
4191
4192
4193
4194
4195
4196
4197
4198
4199
4200
4201
4202
4203
4204
4205
4206
4207
4208
4209
4210
4211
4212
4213
4214
4215
4216
4217
4218
4219
4220
4221
4222
4223
4224
4225
4226
4227
4228
4229
4230
4231
4232
4233
4234
4235
4236
4237
4238
4239
4240
4241
4242
4243
4244
4245
#!/usr/bin/env python
#------------ User-changable settings are available in the menus -------------
from __future__ import generators
from __version__ import *
#------------------------ Startup/restart information ------------------------
import sys, os
if sys.platform == 'linux2' and 'DISPLAY' not in os.environ:
raise SystemError('DISPLAY not set when importing or running pype')
if not hasattr(sys, 'frozen'):
v = '2.6'
import wxversion
if '--unicode' in sys.argv:
wxversion.ensureMinimal(v+'-unicode', optionsRequired=True)
elif '--ansi' in sys.argv:
wxversion.ensureMinimal(v+'-ansi', optionsRequired=True)
else:
wxversion.ensureMinimal(v)
DEBUG = '--debug' in sys.argv
USE_THREAD = '--nothread' not in sys.argv
PRINTMACROS = 0
def _restart(orig_path=os.getcwd(), orig_sysargv=sys.argv[:]):
os.chdir(orig_path)
args = [sys.executable] + orig_sysargv
if len(spawnargs) == 1:
_ = args.pop(0)
os.execvp(args[0], args + ['--last'])
sys.argv = [i for i in sys.argv if i not in ('--ansi', '--unicode', '--debug', '--nothread', '--macros')]
#-------------- Create reference to this module in __builtins__ --------------
if isinstance(__builtins__, dict):
__builtins__['_pype'] = sys.modules[__name__]
else:
__builtins__._pype = sys.modules[__name__]
#------------------------------ System Imports -------------------------------
import stat
import keyword, traceback, cStringIO, imp, fnmatch, re
import time, pprint
from wxPython.wx import *
from wxPython.stc import *
from wxPython.lib.rcsizer import RowColSizer
from wxPython.lib.dialogs import wxScrolledMessageDialog
import wx.lib.mixins.listctrl as listctrl
wxListCtrlAutoWidthMixin, wxColumnSorterMixin, wxTextEditMixin = \
listctrl.ListCtrlAutoWidthMixin, listctrl.ColumnSorterMixin, listctrl.TextEditMixin
import copy
import inspect
import textwrap
import md5
import compiler
import Queue
import threading
import wx
import wx.gizmos
if DEBUG:
from wx.py import crust
current_path = os.getcwd()
EFFECTUAL_NORMCASE = os.path.normcase('AbCdEf') == 'abcdef'
UNICODE = wxUSE_UNICODE
#--------------------------- configuration import ----------------------------
from configuration import *
#---------------------------- Event Declarations -----------------------------
class cancelled(Exception):
'''test docstring'''
def __init__(self, *args, **kwargs):
'''another test docstring'''
Exception.__init__(self, *args, **kwargs)
class pass_keyboard(cancelled): pass
def isdirty(win):
if win.dirty:
return True
fn = win.root.getAlmostAbsolute(win.filename, win.dirname)
dirty = 0
try:
mod = os.stat(fn)[8]
dirty += mod != win.mod
except:
dirty += bool(fn.strip())
r = dirty and True or False
if r:
win.MakeDirty()
return r
#plugin-type thing imports
from plugins import documents
from plugins import logger
from plugins import findbar
from plugins import lru
from plugins import filehistory
from plugins import browser
from plugins import workspace
from plugins import todo
from plugins import findinfiles
from plugins import shell
from plugins import textrepr
from plugins import single_instance
from plugins import interpreter
from plugins import spellcheck
from plugins import help
from plugins import keydialog
from plugins import codetree
from plugins import filtertable
from plugins import triggerdialog
from plugins.window_management import docstate, _choicebook
from plugins import methodhelper
from plugins import lineabstraction
from plugins import macro
## from plugins import project
for i in [logger, findbar, lru, filehistory, browser, workspace, todo,
findinfiles, shell, textrepr, spellcheck, keydialog]:
i.cancelled = cancelled
i.isdirty = isdirty
#some definitions
if 1:
try:
True
except:
True = bool(1)
False = not True
import string
STRINGPRINTABLE = dict.fromkeys(map(ord, string.printable))
IDR = wxNewId()
DDR = wxNewId()
#keypresses
if 1:
keyMap = {}
for name in dir(wx):
if name.startswith('WXK_'):
key = getattr(wx, name)
keyMap[key] = name[4:]
_keys = dict.fromkeys(keyMap.iteritems())
for i in ["SHIFT", "ALT", "CONTROL", "MENU"]:
key = getattr(wx, "WXK_"+i)
keyMap[key] = ''
del key
def _decode_key(keycode):
if keycode >= 256:
return unichr(keycode)
else: #keycode < 256:
return chr(keycode)
def GetKeyPress(evt):
keycode = evt.GetKeyCode()
keyname = keyMap.get(keycode, None)
if keyname is None:
if "unicode" in wx.PlatformInfo:
keycode = evt.GetUnicodeKey()
if keycode <= 127:
keycode = evt.GetKeyCode()
keyname = unichr(evt.GetUnicodeKey())
elif keycode < 256:
if keycode == 0:
keyname = "NUL"
elif keycode < 27:
keyname = chr(ord('A') + keycode-1)
else:
keyname = chr(keycode)
else:
keyname = "(%s)unknown" % keycode
modifiers = ""
for mod, ch in [(evt.ControlDown(), 'Ctrl+'),
(evt.AltDown(), 'Alt+'),
(evt.ShiftDown(), 'Shift+'),
(evt.MetaDown(), 'Meta+')]:
if mod:
modifiers += ch
return modifiers + keyname
#menu preferences
if 1:
MENULIST = []
MENUPREF = {}
OLD_MENUPREF= {}
HOTKEY_TO_ID = {}
def _spl(n):
return (n.split('\t', 1) + [''])[:2]
def recmenu(menu, id):
## print menu.__class__, wxMenuItem, wxMenuItemPtr, wxMenu, wxMenuPtr
if isinstance(menu, (wxMenuBar, wxMenuBarPtr)):
for i in xrange(menu.GetMenuCount()):
r = menu.GetMenu(i)
if r.FindItemById(id):
return "%s->%s"%(menu.GetLabelTop(i), recmenu(r, id))
elif isinstance(menu, (wxMenu, wxMenuPtr)):
ITEMS = menu.GetMenuItems()
for i in ITEMS:
a = recmenu(i, id)
if a:
return a
return ''
elif isinstance(menu, (wxMenuItem, wxMenuItemPtr)):
sm = menu.GetSubMenu()
if sm:
a = recmenu(sm, id)
if a:
return '%s->%s'%(menu.GetLabel(), a)
return ''
elif menu.GetId() == id:
return menu.GetLabel()
else:
return ''
raise Exception("Tried adding a non-menu to a menu? Contact the author.")
def GETACC(X):
if len(X) == 3:
return X
return X[0], X[1], X[1]
def menuAdd(root, menu, name, desc, funct, id, kind=wxITEM_NORMAL):
a = wxMenuItem(menu, id, 'TEMPORARYNAME', desc, kind)
menu.AppendItem(a)
EVT_MENU(root, id, funct)
ns, oacc = _spl(name)
hier = recmenu(menuBar, id)[:-13] + ns
if hier in MENUPREF:
name, acc, acc2 = GETACC(MENUPREF[hier])
else:
if hier in OLD_MENUPREF:
name, acc, acc2 = MENUPREF[hier] = GETACC(OLD_MENUPREF[hier])
else:
name, acc, acc2 = MENUPREF[hier] = GETACC((ns, oacc))
MENULIST.append((hier, name, oacc, acc, kind in [wxITEM_NORMAL, wxITEM_CHECK], acc2))
## if type(acc) != type(acc2):
## acc2 = acc2.decode('latin-1')
## if acc != acc2:
## print "mismatched hotkey: %r %r"%(acc, acc2)
if acc or acc2:
HOTKEY_TO_ID[acc2] = id
menuBar.SetLabel(id, '%s\t%s'%(name, acc))
menuBar.SetHelpString(id, desc)
def menuAddM(parent, menu, name, help=''):
if isinstance(parent, wxMenu) or isinstance(parent, wxMenuPtr):
id = wxNewId()
parent.AppendMenu(id, "TEMPORARYNAME", menu, help)
hier = recmenu(menuBar, id) + name
name, toss, toss2 = MENUPREF[hier] = GETACC(MENUPREF.get(hier, (name, '')))
menuBar.SetLabel(id, name)
menuBar.SetHelpString(id, help)
else:
hier = name
name, toss, toss2 = MENUPREF[hier] = GETACC(MENUPREF.get(hier, (name, '')))
parent.Append(menu, name)
MENULIST.append((hier, name, '', toss, 0, toss2))
def getIcon():
data = getData()
stream = cStringIO.StringIO(data)
image = wxImageFromStream(stream)
bitmap = wxBitmapFromImage(image)
icon = wxEmptyIcon()
icon.CopyFromBitmap(bitmap)
return icon
NEWDOCUMENT = 0L
#document styling events
if 1:
#style ids
# _S 0 _DS 1 2 3 _DD 4 _DD2 5 6
assoc = [(wxNewId(), wxNewId(), 'pyrex', wxSTC_LEX_PYTHON, wxNewId(), wxNewId(), "Pyrex"),
#made Python second to override the lexer2lang option
(wxNewId(), wxNewId(), 'python', wxSTC_LEX_PYTHON, wxNewId(), wxNewId(), "Python"),
(wxNewId(), wxNewId(), 'html', wxSTC_LEX_HTML, wxNewId(), wxNewId(), "HTML"),
(wxNewId(), wxNewId(), 'xml', wxSTC_LEX_XML, wxNewId(), wxNewId(), "XML"),
(wxNewId(), wxNewId(), 'cpp', wxSTC_LEX_CPP, wxNewId(), wxNewId(), "C/C++"),
(wxNewId(), wxNewId(), 'text', wxSTC_LEX_NULL, wxNewId(), wxNewId(), "Text"),
(wxNewId(), wxNewId(), 'tex', wxSTC_LEX_LATEX, wxNewId(), wxNewId(), "TeX/LaTeX")]
ASSOC = assoc
SITO = [i[4] for i in assoc]
SITO2 = [i[5] for i in assoc]
## PY_S, PYX_S, HT_S, XM_S, CC_S, TX_S, TEX_S = [i[0] for i in assoc]
## PY_DS, PYX_DS, HT_DS, XM_DS, CC_DS, TX_DS, TEX_DS = [i[1] for i in assoc]
## PY_DD, PYX_DD, HT_DD, XM_DD, CC_DD, TX_DD, TEX_DD = SITO
## PY_DD2, PYX_DD2, HT_DD2, XM_DD2, CC_DD2, TX_DD2, TEX_DD2 = SITO2
lexers = dict([(i[0],i[2]) for i in assoc])
lexers2 = dict([(i[2],i[0]) for i in assoc])
lexers.update(dict([(i[1],i[2]) for i in assoc]))
lexers3 = dict([(i[2],i[1]) for i in assoc])
lexer2lang = dict([(i[3],i[2]) for i in assoc])
SOURCE_ID_TO_OPTIONS = dict([(i[4], (i[2], i[6])) for i in assoc])
SOURCE_ID_TO_OPTIONS2 = dict([(i[5], (i[2], i[6])) for i in assoc])
ASSOC.insert(1, ASSOC.pop(0))
del assoc
#checkbox ids
if 1:
AUTO = wxNewId()
NUM = wxNewId()
MARGIN = wxNewId()
USETABS = wxNewId()
INDENTGUIDE = wxNewId()
WRAPL = wxNewId()
SLOPPY = wxNewId()
SMARTPASTE = wxNewId()
SAVE_CURSOR = wxNewId()
HIGHLIGHT_LINE = wxNewId()
S_WHITE = wxNewId()
DND_ID = wxNewId()
DB_ID = wxNewId()
IT_ID = wxNewId()
LB_ID = wxNewId()
WIDE_ID = wxNewId()
TALL_ID = wxNewId()
SINGLE_ID = wxNewId()
USEBOM_ID = wxNewId()
ONE_TAB = wxNewId()
TD_ID = wxNewId()
FINDBAR_BELOW_EDITOR = wxNewId()
NO_FINDBAR_HISTORY = wxNewId()
CLEAR_FINDBAR_HISTORY = wxNewId()
ZI = wxNewId()
TRIGGER = wxNewId()
REC_MACRO = wxNewId()
#toolbar ids
TB_MAPPING = {
wxNewId(): (0, 'Hide', "Don't show the tool bar"),
wxNewId(): (1, 'Top', "Show the toolbar accross the top horizontally"),
wxNewId(): (2, 'Left', "Show the toolbar along the left side vertically")
}
TB_RMAPPING = dict([(j[0], (j[0], i, j[1], j[2])) for i,j in TB_MAPPING.iteritems()])
#line ending ids
LE_MAPPING = {
wxNewId():(wxSTC_EOL_CRLF, 0, "CRLF (windows)", "Change the line endings for the current document to CRLF/Windows line endings"),
wxNewId():(wxSTC_EOL_LF, 1, "LF (*nix)", "Change the line endings for the current document to LF/*nix line endings"),
wxNewId():(wxSTC_EOL_CR, 2, "CR (mac)", "Change the line endings for the current document to CR/Macintosh line endings")
}
LE_RMAPPING = dict([(j[0], (j[1], i, j[2], j[3])) for i,j in LE_MAPPING.iteritems()])
#long line indicator ids
LL_MAPPING = {
wxNewId():(wxSTC_EDGE_BACKGROUND, 0, "Background", "Long lines will have a different background color beyond the column limit"),
wxNewId():(wxSTC_EDGE_LINE, 1, "Line", "Long lines will have a vertical line at the column limit"),
wxNewId():(wxSTC_EDGE_NONE, 2, "None", "Show no long line indicator")
}
LL_RMAPPING = dict([(j[0],(j[1], i, j[2], j[3])) for i,j in LL_MAPPING.iteritems()])
#cursor behavior ids
CARET_ID_TO_OPTIONS = {
wxNewId() : (0, wxSTC_CARET_EVEN|wxSTC_CARET_SLOP|wxSTC_CARET_STRICT, 1, "Margin Respecting", "Caret is at least M lines from the top and bottom, N*M pixels from the right and left"),
wxNewId() : (1, wxSTC_CARET_EVEN|wxSTC_CARET_STRICT, 4, "Centered", "Caret is centered on the display, if possible"),
wxNewId() : (2, wxSTC_CARET_STRICT, 3, "Top Attached", "Caret is always on the top line, if possible"),
wxNewId() : (3, wxSTC_CARET_SLOP|wxSTC_CARET_STRICT, 2, "Margin Attached", "Caret is always M lines from the top, and N*M pixels from the right, if possible"),
wxNewId() : (4, wxSTC_CARET_EVEN, 0, "PyPE Classic", "Caret is at least 1 line from the top and bottom, 10 pixels from the right and left"),
}
CARET_OPTION_TO_ID = dict([(j[0], (i, j[1])) for i,j in CARET_ID_TO_OPTIONS.iteritems()])
#caret width option
CARET_W_OPTION_TO_W = dict([(wxNewId(), i) for i in (1,2,3)])
CARET_W_WIDTH_TO_O = dict([(j,i) for i,j in CARET_W_OPTION_TO_W.iteritems()])
#title display ids
TITLE_ID_TO_OPTIONS = {
wxNewId() : (0, "%(pype)s", "No file information"),
wxNewId() : (1, "%(pype)s - %(fn)s", "File name after title"),
wxNewId() : (2, "%(fn)s - %(pype)s", "File name before title"),
wxNewId() : (3, "%(pype)s - %(fn)s - [%(long)s]", "File and full path after title"),
wxNewId() : (4, "%(fn)s - [%(long)s] - %(pype)s", "File and full path before title"),
}
TITLE_OPTION_TO_ID = dict([(j[0], (i, j[1], j[2])) for i,j in TITLE_ID_TO_OPTIONS.iteritems()])
#for determining what to display in the Documents tab.
DOCUMENT_LIST_OPTIONS = {
wxNewId() : (1, "Filename"),
wxNewId() : (3, "Filename, Path"),
wxNewId() : (2, "Path"),
wxNewId() : (0, "Path, Filename")
}
DOCUMENT_LIST_OPTION_TO_ID = dict([(j[0], i) for i,j in DOCUMENT_LIST_OPTIONS.items()])
#for determining what to do when double-clicking on a macro.
MACRO_CLICK_OPTIONS = {
wxNewId() : (0, "do nothing"),
wxNewId() : (1, "open for editing"),
wxNewId() : (2, "run macro")
}
MACRO_CLICK_TO_ID = dict([(j[0], i) for i,j in MACRO_CLICK_OPTIONS.iteritems()])
#bookmark support
BOOKMARKNUMBER = 1
BOOKMARKSYMBOL = wxSTC_MARK_CIRCLE
BOOKMARKMASK = 2
#unicode BOM stuff
if 1:
BOM = [('+/v8-', 'utf-7'),
('\xef\xbb\xbf', 'utf-8'),
('\xfe\xff', 'utf-16-be'),
('\xff\xfe\xff\xfe', 'utf-16'),
('\xff\xfe', 'utf-16-le'),
('', 'ascii'),
('', 'other')]
ADDBOM = {}
ENCODINGS = {}
for i,j in BOM:
ADDBOM[j] = i
ENCODINGS[j] = wxNewId()
del i;del j;
#font stuff
if 1:
cn = 'Courier New'
if wxPlatform == '__WXMSW__':
faces = {'times': cn, 'mono' : cn, 'helv' : cn, 'other': cn,
'size' : 10, 'size2': 9}
else:
faces = {'times': 'Courier', 'mono' : 'Courier',
'helv' : 'Courier', 'other': 'Courier', 'size' : 10,
'size2': 10 }
del cn
#SashWindow stuff
if 1:
def makeSubWindow(parent, id, size, orientation, alignment, sash):
win = wxSashLayoutWindow(
parent, id, wxDefaultPosition, size,
wxNO_BORDER|wxSW_3D
)
win.SetDefaultSize(size)
win.SetOrientation(orientation)
win.SetAlignment(alignment)
## win.SetBackgroundColour(wx.Colour(127, 0, 0))
win.SetSashVisible(sash, True)
## win.SetMinimumSizeX(30)
return win
#subwindow ids
ID_WINDOW_BOTTOM = wxNewId()
ID_WINDOW_RIGHT = wxNewId()
#subwindow constants
SMALL = 10
BIG = 10000
DB_LOC = {0:(wxLAYOUT_LEFT, wxSASH_RIGHT),
1:(wxLAYOUT_RIGHT, wxSASH_LEFT)}
LB_LOC = {0:(wxLAYOUT_TOP, wxSASH_BOTTOM),
1:(wxLAYOUT_BOTTOM, wxSASH_TOP)}
#findbar ids
if 1:
pypeID_DELETE = wxNewId()
pypeID_FINDBAR = wxNewId()
pypeID_REPLACEBAR = wxNewId()
pypeID_TOGGLE_BOOKMARK = wxNewId()
pypeID_NEXT_BOOKMARK = wxNewId()
pypeID_PRIOR_BOOKMARK = wxNewId()
#extension to image map
EXT_TO_IMG = {'python':1, 'pyrex':1}
def GDI(name):
if USE_DOC_ICONS:
return EXT_TO_IMG.get(extns.get(name.split('.')[-1].lower(), 0), 0)
return -1
#
def GetClipboardText():
a = wxClipboard()
if not a.Open():
return
b = wxTextDataObject()
if not a.GetData(b):
return
a.Close()
return b.GetText()
RESET = {'cursorposn':0,
'BM':[],
'FOLD':[]}
#threaded parser
if 1:
parse_queue = Queue.Queue()
from wx.lib.newevent import NewEvent
DoneParsing, EVT_DONE_PARSING = NewEvent()
def parse(lang, source, le, which, x, slowparse=0):
source = source.replace('\r\n', '\n').replace('\r', '\n')
le = '\n'
if lang in ('python', 'pyrex'):
if slowparse:
try:
a = fast_parser(source, le, which, x)
return a
except:
traceback.print_exc()
pass
return faster_parser(source, le, which, x)
elif lang == 'tex':
return latex_parser(source, le, which, x)
elif lang == 'cpp':
return c_parser(source, le, which, x)
elif lang in ('xml', 'html'):
return ml_parser(source, le, which, x)
else:
return [], [], {}, []
def start_parse_thread(frame):
a = threading.Thread(target=parse_thread, args=(frame,))
## a.setDaemon(1)
a.start()
def parse_thread(frame):
null = lambda:None
while 1:
x = parse_queue.get()
if not x:
break
source, stc, lang = x
t = time.time()
tpl = parse(lang, source, '\n', 3, null, 1)
t = time.time()-t
try:
wxPostEvent(frame, DoneParsing(stc=stc, tpl=tpl, delta=t))
except:
#if this raises an exception, then the main frame has closed
break
sys_excepthook = sys.excepthook
def my_excepthook(typ, inst, trace):
if typ is cancelled or typ is pass_keyboard:
return
return sys_excepthook(typ, inst, trace)
sys.excepthook = my_excepthook
def veto(*args):
args[-1].Veto()
#---------------------- Frame that contains everything -----------------------
class MainWindow(wxFrame):
def __init__(self,parent,id,title,fnames):
wxFrame.__init__(self,parent,id, title, size = ( 1024, 600 ),
style=wxDEFAULT_FRAME_STYLE|wxNO_FULL_REPAINT_ON_RESIZE)
self.starting = 1
self.redirect = methodhelper.MethodHelper(self)
#------------------------------- configuration -------------------------------
if 1:
self.SetIcon(getIcon())
self.FINDSHOWN = 0
path = os.path.join(homedir, 'menus.txt')
if UNICODE:
p = os.path.join(homedir, 'menus.u.txt')
if os.path.exists(p):
path = p
print "Loading menus from", path
try: OLD_MENUPREF.update(self.readAndEvalFile(path))
except: pass
single_instance.callback = self.OnDrop
#recent menu relocated to load configuration early on.
recentmenu = wxMenu()
#--------------------------- cmt-001 - 08/06/2003 ----------------------------
#----------------- Adds opened file history to the File menu -----------------
if 1:
self.fileHistory = wxFileHistory()
self.fileHistory.UseMenu(recentmenu)
self.configPath = homedir
self.loadHistory()
self.SetSize(LASTSIZE)
self.SetPosition(LASTPOSITION)
self.restart = 0
self.restartt = 0
EVT_MENU_RANGE(self, wxID_FILE1, wxID_FILE9, self.OnFileHistory)
self.lastused = lru.lastused(128+len(lastopen), LASTUSED)
self.curdocstates = {}
#------------------------- end cmt-001 - 08/06/2003 --------------------------
self.toparse = []
self.parsing = 0
try:
## typ = wxITEM_RADIO
typ = wxITEM_CHECK
self.HAS_RADIO = 1
except:
typ = wxITEM_NORMAL
self.HAS_RADIO = 0
#EVT_IDLE(self, self.SetPos)
#a = wxNewId()
#self.T = wxTimer(self, a)
#EVT_TIMER(self, a, self.SetPos)
#self.T.Start(100)
#------------------------------- window layout -------------------------------
if 1:
self.sb = wxStatusBar(self, -1)
if UNICODE:
#to display encoding in unicode supporting platforms
self.sb.SetFieldsCount(3)
self.sb.SetStatusWidths([-1, 95, 60])
else:
self.sb.SetFieldsCount(2)
self.sb.SetStatusWidths([-1, 95])
self.SetStatusBar(self.sb)
if TOOLBAR:
self._setupToolBar()
self.control = documents.MyNB(self, -1, self)
# Setting up the menu
bottom = makeSubWindow(self, ID_WINDOW_BOTTOM, (BIG, SASH1),
wxLAYOUT_HORIZONTAL,
*LB_LOC[logbarlocn])
right = makeSubWindow(self, ID_WINDOW_RIGHT, (SASH2, BIG),
wxLAYOUT_VERTICAL,
*DB_LOC[docbarlocn])
self.BOTTOM = bottom
self.RIGHT = right
self.BOTTOMNB = wxNotebook(bottom, -1)
self.RIGHTNB = wxNotebook(right, -1)
self.dragger = documents.MyLC(self.RIGHTNB, self)
if DEBUG:
self.crust = crust.Crust(self.RIGHTNB, rootObject=app,
rootLabel='main', execStartupScript=False)
self.RIGHTNB.AddPage(self.crust, "DEBUG")
y = [('Name', 'leftt'), ('Line','rightt'), ('Filter', 'filterl'), ('Todo','todot')]
if ONE_TAB_:
self.single_ctrl = wxChoicebook(self.RIGHTNB, -1)
self.RIGHTNB.AddPage(self.single_ctrl, "Tools")
for name,i in y:
if ONE_TAB_:
ctrl = self.single_ctrl
elif TODOBOTTOM and name=='Todo':
ctrl = self.BOTTOMNB
else:
ctrl = self.RIGHTNB
x = _choicebook(ctrl, -1)
ctrl.AddPage(x, name)
setattr(self, i, x)
self.macropage = macro.macroPanel(self.RIGHTNB, self)
self.RIGHTNB.AddPage(self.macropage, "Macros")
self.BOTTOMNB.AddPage(logger.logger(self.BOTTOMNB), 'Log')
## self.BOTTOMNB.AddPage(findinfiles.FindInFiles(self.BOTTOMNB, self), "Find in Files")
self.BOTTOMNB.AddPage(findinfiles.FindInFiles(self.BOTTOMNB, self), "Search")
self.BOTTOMNB.AddPage(spellcheck.SpellCheck(self.BOTTOMNB, self), "Spell Check")
## self.shell = shell.Shell(self.BOTTOMNB, self, self.config.get('shellprefs', {}))
## self.BOTTOMNB.AddPage(self.shell, "Shell")
if UNICODE:
self.BOTTOMNB.AddPage(textrepr.TextRepr(self.BOTTOMNB, self), "repr(text)")
self.BOTTOMNB.AddPage(help.MyHtmlWindow(self.BOTTOMNB), "Help")
self.RIGHTNB.AddPage(self.dragger, 'Documents')
self.pathmarks = browser.FilesystemBrowser(self.RIGHTNB, self, pathmarksn)
self.RIGHTNB.AddPage(self.pathmarks, "Browse...")
self.Bind(EVT_SASH_DRAGGED_RANGE, self.OnSashDrag, id=ID_WINDOW_BOTTOM, id2=ID_WINDOW_RIGHT)
#------------------------- Insert menus into Menubar -------------------------
global menuBar
menuBar = wxMenuBar()
self.SetMenuBar(menuBar) # Adding the MenuBar to the Frame content.
self.menubar = menuBar
#--------------------------------- File Menu ---------------------------------
if 1:
filemenu= wxMenu()
menuAddM(menuBar, filemenu, "&File")
menuAdd(self, filemenu, "&New\tCtrl+N", "New file", self.OnNew, wxID_NEW)
menuAdd(self, filemenu, "&Open\tCtrl+O", "Open a file", self.OnOpen, wxID_OPEN)
menuAdd(self, filemenu, "Open &Module\tAlt+M", "Open a module for editing using the same path search as import would", self.OnOpenModule, wxNewId())
menuAdd(self, filemenu, "Open &Last\t", "Open all the documents that were opening before last program exit", self.OnOpenPrevDocs, wxNewId())
menuAddM(filemenu, recentmenu, "Open Recent")
filemenu.AppendSeparator()
menuAdd(self, filemenu, "&Save\tCtrl+S", "Save a file", self.OnSave, wxID_SAVE)
menuAdd(self, filemenu, "Save &As", "Save a file as...", self.OnSaveAs, wxID_SAVEAS)
menuAdd(self, filemenu, "Sa&ve All", "Save all open files...", self.OnSaveAll, wxNewId())
filemenu.AppendSeparator()
menuAdd(self, filemenu, "New Python Shell", "Opens a Python shell in a new tab", self.OnNewPythonShell, wxNewId())
menuAdd(self, filemenu, "New Command Shell", "Opens a command line shell in a new tab", self.OnNewCommandShell, wxNewId())
filemenu.AppendSeparator()
menuAdd(self, filemenu, "Add Module Search Path", "Add a path to search during subsequent 'Open Module' executions", self.AddSearchPath, wxNewId())
menuAdd(self, filemenu, "&Reload", "Reload the current document from disk", self.OnReload, wxID_REVERT)
menuAdd(self, filemenu, "&Close\tCtrl+W", "Close the file in this tab", self.OnClose, wxNewId())
workspace.WorkspaceMenu(filemenu, self, workspaces, workspace_order)
menuAdd(self, filemenu, "Restart", "Restart PyPE", self.OnRestart, wxNewId())
menuAdd(self, filemenu, "E&xit\tAlt+F4", "Terminate the program", self.OnExit, wxNewId())
#--------------------------------- Edit Menu ---------------------------------
if 1:
editmenu= wxMenu()
menuAddM(menuBar, editmenu, "&Edit")
menuAdd(self, editmenu, "Undo\tCtrl+Z", "Undo last modifications", self.OnUndo, wxID_UNDO)
menuAdd(self, editmenu, "Redo\tCtrl+Y", "Redo last modifications", self.OnRedo, wxID_REDO)
editmenu.AppendSeparator()
menuAdd(self, editmenu, "Select All\tCtrl+A", "Select all text", self.OnSelectAll, wxNewId())
menuAdd(self, editmenu, "Start/End Selection", "Will allow you to set selection start and end positions without holding shift", self.redirect.OnSelectToggle, wxNewId())
menuAdd(self, editmenu, "Cut\tCtrl+X", "Cut selected text", self.OnCut, wxID_CUT)
menuAdd(self, editmenu, "Copy\tCtrl+C", "Copy selected text", self.OnCopy, wxID_COPY)
menuAdd(self, editmenu, "Paste\tCtrl+V", "Paste selected text", self.OnPaste, wxID_PASTE)
menuAdd(self, editmenu, "Delete", "Delete selected text", self.OnDeleteSelection, pypeID_DELETE)
editmenu.AppendSeparator()
menuAdd(self, editmenu, "Show Find Bar\tCtrl+F", "Shows the find bar at the bottom of the editor", self.OnShowFindbar, pypeID_FINDBAR)
menuAdd(self, editmenu, "Show Replace Bar\tCtrl+R", "Shows the replace bar at the bottom of the editor", self.OnShowReplacebar, pypeID_REPLACEBAR)
menuAdd(self, editmenu, "Find again\tF3", "Finds the text in the find bar again", self.OnFindAgain, wxNewId())
## editmenu.AppendSeparator()
## if self.config['usesnippets']:
## menuAdd(self, editmenu, "Insert Snippet\tCtrl+return", "Insert the currently selected snippet into the document", self.snippet.OnListBoxDClick, wxNewId())
#------------------------------ Transform Menu -------------------------------
if 1:
transformmenu= wxMenu()
menuAddM(menuBar, transformmenu, "&Transforms")
menuAdd(self, transformmenu, "Indent Region\tCtrl+]", "Indent region", self.redirect.OnIndent, IDR)
menuAdd(self, transformmenu, "Dedent Region\tCtrl+[", "Dedent region", self.redirect.OnDedent, DDR)
menuAdd(self, transformmenu, "Wrap Selected Text\tAlt+W", "Wrap selected text to a specified width", self.redirect.OnWrap, wxNewId())
transformmenu.AppendSeparator()
menuAdd(self, transformmenu, "Insert Comment\tCtrl+I", "Insert a centered comment", self.redirect.OnInsertComment, wxNewId())
menuAdd(self, transformmenu, "Comment Selection\tAlt+8", "Comment selected lines", self.redirect.OnCommentSelection, wxNewId())
menuAdd(self, transformmenu, "Uncomment Selection\tAlt+9", "Uncomment selected lines", self.redirect.OnUncommentSelection, wxNewId())
transformmenu.AppendSeparator()
menuAdd(self, transformmenu, "Wrap try/except", "Wrap the selected code in a try/except clause", self.redirect.WrapExcept, wxNewId())
menuAdd(self, transformmenu, "Wrap try/finally", "Wrap the selected code in a try/finally clause", self.redirect.WrapFinally, wxNewId())
menuAdd(self, transformmenu, "Wrap try/except/finally", "Wrap the selected code in a try/except/finally clause", self.redirect.WrapExceptFinally, wxNewId())
transformmenu.AppendSeparator()
menuAdd(self, transformmenu, "Perform Trigger", "Performs a trigger epansion if possible", self.redirect.OnTriggerExpansion, TRIGGER)
#--------------------------------- View Menu ---------------------------------
if 1:
viewmenu= wxMenu()
menuAddM(menuBar, viewmenu,"&View")
menuAdd(self, viewmenu, "Previous Tab\tAlt+,", "View the tab to the left of the one you are currently", self.OnLeft, wxNewId())
menuAdd(self, viewmenu, "Next Tab\tAlt+.", "View the tab to the right of the one you are currently", self.OnRight, wxNewId())
viewmenu.AppendSeparator()
menuAdd(self, viewmenu, "Zoom In\tCtrl++", "Make the text in the editing component bigger", self.OnZoom, ZI)
menuAdd(self, viewmenu, "Zoom Out\tCtrl+-", "Make the text in the editing component smaller", self.OnZoom, wxNewId())
viewmenu.AppendSeparator()
menuAdd(self, viewmenu, "Go to line number\tAlt+G", "Advance to the given line in the currently open document", self.OnGoto, wxNewId())
menuAdd(self, viewmenu, "Go to position", "Advance to the given position in the currently open document", self.OnGotoP, wxNewId())
menuAdd(self, viewmenu, "Jump forward", "Advance the cursor to the next quote/bracket", self.redirect.OnJumpF, wxNewId())
menuAdd(self, viewmenu, "Jump backward", "Advance the cursor to the previous quote/bracket", self.redirect.OnJumpB, wxNewId())
viewmenu.AppendSeparator()
menuAdd(self, viewmenu, "Toggle Bookmark\tCtrl+M", "Create/remove bookmark for this line", self.OnToggleBookmark, pypeID_TOGGLE_BOOKMARK)
menuAdd(self, viewmenu, "Next Bookmark\tF2", "Hop to the next bookmark in this file", self.OnNextBookmark, pypeID_NEXT_BOOKMARK)
menuAdd(self, viewmenu, "Previous Bookmark\tShift+F2", "Hop to the previous bookmark in this file", self.OnPreviousBookmark, pypeID_PRIOR_BOOKMARK)
viewmenu.AppendSeparator()
menuAdd(self, viewmenu, "Find Definition", "Shows the filter tool and tries to find the current word in the definitions", self.OnFindDefn, wxNewId())
#------------------------------- Document menu -------------------------------
if 1:
setmenu= wxMenu()
menuAddM(menuBar, setmenu, "&Document")
## menuAdd(self, setmenu, "Use Snippets (req restart)", "Enable or disable the use of snippets, requires restart for change to take effect", self.OnSnipToggle, SNIPT, wxITEM_CHECK)
## setmenu.AppendSeparator()
#------------------------------ Style subenu ---------------------
stylemenu= wxMenu()
menuAddM(setmenu, stylemenu, "Syntax Highlighting", "Change the syntax highlighting for the currently open document")
for i in ASSOC:
name, mid = i[6], i[0]
st = "Highlight for %s syntax"%name
if name == 'Text':
st = "No Syntax Highlighting"
menuAdd(self, stylemenu, name, st, self.OnStyleChange, mid, typ)
#---------------------------- Encodings submenu ------------------
if UNICODE:
encmenu= wxMenu()
menuAddM(setmenu, encmenu, "Encodings", "Change text encoding")
menuAdd(self, encmenu, 'ascii', "Change encoding for the current file to ascii (will use utf-8 if unicode characters found)", self.OnEncChange, ENCODINGS['ascii'], typ)
menuAdd(self, encmenu, 'other', "Will use the encoding specified in your encoding declaration, reverting to ascii if not found, and utf-8 as necessary", self.OnEncChange, ENCODINGS['other'], typ)
for bom, enc in BOM[:-2]:
menuAdd(self, encmenu, enc, "Change encoding for the current file to %s"%enc, self.OnEncChange, ENCODINGS[enc], typ)
#--------------------------- Line ending menu --------------------
endingmenu = wxMenu()
menuAddM(setmenu, endingmenu, "Line Ending", "Change the line endings on the current document")
x = LE_RMAPPING.values()
x.sort()
for _, idn, name, helpt in x:
menuAdd(self, endingmenu, name, helpt, self.OnLineEndChange, idn, typ)
#
setmenu.AppendSeparator()
menuAdd(self, setmenu, "Show Autocomplete", "Show the autocomplete dropdown while typing", self.OnAutoCompleteToggle, AUTO, wxITEM_CHECK)
menuAdd(self, setmenu, "Show line numbers", "Show or hide the line numbers on the current document", self.OnNumberToggle, NUM, wxITEM_CHECK)
menuAdd(self, setmenu, "Show margin", "Show or hide the bookmark signifier margin on the current document", self.OnMarginToggle, MARGIN, wxITEM_CHECK)
menuAdd(self, setmenu, "Show Indentation Guide", "Show or hide gray indentation guides in indentation", self.OnIndentGuideToggle, INDENTGUIDE, wxITEM_CHECK)
menuAdd(self, setmenu, "Show Whitespace", "Show or hide 'whitespace' characters", self.OnWhitespaceToggle, S_WHITE, wxITEM_CHECK)
menuAdd(self, setmenu, "Save Position", "Remember or forget the last position of the cursor when the current document is closed", self.OnSavePositionToggle, SAVE_CURSOR, wxITEM_CHECK)
menuAdd(self, setmenu, "Highlight Current line", "When checked, will change the background color of the current line", self.HightlightLineToggle, HIGHLIGHT_LINE, wxITEM_CHECK)
setmenu.AppendSeparator()
menuAdd(self, setmenu, "Refresh\tF5", "Refresh the browsable source tree, autocomplete listing, and the tooltips (always accurate, but sometimes slow)", self.OnRefresh, wxNewId())
menuAdd(self, setmenu, "Run Macro", "Run the currently selected macro on the current document", self.macropage.OnPlay, wxNewId())
setmenu.AppendSeparator()
menuAdd(self, setmenu, "Expand all", "Expand all folded code through the entire document", self.OnExpandAll, wxNewId())
menuAdd(self, setmenu, "Fold all", "Fold all expanded code through the entire document", self.OnFoldAll, wxNewId())
menuAdd(self, setmenu, "Use Tabs", "New indentation will include tabs", self.OnSetTabToggle, USETABS, wxITEM_CHECK)
menuAdd(self, setmenu, "Wrap Long Lines", "Visually continue long lines to the next line", self.OnWrapL, WRAPL, wxITEM_CHECK)
menuAdd(self, setmenu, "Sloppy Cut/Copy", "Will select all partially selected lines during cut/copy.", self.OnSloppy, SLOPPY, wxITEM_CHECK)
menuAdd(self, setmenu, "Smart Paste", "Will auto-indent pastes that are multi-line", self.OnSmartPaste, SMARTPASTE, wxITEM_CHECK)
setmenu.AppendSeparator()
menuAdd(self, setmenu, "Set Triggers", "Sets trigger expansions for the current document", self.OnSetTriggers, wxNewId())
menuAdd(self, setmenu, "Set Indent Width", "Set the number of spaces per indentation level", self.OnSetIndent, wxNewId())
menuAdd(self, setmenu, "Set Tab Width", "Set the visual width of tabs in the current open document", self.OnSetTabWidth, wxNewId())
menuAdd(self, setmenu, "Set Long Line Column", "Set the column number for the long line indicator", self.OnSetLongLinePosition, wxNewId())
#---------------------------- Long line submenu ------------------
longlinemenu = wxMenu()
menuAddM(setmenu, longlinemenu, "Set Long Line Indicator", "Change the mode that signifies long lines")
x = LL_RMAPPING.values()
x.sort()
for _, idn, name, helpt in x:
menuAdd(self, longlinemenu, name, helpt, self.OnSetLongLineMode, idn, typ)
#------------------------------- Options Menu --------------------------------
if 1:
optionsmenu= wxMenu()
menuAddM(menuBar, optionsmenu, "&Options")
settingsmenu = wxMenu()
menuAddM(optionsmenu, settingsmenu, "Save Settings", "Set the default behavior of documents opened of a given type")
for mid in SITO:
lang, desc = SOURCE_ID_TO_OPTIONS[mid]
menuAdd(self, settingsmenu, desc, "Save the settings for the current document as the default for %s documents"%desc, self.OnSaveLang, mid)
#menuAdd(self, settingsmenu, "", ", self.OnSaveSettings, wxNewId())
loadsettingsmenu = wxMenu()
menuAddM(optionsmenu, loadsettingsmenu, "Load Settings", "Set the current document behavior to that of the default for documents of a given type")
for mid in SITO2:
lang, desc = SOURCE_ID_TO_OPTIONS2[mid]
menuAdd(self, loadsettingsmenu, desc, "Set the current document behavior to that of the default for %s"%desc, self.OnLoadSavedLang, mid)
optionsmenu.AppendSeparator()
#-------------------------- Default Style submenu ----------------
stylemenu2 = wxMenu()
menuAddM(optionsmenu, stylemenu2, "Default Highlighting", "Set the default syntax highlighting for new or unknown documents")
for i in ASSOC:
name, mid = i[6], i[1]
st = "All new or unknown documents will be highlighted as %s"%name
menuAdd(self, stylemenu2, name, st, self.OnDefaultStyleChange, mid, typ)
optionsmenu.AppendSeparator()
menuAdd(self, optionsmenu, "Enable File Drops", "Enable drag and drop file support onto the text portion of the editor", self.OnDNDToggle, DND_ID, wxITEM_CHECK)
optionsmenu.AppendSeparator()
menuAdd(self, optionsmenu, "Use Icons", "When checked, the editor uses filetype-specific icons next to file names", self.OnIconToggle, IT_ID, wxITEM_CHECK)
menuAdd(self, optionsmenu, "Editor on top", "When checked, the editor is above the Todos, Log, etc., otherwise it is below (requires restart)", self.OnLogBarToggle, LB_ID, wxITEM_CHECK)
menuAdd(self, optionsmenu, "Editor on left", "When checked, the editor is left of the source trees, document list, etc., otherwise it is to the right (requires restart)", self.OnDocBarToggle, DB_ID, wxITEM_CHECK)
menuAdd(self, optionsmenu, "Show Wide Tools", "Shows or hides the tabbed tools that are above or below the editor", self.OnShowWideToggle, WIDE_ID, wxITEM_CHECK)
menuAdd(self, optionsmenu, "Show Tall Tools", "Shows or hides the tabbed tools that are right or left of the editor", self.OnShowTallToggle, TALL_ID, wxITEM_CHECK)
menuAdd(self, optionsmenu, "Wide Todo", "When checked, the todo list will be near the Log tab, when unchecked, will be near the Documenst tab (requires restart)", self.OnTodoToggle, TD_ID, wxITEM_CHECK)
menuAdd(self, optionsmenu, "One Tab", "When checked, the name, line, filter, and todo lists all share a tab (requires restart)", self.OnOneTabToggle, ONE_TAB, wxITEM_CHECK)
menuAdd(self, optionsmenu, "One PyPE", "When checked, will listen on port 9999 for filenames to open", self.OnSingleToggle, SINGLE_ID, wxITEM_CHECK)
if UNICODE:
menuAdd(self, optionsmenu, "Always Write BOM", "If checked, will write BOM when coding: directive is found, otherwise not", self.OnBOMToggle, USEBOM_ID, wxITEM_CHECK)
toolbarOptionsMenu = wxMenu()
menuAddM(optionsmenu, toolbarOptionsMenu, "Toolbar", "When checked, will show a toolbar (requires restart)")
x = TB_RMAPPING.values()
x.sort()
for _, idn, name, helpt in x:
menuAdd(self, toolbarOptionsMenu, name, helpt, self.OnToolBar, idn, typ)
doptmenu = wxMenu()
menuAddM(optionsmenu, doptmenu, "Documents List Options", "Change the filename/path layout in the Documents tab")
for value in (1,3,2,0):
iid = DOCUMENT_LIST_OPTION_TO_ID[value]
desc = DOCUMENT_LIST_OPTIONS[iid][1]
menuAdd(self, doptmenu, desc, "Make the Documents list look like: %s"%desc, self.OnChangeDocumentsOptions, iid, typ)
moptmenu = wxMenu()
menuAddM(optionsmenu, moptmenu, "Macro Options", "Change the behavior of macros during double-click")
for value in xrange(3):
iid = MACRO_CLICK_TO_ID[value]
desc = MACRO_CLICK_OPTIONS[iid][1]
menuAdd(self, moptmenu, desc, "When double clicking on a macro: %s"%desc, self.OnChangeMacroOptions, iid, typ)
optionsmenu.AppendSeparator()
caretmenu = wxMenu()
menuAddM(optionsmenu, caretmenu, "Caret Tracking", "Set how your caret behaves while it is moving around")
x = [(j[2], i, j[3], j[4]) for i,j in CARET_ID_TO_OPTIONS.iteritems()]
x.sort()
for _, idn, name, helpt in x:
menuAdd(self, caretmenu, name, helpt, self.OnCaret, idn, typ)
menuAdd(self, optionsmenu, "Set Caret M value", "Set the number of lines of unapproachable margin, the M value referenced in Caret Options", self.OnCaretM, wxNewId())
menuAdd(self, optionsmenu, "Set Caret N value", "Set the multiplier, the N value referenced in Caret Options", self.OnCaretN, wxNewId())
caretmenu2 = wxMenu()
menuAddM(optionsmenu, caretmenu2, "Caret Width", "Set how wide your caret is to make it more or less visible")
for i in (1,2,3):
menuAdd(self, caretmenu2, "%i pixels"%i, "Set your caret to be %i pixels wide."%i, self.OnCaretWidth, CARET_W_WIDTH_TO_O[i], typ)
menuAdd(self, optionsmenu, "Set Line Color", "The color of the current line when 'Highlight Current Line' is enabled", self.OnLineColor, wxNewId())
optionsmenu.AppendSeparator()
menuAdd(self, optionsmenu, "Findbar below editor", "When checked, any new find/replace bars will be below the editor, otherwise above (bars will need to be reopened)", self.OnFindbarToggle, FINDBAR_BELOW_EDITOR, wxITEM_CHECK)
menuAdd(self, optionsmenu, "Use Findbar history", "When checked, allows for the find and replace bars to keep history of searches (bars will need to be reopened)", self.OnFindbarHistory, NO_FINDBAR_HISTORY, wxITEM_CHECK)
menuAdd(self, optionsmenu, "Clear Find Bar history", "Clears the find/replace history on the current document", self.OnFindbarClear, CLEAR_FINDBAR_HISTORY)
optionsmenu.AppendSeparator()
menuAdd(self, optionsmenu, "Change Menus and Hotkeys", "Change the name of menu items and their hotkeys, any changes will require a restart to take effect", self.OnChangeMenu, wxNewId())
titlemenu = wxMenu()
menuAddM(optionsmenu, titlemenu, "Title Options", "Set what information you would like PyPE to display in the title bar")
fn = "pype.py"
long = "C:\\PyPE\\pype.py"
pype = "PyPE %s"%VERSION
for i in xrange(5):
title_id, proto, desc = TITLE_OPTION_TO_ID[i]
menuAdd(self, titlemenu, desc, "Set the title like: "+proto%locals(), self.OnChangeTitle, title_id, typ)
menuAdd(self, optionsmenu, "Save preferences", "Saves all of your current preferences now", self.OnSavePreferences, wxNewId())
#--------------------------------- Help Menu ---------------------------------
if 1:
helpmenu= wxMenu()
menuAddM(menuBar, helpmenu, "&Help")
menuAdd(self, helpmenu, "About...", "About this piece of software", self.OnAbout, wxID_ABOUT)
helpmenu.AppendSeparator()
menuAdd(self, helpmenu, "PyPE Help\tF1", "View the help", self.OnHelp, wxID_HELP)
#------------------------ A ...few... state variables ------------------------
if 1:
self.Show(true)
self.dirname = '.'
self.closing = 0
self.openfiles = {}
self.realfn = {}
self.dpm = 0
self.menubar.Check(AUTO, showautocomp)
self.menubar.Check(WRAPL, wrapmode != wxSTC_WRAP_NONE)
self.menubar.Check(DND_ID, dnd_file)
self.menubar.Check(IT_ID, USE_DOC_ICONS)
self.menubar.Check(LB_ID, logbarlocn)
self.menubar.Check(DB_ID, docbarlocn)
self.menubar.Check(WIDE_ID, SHOWWIDE)
self.menubar.Check(TALL_ID, SHOWTALL)
self.menubar.Check(SINGLE_ID, single_pype_instance)
if UNICODE:
self.menubar.Check(USEBOM_ID, always_write_bom)
self.menubar.Check(TD_ID, TODOBOTTOM)
self.menubar.Check(USETABS, use_tabs)
self.menubar.Check(INDENTGUIDE, indent_guide)
self.menubar.Check(lexers3[DEFAULTLEXER], 1)
self.menubar.Check(SAVE_CURSOR, save_cursor)
self.menubar.Check(FINDBAR_BELOW_EDITOR, findbar_location)
self.menubar.Check(NO_FINDBAR_HISTORY, not no_findbar_history)
self.menubar.Check(CARET_W_WIDTH_TO_O[CARET_WIDTH], 1)
self.menubar.FindItemById(CLEAR_FINDBAR_HISTORY).Enable(not no_findbar_history)
self.menubar.Check(DOCUMENT_LIST_OPTION_TO_ID[document_options], 1)
#------------------------ Drag and drop file support -------------------------
self.SetDropTarget(FileDropTarget(self))
#set up some events
if 1:
EVT_CLOSE(self, self.OnExit)
EVT_SIZE(self, self.OnSize)
EVT_ACTIVATE(self, self.OnActivation)
EVT_KEY_DOWN(self, self.OnKeyPressed)
self.starting = 0
if self.control.GetPageCount() > 0:
stc = self.getNumWin()[1]
self.OnDocumentChange(stc)
#set up some timers
if 1:
tid = wxNewId()
self.timer = wxTimer(self, tid)
EVT_TIMER(self, tid, self.ex_size)
tid = wxNewId()
self.timer2 = wxTimer(self, tid)
EVT_TIMER(self, tid, self.single_instance_poller)
self.timer2.Start(100, wxTIMER_CONTINUOUS)
#------------------ Open files passed as arguments to PyPE -------------------
if not SHOWTALL:
self.RIGHT.Hide()
if not SHOWWIDE:
self.BOTTOM.Hide()
if (not SHOWWIDE) or (not SHOWTALL):
self.OnSize(None)
self.OnDrop(fnames, 0)
if single_pype_instance:
single_instance.startup()
if USE_THREAD:
self.Bind(EVT_DONE_PARSING, self.doneParsing)
wxCallAfter(start_parse_thread, self)
wxCallAfter(self.control.updateChecks, None)
#...
def getglobal(self, nam):
return globals()[nam]
def getInt(self, title, text, default):
dlg = wxTextEntryDialog(self, text, title, str(default))
resp = dlg.ShowModal()
valu = dlg.GetValue()
dlg.Destroy()
if resp != wxID_OK:
raise cancelled
return validate(valu, default)
def _setupToolBar(self):
size = (16,16)
def getBmp(artId, client):
bmp = wxArtProvider_GetBitmap(artId, client, size)
if not bmp.Ok():
bmp = EmptyBitmap(*size)
return bmp
if TOOLBAR == 1:
orient = wxTB_HORIZONTAL
else:
orient = wxTB_VERTICAL
tb = self.CreateToolBar(
orient|wxNO_BORDER|wxTB_FLAT|wxTB_TEXT)
tb.SetToolBitmapSize(size)
icon = getBmp(wxART_NORMAL_FILE, wxART_TOOLBAR)
tb.AddSimpleTool(wxID_NEW, icon, "New Document",
"Create a new empty document")
icon = getBmp(wxART_FILE_OPEN, wxART_TOOLBAR)
tb.AddSimpleTool(wxID_OPEN, icon, "Open",
"Open an existing document")
icon = getBmp(wxART_FILE_SAVE, wxART_TOOLBAR)
tb.AddSimpleTool(wxID_SAVE, icon, "Save", "Save current document")
icon = getBmp(wxART_FILE_SAVE_AS, wxART_TOOLBAR)
tb.AddSimpleTool(wxID_SAVEAS, icon, "Save as...", "Save current document as...")
tb.AddSeparator()
icon = getBmp(wxART_CUT, wxART_TOOLBAR)
tb.AddSimpleTool(wxID_CUT, icon, "Cut",
"Cut selection to the clibboard")
icon = getBmp(wxART_COPY, wxART_TOOLBAR)
tb.AddSimpleTool(wxID_COPY, icon, "Copy",
"Copy selection to the clibboard")
icon = getBmp(wxART_PASTE, wxART_TOOLBAR)
tb.AddSimpleTool(wxID_PASTE, icon, "Paste",
"Paste current clibboard contents")
icon = getBmp(wxART_DELETE, wxART_TOOLBAR)
tb.AddSimpleTool(pypeID_DELETE, icon, "Delete",
"Delete selection")
tb.AddSeparator()
icon = getBmp(wxART_UNDO, wxART_TOOLBAR)
tb.AddSimpleTool(wxID_UNDO, icon, "Undo",
"Undo edit")
icon = getBmp(wxART_REDO, wxART_TOOLBAR)
tb.AddSimpleTool(wxID_REDO, icon, "Redo",
"Redo edit (i.e. undo undo edit)")
tb.AddSeparator()
icon = getBmp(wxART_FIND, wxART_TOOLBAR)
tb.AddSimpleTool(pypeID_FINDBAR, icon, "Find",
"Find")
icon = getBmp(wxART_FIND_AND_REPLACE, wxART_TOOLBAR)
tb.AddSimpleTool(pypeID_REPLACEBAR, icon, "Replace",
"Find and replace")
tb.AddSeparator()
icon = getBmp(wxART_ADD_BOOKMARK, wxART_TOOLBAR)
tb.AddSimpleTool(pypeID_TOGGLE_BOOKMARK, icon, "Toggle Bookmark",
"Create or Remove a bookmark at the current line")
icon = getBmp(wxART_GO_DOWN, wxART_TOOLBAR)
tb.AddSimpleTool(pypeID_NEXT_BOOKMARK, icon, "Next Bookmark",
"Go to the next bookmark in this file")
icon = getBmp(wxART_GO_UP, wxART_TOOLBAR)
tb.AddSimpleTool(pypeID_PRIOR_BOOKMARK, icon, "Previous Bookmark",
"Go to the previous bookmark in this file")
tb.AddSeparator()
tb.AddSeparator()
icon = getBmp(wxART_HELP, wxART_TOOLBAR)
tb.AddSimpleTool(wxID_HELP, icon, "Help!",
"Opens up the help for PyPE")
tb.Realize()
def OnDocumentChange(self, stc, forced=False):
if not self.starting:
start = time.time()
if stc.cached is None or forced:
if stc.refresh:
return
stc.ConvertEOLs(fmt_mode[stc.format])
out = wxStyledTextCtrl.GetText(stc).replace('\t', stc.GetTabWidth()*' ')
lang = lexer2lang.get(stc.GetLexer(), 'text')
if out and USE_THREAD:
stc.refresh = 1
parse_queue.put((out, stc, lang))
return
tpl = parse(lang, out, stc.format, 3, lambda:None)
stc.cached = tpl
h1, stc.kw, stc.tooltips, todo = tpl
stc.kw.sort()
stc.kw = ' '.join(stc.kw)
## ex1 = copy.deepcopy(h1)
stc.docstate.Update(h1, todo)
self.SetStatusText(("Browsable source tree, autocomplete, tooltips and todo"
" updated for %s in %.1f seconds.")%(stc.filename, time.time()-start))
self.updateWindowTitle()
def doneParsing(self, evt):
stc = evt.stc
if not stc:
return
stc.refresh = 0
stc.cached = tpl = evt.tpl
h1, stc.kw, stc.tooltips, todo = tpl
stc.kw.sort()
stc.kw = ' '.join(stc.kw)
## ex1 = copy.deepcopy(h1)
stc.docstate.Update(h1, todo)
self.SetStatusText(("Browsable source tree, autocomplete, tooltips and todo"
" updated for %s in %.1f seconds.")%(stc.filename, evt.delta))
def updateWindowTitle(self):
pype = "PyPE %s"%VERSION
stc = None
try:
num, stc = self.getNumWin()
except cancelled:
self.SetTitle(pype)
return
if stc is not None:
fn = stc.getshort()
long = stc.getlong()
disp = TITLE_OPTION_TO_ID[title_option][1]%locals()
else:
disp = pype
self.SetTitle(disp)
def ex_size(self, evt=None):
#an attempt to keep the findbar the correct size
try:
win = self.getNumWin()[1]
if win.parent.IsSplit():
size = (win.parent.GetWindow2().GetAdjustedBestSize())[1]+5
win.parent.SetSashPosition(-size)
except cancelled:
pass
def single_instance_poller(self, evt=None):
if single_pype_instance:
single_instance.poll()
def OnSashDrag(self, event):
if event.GetDragStatus() == wxSASH_STATUS_OUT_OF_RANGE:
return
eID = event.GetId()
if eID == ID_WINDOW_RIGHT:
self.RIGHT.SetDefaultSize((max(event.GetDragRect().width, SMALL), BIG))
elif eID == ID_WINDOW_BOTTOM:
self.BOTTOM.SetDefaultSize((BIG, max(event.GetDragRect().height, SMALL)))
wxLayoutAlgorithm().LayoutWindow(self, self.control)
self.control.Refresh()
self.ex_size()
def OnSize(self, event):
wxLayoutAlgorithm().LayoutWindow(self, self.control)
self.ex_size()
def dialog(self, message, title, styl=wxOK):
d= wxMessageDialog(self,message,title,styl)
retr = d.ShowModal()
d.Destroy()
return retr
def exceptDialog(self, title="Error"):
k = cStringIO.StringIO()
traceback.print_exc(file=k)
k.seek(0)
dlg = wxScrolledMessageDialog(self, k.read(), title)
dlg.ShowModal()
dlg.Destroy()
def OnDrop(self, fnames, error=1):
cwd = current_path
for i in fnames:
dn, fn = os.path.split(self.getAlmostAbsolute(i, cwd))
if self.isOpen(fn, dn):
if len(fnames)==1:
self.selectAbsolute(self.getAbsolute(fn, dn))
else:
self.makeOpen(fn, dn)
try:
a = self.newTab(dn, fn, len(fnames)==1)
i = os.path.join(dn, fn)
if UNICODE: a = "%s as %s"%(i, a)
else: a = i
self.SetStatusText("Opened %s"%a)
except:
self.closeOpen(fn, dn)
if error:
self.exceptDialog("File open failed")
self.redrawvisible()
def SetStatusText(self, text, number=0, log=1):
if (number == 0) and text:
if log:
print text
text = "[%s] %s"%(time.asctime(), text)
self.sb.SetStatusText(text, number)
def OnActivation(self, e):
try:
self.control.__iter__
except wxPyDeadObjectError:
e.Skip()
return
try:
self.iter
e.Skip()
return
except:
self.iter = None
for document in self.control.__iter__():
if document.mod != None:
fn = self.getAlmostAbsolute(document.filename, document.dirname)
try:
mod = os.stat(fn)[8]
except OSError:
document.MakeDirty(None)
self.dialog("%s\n"\
"has been deleted from the disk by an external program.\n"\
"Unless the file is saved again, data loss may occur."%fn,
"WARNING!")
document.mod = None
continue
if mod != document.mod:
if open(fn, 'rb').read() == document.GetText():
#Compare the actual text, just to make sure...
#Fixes a problem with PyPE being open during daylight
#savings time changes.
#Also fixes an issue when an identical file is saved
#over a currently-being-edited file.
document.mod = mod
document.MakeClean(None)
continue
document.MakeDirty(None)
a = self.dialog("%s\n"\
"has been modified by an external program.\n"\
"Would you like to reload the file from disk?"%fn,
"WARNING!", wxYES_NO)
if a == wxID_NO:
document.mod = None
else:
self.OnReload(None, document)
del self.iter
self.redrawvisible()
self.SendSizeEvent()
e.Skip()
#--------------------------- cmt-001 - 08/06/2003 ----------------------------
#--------------------- Saving and loading of preferences ---------------------
def loadHistory(self):
if not os.path.exists(self.configPath):
os.mkdir(self.configPath)
path = os.path.join(self.configPath, 'history.txt')
if UNICODE:
p = os.path.join(self.configPath, 'history.u.txt')
if os.path.exists(p):
path = p
print "Loading history from", path
try: self.config = self.readAndEvalFile(path)
except: self.config = {}
if 'history' in self.config:
history = self.config['history']
history.reverse()
for h in history:
self.fileHistory.AddFileToHistory(h)
if 'lastpath' in self.config:
self.lastpath = self.config['lastpath']
doc_def = {}
#insert global document defaults here
dct = {'use_tabs':0,
'spaces_per_tab':8,
'indent':4,
'collapse':1,
'marker_margin':1,
'line_margin':1,
'col_line':78,
'col_mode':wxSTC_EDGE_LINE,
'indent_guide':0,
'showautocomp':0,
'wrapmode':wxSTC_WRAP_NONE,
'sortmode':1,
'save_cursor':0,
'cursor_posn':0,
'whitespace':0,
## 'triggers':{},
'findbarprefs':{},
'sloppy':0,
'smartpaste':0,
'showline':0}
for _i in ASSOC:
doc_def[_i[2]] = dict(dct)
if _i[2] in ('xml', 'html'):
doc_def['indent'] = 2
doc_def[_i[2]]['triggers'] = {}
for (nam, dflt) in [('modulepaths', []),
## ('usesnippets', 0),
## ('usetodo', 0),
## ('paths', {}),
## ('display2code', {}),
## ('displayorder', []),
## ('shellcommands', []),
('lastopen', []),
('LASTUSED', []),
('DEFAULTLEXER', 'python'),
('FIF_STATE', ([], [], [], 0, 0, 0)),
('match_flags', wxFR_DOWN),
('pathmarksn', []),
('workspaces', {}),
('workspace_order', []),
('SASH1', 60),
('SASH2', 300),
('LASTSIZE', (900,600)),
('LASTPOSITION', self.GetPositionTuple()),
('logbarlocn', 1),
('docbarlocn', 1),
('dnd_file', 1),
('caret_option', 0),
('caret_slop', 10),
('caret_multiplier', 20),
('findbarprefs', {}),
('no_findbar_history', 0),
('title_option', 0),
('document_defaults', doc_def),
('DOCUMENT_DEFAULTS', dct),
('TODOBOTTOM', 1),
('TOOLBAR', 0),
('SHOWWIDE', 1),
('SHOWTALL', 1),
('shellprefs', {}),
('findbar_location', 1),
('single_pype_instance', 0),
('DICTIONARIES', {}),
('USE_DOC_ICONS', 1),
('CARET_WIDTH', 1),
('ONE_TAB_', 1),
('always_write_bom', 1),
('document_options', 1),
('macro_doubleclick', 0),
('COLOUR', '#d0d0d0'),
]:
if nam in self.config:
if isinstance(dflt, dict):
for k,v in dflt.iteritems():
if k not in self.config[nam]:
if isinstance(v, dict):
self.config[nam][k] = dict(v)
else:
self.config[nam][k] = v
elif isinstance(v, dict):
V = self.config[nam][k]
for k2,v2 in v.iteritems():
if k2 not in V:
V[k2] = v2
elif isinstance(dflt, dict):
self.config[nam] = dict(dflt)
else:
self.config[nam] = dflt
globals()[nam] = self.config[nam]
globals().update(dct)
globals().update(self.config.setdefault('DOCUMENT_DEFAULTS', dct))
def saveHistory(self):
LASTOPEN = []
sav = []
for win in self.control:
if win.dirname:
sav.append(self.getAlmostAbsolute(win.filename, win.dirname))
LASTOPEN.append((self.getAlmostAbsolute(win.filename, win.dirname), win.GetSaveState()))
if 'LASTOPEN' in self.config:
del self.config['LASTOPEN']
#saving document state
self.config['lastopen'] = sav
self.config['LASTUSED'] = self.lastused.items() + LASTOPEN
self.config['LASTSIZE'] = self.GetSizeTuple()
self.config['LASTPOSITION'] = self.GetPositionTuple()
self.config['SASH1'] = self.BOTTOM.GetSizeTuple()[1]
self.config['SASH2'] = self.RIGHT.GetSizeTuple()[0]
history = []
for i in range(self.fileHistory.GetNoHistoryFiles()):
history.append(self.fileHistory.GetHistoryFile(i))
self.config['history'] = history
## a = []
## for i in self.shell.order:
## a.append(self.shell.menu[i])
## self.config['shellcommands'] = a
self.config['match_flags'] = match_flags
self.config['pathmarksn'] = self.pathmarks.op.GetLabels()
self.config['workspaces'] = workspaces
self.config['workspace_order'] = workspace_order
self.config['logbarlocn'] = logbarlocn
self.config['docbarlocn'] = docbarlocn
self.config['dnd_file'] = dnd_file
self.config['caret_option'] = caret_option
self.config['caret_slop'] = caret_slop
self.config['caret_multiplier'] = caret_multiplier
self.config['findbarprefs'] = findbarprefs
self.config['no_findbar_history'] = no_findbar_history
self.config['title_option'] = title_option
self.config['TODOBOTTOM'] = TODOBOTTOM
self.config['single_pype_instance'] = single_pype_instance
self.config['TOOLBAR'] = TOOLBAR
self.config['SHOWWIDE'] = SHOWWIDE
self.config['SHOWTALL'] = SHOWTALL
self.config['USE_DOC_ICONS'] = USE_DOC_ICONS
## self.config['shellprefs'] = self.shell.save_prefs()
self.config['findbar_location'] = findbar_location
## if self.config['usesnippets'] and (not self.restart):
## self.config['display2code'] = self.snippet.display2code
## self.config['displayorder'] = self.snippet.displayorder
self.config['lastpath'] = self.config.get('lp', current_path)
self.config['CARET_WIDTH'] = CARET_WIDTH
self.config['ONE_TAB_'] = ONE_TAB_
self.config['always_write_bom'] = always_write_bom
self.config['document_options'] = document_options
self.config['macro_doubleclick'] = macro_doubleclick
self.config['COLOUR'] = COLOUR
try:
if UNICODE:
path = os.sep.join([self.configPath, 'history.u.txt'])
else:
path = os.sep.join([self.configPath, 'history.txt'])
print "Saving history to", path
f = open(path, "w")
f.write(pprint.pformat(self.config))
f.close()
if UNICODE:
path = os.sep.join([self.configPath, 'menus.u.txt'])
else:
path = os.sep.join([self.configPath, 'menus.txt'])
print "Saving menus to", path
f = open(path, "w")
f.write(pprint.pformat(MENUPREF))
f.close()
except:
self.exceptDialog("Could not save preferences to %s"%path)
def readAndEvalFile(self, filename):
f = open(filename)
txt = f.read().replace('\r\n','\n')
f.close()
return eval(txt)
#------------------------- end cmt-001 - 08/06/2003 --------------------------
def redrawvisible(self, win=None):
if (not win) and self.control.GetPageCount() > 0:
num, win = self.getNumWin()
if win:
win.parent.Refresh()
#----------------------------- File Menu Methods -----------------------------
def getPositionAbsolute(self, path, newf=0):
## print path
path = os.path.normcase(path)
for i in xrange(self.control.GetPageCount()):
win = self.control.GetPage(i).GetWindow1()
if newf:
if os.path.normcase(win.getshort()) == path:
return i
elif os.path.normcase(win.getlong()) == path:
return i
return -1
def selectAbsolute(self, path):
if self.isAbsOpen(path):
i = self.getPositionAbsolute(path)
if i != -1:
self.control.SetSelection(i)
def isOpen(self, fn, dn):
return dn and fn and (self.getAbsolute(fn, dn) in self.openfiles)
def isAbsOpen(self, path):
return path in self.openfiles
def makeOpen(self, fn, dn):
if fn and dn:
a = self.getAbsolute(fn, dn)
self.openfiles[a] = self.splitAbsolute(a)
self.realfn[a] = self.getAlmostAbsolute(fn, dn)
def closeOpen(self, fn, dn):
if fn and dn:
a = self.getAbsolute(fn, dn)
del self.openfiles[a]
del self.realfn[a]
def getAbsolute(self, fn, dn):
return os.path.normcase(os.path.normpath(os.path.realpath(os.path.join(dn, fn))))
def getAlmostAbsolute(self, fn, dn):
return os.path.normpath(os.path.realpath(os.path.join(dn, fn)))
def splitAbsolute(self, path):
return os.path.split(os.path.normcase(path))
def OnNew(self,e):
self.newTab('', ' ', 1)
self.control.GetPage(self.control.GetSelection()).GetWindow1().opened = 1
def OnSave(self,e):
wnum, win = self.getNumWin(e)
if win.dirname:
try:
txt = win.GetText()
ofn = os.path.join(win.dirname, win.filename)
fil = open(ofn, 'wb')
fil.write(txt)
fil.close()
if UNICODE: a = "%s as %s"%(ofn, win.enc)
else: a = ofn
win.mod = os.stat(ofn)[8]
self.SetStatusText("Correctly saved %s"%a)
self.curdocstates[ofn] = win.GetSaveState()
win.MakeClean()
except cancelled:
raise
except:
self.exceptDialog("Save Failed")
raise cancelled
else:
self.OnSaveAs(e)
def OnSaveAs(self,e):
wnum, win = self.getNumWin(e)
dlg = wxFileDialog(self, "Save file as...", current_path, "", "All files (*.*)|*.*", wxSAVE|wxOVERWRITE_PROMPT)
rslt = dlg.ShowModal()
if rslt == wxID_OK:
fn=dlg.GetFilename()
dn=dlg.GetDirectory()
if sys.platform == 'win32' and dn[1:] == ':':
dn += '\\'
pth = self.getAlmostAbsolute(fn, dn)
dn, fn = os.path.split(pth)
if win.filename != fn or win.dirname != dn:
if self.isOpen(fn, dn):
self.dialog("Another file with that name and path is already open.\nSave aborted to prevent data corruption.", "Save Aborted!")
raise cancelled
if self.isOpen(win.filename, win.dirname):
self.closeOpen(win.filename, win.dirname)
#we do a quick GetText to make sure we don't set the file/dir names
#unless we really can get the text for the file.
x = win.GetText()
win.filename = fn
win.dirname = dn
self.makeOpen(fn, dn)
self.fileHistory.AddFileToHistory(pth)
self.OnSave(e)
#fix the icons and names.
self.dragger._RemoveItem(wnum)
self.dragger._InsertItem(wnum, fn)
win.MakeDirty()
win.MakeClean()
if USE_DOC_ICONS:
self.control.SetPageImage(wnum, GDI(fn))
self.control.SetSelection(wnum)
else:
raise cancelled
def OnSaveAll(self, e):
sel = self.control.GetSelection()
cnt = self.control.GetPageCount()
for i in xrange(cnt):
self.control.SetSelection(i)
try:
self.OnSave(e)
except cancelled:
pass
if cnt:
self.control.SetSelection(sel)
def OnOpen(self,e):
wd = self.config.get('lastpath', current_path)
dlg = wxFileDialog(self, "Choose a/some file(s)...", wd, "", wildcard, wxOPEN|wxMULTIPLE|wxHIDE_READONLY)
if dlg.ShowModal() == wxID_OK:
self.OnDrop(dlg.GetPaths())
self.config['lp'] = dlg.GetDirectory()
dlg.Destroy()
def FindModule(self, mod):
fndmod = mod.split('.')
lf = len(fndmod)
pth = sys.path[:]
pth[1:1] = [current_path]
for j in range(lf):
i = fndmod[j]
fdsc = imp.find_module(i, pth)
if not (fdsc[0] is None):
fdsc[0].close()
mod = fdsc[1]
if fdsc[2][2] != imp.PY_SOURCE:
return self.dialog("%s is not python source"%mod, "not correct format for editing")
return mod
elif fdsc[1]:
pth[1:1] = [fdsc[1]]
else:
raise cancelled
#If we are outside the loop, this means that the current 'module'
#that we are on is a folder-module. We can easily load the __init__.py
#from this folder.
return os.sep.join([pth[1], '__init__.py'])
def OnOpenModule(self,e):
dlg = wxTextEntryDialog(self, 'Enter the module name you would like to open', 'Open module...')
if dlg.ShowModal() == wxID_OK:
mod = dlg.GetValue()
else:
mod = ''
dlg.Destroy()
if mod:
sp = sys.path[:]
sys.path.extend(self.config['modulepaths'])
try:
self.OnDrop([self.FindModule(mod)])
except:
self.dialog("module %s not found"%mod, "not found")
sys.path = sp
def OnOpenPrevDocs(self, e):
if "lastopen" in self.config:
self.OnDrop(self.config['lastopen'], 1)
def AddSearchPath(self, e):
dlg = wxDirDialog(self, "Choose a path", "", style=wxDD_DEFAULT_STYLE|wxDD_NEW_DIR_BUTTON)
if dlg.ShowModal() == wxID_OK:
path = os.path.normcase(os.path.normpath(dlg.GetPath()))
if not (path in self.config['modulepaths']) and not (path in sys.path):
self.config['modulepaths'].append(path)
def OnNewPythonShell(self, e):
self.newTab("", " ", 1, 1)
def OnNewCommandShell(self, e):
self.newTab("", " ", 1, 2)
def newTab(self, d, fn, switch=0, shell=0):
if 'lastpath' in self.config:
del self.config['lastpath']
#ctrlwidth, ctrlh = self.control.GetSizeTuple()
if d:
d, fn = os.path.split(self.getAlmostAbsolute(fn, d))
FN = self.getAlmostAbsolute(fn, d)
f = open(FN, 'rb')
txt = f.read()
f.close()
else:
FN = ''
txt = ''
split = SplitterWindow(self.control, wxNewId(), style=wxSP_NOBORDER)
split.SetMinimumPaneSize(0)
EVT_SPLITTER_SASH_POS_CHANGING(self, split.GetId(), veto)
ftype = extns.get(fn.split('.')[-1].lower(), 'python')
## if ftype in document_defaults:
## print "found filetype-specific defaults", ftype
## else:
## print "could not find", ftype
state = dict(document_defaults.get(ftype, DOCUMENT_DEFAULTS))
if not shell:
nwin = PythonSTC(self.control, wxNewId(), split)
else:
state = dict(state)
state['wrapmode'] = 1
state['whitespace'] = 0
nwin = interpreter.MyShell(split, wxNewId(), self, None, shell&1)
nwin.filename = fn
nwin.dirname = d
if shell < 2:
nwin.changeStyle(stylefile, self.style(fn))
else:
#we don't want to syntax highlight by default for non-python shells.
nwin.changeStyle(stylefile, self.style('a.txt'))
if d:
nwin.mod = os.stat(FN)[8]
if len(txt) == 0:
nwin.format = eol
nwin.SetText('')
else:
nwin.format = detectLineEndings(txt)
nwin.SetText(txt)
#if FN in self.config['LASTOPEN']:
# state = self.config['LASTOPEN'][FN]
if FN in self.lastused:
_ = self.lastused[FN]
__ = _.pop('triggers', None)
state.update(_)
del _, __, self.lastused[FN]
## else:
## pass
else:
nwin.mod = None
nwin.format = eol
nwin.SetText(txt)
## print 2
if not ((d == '') and (fn == ' ')):
self.fileHistory.AddFileToHistory(os.path.join(d, fn))
if 'checksum' in state:
if md5.new(txt).hexdigest() != state['checksum']:
## print "mismatched checksum"
state.update(RESET)
else:
## print "no checksum", fn
state.update(RESET)
if FN:
self.curdocstates[FN] = state
nwin.SetSaveState(state)
## nwin.SetSaveState({})
## print 3
if fn == ' ':
## print 3.5
globals()['NEWDOCUMENT'] += 1
nwin.NEWDOCUMENT = NEWDOCUMENT
nwin.docstate = docstate(self, nwin)
## print 4
split.Initialize(nwin)
## print 5
self.control.AddPage(split, nwin.getshort(), switch)
nwin.MakeClean()
## self.OnRefresh(None, nwin)
self.updateWindowTitle()
if switch:
nwin.SetFocus()
## self.OnDocumentChange(nwin)
return nwin.enc
def OnReload(self, e, win=None):
if win == None:
num, win = self.getNumWin(e)
if not e is None:
dlg = wxMessageDialog(self, "%s was modified after last save.\nReloading from disk will destroy all changes.\n\nContinue anyway?"%win.filename, 'File was modified, data loss may occur!', wxYES_NO|wxCANCEL)
a = dlg.ShowModal()
if a == wxID_CANCEL:
raise cancelled
elif a == wxID_NO:
return
try:
FN = self.getAlmostAbsolute(win.filename, win.dirname)
fil = open(FN, 'rb')
txt = fil.read()
fil.close()
win.BeginUndoAction()
try:
win.SetText(txt, 0)
finally:
win.EndUndoAction()
win.mod = os.stat(FN)[8]
win.SetSavePoint()
win.MakeClean()
self.curdocstates[FN] = {'checksum':md5.new(txt).hexdigest()}
self.OnRefresh(None, win)
except:
self.dialog("Error encountered while trying to reload from disk.", "Reload failed")
def sharedsave(self, win):
nam = win.filename
if not win.dirname:
nam = "<untitled %i>"%win.NEWDOCUMENT
a = self.dialog("%s was modified after last save.\nSave changes before closing?"%nam,\
"Save changes?", wxYES_NO|wxCANCEL)
if a == wxID_CANCEL:
raise cancelled
elif a == wxID_NO:
return 0
else:
self.OnSave(None)
return 1
def OnClose(self, e, wnum=None, win=None):
if wnum is None or win is None:
wnum, win = self.getNumWin(e)
fn = self.getAlmostAbsolute(win.filename, win.dirname)
if isdirty(win):
for i, w in enumerate(self.control):
if w is win:
self.control.SetSelection(i)
break
if win.GetParent().IsSplit():
f = win.GetParent().GetWindow2()
if f.replacing:
f.loop = 1
del f
saved = self.sharedsave(win)
elif self.isOpen(win.filename, win.dirname):
self.curdocstates[fn] = win.GetSaveState()
if self.isOpen(win.filename, win.dirname):
self.lastused[fn] = self.curdocstates.pop(fn, {})
self.closeOpen(win.filename, win.dirname)
self.SetStatusText("Closed %s"%self.getAlmostAbsolute(win.filename, win.dirname))
else:
self.SetStatusText("Closed unnamed file without saving")
if hasattr(win, "kill"):
win.kill()
self.control.DeletePage(wnum)
self.updateWindowTitle()
def OnRestart(self, e):
self.OnExit(e)
_restart()
def OnExit(self,e):
if self.closing:
return e.Skip()
self.closing = 1
if USE_THREAD:
parse_queue.put(None)
sel = self.control.GetSelection()
cnt = self.control.GetPageCount()
try:
for i in xrange(cnt):
win = self.control.GetPage(i).GetWindow1()
if isdirty(win):
self.control.SetSelection(i)
self.sharedsave(win)
else:
self.curdocstates[self.getAlmostAbsolute(win.filename, win.dirname)] = win.GetSaveState()
except cancelled:
self.closing = 0
try: return e.Veto()
except: return e.Skip()
self.saveHistory()
if sel > -1:
self.control.SetSelection(sel)
return self.Close(True)
#--------------------------- cmt-001 - 08/06/2003 ----------------------------
#------------- Open the file selected from the file history menu -------------
def OnFileHistory(self, e):
fileNum = e.GetId() - wxID_FILE1
path = self.fileHistory.GetHistoryFile(fileNum)
self.OnDrop([path])
#------------------------- end cmt-001 - 08/06/2003 --------------------------
#----------------------------- Edit Menu Methods -----------------------------
def OneCmd(self, funct_name, evt):
wnum, win = self.getNumWin(evt)
ff = self.FindFocus()
if ff != win:
if isinstance(ff, (wxComboBox, wxTextCtrl)):
if isinstance(ff, wxComboBox):
gm, sm = ff.GetMark, ff.SetMark
else:
gm, sm = ff.GetSelection, ff.SetSelection
if funct_name == 'DeleteSelection':
return ff.Remove(*gm())
elif funct_name == 'SelectAll':
return sm(0, ff.GetLastPosition())
elif sys.platform == 'win32':
if hasattr(ff, 'Can'+funct_name) and getattr(ff, 'Can'+funct_name)():
return getattr(ff, funct_name)()
return
else:
return getattr(ff, funct_name)()
return evt.Skip()
getattr(win, funct_name)()
def OnUndo(self, e):
self.OneCmd('Undo',e)
def OnRedo(self, e):
self.OneCmd('Redo',e)
def OnSelectAll(self, e):
self.OneCmd('SelectAll',e)
def OnCut(self, e):
self.OneCmd('Cut',e)
def OnCopy(self, e):
self.OneCmd('Copy',e)
def OnPaste(self, e):
self.OneCmd('Paste',e)
def OnDeleteSelection(self, e):
self.OneCmd('DeleteSelection',e)
#----------------------- Find and Replace Bar Display ------------------------
def getNumWin(self, e=None):
num = self.control.GetSelection()
if num >= 0:
return num, self.control.GetPage(num).GetWindow1()
if e:
e.Skip()
raise cancelled
def OnShowFindbar(self, evt):
num, win = self.getNumWin(evt)
if win.parent.IsSplit() and not isinstance(win.parent.GetWindow2(), findbar.FindBar):
win.parent.GetWindow2().close()
if not win.parent.IsSplit():
bar = findbar.FindBar(win.parent, self)
win.parent.SplitHorizontally(win, bar, -(bar.GetBestSize())[1]-5, 1-findbar_location)
bar = win.parent.GetWindow2()
focused = self.FindFocus()
hasfocus = (focused == bar) or (focused and focused.GetParent() == bar)
self.commonbar(win)
if hasfocus:
bar.OnFindN(evt)
def OnShowReplacebar(self, evt):
num, win = self.getNumWin(evt)
if win.parent.IsSplit() and isinstance(win.parent.GetWindow2(), findbar.FindBar):
win.parent.GetWindow2().close()
if not win.parent.IsSplit():
bar = findbar.ReplaceBar(win.parent, self)
win.parent.SplitHorizontally(win, bar, -(bar.GetBestSize())[1]-5, 1-findbar_location)
self.commonbar(win)
def commonbar(self, win):
st,end = win.GetSelection()
box = win.parent.GetWindow2().box1
if st == end and box.GetLastPosition() == 0:
gcp = win.GetCurrentPos()
st = win.WordStartPosition(gcp, 1)
end = win.WordEndPosition(gcp, 1)
if st != end:
x = win.GetTextRange(st, end)
try:
x = str(x)
except UnicodeError:
pass
if not isinstance(x, unicode):
rx = x.encode('string-escape')
if rx != x:
x = repr(x)
box.SetValue(x)
win.SetSelection(st, end)
box.SetFocus()
if isinstance(box, wxTextCtrl):
box.SetSelection(0, box.GetLastPosition())
else:
box.SetMark(0, box.GetLastPosition())
def OnFindAgain(self, evt):
num, win = self.getNumWin(evt)
if win.parent.IsSplit():
win.parent.GetWindow2().OnFindN(evt)
win.SetFocus()
#----------------------------- View Menu Methods -----------------------------
def Maximize(self, b):
wxFrame.Maximize(b)
wxPostEvent(wxSizeEvent((0,0), self.GetId()))
def OnZoom(self, e):
wnum, win = self.getNumWin(e)
if e.GetId() == ZI:incr = 1
else: incr = -1
win.SetZoom(win.GetZoom()+incr)
def OnGoto(self, e):
wnum, win = self.getNumWin(e)
valu = self.getInt('Which line would you like to advance to?', '', win.LineFromPosition(win.GetSelection()[0])+1)
valu -= 1
if valu < win.GetLineCount():
linepos = win.GetLineEndPosition(valu)
win.EnsureVisible(valu)
win.SetSelection(linepos-len(win.GetLine(valu))+len(win.format), linepos)
win.ScrollToColumn(0)
def OnGotoP(self, e):
wnum, win = self.getNumWin(e)
x = win.GetSelection()[0]
valu = 0
while x > 0:
y, x = x, win.PositionBefore(x)
valu += len(win.GetTextRange(y,x))
valu = self.getInt('What position would you like to advance to?', '', valu)
length = win.GetLength()
x = 0
while valu > 0 and x < length:
y, x = x, win.PositionAfter(x)
valu -= len(win.GetTextRange(y,x))
if not valu:
win.SetSelection(x, x)
def OnRefresh(self, e, win=None):
if win is None:
num, win = self.getNumWin(e)
self.OnDocumentChange(win, True)
def OnToggleBookmark (self, e):
wnum, win = self.getNumWin(e)
lineNo = win.GetCurrentLine()
if win.MarkerGet(lineNo) & BOOKMARKMASK:
win.MarkerDelete(lineNo, BOOKMARKNUMBER)
else:
win.MarkerAdd(lineNo, BOOKMARKNUMBER)
def OnNextBookmark (self, e):
wnum, win = self.getNumWin(e)
lineNo = win.GetCurrentLine()
newLineNo = win.MarkerNext(lineNo + 1, BOOKMARKMASK)
if newLineNo != -1:
win.GotoLine(newLineNo)
else:
lineNo = win.GetLineCount()
newLineNo = win.MarkerNext(0, BOOKMARKMASK)
if newLineNo != -1:
win.GotoLine(newLineNo)
win.EnsureVisible(win.GetCurrentLine())
win.EnsureCaretVisible()
def OnPreviousBookmark (self, e):
wnum, win = self.getNumWin(e)
lineNo = win.GetCurrentLine()
newLineNo = win.MarkerPrevious(lineNo - 1, BOOKMARKMASK)
if newLineNo != -1:
win.GotoLine(newLineNo)
else:
lineNo = win.GetLineCount()
newLineNo = win.MarkerPrevious(lineNo, BOOKMARKMASK)
if newLineNo != -1:
win.GotoLine(newLineNo)
win.EnsureVisible(win.GetCurrentLine())
win.EnsureCaretVisible()
def OnLeft(self, e):
self.control.AdvanceSelection(False)
def OnRight(self, e):
self.control.AdvanceSelection(True)
def OnFindDefn(self, e):
num, win = self.getNumWin(e)
if hasattr(self, 'single_ctrl'):
x = self.single_ctrl
else:
x = self.RIGHTNB
x.SetSelection(2)
gcp = win.GetCurrentPos()
st = win.WordStartPosition(gcp, 1)
end = win.WordEndPosition(gcp, 1)
f = win.docstate.filter
f.cs.SetValue(1)
f.filter.SetValue(win.GetTextRange(st, end))
f.how.SetValue('exact')
f.update()
f.filter.SetFocus()
#--------------------------- Document Menu Methods ---------------------------
def OnStyleChange(self,e):
wnum, win = self.getNumWin(e)
lang = lexers[e.GetId()]
win.changeStyle(stylefile, lang)
win.triggers = document_defaults[lang]['triggers']
wxCallAfter(self.control.updateChecks, win)
def style(self, fn):
ext = fn.split('.')[-1].lower()
return extns.get(ext, DEFAULTLEXER)
def OnEncChange(self, e):
num, win = self.getNumWin(e)
mid = e.GetId()
newenc = self.menubar.GetLabel(mid)
oldenc = win.enc
if oldenc != newenc:
win.enc = newenc.strip()
self.SetStatusText("encoding changed to %s for %s"%(win.enc,
win.filename.strip() or self.control.GetPageText(num).strip(' *')))
self.SetStatusText(win.enc, 2)
wxCallAfter(self.control.updateChecks, win)
def OnLineEndChange(self, e):
n, win = self.getNumWin(e)
endid = e.GetId()
newend = LE_MAPPING[endid][0]
oldend = win.GetEOLMode()
if oldend != newend:
win.format = fmt_Rmode[newend]
win.ConvertEOLs(newend)
win.SetEOLMode(newend)
wxCallAfter(self.control.updateChecks, win)
def OnAutoCompleteToggle(self, event):
# Images are specified with a appended "?type"
#for i in range(len(kw)):
# if kw[i] in keyword.kwlist:
# kw[i] = kw[i]# + "?1"
n, win = self.getNumWin(event)
win.showautocomp = (win.showautocomp+1)%2
def OnNumberToggle(self, e):
n, win = self.getNumWin(e)
win.SetMarginWidth(0, (win.GetMarginWidth(0)+40)%80)
def OnMarginToggle(self, e):
n, win = self.getNumWin(e)
win.SetMarginWidth(1, (win.GetMarginWidth(1)+16)%32)
def OnIndentGuideToggle(self, e):
n, win = self.getNumWin(e)
win.SetIndentationGuides((win.GetIndentationGuides()+1)%2)
def OnWhitespaceToggle(self, e):
n, win = self.getNumWin(e)
win.SetViewWhiteSpace((win.GetViewWhiteSpace()+1)%2)
def OnSavePositionToggle(self, e):
n, win = self.getNumWin(e)
win.save_cursor = (1+win.save_cursor)%2
def HightlightLineToggle(self, e):
n, win = self.getNumWin(e)
win.SetCaretLineVisible(not win.GetCaretLineVisible())
def OnExpandAll(self, e):
n, win = self.getNumWin(e)
lc = win.GetLineCount()
win.ShowLines(0, lc-1)
for line in xrange(lc):
if win.GetFoldLevel(line) & wxSTC_FOLDLEVELHEADERFLAG:
win.SetFoldExpanded(line, 1)
def OnFoldAll(self, e):
n, win = self.getNumWin(e)
#these next two lines are to allow
#win.GetFoldLevel() to be accurate
win.HideLines(0, win.GetLineCount()-1)
try: wxYield()
except: pass
#toss all the old folds
self.OnExpandAll(e)
lc = win.GetLineCount()
lines = []
for line in xrange(lc):
if win.GetFoldLevel(line) & wxSTC_FOLDLEVELHEADERFLAG:
lines.append(line)
lines.reverse()
for line in lines:
a = win.GetLastChild(line, -1)
win.HideLines(line+1,a)
win.SetFoldExpanded(line, 0)
def OnSetTabToggle(self, e):
n, win = self.getNumWin(e)
a = win.GetUseTabs()
win.SetUseTabs((a+1)%2)
win.SetProperty("tab.timmy.whinge.level", str(a))
def OnWrapL(self, e):
wnum, win = self.getNumWin(e)
self.WrapToggle(win)
def OnSloppy(self, e):
wnum, win = self.getNumWin(e)
win.sloppy = (win.sloppy + 1) % 2
def OnSmartPaste(self, e):
wnum, win = self.getNumWin(e)
win.smartpaste = (win.smartpaste + 1) % 2
def WrapToggle(self, win):
#tossing the current home/end key configuration, as it will change
win.CmdKeyClear(wxSTC_KEY_HOME,0)
win.CmdKeyClear(wxSTC_KEY_HOME,wxSTC_SCMOD_SHIFT)
win.CmdKeyClear(wxSTC_KEY_HOME,wxSTC_SCMOD_ALT)
win.CmdKeyClear(wxSTC_KEY_HOME,wxSTC_SCMOD_ALT|wxSTC_SCMOD_SHIFT)
win.CmdKeyClear(wxSTC_KEY_END,0)
win.CmdKeyClear(wxSTC_KEY_END,wxSTC_SCMOD_SHIFT)
win.CmdKeyClear(wxSTC_KEY_END,wxSTC_SCMOD_ALT)
win.CmdKeyClear(wxSTC_KEY_END,wxSTC_SCMOD_ALT|wxSTC_SCMOD_SHIFT)
if win.GetWrapMode() == wxSTC_WRAP_NONE:
win.SetWrapMode(wxSTC_WRAP_WORD)
#making home and end work like we expect them to when lines are wrapped
win.CmdKeyAssign(wxSTC_KEY_HOME, 0, wxSTC_CMD_HOMEDISPLAY)
win.CmdKeyAssign(wxSTC_KEY_HOME, wxSTC_SCMOD_SHIFT, wxSTC_CMD_HOMEDISPLAYEXTEND)
win.CmdKeyAssign(wxSTC_KEY_HOME, wxSTC_SCMOD_ALT, wxSTC_CMD_VCHOME)
win.CmdKeyAssign(wxSTC_KEY_HOME, wxSTC_SCMOD_ALT|wxSTC_SCMOD_SHIFT, wxSTC_CMD_VCHOMEEXTEND)
win.CmdKeyAssign(wxSTC_KEY_END, 0, wxSTC_CMD_LINEENDDISPLAY)
win.CmdKeyAssign(wxSTC_KEY_END, wxSTC_SCMOD_SHIFT, wxSTC_CMD_LINEENDDISPLAYEXTEND)
win.CmdKeyAssign(wxSTC_KEY_END, wxSTC_SCMOD_ALT, wxSTC_CMD_LINEEND)
win.CmdKeyAssign(wxSTC_KEY_END, wxSTC_SCMOD_ALT|wxSTC_SCMOD_SHIFT, wxSTC_CMD_LINEENDEXTEND)
else:
win.SetWrapMode(wxSTC_WRAP_NONE)
#making home and end work like we expect them to when lines are not wrapped
win.CmdKeyAssign(wxSTC_KEY_HOME, 0, wxSTC_CMD_VCHOME)
win.CmdKeyAssign(wxSTC_KEY_HOME, wxSTC_SCMOD_SHIFT, wxSTC_CMD_VCHOMEEXTEND)
win.CmdKeyAssign(wxSTC_KEY_HOME, wxSTC_SCMOD_ALT, wxSTC_CMD_HOMEDISPLAY)
win.CmdKeyAssign(wxSTC_KEY_HOME, wxSTC_SCMOD_ALT|wxSTC_SCMOD_SHIFT, wxSTC_CMD_HOMEDISPLAYEXTEND)
win.CmdKeyAssign(wxSTC_KEY_END, 0, wxSTC_CMD_LINEEND)
win.CmdKeyAssign(wxSTC_KEY_END, wxSTC_SCMOD_SHIFT, wxSTC_CMD_LINEENDEXTEND)
win.CmdKeyAssign(wxSTC_KEY_END, wxSTC_SCMOD_ALT, wxSTC_CMD_LINEENDDISPLAY)
win.CmdKeyAssign(wxSTC_KEY_END, wxSTC_SCMOD_ALT|wxSTC_SCMOD_SHIFT, wxSTC_CMD_LINEENDDISPLAYEXTEND)
def OnSetTriggers(self, e):
num, win = self.getNumWin(e)
## print win.triggers
a = triggerdialog.TriggerDialog(self, win, win.triggers)
a.ShowModal()
def OnSetIndent(self, e):
n, win = self.getNumWin(e)
rslt = self.getInt("How many spaces per indent level?", "Enter an integer > 0.",
win.GetIndent())
win.SetIndent(rslt)
def OnSetTabWidth(self, e):
n, win = self.getNumWin(e)
rslt = self.getInt("How many spaces per tab?",
"How many spaces should a tab character,\n"\
"'\\t' represent? Enter an integer > 0.",
win.GetTabWidth())
win.SetTabWidth(rslt)
def OnSetLongLinePosition(self, e):
n, win = self.getNumWin(e)
rslt = self.getInt("Long Line Indicator",
"At what column would you like a long line\n"\
"signifier to be displayed? Enter an integer > 0.",
win.GetEdgeColumn())
win.SetEdgeColumn(rslt)
def OnSetLongLineMode(self, e):
n, win = self.getNumWin(e)
eid = e.GetId()
win.SetEdgeMode(LL_MAPPING[eid][0])
wxCallAfter(self.control.updateChecks, win)
#--------------------------- Options Menu Methods ----------------------------
def OnSaveLang(self, e):
mid = e.GetId()
lang, desc = SOURCE_ID_TO_OPTIONS.get(mid, ('python', ''))
n, win = self.getNumWin()
dct = win.GetSaveState()
del dct['BM']
del dct['FOLD']
del dct['checksum']
document_defaults[lang].update(dct)
self.SetStatusText("Updated document defaults for " + desc)
def OnLoadSavedLang(self, e):
mid = e.GetId()
lang, desc = SOURCE_ID_TO_OPTIONS2.get(mid, ('python', ''))
n, win = self.getNumWin()
dct = win.GetSaveState()
dct.update(document_defaults[lang])
s,e = win.GetSelection()
win.SetSaveState(dct)
win.SetSelection(s,e)
self.control.updateChecks(win)
self.SetStatusText("Updated document settings to %s for %s"%(desc, os.path.join(win.dirname, win.filename)))
def OnDefaultStyleChange(self, e):
dl = lexers[e.GetId()]
self.config['DEFAULTLEXER'] = dl
globals()['DEFAULTLEXER'] = dl
wxCallAfter(self.control.updateChecks, None)
def OnSaveSettings(self, e):
#unused right now.
n, win = self.getNumWin()
dct = win.GetSaveState()
del dct['BM']
del dct['FOLD']
del dct['checksum']
globals().update(dct)
self.config['DOCUMENT_DEFAULTS'] = dct
def OnDNDToggle(self, e):
global dnd_file
dnd_file = not dnd_file
def OnIconToggle(self, e):
global USE_DOC_ICONS
USE_DOC_ICONS = not USE_DOC_ICONS
def OnLogBarToggle(self, e):
global logbarlocn
logbarlocn = not logbarlocn
def OnDocBarToggle(self, e):
global docbarlocn
docbarlocn = not docbarlocn
def OnShowWideToggle(self, e):
global SHOWWIDE
SHOWWIDE = not SHOWWIDE
if SHOWWIDE:
self.BOTTOM.Show()
else:
self.BOTTOM.Hide()
self.OnSize(None)
def OnShowTallToggle(self, e):
global SHOWTALL
SHOWTALL = not SHOWTALL
if SHOWTALL:
self.RIGHT.Show()
else:
self.RIGHT.Hide()
self.OnSize(None)
def OnTodoToggle(self, e):
global TODOBOTTOM
TODOBOTTOM = not TODOBOTTOM
def OnOneTabToggle(self, e):
global ONE_TAB_
ONE_TAB_ = not ONE_TAB_
def OnSingleToggle(self, e):
global single_pype_instance
if single_pype_instance:
single_instance.shutdown()
try:
x = open(os.path.join(runpath, 'nosocket'), 'w')
x.close()
except:
pass
single_pype_instance = 0
else:
try:
os.remove(os.path.join(runpath, 'nosocket'))
except:
if nosocket:
self.menubar.Check(SINGLE_ID, single_pype_instance)
return
try:
single_instance.startup()
except:
single_instance.traceback.print_exc()
self.menubar.Check(SINGLE_ID, single_pype_instance)
else:
single_pype_instance = 1
def OnBOMToggle(self, e):
global always_write_bom
always_write_bom = not always_write_bom
def OnToolBar(self, e):
global TOOLBAR
TOOLBAR = TB_MAPPING[e.GetId()][0]
self.SetStatusText("To apply your changed toolbar settings, restart PyPE.")
wxCallAfter(self.control.updateChecks, None)
def OnCaret(self, e):
global caret_option
i = e.GetId()
caret_option, flags = CARET_ID_TO_OPTIONS[i][:2]
wxCallAfter(self.control.updateChecks, None)
self.SharedCaret()
def OnCaretM(self, e):
global caret_slop
caret_slop = self.getInt("Set Caret M Value", "", caret_slop)
self.SharedCaret()
def OnCaretN(self, e):
global caret_multiplier
caret_multiplier = self.getInt("Set Caret N Value", "", caret_multiplier)
self.SharedCaret()
def OnCaretWidth(self, e):
global CARET_WIDTH
CARET_WIDTH = CARET_W_OPTION_TO_W.get(e.GetId(), 1)
for i in CARET_W_OPTION_TO_W:
self.menubar.Check(i, 0)
self.menubar.Check(e.GetId(), 1)
num, win = self.getNumWin(e)
win.SetCaretWidth(CARET_WIDTH)
def OnLineColor(self, e):
global COLOUR
data = wx.ColourData()
data.SetChooseFull(True)
data.SetColour(COLOUR)
dlg = wx.ColourDialog(self, data)
changed = dlg.ShowModal() == wx.ID_OK
if changed:
c = dlg.GetColourData().GetColour()
COLOUR = '#%02x%02x%02x'%(c.Red(), c.Green(), c.Blue())
dlg.Destroy()
self.getNumWin()[1].SetCaretLineBack(COLOUR)
def SharedCaret(self):
_, flags = CARET_OPTION_TO_ID[caret_option]
for win in self.control:
win.SetXCaretPolicy(flags, caret_slop*caret_multiplier)
win.SetYCaretPolicy(flags, caret_slop)
win.SetSelection(*win.GetSelection())
def OnFinbarDefault(self, e):
n, win = self.getNumWin()
if win.GetParent().IsSplit():
win.GetParent().GetWindow2().savePreferences()
a = dict(win.findbarprefs)
del a['find']
del a['replace']
global findbarprefs
findbarprefs = a
def OnFindbarClear(self, e):
n, win = self.getNumWin()
if win.GetParent().IsSplit():
bar = win.GetParent().GetWindow2()
bar.box1.Clear()
bar.box1.SetValue("")
if not isinstance(bar, findbar.FindBar):
bar.box2.Clear()
bar.box2.SetValue("")
else:
win.findbarprefs['replace'] = []
else:
win.findbarprefs['find'] = []
win.findbarprefs['replace'] = []
def OnFindbarToggle(self, e):
global findbar_location
findbar_location = (findbar_location + 1)%2
def OnFindbarHistory(self, e):
global no_findbar_history
no_findbar_history = (no_findbar_history + 1) % 2
self.menubar.FindItemById(CLEAR_FINDBAR_HISTORY).Enable(not no_findbar_history)
def OnChangeMenu(self, e):
keydialog.MenuItemDialog(self, self).ShowModal()
def OnChangeTitle(self, e):
global title_option
i = e.GetId()
title_option, _, _ = TITLE_ID_TO_OPTIONS[i]
self.updateWindowTitle()
wxCallAfter(self.control.updateChecks, None)
def OnChangeDocumentsOptions(self, e):
global document_options
i = e.GetId()
document_options = DOCUMENT_LIST_OPTIONS[i][0]
self.dragger.setupcolumns()
self.dragger._Refresh()
wxCallAfter(self.control.updateChecks, None)
def OnChangeMacroOptions(self, e):
global macro_doubleclick
i = e.GetId()
macro_doubleclick = MACRO_CLICK_OPTIONS[i][0]
wxCallAfter(self.control.updateChecks, None)
def OnSavePreferences(self, e):
self.saveHistory()
#----------------------------- Help Menu Methods -----------------------------
def OnAbout(self, e):
txt = """
PyPE was written to scratch an itch. I (Josiah Carlson), was looking for
an editor for Python that had the features I wanted. I couldn't find one,
so I wrote PyPE.
PyPE %s (Python Programmers Editor)
http://come.to/josiah
PyPE is copyright 2003-2006 Josiah Carlson.
Contributions are copyright their respective authors.
This software is licensed under the GPL (GNU General Public License) version 2
as it appears here: http://www.gnu.org/copyleft/gpl.html
It is also included with this software as gpl.txt.
If you do not also receive a copy of gpl.txt with your version of this
software, please inform the me of the violation at the web page near the top
of this document."""%VERSION
self.dialog(txt.replace(' ', ''), "About...")
def OnHelp(self, e):
if not SHOWWIDE:
self.OnShowWideToggle(None)
self.BOTTOMNB.SetSelection(self.BOTTOMNB.GetPageCount()-1)
def fixsize():
h = self.GetClientSizeTuple()[1]
self.BOTTOM.SetDefaultSize((BIG, max(h//2, self.BOTTOM.GetSize()[1])))
wxLayoutAlgorithm().LayoutWindow(self, self.control)
self.control.Refresh()
self.ex_size()
wxCallAfter(fixsize)
#-------------------------- Hot Key support madness --------------------------
def keyboardShortcut(self, keypressed, evt=None):
menuid = HOTKEY_TO_ID[keypressed]
wxPostEvent(self, wxMenuEvent(wxEVT_COMMAND_MENU_SELECTED, menuid))
def OnKeyPressed(self, event):
showpress=0
keypressed = GetKeyPress(event)
if showpress: print "keypressed", keypressed
if keypressed in HOTKEY_TO_ID:
return self.keyboardShortcut(keypressed, event)
if self.macropage.RunMacro(keypressed):
return
key = event.KeyCode()
wnum = self.control.GetSelection()
pagecount = self.control.GetPageCount()
if wnum > -1:
win = self.control.GetPage(wnum).GetWindow1()
if pagecount:
if (key==13):
#when 'enter' is pressed, indentation needs to happen.
if win.AutoCompActive():
return win.AutoCompComplete()
if win.CallTipActive():
win.CallTipCancel()
win._autoindent()
else:
event.Skip()
if not (win.GetStyleAt(win.GetCurrentPos())):
#3, 13, 6, 7
if win.CallTipActive():
good = STRINGPRINTABLE
if (key in good) or (key in (WXK_SHIFT, WXK_CONTROL, WXK_ALT)):
pass
#if key in (48, 57) and event.ShiftDown():
# win.CallTipCancel()
#else it is something in the arguments that is OK.
else:
win.CallTipCancel()
if (not win.CallTipActive()) and event.ShiftDown() and (key == ord('9')):
win.CallTipSetBackground(wxColour(255, 255, 232))
cur, colpos, word = self.getLeftFunct(win)
tip = '\n'.join(win.tooltips.get(word, []))
if tip:
win.CallTipShow(win.GetCurrentPos(),tip)
elif win.showautocomp and bool(win.kw):
if keypressed.split('+')[-1] in _keys:
return
if keypressed.endswith('+') and not keypressed.endswith('++'):
return
wxCallAfter(self._ac, win)
else:
return event.Skip()
def getLeftFunct(self, win):
t = ' .,;:([)]}\'"\\<>%^&+-=*/|`'
bad = dict(zip(t, [0]*len(t)))
line = win.GetLine(win.GetCurrentLine())
colpos = win.GetColumn(win.GetCurrentPos())
cur = colpos-1
while (cur >= 0) and not (line[cur:cur+1] in bad):
cur -= 1
cur += 1
return cur, colpos, line[cur:colpos]
def _ac(self, win):
cur, colpos, word = self.getLeftFunct(win)
if not word:
return win.AutoCompCancel()
words = [i for i in win.kw.split() if i.startswith(word)]
if len(words) == 0:
return win.AutoCompCancel()
if len(words) == 1 and words[-1] == word:
return win.AutoCompCancel()
words = ' '.join(words)
win.AutoCompSetIgnoreCase(False)
win.AutoCompShow(colpos-cur, words)
#------------- Ahh, Styled Text Control, you make this possible. -------------
#the following table maps from event numbers to method names in the STC macro
#recording
message_lookup_table = {
2013:'SelectAll',
2177:'Cut',
2178:'Copy',
2179:'Paste',
2180:'Clear',
2300:'LineDown',
2301:'LineDownExtend',
2302:'LineUp',
2303:'LineUpExtend',
2304:'CharLeft',
2305:'CharLeftExtend',
2306:'CharRight',
2307:'CharRightExtend',
2308:'WordLeft',
2309:'WordLeftExtend',
2310:'WordRight',
2311:'WordRightExtend',
2312:'Home',
2313:'HomeExtend',
2314:'LineEnd',
2315:'LineEndExtend',
2316:'DocumentStart',
2317:'DocumentStartExtend',
2318:'DocumentEnd',
2319:'DocumentEndExtend',
2320:'PageUp',
2321:'PageUpExtend',
2322:'PageDown',
2323:'PageDownExtend',
2324:'EditToggleOvertype',
2325:'Cancel',
2326:'DeleteBack',
2327:'Tab',
2328:'BackTab',
2329:'NewLine',
2330:'FormFeed',
2331:'VCHome',
2332:'VCHomeExtend',
2333:'ZoomIn',
2334:'ZoomOut',
2335:'DelWordLeft',
2336:'DelWordRight',
2337:'LineCut',
2338:'LineDelete',
2339:'LineTranspose',
2340:'LowerCase',
2341:'UpperCase',
2342:'LineScrollDown',
2343:'LineScrollUp',
2344:'DeleteBackNotLine',
2345:'HomeDisplay',
2346:'HomeDisplayExtend',
2347:'LineEndDisplay',
2348:'LineEndDisplayExtend'
}
class PythonSTC(wxStyledTextCtrl):
def __init__(self, notebook, ID, parent):
wxStyledTextCtrl.__init__(self, parent, ID)#, style = wxNO_FULL_REPAINT_ON_RESIZE)
self.SetWordChars('abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ')
self.SetEndAtLastLine(False)
self.cached = None
self.MarkerDefine(BOOKMARKNUMBER, BOOKMARKSYMBOL, 'blue', 'blue')
_, flags = CARET_OPTION_TO_ID[caret_option]
self.SetXCaretPolicy(flags, caret_slop*caret_multiplier)
self.SetYCaretPolicy(flags, caret_slop)
self.hierarchy = []
self.kw = []
self.tooltips = {}
self.ignore = {}
self.lines = lineabstraction.LineAbstraction(self)
self.parent = parent
self.notebook = notebook #should also be equal to self.parent.parent
self.root = self.notebook.root
self.sloppy = 0
self.smartpaste = 0
self.dirty = 0
self.refresh = 0
self.lexer = 'text'
self.selep = None
self.recording = 0
self.macro = []
#Text is included in the original, but who drags text? Below for dnd file support.
if dnd_file: self.SetDropTarget(FileDropTarget(self.root))
#for command comlpetion
self.SetKeyWords(0, " ".join(keyword.kwlist))
self.SetMargins(0,0)
self.SetViewWhiteSpace(False)
self.SetBackSpaceUnIndents(1)
#self.SetBufferedDraw(False)
#self.SetViewEOL(True)
self.SetMarginType(0, wxSTC_MARGIN_NUMBER)
#self.StyleSetSpec(wxSTC_STYLE_LINENUMBER, "size:%(size)d,face:%(mono)s" % faces)
# Setup a margin to hold fold markers
#I agree, what is this value?
#self.SetFoldFlags(16) ### WHAT IS THIS VALUE? WHAT ARE THE OTHER FLAGS? DOES IT MATTER?
self.SetProperty("fold", "1")
self.SetMarginType(2, wxSTC_MARGIN_SYMBOL)
self.SetMarginMask(2, wxSTC_MASK_FOLDERS)
self.SetMarginSensitive(2, True)
self.SetMarginWidth(2, 12)
self.SetPasteConvertEndings(1)
if collapse_style: # simple folder marks, like the old version
self.MarkerDefine(wxSTC_MARKNUM_FOLDER, wxSTC_MARK_BOXPLUS, "navy", "white")
self.MarkerDefine(wxSTC_MARKNUM_FOLDEROPEN, wxSTC_MARK_BOXMINUS, "navy", "white")
# Set these to an invisible mark
self.MarkerDefine(wxSTC_MARKNUM_FOLDEROPENMID, wxSTC_MARK_BACKGROUND, "white", "black")
self.MarkerDefine(wxSTC_MARKNUM_FOLDERMIDTAIL, wxSTC_MARK_BACKGROUND, "white", "black")
self.MarkerDefine(wxSTC_MARKNUM_FOLDERSUB, wxSTC_MARK_BACKGROUND, "white", "black")
self.MarkerDefine(wxSTC_MARKNUM_FOLDERTAIL, wxSTC_MARK_BACKGROUND, "white", "black")
else: # more involved "outlining" folder marks
self.MarkerDefine(wxSTC_MARKNUM_FOLDEREND, wxSTC_MARK_BOXPLUSCONNECTED, "white", "black")
self.MarkerDefine(wxSTC_MARKNUM_FOLDEROPENMID, wxSTC_MARK_BOXMINUSCONNECTED, "white", "black")
self.MarkerDefine(wxSTC_MARKNUM_FOLDERMIDTAIL, wxSTC_MARK_TCORNER, "white", "black")
self.MarkerDefine(wxSTC_MARKNUM_FOLDERTAIL, wxSTC_MARK_LCORNER, "white", "black")
self.MarkerDefine(wxSTC_MARKNUM_FOLDERSUB, wxSTC_MARK_VLINE, "white", "black")
self.MarkerDefine(wxSTC_MARKNUM_FOLDER, wxSTC_MARK_BOXPLUS, "white", "black")
self.MarkerDefine(wxSTC_MARKNUM_FOLDEROPEN, wxSTC_MARK_BOXMINUS, "white", "black")
# Make some styles, The lexer defines what each style is used for, we
# just have to define what each style looks like. This set is adapted from
# Scintilla sample property files.
#And good wxPython users who have seen some demos know the above was copied
#and pasted, along with a lot of sample code, right out of the demo. The
#demo r0XX0rs.
# Global default styles for all languages
self.StyleSetSpec(wxSTC_STYLE_DEFAULT, "fore:#000000,face:%(mono)s,back:#FFFFFF,size:%(size)d" % faces)
self.StyleSetSpec(wxSTC_STYLE_LINENUMBER, "back:#C0C0C0,face:Lucida Console,size:%(size2)d" % faces)
self.StyleSetSpec(wxSTC_STYLE_CONTROLCHAR, "face:%(other)s" % faces)
self.StyleSetSpec(wxSTC_STYLE_BRACELIGHT, "fore:#003000,face:%(mono)s,back:#80E0E0"% faces)
self.StyleSetSpec(wxSTC_STYLE_BRACEBAD, "fore:#E0FFE0,face:%(mono)s,back:#FF0000"% faces)
#various settings
self.SetSelBackground(1, '#B0B0FF')
#again, some state variables
self.filename = ''
self.dirname = ''
self.opened = 0
self.AutoCompStops(' .,;:()[]{}\'"\\<>%^&+-=*/|`')
EVT_STC_UPDATEUI(self, ID, self.OnUpdateUI)
EVT_STC_MARGINCLICK(self, ID, self.OnMarginClick)
EVT_KEY_DOWN(self, self.root.OnKeyPressed)
#EVT_CHAR(self, self.root.OnKeyPressed)
EVT_KEY_UP(self, self.key_up)
EVT_STC_CHARADDED(self, ID, self.added)
EVT_STC_CHANGE(self, ID, self.key_up)
#unavailable in 2.5.1.2, didn't work in previous versions of wxPython
# EVT_STC_POSCHANGED(self, ID, self.pos)
EVT_STC_SAVEPOINTREACHED(self, ID, self.MakeClean)
EVT_STC_SAVEPOINTLEFT(self, ID, self.MakeDirty)
EVT_STC_NEEDSHOWN(self, ID, self.OnNeedShown)
self.Bind(EVT_STC_MACRORECORD, self.GotEvent)
self.SetModEventMask(wxSTC_MOD_INSERTTEXT|wxSTC_MOD_DELETETEXT|wxSTC_PERFORMED_USER|wxSTC_PERFORMED_UNDO|wxSTC_PERFORMED_REDO)
if REM_SWAP:
self.CmdKeyClear(ord('T'), wxSTC_SCMOD_CTRL)
self.CmdKeyClear(ord('Z'), wxSTC_SCMOD_CTRL)
self.CmdKeyClear(ord('Y'), wxSTC_SCMOD_CTRL)
self.CmdKeyClear(ord('X'), wxSTC_SCMOD_CTRL)
self.CmdKeyClear(ord('C'), wxSTC_SCMOD_CTRL)
self.CmdKeyClear(ord('V'), wxSTC_SCMOD_CTRL)
self.CmdKeyClear(ord('A'), wxSTC_SCMOD_CTRL)
def getshort(self):
if self.dirname:
return self.filename
return '<untitled %i>'%self.NEWDOCUMENT
def getlong(self):
if self.dirname:
return os.path.join(self.dirname, self.filename)
return ''
def MacroToggle(self, e):
self.recording = not self.recording
if self.recording:
self.macro = []
self.StartRecord()
else:
self.StopRecord()
self.root.SetStatusText("Recorded %s steps for the macro"%len(self.macro))
def StopRecord(self):
wxStyledTextCtrl.StopRecord(self)
#macro: merge all character 2170 events together
macro = []
last = []
x = len(self.macro)
for i in self.macro:
if i[0] != 2170 or (i[0] == 2170 and isinstance(i[-1], (int, long))):
if last:
macro.append((2170, 0, ''.join(last)))
last = []
macro.append(i)
else:
last.append(i[-1])
if last:
macro.append((2170, 0, ''.join(last)))
if len(macro) < x:
self.macro = macro
if PRINTMACROS: print "Reduced macro from %i to %i steps"%(x, len(macro))
def _macro_to_source(self):
mlt = message_lookup_table
z = ['def macro(self):']
for i in self.macro:
m,w,l = i
if m in mlt:
z.append(' self.%s()'%mlt[m])
elif m is None:
z.append(' self.%s(%s)'%(l, w))
elif isinstance(m, basestring):
if l == None:
z.append(" self.root.keyboardShortcut(%r)"%m)
else:
z.append(" #the following shouldn't happen: %r"%(i,))
z.append(" root.Dent(None, %i)"%l)
elif m == 2170:
if isinstance(l, basestring):
z.append(" self.ReplaceSelection(%r)"%l)
else:
z.append(" #this event shouldn't happen: %r"%(i,))
else:
z.append(" #this event shouldn't happen: %r"%(i,))
return '\n'.join(z)
def InterpretTrigger(self, tr, strict=0):
self.BeginUndoAction()
try:
if not strict:
tr = tr.replace('\r\n', '\n').replace('\r', '\n').replace('\n', '%L')
posn = p = self.GetSelection()[0]
todos = tr.split('%C')
for y, todo in enumerate(todos):
if '\n' in todo:
ts = todo.split('%L')
for x, line in enumerate(ts):
self.ReplaceSelection(line)
if x != len(ts)-1:
self._autoindent()
else:
self.ReplaceSelection(todo)
if y != len(todos)-1:
posn = self.GetSelection()[0]
if posn != p:
self.SetSelection(posn, posn)
finally:
self.EndUndoAction()
def _tdisable(self, fcn, *args, **kwargs):
_, self.recording = self.recording, 0
try:
return fcn(*args, **kwargs)
finally:
self.recording = _
def GotEvent(self, e):
if self.recording:
x = (e.GetMessage(), e.GetWParam(), e.GetLParam())
if x[0] in message_lookup_table:
self.macro.append(x)
elif x[0] != 2170:
print "Unhandled event, please report to the author", x
def PlayMacro(self):
mlt = message_lookup_table
## self.BeginUndoAction()
#macro: z represents generated code based on method name
z = ['def macro(self):']
for i in self.macro:
m,w,l = i
## print i,
if m in mlt:
method = getattr(self, mlt[m])
z.append(' self.%s()'%mlt[m])
method()
elif m is None:
z.append(' self.%s(%s)'%(l, w))
getattr(self, l)(w)
elif isinstance(m, basestring):
if l == None:
z.append(" self.root.keyboardShortcut(%r)"%m)
self.root.keyboardShortcut(m)
else:
print "shouldn't happen!", i
z.append(" root.Dent(None, %i)"%l)
self.root.Dent(None, l)
elif m == 2170:
if isinstance(l, basestring):
z.append(" self.ReplaceSelection(%r)"%l)
self.ReplaceSelection(l)
else:
print "shouldn't happen!", i
else:
print "Unhandled event:",i
wxYield()
time.sleep(.01)
## self.EndUndoAction()
print "Performed %s steps of the macro!"%len(self.macro)
if PRINTMACROS: print '\n'.join(z)
def save(self, e):
#print "save reached"
self.key_up(e)
def savel(self, e):
#print "save left"
self.key_up(e)
def key_up(self, e):
if self.GetModify(): self.MakeDirty()
else: self.MakeClean()
def pos_ch(self, e):
if self.root.control.GetCurrentPage() == self.GetParent():
if not hasattr(self, 'lines'):
return
l = self.lines
self.root.SetStatusText("L%i C%i"%(l.curlinei+1, l.curlinep), 1)
if e:
e.Skip()
def added(self, e):
if self.recording:
if e:
self.macro.append((2170, 0, _decode_key(e.GetKey())))
## print "got key", repr(self.macro[-1][-1]), e.GetKey()
expanded = 0
try:
full = e is None
tr = self.triggers
c = 0
gcp = self.GetCurrentPos()
for p in xrange(gcp-1, -1, -1):
if not full and p < gcp-1:
break
ch = self.GetCharAt(p)
if UNICODE:
ch = (chr((ch>>8)&255)+chr(ch&255)).decode('utf-16-be')
else:
ch = chr(ch)
c += 1
tr = tr.get(ch, None)
if tr is None:
## print "ran off of triggers!", ch, gcp-p-1
break
elif isinstance(tr, (str, unicode)):
if e:
self.macro.append((None, 1, 'added'))
self.SetSelection(p, p+c)
self.ReplaceSelection('')
self.InterpretTrigger(tr)
expanded = 1
break
finally:
self.key_up(e)
def jump(self, direction):
#1 forward, -1 backward
if direction not in (1,-1):
return
#set up characters
chars2, chars3 = '({[:,\'"', ')}]\'"'
if self.GetLexer() in (wxSTC_LEX_HTML, wxSTC_LEX_XML):
chars2 = chars2 + '>'
chars3 = chars3 + '<'
#chars2 are things that we want to be to the right of
#chars3 are things that we want to be to the left of
chars1 = chars2 + chars3
#cursor position information
linenum = self.GetCurrentLine()
pos = self.GetCurrentPos()
#iterator setup
if direction == 1:
it = xrange(pos, self.GetTextLength())
else:
it = xrange(pos-1, -1, -1)
#updates information cross-lines
for p in it:
ch = self.GetTextRange(p, p+1)
if ch not in chars1:
continue
if direction == 1: #if we are heading to the right
#if we want to be to the right of line[p], make it so
if ch in chars2:
p += 1
break
#else if this character is just to the right of where we are at, skip it
elif p == pos:
continue
#else if we want to be to the left of line[p], make it so
elif ch in chars3:
break
else: #else we are heading to the left
#if we want to be to the left of line[p], make it so
if ch in chars3:
break
#else if this character is just to the left of where we are at, skip it
elif p == pos-1:
continue
#else if we want to be to the right of line[p], make it so
elif ch in chars2:
p += 1
break
else:
return
self._tdisable(self.SetSelection, p, p)
def OnJumpF(self, e):
self.jump(1)
def OnJumpB(self, e):
self.jump(-1)
#------------------------- persistant document state -------------------------
def GetSaveState(self):
BM = []
FOLD = []
if self.GetParent().IsSplit():
self.GetParent().GetWindow2().savePreferences()
ret = {'BM':BM,
'FOLD':FOLD,
'use_tabs':self.GetUseTabs(),
'spaces_per_tab':self.GetTabWidth(),
'indent':self.GetIndent(),
'marker_margin':bool(self.GetMarginWidth(1)),
'line_margin':bool(self.GetMarginWidth(0)),
'col_line':self.GetEdgeColumn(),
'col_mode':self.GetEdgeMode(),
'indent_guide':self.GetIndentationGuides(),
'showautocomp':self.showautocomp,
'wrapmode':self.GetWrapMode(),
## 'sortmode':self.tree.tree.SORTTREE,
'save_cursor':self.save_cursor,
'cursor_posn':self.GetCurrentPos(),
'findbarprefs':self.findbarprefs,
## 'triggers':self.triggers,
'whitespace':self.GetViewWhiteSpace(),
'sloppy':self.sloppy,
'smartpaste':self.smartpaste,
'checksum':md5.new(self.GetText()).hexdigest(),
'showline':self.GetCaretLineVisible()
}
for line in xrange(self.GetLineCount()):
if self.MarkerGet(line) & BOOKMARKMASK:
BM.append(line)
if (self.GetFoldLevel(line) & wxSTC_FOLDLEVELHEADERFLAG) and\
(not self.GetFoldExpanded(line)):
FOLD.append(line)
FOLD.reverse()
return ret
def SetSaveState(self, saved):
self.SetUseTabs(saved['use_tabs'])
self.SetProperty("tab.timmy.whinge.level", "10"[bool(saved['use_tabs'])])
self.SetTabWidth(saved['spaces_per_tab'])
self.SetIndent(saved['indent'])
self.SetMarginWidth(0, 40*saved['line_margin'])
self.SetMarginWidth(1, 16*saved['marker_margin'])
self.SetEdgeColumn(saved['col_line'])
self.SetEdgeMode(saved['col_mode'])
self.SetIndentationGuides(saved['indent_guide'])
self.showautocomp = saved['showautocomp']
self.findbarprefs = dict(saved.get('findbarprefs', {}))
self.triggers = saved['triggers']
self.sloppy = saved['sloppy']
self.smartpaste = saved['smartpaste']
self.SetCaretLineVisible(saved['showline'])
if self.GetWrapMode() != saved['wrapmode']:
self.root.WrapToggle(self)
## self.tree.tree.SORTTREE = saved.get('sortmode', sortmode)
self.save_cursor = saved['save_cursor']
for bml in saved.get('BM', []):
self.MarkerAdd(bml, BOOKMARKNUMBER)
for exl in saved.get('FOLD', []):
a = self.GetLastChild(exl, -1)
self.HideLines(exl+1,a)
self.SetFoldExpanded(exl, 0)
try: wxYield()
except: pass
if self.save_cursor:
a = saved.get('cursor_posn', 0)
self.SetSelection(a,a)
self.EnsureCaretVisible()
self.ScrollToColumn(0)
#-------------------- fix for SetText for the 'dirty bit' --------------------
def SetText(self, txt, emptyundo=1):
self.SetEOLMode(fmt_mode[self.format])
self.enc = actual = 'ascii'
if UNICODE:
for bom, enc in BOM:
if txt[:len(bom)] == bom:
self.enc = actual = enc
txt = txt[len(bom):]
## print "chose", enc
break
twolines = txt.split(self.format, 2)[:2]
foundcoding = 0
for line in twolines:
x = re.search('coding[=:]\s*([-\w.]+)', line)
if not x:
continue
x = x.group(1).lower()
## print "ENCODING:", x
if x in ADDBOM:
if actual != 'ascii' and actual != x:
#BOM did not match coding: directive.
#We are going to decode based on the BOM, but claim
#whatever
self.enc = x
else:
self.enc = actual = x
else:
self.enc = x
if actual == 'ascii':
actual = x
foundcoding = 1
break
while 1:
try:
txt = txt.decode(actual)
except Exception, why:
if self.enc != actual:
self.root.dialog(('''\
You have declared %r as your encoding, but
your document included a BOM for %r.
PyPE was not able to decode your document as
%r due to:
%s
PyPE will now attempt to decode your document as
%r.'''%(self.enc, actual, actual, why, self.enc)).replace(28*' ', ''),
"%r decoding error"%actual)
actual = self.enc
continue
if foundcoding:
self.root.dialog(('''\
You have used %r as your encoding
declaration, but PyPE was unable to decode
your document due to:
%s
PyPE will load your document as ASCII.
Depending on the content of your file, this
may cause data loss if you save the opened
version. You do so at your own risk, and
have now been warned.
To prevent loss or corruption of data, it
is suggested that you close the document,
do not save. Then try to open the document
with the application you originally created
it with. If PyPE was the original creator
and only editor of the document, please
contact the author and submit a bug report.'''%(actual, why)).replace(28*' ', ''),
"%r decoding error"%actual)
else: #foundbom
self.root.dialog(('''\
While attempting to decode your document
as %r based on the BOM included with it,
there was a unicode decoding error:
%s
PyPE will load your document as ASCII.
Depending on the content of your file, this
may cause data loss if you save the opened
version. You do so at your own risk, and
have now been warned.
To prevent loss or corruption of data, it
is suggested that you close the document,
do not save. Then try to open the document
with the application you originally created
it with. If PyPE was the original creator
and only editor of the document, please
contact the author and submit a bug report.'''%(actual, why)).replace(28*' ', ''),
"Unicode decoding error.")
self.enc = 'ascii'
break
if self.enc not in ADDBOM:
self.enc = 'other'
wxStyledTextCtrl.SetText(self, txt)
self.ConvertEOLs(fmt_mode[self.format])
self.opened = 1
if emptyundo:
self.EmptyUndoBuffer()
self.SetSavePoint()
def GetText(self):
self.ConvertEOLs(fmt_mode[self.format])
if UNICODE:
txt = otxt = wxStyledTextCtrl.GetText(self)
twolines = txt.split(self.format, 2)[:2]
x = None
#pull the encoding
for line in twolines:
x = re.search('coding[=:]\s*([-\w.]+)', line)
if not x:
continue
x = str(x.group(1).lower())
break
#try self.enc, the discovered coding, ascii, then utf-8 in that order
why = None
z = {}
for i in [j for j in (self.enc, x, 'ascii', 'utf-8') if j and j != 'other']:
if i in z:
continue
z[i] = None
try:
txt = otxt.encode(i)
except UnicodeEncodeError, wh:
if why is None:
why = wh
else:
if (self.enc != 'other' and self.enc != i) or \
(self.enc == 'other' and x != i):
y = os.path.join(self.dirname, self.filename)
if self.root.dialog(('''\
While trying to save the file named:
%s
PyPE was not able to encode the file as specified
in the encoding declaration or the Document -> Encoding
option:
%r
Due to:
%s
Would you like for PyPE to instead use %r as an encoding?
'''%(y, x, why, i)).replace(32*' ', ''),
"Continue with alternate encoding?", wxYES_NO) != wxID_YES:
raise cancelled
self.root.SetStatusText("Using %r encoding for %s"%(i, y))
## print 'SAVED ENCODING:', i
if (always_write_bom and i == x) or (i != x):
## print "added BOM for", i
txt = ADDBOM.get(i, '') + txt
return txt
#this exception should never be raised
raise Exception, "You should contact the author of this software."
return wxStyledTextCtrl.GetText(self)
#----- Takes care of the little '*' modified next to the open file name ------
def MakeDirty(self, e=None):
if (not self.dirty) and self.opened:
self.dirty = 1
f = self.getshort()
c = 0
for i in self.notebook:
if i == self:
break
c += 1
self.notebook.SetPageText(c, '* '+f)
self.root.redrawvisible(self)
if e:
e.Skip()
def MakeClean(self, e=None):
if self.dirty:
self.dirty = 0
f = self.getshort()
c = 0
for i in self.notebook:
if i == self:
break
c += 1
self.notebook.SetPageText(c, f)
self.SetSavePoint()
self.root.redrawvisible(self)
if e:
e.Skip()
def nada(self, e):
pass
def do(self, funct, dirty=1):
if dirty:
self.MakeDirty(None)
funct(self)
self.root.redrawvisible(self)
def SelectLines(self, force=0):
x,y = self.GetSelection()
if not force and x==y:
return
x,y = self.lines.selectedlinesi
if y-x > 1 or force:
self.lines.selectedlinesi = x,y
def Cut(self):
if self.sloppy and not self.SelectionIsRectangle():
self.SelectLines()
self.do(wxStyledTextCtrl.Cut)
def Copy(self):
if self.sloppy and not self.SelectionIsRectangle():
self.SelectLines()
self.do(wxStyledTextCtrl.Copy, 0)
def Paste(self):
if self.recording:
self.macro.append((2179, 0, 0))
while self.smartpaste:
x,y = self.GetSelection()
if x != y:
break
d = GetClipboardText()
if d is None or '\n' not in d:
break
self.BeginUndoAction()
#create a new line using the auto-indent stuff
try:
curline = self.LineFromPosition(x)
x = self.GetLineEndPosition(curline)
self.SetSelection(x,x)
if self.GetLineIndentation(curline)+self.PositionFromLine(curline) != x:
self._tdisable(self._autoindent, self)
#sanitize the information to be pasted
lines = d.replace('\r\n', '\n').replace('\r', '\n').split('\n')
#find the leading indentation for the clipboard text
tabwidth = self.GetTabWidth()
repl = tabwidth*' '
x = []
z = len(d)
for line in lines:
leading_whitespace = line[:len(line)-len(line.lstrip())]
rest = line[len(leading_whitespace):]
leading_whitespace = leading_whitespace.replace('\t', repl)
llw = len(leading_whitespace)
if not rest.strip():
llw = z
x.append((llw, leading_whitespace, rest))
#reindent the clipboard text
base = self.GetLineIndentation(self.LineFromPosition(self.GetSelection()[0]))*' '
min_i = min(x)[0]
usetabs = self.GetUseTabs()
out = []
for y, (li, lw, lr) in enumerate(x):
lw = lw[min_i:]
if y:
## print "non-first line", lr
lw = base + lw
if usetabs:
lw = lw.replace(repl, '\t')
out.append(lw+lr)
x = self.format.join(out)
#insert the clipboard text
self.ReplaceSelection(x)
finally:
self.EndUndoAction()
return
self.do(wxStyledTextCtrl.Paste)
def DeleteSelection(self): self.do(wxStyledTextCtrl.DeleteBack)
def Undo(self): self.do(wxStyledTextCtrl.Undo)
def Redo(self): self.do(wxStyledTextCtrl.Redo)
def CanEdit(self):
return 1
#--------- Ahh, the style change code...isn't it great? Not really. ---------
def changeStyle(self, stylefile, language):
try:
#from StyleSupport import initSTC
## from STCStyleEditor import initSTC
from StyleSetter import initSTC
initSTC(self, stylefile, language)
## self.SetLexer(wxSTC_LEX_NULL)
self.lexer = language
except:
#self.root.exceptDialog("Style Change failed, assuming plain text")
self.root.SetStatusText("Style Change failed for %s, assuming plain text"%language)
self.root.exceptDialog()
#----------------- Defaults, in case the other code was bad. -----------------
#for some default font styles
self.SetLexer(wxSTC_LEX_NULL)
self.lexer = 'text'
### Python styles
##
### White space
##self.StyleSetSpec(wxSTC_P_DEFAULT, "fore:#000000,face:%(helv)s,size:%(size)d" % faces)
### Comment
##self.StyleSetSpec(wxSTC_P_COMMENTLINE, "fore:#007F00,face:%(mono)s,back:#E0FFE0,size:%(size)d" % faces)
### Number
##self.StyleSetSpec(wxSTC_P_NUMBER, "fore:#007F7F,face:%(times)s,size:%(size)d" % faces)
### String
##self.StyleSetSpec(wxSTC_P_STRING, "fore:#7F007F,face:%(times)s,size:%(size)d" % faces)
### Single quoted string
##self.StyleSetSpec(wxSTC_P_CHARACTER, "fore:#7F007F,face:%(times)s,size:%(size)d" % faces)
### Keyword
##self.StyleSetSpec(wxSTC_P_WORD, "fore:#F0B000,face:%(mono)s,size:%(size)d,bold" % faces)
### Triple quotes
##self.StyleSetSpec(wxSTC_P_TRIPLE, "fore:#603000,face:%(times)s,back:#FFFFE0,size:%(size)d" % faces)
### Triple double quotes
##self.StyleSetSpec(wxSTC_P_TRIPLEDOUBLE, "fore:#603000,face:%(times)s,back:#FFFFE0,size:%(size)d" % faces)
### Class name definition
##self.StyleSetSpec(wxSTC_P_CLASSNAME, "fore:#0000FF,face:%(times)s,size:%(size)d,bold" % faces)
### Function or method name definition
##self.StyleSetSpec(wxSTC_P_DEFNAME, "fore:#0000FF,face:%(times)s,size:%(size)d,bold" % faces)
### Operators
##self.StyleSetSpec(wxSTC_P_OPERATOR, "face:%(times)s,size:%(size)d" % faces)
### Identifiers
##self.StyleSetSpec(wxSTC_P_IDENTIFIER, "fore:#000000,face:%(helv)s,size:%(size)d" % faces)
### Comment-blocks
##self.StyleSetSpec(wxSTC_P_COMMENTBLOCK, "fore:#7F7F7F,face:%(times)s,size:%(size)d" % faces)
### End of line where string is not closed
##self.StyleSetSpec(wxSTC_P_STRINGEOL, "fore:#000000,face:%(mono)s,back:#E0C0E0,eol,size:%(size)d" % faces)
##
##self.SetCaretForeground("BLACK")
##
### prototype for registering some images for use in the AutoComplete box.
###self.RegisterImage(1, images.getSmilesBitmap())
#------------ copied and pasted from the wxStyledTextCtrl_2 demo -------------
def OnUpdateUI(self, evt):
# check for matching braces
braceAtCaret = -1
braceOpposite = -1
charBefore = None
caretPos = self.GetCurrentPos()
if caretPos > 0:
charBefore = self.GetCharAt(caretPos - 1)
styleBefore = self.GetStyleAt(caretPos - 1)
# check before
if charBefore and chr(charBefore) in "[]{}()" and styleBefore == wxSTC_P_OPERATOR:
braceAtCaret = caretPos - 1
# check after
if braceAtCaret < 0:
charAfter = self.GetCharAt(caretPos)
styleAfter = self.GetStyleAt(caretPos)
if charAfter and chr(charAfter) in "[]{}()" and styleAfter == wxSTC_P_OPERATOR:
braceAtCaret = caretPos
if braceAtCaret >= 0:
braceOpposite = self.BraceMatch(braceAtCaret)
if braceAtCaret != -1 and braceOpposite == -1:
self.BraceBadLight(braceAtCaret)
else:
self.BraceHighlight(braceAtCaret, braceOpposite)
#pt = self.PointFromPosition(braceOpposite)
#self.Refresh(True, wxRect(pt.x, pt.y, 5,5))
#print pt
#self.Refresh(False)
self.pos_ch(None)
def OnMarginClick(self, evt):
# fold and unfold as needed
if evt.GetMargin() == 2:
lineClicked = self.LineFromPosition(evt.GetPosition())
if self.GetFoldLevel(lineClicked) & wxSTC_FOLDLEVELHEADERFLAG:
if evt.GetShift():
self.SetFoldExpanded(lineClicked, True)
self.Expand(lineClicked, True, True, 1)
elif evt.GetControl():
if self.GetFoldExpanded(lineClicked):
self.SetFoldExpanded(lineClicked, False)
self.Expand(lineClicked, False, True, 0)
else:
self.SetFoldExpanded(lineClicked, True)
self.Expand(lineClicked, True, True, 100)
else:
self.ToggleFold(lineClicked)
def FoldAll(self):
lineCount = self.GetLineCount()
expanding = True
# find out if we are folding or unfolding
for lineNum in range(lineCount):
if self.GetFoldLevel(lineNum) & wxSTC_FOLDLEVELHEADERFLAG:
expanding = not self.GetFoldExpanded(lineNum)
break;
lineNum = 0
while lineNum < lineCount:
level = self.GetFoldLevel(lineNum)
if level & wxSTC_FOLDLEVELHEADERFLAG and \
(level & wxSTC_FOLDLEVELNUMBERMASK) == wxSTC_FOLDLEVELBASE:
if expanding:
self.SetFoldExpanded(lineNum, True)
lineNum = self.Expand(lineNum, True)
lineNum = lineNum - 1
else:
lastChild = self.GetLastChild(lineNum, -1)
self.SetFoldExpanded(lineNum, False)
if lastChild > lineNum:
self.HideLines(lineNum+1, lastChild)
lineNum = lineNum + 1
def Expand(self, line, doExpand, force=False, visLevels=0, level=-1):
lastChild = self.GetLastChild(line, level)
line = line + 1
while line <= lastChild:
if force:
if visLevels > 0:
self.ShowLines(line, line)
else:
self.HideLines(line, line)
else:
if doExpand:
self.ShowLines(line, line)
if level == -1:
level = self.GetFoldLevel(line)
if level & wxSTC_FOLDLEVELHEADERFLAG:
if force:
if visLevels > 1:
self.SetFoldExpanded(line, True)
else:
self.SetFoldExpanded(line, False)
line = self.Expand(line, doExpand, force, visLevels-1)
else:
if doExpand and self.GetFoldExpanded(line):
line = self.Expand(line, True, force, visLevels-1)
else:
line = self.Expand(line, False, force, visLevels-1)
else:
line = line + 1;
return line
#-------------- end of copied code from wxStyledTextCtrl_2 demo --------------
#(really I copied a lot more, but that part I didn't modify at all, I
#wanted to understand it, but it just worked, so there was no need)
#----------------------------- from Paul McNett ------------------------------
def OnNeedShown(self, evt):
""" Called when the user deletes a hidden header line."""
# We expand the previously folded text, but it may be better
# to delete the text instead, since the user asked for it.
# There are two bits of information in the event; the position
# and the length. I think we could easily clear the text based
# on this information, but for now I'll keep it just displaying
# the previously hidden text. --pkm 2006-04-04.
o = evt.GetEventObject()
position = evt.GetPosition()
## length = evt.GetLength()
line = o.LineFromPosition(position)
o.Expand(line, True)
#-------------------------- Transforms Menu Methods --------------------------
def OnWrap(self, e):
valu = self.root.getInt('Wrap to how many columns?', '', col_line)
self.MakeDirty()
self.SelectLines(1)
x,y = self.GetSelection()
if x==y:
return
print repr(self.GetSelectedText())
lnstart = self.LineFromPosition(x)
lnend = self.LineFromPosition(y-1)
paragraphs = []
lines = []
for ln in xrange(lnstart, lnend+1):
lin = self.GetLine(ln)
if not lin.strip():
if lines:
paragraphs.append(self.format.join(textwrap.wrap(' '.join(lines), valu)))
paragraphs.append(lin.rstrip('\r\n'))
lines = []
else:
lines.append(lin.strip())
if lines:
paragraphs.append(self.format.join(textwrap.wrap(' '.join(lines), valu)))
paragraphs.append('')
self.ReplaceSelection(self.format.join(paragraphs))
def Dent(self, e, incr):
incr *= self.GetIndent()
x,y = self.GetSelection()
if x==y:
lnstart = self.GetCurrentLine()
lnend = lnstart
if incr < 0:
a = self.GetLineIndentation(lnstart)%(abs(incr))
if a:
incr = -a
pos = self.GetCurrentPos()
col = self.GetColumn(pos)
linestart = pos-col
a = max(linestart+col+incr, linestart)
else:
lnstart = self.LineFromPosition(x)
lnend = self.LineFromPosition(y-1)
self.BeginUndoAction()
try:
for ln in xrange(lnstart, lnend+1):
count = self.GetLineIndentation(ln)
m = (count+incr)
m += cmp(0, incr)*(m%incr)
m = max(m, 0)
self.SetLineIndentation(ln, m)
if x==y:
pos = pos + (m-count) - min(0, col + (m-count))
self.SetSelection(pos, pos)
else:
p = 0
if lnstart != 0:
p = self.GetLineEndPosition(lnstart-1) + len(self.format)
self.SetSelection(p, self.GetLineEndPosition(lnend))
finally:
self.EndUndoAction()
def OnIndent(self, e):
self.Dent(e, 1)
def OnDedent(self, e):
self.Dent(e, -1)
def OnInsertComment(self, e):
dlg = wxTextEntryDialog(self, '', 'Enter a comment.', '')
resp = dlg.ShowModal()
valu = dlg.GetValue()
dlg.Destroy()
if resp != wxID_OK:
raise cancelled
_lexer = self.GetLexer()
k = len(valu)
d = ''
if _lexer == wxSTC_LEX_CPP:
c = '/*'
d = '*/'
elif _lexer in (wxSTC_LEX_HTML, wxSTC_LEX_XML):
c = '<!-- '
d = ' -->'
elif _lexer == wxSTC_LEX_LATEX:
c = '%'
else:
c = '#'
a = self.GetEdgeColumn() - len(c) - len(d) - 2 - k
b = a*'-'
st = '%s%s %s %s%s%s'%(c, b[:a/2], valu, b[a/2:], d, self.format)
lin = self.GetCurrentLine()
if lin>0:
self.InsertText(self.GetLineEndPosition(lin-1)+len(self.format), st)
else:
self.InsertText(0, st)
self.MakeDirty()
def OnCommentSelection(self, e):
sel = self.GetSelection()
start = self.LineFromPosition(sel[0])
end = self.LineFromPosition(sel[1])
if end > start and self.GetColumn(sel[1]) == 0:
end = end - 1
self.MakeDirty()
self.BeginUndoAction()
try:
_lexer = self.GetLexer()
for lineNumber in range(start, end + 1):
firstChar = self.GetLineIndentPosition(lineNumber)
lastChar = self.GetLineEndPosition(lineNumber)
ranga = self.GetTextRange(firstChar,lastChar)
if len(ranga.strip()) != 0:
if _lexer == wxSTC_LEX_CPP:
self.InsertText(firstChar, '// ')
elif self.GetLexer() in (wxSTC_LEX_HTML, wxSTC_LEX_XML):
self.InsertText(lastChar, ' -->')
self.InsertText(firstChar, '<!-- ')
elif _lexer == wxSTC_LEX_LATEX:
self.InsertText(firstChar, '%')
else:
self.InsertText(firstChar, '## ')
self.SetCurrentPos(self.PositionFromLine(start))
self.SetAnchor(self.GetLineEndPosition(end))
finally:
self.EndUndoAction()
def OnUncommentSelection(self, e):
sel = self.GetSelection()
start = self.LineFromPosition(sel[0])
end = self.LineFromPosition(sel[1])
if end > start and self.GetColumn(sel[1]) == 0:
end = end - 1
self.MakeDirty()
self.BeginUndoAction()
try:
_lexer = self.GetLexer()
for lineNumber in range(start, end + 1):
firstChar = self.GetLineIndentPosition(lineNumber)
lastChar = self.GetLineEndPosition(lineNumber)
texta = self.GetTextRange(firstChar,lastChar)
lengtha = 0
rangeb = None
if len(texta.strip()) != 0:
if _lexer == wxSTC_LEX_CPP:
if texta.startswith('// '):
lengtha = 3
elif texta.startswith('//'):
lengtha = 2
elif self.GetLexer() in (wxSTC_LEX_HTML, wxSTC_LEX_XML):
if texta.startswith('<!-- '):
lengtha = 5
elif texta.startswith('<!--'):
lengtha = 4
if lengtha:
if texta.endswith(' -->'):
rangeb = (lastChar-4, lastChar)
elif texta.endswith('-->'):
rangeb = (lastChar-3, lastChar)
elif _lexer == wxSTC_LEX_LATEX:
if texta.startswith('%'):
lengtha = 1
else:
if texta.startswith('## '):
lengtha = 3
elif texta.startswith('##'):
lengtha = 2
elif texta.startswith('#'):
lengtha = 1
if lengtha:
if rangeb:
self.SetSelection(*rangeb)
self.ReplaceSelection("")
self.SetSelection(firstChar,firstChar+lengtha)
self.ReplaceSelection("")
self.SetCurrentPos(self.PositionFromLine(start))
self.SetAnchor(self.GetLineEndPosition(end))
finally:
self.EndUndoAction()
def WrapFE(self, e, tail):
x,y = self.GetSelection()
if x==y:
lnstart = self.GetCurrentLine()
lnend = lnstart
else:
lnstart = self.LineFromPosition(x)
lnend = self.LineFromPosition(y-1)
for linenum in xrange(lnstart, lnend+1):
line = self.GetLine(linenum)
if not line.strip():
continue
x = self.GetLineIndentation(linenum)
break
else:
self.root.SetStatusText("Could not find anything to wrap with try: %s:!"%tail)
return
self.BeginUndoAction()
try:
self.OnIndent(e)
#find the indentation level for the except/finally clause
xp = x+self.GetIndent()
xp -= xp%self.GetIndent()
#get some line and selection information
ss, es = self.GetSelection()
lnstart = self.LineFromPosition(ss)
lnend = self.LineFromPosition(es)
#insert the except/finally
self.SetSelection(es, es)
self.ReplaceSelection(self.format + tail + ':' + self.format)
self.SetLineIndentation(lnend+1, x)
self.SetLineIndentation(lnend+2, xp)
#insert the try
self.SetSelection(ss, ss)
self.ReplaceSelection('try:' + self.format)
self.SetLineIndentation(lnstart, x)
#relocate the cursor
p = 0
if lnstart != 0:
p = self.GetLineEndPosition(lnstart-1) + len(self.format)
self.SetSelection(p, self.GetLineEndPosition(lnend+3))
finally:
self.EndUndoAction()
def WrapFinally(self, e):
self.WrapFE(e, 'finally')
def WrapExcept(self, e):
self.WrapFE(e, 'except')
def WrapExceptFinally(self, e):
self.BeginUndoAction()
try:
self.WrapFE(e, 'except')
self.WrapFE(e, 'finally')
finally:
self.EndUndoAction()
def OnTriggerExpansion(self, e):
self.added(None)
def style(self):
return lexer2lang[self.GetLexer()]
def _autoindent(self, ignore=None):
if self.recording:
self.macro.append((None, 0, '_autoindent'))
#will indent the current line to be equivalent to the line above
#unless a language-specific indent cue is present
#get information about the current cursor position
linenum = self.GetCurrentLine()
pos = self.GetCurrentPos()
col = self.GetColumn(pos)
linestart = self.PositionFromLine(linenum)
line = self.GetLine(linenum)[:pos-linestart]
#get info about the current line's indentation
ind = self.GetLineIndentation(linenum)
xtra = 0
lang = self.style()
if col <= ind:
xtra = None
if self.GetUseTabs():
self.ReplaceSelection(self.format+(col*' ').replace(self.GetTabWidth()*' ', '\t'))
else:
self.ReplaceSelection(self.format+(col*' '))
elif not pos:
xtra = None
self.ReplaceSelection(self.format)
elif lang == 'cpp':
## print "indent on return for cpp"
dmap = {'{':1, '}':2}
first = None
x = [0,0,0]
for ch in line:
y = dmap.get(ch, 0)
x[y] += 1
if not first and y:
first=y
x[2] -= first==2
xtra = x[1]-x[2]
if line.split()[:1] == ['return']:
xtra -= 1
elif lang in ('xml', 'html'):
## print "trying", lang
ls = line.split('<')
for i in xrange(len(ls)-1, -1, -1):
lsi = ls[i]
lsis = lsi.strip()
lsil = lsi.lower()
c = 0
for i in no_ends:
if lsil.startswith(i):
c = 1
break
if c:
continue
if '/>' in lsi or '/ >' in lsi:
continue
elif lsi[:1] == '/':
xtra -= 1
elif lsis:
xtra += 1
#we are limiting ourselves to 1 indent/dedent per step
xtra = min(max(xtra, -1), 1)
elif lang == 'tex':
## print "trying", lang, line.strip()
if line.lstrip().startswith('\\begin'):
xtra = 1
#end doesn't make sense, as it should be on the same indent level
#as the begin.
## elif line.lstrip()[:4] == '\\end':
## xtra = -1
#insert other indentation per language here.
else: #if language is python
## print "indent on return for python"
colon = ord(':')
if (line.find(':')>-1):
for i in xrange(linestart, min(pos, self.GetTextLength())):
styl = self.GetStyleAt(i)
#print styl, self.GetCharAt(i)
if not xtra:
if (styl==10) and (self.GetCharAt(i) == colon):
xtra = 1
elif (styl == 1):
#it is a comment, ignore the character
pass
elif (styl == 0) and (self.GetCharAt(i) in [ord(i) for i in ' \t\r\n']):
#is not a comment, but is the space before a comment
#or the end of a line, ignore the character
pass
else:
#this is not a comment or some innocuous other character
#this is a docstring or otherwise, no additional indent
xtra = 0
#commenting the break fixes stuff like this
# for i in blah[:]:
#break
if xtra:
#This deals with ending single and multi-line definitions properly.
while linenum >= 0:
found = []
for i in ['def', 'class', 'if', 'else', 'elif', 'while',
'for', 'try', 'except', 'finally', 'with', 'cdef']:
a = line.find(i)
if (a > -1):
found.append(a)
#print 'fnd', found
if found: found = min(found)
else: found = -1
if (found > -1) and\
(self.GetStyleAt(self.GetLineEndPosition(linenum)-len(line)+found)==5) and\
(self.GetLineIndentation(linenum) == found):
ind = self.GetLineIndentation(linenum)
break
linenum -= 1
line = self.GetLine(linenum)
#if we were to do indentation for ()[]{}, it would be here
if not xtra:
#yep, right here.
fnd = 0
for i in "(){}[]":
if (line.find(i) > -1):
fnd = 1
break
if fnd:
seq = []
#print "finding stuff"
for i in "(){}[]":
a = line.find(i)
start = 0
while a > -1:
start += a+1
if self.GetStyleAt(start+linestart-1)==10:
seq.append((start, i))
a = line[start:].find(i)
seq.sort()
cl = {')':'(', ']': '[', '}': '{',
'(':'', '[': '', '{': ''}
stk = []
#print "making tree"
for po, ch in seq:
#print ch,
if not cl[ch]:
#standard opening
stk.append((po, ch))
elif stk:
if cl[ch] == stk[-1][1]:
#proper closing of something
stk.pop()
else:
#probably a syntax error
#does it matter what is done?
stk = []
break
else:
#Probably closing something on another line, should probably find
#the indent level of the opening, but that would require checking
#multiple previous items for the opening item.
#single-line dedent.
stk = []
break
if stk:
#print "stack remaining", stk
ind = stk[-1][0]
if not xtra:
ls = line.lstrip()
if (ls[:6] == 'return') or (ls[:4] == 'pass') or (ls[:5] == 'break') or (ls[:8] == 'continue'):
xtra = -1
if xtra != None:
a = max(ind+xtra*self.GetIndent(), 0)*' '
if self.GetUseTabs():
a = a.replace(self.GetTabWidth()*' ', '\t')
## self._tdisable(self.ReplaceSelection, self.format+a)
self.ReplaceSelection(self.format+a)
def OnSelectToggle(self, e):
if self.selep is None:
self.selep = self.GetCurrentPos()
else:
self.SetAnchor(self.selep)
self.selep = None
def _AddTextWAttr(self, start, end, text, attr):
## attr = attr % 3
self.SetTargetStart(start)
self.SetTargetEnd(end)
self.ReplaceTarget(text)
self.StartStyling(start, wxSTC_INDIC0_MASK)
self.SetStyling(len(text), wxSTC_INDIC0_MASK)
self.IndicatorSetStyle(wxSTC_INDIC0_MASK, wx.stc.STC_INDIC_BOX)
self.IndicatorSetForeground(wxSTC_INDIC0_MASK, wx.RED)
class FileDropTarget(wxFileDropTarget):
def __init__(self, root):
wxFileDropTarget.__init__(self)
self.root = root
def OnDropFiles(self, x, y, filenames):
self.root.OnDrop(filenames)
class TextDropTarget(wxTextDropTarget):
def __init__(self, parent):
wxTextDropTarget.__init__(self)
self.parent = parent
def OnDropText(self, x, y, text):
self.parent.OnDropText(text)
#This is so that you can keep your document unchanged while adding
#code snippets.
return False
class SplitterWindow(wxSplitterWindow):
if 1:
swap = 0
def SplitVertically(self, win1, win2, sashPosition=0, swap=0):
self.swap = swap
if swap:
win1, win2, sashPosition = win2, win1, -sashPosition
wxSplitterWindow.SplitVertically(self, win1, win2, sashPosition)
def SplitHorizontally(self, win1, win2, sashPosition=0, swap=0):
self.swap = swap
if swap:
win1, win2, sashPosition = win2, win1, -sashPosition
wxSplitterWindow.SplitHorizontally(self, win1, win2, sashPosition)
def Unsplit(self, which=None):
if which is None:
which = self.GetWindow2()
wxSplitterWindow.Unsplit(self, which)
self.swap = 0
def GetWindow1(self):
if self.IsSplit() and self.swap:
x = wxSplitterWindow.GetWindow2(self)
else:
x = wxSplitterWindow.GetWindow1(self)
return x
def GetWindow2(self):
if self.IsSplit() and self.swap:
x = wxSplitterWindow.GetWindow1(self)
else:
x = wxSplitterWindow.GetWindow2(self)
return x
def SetSashPosition(self, position, redraw = 1):
if self.swap:
position = -position
return wxSplitterWindow.SetSashPosition(self, position, redraw)
VS = wx.VERSION_STRING
def main():
docs = [os.path.abspath(os.path.join(current_path, i))
for i in sys.argv[1:]]
if single_instance.send_documents(docs):
return
global IMGLIST1, IMGLIST2, root, app
app = wxPySimpleApp()
IMGLIST1 = wxImageList(16, 16)
IMGLIST2 = wxImageList(16, 16)
for il in (IMGLIST1, IMGLIST2):
for icf in ('icons/blank.ico', 'icons/py.ico'):
icf = os.path.join(runpath, icf)
img = wxImageFromBitmap(wxBitmap(icf))
img.Rescale(16,16)
bmp = wxBitmapFromImage(img)
il.AddIcon(wxIconFromBitmap(bmp))
opn=0
if len(sys.argv)>1 and ('--last' in sys.argv):
opn=1
filehistory.root = root = app.frame = MainWindow(None, -1, "PyPE", docs)
root.updateWindowTitle()
app.SetTopWindow(app.frame)
app.frame.Show(1)
if opn:
app.frame.OnOpenPrevDocs(None)
app.frame.SendSizeEvent()
app.MainLoop()
if __name__ == '__main__':
main()