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 4246 4247 4248 4249 4250 4251 4252 4253 4254 4255 4256 4257 4258 4259 4260 4261 4262 4263 4264 4265 4266 4267 4268 4269 4270 4271 4272 4273 4274 4275 4276 4277 4278 4279 4280 4281 4282 4283 4284 4285 4286 4287 4288 4289 4290 4291 4292 4293 4294 4295 4296 4297 4298 4299 4300 4301 4302 4303 4304 4305 4306 4307 4308 4309 4310 4311 4312 4313 4314 4315 4316 4317 4318 4319 4320 4321 4322 4323 4324 4325 4326 4327 4328 4329 4330 4331 4332 4333 4334 4335 4336 4337 4338 4339 4340 4341 4342 4343 4344 4345 4346 4347 4348 4349 4350 4351 4352 4353 4354 4355 4356 4357 4358 4359 4360 4361 4362 4363 4364 4365 4366 4367 4368 4369 4370 4371 4372 4373 4374 4375 4376 4377 4378 4379 4380 4381 4382 4383 4384 4385 4386 4387 4388 4389 4390 4391 4392 4393 4394 4395 4396 4397 4398 4399 4400 4401 4402 4403 4404 4405 4406 4407 4408 4409 4410 4411 4412 4413 4414 4415 4416 4417 4418 4419 4420 4421 4422 4423 4424 4425 4426 4427 4428 4429 4430 4431 4432 4433 4434 4435 4436 4437 4438 4439 4440 4441 4442 4443 4444 4445 4446 4447 4448 4449 4450 4451 4452 4453 4454 4455 4456 4457 4458 4459 4460 4461 4462 4463 4464 4465 4466 4467 4468 4469 4470 4471 4472 4473 4474 4475 4476 4477 4478 4479 4480 4481 4482 4483 4484 4485 4486 4487 4488 4489 4490 4491 4492 4493 4494 4495 4496 4497 4498 4499 4500 4501 4502 4503 4504 4505 4506 4507 4508 4509 4510 4511 4512 4513 4514 4515 4516 4517 4518 4519 4520 4521 4522 4523 4524 4525 4526 4527 4528 4529 4530 4531 4532 4533 4534 4535 4536 4537 4538 4539 4540 4541 4542 4543 4544 4545 4546 4547 4548 4549 4550 4551 4552 4553 4554 4555 4556 4557 4558 4559 4560 4561 4562 4563 4564 4565 4566 4567 4568 4569 4570 4571 4572 4573 4574 4575 4576 4577 4578 4579 4580 4581 4582 4583 4584 4585 4586 4587 4588 4589 4590 4591 4592 4593 4594 4595 4596 4597 4598 4599 4600 4601 4602 4603 4604 4605 4606 4607 4608 4609 4610 4611 4612 4613 4614 4615 4616 4617 4618 4619 4620 4621 4622 4623 4624 4625 4626 4627 4628 4629 4630 4631 4632 4633 4634 4635 4636 4637 4638 4639 4640 4641 4642 4643 4644 4645 4646 4647 4648 4649 4650 4651 4652 4653 4654 4655 4656 4657 4658 4659 4660 4661 4662 4663 4664 4665 4666 4667 4668 4669 4670 4671 4672 4673 4674 4675 4676 4677 4678 4679 4680 4681 4682 4683 4684 4685 4686 4687 4688 4689 4690 4691 4692 4693 4694 4695 4696 4697 4698 4699 4700 4701 4702 4703 4704 4705 4706 4707 4708 4709 4710 4711 4712 4713 4714 4715 4716 4717 4718 4719 4720 4721 4722 4723 4724 4725 4726 4727 4728 4729 4730 4731 4732 4733 4734 4735 4736 4737 4738 4739 4740 4741 4742 4743 4744 4745 4746 4747 4748 4749 4750 4751 4752 4753 4754 4755 4756 4757 4758 4759 4760 4761 4762 4763 4764 4765 4766 4767 4768 4769 4770 4771 4772 4773 4774 4775 4776 4777 4778 4779 4780 4781 4782 4783 4784 4785 4786 4787 4788 4789 4790 4791 4792 4793 4794 4795 4796 4797 4798 4799 4800 4801 4802 4803 4804 4805 4806 4807 4808 4809 4810 4811 4812 4813 4814 4815 4816 4817 4818 4819 4820 4821 4822 4823 4824 4825 4826 4827 4828 4829 4830 4831 4832 4833 4834 4835 4836 4837 4838 4839 4840 4841 4842 4843 4844 4845 4846 4847 4848 4849 4850 4851 4852 4853 4854 4855 4856 4857 4858 4859 4860 4861 4862 4863 4864 4865 4866 4867 4868 4869 4870 4871 4872 4873 4874 4875 4876 4877 4878 4879 4880 4881 4882 4883 4884 4885 4886 4887 4888 4889 4890 4891 4892 4893 4894 4895 4896 4897 4898 4899 4900 4901 4902 4903 4904 4905 4906 4907 4908 4909 4910 4911 4912 4913 4914 4915 4916 4917 4918 4919 4920 4921 4922 4923 4924 4925 4926 4927 4928 4929 4930 4931 4932 4933 4934 4935 4936 4937 4938 4939 4940 4941 4942 4943 4944 4945 4946 4947 4948 4949 4950 4951 4952 4953 4954 4955 4956 4957 4958 4959 4960 4961 4962 4963 4964 4965 4966 4967 4968 4969 4970 4971 4972 4973 4974 4975 4976 4977 4978 4979 4980 4981 4982 4983 4984 4985 4986 4987 4988 4989 4990 4991 4992 4993 4994 4995 4996 4997 4998 4999 5000 5001 5002 5003 5004 5005 5006 5007 5008 5009 5010 5011 5012 5013 5014 5015 5016 5017 5018 5019 5020 5021 5022 5023 5024 5025 5026 5027 5028 5029 5030 5031 5032 5033 5034 5035 5036 5037 5038 5039 5040 5041 5042 5043 5044 5045 5046 5047 5048 5049 5050 5051 5052 5053 5054 5055 5056 5057 5058 5059 5060 5061 5062 5063 5064 5065 5066 5067 5068 5069 5070 5071 5072 5073 5074 5075 5076 5077 5078 5079 5080 5081 5082 5083 5084 5085 5086 5087 5088 5089 5090 5091 5092 5093 5094 5095 5096 5097 5098 5099 5100 5101 5102 5103 5104 5105 5106 5107 5108 5109 5110 5111 5112 5113 5114 5115 5116 5117 5118 5119 5120 5121 5122 5123 5124 5125 5126 5127 5128 5129 5130 5131 5132 5133 5134 5135 5136 5137 5138 5139 5140 5141 5142 5143 5144 5145 5146 5147 5148 5149 5150 5151 5152 5153 5154 5155 5156 5157 5158 5159 5160 5161 5162 5163 5164 5165 5166 5167 5168 5169 5170 5171 5172 5173 5174 5175 5176 5177 5178 5179 5180 5181 5182 5183 5184 5185 5186 5187 5188 5189 5190 5191 5192 5193 5194 5195 5196 5197 5198 5199 5200 5201 5202 5203 5204 5205 5206 5207 5208 5209 5210 5211 5212 5213 5214 5215 5216 5217 5218 5219 5220 5221 5222 5223 5224 5225 5226 5227 5228 5229 5230 5231 5232 5233 5234 5235 5236 5237 5238 5239 5240 5241 5242 5243 5244 5245 5246 5247 5248 5249 5250 5251 5252 5253 5254 5255 5256 5257 5258 5259 5260 5261 5262 5263 5264 5265 5266 5267 5268 5269 5270 5271 5272 5273 5274 5275 5276 5277 5278 5279 5280 5281 5282 5283 5284 5285 5286 5287 5288 5289 5290 5291 5292 5293 5294 5295 5296 5297 5298 5299 5300 5301 5302 5303 5304 5305 5306 5307 5308 5309 5310 5311 5312 5313 5314 5315 5316 5317 5318 5319 5320 5321 5322 5323 5324 5325 5326 5327 5328 5329 5330 5331 5332 5333 5334 5335 5336 5337 5338 5339 5340 5341 5342 5343 5344 5345 5346 5347 5348 5349 5350 5351 5352 5353 5354 5355 5356 5357 5358 5359 5360 5361 5362 5363 5364 5365 5366 5367 5368 5369 5370 5371 5372 5373 5374 5375 5376 5377 5378 5379 5380 5381 5382 5383 5384 5385 5386 5387 5388 5389 5390 5391 5392 5393 5394 5395 5396 5397 5398 5399 5400 5401 5402 5403 5404 5405 5406 5407 5408 5409 5410 5411 5412 5413 5414 5415 5416 5417 5418 5419 5420 5421 5422 5423 5424 5425 5426 5427 5428 5429 5430 5431 5432 5433 5434 5435 5436 5437 5438 5439 5440 5441 5442 5443 5444 5445 5446 5447 5448 5449 5450 5451 5452 5453 5454 5455 5456 5457 5458 5459 5460 5461 5462 5463 5464 5465 5466 5467 5468 5469 5470 5471 5472 5473 5474 5475 5476 5477 5478 5479 5480 5481 5482 5483 5484 5485 5486 5487 5488 5489 5490 5491 5492 5493 5494 5495 5496 5497 5498 5499 5500 5501 5502 5503 5504 5505 5506 5507 5508 5509 5510 5511 5512 5513 5514 5515 5516 5517 5518 5519 5520 5521 5522 5523 5524 5525 5526 5527 5528 5529 5530 5531 5532 5533 5534 5535 5536 5537 5538 5539 5540 5541 5542 5543 5544 5545 5546 5547 5548 5549 5550 5551 5552 5553 5554 5555 5556 5557 5558 5559 5560 5561 5562 5563 5564 5565 5566 5567 5568 5569 5570 5571 5572 5573 5574 5575 5576 5577 5578 5579 5580 5581 5582 5583 5584 5585 5586 5587 5588 5589 5590 5591 5592 5593 5594 5595 5596 5597 5598 5599 5600 5601 5602 5603 5604 5605 5606 5607 5608 5609 5610 5611 5612 5613 5614 5615 5616 5617 5618 5619 5620 5621 5622 5623 5624 5625 5626 5627 5628 5629 5630 5631 5632 5633 5634 5635 5636 5637 5638 5639 5640 5641 5642 5643 5644 5645 5646 5647 5648 5649 5650 5651 5652 5653 5654 5655 5656 5657 5658 5659 5660 5661 5662 5663 5664 5665 5666 5667 5668 5669 5670 5671 5672 5673 5674 5675 5676 5677 5678 5679 5680 5681 5682 5683 5684 5685 5686 5687 5688 5689 5690 5691 5692 5693 5694 5695 5696 5697 5698 5699 5700 5701 5702 5703 5704 5705 5706 5707 5708 5709 5710 5711 5712 5713 5714 5715 5716 5717 5718 5719 5720 5721 5722 5723 5724 5725 5726 5727 5728 5729 5730 5731 5732 5733 5734 5735 5736 5737 5738 5739 5740 5741 5742 5743 5744 5745 5746 5747 5748 5749 5750 5751 5752 5753 5754 5755 5756 5757 5758 5759 5760 5761 5762 5763 5764 5765 5766 5767 5768 5769 5770 5771 5772 5773 5774 5775 5776 5777 5778 5779 5780 5781 5782 5783 5784 5785 5786 5787 5788 5789 5790 5791 5792 5793 5794 5795 5796 5797 5798 5799 5800 5801 5802 5803 5804 5805 5806 5807 5808 5809 5810 5811 5812 5813 5814 5815 5816 5817 5818 5819 5820 5821 5822 5823 5824 5825 5826 5827 5828 5829 5830 5831 5832 5833 5834 5835 5836 5837 5838 5839 5840 5841 5842 5843 5844 5845 5846 5847 5848 5849 5850 5851 5852 5853 5854 5855 5856 5857 5858 5859 5860 5861 5862 5863 5864 5865 5866 5867 5868 5869 5870 5871 5872 5873 5874 5875 5876 5877 5878 5879 5880 5881 5882 5883 5884 5885 5886 5887 5888 5889 5890 5891 5892 5893 5894 5895 5896 5897 5898 5899 5900 5901 5902 5903 5904 5905 5906 5907 5908 5909 5910 5911 5912 5913 5914 5915 5916 5917 5918 5919 5920 5921 5922 5923 5924 5925 5926 5927 5928 5929 5930 5931 5932 5933 5934 5935 5936 5937 5938 5939 5940 5941 5942 5943 5944 5945 5946 5947 5948 5949 5950 5951 5952 5953 5954 5955 5956 5957 5958 5959 5960 5961 5962 5963 5964 5965 5966 5967 5968 5969 5970 5971 5972 5973 5974 5975 5976 5977 5978 5979 5980 5981 5982 5983 5984 5985 5986 5987 5988 5989 5990 5991 5992 5993 5994 5995 5996 5997 5998 5999 6000 6001 6002 6003 6004 6005 6006 6007 6008 6009 6010 6011 6012 6013 6014 6015 6016 6017 6018 6019 6020 6021 6022 6023 6024 6025 6026 6027 6028 6029 6030 6031 6032 6033 6034 6035 6036 6037 6038 6039 6040 6041 6042 6043 6044 6045 6046 6047 6048 6049 6050 6051 6052 6053 6054 6055 6056 6057 6058 6059 6060 6061 6062 6063 6064 6065 6066 6067 6068 6069 6070 6071 6072 6073 6074 6075 6076
|
"""
`auibook.py` contains a notebook control which implements many features common in
applications with dockable panes. Specifically, :class:`AuiNotebook` implements functionality
which allows the user to rearrange tab order via drag-and-drop, split the tab window
into many different splitter configurations, and toggle through different themes to
customize the control's look and feel.
An effort has been made to try to maintain an API as similar to that of :class:`Notebook`.
The default theme that is used is :class:`~lib.agw.aui.tabart.AuiDefaultTabArt`, which provides a modern, glossy
look and feel. The theme can be changed by calling :meth:`AuiNotebook.SetArtProvider() <AuiNotebook.SetArtProvider>`.
"""
__author__ = "Andrea Gavana <andrea.gavana@gmail.com>"
__date__ = "31 March 2009"
import wx
import types
import datetime
from wx.lib.expando import ExpandoTextCtrl
import framemanager
import tabart as TA
from aui_utilities import LightColour, MakeDisabledBitmap, TabDragImage
from aui_utilities import TakeScreenShot, RescaleScreenShot
from aui_constants import *
# AuiNotebook events
wxEVT_COMMAND_AUINOTEBOOK_PAGE_CLOSE = wx.NewEventType()
wxEVT_COMMAND_AUINOTEBOOK_PAGE_CLOSED = wx.NewEventType()
wxEVT_COMMAND_AUINOTEBOOK_PAGE_CHANGED = wx.NewEventType()
wxEVT_COMMAND_AUINOTEBOOK_PAGE_CHANGING = wx.NewEventType()
wxEVT_COMMAND_AUINOTEBOOK_BUTTON = wx.NewEventType()
wxEVT_COMMAND_AUINOTEBOOK_BEGIN_DRAG = wx.NewEventType()
wxEVT_COMMAND_AUINOTEBOOK_END_DRAG = wx.NewEventType()
wxEVT_COMMAND_AUINOTEBOOK_DRAG_MOTION = wx.NewEventType()
wxEVT_COMMAND_AUINOTEBOOK_ALLOW_DND = wx.NewEventType()
wxEVT_COMMAND_AUINOTEBOOK_DRAG_DONE = wx.NewEventType()
wxEVT_COMMAND_AUINOTEBOOK_TAB_LEFT_UP = wx.NewEventType()
wxEVT_COMMAND_AUINOTEBOOK_TAB_MIDDLE_DOWN = wx.NewEventType()
wxEVT_COMMAND_AUINOTEBOOK_TAB_MIDDLE_UP = wx.NewEventType()
wxEVT_COMMAND_AUINOTEBOOK_TAB_RIGHT_DOWN = wx.NewEventType()
wxEVT_COMMAND_AUINOTEBOOK_TAB_RIGHT_UP = wx.NewEventType()
wxEVT_COMMAND_AUINOTEBOOK_TAB_DCLICK = wx.NewEventType()
wxEVT_COMMAND_AUINOTEBOOK_BG_LEFT_UP = wx.NewEventType()
wxEVT_COMMAND_AUINOTEBOOK_BG_MIDDLE_DOWN = wx.NewEventType()
wxEVT_COMMAND_AUINOTEBOOK_BG_MIDDLE_UP = wx.NewEventType()
wxEVT_COMMAND_AUINOTEBOOK_BG_RIGHT_DOWN = wx.NewEventType()
wxEVT_COMMAND_AUINOTEBOOK_BG_RIGHT_UP = wx.NewEventType()
wxEVT_COMMAND_AUINOTEBOOK_BG_DCLICK = wx.NewEventType()
# Define a new event for a drag cancelled
wxEVT_COMMAND_AUINOTEBOOK_CANCEL_DRAG = wx.NewEventType()
# Define events for editing a tab label
wxEVT_COMMAND_AUINOTEBOOK_BEGIN_LABEL_EDIT = wx.NewEventType()
wxEVT_COMMAND_AUINOTEBOOK_END_LABEL_EDIT = wx.NewEventType()
# Create event binders
EVT_AUINOTEBOOK_PAGE_CLOSE = wx.PyEventBinder(wxEVT_COMMAND_AUINOTEBOOK_PAGE_CLOSE, 1)
""" A tab in `AuiNotebook` is being closed. Can be vetoed by calling `Veto()`. """
EVT_AUINOTEBOOK_PAGE_CLOSED = wx.PyEventBinder(wxEVT_COMMAND_AUINOTEBOOK_PAGE_CLOSED, 1)
""" A tab in `AuiNotebook` has been closed. """
EVT_AUINOTEBOOK_PAGE_CHANGED = wx.PyEventBinder(wxEVT_COMMAND_AUINOTEBOOK_PAGE_CHANGED, 1)
""" The page selection was changed. """
EVT_AUINOTEBOOK_PAGE_CHANGING = wx.PyEventBinder(wxEVT_COMMAND_AUINOTEBOOK_PAGE_CHANGING, 1)
""" The page selection is being changed. """
EVT_AUINOTEBOOK_BUTTON = wx.PyEventBinder(wxEVT_COMMAND_AUINOTEBOOK_BUTTON, 1)
""" The user clicked on a button in the `AuiNotebook` tab area. """
EVT_AUINOTEBOOK_BEGIN_DRAG = wx.PyEventBinder(wxEVT_COMMAND_AUINOTEBOOK_BEGIN_DRAG, 1)
""" A drag-and-drop operation on a notebook tab has started. """
EVT_AUINOTEBOOK_END_DRAG = wx.PyEventBinder(wxEVT_COMMAND_AUINOTEBOOK_END_DRAG, 1)
""" A drag-and-drop operation on a notebook tab has finished. """
EVT_AUINOTEBOOK_DRAG_MOTION = wx.PyEventBinder(wxEVT_COMMAND_AUINOTEBOOK_DRAG_MOTION, 1)
""" A drag-and-drop operation on a notebook tab is ongoing. """
EVT_AUINOTEBOOK_ALLOW_DND = wx.PyEventBinder(wxEVT_COMMAND_AUINOTEBOOK_ALLOW_DND, 1)
""" Fires an event asking if it is OK to drag and drop a tab. """
EVT_AUINOTEBOOK_DRAG_DONE = wx.PyEventBinder(wxEVT_COMMAND_AUINOTEBOOK_DRAG_DONE, 1)
""" A drag-and-drop operation on a notebook tab has finished. """
EVT_AUINOTEBOOK_TAB_LEFT_UP = wx.PyEventBinder(wxEVT_COMMAND_AUINOTEBOOK_TAB_LEFT_UP, 1)
""" The user clicked with the left mouse button on a tab. """
EVT_AUINOTEBOOK_TAB_MIDDLE_DOWN = wx.PyEventBinder(wxEVT_COMMAND_AUINOTEBOOK_TAB_MIDDLE_DOWN, 1)
""" The user clicked with the middle mouse button on a tab. """
EVT_AUINOTEBOOK_TAB_MIDDLE_UP = wx.PyEventBinder(wxEVT_COMMAND_AUINOTEBOOK_TAB_MIDDLE_UP, 1)
""" The user clicked with the middle mouse button on a tab. """
EVT_AUINOTEBOOK_TAB_RIGHT_DOWN = wx.PyEventBinder(wxEVT_COMMAND_AUINOTEBOOK_TAB_RIGHT_DOWN, 1)
""" The user clicked with the right mouse button on a tab. """
EVT_AUINOTEBOOK_TAB_RIGHT_UP = wx.PyEventBinder(wxEVT_COMMAND_AUINOTEBOOK_TAB_RIGHT_UP, 1)
""" The user clicked with the right mouse button on a tab. """
EVT_AUINOTEBOOK_BG_LEFT_UP = wx.PyEventBinder(wxEVT_COMMAND_AUINOTEBOOK_BG_LEFT_UP, 1)
""" The user left-clicked in the tab area but not over a tab or a button. """
EVT_AUINOTEBOOK_BG_MIDDLE_DOWN = wx.PyEventBinder(wxEVT_COMMAND_AUINOTEBOOK_BG_MIDDLE_DOWN, 1)
""" The user middle-clicked in the tab area but not over a tab or a button. """
EVT_AUINOTEBOOK_BG_MIDDLE_UP = wx.PyEventBinder(wxEVT_COMMAND_AUINOTEBOOK_BG_MIDDLE_UP, 1)
""" The user middle-clicked in the tab area but not over a tab or a button. """
EVT_AUINOTEBOOK_BG_RIGHT_DOWN = wx.PyEventBinder(wxEVT_COMMAND_AUINOTEBOOK_BG_RIGHT_DOWN, 1)
""" The user right-clicked in the tab area but not over a tab or a button. """
EVT_AUINOTEBOOK_BG_RIGHT_UP = wx.PyEventBinder(wxEVT_COMMAND_AUINOTEBOOK_BG_RIGHT_UP, 1)
""" The user right-clicked in the tab area but not over a tab or a button. """
EVT_AUINOTEBOOK_BG_DCLICK = wx.PyEventBinder(wxEVT_COMMAND_AUINOTEBOOK_BG_DCLICK, 1)
""" The user left-clicked on the tab area not occupied by `AuiNotebook` tabs. """
EVT_AUINOTEBOOK_CANCEL_DRAG = wx.PyEventBinder(wxEVT_COMMAND_AUINOTEBOOK_CANCEL_DRAG, 1)
""" A drag and drop operation has been cancelled. """
EVT_AUINOTEBOOK_TAB_DCLICK = wx.PyEventBinder(wxEVT_COMMAND_AUINOTEBOOK_TAB_DCLICK, 1)
""" The user double-clicked with the left mouse button on a tab. """
EVT_AUINOTEBOOK_BEGIN_LABEL_EDIT = wx.PyEventBinder(wxEVT_COMMAND_AUINOTEBOOK_BEGIN_LABEL_EDIT, 1)
""" The user double-clicked with the left mouse button on a tab which text is editable. """
EVT_AUINOTEBOOK_END_LABEL_EDIT = wx.PyEventBinder(wxEVT_COMMAND_AUINOTEBOOK_END_LABEL_EDIT, 1)
""" The user finished editing a tab label. """
# -----------------------------------------------------------------------------
# Auxiliary class: TabTextCtrl
# This is the temporary ExpandoTextCtrl created when you edit the text of a tab
# -----------------------------------------------------------------------------
class TabTextCtrl(ExpandoTextCtrl):
""" Control used for in-place edit. """
def __init__(self, owner, tab, page_index):
"""
Default class constructor.
For internal use: do not call it in your code!
:param `owner`: the :class:`AuiNotebook` owning the tab;
:param `tab`: the actual :class:`AuiTabCtrl` tab;
:param integer `page_index`: the :class:`AuiTabContainer` page index for the tab.
"""
self._owner = owner
self._tabEdited = tab
self._pageIndex = page_index
self._startValue = tab.caption
self._finished = False
self._aboutToFinish = False
self._currentValue = self._startValue
x, y, w, h = self._tabEdited.rect
wnd = self._tabEdited.control
if wnd:
x += wnd.GetSize()[0] + 2
h = 0
image_h = 0
image_w = 0
image = tab.bitmap
if image.IsOk():
image_w, image_h = image.GetWidth(), image.GetHeight()
image_w += 6
dc = wx.ClientDC(self._owner)
h = max(image_h, dc.GetMultiLineTextExtent(tab.caption)[1])
h = h + 2
# FIXME: what are all these hardcoded 4, 8 and 11s really?
x += image_w
w -= image_w + 4
y = (self._tabEdited.rect.height - h)/2 + 1
expandoStyle = wx.WANTS_CHARS
if wx.Platform in ["__WXGTK__", "__WXMAC__"]:
expandoStyle |= wx.SIMPLE_BORDER
xSize, ySize = w + 2, h
else:
expandoStyle |= wx.SUNKEN_BORDER
xSize, ySize = w + 2, h+2
ExpandoTextCtrl.__init__(self, self._owner, wx.ID_ANY, self._startValue,
wx.Point(x, y), wx.Size(xSize, ySize),
expandoStyle)
if wx.Platform == "__WXMAC__":
self.SetFont(owner.GetFont())
bs = self.GetBestSize()
self.SetSize((-1, bs.height))
self.Bind(wx.EVT_CHAR, self.OnChar)
self.Bind(wx.EVT_KEY_UP, self.OnKeyUp)
self.Bind(wx.EVT_KILL_FOCUS, self.OnKillFocus)
def AcceptChanges(self):
""" Accepts/refuses the changes made by the user. """
value = self.GetValue()
notebook = self._owner.GetParent()
if value == self._startValue:
# nothing changed, always accept
# when an item remains unchanged, the owner
# needs to be notified that the user decided
# not to change the tree item label, and that
# the edit has been cancelled
notebook.OnRenameCancelled(self._pageIndex)
return True
if not notebook.OnRenameAccept(self._pageIndex, value):
# vetoed by the user
return False
# accepted, do rename the item
notebook.SetPageText(self._pageIndex, value)
return True
def Finish(self):
""" Finish editing. """
if not self._finished:
notebook = self._owner.GetParent()
self._finished = True
self._owner.SetFocus()
notebook.ResetTextControl()
def OnChar(self, event):
"""
Handles the ``wx.EVT_CHAR`` event for :class:`TabTextCtrl`.
:param `event`: a :class:`KeyEvent` event to be processed.
"""
keycode = event.GetKeyCode()
shiftDown = event.ShiftDown()
if keycode == wx.WXK_RETURN:
if shiftDown and self._tabEdited.IsMultiline():
event.Skip()
else:
self._aboutToFinish = True
self.SetValue(self._currentValue)
# Notify the owner about the changes
self.AcceptChanges()
# Even if vetoed, close the control (consistent with MSW)
wx.CallAfter(self.Finish)
elif keycode == wx.WXK_ESCAPE:
self.StopEditing()
else:
event.Skip()
def OnKeyUp(self, event):
"""
Handles the ``wx.EVT_KEY_UP`` event for :class:`TabTextCtrl`.
:param `event`: a :class:`KeyEvent` event to be processed.
"""
if not self._finished:
# auto-grow the textctrl:
mySize = self.GetSize()
dc = wx.ClientDC(self)
sx, sy, dummy = dc.GetMultiLineTextExtent(self.GetValue() + "M")
self.SetSize((sx, -1))
self._currentValue = self.GetValue()
event.Skip()
def OnKillFocus(self, event):
"""
Handles the ``wx.EVT_KILL_FOCUS`` event for :class:`TabTextCtrl`.
:param `event`: a :class:`FocusEvent` event to be processed.
"""
if not self._finished and not self._aboutToFinish:
# We must finish regardless of success, otherwise we'll get
# focus problems:
if not self.AcceptChanges():
self._owner.GetParent().OnRenameCancelled(self._pageIndex)
# We must let the native text control handle focus, too, otherwise
# it could have problems with the cursor (e.g., in wxGTK).
event.Skip()
wx.CallAfter(self._owner.GetParent().ResetTextControl)
def StopEditing(self):
""" Suddenly stops the editing. """
self._owner.GetParent().OnRenameCancelled(self._pageIndex)
self.Finish()
def item(self):
""" Returns the item currently edited. """
return self._tabEdited
# ----------------------------------------------------------------------
class AuiNotebookPage(object):
"""
A simple class which holds information about tab captions, bitmaps and
colours.
"""
def __init__(self):
"""
Default class constructor.
Used internally, do not call it in your code!
"""
self.window = None # page's associated window
self.caption = "" # caption displayed on the tab
self.bitmap = wx.NullBitmap # tab's bitmap
self.dis_bitmap = wx.NullBitmap # tab's disabled bitmap
self.tooltip = "" # tab's tooltip
self.rect = wx.Rect() # tab's hit rectangle
self.active = False # True if the page is currently active
self.enabled = True # True if the page is currently enabled
self.hasCloseButton = True # True if the page has a close button using the style
# AUI_NB_CLOSE_ON_ALL_TABS
self.control = None # A control can now be inside a tab
self.renamable = False # If True, a tab can be renamed by a left double-click
self.text_colour = wx.SystemSettings.GetColour(wx.SYS_COLOUR_BTNTEXT)
self.access_time = datetime.datetime.now() # Last time this page was selected
def IsMultiline(self):
""" Returns whether the tab contains multiline text. """
return "\n" in self.caption
# ----------------------------------------------------------------------
class AuiTabContainerButton(object):
"""
A simple class which holds information about tab buttons and their state.
"""
def __init__(self):
"""
Default class constructor.
Used internally, do not call it in your code!
"""
self.id = -1 # button's id
self.name = ""
self.cur_state = AUI_BUTTON_STATE_NORMAL # current state (normal, hover, pressed, etc.)
self.location = wx.LEFT # buttons location (wxLEFT, wxRIGHT, or wxCENTER)
self.bitmap = wx.NullBitmap # button's hover bitmap
self.dis_bitmap = wx.NullBitmap # button's disabled bitmap
self.rect = wx.Rect() # button's hit rectangle
# ----------------------------------------------------------------------
class CommandNotebookEvent(wx.PyCommandEvent):
""" A specialized command event class for events sent by :class:`AuiNotebook` . """
def __init__(self, command_type=None, win_id=0):
"""
Default class constructor.
:param `command_type`: the event kind or an instance of :class:`PyCommandEvent`.
:param integer `win_id`: the window identification number.
"""
if type(command_type) == types.IntType:
wx.PyCommandEvent.__init__(self, command_type, win_id)
else:
wx.PyCommandEvent.__init__(self, command_type.GetEventType(), command_type.GetId())
self.old_selection = -1
self.selection = -1
self.drag_source = None
self.dispatched = 0
self.label = ""
self.editCancelled = False
self.page = None
def SetSelection(self, s):
"""
Sets the selection member variable.
:param integer `s`: the new selection.
"""
self.selection = s
self._commandInt = s
def GetSelection(self):
""" Returns the currently selected page, or -1 if none was selected. """
return self.selection
def SetOldSelection(self, s):
"""
Sets the id of the page selected before the change.
:param integer `s`: the old selection.
"""
self.old_selection = s
def GetOldSelection(self):
"""
Returns the page that was selected before the change, or -1 if none was
selected.
"""
return self.old_selection
def SetDragSource(self, s):
"""
Sets the drag and drop source.
:param `s`: the drag source.
"""
self.drag_source = s
def GetDragSource(self):
""" Returns the drag and drop source. """
return self.drag_source
def SetDispatched(self, b):
"""
Sets the event as dispatched (used for automatic :class:`AuiNotebook` ).
:param `b`: whether the event was dispatched or not.
"""
self.dispatched = b
def GetDispatched(self):
""" Returns whether the event was dispatched (used for automatic :class:`AuiNotebook` ). """
return self.dispatched
def IsEditCancelled(self):
""" Returns the edit cancel flag (for ``EVT_AUINOTEBOOK_BEGIN`` | ``END_LABEL_EDIT`` only)."""
return self.editCancelled
def SetEditCanceled(self, editCancelled):
"""
Sets the edit cancel flag (for ``EVT_AUINOTEBOOK_BEGIN`` | ``END_LABEL_EDIT`` only).
:param bool `editCancelled`: whether the editing action has been cancelled or not.
"""
self.editCancelled = editCancelled
def GetLabel(self):
"""Returns the label-itemtext (for ``EVT_AUINOTEBOOK_BEGIN`` | ``END_LABEL_EDIT`` only)."""
return self.label
def SetLabel(self, label):
"""
Sets the label. Useful only for ``EVT_AUINOTEBOOK_END_LABEL_EDIT``.
:param string `label`: the new label.
"""
self.label = label
Page = property(lambda self: self.page,
lambda self, page: setattr(self, 'page', page))
Selection = property(lambda self: self.GetSelection(), lambda self, sel: self.SetSelection(sel))
# ----------------------------------------------------------------------
class AuiNotebookEvent(CommandNotebookEvent):
""" A specialized command event class for events sent by :class:`AuiNotebook`. """
def __init__(self, command_type=None, win_id=0):
"""
Default class constructor.
:param `command_type`: the event kind or an instance of :class:`PyCommandEvent`.
:param integer `win_id`: the window identification number.
"""
CommandNotebookEvent.__init__(self, command_type, win_id)
if type(command_type) == types.IntType:
self.notify = wx.NotifyEvent(command_type, win_id)
else:
self.notify = wx.NotifyEvent(command_type.GetEventType(), command_type.GetId())
def GetNotifyEvent(self):
""" Returns the actual :class:`NotifyEvent`. """
return self.notify
def IsAllowed(self):
""" Returns whether the event is allowed or not. """
return self.notify.IsAllowed()
def Veto(self):
"""
Prevents the change announced by this event from happening.
It is in general a good idea to notify the user about the reasons for
vetoing the change because otherwise the applications behaviour (which
just refuses to do what the user wants) might be quite surprising.
"""
self.notify.Veto()
def Allow(self):
"""
This is the opposite of :meth:`Veto`: it explicitly allows the event to be
processed. For most events it is not necessary to call this method as the
events are allowed anyhow but some are forbidden by default (this will
be mentioned in the corresponding event description).
"""
self.notify.Allow()
# ---------------------------------------------------------------------------- #
# Class TabNavigatorProps
# ---------------------------------------------------------------------------- #
class TabNavigatorProps(object):
"""
Data storage class for managing and providing access to :class:`TabNavigatorWindow` properties.
"""
def __init__(self):
""" Default class constructor. """
super(TabNavigatorProps, self).__init__()
# Attributes
self._icon = wx.NullBitmap
self._font = wx.NullFont
self._minsize = wx.DefaultSize
# Accessors
Icon = property(lambda self: self._icon,
lambda self, icon: setattr(self, '_icon', icon),
doc='Sets/Gets the icon for the L{TabNavigatorWindow}, an instance of :class:`Bitmap`.')
Font = property(lambda self: self._font,
lambda self, font: setattr(self, '_font', font),
doc='Sets/Gets the font for the L{TabNavigatorWindow}, an instance of :class:`Font`.')
MinSize = property(lambda self: self._minsize,
lambda self, size: setattr(self, '_minsize', size),
doc='Sets/Gets the minimum size for the L{TabNavigatorWindow}, an instance of :class:`Size`.')
# ---------------------------------------------------------------------------- #
# Class TabNavigatorWindow
# ---------------------------------------------------------------------------- #
class TabNavigatorWindow(wx.Dialog):
"""
This class is used to create a modal dialog that enables "Smart Tabbing",
similar to what you would get by hitting ``Alt`` + ``Tab`` on Windows.
"""
def __init__(self, parent, props):
"""
Default class constructor. Used internally.
:param `parent`: the :class:`TabNavigatorWindow` parent;
:param `props`: the :class:`TabNavigatorProps` object.
"""
wx.Dialog.__init__(self, parent, wx.ID_ANY, "", size=props.MinSize, style=0)
self._selectedItem = -1
self._indexMap = []
self._props = props
if not self._props.Icon.IsOk():
self._props.Icon = Mondrian.GetBitmap()
if props.Icon.GetSize() != (16, 16):
img = self._props.Icon.ConvertToImage()
img.Rescale(16, 16, wx.IMAGE_QUALITY_HIGH)
self._props.Icon = wx.BitmapFromImage(img)
if self._props.Font.IsOk():
self.Font = self._props.Font
sz = wx.BoxSizer(wx.VERTICAL)
self._listBox = wx.ListBox(self, wx.ID_ANY,
wx.DefaultPosition,
wx.Size(200, 150), [],
wx.LB_SINGLE | wx.NO_BORDER)
mem_dc = wx.MemoryDC()
mem_dc.SelectObject(wx.EmptyBitmap(1,1))
font = wx.SystemSettings_GetFont(wx.SYS_DEFAULT_GUI_FONT)
font.SetWeight(wx.BOLD)
mem_dc.SetFont(font)
panelHeight = mem_dc.GetCharHeight()
panelHeight += 4 # Place a spacer of 2 pixels
# Out signpost bitmap is 24 pixels
if panelHeight < 24:
panelHeight = 24
self._panel = wx.Panel(self, wx.ID_ANY, wx.DefaultPosition,
wx.Size(-1, panelHeight))
sz.Add(self._panel, 0, wx.EXPAND)
sz.Add(self._listBox, 1, wx.EXPAND)
self.SetSizer(sz)
# Connect events to the list box
self._listBox.Bind(wx.EVT_KEY_UP, self.OnKeyUp)
self._listBox.Bind(wx.EVT_NAVIGATION_KEY, self.OnNavigationKey)
self._listBox.Bind(wx.EVT_LISTBOX_DCLICK, self.OnItemSelected)
# Connect paint event to the panel
self._panel.Bind(wx.EVT_PAINT, self.OnPanelPaint)
self._panel.Bind(wx.EVT_ERASE_BACKGROUND, self.OnPanelEraseBg)
self.SetBackgroundColour(wx.SystemSettings_GetColour(wx.SYS_COLOUR_3DFACE))
self._listBox.SetBackgroundColour(wx.SystemSettings_GetColour(wx.SYS_COLOUR_3DFACE))
self.PopulateListControl(parent)
self.SetInitialSize(props.MinSize)
self.Centre()
# Set focus on the list box to avoid having to click on it to change
# the tab selection under GTK.
self._listBox.SetFocus()
def OnKeyUp(self, event):
"""
Handles the ``wx.EVT_KEY_UP`` for the :class:`TabNavigatorWindow`.
:param `event`: a :class:`KeyEvent` event to be processed.
"""
if event.GetKeyCode() == wx.WXK_CONTROL:
self.CloseDialog()
def OnNavigationKey(self, event):
"""
Handles the ``wx.EVT_NAVIGATION_KEY`` for the :class:`TabNavigatorWindow`.
:param `event`: a :class:`NavigationKeyEvent` event to be processed.
"""
selected = self._listBox.GetSelection()
bk = self.GetParent()
maxItems = bk.GetPageCount()
if event.GetDirection():
# Select next page
if selected == maxItems - 1:
itemToSelect = 0
else:
itemToSelect = selected + 1
else:
# Previous page
if selected == 0:
itemToSelect = maxItems - 1
else:
itemToSelect = selected - 1
self._listBox.SetSelection(itemToSelect)
def PopulateListControl(self, book):
"""
Populates the :class:`TabNavigatorWindow` listbox with a list of tabs.
:param `book`: the actual :class:`AuiNotebook`.
"""
# Index of currently selected page
selection = book.GetSelection()
# Total number of pages
count = book.GetPageCount()
# List of (index, AuiNotebookPage)
pages = list(enumerate(book.GetTabContainer().GetPages()))
if book.GetAGWWindowStyleFlag() & AUI_NB_ORDER_BY_ACCESS:
# Sort pages using last access time. Most recently used is the
# first in line
pages.sort(
key = lambda element: element[1].access_time,
reverse = True
)
else:
# Manually add the current selection as first item
# Remaining ones are added in the next loop
del pages[selection]
self._listBox.Append(book.GetPageText(selection))
self._indexMap.append(selection)
for (index, page) in pages:
self._listBox.Append(book.GetPageText(index))
self._indexMap.append(index)
# Select the next entry after the current selection
self._listBox.SetSelection(0)
dummy = wx.NavigationKeyEvent()
dummy.SetDirection(True)
self.OnNavigationKey(dummy)
def OnItemSelected(self, event):
"""
Handles the ``wx.EVT_LISTBOX_DCLICK`` event for the :class:`ListBox` inside :class:`TabNavigatorWindow`.
:param `event`: a :class:`ListEvent` event to be processed.
"""
self.CloseDialog()
def CloseDialog(self):
""" Closes the :class:`TabNavigatorWindow` dialog, setting selection in :class:`AuiNotebook`. """
bk = self.GetParent()
self._selectedItem = self._listBox.GetSelection()
self.EndModal(wx.ID_OK)
def GetSelectedPage(self):
""" Gets the page index that was selected when the dialog was closed. """
return self._indexMap[self._selectedItem]
def OnPanelPaint(self, event):
"""
Handles the ``wx.EVT_PAINT`` event for :class:`TabNavigatorWindow` top panel.
:param `event`: a :class:`PaintEvent` event to be processed.
"""
dc = wx.PaintDC(self._panel)
rect = self._panel.GetClientRect()
bmp = wx.EmptyBitmap(rect.width, rect.height)
mem_dc = wx.MemoryDC()
mem_dc.SelectObject(bmp)
endColour = wx.SystemSettings_GetColour(wx.SYS_COLOUR_BTNSHADOW)
startColour = LightColour(endColour, 50)
mem_dc.GradientFillLinear(rect, startColour, endColour, wx.SOUTH)
# Draw the caption title and place the bitmap
# get the bitmap optimal position, and draw it
bmpPt, txtPt = wx.Point(), wx.Point()
bmpPt.y = (rect.height - self._props.Icon.GetHeight())/2
bmpPt.x = 3
mem_dc.DrawBitmap(self._props.Icon, bmpPt.x, bmpPt.y, True)
# get the text position, and draw it
font = wx.SystemSettings_GetFont(wx.SYS_DEFAULT_GUI_FONT)
font.SetWeight(wx.BOLD)
mem_dc.SetFont(font)
fontHeight = mem_dc.GetCharHeight()
txtPt.x = bmpPt.x + self._props.Icon.GetWidth() + 4
txtPt.y = (rect.height - fontHeight)/2
mem_dc.SetTextForeground(wx.WHITE)
mem_dc.DrawText("Opened tabs:", txtPt.x, txtPt.y)
mem_dc.SelectObject(wx.NullBitmap)
dc.DrawBitmap(bmp, 0, 0)
def OnPanelEraseBg(self, event):
"""
Handles the ``wx.EVT_ERASE_BACKGROUND`` event for :class:`TabNavigatorWindow` top panel.
:param `event`: a :class:`EraseEvent` event to be processed.
:note: This is intentionally empty, to reduce flicker.
"""
pass
# ----------------------------------------------------------------------
# -- AuiTabContainer class implementation --
class AuiTabContainer(object):
"""
AuiTabContainer is a class which contains information about each tab.
It also can render an entire tab control to a specified DC.
It's not a window class itself, because this code will be used by
the :class:`AuiNotebook`, where it is disadvantageous to have separate
windows for each tab control in the case of "docked tabs".
A derived class, :class:`AuiTabCtrl`, is an actual :class:`Window` - derived window
which can be used as a tab control in the normal sense.
"""
def __init__(self, auiNotebook):
"""
Default class constructor.
Used internally, do not call it in your code!
:param `auiNotebook`: the parent :class:`AuiNotebook` window.
"""
self._tab_offset = 0
self._agwFlags = 0
self._art = TA.AuiDefaultTabArt()
self._buttons = []
self._pages = []
self._tab_close_buttons = []
self._click_tab = None
self._rect = wx.Rect()
self._auiNotebook = auiNotebook
self.AddButton(AUI_BUTTON_LEFT, wx.LEFT, name="Scroll Left")
self.AddButton(AUI_BUTTON_RIGHT, wx.RIGHT, name="Scroll Right")
self.AddButton(AUI_BUTTON_WINDOWLIST, wx.RIGHT, name="Window List")
self.AddButton(AUI_BUTTON_CLOSE, wx.RIGHT, name="Close")
def SetArtProvider(self, art):
"""
Instructs :class:`AuiTabContainer` to use art provider specified by parameter `art`
for all drawing calls. This allows plugable look-and-feel features.
:param `art`: an art provider.
:note: The previous art provider object, if any, will be deleted by :class:`AuiTabContainer`.
"""
del self._art
self._art = art
if self._art:
self._art.SetAGWFlags(self._agwFlags)
def GetArtProvider(self):
""" Returns the current art provider being used. """
return self._art
def SetAGWFlags(self, agwFlags):
"""
Sets the tab art flags.
:param integer `agwFlags`: a combination of the following values:
==================================== ==================================
Flag name Description
==================================== ==================================
``AUI_NB_TOP`` With this style, tabs are drawn along the top of the notebook
``AUI_NB_LEFT`` With this style, tabs are drawn along the left of the notebook. Not implemented yet
``AUI_NB_RIGHT`` With this style, tabs are drawn along the right of the notebook. Not implemented yet
``AUI_NB_BOTTOM`` With this style, tabs are drawn along the bottom of the notebook
``AUI_NB_TAB_SPLIT`` Allows the tab control to be split by dragging a tab
``AUI_NB_TAB_MOVE`` Allows a tab to be moved horizontally by dragging
``AUI_NB_TAB_EXTERNAL_MOVE`` Allows a tab to be moved to another tab control
``AUI_NB_TAB_FIXED_WIDTH`` With this style, all tabs have the same width
``AUI_NB_SCROLL_BUTTONS`` With this style, left and right scroll buttons are displayed
``AUI_NB_WINDOWLIST_BUTTON`` With this style, a drop-down list of windows is available
``AUI_NB_CLOSE_BUTTON`` With this style, a close button is available on the tab bar
``AUI_NB_CLOSE_ON_ACTIVE_TAB`` With this style, a close button is available on the active tab
``AUI_NB_CLOSE_ON_ALL_TABS`` With this style, a close button is available on all tabs
``AUI_NB_MIDDLE_CLICK_CLOSE`` Allows to close :class:`AuiNotebook` tabs by mouse middle button click
``AUI_NB_SUB_NOTEBOOK`` This style is used by :class:`~lib.agw.aui.framemanager.AuiManager` to create automatic AuiNotebooks
``AUI_NB_HIDE_ON_SINGLE_TAB`` Hides the tab window if only one tab is present
``AUI_NB_SMART_TABS`` Use Smart Tabbing, like ``Alt`` + ``Tab`` on Windows
``AUI_NB_USE_IMAGES_DROPDOWN`` Uses images on dropdown window list menu instead of check items
``AUI_NB_CLOSE_ON_TAB_LEFT`` Draws the tab close button on the left instead of on the right (a la Camino browser)
``AUI_NB_TAB_FLOAT`` Allows the floating of single tabs. Known limitation: when the notebook is more or less full screen,
tabs cannot be dragged far enough outside of the notebook to become floating pages
``AUI_NB_DRAW_DND_TAB`` Draws an image representation of a tab while dragging (on by default)
``AUI_NB_ORDER_BY_ACCESS`` Tab navigation order by last access time for the tabs
``AUI_NB_NO_TAB_FOCUS`` Don't draw tab focus rectangle
==================================== ==================================
.. todo:: Implementation of flags ``AUI_NB_RIGHT`` and ``AUI_NB_LEFT``.
"""
self._agwFlags = agwFlags
# check for new close button settings
self.RemoveButton(AUI_BUTTON_LEFT)
self.RemoveButton(AUI_BUTTON_RIGHT)
self.RemoveButton(AUI_BUTTON_WINDOWLIST)
self.RemoveButton(AUI_BUTTON_CLOSE)
if agwFlags & AUI_NB_SCROLL_BUTTONS:
self.AddButton(AUI_BUTTON_LEFT, wx.LEFT, name="Scroll Left")
self.AddButton(AUI_BUTTON_RIGHT, wx.RIGHT, name="Scroll Right")
if agwFlags & AUI_NB_WINDOWLIST_BUTTON:
self.AddButton(AUI_BUTTON_WINDOWLIST, wx.RIGHT, name="Window List")
if agwFlags & AUI_NB_CLOSE_BUTTON:
self.AddButton(AUI_BUTTON_CLOSE, wx.RIGHT, name="Close")
if self._art:
self._art.SetAGWFlags(self._agwFlags)
def GetAGWFlags(self):
"""
Returns the tab art flags.
.. seealso:: :meth:`SetAGWFlags` for a list of possible return values.
"""
return self._agwFlags
def SetNormalFont(self, font):
"""
Sets the normal font for drawing tab labels.
:param Font `font`: the new font to use to draw tab labels in their normal, un-selected state.
"""
self._art.SetNormalFont(font)
def SetSelectedFont(self, font):
"""
Sets the selected tab font for drawing tab labels.
:param Font `font`: the new font to use to draw tab labels in their selected state.
"""
self._art.SetSelectedFont(font)
def SetMeasuringFont(self, font):
"""
Sets the font for calculating text measurements.
:param Font `font`: the new font to use to measure tab label text extents.
"""
self._art.SetMeasuringFont(font)
def SetTabRect(self, rect):
"""
Sets the tab area rectangle.
:param Rect `rect`: the available area for :class:`AuiTabContainer`.
"""
self._rect = rect
if self._art:
minMaxTabWidth = self._auiNotebook.GetMinMaxTabWidth()
self._art.SetSizingInfo(rect.GetSize(), len(self._pages), minMaxTabWidth)
def AddPage(self, page, info):
"""
Adds a page to the tab control.
:param Window `page`: the window associated with this tab;
:param `info`: an instance of :class:`AuiNotebookPage`.
"""
page_info = info
page_info.window = page
self._pages.append(page_info)
# let the art provider know how many pages we have
if self._art:
minMaxTabWidth = self._auiNotebook.GetMinMaxTabWidth()
self._art.SetSizingInfo(self._rect.GetSize(), len(self._pages), minMaxTabWidth)
return True
def InsertPage(self, page, info, idx):
"""
Inserts a page in the tab control in the position specified by `idx`.
:param Window `page`: the window associated with this tab;
:param `info`: an instance of :class:`AuiNotebookPage`;
:param integer `idx`: the page insertion index.
"""
page_info = info
page_info.window = page
if idx >= len(self._pages):
self._pages.append(page_info)
else:
self._pages.insert(idx, page_info)
# let the art provider know how many pages we have
if self._art:
minMaxTabWidth = self._auiNotebook.GetMinMaxTabWidth()
self._art.SetSizingInfo(self._rect.GetSize(), len(self._pages), minMaxTabWidth)
return True
def MovePage(self, page, new_idx):
"""
Moves a page in a new position specified by `new_idx`.
:param Window `page`: the window associated with this tab;
:param integer `new_idx`: the new page position.
"""
idx = self.GetIdxFromWindow(page)
if idx == -1:
return False
# get page entry, make a copy of it
p = self.GetPage(idx)
# remove old page entry
self.RemovePage(page)
# insert page where it should be
self.InsertPage(page, p, new_idx)
return True
def RemovePage(self, wnd):
"""
Removes a page from the tab control.
:param `wnd`: an instance of :class:`Window`, a window associated with this tab.
"""
minMaxTabWidth = self._auiNotebook.GetMinMaxTabWidth()
for page in self._pages:
if page.window == wnd:
self._pages.remove(page)
self._tab_offset = min(self._tab_offset, len(self._pages) - 1)
# let the art provider know how many pages we have
if self._art:
self._art.SetSizingInfo(self._rect.GetSize(), len(self._pages), minMaxTabWidth)
return True
return False
def SetActivePage(self, wndOrInt):
"""
Sets the :class:`AuiNotebook` active page.
:param `wndOrInt`: an instance of :class:`Window` or an integer specifying a tab index.
"""
if type(wndOrInt) == types.IntType:
if wndOrInt >= len(self._pages):
return False
wnd = self._pages[wndOrInt].window
else:
wnd = wndOrInt
found = False
for indx, page in enumerate(self._pages):
if page.window == wnd:
page.active = True
found = True
else:
page.active = False
return found
def SetNoneActive(self):
""" Sets all the tabs as inactive (non-selected). """
for page in self._pages:
page.active = False
def GetActivePage(self):
""" Returns the current selected tab or ``wx.NOT_FOUND`` if none is selected. """
for indx, page in enumerate(self._pages):
if page.active:
return indx
return wx.NOT_FOUND
def GetWindowFromIdx(self, idx):
"""
Returns the window associated with the tab with index `idx`.
:param integer `idx`: the tab index.
"""
if idx >= len(self._pages):
return None
return self._pages[idx].window
def GetIdxFromWindow(self, wnd):
"""
Returns the tab index based on the window `wnd` associated with it.
:param `wnd`: an instance of :class:`Window`.
"""
for indx, page in enumerate(self._pages):
if page.window == wnd:
return indx
return wx.NOT_FOUND
def GetPage(self, idx):
"""
Returns the page specified by the given index.
:param integer `idx`: the tab index.
"""
if idx < 0 or idx >= len(self._pages):
raise Exception("Invalid Page index")
return self._pages[idx]
def GetPages(self):
""" Returns a list of all the pages in this :class:`AuiTabContainer`. """
return self._pages
def GetPageCount(self):
""" Returns the number of pages in the :class:`AuiTabContainer`. """
return len(self._pages)
def GetEnabled(self, idx):
"""
Returns whether a tab is enabled or not.
:param integer `idx`: the tab index.
"""
if idx < 0 or idx >= len(self._pages):
return False
return self._pages[idx].enabled
def EnableTab(self, idx, enable=True):
"""
Enables/disables a tab in the :class:`AuiTabContainer`.
:param integer `idx`: the tab index;
:param bool `enable`: ``True`` to enable a tab, ``False`` to disable it.
"""
if idx < 0 or idx >= len(self._pages):
raise Exception("Invalid Page index")
self._pages[idx].enabled = enable
wnd = self.GetWindowFromIdx(idx)
wnd.Enable(enable)
def AddButton(self, id, location, normal_bitmap=wx.NullBitmap, disabled_bitmap=wx.NullBitmap, name=""):
"""
Adds a button in the tab area.
:param integer `id`: the button identifier. This can be one of the following:
============================== =================================
Button Identifier Description
============================== =================================
``AUI_BUTTON_CLOSE`` Shows a close button on the tab area
``AUI_BUTTON_WINDOWLIST`` Shows a window list button on the tab area
``AUI_BUTTON_LEFT`` Shows a left button on the tab area
``AUI_BUTTON_RIGHT`` Shows a right button on the tab area
============================== =================================
:param integer `location`: the button location. Can be ``wx.LEFT`` or ``wx.RIGHT``;
:param Bitmap `normal_bitmap`: the bitmap for an enabled tab;
:param Bitmap `disabled_bitmap`: the bitmap for a disabled tab;
:param string `name`: the button name.
"""
button = AuiTabContainerButton()
button.id = id
button.name = name
button.bitmap = normal_bitmap
button.dis_bitmap = disabled_bitmap
button.location = location
button.cur_state = AUI_BUTTON_STATE_NORMAL
self._buttons.append(button)
def CloneButtons(self):
"""
Clones the tab area buttons when the :class:`AuiNotebook` is being split.
:see: :meth:`AddButton`
:note: Standard buttons for :class:`AuiNotebook` are not cloned, only custom ones.
"""
singleton_list = [AUI_BUTTON_CLOSE, AUI_BUTTON_WINDOWLIST, AUI_BUTTON_LEFT, AUI_BUTTON_RIGHT]
clones = []
for button in self._buttons:
if button.id not in singleton_list:
new_button = AuiTabContainerButton()
new_button.id = button.id
new_button.bitmap = button.bitmap
new_button.dis_bitmap = button.dis_bitmap
new_button.location = button.location
clones.append(new_button)
return clones
def RemoveButton(self, id):
"""
Removes a button from the tab area.
:param integer `id`: the button identifier. See :meth:`AddButton` for a list of button identifiers.
:see: :meth:`AddButton`
"""
for button in self._buttons:
if button.id == id:
self._buttons.remove(button)
return
def GetTabOffset(self):
""" Returns the tab offset. """
return self._tab_offset
def SetTabOffset(self, offset):
"""
Sets the tab offset.
:param integer `offset`: the tab offset.
"""
self._tab_offset = offset
def Render(self, raw_dc, wnd):
"""
Renders the tab catalog to the specified :class:`DC`.
It is a virtual function and can be overridden to provide custom drawing
capabilities.
:param `raw_dc`: a :class:`DC` device context;
:param `wnd`: an instance of :class:`Window`.
"""
if not raw_dc or not raw_dc.IsOk():
return
dc = wx.MemoryDC()
# use the same layout direction as the window DC uses to ensure that the
# text is rendered correctly
dc.SetLayoutDirection(raw_dc.GetLayoutDirection())
page_count = len(self._pages)
button_count = len(self._buttons)
# create off-screen bitmap
bmp = wx.EmptyBitmap(self._rect.GetWidth(), self._rect.GetHeight())
dc.SelectObject(bmp)
if not dc.IsOk():
return
# prepare the tab-close-button array
# make sure tab button entries which aren't used are marked as hidden
for i in xrange(page_count, len(self._tab_close_buttons)):
self._tab_close_buttons[i].cur_state = AUI_BUTTON_STATE_HIDDEN
# make sure there are enough tab button entries to accommodate all tabs
while len(self._tab_close_buttons) < page_count:
tempbtn = AuiTabContainerButton()
tempbtn.id = AUI_BUTTON_CLOSE
tempbtn.location = wx.CENTER
tempbtn.cur_state = AUI_BUTTON_STATE_HIDDEN
self._tab_close_buttons.append(tempbtn)
# find out if size of tabs is larger than can be
# afforded on screen
total_width = visible_width = 0
tab_width = [0] * page_count
for i in xrange(page_count):
page = self._pages[i]
# determine if a close button is on this tab
close_button = False
if (self._agwFlags & AUI_NB_CLOSE_ON_ALL_TABS and page.hasCloseButton) or \
(self._agwFlags & AUI_NB_CLOSE_ON_ACTIVE_TAB and page.active and page.hasCloseButton):
close_button = True
control = page.control
if control:
try:
control.GetSize()
except wx.PyDeadObjectError:
page.control = None
size, x_extent = self._art.GetTabSize(dc, wnd, page.caption, page.bitmap, page.active,
(close_button and [AUI_BUTTON_STATE_NORMAL] or \
[AUI_BUTTON_STATE_HIDDEN])[0], page.control)
if i+1 < page_count:
total_width += x_extent
tab_width[i] = x_extent
else:
total_width += size[0]
tab_width[i] = size[0]
if i >= self._tab_offset:
if i+1 < page_count:
visible_width += x_extent
else:
visible_width += size[0]
# Calculate the width of visible buttons
buttons_width = 0
for button in self._buttons:
if not (button.cur_state & AUI_BUTTON_STATE_HIDDEN):
buttons_width += button.rect.GetWidth()
total_width += buttons_width
if (total_width > self._rect.GetWidth() and page_count > 1) or self._tab_offset != 0:
# show left/right buttons
for button in self._buttons:
if button.id == AUI_BUTTON_LEFT or \
button.id == AUI_BUTTON_RIGHT:
button.cur_state &= ~AUI_BUTTON_STATE_HIDDEN
else:
# hide left/right buttons
for button in self._buttons:
if button.id == AUI_BUTTON_LEFT or \
button.id == AUI_BUTTON_RIGHT:
button.cur_state |= AUI_BUTTON_STATE_HIDDEN
# Re-calculate the width of visible buttons (may have been hidden/shown)
buttons_width = 0
for button in self._buttons:
if not (button.cur_state & AUI_BUTTON_STATE_HIDDEN):
buttons_width += button.rect.GetWidth()
# Shift the tab offset down to make use of available space
available_width = self._rect.GetWidth() - buttons_width
while self._tab_offset > 0 and visible_width + tab_width[self._tab_offset - 1] < available_width:
self._tab_offset -= 1
visible_width += tab_width[self._tab_offset]
# determine whether left button should be enabled
for button in self._buttons:
if button.id == AUI_BUTTON_LEFT:
if self._tab_offset == 0:
button.cur_state |= AUI_BUTTON_STATE_DISABLED
else:
button.cur_state &= ~AUI_BUTTON_STATE_DISABLED
if button.id == AUI_BUTTON_RIGHT:
if visible_width < self._rect.GetWidth() - buttons_width:
button.cur_state |= AUI_BUTTON_STATE_DISABLED
else:
button.cur_state &= ~AUI_BUTTON_STATE_DISABLED
# draw background
self._art.DrawBackground(dc, wnd, self._rect)
# draw buttons
left_buttons_width = 0
right_buttons_width = 0
# draw the buttons on the right side
offset = self._rect.x + self._rect.width
for i in xrange(button_count):
button = self._buttons[button_count - i - 1]
if button.location != wx.RIGHT:
continue
if button.cur_state & AUI_BUTTON_STATE_HIDDEN:
continue
button_rect = wx.Rect(*self._rect)
button_rect.SetY(1)
button_rect.SetWidth(offset)
button.rect = self._art.DrawButton(dc, wnd, button_rect, button, wx.RIGHT)
offset -= button.rect.GetWidth()
right_buttons_width += button.rect.GetWidth()
offset = 0
# draw the buttons on the left side
for i in xrange(button_count):
button = self._buttons[button_count - i - 1]
if button.location != wx.LEFT:
continue
if button.cur_state & AUI_BUTTON_STATE_HIDDEN:
continue
button_rect = wx.Rect(offset, 1, 1000, self._rect.height)
button.rect = self._art.DrawButton(dc, wnd, button_rect, button, wx.LEFT)
offset += button.rect.GetWidth()
left_buttons_width += button.rect.GetWidth()
if offset == 0:
offset += self._art.GetIndentSize()
# buttons before the tab offset must be set to hidden
for i in xrange(self._tab_offset):
self._tab_close_buttons[i].cur_state = AUI_BUTTON_STATE_HIDDEN
if self._pages[i].control:
if self._pages[i].control.IsShown():
self._pages[i].control.Hide()
# draw tab before tab offset
if self._tab_offset > 0:
page = self._pages[self._tab_offset - 1]
tab_button = self._tab_close_buttons[self._tab_offset - 1]
size, x_extent = self._art.GetTabSize(dc, wnd, page.caption, page.bitmap, page.active, tab_button.cur_state, page.control)
rect = wx.Rect(offset - x_extent, 0, self._rect.width - right_buttons_width - offset - x_extent - 2, self._rect.height)
clip_rect = wx.Rect(*self._rect)
clip_rect.x = offset
dc.SetClippingRect(clip_rect)
self._art.DrawTab(dc, wnd, page, rect, tab_button.cur_state)
dc.DestroyClippingRegion()
# draw the tabs
active = 999
active_offset = 0
rect = wx.Rect(*self._rect)
rect.y = 0
rect.height = self._rect.height
for i in xrange(self._tab_offset, page_count):
page = self._pages[i]
tab_button = self._tab_close_buttons[i]
# determine if a close button is on this tab
if (self._agwFlags & AUI_NB_CLOSE_ON_ALL_TABS and page.hasCloseButton) or \
(self._agwFlags & AUI_NB_CLOSE_ON_ACTIVE_TAB and page.active and page.hasCloseButton):
if tab_button.cur_state == AUI_BUTTON_STATE_HIDDEN:
tab_button.id = AUI_BUTTON_CLOSE
tab_button.cur_state = AUI_BUTTON_STATE_NORMAL
tab_button.location = wx.CENTER
else:
tab_button.cur_state = AUI_BUTTON_STATE_HIDDEN
rect.x = offset
rect.width = self._rect.width - right_buttons_width - offset - 2
if rect.width <= 0:
break
page.rect, tab_button.rect, x_extent = self._art.DrawTab(dc, wnd, page, rect, tab_button.cur_state)
if page.active:
active = i
active_offset = offset
active_rect = wx.Rect(*rect)
offset += x_extent
lenPages = len(self._pages)
# make sure to deactivate buttons which are off the screen to the right
for j in xrange(i+1, len(self._tab_close_buttons)):
self._tab_close_buttons[j].cur_state = AUI_BUTTON_STATE_HIDDEN
if j > 0 and j <= lenPages:
if self._pages[j-1].control:
if self._pages[j-1].control.IsShown():
self._pages[j-1].control.Hide()
# draw the active tab again so it stands in the foreground
if active >= self._tab_offset and active < len(self._pages):
page = self._pages[active]
tab_button = self._tab_close_buttons[active]
rect.x = active_offset
dummy = self._art.DrawTab(dc, wnd, page, active_rect, tab_button.cur_state)
raw_dc.Blit(self._rect.x, self._rect.y, self._rect.GetWidth(), self._rect.GetHeight(), dc, 0, 0)
def IsTabVisible(self, tabPage, tabOffset, dc, wnd):
"""
Returns whether a tab is visible or not.
:param integer `tabPage`: the tab index;
:param integer `tabOffset`: the tab offset;
:param `dc`: a :class:`DC` device context;
:param `wnd`: an instance of :class:`Window` derived window.
"""
if not dc or not dc.IsOk():
return False
page_count = len(self._pages)
button_count = len(self._buttons)
self.Render(dc, wnd)
# Hasn't been rendered yet assume it's visible
if len(self._tab_close_buttons) < page_count:
return True
if self._agwFlags & AUI_NB_SCROLL_BUTTONS:
# First check if both buttons are disabled - if so, there's no need to
# check further for visibility.
arrowButtonVisibleCount = 0
for i in xrange(button_count):
button = self._buttons[i]
if button.id == AUI_BUTTON_LEFT or \
button.id == AUI_BUTTON_RIGHT:
if button.cur_state & AUI_BUTTON_STATE_HIDDEN == 0:
arrowButtonVisibleCount += 1
# Tab must be visible
if arrowButtonVisibleCount == 0:
return True
# If tab is less than the given offset, it must be invisible by definition
if tabPage < tabOffset:
return False
# draw buttons
left_buttons_width = 0
right_buttons_width = 0
# calculate size of the buttons on the right side
for i in xrange(button_count):
button = self._buttons[button_count - i - 1]
if button.location != wx.RIGHT:
continue
if button.cur_state & AUI_BUTTON_STATE_HIDDEN:
continue
right_buttons_width += button.rect.GetWidth()
offset = 0
# calculate size of the buttons on the left side
for i in xrange(button_count):
button = self._buttons[button_count - i - 1]
if button.location != wx.LEFT:
continue
if button.cur_state & AUI_BUTTON_STATE_HIDDEN:
continue
offset += button.rect.GetWidth()
left_buttons_width += button.rect.GetWidth()
if offset == 0:
offset += self._art.GetIndentSize()
rect = wx.Rect(*self._rect)
rect.y = 0
rect.height = self._rect.height
# See if the given page is visible at the given tab offset (effectively scroll position)
for i in xrange(tabOffset, page_count):
page = self._pages[i]
tab_button = self._tab_close_buttons[i]
rect.x = offset
rect.width = self._rect.width - right_buttons_width - offset - 2
if rect.width <= 0:
return False # haven't found the tab, and we've run out of space, so return False
size, x_extent = self._art.GetTabSize(dc, wnd, page.caption, page.bitmap, page.active, tab_button.cur_state, page.control)
offset += x_extent
if i == tabPage:
# If not all of the tab is visible, and supposing there's space to display it all,
# we could do better so we return False.
if (self._rect.width - right_buttons_width - offset - 2) <= 0 and (self._rect.width - right_buttons_width - left_buttons_width) > x_extent:
return False
else:
return True
# Shouldn't really get here, but if it does, assume the tab is visible to prevent
# further looping in calling code.
return True
def MakeTabVisible(self, tabPage, win):
"""
Make the tab visible if it wasn't already.
:param integer `tabPage`: the tab index;
:param `win`: an instance of :class:`Window` derived window.
"""
dc = wx.ClientDC(win)
if not self.IsTabVisible(tabPage, self.GetTabOffset(), dc, win):
for i in xrange(len(self._pages)):
if self.IsTabVisible(tabPage, i, dc, win):
self.SetTabOffset(i)
win.Refresh()
return
def TabHitTest(self, x, y):
"""
TabHitTest() tests if a tab was hit, passing the window pointer
back if that condition was fulfilled.
:param integer `x`: the mouse `x` position;
:param integer `y`: the mouse `y` position.
"""
if not self._rect.Contains((x,y)):
return None
btn = self.ButtonHitTest(x, y)
if btn:
if btn in self._buttons:
return None
for i in xrange(self._tab_offset, len(self._pages)):
page = self._pages[i]
if page.rect.Contains((x,y)):
return page.window
return None
def ButtonHitTest(self, x, y, state_flags=AUI_BUTTON_STATE_HIDDEN|AUI_BUTTON_STATE_DISABLED):
"""
Tests if a button was hit.
:param integer `x`: the mouse `x` position;
:param integer `y`: the mouse `y` position;
:param integer `state_flags`: the current button state (hidden, disabled, etc...).
:returns: and instance of :class:`AuiTabContainerButton` if a button was hit, ``None`` otherwise.
"""
if not self._rect.Contains((x,y)):
return None
for button in self._buttons:
if button.rect.Contains((x,y)) and \
(button.cur_state & state_flags) == 0:
return button
for button in self._tab_close_buttons:
if button.rect.Contains((x,y)) and \
(button.cur_state & state_flags) == 0:
return button
return None
def DoShowHide(self):
"""
This function shows the active window, then hides all of the other windows
(in that order).
"""
pages = self.GetPages()
# show new active page first
for page in pages:
if page.active:
page.window.Show(True)
break
# hide all other pages
for page in pages:
if not page.active:
page.window.Show(False)
# ----------------------------------------------------------------------
# -- AuiTabCtrl class implementation --
class AuiTabCtrl(wx.PyControl, AuiTabContainer):
"""
This is an actual :class:`Window` - derived window which can be used as a tab control in the normal sense.
"""
def __init__(self, parent, id=wx.ID_ANY, pos=wx.DefaultPosition, size=wx.DefaultSize,
style=wx.NO_BORDER|wx.WANTS_CHARS|wx.TAB_TRAVERSAL):
"""
Default class constructor.
Used internally, do not call it in your code!
:param `parent`: the :class:`AuiNotebook` parent;
:param integer `id`: an identifier for the control: a value of -1 is taken to mean a default;
:param Point `pos`: the control position. A value of (-1, -1) indicates a default position,
chosen by either the windowing system or wxPython, depending on platform;
:param Size `size`: the control size. A value of (-1, -1) indicates a default size,
chosen by either the windowing system or wxPython, depending on platform;
:param integer `style`: the window style.
"""
wx.PyControl.__init__(self, parent, id, pos, size, style, name="AuiTabCtrl")
AuiTabContainer.__init__(self, parent)
self._click_pt = wx.Point(-1, -1)
self._is_dragging = False
self._hover_button = None
self._pressed_button = None
self._drag_image = None
self._drag_img_offset = (0, 0)
self._on_button = False
self._tooltip_timer = None
self._tooltip_wnd = None
self.Bind(wx.EVT_PAINT, self.OnPaint)
self.Bind(wx.EVT_ERASE_BACKGROUND, self.OnEraseBackground)
self.Bind(wx.EVT_SIZE, self.OnSize)
self.Bind(wx.EVT_LEFT_DOWN, self.OnLeftDown)
self.Bind(wx.EVT_LEFT_DCLICK, self.OnLeftDClick)
self.Bind(wx.EVT_LEFT_UP, self.OnLeftUp)
self.Bind(wx.EVT_MIDDLE_DOWN, self.OnMiddleDown)
self.Bind(wx.EVT_MIDDLE_UP, self.OnMiddleUp)
self.Bind(wx.EVT_RIGHT_DOWN, self.OnRightDown)
self.Bind(wx.EVT_RIGHT_UP, self.OnRightUp)
self.Bind(wx.EVT_SET_FOCUS, self.OnSetFocus)
self.Bind(wx.EVT_KILL_FOCUS, self.OnKillFocus)
self.Bind(wx.EVT_KEY_DOWN, self.OnKeyDown)
self.Bind(wx.EVT_MOUSE_CAPTURE_LOST, self.OnCaptureLost)
self.Bind(wx.EVT_MOTION, self.OnMotion)
self.Bind(wx.EVT_ENTER_WINDOW, self.OnEnterWindow)
self.Bind(wx.EVT_LEAVE_WINDOW, self.OnLeaveWindow)
self.Bind(EVT_AUINOTEBOOK_BUTTON, self.OnButton)
def IsDragging(self):
""" Returns whether the user is dragging a tab with the mouse or not. """
return self._is_dragging
def GetDefaultBorder(self):
""" Returns the default border style for :class:`AuiTabCtrl`. """
return wx.BORDER_NONE
def OnPaint(self, event):
"""
Handles the ``wx.EVT_PAINT`` event for :class:`AuiTabCtrl`.
:param `event`: a :class:`PaintEvent` event to be processed.
"""
dc = wx.PaintDC(self)
dc.SetFont(self.GetFont())
if self.GetPageCount() > 0:
self.Render(dc, self)
def OnEraseBackground(self, event):
"""
Handles the ``wx.EVT_ERASE_BACKGROUND`` event for :class:`AuiTabCtrl`.
:param `event`: a :class:`EraseEvent` event to be processed.
:note: This is intentionally empty, to reduce flicker.
"""
pass
def DoGetBestSize(self):
"""
Gets the size which best suits the window: for a control, it would be the
minimal size which doesn't truncate the control, for a panel - the same
size as it would have after a call to `Fit()`.
:note: Overridden from :class:`PyControl`.
"""
return wx.Size(self._rect.width, self._rect.height)
def OnSize(self, event):
"""
Handles the ``wx.EVT_SIZE`` event for :class:`AuiTabCtrl`.
:param `event`: a :class:`SizeEvent` event to be processed.
"""
s = event.GetSize()
self.SetTabRect(wx.Rect(0, 0, s.GetWidth(), s.GetHeight()))
def OnLeftDown(self, event):
"""
Handles the ``wx.EVT_LEFT_DOWN`` event for :class:`AuiTabCtrl`.
:param `event`: a :class:`MouseEvent` event to be processed.
"""
self.StopTooltipTimer()
if not self.HasCapture():
self.CaptureMouse()
self._click_pt = wx.Point(-1, -1)
self._is_dragging = False
self._click_tab = None
self._pressed_button = None
wnd = self.TabHitTest(event.GetX(), event.GetY())
if wnd is not None:
new_selection = self.GetIdxFromWindow(wnd)
# AuiNotebooks always want to receive this event
# even if the tab is already active, because they may
# have multiple tab controls
if (new_selection != self.GetActivePage() or isinstance(self.GetParent(), AuiNotebook)) and \
not self._hover_button:
e = AuiNotebookEvent(wxEVT_COMMAND_AUINOTEBOOK_PAGE_CHANGING, self.GetId())
e.SetSelection(new_selection)
e.SetOldSelection(self.GetActivePage())
e.SetEventObject(self)
self.GetEventHandler().ProcessEvent(e)
self._click_pt.x = event.GetX()
self._click_pt.y = event.GetY()
self._click_tab = wnd
wnd.SetFocus()
else:
page_index = self.GetActivePage()
if page_index != wx.NOT_FOUND:
self.GetWindowFromIdx(page_index).SetFocus()
self._hover_button = self.ButtonHitTest(event.GetX(), event.GetY())
if self._hover_button:
self._pressed_button = self._hover_button
self._pressed_button.cur_state = AUI_BUTTON_STATE_PRESSED
self._on_button = True
self.Refresh()
self.Update()
def OnCaptureLost(self, event):
"""
Handles the ``wx.EVT_MOUSE_CAPTURE_LOST`` event for :class:`AuiTabCtrl`.
:param `event`: a :class:`MouseCaptureLostEvent` event to be processed.
"""
if self._click_tab:
e = AuiNotebookEvent(wxEVT_COMMAND_AUINOTEBOOK_TAB_LEFT_UP, self.GetId())
e.SetEventObject(self)
e.SetSelection(self.GetIdxFromWindow(self._click_tab))
self.GetEventHandler().ProcessEvent(e)
if self._is_dragging:
self._is_dragging = False
self._on_button = False
if self._drag_image:
self._drag_image.EndDrag()
del self._drag_image
self._drag_image = None
event = AuiNotebookEvent(wxEVT_COMMAND_AUINOTEBOOK_CANCEL_DRAG, self.GetId())
event.SetSelection(self.GetIdxFromWindow(self._click_tab))
event.SetOldSelection(event.GetSelection())
event.SetEventObject(self)
self.GetEventHandler().ProcessEvent(event)
if self._hover_button:
self._hover_button.cur_state = AUI_BUTTON_STATE_NORMAL
self._hover_button = None
self.Refresh()
self.Update()
def OnLeftUp(self, event):
"""
Handles the ``wx.EVT_LEFT_UP`` event for :class:`AuiTabCtrl`.
:param `event`: a :class:`MouseEvent` event to be processed.
"""
if self._click_tab:
e = AuiNotebookEvent(wxEVT_COMMAND_AUINOTEBOOK_TAB_LEFT_UP, self.GetId())
e.SetEventObject(self)
e.SetSelection(self.GetIdxFromWindow(self._click_tab))
self.GetEventHandler().ProcessEvent(e)
elif not self.ButtonHitTest(event.GetX(), event.GetY()):
e = AuiNotebookEvent(wxEVT_COMMAND_AUINOTEBOOK_BG_LEFT_UP, self.GetId())
e.SetEventObject(self)
self.GetEventHandler().ProcessEvent(e)
self._on_button = False
if self._is_dragging:
if self.HasCapture():
self.ReleaseMouse()
self._is_dragging = False
if self._drag_image:
self._drag_image.EndDrag()
del self._drag_image
self._drag_image = None
self.GetParent().Refresh()
evt = AuiNotebookEvent(wxEVT_COMMAND_AUINOTEBOOK_END_DRAG, self.GetId())
evt.SetSelection(self.GetIdxFromWindow(self._click_tab))
evt.SetOldSelection(evt.GetSelection())
evt.SetEventObject(self)
self.GetEventHandler().ProcessEvent(evt)
return
self.GetParent()._mgr.HideHint()
if self.HasCapture():
self.ReleaseMouse()
if self._hover_button:
self._pressed_button = self._hover_button
self._hover_button.cur_state = AUI_BUTTON_STATE_NORMAL
if self._pressed_button:
# make sure we're still clicking the button
button = self.ButtonHitTest(event.GetX(), event.GetY())
if button is None:
return
if button != self._pressed_button:
self._pressed_button = None
return
self.Refresh()
self.Update()
if self._pressed_button.cur_state & AUI_BUTTON_STATE_DISABLED == 0:
evt = AuiNotebookEvent(wxEVT_COMMAND_AUINOTEBOOK_BUTTON, self.GetId())
evt.SetSelection(self.GetIdxFromWindow(self._click_tab))
evt.SetInt(self._pressed_button.id)
evt.SetEventObject(self)
eventHandler = self.GetEventHandler()
if eventHandler is not None:
eventHandler.ProcessEvent(evt)
self._pressed_button = None
self._click_pt = wx.Point(-1, -1)
self._is_dragging = False
self._click_tab = None
def OnMiddleUp(self, event):
"""
Handles the ``wx.EVT_MIDDLE_UP`` event for :class:`AuiTabCtrl`.
:param `event`: a :class:`MouseEvent` event to be processed.
"""
eventHandler = self.GetEventHandler()
if not isinstance(eventHandler, AuiTabCtrl):
event.Skip()
return
x, y = event.GetX(), event.GetY()
wnd = self.TabHitTest(x, y)
if wnd:
e = AuiNotebookEvent(wxEVT_COMMAND_AUINOTEBOOK_TAB_MIDDLE_UP, self.GetId())
e.SetEventObject(self)
e.Page = wnd
e.SetSelection(self.GetIdxFromWindow(wnd))
self.GetEventHandler().ProcessEvent(e)
elif not self.ButtonHitTest(x, y):
e = AuiNotebookEvent(wxEVT_COMMAND_AUINOTEBOOK_BG_MIDDLE_UP, self.GetId())
e.SetEventObject(self)
self.GetEventHandler().ProcessEvent(e)
def OnMiddleDown(self, event):
"""
Handles the ``wx.EVT_MIDDLE_DOWN`` event for :class:`AuiTabCtrl`.
:param `event`: a :class:`MouseEvent` event to be processed.
"""
self.StopTooltipTimer()
eventHandler = self.GetEventHandler()
if not isinstance(eventHandler, AuiTabCtrl):
event.Skip()
return
x, y = event.GetX(), event.GetY()
wnd = self.TabHitTest(x, y)
if wnd:
e = AuiNotebookEvent(wxEVT_COMMAND_AUINOTEBOOK_TAB_MIDDLE_DOWN, self.GetId())
e.SetEventObject(self)
e.Page = wnd
e.SetSelection(self.GetIdxFromWindow(wnd))
self.GetEventHandler().ProcessEvent(e)
elif not self.ButtonHitTest(x, y):
e = AuiNotebookEvent(wxEVT_COMMAND_AUINOTEBOOK_BG_MIDDLE_DOWN, self.GetId())
e.SetEventObject(self)
self.GetEventHandler().ProcessEvent(e)
def OnRightUp(self, event):
"""
Handles the ``wx.EVT_RIGHT_UP`` event for :class:`AuiTabCtrl`.
:param `event`: a :class:`MouseEvent` event to be processed.
"""
x, y = event.GetX(), event.GetY()
wnd = self.TabHitTest(x, y)
if wnd:
e = AuiNotebookEvent(wxEVT_COMMAND_AUINOTEBOOK_TAB_RIGHT_UP, self.GetId())
e.SetEventObject(self)
e.Selection = self.GetIdxFromWindow(wnd)
e.Page = wnd
self.GetEventHandler().ProcessEvent(e)
elif not self.ButtonHitTest(x, y):
e = AuiNotebookEvent(wxEVT_COMMAND_AUINOTEBOOK_BG_RIGHT_UP, self.GetId())
e.SetEventObject(self)
self.GetEventHandler().ProcessEvent(e)
def OnRightDown(self, event):
"""
Handles the ``wx.EVT_RIGHT_DOWN`` event for :class:`AuiTabCtrl`.
:param `event`: a :class:`MouseEvent` event to be processed.
"""
self.StopTooltipTimer()
x, y = event.GetX(), event.GetY()
wnd = self.TabHitTest(x, y)
if wnd:
e = AuiNotebookEvent(wxEVT_COMMAND_AUINOTEBOOK_TAB_RIGHT_DOWN, self.GetId())
e.SetEventObject(self)
e.SetSelection(self.GetIdxFromWindow(wnd))
e.Page = wnd
self.GetEventHandler().ProcessEvent(e)
elif not self.ButtonHitTest(x, y):
e = AuiNotebookEvent(wxEVT_COMMAND_AUINOTEBOOK_BG_RIGHT_DOWN, self.GetId())
e.SetEventObject(self)
self.GetEventHandler().ProcessEvent(e)
def OnLeftDClick(self, event):
"""
Handles the ``wx.EVT_LEFT_DCLICK`` event for :class:`AuiTabCtrl`.
:param `event`: a :class:`MouseEvent` event to be processed.
"""
x, y = event.GetX(), event.GetY()
wnd = self.TabHitTest(x, y)
if wnd:
e = AuiNotebookEvent(wxEVT_COMMAND_AUINOTEBOOK_TAB_DCLICK, self.GetId())
e.SetEventObject(self)
e.SetSelection(self.GetIdxFromWindow(wnd))
e.Page = wnd
self.GetEventHandler().ProcessEvent(e)
elif not self.ButtonHitTest(x, y, state_flags=AUI_BUTTON_STATE_HIDDEN):
e = AuiNotebookEvent(wxEVT_COMMAND_AUINOTEBOOK_BG_DCLICK, self.GetId())
e.SetEventObject(self)
self.GetEventHandler().ProcessEvent(e)
def OnMotion(self, event):
"""
Handles the ``wx.EVT_MOTION`` event for :class:`AuiTabCtrl`.
:param `event`: a :class:`MouseEvent` event to be processed.
"""
pos = event.GetPosition()
# check if the mouse is hovering above a button
button = self.ButtonHitTest(pos.x, pos.y)
wnd = self.TabHitTest(pos.x, pos.y)
if wnd is not None:
mouse_tab = self.GetIdxFromWindow(wnd)
if not self._pages[mouse_tab].enabled:
self._hover_button = None
return
if self._on_button:
return
if button:
if self._hover_button and button != self._hover_button:
self._hover_button.cur_state = AUI_BUTTON_STATE_NORMAL
self._hover_button = None
self.Refresh()
self.Update()
if button.cur_state != AUI_BUTTON_STATE_HOVER:
button.cur_state = AUI_BUTTON_STATE_HOVER
self.Refresh()
self.Update()
self._hover_button = button
return
else:
if self._hover_button:
self._hover_button.cur_state = AUI_BUTTON_STATE_NORMAL
self._hover_button = None
self.Refresh()
self.Update()
if not event.LeftIsDown() or self._click_pt == wx.Point(-1, -1):
# if the mouse has moved from one tab to another then restart the
# tooltip timer.
if wnd != self._tooltip_wnd or (wnd is None and self._hover_button is not None):
self.RestartTooltipTimer(wnd)
return
if not self.HasCapture():
return
wnd = self.TabHitTest(pos.x, pos.y)
if not self._is_dragging:
drag_x_threshold = wx.SystemSettings.GetMetric(wx.SYS_DRAG_X)
drag_y_threshold = wx.SystemSettings.GetMetric(wx.SYS_DRAG_Y)
if abs(pos.x - self._click_pt.x) > drag_x_threshold or \
abs(pos.y - self._click_pt.y) > drag_y_threshold:
self._is_dragging = True
if self._drag_image:
self._drag_image.EndDrag()
del self._drag_image
self._drag_image = None
if self._agwFlags & AUI_NB_DRAW_DND_TAB:
# Create the custom draw image from the icons and the text of the item
mouse_tab = self.GetIdxFromWindow(wnd)
page = self._pages[mouse_tab]
tab_button = self._tab_close_buttons[mouse_tab]
self._drag_image = TabDragImage(self, page, tab_button.cur_state, self._art)
if self.HasCapture():
self.ReleaseMouse()
if self._agwFlags & AUI_NB_TAB_FLOAT:
self._drag_image.BeginDrag(wx.Point(0,0), self, fullScreen=True)
else:
self._drag_image.BeginDragBounded(wx.Point(0,0), self, self.GetParent())
# Capture the mouse cursor position offset relative to
# The tab image location
self._drag_img_offset = (pos[0] - page.rect.x,
pos[1] - page.rect.y)
self._drag_image.Show()
if not wnd:
evt2 = AuiNotebookEvent(wxEVT_COMMAND_AUINOTEBOOK_BEGIN_DRAG, self.GetId())
evt2.SetSelection(self.GetIdxFromWindow(self._click_tab))
evt2.SetOldSelection(evt2.GetSelection())
evt2.SetEventObject(self)
self.GetEventHandler().ProcessEvent(evt2)
if evt2.GetDispatched():
return
evt3 = AuiNotebookEvent(wxEVT_COMMAND_AUINOTEBOOK_DRAG_MOTION, self.GetId())
evt3.SetSelection(self.GetIdxFromWindow(self._click_tab))
evt3.SetOldSelection(evt3.GetSelection())
evt3.SetEventObject(self)
self.GetEventHandler().ProcessEvent(evt3)
if self._drag_image:
# Apply the drag images offset
pos -= self._drag_img_offset
self._drag_image.Move(pos)
def GetPointedToTab(self):
"""
Returns the page at which the mouse is pointing (if any).
:rtype: :class:`Window`.
"""
screen_pt = wx.GetMousePosition()
client_pt = self.ScreenToClient(screen_pt)
return self.TabHitTest(client_pt.x, client_pt.y)
def RestartTooltipTimer(self, wnd):
"""
Starts a timer: when it fires, a tooltip will be shown on the notebook tab
the mouse is pointing at.
:param Window `wnd`: the window pointed by the mouse.
"""
self._tooltip_wnd = wnd
if (wnd is None and self._hover_button is None) or not wx.GetApp().IsActive():
self.StopTooltipTimer()
elif self._tooltip_timer:
self._tooltip_timer.Start()
else:
self._tooltip_timer = wx.CallLater(1000, self.ShowTooltip)
def StopTooltipTimer(self):
""" Stops the timer keeping track of tooltips and mouse movements on the tab area. """
if self._tooltip_timer:
self._tooltip_timer.Stop()
self._tooltip_timer = None
def OnEnterWindow(self, event):
"""
Handles the ``wx.EVT_ENTER_WINDOW`` event fof :class:`AuiTabCtrl`.
:param `event`: a :class:`MouseEvent` event to be processed.
"""
self.RestartTooltipTimer(self.GetPointedToTab())
def ShowTooltip(self):
""" Shows the tooltip on the tab. """
wnd = self.GetPointedToTab()
if wnd != self._tooltip_wnd:
self.RestartTooltipTimer(wnd)
else:
idx = self.GetIdxFromWindow(wnd)
if idx >= 0 and idx < len(self._pages):
page = self._pages[idx]
if page.tooltip:
pos = self.ClientToScreen(page.rect.GetPosition())
rect = wx.RectPS(pos, page.rect.GetSize())
tooltip = wx.TipWindow(self, page.tooltip)
tooltip.SetBoundingRect(rect)
else:
pos = self.ScreenToClient(wx.GetMousePosition())
button = self.ButtonHitTest(pos.x, pos.y)
if button:
pos = self.ClientToScreen(button.rect.GetPosition())
rect = wx.RectPS(pos, button.rect.GetSize())
tooltip = wx.TipWindow(self, button.name)
tooltip.SetBoundingRect(rect)
def OnLeaveWindow(self, event):
"""
Handles the ``wx.EVT_LEAVE_WINDOW`` event for :class:`AuiTabCtrl`.
:param `event`: a :class:`MouseEvent` event to be processed.
"""
self.StopTooltipTimer()
if self._hover_button:
self._hover_button.cur_state = AUI_BUTTON_STATE_NORMAL
self._hover_button = None
self.Refresh()
self.Update()
def OnButton(self, event):
"""
Handles the ``EVT_AUINOTEBOOK_BUTTON`` event for :class:`AuiTabCtrl`.
:param `event`: a :class:`AuiNotebookEvent` event to be processed.
"""
button = event.GetInt()
if button == AUI_BUTTON_LEFT or button == AUI_BUTTON_RIGHT:
if button == AUI_BUTTON_LEFT:
if self.GetTabOffset() > 0:
self.SetTabOffset(self.GetTabOffset()-1)
self.Refresh()
self.Update()
else:
self.SetTabOffset(self.GetTabOffset()+1)
self.Refresh()
self.Update()
elif button == AUI_BUTTON_WINDOWLIST:
idx = self.GetArtProvider().ShowDropDown(self, self._pages, self.GetActivePage())
if idx != -1:
e = AuiNotebookEvent(wxEVT_COMMAND_AUINOTEBOOK_PAGE_CHANGING, self.GetId())
e.SetSelection(idx)
e.SetOldSelection(self.GetActivePage())
e.SetEventObject(self)
self.GetEventHandler().ProcessEvent(e)
else:
event.Skip()
def OnSetFocus(self, event):
"""
Handles the ``wx.EVT_SET_FOCUS`` event for :class:`AuiTabCtrl`.
:param `event`: a :class:`FocusEvent` event to be processed.
"""
self.Refresh()
def OnKillFocus(self, event):
"""
Handles the ``wx.EVT_KILL_FOCUS`` event for :class:`AuiTabCtrl`.
:param `event`: a :class:`FocusEvent` event to be processed.
"""
self.Refresh()
def OnKeyDown(self, event):
"""
Handles the ``wx.EVT_KEY_DOWN`` event for :class:`AuiTabCtrl`.
:param `event`: a :class:`KeyEvent` event to be processed.
"""
key = event.GetKeyCode()
nb = self.GetParent()
if key == wx.WXK_LEFT:
nb.AdvanceSelection(False)
self.SetFocus()
elif key == wx.WXK_RIGHT:
nb.AdvanceSelection(True)
self.SetFocus()
elif key == wx.WXK_HOME:
newPage = 0
nb.SetSelection(newPage)
self.SetFocus()
elif key == wx.WXK_END:
newPage = nb.GetPageCount() - 1
nb.SetSelection(newPage)
self.SetFocus()
elif key == wx.WXK_TAB:
if not event.ControlDown():
flags = 0
if not event.ShiftDown(): flags |= wx.NavigationKeyEvent.IsForward
if event.CmdDown(): flags |= wx.NavigationKeyEvent.WinChange
self.Navigate(flags)
else:
if not nb or not isinstance(nb, AuiNotebook):
event.Skip()
return
bForward = bWindowChange = 0
if not event.ShiftDown(): bForward |= wx.NavigationKeyEvent.IsForward
if event.CmdDown(): bWindowChange |= wx.NavigationKeyEvent.WinChange
keyEvent = wx.NavigationKeyEvent()
keyEvent.SetDirection(bForward)
keyEvent.SetWindowChange(bWindowChange)
keyEvent.SetFromTab(True)
keyEvent.SetEventObject(nb)
if not nb.GetEventHandler().ProcessEvent(keyEvent):
# Not processed? Do an explicit tab into the page.
win = self.GetWindowFromIdx(self.GetActivePage())
if win:
win.SetFocus()
self.SetFocus()
return
else:
event.Skip()
def OnKeyDown2(self, event):
"""
Handles the ``wx.EVT_KEY_DOWN`` event for :class:`AuiTabCtrl`.
:param `event`: a :class:`KeyEvent` event to be processed.
.. deprecated:: 0.6
This implementation is now deprecated. Refer to :meth:`OnKeyDown` for the correct one.
"""
if self.GetActivePage() == -1:
event.Skip()
return
# We can't leave tab processing to the system on Windows, tabs and keys
# get eaten by the system and not processed properly if we specify both
# wxTAB_TRAVERSAL and wxWANTS_CHARS. And if we specify just wxTAB_TRAVERSAL,
# we don't key arrow key events.
key = event.GetKeyCode()
if key == wx.WXK_NUMPAD_PAGEUP:
key = wx.WXK_PAGEUP
if key == wx.WXK_NUMPAD_PAGEDOWN:
key = wx.WXK_PAGEDOWN
if key == wx.WXK_NUMPAD_HOME:
key = wx.WXK_HOME
if key == wx.WXK_NUMPAD_END:
key = wx.WXK_END
if key == wx.WXK_NUMPAD_LEFT:
key = wx.WXK_LEFT
if key == wx.WXK_NUMPAD_RIGHT:
key = wx.WXK_RIGHT
if key == wx.WXK_TAB or key == wx.WXK_PAGEUP or key == wx.WXK_PAGEDOWN:
bCtrlDown = event.ControlDown()
bShiftDown = event.ShiftDown()
bForward = (key == wx.WXK_TAB and not bShiftDown) or (key == wx.WXK_PAGEDOWN)
bWindowChange = (key == wx.WXK_PAGEUP) or (key == wx.WXK_PAGEDOWN) or bCtrlDown
bFromTab = (key == wx.WXK_TAB)
nb = self.GetParent()
if not nb or not isinstance(nb, AuiNotebook):
event.Skip()
return
keyEvent = wx.NavigationKeyEvent()
keyEvent.SetDirection(bForward)
keyEvent.SetWindowChange(bWindowChange)
keyEvent.SetFromTab(bFromTab)
keyEvent.SetEventObject(nb)
if not nb.GetEventHandler().ProcessEvent(keyEvent):
# Not processed? Do an explicit tab into the page.
win = self.GetWindowFromIdx(self.GetActivePage())
if win:
win.SetFocus()
return
if len(self._pages) < 2:
event.Skip()
return
newPage = -1
if self.GetLayoutDirection() == wx.Layout_RightToLeft:
forwardKey = wx.WXK_LEFT
backwardKey = wx.WXK_RIGHT
else:
forwardKey = wx.WXK_RIGHT
backwardKey = wx.WXK_LEFT
if key == forwardKey:
if self.GetActivePage() == -1:
newPage = 0
elif self.GetActivePage() < len(self._pages) - 1:
newPage = self.GetActivePage() + 1
elif key == backwardKey:
if self.GetActivePage() == -1:
newPage = len(self._pages) - 1
elif self.GetActivePage() > 0:
newPage = self.GetActivePage() - 1
elif key == wx.WXK_HOME:
newPage = 0
elif key == wx.WXK_END:
newPage = len(self._pages) - 1
else:
event.Skip()
if newPage != -1:
e = AuiNotebookEvent(wxEVT_COMMAND_AUINOTEBOOK_PAGE_CHANGING, self.GetId())
e.SetSelection(newPage)
e.SetOldSelection(newPage)
e.SetEventObject(self)
self.GetEventHandler().ProcessEvent(e)
else:
event.Skip()
# ----------------------------------------------------------------------
class TabFrame(wx.PyWindow):
"""
TabFrame is an interesting case. It's important that all child pages
of the multi-notebook control are all actually children of that control
(and not grandchildren). TabFrame facilitates this. There is one
instance of TabFrame for each tab control inside the multi-notebook.
It's important to know that TabFrame is not a real window, but it merely
used to capture the dimensions/positioning of the internal tab control and
it's managed page windows.
"""
def __init__(self, parent):
"""
Default class constructor.
Used internally, do not call it in your code!
"""
pre = wx.PrePyWindow()
self._tabs = None
self._rect = wx.Rect(0, 0, 200, 200)
self._tab_ctrl_height = 20
self._tab_rect = wx.Rect()
self._parent = parent
self.PostCreate(pre)
def SetTabCtrlHeight(self, h):
"""
Sets the tab control height.
:param integer `h`: the tab area height.
"""
self._tab_ctrl_height = h
def DoSetSize(self, x, y, width, height, flags=wx.SIZE_AUTO):
"""
Sets the position and size of the window in pixels. The `flags`
parameter indicates the interpretation of the other params if they are
equal to -1.
:param integer `x`: the window `x` position;
:param integer `y`: the window `y` position;
:param integer `width`: the window width;
:param integer `height`: the window height;
:param integer `flags`: may have one of this bit set:
=================================== ======================================
Size Flags Description
=================================== ======================================
``wx.SIZE_AUTO`` A -1 indicates that a class-specific default should be used.
``wx.SIZE_AUTO_WIDTH`` A -1 indicates that a class-specific default should be used for the width.
``wx.SIZE_AUTO_HEIGHT`` A -1 indicates that a class-specific default should be used for the height.
``wx.SIZE_USE_EXISTING`` Existing dimensions should be used if -1 values are supplied.
``wx.SIZE_ALLOW_MINUS_ONE`` Allow dimensions of -1 and less to be interpreted as real dimensions, not default values.
``wx.SIZE_FORCE`` Normally, if the position and the size of the window are already the same as the
parameters of this function, nothing is done. but with this flag a window resize
may be forced even in this case (supported in wx 2.6.2 and later and only implemented
for MSW and ignored elsewhere currently)
=================================== ======================================
:note: Overridden from :class:`PyControl`.
"""
self._rect = wx.Rect(x, y, max(1, width), max(1, height))
self.DoSizing()
def DoGetSize(self):
"""
Returns the window size.
:note: Overridden from :class:`PyControl`.
"""
return self._rect.width, self._rect.height
def DoGetClientSize(self):
"""
Returns the window client size.
:note: Overridden from :class:`PyControl`.
"""
return self._rect.width, self._rect.height
def Show(self, show=True):
"""
Shows/hides the window.
:param bool `show`: ``True`` to show the window, ``False`` otherwise.
:note:
Overridden from :class:`PyControl`, this method always returns ``False`` as
:class:`TabFrame` should never be phisically shown on screen.
"""
return False
def DoSizing(self):
""" Does the actual sizing of the tab control. """
if not self._tabs:
return
hideOnSingle = ((self._tabs.GetAGWFlags() & AUI_NB_HIDE_ON_SINGLE_TAB) and \
self._tabs.GetPageCount() <= 1)
if not hideOnSingle and not self._parent._hide_tabs:
tab_height = self._tab_ctrl_height
self._tab_rect = wx.Rect(self._rect.x, self._rect.y, self._rect.width, self._tab_ctrl_height)
if self._tabs.GetAGWFlags() & AUI_NB_BOTTOM:
self._tab_rect = wx.Rect(self._rect.x, self._rect.y + self._rect.height - tab_height,
self._rect.width, tab_height)
self._tabs.SetDimensions(self._rect.x, self._rect.y + self._rect.height - tab_height,
self._rect.width, tab_height)
self._tabs.SetTabRect(wx.Rect(0, 0, self._rect.width, tab_height))
else:
self._tab_rect = wx.Rect(self._rect.x, self._rect.y, self._rect.width, tab_height)
self._tabs.SetDimensions(self._rect.x, self._rect.y, self._rect.width, tab_height)
self._tabs.SetTabRect(wx.Rect(0, 0, self._rect.width, tab_height))
# TODO: elif (GetAGWFlags() & AUI_NB_LEFT)
# TODO: elif (GetAGWFlags() & AUI_NB_RIGHT)
self._tabs.Refresh()
self._tabs.Update()
else:
tab_height = 0
self._tabs.SetDimensions(self._rect.x, self._rect.y, self._rect.width, tab_height)
self._tabs.SetTabRect(wx.Rect(0, 0, self._rect.width, tab_height))
pages = self._tabs.GetPages()
for page in pages:
height = self._rect.height - tab_height
if height < 0:
# avoid passing negative height to wx.Window.SetSize(), this
# results in assert failures/GTK+ warnings
height = 0
if self._tabs.GetAGWFlags() & AUI_NB_BOTTOM:
page.window.SetDimensions(self._rect.x, self._rect.y, self._rect.width, height)
else:
page.window.SetDimensions(self._rect.x, self._rect.y + tab_height,
self._rect.width, height)
# TODO: elif (GetAGWFlags() & AUI_NB_LEFT)
# TODO: elif (GetAGWFlags() & AUI_NB_RIGHT)
if repr(page.window.__class__).find("AuiMDIChildFrame") >= 0:
page.window.ApplyMDIChildFrameRect()
def Update(self):
"""
Calling this method immediately repaints the invalidated area of the window
and all of its children recursively while this would usually only happen when
the flow of control returns to the event loop.
:note: Notice that this function doesn't invalidate any area of the window so
nothing happens if nothing has been invalidated (i.e. marked as requiring a redraw).
Use `Refresh` first if you want to immediately redraw the window unconditionally.
:note: Overridden from :class:`PyControl`.
"""
# does nothing
pass
# ----------------------------------------------------------------------
# -- AuiNotebook class implementation --
class AuiNotebook(wx.PyPanel):
"""
AuiNotebook is a notebook control which implements many features common in applications with dockable panes.
Specifically, AuiNotebook implements functionality which allows the user to rearrange tab
order via drag-and-drop, split the tab window into many different splitter configurations, and toggle
through different themes to customize the control's look and feel.
An effort has been made to try to maintain an API as similar to that of :class:`Notebook`.
The default theme that is used is :class:`~lib.agw.aui.tabart.AuiDefaultTabArt`, which provides a modern, glossy
look and feel. The theme can be changed by calling :meth:`AuiNotebook.SetArtProvider`.
"""
def __init__(self, parent, id=wx.ID_ANY, pos=wx.DefaultPosition, size=wx.DefaultSize,
style=0, agwStyle=AUI_NB_DEFAULT_STYLE, name="AuiNotebook"):
"""
Default class constructor.
:param Window `parent`: the :class:`AuiNotebook` parent;
:param integer `id`: an identifier for the control: a value of -1 is taken to mean a default;
:param Point `pos`: the control position. A value of (-1, -1) indicates a default position,
chosen by either the windowing system or wxPython, depending on platform;
:param Size `size`: the control size. A value of (-1, -1) indicates a default size,
chosen by either the windowing system or wxPython, depending on platform;
:param integer `style`: the underlying :class:`PyPanel` window style;
:param integer `agwStyle`: the AGW-specific window style. This can be a combination of the following bits:
==================================== ==================================
Flag name Description
==================================== ==================================
``AUI_NB_TOP`` With this style, tabs are drawn along the top of the notebook
``AUI_NB_LEFT`` With this style, tabs are drawn along the left of the notebook. Not implemented yet.
``AUI_NB_RIGHT`` With this style, tabs are drawn along the right of the notebook. Not implemented yet.
``AUI_NB_BOTTOM`` With this style, tabs are drawn along the bottom of the notebook
``AUI_NB_TAB_SPLIT`` Allows the tab control to be split by dragging a tab
``AUI_NB_TAB_MOVE`` Allows a tab to be moved horizontally by dragging
``AUI_NB_TAB_EXTERNAL_MOVE`` Allows a tab to be moved to another tab control
``AUI_NB_TAB_FIXED_WIDTH`` With this style, all tabs have the same width
``AUI_NB_SCROLL_BUTTONS`` With this style, left and right scroll buttons are displayed
``AUI_NB_WINDOWLIST_BUTTON`` With this style, a drop-down list of windows is available
``AUI_NB_CLOSE_BUTTON`` With this style, a close button is available on the tab bar
``AUI_NB_CLOSE_ON_ACTIVE_TAB`` With this style, a close button is available on the active tab
``AUI_NB_CLOSE_ON_ALL_TABS`` With this style, a close button is available on all tabs
``AUI_NB_MIDDLE_CLICK_CLOSE`` Allows to close :class:`AuiNotebook` tabs by mouse middle button click
``AUI_NB_SUB_NOTEBOOK`` This style is used by :class:`~lib.agw.aui.framemanager.AuiManager` to create automatic AuiNotebooks
``AUI_NB_HIDE_ON_SINGLE_TAB`` Hides the tab window if only one tab is present
``AUI_NB_SMART_TABS`` Use Smart Tabbing, like ``Alt`` + ``Tab`` on Windows
``AUI_NB_USE_IMAGES_DROPDOWN`` Uses images on dropdown window list menu instead of check items
``AUI_NB_CLOSE_ON_TAB_LEFT`` Draws the tab close button on the left instead of on the right (a la Camino browser)
``AUI_NB_TAB_FLOAT`` Allows the floating of single tabs. Known limitation: when the notebook is more or less full screen,
tabs cannot be dragged far enough outside of the notebook to become floating pages
``AUI_NB_DRAW_DND_TAB`` Draws an image representation of a tab while dragging (on by default)
``AUI_NB_ORDER_BY_ACCESS`` Tab navigation order by last access time for the tabs
``AUI_NB_NO_TAB_FOCUS`` Don't draw tab focus rectangle
==================================== ==================================
Default value for `agwStyle` is:
``AUI_NB_DEFAULT_STYLE`` = ``AUI_NB_TOP`` | ``AUI_NB_TAB_SPLIT`` | ``AUI_NB_TAB_MOVE`` | ``AUI_NB_SCROLL_BUTTONS`` | ``AUI_NB_CLOSE_ON_ACTIVE_TAB`` | ``AUI_NB_MIDDLE_CLICK_CLOSE`` | ``AUI_NB_DRAW_DND_TAB``
:param string `name`: the window name.
"""
self._curpage = -1
self._tab_id_counter = AuiBaseTabCtrlId
self._dummy_wnd = None
self._hide_tabs = False
self._sash_dclick_unsplit = False
self._tab_ctrl_height = 20
self._requested_bmp_size = wx.Size(-1, -1)
self._requested_tabctrl_height = -1
self._textCtrl = None
self._tabBounds = (-1, -1)
wx.PyPanel.__init__(self, parent, id, pos, size, style|wx.BORDER_NONE|wx.TAB_TRAVERSAL, name=name)
self._mgr = framemanager.AuiManager()
self._tabs = AuiTabContainer(self)
self.InitNotebook(agwStyle)
NavigatorProps = property(lambda self: self._navProps)
def Destroy(self):
"""
Destroys the window safely.
Use this function instead of the ``del`` operator, since different window
classes can be destroyed differently. Frames and dialogs are not destroyed
immediately when this function is called -- they are added to a list of
windows to be deleted on idle time, when all the window's events have been
processed. This prevents problems with events being sent to non-existent windows.
:return: ``True`` if the window has either been successfully deleted, or
it has been added to the list of windows pending real deletion.
.. note::
This method has been added to safely un-initialize the underlying
:class:`~lib.agw.aui.framemanager.AuiManager` which manages the :class:`AuiNotebook`
layout (i.e., tab split, re-ordering, tab floating etc...).
"""
self._mgr.UnInit()
return wx.PyPanel.Destroy(self)
def __getitem__(self, index):
"""
More Pythonic way to get a specific page, also useful for iterating
over all pages.
:param integer `index`: the page index.
.. note::
This method makes easier to iterate over all the pages in the notebook, i.e. you can
safely do::
for page in notebook:
DoSomething(page)
"""
if index < self.GetPageCount():
return self.GetPage(index)
else:
raise IndexError("Invalid page index")
def GetTabContainer(self):
""" Returns the instance of :class:`AuiTabContainer`. """
return self._tabs
def InitNotebook(self, agwStyle):
"""
Contains common initialization code called by all constructors.
:param integer `agwStyle`: the notebook style.
:see: :meth:`~AuiNotebook.__init__` for a list of available `agwStyle` bits.
"""
self._agwFlags = agwStyle
self._popupWin = None
self._imageList = None
self._navProps = TabNavigatorProps()
self._last_drag_x = 0
self._normal_font = wx.SystemSettings.GetFont(wx.SYS_DEFAULT_GUI_FONT)
self._selected_font = wx.SystemSettings.GetFont(wx.SYS_DEFAULT_GUI_FONT)
self._selected_font.SetWeight(wx.BOLD)
self.SetArtProvider(TA.AuiDefaultTabArt())
self._dummy_wnd = wx.Window(self, wx.ID_ANY, wx.Point(0, 0), wx.Size(0, 0))
self._dummy_wnd.SetSize((200, 200))
self._dummy_wnd.Show(False)
self._mgr.SetManagedWindow(self)
self._mgr.SetAGWFlags(AUI_MGR_DEFAULT)
self._mgr.SetDockSizeConstraint(1.0, 1.0) # no dock size constraint
self._mgr.AddPane(self._dummy_wnd, framemanager.AuiPaneInfo().Name("dummy").Bottom().CaptionVisible(False).Show(False))
self._mgr.Update()
self.Bind(wx.EVT_SIZE, self.OnSize)
self.Bind(wx.EVT_CHILD_FOCUS, self.OnChildFocusNotebook)
self.Bind(EVT_AUINOTEBOOK_PAGE_CHANGING, self.OnTabClicked,
id=AuiBaseTabCtrlId, id2=AuiBaseTabCtrlId+500)
self.Bind(EVT_AUINOTEBOOK_BEGIN_DRAG, self.OnTabBeginDrag,
id=AuiBaseTabCtrlId, id2=AuiBaseTabCtrlId+500)
self.Bind(EVT_AUINOTEBOOK_END_DRAG, self.OnTabEndDrag,
id=AuiBaseTabCtrlId, id2=AuiBaseTabCtrlId+500)
self.Bind(EVT_AUINOTEBOOK_DRAG_MOTION, self.OnTabDragMotion,
id=AuiBaseTabCtrlId, id2=AuiBaseTabCtrlId+500)
self.Bind(EVT_AUINOTEBOOK_CANCEL_DRAG, self.OnTabCancelDrag,
id=AuiBaseTabCtrlId, id2=AuiBaseTabCtrlId+500)
self.Bind(EVT_AUINOTEBOOK_BUTTON, self.OnTabButton,
id=AuiBaseTabCtrlId, id2=AuiBaseTabCtrlId+500)
self.Bind(EVT_AUINOTEBOOK_TAB_MIDDLE_DOWN, self.OnTabMiddleDown,
id=AuiBaseTabCtrlId, id2=AuiBaseTabCtrlId+500)
self.Bind(EVT_AUINOTEBOOK_TAB_MIDDLE_UP, self.OnTabMiddleUp,
id=AuiBaseTabCtrlId, id2=AuiBaseTabCtrlId+500)
self.Bind(EVT_AUINOTEBOOK_TAB_RIGHT_DOWN, self.OnTabRightDown,
id=AuiBaseTabCtrlId, id2=AuiBaseTabCtrlId+500)
self.Bind(EVT_AUINOTEBOOK_TAB_RIGHT_UP, self.OnTabRightUp,
id=AuiBaseTabCtrlId, id2=AuiBaseTabCtrlId+500)
self.Bind(EVT_AUINOTEBOOK_BG_DCLICK, self.OnTabBgDClick,
id=AuiBaseTabCtrlId, id2=AuiBaseTabCtrlId+500)
self.Bind(EVT_AUINOTEBOOK_TAB_DCLICK, self.OnTabDClick,
id=AuiBaseTabCtrlId, id2=AuiBaseTabCtrlId+500)
self.Bind(wx.EVT_NAVIGATION_KEY, self.OnNavigationKeyNotebook)
def SetArtProvider(self, art):
"""
Sets the art provider to be used by the notebook.
:param `art`: an art provider.
"""
self._tabs.SetArtProvider(art)
self.UpdateTabCtrlHeight(force=True)
def SavePerspective(self):
"""
Saves the entire user interface layout into an encoded string, which can then
be stored by the application (probably using :class:`Config`). When a perspective
is restored using :meth:`LoadPerspective`, the entire user interface will return
to the state it was when the perspective was saved.
"""
# Build list of panes/tabs
tabs = ""
all_panes = self._mgr.GetAllPanes()
for pane in all_panes:
if pane.name == "dummy":
continue
tabframe = pane.window
if tabs:
tabs += "|"
tabs += pane.name + "="
# add tab id's
page_count = tabframe._tabs.GetPageCount()
for p in xrange(page_count):
page = tabframe._tabs.GetPage(p)
page_idx = self._tabs.GetIdxFromWindow(page.window)
if p:
tabs += ","
if p == tabframe._tabs.GetActivePage():
tabs += "+"
elif page_idx == self._curpage:
tabs += "*"
tabs += "%u"%page_idx
tabs += "@"
# Add frame perspective
tabs += self._mgr.SavePerspective()
return tabs
def LoadPerspective(self, layout):
"""
Loads a layout which was saved with :meth:`SavePerspective`.
:param string `layout`: a string which contains a saved :class:`AuiNotebook` layout.
"""
# Remove all tab ctrls (but still keep them in main index)
tab_count = self._tabs.GetPageCount()
for i in xrange(tab_count):
wnd = self._tabs.GetWindowFromIdx(i)
# find out which onscreen tab ctrl owns this tab
ctrl, ctrl_idx = self.FindTab(wnd)
if not ctrl:
return False
# remove the tab from ctrl
if not ctrl.RemovePage(wnd):
return False
self.RemoveEmptyTabFrames()
sel_page = 0
tabs = layout[0:layout.index("@")]
to_break1 = False
while 1:
if "|" not in tabs:
to_break1 = True
tab_part = tabs
else:
tab_part = tabs[0:tabs.index('|')]
if "=" not in tab_part:
# No pages in this perspective...
return False
# Get pane name
pane_name = tab_part[0:tab_part.index("=")]
# create a new tab frame
new_tabs = TabFrame(self)
self._tab_id_counter += 1
new_tabs._tabs = AuiTabCtrl(self, self._tab_id_counter)
new_tabs._tabs.SetArtProvider(self._tabs.GetArtProvider().Clone())
new_tabs.SetTabCtrlHeight(self._tab_ctrl_height)
new_tabs._tabs.SetAGWFlags(self._agwFlags)
dest_tabs = new_tabs._tabs
# create a pane info structure with the information
# about where the pane should be added
pane_info = framemanager.AuiPaneInfo().Name(pane_name).Bottom().CaptionVisible(False)
self._mgr.AddPane(new_tabs, pane_info)
# Get list of tab id's and move them to pane
tab_list = tab_part[tab_part.index("=")+1:]
to_break2, active_found = False, False
while 1:
if "," not in tab_list:
to_break2 = True
tab = tab_list
else:
tab = tab_list[0:tab_list.index(",")]
tab_list = tab_list[tab_list.index(",")+1:]
# Check if this page has an 'active' marker
c = tab[0]
if c in ['+', '*']:
tab = tab[1:]
tab_idx = int(tab)
if tab_idx >= self.GetPageCount():
to_break1 = True
break
# Move tab to pane
page = self._tabs.GetPage(tab_idx)
newpage_idx = dest_tabs.GetPageCount()
dest_tabs.InsertPage(page.window, page, newpage_idx)
if c == '+':
dest_tabs.SetActivePage(newpage_idx)
active_found = True
elif c == '*':
sel_page = tab_idx
if to_break2:
break
if not active_found:
dest_tabs.SetActivePage(0)
new_tabs.DoSizing()
dest_tabs.DoShowHide()
dest_tabs.Refresh()
if to_break1:
break
tabs = tabs[tabs.index('|')+1:]
# Load the frame perspective
frames = layout[layout.index('@')+1:]
self._mgr.LoadPerspective(frames)
# Force refresh of selection
self._curpage = -1
self.SetSelection(sel_page)
return True
def SetTabCtrlHeight(self, height):
"""
Sets the tab height.
By default, the tab control height is calculated by measuring the text
height and bitmap sizes on the tab captions.
Calling this method will override that calculation and set the tab control
to the specified height parameter. A call to this method will override
any call to :meth:`SetUniformBitmapSize`. Specifying -1 as the height will
return the control to its default auto-sizing behaviour.
:param integer `height`: the tab control area height.
"""
self._requested_tabctrl_height = height
# if window is already initialized, recalculate the tab height
if self._dummy_wnd:
self.UpdateTabCtrlHeight()
def SetUniformBitmapSize(self, size):
"""
Ensures that all tabs will have the same height, even if some tabs don't have bitmaps.
Passing ``wx.DefaultSize`` to this method will instruct the control to use dynamic tab
height, which is the default behaviour. Under the default behaviour, when a tab with a
large bitmap is added, the tab control's height will automatically increase to accommodate
the larger bitmap.
:param Size `size`: the tab bitmap size.
"""
self._requested_bmp_size = wx.Size(*size)
# if window is already initialized, recalculate the tab height
if self._dummy_wnd:
self.UpdateTabCtrlHeight()
def UpdateTabCtrlHeight(self, force=False):
"""
:meth:`UpdateTabCtrlHeight` does the actual tab resizing. It's meant
to be used interally.
:param bool `force`: ``True`` to force the tab art to repaint.
"""
# get the tab ctrl height we will use
height = self.CalculateTabCtrlHeight()
# if the tab control height needs to change, update
# all of our tab controls with the new height
if self._tab_ctrl_height != height or force:
art = self._tabs.GetArtProvider()
self._tab_ctrl_height = height
all_panes = self._mgr.GetAllPanes()
for pane in all_panes:
if pane.name == "dummy":
continue
tab_frame = pane.window
tabctrl = tab_frame._tabs
tab_frame.SetTabCtrlHeight(self._tab_ctrl_height)
tabctrl.SetArtProvider(art.Clone())
tab_frame.DoSizing()
def UpdateHintWindowSize(self):
""" Updates the :class:`~lib.agw.aui.framemanager.AuiManager` hint window size. """
size = self.CalculateNewSplitSize()
# the placeholder hint window should be set to this size
info = self._mgr.GetPane("dummy")
if info.IsOk():
info.MinSize(size)
info.BestSize(size)
self._dummy_wnd.SetSize(size)
def CalculateNewSplitSize(self):
""" Calculates the size of the new split. """
# count number of tab controls
tab_ctrl_count = 0
all_panes = self._mgr.GetAllPanes()
for pane in all_panes:
if pane.name == "dummy":
continue
tab_ctrl_count += 1
# if there is only one tab control, the first split
# should happen around the middle
if tab_ctrl_count < 2:
new_split_size = self.GetClientSize()
new_split_size.x /= 2
new_split_size.y /= 2
else:
# this is in place of a more complicated calculation
# that needs to be implemented
new_split_size = wx.Size(180, 180)
return new_split_size
def CalculateTabCtrlHeight(self):
""" Calculates the tab control area height. """
# if a fixed tab ctrl height is specified,
# just return that instead of calculating a
# tab height
if self._requested_tabctrl_height != -1:
return self._requested_tabctrl_height
# find out new best tab height
art = self._tabs.GetArtProvider()
return art.GetBestTabCtrlSize(self, self._tabs.GetPages(), self._requested_bmp_size)
def GetArtProvider(self):
""" Returns the associated art provider. """
return self._tabs.GetArtProvider()
def SetAGWWindowStyleFlag(self, agwStyle):
"""
Sets the AGW-specific style of the window.
:param integer `agwStyle`: the new window style. This can be a combination of the following bits:
==================================== ==================================
Flag name Description
==================================== ==================================
``AUI_NB_TOP`` With this style, tabs are drawn along the top of the notebook
``AUI_NB_LEFT`` With this style, tabs are drawn along the left of the notebook. Not implemented yet.
``AUI_NB_RIGHT`` With this style, tabs are drawn along the right of the notebook. Not implemented yet.
``AUI_NB_BOTTOM`` With this style, tabs are drawn along the bottom of the notebook
``AUI_NB_TAB_SPLIT`` Allows the tab control to be split by dragging a tab
``AUI_NB_TAB_MOVE`` Allows a tab to be moved horizontally by dragging
``AUI_NB_TAB_EXTERNAL_MOVE`` Allows a tab to be moved to another tab control
``AUI_NB_TAB_FIXED_WIDTH`` With this style, all tabs have the same width
``AUI_NB_SCROLL_BUTTONS`` With this style, left and right scroll buttons are displayed
``AUI_NB_WINDOWLIST_BUTTON`` With this style, a drop-down list of windows is available
``AUI_NB_CLOSE_BUTTON`` With this style, a close button is available on the tab bar
``AUI_NB_CLOSE_ON_ACTIVE_TAB`` With this style, a close button is available on the active tab
``AUI_NB_CLOSE_ON_ALL_TABS`` With this style, a close button is available on all tabs
``AUI_NB_MIDDLE_CLICK_CLOSE`` Allows to close :class:`AuiNotebook` tabs by mouse middle button click
``AUI_NB_SUB_NOTEBOOK`` This style is used by :class:`~lib.agw.aui.framemanager.AuiManager` to create automatic AuiNotebooks
``AUI_NB_HIDE_ON_SINGLE_TAB`` Hides the tab window if only one tab is present
``AUI_NB_SMART_TABS`` Use Smart Tabbing, like ``Alt`` + ``Tab`` on Windows
``AUI_NB_USE_IMAGES_DROPDOWN`` Uses images on dropdown window list menu instead of check items
``AUI_NB_CLOSE_ON_TAB_LEFT`` Draws the tab close button on the left instead of on the right (a la Camino browser)
``AUI_NB_TAB_FLOAT`` Allows the floating of single tabs. Known limitation: when the notebook is more or less full screen,
tabs cannot be dragged far enough outside of the notebook to become floating pages
``AUI_NB_DRAW_DND_TAB`` Draws an image representation of a tab while dragging (on by default)
``AUI_NB_ORDER_BY_ACCESS`` Tab navigation order by last access time for the tabs
``AUI_NB_NO_TAB_FOCUS`` Don't draw tab focus rectangle
==================================== ==================================
:note: Please note that some styles cannot be changed after the window
creation and that `Refresh` might need to be be called after changing the
others for the change to take place immediately.
.. todo:: Implementation of flags ``AUI_NB_RIGHT`` and ``AUI_NB_LEFT``.
"""
self._agwFlags = agwStyle
# if the control is already initialized
if self._mgr.GetManagedWindow() == self:
# let all of the tab children know about the new style
all_panes = self._mgr.GetAllPanes()
for pane in all_panes:
if pane.name == "dummy":
continue
tabframe = pane.window
tabctrl = tabframe._tabs
tabctrl.SetAGWFlags(self._agwFlags)
tabframe.DoSizing()
tabctrl.Refresh()
tabctrl.Update()
def GetAGWWindowStyleFlag(self):
"""
Returns the AGW-specific style of the window.
:see: :meth:`SetAGWWindowStyleFlag` for a list of possible AGW-specific window styles.
"""
return self._agwFlags
def AddPage(self, page, caption, select=False, bitmap=wx.NullBitmap, disabled_bitmap=wx.NullBitmap, control=None, tooltip=""):
"""
Adds a page. If the `select` parameter is ``True``, calling this will generate a
page change event.
:param Window `page`: the page to be added;
:param string `caption`: specifies the text for the new page;
:param bool `select`: specifies whether the page should be selected;
:param Bitmap `bitmap`: the bitmap to display in the enabled tab;
:param Bitmap `disabled_bitmap`: the bitmap to display in the disabled tab;
:param Window `control`: almost any :class:`Window` -derived instance to be located
inside a tab;
:param string `tooltip`: the tooltip to display when the mouse hovers over the tab.
"""
return self.InsertPage(self.GetPageCount(), page, caption, select, bitmap, disabled_bitmap, control, tooltip)
def InsertPage(self, page_idx, page, caption, select=False, bitmap=wx.NullBitmap, disabled_bitmap=wx.NullBitmap,
control=None, tooltip=""):
"""
This is similar to :meth:`AddPage`, but allows the ability to specify the insert location.
:param integer `page_idx`: specifies the position for the new page;
:param Window `page`: the page to be added;
:param string `caption`: specifies the text for the new page;
:param bool `select`: specifies whether the page should be selected;
:param Bitmap `bitmap`: the bitmap to display in the enabled tab;
:param Bitmap `disabled_bitmap`: the bitmap to display in the disabled tab;
:param Window `control`: almost any :class:`Window` -derived instance to be located
inside a ;
:param string `tooltip`: the tooltip to display when the mouse hovers over the tab.
"""
if not page:
return False
page.Reparent(self)
info = AuiNotebookPage()
info.window = page
info.caption = caption
info.bitmap = bitmap
info.active = False
info.control = control
info.tooltip = tooltip
originalPaneMgr = framemanager.GetManager(page)
if originalPaneMgr:
originalPane = originalPaneMgr.GetPane(page)
if originalPane:
info.hasCloseButton = originalPane.HasCloseButton()
if bitmap.IsOk() and not disabled_bitmap.IsOk():
disabled_bitmap = MakeDisabledBitmap(bitmap)
info.dis_bitmap = disabled_bitmap
# if there are currently no tabs, the first added
# tab must be active
if self._tabs.GetPageCount() == 0:
info.active = True
self._tabs.InsertPage(page, info, page_idx)
# if that was the first page added, even if
# select is False, it must become the "current page"
# (though no select events will be fired)
if not select and self._tabs.GetPageCount() == 1:
select = True
active_tabctrl = self.GetActiveTabCtrl()
if page_idx >= active_tabctrl.GetPageCount():
active_tabctrl.AddPage(page, info)
else:
active_tabctrl.InsertPage(page, info, page_idx)
force = False
if control:
force = True
control.Reparent(active_tabctrl)
control.Show()
self.UpdateTabCtrlHeight(force=force)
self.DoSizing()
active_tabctrl.DoShowHide()
# adjust selected index
if self._curpage >= page_idx:
self._curpage += 1
if select:
self.SetSelectionToWindow(page)
return True
def DeletePage(self, page_idx):
"""
Deletes a page at the given index. Calling this method will generate a page
change event.
:param integer `page_idx`: the page index to be deleted.
:note:
:meth:`DeletePage` removes a tab from the multi-notebook, and destroys the window as well.
:see: :meth:`RemovePage`
"""
if page_idx >= self._tabs.GetPageCount():
return False
wnd = self._tabs.GetWindowFromIdx(page_idx)
# hide the window in advance, as this will
# prevent flicker
wnd.Show(False)
self.RemoveControlFromPage(page_idx)
if not self.RemovePage(page_idx):
return False
wnd.Destroy()
return True
def RemovePage(self, page_idx):
"""
Removes a page, without deleting the window pointer.
:param integer `page_idx`: the page index to be removed.
:note:
:meth:`RemovePage` removes a tab from the multi-notebook, but does not destroy the window.
:see: :meth:`DeletePage`
"""
# save active window pointer
active_wnd = None
if self._curpage >= 0:
active_wnd = self._tabs.GetWindowFromIdx(self._curpage)
# save pointer of window being deleted
wnd = self._tabs.GetWindowFromIdx(page_idx)
new_active = None
# make sure we found the page
if not wnd:
return False
# find out which onscreen tab ctrl owns this tab
ctrl, ctrl_idx = self.FindTab(wnd)
if not ctrl:
return False
currentPage = ctrl.GetPage(ctrl_idx)
is_curpage = (self._curpage == page_idx)
is_active_in_split = currentPage.active
# remove the tab from main catalog
if not self._tabs.RemovePage(wnd):
return False
# remove the tab from the onscreen tab ctrl
ctrl.RemovePage(wnd)
if is_active_in_split:
ctrl_new_page_count = ctrl.GetPageCount()
if ctrl_idx >= ctrl_new_page_count:
ctrl_idx = ctrl_new_page_count - 1
if ctrl_idx >= 0 and ctrl_idx < ctrl.GetPageCount():
ctrl_idx = self.FindNextActiveTab(ctrl_idx, ctrl)
# set new page as active in the tab split
ctrl.SetActivePage(ctrl_idx)
# if the page deleted was the current page for the
# entire tab control, then record the window
# pointer of the new active page for activation
if is_curpage:
new_active = ctrl.GetWindowFromIdx(ctrl_idx)
else:
# we are not deleting the active page, so keep it the same
new_active = active_wnd
if not new_active:
# we haven't yet found a new page to active,
# so select the next page from the main tab
# catalogue
if 0 <= page_idx < self._tabs.GetPageCount():
new_active = self._tabs.GetPage(page_idx).window
if not new_active and self._tabs.GetPageCount() > 0:
new_active = self._tabs.GetPage(0).window
self.RemoveEmptyTabFrames()
# set new active pane
if new_active:
if not self.IsBeingDeleted():
self._curpage = -1
self.SetSelectionToWindow(new_active)
else:
self._curpage = -1
self._tabs.SetNoneActive()
return True
def FindNextActiveTab(self, ctrl_idx, ctrl):
"""
Finds the next active tab (used mainly when :class:`AuiNotebook` has inactive/disabled
tabs in it).
:param integer `ctrl_idx`: the index of the first (most obvious) tab to check for active status;
:param `ctrl`: an instance of :class:`AuiTabCtrl`.
"""
if self.GetEnabled(ctrl_idx):
return ctrl_idx
for indx in xrange(ctrl_idx, ctrl.GetPageCount()):
if self.GetEnabled(indx):
return indx
for indx in xrange(ctrl_idx, -1, -1):
if self.GetEnabled(indx):
return indx
return 0
def HideAllTabs(self, hidden=True):
"""
Hides all tabs on the :class:`AuiNotebook` control.
:param bool `hidden`: if ``True`` hides all tabs.
"""
self._hide_tabs = hidden
def SetSashDClickUnsplit(self, unsplit=True):
"""
Sets whether to unsplit a splitted :class:`AuiNotebook` when double-clicking on a sash.
:param bool `unsplit`: ``True`` to unsplit on sash double-clicking, ``False`` otherwise.
"""
self._sash_dclick_unsplit = unsplit
def GetSashDClickUnsplit(self):
"""
Returns whether a splitted :class:`AuiNotebook` can be unsplitted by double-clicking
on the splitter sash.
"""
return self._sash_dclick_unsplit
def SetMinMaxTabWidth(self, minTabWidth, maxTabWidth):
"""
Sets the minimum and/or the maximum tab widths for :class:`AuiNotebook` when the
``AUI_NB_TAB_FIXED_WIDTH`` style is defined.
Pass -1 to either `minTabWidth` or `maxTabWidth` to reset to the default tab
width behaviour for :class:`AuiNotebook`.
:param integer `minTabWidth`: the minimum allowed tab width, in pixels;
:param integer `maxTabWidth`: the maximum allowed tab width, in pixels.
:note: Minimum and maximum tabs widths are used only when the ``AUI_NB_TAB_FIXED_WIDTH``
style is present.
"""
if minTabWidth > maxTabWidth:
raise Exception("Minimum tab width must be less or equal than maximum tab width")
self._tabBounds = (minTabWidth, maxTabWidth)
self.SetAGWWindowStyleFlag(self._agwFlags)
def GetMinMaxTabWidth(self):
"""
Returns the minimum and the maximum tab widths for :class:`AuiNotebook` when the
``AUI_NB_TAB_FIXED_WIDTH`` style is defined.
:note: Minimum and maximum tabs widths are used only when the ``AUI_NB_TAB_FIXED_WIDTH``
style is present.
:see: :meth:`SetMinMaxTabWidth` for more information.
"""
return self._tabBounds
def GetPageIndex(self, page_wnd):
"""
Returns the page index for the specified window. If the window is not
found in the notebook, ``wx.NOT_FOUND`` is returned.
:param Window `page_wnd`: the window we are looking for.
"""
return self._tabs.GetIdxFromWindow(page_wnd)
def SetPageText(self, page_idx, text):
"""
Sets the tab label for the page.
:param integer `page_idx`: the page index;
:param string `text`: the new tab label.
"""
if page_idx >= self._tabs.GetPageCount():
return False
# update our own tab catalog
page_info = self._tabs.GetPage(page_idx)
should_refresh = page_info.caption != text
page_info.caption = text
# update what's on screen
ctrl, ctrl_idx = self.FindTab(page_info.window)
if not ctrl:
return False
info = ctrl.GetPage(ctrl_idx)
should_refresh = should_refresh or info.caption != text
info.caption = text
if should_refresh:
ctrl.Refresh()
ctrl.Update()
self.UpdateTabCtrlHeight(force=True)
return True
def GetPageText(self, page_idx):
"""
Returns the tab label for the page.
:param integer `page_idx`: the page index.
"""
if page_idx >= self._tabs.GetPageCount():
return ""
# update our own tab catalog
page_info = self._tabs.GetPage(page_idx)
return page_info.caption
def SetPageBitmap(self, page_idx, bitmap):
"""
Sets the tab bitmap for the page.
:param integer `page_idx`: the page index;
:param Bitmap `bitmap`: the bitmap to display on the page tab.
"""
if page_idx >= self._tabs.GetPageCount():
return False
# update our own tab catalog
page_info = self._tabs.GetPage(page_idx)
should_refresh = page_info.bitmap is not bitmap
page_info.bitmap = bitmap
if bitmap.IsOk() and not page_info.dis_bitmap.IsOk():
page_info.dis_bitmap = MakeDisabledBitmap(bitmap)
# tab height might have changed
self.UpdateTabCtrlHeight()
# update what's on screen
ctrl, ctrl_idx = self.FindTab(page_info.window)
if not ctrl:
return False
info = ctrl.GetPage(ctrl_idx)
should_refresh = should_refresh or info.bitmap is not bitmap
info.bitmap = bitmap
info.dis_bitmap = page_info.dis_bitmap
if should_refresh:
ctrl.Refresh()
ctrl.Update()
return True
def GetPageBitmap(self, page_idx):
"""
Returns the tab bitmap for the page.
:param integer `page_idx`: the page index.
"""
if page_idx >= self._tabs.GetPageCount():
return wx.NullBitmap
# update our own tab catalog
page_info = self._tabs.GetPage(page_idx)
return page_info.bitmap
def SetPageTooltip(self, page_idx, tooltip):
"""
Sets the tab tooltip for the page.
:param integer `page_idx`: the page index;
:param string `tooltip`: the new tooltip.
:returns: ``True`` if the page tooltip has been set, ``False`` otherwise
(for example when the input `page_idx` is greater than the number of
pages in the notebook.
"""
if page_idx >= self._tabs.GetPageCount():
return False
# update our own tab catalog
page_info = self._tabs.GetPage(page_idx)
page_info.tooltip = tooltip
return True
def GetPageTooltip(self, page_idx):
"""
Returns the tab tooltip for the page.
:param integer `page_idx`: the page index.
"""
if page_idx >= self._tabs.GetPageCount():
return ""
page_info = self._tabs.GetPage(page_idx)
return page_info.tooltip
def SetImageList(self, imageList):
"""
Sets the image list for the :class:`AuiNotebook` control.
:param ImageList `imageList`: the bitmap image list to associate to :class:`AuiNotebook`.
"""
self._imageList = imageList
def AssignImageList(self, imageList):
"""
Sets the image list for the :class:`AuiNotebook` control.
:param `imageList`: an instance of :class:`ImageList`.
"""
self.SetImageList(imageList)
def GetImageList(self):
""" Returns the associated image list (if any). """
return self._imageList
def SetPageImage(self, page, image):
"""
Sets the image index for the given page.
:param integer `page`: the page index;
:param integer `image`: an index into the image list which was set with :meth:`SetImageList`.
"""
if page >= self._tabs.GetPageCount():
return False
if not isinstance(image, types.IntType):
raise Exception("The image parameter must be an integer, you passed " \
"%s"%repr(image))
if not self._imageList:
raise Exception("To use SetPageImage you need to associate an image list " \
"Using SetImageList or AssignImageList")
if image >= self._imageList.GetImageCount():
raise Exception("Invalid image index (%d), the image list contains only" \
" (%d) bitmaps"%(image, self._imageList.GetImageCount()))
if image == -1:
self.SetPageBitmap(page, wx.NullBitmap)
return
bitmap = self._imageList.GetBitmap(image)
self.SetPageBitmap(page, bitmap)
def GetPageImage(self, page):
"""
Returns the image index for the given page.
:param integer `page`: the given page for which to retrieve the image index.
"""
if page >= self._tabs.GetPageCount():
return wx.NOT_FOUND
bitmap = self.GetPageBitmap(page)
bmpData1 = bitmap.ConvertToImage().GetData()
for indx in xrange(self._imageList.GetImageCount()):
imgListBmp = self._imageList.GetBitmap(indx)
bmpData2 = imgListBmp.ConvertToImage().GetData()
if bmpData1 == bmpData2:
return indx
return wx.NOT_FOUND
def SetPageTextColour(self, page_idx, colour):
"""
Sets the tab text colour for the page.
:param integer `page_idx`: the page index;
:param Colour `colour`: the new tab label text colour.
"""
if page_idx >= self._tabs.GetPageCount():
return False
# update our own tab catalog
page_info = self._tabs.GetPage(page_idx)
should_refresh = page_info.text_colour != colour
page_info.text_colour = colour
# update what's on screen
ctrl, ctrl_idx = self.FindTab(page_info.window)
if not ctrl:
return False
info = ctrl.GetPage(ctrl_idx)
should_refresh = should_refresh or info.text_colour != colour
info.text_colour = page_info.text_colour
if should_refresh:
ctrl.Refresh()
ctrl.Update()
return True
def GetPageTextColour(self, page_idx):
"""
Returns the tab text colour for the page.
:param integer `page_idx`: the page index.
"""
if page_idx >= self._tabs.GetPageCount():
return wx.NullColour
# update our own tab catalog
page_info = self._tabs.GetPage(page_idx)
return page_info.text_colour
def AddControlToPage(self, page_idx, control):
"""
Adds a control inside a tab (not in the tab area).
:param integer `page_idx`: the page index;
:param Window `control`: almost any :class:`Window` -derived instance to be located
inside a tab.
"""
if page_idx >= self._tabs.GetPageCount():
return False
# update our own tab catalog
page_info = self._tabs.GetPage(page_idx)
page_info.control = control
# tab height might have changed
self.UpdateTabCtrlHeight(force=True)
# update what's on screen
ctrl, ctrl_idx = self.FindTab(page_info.window)
if not ctrl:
return False
control.Reparent(ctrl)
info = ctrl.GetPage(ctrl_idx)
info.control = control
ctrl.Refresh()
ctrl.Update()
return True
def RemoveControlFromPage(self, page_idx):
"""
Removes a control from a tab (not from the tab area).
:param integer `page_idx`: the page index.
"""
if page_idx >= self._tabs.GetPageCount():
return False
page_info = self._tabs.GetPage(page_idx)
if page_info.control is None:
return False
page_info.control.Destroy()
page_info.control = None
# tab height might have changed
self.UpdateTabCtrlHeight(force=True)
# update what's on screen
ctrl, ctrl_idx = self.FindTab(page_info.window)
if not ctrl:
return False
info = ctrl.GetPage(ctrl_idx)
info.control = None
ctrl.Refresh()
ctrl.Update()
return True
def SetCloseButton(self, page_idx, hasCloseButton):
"""
Sets whether a tab should display a close button or not.
:param integer `page_idx`: the page index;
:param bool `hasCloseButton`: ``True`` if the page displays a close button.
:note: This can only be called if ``AUI_NB_CLOSE_ON_ALL_TABS`` is specified.
"""
if page_idx >= self._tabs.GetPageCount():
return False
if self._agwFlags & AUI_NB_CLOSE_ON_ALL_TABS == 0:
raise Exception("SetCloseButton can only be used with AUI_NB_CLOSE_ON_ALL_TABS style.")
# update our own tab catalog
page_info = self._tabs.GetPage(page_idx)
page_info.hasCloseButton = hasCloseButton
# update what's on screen
ctrl, ctrl_idx = self.FindTab(page_info.window)
if not ctrl:
return False
info = ctrl.GetPage(ctrl_idx)
info.hasCloseButton = page_info.hasCloseButton
ctrl.Refresh()
ctrl.Update()
return True
def HasCloseButton(self, page_idx):
"""
Returns whether a tab displays a close button or not.
:param integer `page_idx`: the page index.
:note: This can only be called if ``AUI_NB_CLOSE_ON_ALL_TABS`` is specified.
"""
if page_idx >= self._tabs.GetPageCount():
return False
page_info = self._tabs.GetPage(page_idx)
return page_info.hasCloseButton
def GetSelection(self):
""" Returns the index of the currently active page, or -1 if none was selected. """
return self._curpage
def GetCurrentPage(self):
""" Returns the currently active page (not the index), or ``None`` if none was selected. """
if self._curpage >= 0 and self._curpage < self._tabs.GetPageCount():
return self.GetPage(self._curpage)
return None
def EnsureVisible(self, indx):
"""
Ensures the input page index `indx` is visible.
:param integer `indx`: the page index.
"""
self._tabs.MakeTabVisible(indx, self)
def SetSelection(self, new_page, force=False):
"""
Sets the page selection. Calling this method will generate a page change event.
:param integer `new_page`: the index of the new selection;
:param bool `force`: whether to force the selection or not.
"""
wnd = self._tabs.GetWindowFromIdx(new_page)
#Update page access time
self._tabs.GetPages()[new_page].access_time = datetime.datetime.now()
if not wnd or not self.GetEnabled(new_page):
return self._curpage
# don't change the page unless necessary
# however, clicking again on a tab should give it the focus.
if new_page == self._curpage and not force:
ctrl, ctrl_idx = self.FindTab(wnd)
if wx.Window.FindFocus() != ctrl:
ctrl.SetFocus()
return self._curpage
evt = AuiNotebookEvent(wxEVT_COMMAND_AUINOTEBOOK_PAGE_CHANGING, self.GetId())
evt.SetSelection(new_page)
evt.SetOldSelection(self._curpage)
evt.SetEventObject(self)
if not self.GetEventHandler().ProcessEvent(evt) or evt.IsAllowed():
old_curpage = self._curpage
self._curpage = new_page
# program allows the page change
evt.SetEventType(wxEVT_COMMAND_AUINOTEBOOK_PAGE_CHANGED)
self.GetEventHandler().ProcessEvent(evt)
if not evt.IsAllowed(): # event is no longer allowed after handler
return self._curpage
ctrl, ctrl_idx = self.FindTab(wnd)
if ctrl:
self._tabs.SetActivePage(wnd)
ctrl.SetActivePage(ctrl_idx)
self.DoSizing()
ctrl.DoShowHide()
ctrl.MakeTabVisible(ctrl_idx, ctrl)
# set fonts
all_panes = self._mgr.GetAllPanes()
for pane in all_panes:
if pane.name == "dummy":
continue
tabctrl = pane.window._tabs
if tabctrl != ctrl:
tabctrl.SetSelectedFont(self._normal_font)
else:
tabctrl.SetSelectedFont(self._selected_font)
tabctrl.Refresh()
tabctrl.Update()
# Set the focus to the page if we're not currently focused on the tab.
# This is Firefox-like behaviour.
if wnd.IsShownOnScreen() and wx.Window.FindFocus() != ctrl:
wnd.SetFocus()
return old_curpage
return self._curpage
def SetSelectionToWindow(self, win):
"""
Sets the selection based on the input window `win`.
:param `win`: a :class:`Window` derived window.
"""
idx = self._tabs.GetIdxFromWindow(win)
if idx == wx.NOT_FOUND:
raise Exception("invalid notebook page")
if not self.GetEnabled(idx):
return
# since a tab was clicked, let the parent know that we received
# the focus, even if we will assign that focus immediately
# to the child tab in the SetSelection call below
# (the child focus event will also let AuiManager, if any,
# know that the notebook control has been activated)
parent = self.GetParent()
if parent:
eventFocus = wx.ChildFocusEvent(self)
parent.GetEventHandler().ProcessEvent(eventFocus)
self.SetSelection(idx)
def SetSelectionToPage(self, page):
"""
Sets the selection based on the input page.
:param `page`: an instance of :class:`AuiNotebookPage`.
"""
self.SetSelectionToWindow(page.window)
def GetPageCount(self):
""" Returns the number of pages in the notebook. """
return self._tabs.GetPageCount()
def GetPage(self, page_idx):
"""
Returns the page specified by the given index.
:param integer `page_idx`: the page index.
"""
if page_idx >= self._tabs.GetPageCount():
raise Exception("invalid notebook page")
return self._tabs.GetWindowFromIdx(page_idx)
def GetPageInfo(self, page_idx):
"""
Returns the :class:`AuiNotebookPage` info structure specified by the given index.
:param integer `page_idx`: the page index.
"""
if page_idx >= self._tabs.GetPageCount():
raise Exception("invalid notebook page")
return self._tabs.GetPage(page_idx)
def GetEnabled(self, page_idx):
"""
Returns whether the page specified by the index `page_idx` is enabled.
:param integer `page_idx`: the page index.
"""
return self._tabs.GetEnabled(page_idx)
def EnableTab(self, page_idx, enable=True):
"""
Enables/disables a page in the notebook.
:param integer `page_idx`: the page index;
:param bool `enable`: ``True`` to enable the page, ``False`` to disable it.
"""
self._tabs.EnableTab(page_idx, enable)
self.Refresh()
def DoSizing(self):
""" Performs all sizing operations in each tab control. """
all_panes = self._mgr.GetAllPanes()
for pane in all_panes:
if pane.name == "dummy":
continue
tabframe = pane.window
tabframe.DoSizing()
def GetAuiManager(self):
""" Returns the associated :class:`~lib.agw.aui.framemanager.AuiManager`. """
return self._mgr
def GetActiveTabCtrl(self):
"""
Returns the active tab control. It is called to determine which control
gets new windows being added.
"""
if self._curpage >= 0 and self._curpage < self._tabs.GetPageCount():
# find the tab ctrl with the current page
ctrl, idx = self.FindTab(self._tabs.GetPage(self._curpage).window)
if ctrl:
return ctrl
# no current page, just find the first tab ctrl
all_panes = self._mgr.GetAllPanes()
for pane in all_panes:
if pane.name == "dummy":
continue
tabframe = pane.window
return tabframe._tabs
# If there is no tabframe at all, create one
tabframe = TabFrame(self)
tabframe.SetTabCtrlHeight(self._tab_ctrl_height)
self._tab_id_counter += 1
tabframe._tabs = AuiTabCtrl(self, self._tab_id_counter)
tabframe._tabs.SetAGWFlags(self._agwFlags)
tabframe._tabs.SetArtProvider(self._tabs.GetArtProvider().Clone())
self._mgr.AddPane(tabframe, framemanager.AuiPaneInfo().Center().CaptionVisible(False).
PaneBorder((self._agwFlags & AUI_NB_SUB_NOTEBOOK) == 0))
self._mgr.Update()
return tabframe._tabs
def FindTab(self, page):
"""
Finds the tab control that currently contains the window as well
as the index of the window in the tab control. It returns ``True`` if the
window was found, otherwise ``False``.
:param `page`: an instance of :class:`AuiNotebookPage`.
"""
all_panes = self._mgr.GetAllPanes()
for pane in all_panes:
if pane.name == "dummy":
continue
tabframe = pane.window
page_idx = tabframe._tabs.GetIdxFromWindow(page)
if page_idx != -1:
ctrl = tabframe._tabs
idx = page_idx
return ctrl, idx
return None, wx.NOT_FOUND
def Split(self, page, direction):
"""
Performs a split operation programmatically.
:param integer `page`: indicates the page that will be split off. This page will also become
the active page after the split.
:param integer `direction`: specifies where the pane should go, it should be one of the
following: ``wx.TOP``, ``wx.BOTTOM``, ``wx.LEFT``, or ``wx.RIGHT``.
"""
cli_size = self.GetClientSize()
# get the page's window pointer
wnd = self.GetPage(page)
if not wnd:
return
# notebooks with 1 or less pages can't be split
if self.GetPageCount() < 2:
return
# find out which tab control the page currently belongs to
src_tabs, src_idx = self.FindTab(wnd)
if not src_tabs:
return
selection = self.GetSelection()
# choose a split size
if self.GetPageCount() > 2:
split_size = self.CalculateNewSplitSize()
else:
# because there are two panes, always split them
# equally
split_size = self.GetClientSize()
split_size.x /= 2
split_size.y /= 2
# create a new tab frame
new_tabs = TabFrame(self)
new_tabs._rect = wx.RectPS(wx.Point(0, 0), split_size)
new_tabs.SetTabCtrlHeight(self._tab_ctrl_height)
self._tab_id_counter += 1
new_tabs._tabs = AuiTabCtrl(self, self._tab_id_counter)
new_tabs._tabs.SetArtProvider(self._tabs.GetArtProvider().Clone())
new_tabs._tabs.SetAGWFlags(self._agwFlags)
dest_tabs = new_tabs._tabs
page_info = src_tabs.GetPage(src_idx)
if page_info.control:
self.ReparentControl(page_info.control, dest_tabs)
cloned_buttons = self.CloneTabAreaButtons()
for clone in cloned_buttons:
dest_tabs.AddButton(clone.id, clone.location, clone.bitmap, clone.dis_bitmap)
# create a pane info structure with the information
# about where the pane should be added
pane_info = framemanager.AuiPaneInfo().Bottom().CaptionVisible(False)
if direction == wx.LEFT:
pane_info.Left()
mouse_pt = wx.Point(0, cli_size.y/2)
elif direction == wx.RIGHT:
pane_info.Right()
mouse_pt = wx.Point(cli_size.x, cli_size.y/2)
elif direction == wx.TOP:
pane_info.Top()
mouse_pt = wx.Point(cli_size.x/2, 0)
elif direction == wx.BOTTOM:
pane_info.Bottom()
mouse_pt = wx.Point(cli_size.x/2, cli_size.y)
self._mgr.AddPane(new_tabs, pane_info, mouse_pt)
self._mgr.Update()
# remove the page from the source tabs
page_info.active = False
src_tabs.RemovePage(page_info.window)
if src_tabs.GetPageCount() > 0:
if selection < 0 or selection == src_idx:
active_page = 0
else:
if selection > src_idx:
selection -= 1
active_page = selection
src_tabs.SetActivePage(active_page)
src_tabs.DoShowHide()
src_tabs.Refresh()
# add the page to the destination tabs
dest_tabs.InsertPage(page_info.window, page_info, 0)
if src_tabs.GetPageCount() == 0:
self.RemoveEmptyTabFrames()
self.DoSizing()
dest_tabs.DoShowHide()
dest_tabs.Refresh()
# force the set selection function reset the selection
self._curpage = -1
# set the active page to the one we just split off
self.SetSelectionToPage(page_info)
self.UpdateHintWindowSize()
def UnSplit(self):
""" Restores original view after a tab split. """
self.Freeze()
# remember the tab now selected
nowSelected = self.GetSelection()
# select first tab as destination
self.SetSelection(0)
# iterate all other tabs
for idx in xrange(1, self.GetPageCount()):
# get win reference
win = self.GetPage(idx)
# get tab title
title = self.GetPageText(idx)
# get page bitmap
bmp = self.GetPageBitmap(idx)
# remove from notebook
self.RemovePage(idx)
# re-add in the same position so it will tab
self.InsertPage(idx, win, title, False, bmp)
# restore orignial selected tab
self.SetSelection(nowSelected)
self.Thaw()
def ReparentControl(self, control, dest_tabs):
"""
Reparents a control added inside a tab.
:param Window `control`: almost any :class:`Window` -derived instance to be located
inside a tab;
:param `dest_tabs`: the destination :class:`AuiTabCtrl`.
"""
control.Hide()
control.Reparent(dest_tabs)
def UnsplitDClick(self, part, sash_size, pos):
"""
Unsplit the :class:`AuiNotebook` on sash double-click.
:param `part`: an UI part representing the sash;
:param integer `sash_size`: the sash size;
:param Point `pos`: the double-click mouse position.
.. warning::
Due to a bug on MSW, for disabled pages :func:`FindWindowAtPoint`
returns the wrong window. See http://trac.wxwidgets.org/ticket/2942
"""
if not self._sash_dclick_unsplit:
# Unsplit not allowed
return
pos1 = wx.Point(*pos)
pos2 = wx.Point(*pos)
if part.orientation == wx.HORIZONTAL:
pos1.y -= 2*sash_size
pos2.y += 2*sash_size + self.GetTabCtrlHeight()
elif part.orientation == wx.VERTICAL:
pos1.x -= 2*sash_size
pos2.x += 2*sash_size
else:
raise Exception("Invalid UI part orientation")
pos1, pos2 = self.ClientToScreen(pos1), self.ClientToScreen(pos2)
win1, win2 = wx.FindWindowAtPoint(pos1), wx.FindWindowAtPoint(pos2)
if isinstance(win1, wx.ScrollBar):
# Hopefully it will work
pos1 = wx.Point(*pos)
shift = wx.SystemSettings.GetMetric(wx.SYS_VSCROLL_X) + 2*(sash_size+1)
if part.orientation == wx.HORIZONTAL:
pos1.y -= shift
else:
pos1.x -= shift
pos1 = self.ClientToScreen(pos1)
win1 = wx.FindWindowAtPoint(pos1)
if isinstance(win2, wx.ScrollBar):
pos2 = wx.Point(*pos)
shift = wx.SystemSettings.GetMetric(wx.SYS_VSCROLL_X) + 2*(sash_size+1)
if part.orientation == wx.HORIZONTAL:
pos2.y += shift
else:
pos2.x += shift
pos2 = self.ClientToScreen(pos2)
win2 = wx.FindWindowAtPoint(pos2)
if not win1 or not win2:
# How did we get here?
return
if isinstance(win1, AuiNotebook) or isinstance(win2, AuiNotebook):
# This is a bug on MSW, for disabled pages wx.FindWindowAtPoint
# returns the wrong window.
# See http://trac.wxwidgets.org/ticket/2942
return
tab_frame1, tab_frame2 = self.GetTabFrameFromWindow(win1), self.GetTabFrameFromWindow(win2)
if not tab_frame1 or not tab_frame2:
return
tab_ctrl_1, tab_ctrl_2 = tab_frame1._tabs, tab_frame2._tabs
if tab_ctrl_1.GetPageCount() > tab_ctrl_2.GetPageCount():
src_tabs = tab_ctrl_2
dest_tabs = tab_ctrl_1
else:
src_tabs = tab_ctrl_1
dest_tabs = tab_ctrl_2
selection = -1
page_count = dest_tabs.GetPageCount()
for page in xrange(src_tabs.GetPageCount()-1, -1, -1):
# remove the page from the source tabs
page_info = src_tabs.GetPage(page)
if page_info.active:
selection = page_count + page
src_tabs.RemovePage(page_info.window)
# add the page to the destination tabs
dest_tabs.AddPage(page_info.window, page_info)
if page_info.control:
self.ReparentControl(page_info.control, dest_tabs)
self.RemoveEmptyTabFrames()
dest_tabs.DoShowHide()
self.DoSizing()
dest_tabs.Refresh()
self._mgr.Update()
if selection > 0:
wx.CallAfter(dest_tabs.MakeTabVisible, selection, self)
def OnSize(self, event):
"""
Handles the ``wx.EVT_SIZE`` event for :class:`AuiNotebook`.
:param `event`: a :class:`SizeEvent` event to be processed.
"""
self.UpdateHintWindowSize()
event.Skip()
def OnTabClicked(self, event):
"""
Handles the ``EVT_AUINOTEBOOK_PAGE_CHANGING`` event for :class:`AuiNotebook`.
:param `event`: a :class:`AuiNotebookEvent` event to be processed.
"""
if self._textCtrl is not None:
self._textCtrl.StopEditing()
ctrl = event.GetEventObject()
assert ctrl != None
wnd = ctrl.GetWindowFromIdx(event.GetSelection())
assert wnd != None
self.SetSelectionToWindow(wnd)
def OnTabBgDClick(self, event):
"""
Handles the ``EVT_AUINOTEBOOK_BG_DCLICK`` event for :class:`AuiNotebook`.
:param `event`: a :class:`AuiNotebookEvent` event to be processed.
"""
if self._textCtrl is not None:
self._textCtrl.StopEditing()
# notify owner that the tabbar background has been double-clicked
e = AuiNotebookEvent(wxEVT_COMMAND_AUINOTEBOOK_BG_DCLICK, self.GetId())
e.SetEventObject(self)
self.GetEventHandler().ProcessEvent(e)
def OnTabDClick(self, event):
"""
Handles the ``EVT_AUINOTEBOOK_TAB_DCLICK`` event for :class:`AuiNotebook`.
:param `event`: a :class:`AuiNotebookEvent` event to be processed.
"""
# notify owner that the tabbar background has been double-clicked
e = AuiNotebookEvent(wxEVT_COMMAND_AUINOTEBOOK_TAB_DCLICK, self.GetId())
e.SetEventObject(self)
self.GetEventHandler().ProcessEvent(e)
tabs = event.GetEventObject()
if not tabs.GetEnabled(event.GetSelection()):
return
if not self.IsRenamable(event.GetSelection()):
return
self.EditTab(event.GetSelection())
def OnTabBeginDrag(self, event):
"""
Handles the ``EVT_AUINOTEBOOK_BEGIN_DRAG`` event for :class:`AuiNotebook`.
:param `event`: a :class:`AuiNotebookEvent` event to be processed.
"""
tabs = event.GetEventObject()
if not tabs.GetEnabled(event.GetSelection()):
return
self._last_drag_x = 0
def OnTabDragMotion(self, event):
"""
Handles the ``EVT_AUINOTEBOOK_DRAG_MOTION`` event for :class:`AuiNotebook`.
:param `event`: a :class:`AuiNotebookEvent` event to be processed.
"""
self._curpage = event.GetSelection()
tabs = event.GetEventObject()
if not tabs.GetEnabled(event.GetSelection()):
return
if self._textCtrl is not None:
self._textCtrl.StopEditing()
screen_pt = wx.GetMousePosition()
client_pt = self.ScreenToClient(screen_pt)
zero = wx.Point(0, 0)
src_tabs = event.GetEventObject()
dest_tabs = self.GetTabCtrlFromPoint(client_pt)
if dest_tabs == src_tabs:
# always hide the hint for inner-tabctrl drag
self._mgr.HideHint()
# if tab moving is not allowed, leave
if not self._agwFlags & AUI_NB_TAB_MOVE:
return
pt = dest_tabs.ScreenToClient(screen_pt)
# this is an inner-tab drag/reposition
dest_location_tab = dest_tabs.TabHitTest(pt.x, pt.y)
if dest_location_tab:
src_idx = event.GetSelection()
dest_idx = dest_tabs.GetIdxFromWindow(dest_location_tab)
# prevent jumpy drag
if (src_idx == dest_idx) or dest_idx == -1 or \
(src_idx > dest_idx and self._last_drag_x <= pt.x) or \
(src_idx < dest_idx and self._last_drag_x >= pt.x):
self._last_drag_x = pt.x
return
src_tab = dest_tabs.GetWindowFromIdx(src_idx)
dest_tabs.MovePage(src_tab, dest_idx)
self._tabs.MovePage(self._tabs.GetPage(src_idx).window, dest_idx)
dest_tabs.SetActivePage(dest_idx)
dest_tabs.DoShowHide()
dest_tabs.Refresh()
self._last_drag_x = pt.x
return
# if external drag is allowed, check if the tab is being dragged
# over a different AuiNotebook control
if self._agwFlags & AUI_NB_TAB_EXTERNAL_MOVE:
tab_ctrl = wx.FindWindowAtPoint(screen_pt)
# if we aren't over any window, stop here
if not tab_ctrl:
if self._agwFlags & AUI_NB_TAB_FLOAT:
if self.IsMouseWellOutsideWindow():
hintRect = wx.RectPS(screen_pt, (400, 300))
# Use CallAfter so we overwrite the hint that might be
# shown by our superclass:
wx.CallAfter(self._mgr.ShowHint, hintRect)
return
# make sure we are not over the hint window
if not isinstance(tab_ctrl, wx.Frame):
while tab_ctrl:
if isinstance(tab_ctrl, AuiTabCtrl):
break
tab_ctrl = tab_ctrl.GetParent()
if tab_ctrl:
nb = tab_ctrl.GetParent()
if nb != self:
hint_rect = tab_ctrl.GetClientRect()
hint_rect.x, hint_rect.y = tab_ctrl.ClientToScreenXY(hint_rect.x, hint_rect.y)
self._mgr.ShowHint(hint_rect)
return
else:
if not dest_tabs:
# we are either over a hint window, or not over a tab
# window, and there is no where to drag to, so exit
return
if self._agwFlags & AUI_NB_TAB_FLOAT:
if self.IsMouseWellOutsideWindow():
hintRect = wx.RectPS(screen_pt, (400, 300))
# Use CallAfter so we overwrite the hint that might be
# shown by our superclass:
wx.CallAfter(self._mgr.ShowHint, hintRect)
return
# if there are less than two panes, split can't happen, so leave
if self._tabs.GetPageCount() < 2:
return
# if tab moving is not allowed, leave
if not self._agwFlags & AUI_NB_TAB_SPLIT:
return
if dest_tabs:
hint_rect = dest_tabs.GetRect()
hint_rect.x, hint_rect.y = self.ClientToScreenXY(hint_rect.x, hint_rect.y)
self._mgr.ShowHint(hint_rect)
else:
rect = self._mgr.CalculateHintRect(self._dummy_wnd, client_pt, zero)
if rect.IsEmpty():
self._mgr.HideHint()
return
hit_wnd = wx.FindWindowAtPoint(screen_pt)
if hit_wnd and not isinstance(hit_wnd, AuiNotebook):
tab_frame = self.GetTabFrameFromWindow(hit_wnd)
if tab_frame:
hint_rect = wx.Rect(*tab_frame._rect)
hint_rect.x, hint_rect.y = self.ClientToScreenXY(hint_rect.x, hint_rect.y)
rect.Intersect(hint_rect)
self._mgr.ShowHint(rect)
else:
self._mgr.DrawHintRect(self._dummy_wnd, client_pt, zero)
else:
self._mgr.DrawHintRect(self._dummy_wnd, client_pt, zero)
def OnTabEndDrag(self, event):
"""
Handles the ``EVT_AUINOTEBOOK_END_DRAG`` event for :class:`AuiNotebook`.
:param `event`: a :class:`AuiNotebookEvent` event to be processed.
"""
tabs = event.GetEventObject()
if not tabs.GetEnabled(event.GetSelection()):
return
self._mgr.HideHint()
src_tabs = event.GetEventObject()
if not src_tabs:
raise Exception("no source object?")
# get the mouse position, which will be used to determine the drop point
mouse_screen_pt = wx.GetMousePosition()
mouse_client_pt = self.ScreenToClient(mouse_screen_pt)
# check for an external move
if self._agwFlags & AUI_NB_TAB_EXTERNAL_MOVE:
tab_ctrl = wx.FindWindowAtPoint(mouse_screen_pt)
while tab_ctrl:
if isinstance(tab_ctrl, AuiTabCtrl):
break
tab_ctrl = tab_ctrl.GetParent()
if tab_ctrl:
nb = tab_ctrl.GetParent()
if nb != self:
# find out from the destination control
# if it's ok to drop this tab here
e = AuiNotebookEvent(wxEVT_COMMAND_AUINOTEBOOK_ALLOW_DND, self.GetId())
e.SetSelection(event.GetSelection())
e.SetOldSelection(event.GetSelection())
e.SetEventObject(self)
e.SetDragSource(self)
e.Veto() # dropping must be explicitly approved by control owner
nb.GetEventHandler().ProcessEvent(e)
if not e.IsAllowed():
# no answer or negative answer
self._mgr.HideHint()
return
# drop was allowed
src_idx = event.GetSelection()
src_page = src_tabs.GetWindowFromIdx(src_idx)
# Check that it's not an impossible parent relationship
p = nb
while p and not p.IsTopLevel():
if p == src_page:
return
p = p.GetParent()
# get main index of the page
main_idx = self._tabs.GetIdxFromWindow(src_page)
if main_idx == wx.NOT_FOUND:
raise Exception("no source page?")
# make a copy of the page info
page_info = self._tabs.GetPage(main_idx)
# remove the page from the source notebook
self.RemovePage(main_idx)
# reparent the page
src_page.Reparent(nb)
# Reparent the control in a tab (if any)
if page_info.control:
self.ReparentControl(page_info.control, tab_ctrl)
# find out the insert idx
dest_tabs = tab_ctrl
pt = dest_tabs.ScreenToClient(mouse_screen_pt)
target = dest_tabs.TabHitTest(pt.x, pt.y)
insert_idx = -1
if target:
insert_idx = dest_tabs.GetIdxFromWindow(target)
# add the page to the new notebook
if insert_idx == -1:
insert_idx = dest_tabs.GetPageCount()
dest_tabs.InsertPage(page_info.window, page_info, insert_idx)
nb._tabs.AddPage(page_info.window, page_info)
nb.DoSizing()
dest_tabs.DoShowHide()
dest_tabs.Refresh()
# set the selection in the destination tab control
nb.SetSelectionToPage(page_info)
# notify owner that the tab has been dragged
e2 = AuiNotebookEvent(wxEVT_COMMAND_AUINOTEBOOK_DRAG_DONE, self.GetId())
e2.SetSelection(event.GetSelection())
e2.SetOldSelection(event.GetSelection())
e2.SetEventObject(self)
self.GetEventHandler().ProcessEvent(e2)
# notify the target notebook that the tab has been dragged
e3 = AuiNotebookEvent(wxEVT_COMMAND_AUINOTEBOOK_DRAG_DONE, nb.GetId())
e3.SetSelection(insert_idx)
e3.SetOldSelection(insert_idx)
e3.SetEventObject(nb)
nb.GetEventHandler().ProcessEvent(e3)
return
if self._agwFlags & AUI_NB_TAB_FLOAT:
self._mgr.HideHint()
if self.IsMouseWellOutsideWindow():
# Use CallAfter so we our superclass can deal with the event first
wx.CallAfter(self.FloatPage, self.GetSelection())
event.Skip()
return
# only perform a tab split if it's allowed
dest_tabs = None
if self._agwFlags & AUI_NB_TAB_SPLIT and self._tabs.GetPageCount() >= 2:
# If the pointer is in an existing tab frame, do a tab insert
hit_wnd = wx.FindWindowAtPoint(mouse_screen_pt)
tab_frame = self.GetTabFrameFromTabCtrl(hit_wnd)
insert_idx = -1
if tab_frame:
dest_tabs = tab_frame._tabs
if dest_tabs == src_tabs:
return
pt = dest_tabs.ScreenToClient(mouse_screen_pt)
target = dest_tabs.TabHitTest(pt.x, pt.y)
if target:
insert_idx = dest_tabs.GetIdxFromWindow(target)
else:
zero = wx.Point(0, 0)
rect = self._mgr.CalculateHintRect(self._dummy_wnd, mouse_client_pt, zero)
if rect.IsEmpty():
# there is no suitable drop location here, exit out
return
# If there is no tabframe at all, create one
new_tabs = TabFrame(self)
new_tabs._rect = wx.RectPS(wx.Point(0, 0), self.CalculateNewSplitSize())
new_tabs.SetTabCtrlHeight(self._tab_ctrl_height)
self._tab_id_counter += 1
new_tabs._tabs = AuiTabCtrl(self, self._tab_id_counter)
new_tabs._tabs.SetArtProvider(self._tabs.GetArtProvider().Clone())
new_tabs._tabs.SetAGWFlags(self._agwFlags)
self._mgr.AddPane(new_tabs, framemanager.AuiPaneInfo().Bottom().CaptionVisible(False), mouse_client_pt)
self._mgr.Update()
dest_tabs = new_tabs._tabs
cloned_buttons = self.CloneTabAreaButtons()
for clone in cloned_buttons:
dest_tabs.AddButton(clone.id, clone.location, clone.bitmap, clone.dis_bitmap)
# remove the page from the source tabs
page_info = src_tabs.GetPage(event.GetSelection())
if page_info.control:
self.ReparentControl(page_info.control, dest_tabs)
page_info.active = False
src_tabs.RemovePage(page_info.window)
if src_tabs.GetPageCount() > 0:
src_tabs.SetActivePage(0)
src_tabs.DoShowHide()
src_tabs.Refresh()
# add the page to the destination tabs
if insert_idx == -1:
insert_idx = dest_tabs.GetPageCount()
dest_tabs.InsertPage(page_info.window, page_info, insert_idx)
if src_tabs.GetPageCount() == 0:
self.RemoveEmptyTabFrames()
self.DoSizing()
dest_tabs.DoShowHide()
dest_tabs.Refresh()
# force the set selection function reset the selection
self._curpage = -1
# set the active page to the one we just split off
self.SetSelectionToPage(page_info)
self.UpdateHintWindowSize()
# notify owner that the tab has been dragged
e = AuiNotebookEvent(wxEVT_COMMAND_AUINOTEBOOK_DRAG_DONE, self.GetId())
e.SetSelection(event.GetSelection())
e.SetOldSelection(event.GetSelection())
e.SetEventObject(self)
self.GetEventHandler().ProcessEvent(e)
def OnTabCancelDrag(self, event):
"""
Handles the ``EVT_AUINOTEBOOK_CANCEL_DRAG`` event for :class:`AuiNotebook`.
:param `event`: a :class:`AuiNotebookEvent` event to be processed.
"""
tabs = event.GetEventObject()
if not tabs.GetEnabled(event.GetSelection()):
return
self._mgr.HideHint()
src_tabs = event.GetEventObject()
if not src_tabs:
raise Exception("no source object?")
def IsMouseWellOutsideWindow(self):
""" Returns whether the mouse is well outside the :class:`AuiNotebook` screen rectangle. """
screen_rect = self.GetScreenRect()
screen_rect.Inflate(50, 50)
return not screen_rect.Contains(wx.GetMousePosition())
def FloatPage(self, page_index):
"""
Float the page in `page_index` by reparenting it to a floating frame.
:param integer `page_index`: the index of the page to be floated.
.. warning::
When the notebook is more or less full screen, tabs cannot be dragged far
enough outside of the notebook to become floating pages.
"""
root_manager = framemanager.GetManager(self)
page_title = self.GetPageText(page_index)
page_contents = self.GetPage(page_index)
page_bitmap = self.GetPageBitmap(page_index)
text_colour = self.GetPageTextColour(page_index)
info = self.GetPageInfo(page_index)
if root_manager and root_manager != self._mgr:
root_manager = framemanager.GetManager(self)
if hasattr(page_contents, "__floating_size__"):
floating_size = wx.Size(*page_contents.__floating_size__)
else:
floating_size = page_contents.GetBestSize()
if floating_size == wx.DefaultSize:
floating_size = wx.Size(300, 200)
page_contents.__page_index__ = page_index
page_contents.__aui_notebook__ = self
page_contents.__text_colour__ = text_colour
page_contents.__control__ = info.control
if info.control:
info.control.Reparent(page_contents)
info.control.Hide()
info.control = None
self.RemovePage(page_index)
self.RemoveEmptyTabFrames()
pane_info = framemanager.AuiPaneInfo().Float().FloatingPosition(wx.GetMousePosition()). \
FloatingSize(floating_size).BestSize(floating_size).Name("__floating__%s"%page_title). \
Caption(page_title).Icon(page_bitmap)
root_manager.AddPane(page_contents, pane_info)
root_manager.Bind(framemanager.EVT_AUI_PANE_CLOSE, self.OnCloseFloatingPage)
self.GetActiveTabCtrl().DoShowHide()
self.DoSizing()
root_manager.Update()
else:
frame = wx.Frame(self, title=page_title,
style=wx.DEFAULT_FRAME_STYLE|wx.FRAME_TOOL_WINDOW|
wx.FRAME_FLOAT_ON_PARENT | wx.FRAME_NO_TASKBAR)
if info.control:
info.control.Reparent(frame)
info.control.Hide()
frame.bitmap = page_bitmap
frame.page_index = page_index
frame.text_colour = text_colour
frame.control = info.control
page_contents.Reparent(frame)
frame.Bind(wx.EVT_CLOSE, self.OnCloseFloatingPage)
frame.Move(wx.GetMousePosition())
frame.Show()
self.RemovePage(page_index)
self.RemoveEmptyTabFrames()
wx.CallAfter(self.RemoveEmptyTabFrames)
def OnCloseFloatingPage(self, event):
"""
Handles the ``wx.EVT_CLOSE`` event for a floating page in :class:`AuiNotebook`.
:param `event`: a :class:`CloseEvent` event to be processed.
"""
root_manager = framemanager.GetManager(self)
if root_manager and root_manager != self._mgr:
pane = event.pane
if pane.name.startswith("__floating__"):
self.ReDockPage(pane)
return
event.Skip()
else:
event.Skip()
frame = event.GetEventObject()
page_title = frame.GetTitle()
page_contents = list(frame.GetChildren())[-1]
page_contents.Reparent(self)
self.InsertPage(frame.page_index, page_contents, page_title, select=True, bitmap=frame.bitmap, control=frame.control)
if frame.control:
src_tabs, idx = self.FindTab(page_contents)
frame.control.Reparent(src_tabs)
frame.control.Hide()
frame.control = None
self.SetPageTextColour(frame.page_index, frame.text_colour)
def ReDockPage(self, pane):
"""
Re-docks a floating :class:`AuiNotebook` tab in the original position, when possible.
:param `pane`: an instance of :class:`~lib.agw.aui.framemanager.AuiPaneInfo`.
"""
root_manager = framemanager.GetManager(self)
pane.window.__floating_size__ = wx.Size(*pane.floating_size)
page_index = pane.window.__page_index__
text_colour = pane.window.__text_colour__
control = pane.window.__control__
root_manager.DetachPane(pane.window)
self.InsertPage(page_index, pane.window, pane.caption, True, pane.icon, control=control)
self.SetPageTextColour(page_index, text_colour)
self.GetActiveTabCtrl().DoShowHide()
self.DoSizing()
if control:
self.UpdateTabCtrlHeight(force=True)
self._mgr.Update()
root_manager.Update()
def GetTabCtrlFromPoint(self, pt):
"""
Returns the tab control at the specified point.
:param Point `pt`: the mouse location.
"""
# if we've just removed the last tab from the source
# tab set, the remove the tab control completely
all_panes = self._mgr.GetAllPanes()
for pane in all_panes:
if pane.name == "dummy":
continue
tabframe = pane.window
if tabframe._tab_rect.Contains(pt):
return tabframe._tabs
return None
def GetTabFrameFromTabCtrl(self, tab_ctrl):
"""
Returns the tab frame associated with a tab control.
:param `tab_ctrl`: an instance of :class:`AuiTabCtrl`.
"""
# if we've just removed the last tab from the source
# tab set, the remove the tab control completely
all_panes = self._mgr.GetAllPanes()
for pane in all_panes:
if pane.name == "dummy":
continue
tabframe = pane.window
if tabframe._tabs == tab_ctrl:
return tabframe
return None
def GetTabFrameFromWindow(self, wnd):
"""
Returns the tab frame associated with a window.
:param Window `wnd`: the window for which we want to locate the :class:`TabFrame`.
"""
all_panes = self._mgr.GetAllPanes()
for pane in all_panes:
if pane.name == "dummy":
continue
tabframe = pane.window
for page in tabframe._tabs.GetPages():
if wnd == page.window:
return tabframe
return None
def RemoveEmptyTabFrames(self):
""" Removes all the empty tab frames. """
# if we've just removed the last tab from the source
# tab set, the remove the tab control completely
all_panes = self._mgr.GetAllPanes()
for indx in xrange(len(all_panes)-1, -1, -1):
pane = all_panes[indx]
if pane.name == "dummy":
continue
tab_frame = pane.window
if tab_frame._tabs.GetPageCount() == 0:
self._mgr.DetachPane(tab_frame)
tab_frame._tabs.Destroy()
tab_frame._tabs = None
del tab_frame
# check to see if there is still a center pane
# if there isn't, make a frame the center pane
first_good = None
center_found = False
all_panes = self._mgr.GetAllPanes()
for pane in all_panes:
if pane.name == "dummy":
continue
if pane.dock_direction == AUI_DOCK_CENTRE:
center_found = True
if not first_good:
first_good = pane.window
if not center_found and first_good:
self._mgr.GetPane(first_good).Centre()
if not self.IsBeingDeleted():
self._mgr.Update()
def OnChildFocusNotebook(self, event):
"""
Handles the ``wx.EVT_CHILD_FOCUS`` event for :class:`AuiNotebook`.
:param `event`: a :class:`ChildFocusEvent` event to be processed.
"""
# if we're dragging a tab, don't change the current selection.
# This code prevents a bug that used to happen when the hint window
# was hidden. In the bug, the focus would return to the notebook
# child, which would then enter this handler and call
# SetSelection, which is not desired turn tab dragging.
event.Skip()
all_panes = self._mgr.GetAllPanes()
for pane in all_panes:
if pane.name == "dummy":
continue
tabframe = pane.window
if tabframe._tabs.IsDragging():
return
## # change the tab selection to the child
## # which was focused
## idx = self._tabs.GetIdxFromWindow(event.GetWindow())
## if idx != -1 and idx != self._curpage:
## self.SetSelection(idx)
def SetNavigatorIcon(self, bmp):
"""
Sets the icon used by the :class:`TabNavigatorWindow`.
:param Bitmap `bmp`: the new bitmap for the :class:`TabNavigatorWindow`.
"""
if isinstance(bmp, wx.Bitmap) and bmp.IsOk():
self.NavigatorProps.Icon = bmp
else:
raise TypeError("SetNavigatorIcon requires a valid bitmap")
def OnNavigationKeyNotebook(self, event):
"""
Handles the ``wx.EVT_NAVIGATION_KEY`` event for :class:`AuiNotebook`.
:param `event`: a :class:`NavigationKeyEvent` event to be processed.
"""
if event.IsWindowChange():
if self._agwFlags & AUI_NB_SMART_TABS:
if not self._popupWin:
self._popupWin = TabNavigatorWindow(self, self.NavigatorProps)
self._popupWin.SetReturnCode(wx.ID_OK)
self._popupWin.ShowModal()
idx = self._popupWin.GetSelectedPage()
self._popupWin.Destroy()
self._popupWin = None
# Need to do CallAfter so that the selection and its
# associated events get processed outside the context of
# this key event. Not doing so causes odd issues with the
# window focus under certain use cases on Windows.
wx.CallAfter(self.SetSelection, idx, True)
else:
# a dialog is already opened
self._popupWin.OnNavigationKey(event)
return
else:
# change pages
# FIXME: the problem with this is that if we have a split notebook,
# we selection may go all over the place.
self.AdvanceSelection(event.GetDirection())
else:
# we get this event in 3 cases
#
# a) one of our pages might have generated it because the user TABbed
# out from it in which case we should propagate the event upwards and
# our parent will take care of setting the focus to prev/next sibling
#
# or
#
# b) the parent panel wants to give the focus to us so that we
# forward it to our selected page. We can't deal with this in
# OnSetFocus() because we don't know which direction the focus came
# from in this case and so can't choose between setting the focus to
# first or last panel child
#
# or
#
# c) we ourselves (see MSWTranslateMessage) generated the event
#
parent = self.GetParent()
# the wxObject* casts are required to avoid MinGW GCC 2.95.3 ICE
isFromParent = event.GetEventObject() == parent
isFromSelf = event.GetEventObject() == self
if isFromParent or isFromSelf:
# no, it doesn't come from child, case (b) or (c): forward to a
# page but only if direction is backwards (TAB) or from ourselves,
if self.GetSelection() != wx.NOT_FOUND and (not event.GetDirection() or isFromSelf):
# so that the page knows that the event comes from it's parent
# and is being propagated downwards
event.SetEventObject(self)
page = self.GetPage(self.GetSelection())
if not page.GetEventHandler().ProcessEvent(event):
page.SetFocus()
#else: page manages focus inside it itself
else: # otherwise set the focus to the notebook itself
self.SetFocus()
else:
# send this event back for the 'wraparound' focus.
winFocus = event.GetCurrentFocus()
if winFocus:
event.SetEventObject(self)
winFocus.GetEventHandler().ProcessEvent(event)
def OnTabButton(self, event):
"""
Handles the ``EVT_AUINOTEBOOK_BUTTON`` event for :class:`AuiNotebook`.
:param `event`: a :class:`AuiNotebookEvent` event to be processed.
"""
tabs = event.GetEventObject()
button_id = event.GetInt()
if button_id == AUI_BUTTON_CLOSE:
selection = event.GetSelection()
if selection == -1:
# if the close button is to the right, use the active
# page selection to determine which page to close
selection = tabs.GetActivePage()
if selection == -1 or not tabs.GetEnabled(selection):
return
if selection != -1:
close_wnd = tabs.GetWindowFromIdx(selection)
if close_wnd.GetName() == "__fake__page__":
# This is a notebook preview
previous_active, page_status = close_wnd.__previousStatus
for page, status in zip(tabs.GetPages(), page_status):
page.enabled = status
main_idx = self._tabs.GetIdxFromWindow(close_wnd)
self.DeletePage(main_idx)
if previous_active >= 0:
tabs.SetActivePage(previous_active)
page_count = tabs.GetPageCount()
selection = -1
for page in xrange(page_count):
# remove the page from the source tabs
page_info = tabs.GetPage(page)
if page_info.active:
selection = page
break
tabs.DoShowHide()
self.DoSizing()
tabs.Refresh()
if selection >= 0:
wx.CallAfter(tabs.MakeTabVisible, selection, self)
# Don't fire the event
return
# ask owner if it's ok to close the tab
e = AuiNotebookEvent(wxEVT_COMMAND_AUINOTEBOOK_PAGE_CLOSE, self.GetId())
idx = self._tabs.GetIdxFromWindow(close_wnd)
e.SetSelection(idx)
e.SetOldSelection(event.GetSelection())
e.SetEventObject(self)
self.GetEventHandler().ProcessEvent(e)
if not e.IsAllowed():
return
if repr(close_wnd.__class__).find("AuiMDIChildFrame") >= 0:
close_wnd.Close()
else:
main_idx = self._tabs.GetIdxFromWindow(close_wnd)
self.DeletePage(main_idx)
# notify owner that the tab has been closed
e2 = AuiNotebookEvent(wxEVT_COMMAND_AUINOTEBOOK_PAGE_CLOSED, self.GetId())
e2.SetSelection(idx)
e2.SetEventObject(self)
self.GetEventHandler().ProcessEvent(e2)
if self.GetPageCount() == 0:
mgr = self.GetAuiManager()
win = mgr.GetManagedWindow()
win.SendSizeEvent()
def OnTabMiddleDown(self, event):
"""
Handles the ``EVT_AUINOTEBOOK_TAB_MIDDLE_DOWN`` event for :class:`AuiNotebook`.
:param `event`: a :class:`AuiNotebookEvent` event to be processed.
"""
tabs = event.GetEventObject()
if not tabs.GetEnabled(event.GetSelection()):
return
# patch event through to owner
wnd = tabs.GetWindowFromIdx(event.GetSelection())
e = AuiNotebookEvent(wxEVT_COMMAND_AUINOTEBOOK_TAB_MIDDLE_DOWN, self.GetId())
e.SetSelection(self._tabs.GetIdxFromWindow(wnd))
e.SetEventObject(self)
self.GetEventHandler().ProcessEvent(e)
def OnTabMiddleUp(self, event):
"""
Handles the ``EVT_AUINOTEBOOK_TAB_MIDDLE_UP`` event for :class:`AuiNotebook`.
:param `event`: a :class:`AuiNotebookEvent` event to be processed.
"""
tabs = event.GetEventObject()
if not tabs.GetEnabled(event.GetSelection()):
return
# if the AUI_NB_MIDDLE_CLICK_CLOSE is specified, middle
# click should act like a tab close action. However, first
# give the owner an opportunity to handle the middle up event
# for custom action
wnd = tabs.GetWindowFromIdx(event.GetSelection())
e = AuiNotebookEvent(wxEVT_COMMAND_AUINOTEBOOK_TAB_MIDDLE_UP, self.GetId())
e.SetSelection(self._tabs.GetIdxFromWindow(wnd))
e.SetEventObject(self)
if self.GetEventHandler().ProcessEvent(e):
return
if not e.IsAllowed():
return
# check if we are supposed to close on middle-up
if self._agwFlags & AUI_NB_MIDDLE_CLICK_CLOSE == 0:
return
# simulate the user pressing the close button on the tab
event.SetInt(AUI_BUTTON_CLOSE)
self.OnTabButton(event)
def OnTabRightDown(self, event):
"""
Handles the ``EVT_AUINOTEBOOK_TAB_RIGHT_DOWN`` event for :class:`AuiNotebook`.
:param `event`: a :class:`AuiNotebookEvent` event to be processed.
"""
tabs = event.GetEventObject()
if not tabs.GetEnabled(event.GetSelection()):
return
# patch event through to owner
wnd = tabs.GetWindowFromIdx(event.GetSelection())
e = AuiNotebookEvent(wxEVT_COMMAND_AUINOTEBOOK_TAB_RIGHT_DOWN, self.GetId())
e.SetSelection(self._tabs.GetIdxFromWindow(wnd))
e.SetEventObject(self)
self.GetEventHandler().ProcessEvent(e)
def OnTabRightUp(self, event):
"""
Handles the ``EVT_AUINOTEBOOK_TAB_RIGHT_UP`` event for :class:`AuiNotebook`.
:param `event`: a :class:`AuiNotebookEvent` event to be processed.
"""
tabs = event.GetEventObject()
if not tabs.GetEnabled(event.GetSelection()):
return
# patch event through to owner
wnd = tabs.GetWindowFromIdx(event.GetSelection())
e = AuiNotebookEvent(wxEVT_COMMAND_AUINOTEBOOK_TAB_RIGHT_UP, self.GetId())
e.SetSelection(self._tabs.GetIdxFromWindow(wnd))
e.SetEventObject(self)
self.GetEventHandler().ProcessEvent(e)
def SetNormalFont(self, font):
"""
Sets the normal font for drawing tab labels.
:param Font `font`: the new font to use to draw tab labels in their normal, un-selected state.
"""
self._normal_font = font
self.GetArtProvider().SetNormalFont(font)
def SetSelectedFont(self, font):
"""
Sets the selected tab font for drawing tab labels.
:param Font `font`: the new font to use to draw tab labels in their selected state.
"""
self._selected_font = font
self.GetArtProvider().SetSelectedFont(font)
def SetMeasuringFont(self, font):
"""
Sets the font for calculating text measurements.
:param Font `font`: the new font to use to measure tab label text extents.
"""
self.GetArtProvider().SetMeasuringFont(font)
def SetFont(self, font):
"""
Sets the tab font.
:param Font `font`: the new font to use to draw tab labels in their normal, un-selected state.
:note: Overridden from :class:`PyPanel`.
"""
wx.PyPanel.SetFont(self, font)
selectedFont = wx.Font(font.GetPointSize(), font.GetFamily(),
font.GetStyle(), wx.BOLD, font.GetUnderlined(),
font.GetFaceName(), font.GetEncoding())
self.SetNormalFont(font)
self.SetSelectedFont(selectedFont)
self.SetMeasuringFont(selectedFont)
# Recalculate tab container size based on new font
self.UpdateTabCtrlHeight(force=False)
self.DoSizing()
return True
def GetTabCtrlHeight(self):
""" Returns the tab control height. """
return self._tab_ctrl_height
def GetHeightForPageHeight(self, pageHeight):
"""
Gets the height of the notebook for a given page height.
:param integer `pageHeight`: the given page height.
"""
self.UpdateTabCtrlHeight()
tabCtrlHeight = self.GetTabCtrlHeight()
decorHeight = 2
return tabCtrlHeight + pageHeight + decorHeight
def AdvanceSelection(self, forward=True, wrap=True):
"""
Cycles through the tabs.
:param bool `forward`: whether to advance forward or backward;
:param bool `wrap`: ``True`` to return to the first tab if we reach the last tab.
:note: The call to this function generates the page changing events.
"""
tabCtrl = self.GetActiveTabCtrl()
newPage = -1
focusWin = wx.Window.FindFocus()
activePage = tabCtrl.GetActivePage()
lenPages = len(tabCtrl.GetPages())
if lenPages == 1:
return False
if forward:
if lenPages > 1:
if activePage == -1 or activePage == lenPages - 1:
if not wrap:
return False
newPage = 0
elif activePage < lenPages - 1:
newPage = activePage + 1
else:
if lenPages > 1:
if activePage == -1 or activePage == 0:
if not wrap:
return False
newPage = lenPages - 1
elif activePage > 0:
newPage = activePage - 1
if newPage != -1:
if not self.GetEnabled(newPage):
return False
e = AuiNotebookEvent(wxEVT_COMMAND_AUINOTEBOOK_PAGE_CHANGING, tabCtrl.GetId())
e.SetSelection(newPage)
e.SetOldSelection(activePage)
e.SetEventObject(tabCtrl)
self.GetEventHandler().ProcessEvent(e)
## if focusWin:
## focusWin.SetFocus()
return True
def ShowWindowMenu(self):
"""
Shows the window menu for the active tab control associated with this
notebook, and returns ``True`` if a selection was made.
"""
tabCtrl = self.GetActiveTabCtrl()
idx = tabCtrl.GetArtProvider().ShowDropDown(tabCtrl, tabCtrl.GetPages(), tabCtrl.GetActivePage())
if not self.GetEnabled(idx):
return False
if idx != -1:
e = AuiNotebookEvent(wxEVT_COMMAND_AUINOTEBOOK_PAGE_CHANGING, tabCtrl.GetId())
e.SetSelection(idx)
e.SetOldSelection(tabCtrl.GetActivePage())
e.SetEventObject(tabCtrl)
self.GetEventHandler().ProcessEvent(e)
return True
else:
return False
def AddTabAreaButton(self, id, location, normal_bitmap=wx.NullBitmap, disabled_bitmap=wx.NullBitmap, name=""):
"""
Adds a button in the tab area.
:param integer `id`: the button identifier. This can be one of the following:
============================== =================================
Button Identifier Description
============================== =================================
``AUI_BUTTON_CLOSE`` Shows a close button on the tab area
``AUI_BUTTON_WINDOWLIST`` Shows a window list button on the tab area
``AUI_BUTTON_LEFT`` Shows a left button on the tab area
``AUI_BUTTON_RIGHT`` Shows a right button on the tab area
============================== =================================
:param integer `location`: the button location. Can be ``wx.LEFT`` or ``wx.RIGHT``;
:param Bitmap `normal_bitmap`: the bitmap for an enabled tab;
:param Bitmap `disabled_bitmap`: the bitmap for a disabled tab;
:param string `name`: the button name.
"""
active_tabctrl = self.GetActiveTabCtrl()
active_tabctrl.AddButton(id, location, normal_bitmap, disabled_bitmap, name=name)
def RemoveTabAreaButton(self, id):
"""
Removes a button from the tab area.
:param integer `id`: the button identifier.
:see: :meth:`AddTabAreaButton` for a list of button identifiers.
"""
active_tabctrl = self.GetActiveTabCtrl()
active_tabctrl.RemoveButton(id)
def CloneTabAreaButtons(self):
"""
Clones the tab area buttons when the :class:`AuiNotebook` is being split.
:see: :meth:`AddTabAreaButton`
:note: Standard buttons for :class:`AuiNotebook` are not cloned, only custom ones.
"""
active_tabctrl = self.GetActiveTabCtrl()
clones = active_tabctrl.CloneButtons()
return clones
def HasMultiplePages(self):
"""
This method should be overridden to return ``True`` if this window has multiple pages. All
standard class with multiple pages such as :class:`Notebook`, :class:`Listbook` and :class:`Treebook`
already override it to return ``True`` and user-defined classes with similar behaviour
should do it as well to allow the library to handle such windows appropriately.
:note: Overridden from :class:`PyPanel`.
"""
return True
def GetDefaultBorder(self):
""" Returns the default border style for :class:`AuiNotebook`. """
return wx.BORDER_NONE
def NotebookPreview(self, thumbnail_size=200):
"""
Generates a preview of all the pages in the notebook (MSW and GTK only).
:param integer `thumbnail_size`: the maximum size of every page thumbnail
(default=200 pixels).
:note: this functionality is currently unavailable on wxMAC.
"""
if wx.Platform == "__WXMAC__":
return False
tabCtrl = self.GetActiveTabCtrl()
activePage = tabCtrl.GetActivePage()
pages = tabCtrl.GetPages()
pageStatus, pageText = [], []
for indx, page in enumerate(pages):
pageStatus.append(page.enabled)
if not page.enabled:
continue
self.SetSelectionToPage(page)
pageText.append(page.caption)
rect = page.window.GetScreenRect()
bmp = RescaleScreenShot(TakeScreenShot(rect), thumbnail_size)
page.enabled = False
if indx == 0:
il = wx.ImageList(bmp.GetWidth(), bmp.GetHeight(), True)
il.Add(bmp)
# create the list control
listCtrl = wx.ListCtrl(self, style=wx.LC_ICON|wx.LC_AUTOARRANGE|wx.LC_HRULES|wx.LC_VRULES,
name="__fake__page__")
# assign the image list to it
listCtrl.AssignImageList(il, wx.IMAGE_LIST_NORMAL)
listCtrl.__previousStatus = [activePage, pageStatus]
# create some items for the list
for indx, text in enumerate(pageText):
listCtrl.InsertImageStringItem(10000, text, indx)
self.AddPage(listCtrl, "AuiNotebook Preview", True, bitmap=auinotebook_preview.GetBitmap(), disabled_bitmap=wx.NullBitmap)
return True
def SetRenamable(self, page_idx, renamable):
"""
Sets whether a tab can be renamed via a left double-click or not.
:param integer `page_idx`: the page index;
:param bool `renamable`: ``True`` if the page can be renamed.
"""
if page_idx >= self._tabs.GetPageCount():
return False
# update our own tab catalog
page_info = self._tabs.GetPage(page_idx)
page_info.renamable = renamable
# update what's on screen
ctrl, ctrl_idx = self.FindTab(page_info.window)
if not ctrl:
return False
info = ctrl.GetPage(ctrl_idx)
info.renamable = page_info.renamable
return True
def IsRenamable(self, page_idx):
"""
Returns whether a tab can be renamed or not.
:param integer `page_idx`: the page index.
:returns: ``True`` is a page can be renamed, ``False`` otherwise.
"""
if page_idx >= self._tabs.GetPageCount():
return False
page_info = self._tabs.GetPage(page_idx)
return page_info.renamable
def OnRenameCancelled(self, page_index):
"""
Called by :class:`TabTextCtrl`, to cancel the changes and to send the
``EVT_AUINOTEBOOK_END_LABEL_EDIT`` event.
:param integer `page_index`: the page index in the notebook.
"""
# let owner know that the edit was cancelled
evt = AuiNotebookEvent(wxEVT_COMMAND_AUINOTEBOOK_END_LABEL_EDIT, self.GetId())
evt.SetSelection(page_index)
evt.SetEventObject(self)
evt.SetLabel("")
evt.SetEditCanceled(True)
self.GetEventHandler().ProcessEvent(evt)
def OnRenameAccept(self, page_index, value):
"""
Called by :class:`TabTextCtrl`, to accept the changes and to send the
``EVT_AUINOTEBOOK_END_LABEL_EDIT`` event.
:param integer `page_index`: the page index in the notebook;
:param string `value`: the new label for the tab.
"""
evt = AuiNotebookEvent(wxEVT_COMMAND_AUINOTEBOOK_END_LABEL_EDIT, self.GetId())
evt.SetSelection(page_index)
evt.SetEventObject(self)
evt.SetLabel(value)
evt.SetEditCanceled(False)
return not self.GetEventHandler().ProcessEvent(evt) or evt.IsAllowed()
def ResetTextControl(self):
""" Called by :class:`TabTextCtrl` when it marks itself for deletion. """
if not self._textCtrl:
return
self._textCtrl.Destroy()
self._textCtrl = None
# tab height might have changed
self.UpdateTabCtrlHeight(force=True)
def EditTab(self, page_index):
"""
Starts the editing of an item label, sending a ``EVT_AUINOTEBOOK_BEGIN_LABEL_EDIT`` event.
:param integer `page_index`: the page index we want to edit.
"""
if page_index >= self._tabs.GetPageCount():
return False
if not self.IsRenamable(page_index):
return False
page_info = self._tabs.GetPage(page_index)
ctrl, ctrl_idx = self.FindTab(page_info.window)
if not ctrl:
return False
evt = AuiNotebookEvent(wxEVT_COMMAND_AUINOTEBOOK_BEGIN_LABEL_EDIT, self.GetId())
evt.SetSelection(page_index)
evt.SetEventObject(self)
if self.GetEventHandler().ProcessEvent(evt) and not evt.IsAllowed():
# vetoed by user
return False
if self._textCtrl is not None and page_info != self._textCtrl.item():
self._textCtrl.StopEditing()
self._textCtrl = TabTextCtrl(ctrl, page_info, page_index)
self._textCtrl.SetFocus()
return True
|