/usr/share/pyshared/fltk/test/tree.py is in python-fltk 1.3.0-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 | #! /usr/bin/env python
#
# "$Id: tree.py 473 2011-01-25 21:49:20Z andreasheld $"
#
# Tree widget test program for pyFLTK the Python bindings
# for the Fast Light Tool Kit (FLTK).
#
# FLTK copyright 1998-1999 by Bill Spitzak and others.
# pyFLTK copyright 2003 by Andreas Held and others.
#
# This library is free software you can redistribute it and/or
# modify it under the terms of the GNU Library General Public
# License as published by the Free Software Foundation either
# version 2 of the License, or (at your option) any later version.
#
# This library is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# Library General Public License for more details.
#
# You should have received a copy of the GNU Library General Public
# License along with this library if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
# USA.
#
# Please report all bugs and problems to "pyfltk-user@lists.sourceforge.net".
#
"""
Tree test program.
"""
import traceback, sys
from fltk import *
G_cb_counter = 0
but = None
grp = None
def reason_as_name(reason):
if reason == FL_TREE_REASON_NONE:
return "none"
elif reason == FL_TREE_REASON_SELECTED:
return "selected"
elif reason == FL_TREE_REASON_DESELECTED:
return "deselected"
elif reason == FL_TREE_REASON_OPENED:
return "opened"
elif reason == FL_TREE_REASON_CLOSED:
return "closed"
else:
return "???"
def Button_CB(w):
print "'%s' button pushed\n"%w.label()
def RebuildTree(tree):
global but, grp
# REBUILD THE TREE TO MAKE CURRENT "DEFAULT" PREFS TAKE EFFECT
tree.clear()
tree.add("Aaa")
tree.add("Bbb")
tree.add("Ccc")
tree.add("Ddd")
tree.add("Bbb/child-01")
tree.add("Bbb/child-01/111")
tree.add("Bbb/child-01/222")
tree.add("Bbb/child-01/333")
tree.add("Bbb/child-02")
tree.add("Bbb/child-03")
tree.add("Bbb/child-04")
# Assign an FLTK widget to one of the items
i = tree.find_item("Bbb/child-03")
if i != None:
if but == None: # only do this once at program startup
tree.begin()
but = Fl_Button(1,1,140,1,"ccc button") # we control w() only
but.labelsize(10)
but.callback(Button_CB)
i.widget(but)
tree.end()
# Assign an FLTK group to one of the items with widgets
i = tree.find_item("Bbb/child-04")
if i != None:
if grp == None: # only do this once at program startup
tree.begin()
grp = Fl_Group(100,100,140,18) # build group.. tree handles position
grp.color(FL_WHITE);
grp.begin()
abut = Fl_Button(grp.x()+0 ,grp.y()+2,65,15,"D1")
abut.labelsize(10)
abut.callback(Button_CB)
bbut = Fl_Button(grp.x()+75,grp.y()+2,65,15,"D2")
bbut.labelsize(10)
bbut.callback(Button_CB)
grp.end()
grp.resizable(grp)
tree.end()
i.widget(grp);
# Add an 'Ascending' node, and create it sorted
tree.sortorder(FL_TREE_SORT_NONE)
tree.add("Ascending").close()
tree.sortorder(FL_TREE_SORT_ASCENDING)
tree.add("Ascending/Zzz")
tree.add("Ascending/Xxx")
tree.add("Ascending/Aaa")
tree.add("Ascending/Bbb")
tree.add("Ascending/Yyy")
tree.add("Ascending/Ccc")
# Add a 'Descending' node, and create it sorted
tree.sortorder(FL_TREE_SORT_NONE)
tree.add("Descending").close()
tree.sortorder(FL_TREE_SORT_DESCENDING)
tree.add("Descending/Zzz")
tree.add("Descending/Xxx")
tree.add("Descending/Aaa")
tree.add("Descending/Bbb")
tree.add("Descending/Yyy")
tree.add("Descending/Ccc")
# Add 500 items in numerical order
tree.sortorder(FL_TREE_SORT_NONE);
for t in range(500):
s = "500 Items/item %04d"%t
tree.add(s)
tree.close("500 Items") # close the 500 items by default
tree.redraw()
def cb_tree(tree, data):
global G_cb_counter
# Increment callback counter whenever tree callback is invoked
G_cb_counter = G_cb_counter+1
item = tree.callback_item()
if item:
print "TREE CALLBACK: label='%s' userdata=%ld reason=%s\n"%(
item.label(),
data,
reason_as_name(tree.callback_reason()))
else:
print "TREE CALLBACK: reason=%s item=(no item -- probably multiple items were changed at once)\n"%(
reason_as_name(tree.callback_reason()))
def cb_margintop_slider(margintop_slider, tree):
val = int(margintop_slider.value())
tree.margintop(val)
tree.redraw()
def cb_marginleft_slider(marginleft_slider, tree):
val = int(marginleft_slider.value())
tree.marginleft(val)
tree.redraw()
def cb_openchild_marginbottom_slider(openchild_marginbottom_slider, tree):
val = int(openchild_marginbottom_slider.value())
tree.openchild_marginbottom(val)
tree.redraw()
def cb_labelsize_slider(labelsize_slider, tree):
size = int(labelsize_slider.value())
count = 0
item = tree.first()
while item != None:
if item.is_selected():
item.labelsize(size)
count = count+1
item = tree.next(item)
if count == 0:
item = tree.first()
while item != None:
item.labelsize(size)
item = tree.next(item)
tree.redraw()
def cb_connectorwidth_slider(connectorwidth_slider, tree):
val = int(connectorwidth_slider.value())
tree.connectorwidth(val)
#tree.redraw()
L_folderpixmap = None
L_documentpixmap = None
def cb_usericon_radio(usericon_radio, tree):
global L_folderpixmap, L_documentpixmap
L_folder_xpm = [
"11 11 3 1",
". c None",
"x c #d8d833",
"@ c #808011",
"...........",
".....@@@@..",
"....@xxxx@.",
"@@@@@xxxx@@",
"@xxxxxxxxx@",
"@xxxxxxxxx@",
"@xxxxxxxxx@",
"@xxxxxxxxx@",
"@xxxxxxxxx@",
"@xxxxxxxxx@",
"@@@@@@@@@@@"]
L_folderpixmap = Fl_Pixmap(L_folder_xpm)
L_document_xpm = [
"11 11 3 1",
". c None",
"x c #d8d8f8",
"@ c #202060",
".@@@@@@@@@.",
".@xxxxxxx@.",
".@xxxxxxx@.",
".@xxxxxxx@.",
".@xxxxxxx@.",
".@xxxxxxx@.",
".@xxxxxxx@.",
".@xxxxxxx@.",
".@xxxxxxx@.",
".@xxxxxxx@.",
".@@@@@@@@@."]
L_documentpixmap = Fl_Pixmap(L_document_xpm)
i = None
if usericon_radio.value() != 0.0:
tree.usericon(L_folderpixmap)
i = tree.find_item("Bbb/bgb/111")
if i != None:
i.usericon(L_documentpixmap)
i = tree.find_item("Bbb/bgb/222")
if i != None:
i.usericon(L_documentpixmap)
i = tree.find_item("Bbb/bgb/333")
if i != None:
i.usericon(L_documentpixmap)
else:
tree.usericon(None)
i = tree.find_item("Bbb/bgb/111")
if i != None:
i.usericon(0)
i = tree.find_item("Bbb/bgb/222")
if i != None:
i.usericon(0)
i = tree.find_item("Bbb/bgb/333")
if i != None:
i.usericon(0)
def cb_showroot_radio(showroot_radio, datatree):
onoff = int(showroot_radio.value())
tree.showroot(onoff)
def cb_visiblefocus_checkbox(visiblefocus_checkbox, tree):
onoff = int(visiblefocus_checkbox.value())
tree.visible_focus(onoff)
L_openpixmap = None
L_closepixmap = None
def cb_collapseicons_chooser(collapseicons_chooser, tree):
global L_openpixmap, L_closepixmap
L_open_xpm = [
"11 11 2 1",
". c None",
"@ c #000000",
"...@.......",
"...@@......",
"...@@@.....",
"...@@@@....",
"...@@@@@...",
"...@@@@@@..",
"...@@@@@...",
"...@@@@....",
"...@@@.....",
"...@@......",
"...@......."]
L_openpixmap = Fl_Pixmap(L_open_xpm)
L_close_xpm = [
"11 11 2 1",
". c None",
"@ c #000000",
"...........",
"...........",
"...........",
"...........",
"...........",
"@@@@@@@@@@@",
".@@@@@@@@@.",
"..@@@@@@@..",
"...@@@@@...",
"....@@@....",
".....@....."]
L_closepixmap = Fl_Pixmap (L_close_xpm)
if collapseicons_chooser.value() == 0:
tree.showcollapse(1)
tree.openicon(None)
tree.closeicon(None)
elif collapseicons_chooser.value() == 1:
tree.showcollapse(1)
tree.openicon(L_openpixmap)
tree.closeicon(L_closepixmap)
elif collapseicons_chooser.value() == 2:
tree.showcollapse(0)
menu_collapseicons_chooser = (("Normal", 0, 0, 0, 0, FL_NORMAL_LABEL, 0, 11, 0),
("Custom", 0, 0, 0, 0, FL_NORMAL_LABEL, 0, 11, 0),
("Off", 0, 0, 0, 0, FL_NORMAL_LABEL, 0, 11, 0),
(None,))
def cb_connectorstyle_chooser(connectorstyle_chooser, tree):
# CHANGE COLLAPSESTYLE
if connectorstyle_chooser.value() == 0:
tree.connectorstyle(FL_TREE_CONNECTOR_NONE)
elif connectorstyle_chooser.value() == 1:
tree.connectorstyle(FL_TREE_CONNECTOR_DOTTED)
elif connectorstyle_chooser.value() == 2:
tree.connectorstyle(FL_TREE_CONNECTOR_SOLID)
menu_connectorstyle_chooser = (("None", 0, 0, 0, 0, FL_NORMAL_LABEL, 0, 11, 0),
("Dotted", 0, 0, 0, 0, FL_NORMAL_LABEL, 0, 11, 0),
("Solid", 0, 0, 0, 0, FL_NORMAL_LABEL, 0, 11, 0),
(None,))
def cb_labelcolor_chooser(labelcolor_chooser, tree):
# Set color..
c = 0x00000000
if labelcolor_chooser.value() == 0:
c = 0x00000000 # black
elif labelcolor_chooser.value() == 1:
c = 0xd0000000 # red
elif labelcolor_chooser.value() == 2:
c = 0x00a00000 # green
elif labelcolor_chooser.value() == 3:
c = 0x0000a000 # blue
else:
c = 0x00000000 # black
# DO SELECTED ITEMS
count = 0
item = tree.first()
while item != None:
if item.is_selected():
item.labelcolor(c)
count = count + 1
item = tree.next(item)
# NO ITEMS SELECTED? DO ALL
if count == 0:
item = tree.first()
while item != None:
item.labelcolor(c)
item = tree.next(item)
tree.redraw()
menu_labelcolor_chooser = (
("Black", 0, 0, 0, 0, FL_NORMAL_LABEL, 0, 11, 0),
("Red", 0, 0, 0, 0, FL_NORMAL_LABEL, 0, 11, 0),
("Green", 0, 0, 0, 0, FL_NORMAL_LABEL, 0, 11, 0),
("Blue", 0, 0, 0, 0, FL_NORMAL_LABEL, 0, 11, 0),
(None,))
def cb_selectmode_chooser(selectmode_chooser, tree):
# Set selection mode
if selectmode_chooser.value() == 0:
tree.selectmode(FL_TREE_SELECT_NONE)
elif selectmode_chooser.value() == 1:
tree.selectmode(FL_TREE_SELECT_SINGLE)
elif selectmode_chooser.value() == 2:
tree.selectmode(FL_TREE_SELECT_MULTI)
else:
tree.selectmode(FL_TREE_SELECT_SINGLE)
menu_selectmode_chooser = (
("None", 0, 0, 0, 0, FL_NORMAL_LABEL, 0, 11, 0),
("Single", 0, 0, 0, 0, FL_NORMAL_LABEL, 0, 11, 0),
("Multi", 0, 0, 0, 0, FL_NORMAL_LABEL, 0, 11, 0),
(None,))
def cb_whenmode_chooser(whenmode_chooser, tree):
# Set when mode
if whenmode_chooser.value() == 0:
tree.when(FL_WHEN_RELEASE)
elif whenmode_chooser.value() == 1:
tree.when(FL_WHEN_CHANGED)
elif whenmode_chooser.value() == 2:
tree.when(FL_WHEN_NEVER)
else:
tree.when(FL_WHEN_RELEASE)
menu_whenmode_chooser = (
("Changed", 0, 0, 0, 0, FL_NORMAL_LABEL, 0, 11, 0),
("Released", 0, 0, 0, 0, FL_NORMAL_LABEL, 0, 11, 0),
("Never", 0, 0, 0, 0, FL_NORMAL_LABEL, 0, 11, 0),
(None,))
def cb_Show(show_btn, tree):
item = tree.next_selected_item()
print item
tree.show_item(item)
def cb_Top(top_btn, tree):
item = tree.next_selected_item()
print item
tree.show_item_top(item)
def cb_Mid(mid_btn, tree):
item = tree.next_selected_item()
tree.show_item_middle(item)
def cb_Bot(bot_btn, tree):
item = tree.next_selected_item()
tree.show_item_bottom(item)
def cb_selectall_button(selectall_button, tree):
tree.select_all(None)
tree.redraw()
def cb_deselectall_button(deselectall_button, tree):
tree.deselect_all(None)
tree.redraw()
def cb_bbbselect_toggle(bbbselect_toggle, tree):
# Toggle select of just the Bbb item (not children)
bbb = tree.find_item("/Bbb")
if bbb == None:
fl_alert("FAIL: Couldn't find item '/Bbb'???")
return
onoff = bbbselect_toggle.value()
if onoff != 0:
tree.select(bbb) # select /Bbb
else:
tree.deselect(bbb) # deselect /Bbb
def cb_bbbselect2_toggle(bbbselect2_toggle, tree):
# Toggle select of just the Bbb item and its immediate children
bbb = tree.find_item("/Bbb")
if bbb == None:
fl_alert("FAIL: Couldn't find item '/Bbb'???")
return
onoff = bbbselect2_toggle.value()
if onoff != 0:
tree.select_all(bbb) # select /Bbb
else:
tree.deselect_all(bbb) # deselect /Bbb
def cb_bbbchild02select_toggle(bbbchild02select_toggle, tree):
# Toggle select of just the /Bbb/child-02 item
onoff = bbbchild02select_toggle.value()
if onoff != 0:
tree.select("/Bbb/child-02")
else:
tree.deselect("/Bbb/child-02")
def cb_rootselect_toggle(rootselect_toggle, tree):
# Toggle select of ROOT item and its children
item = tree.find_item("/ROOT")
if item == None:
fl_alert("FAIL: Couldn't find item '/ROOT'???")
return
onoff = rootselect_toggle.value()
if onoff != 0:
tree.select(item) # select /ROOT and its children
else:
tree.deselect(item) # deselect /ROOT and its children
def cb_rootselect2_toggle(rootselect2_toggle, tree):
# Toggle select of ROOT item and its children
item = tree.find_item("/ROOT")
if item == None:
fl_alert("FAIL: Couldn't find item '/ROOT'???")
return
onoff = rootselect_toggle.value()
if onoff != 0:
tree.select_all(item) # select /ROOT and its children
else:
tree.deselect_all(item) # deselect /ROOT and its children
def cb_deactivate_toggle(deactivate_toggle, tree):
onoff = deactivate_toggle.value()
if onoff != 0:
onoff = 1
count = 0
item=tree.first()
while item != None:
if item.is_selected():
item.activate(onoff)
count = count+1
item = tree.next(item)
if count == 0:
item=tree.first()
while item != None:
item.activate(onoff)
item = tree.next(item)
tree.redraw()
def cb_bold_toggle(bold_toggle, tree):
face = FL_HELVETICA
if bold_toggle.value() != 0:
face = FL_HELVETICA_BOLD
# DO SELECTED ITEMS
count = 0
item=tree.first()
while item != None:
if item.is_selected():
item.labelfont(face)
count = count+1
item = tree.next(item)
# NO ITEMS SELECTED? DO ALL
if count == 0:
item=tree.first()
while item != None:
item.labelfont(face)
item = tree.next(item)
tree.redraw()
def cb_loaddb_button(loaddb_button, tree):
filename = fl_file_chooser("Select a Preferences style Database", "Preferences(*.prefs)", 0L)
if len(filename) > 0:
tree.clear()
prefs = Fl_Preferences(filename, 0L, 0L)
tree.load(prefs)
tree.redraw()
def cb_insertabove_button(insertabove_button, tree):
item=tree.first()
while item != None:
if item.is_selected():
tree.insert_above(item, "AaaAaa")
tree.insert_above(item, "BbbBbb")
tree.insert_above(item, "CccCcc")
item = item.next()
tree.redraw()
def cb_rebuildtree_button(rebuildtree_button, tree):
RebuildTree(tree)
def cb_showpathname_button(showpathname_button, tree):
item = tree.first_selected_item()
if item == None:
fl_message("No item was selected")
return
pathname = ""
ret_val = tree.item_pathname(pathname, len(pathname), item)
if ret_val == 0:
msg = item.label()
if msg == None or msg == "":
msg = "???"
fl_message("Pathname for '%s' is: \"%s\"", msg, pathname)
elif ret_val == -1:
fl_message("item_pathname() returned -1 (NOT FOUND)")
elif ret_val == -2:
fl_message("item_pathname() returned -2 (STRING TOO LONG)")
def cb_showselected_button(showselected_button, tree):
print "--- SELECTED ITEMS"
item = tree.first_selected_item()
while item != None:
msg = item.label()
if msg == None or msg == "":
msg = "???"
print "\t%s\n"%msg
item = tree.next_selected_item(item)
def cb_clearselected_button(clearselected_button, tree):
item=tree.first()
while item != None:
if item.is_selected():
if tree.remove(item) == -1:
break
item = tree.first()
else:
item = item.next()
tree.redraw()
def cb_clearall_button(clearall_button, tree):
tree.clear()
tree.redraw()
def cb_testcallbackflag_button(testcallbackflag_button, tree):
global G_cb_counter
root = tree.root()
print "--- Checking docallback off\n"
# "OFF" TEST
# open/close: Make sure these methods don't trigger cb
G_cb_counter = 0
tree.close(root, 0)
if G_cb_counter != 0:
fl_alert("FAILED 'OFF' TEST\n close(item) triggered cb!")
G_cb_counter = 0
tree.open(root, 0)
if G_cb_counter != 0:
fl_alert("FAILED 'OFF' TEST\n open(item) triggered cb!")
G_cb_counter = 0
tree.open_toggle(root, 0)
if G_cb_counter != 0:
fl_alert("FAILED 'OFF' TEST\n open_toggle(item) triggered cb!")
G_cb_counter = 0
tree.open("ROOT", 0)
if G_cb_counter != 0:
fl_alert("FAILED 'OFF' TEST\n open(path) triggered cb!")
G_cb_counter = 0
tree.close("ROOT", 0)
if G_cb_counter != 0:
fl_alert("FAILED 'OFF' TEST\n close(path) triggered cb!")
tree.open(root,0) # leave root open
# select/deselect: Make sure these methods don't trigger cb
G_cb_counter = 0
tree.select(root, 0)
if G_cb_counter != 0:
fl_alert("FAILED 'OFF' TEST\n select(item) triggered cb!")
G_cb_counter = 0
tree.deselect(root, 0)
if G_cb_counter != 0:
fl_alert("FAILED 'OFF' TEST\n deselect(item) triggered cb!")
G_cb_counter = 0
tree.select_toggle(root, 0);
if G_cb_counter != 0:
fl_alert("FAILED 'OFF' TEST\n select_toggle(item) triggered cb!")
G_cb_counter = 0
tree.deselect("ROOT", 0)
if G_cb_counter != 0:
fl_alert("FAILED 'OFF' TEST\n deselect(path) triggered cb!")
G_cb_counter = 0
tree.select("ROOT", 0);
if G_cb_counter != 0:
fl_alert("FAILED 'OFF' TEST\n select(path) triggered cb!")
tree.deselect("ROOT") # leave deselected
# "ON" TEST
# open/close: Make sure these methods don't trigger cb
G_cb_counter = 0
tree.close(root, 1)
if G_cb_counter == 0:
fl_alert("FAILED 'ON' TEST\n close(item) cb wasn't triggered!")
G_cb_counter = 0
tree.open(root, 1)
if G_cb_counter == 0:
fl_alert("FAILED 'ON' TEST\n open(item) cb wasn't triggered!")
G_cb_counter = 0
tree.open_toggle(root, 1);
if G_cb_counter == 0:
fl_alert("FAILED 'ON' TEST\n open_toggle(item) cb wasn't triggered!")
G_cb_counter = 0
tree.open(root, 1)
if G_cb_counter == 0:
fl_alert("FAILED 'ON' TEST\n open(item)[2] cb wasn't triggered!")
G_cb_counter = 0
tree.close(root, 1)
if G_cb_counter == 0:
fl_alert("FAILED 'ON' TEST\n close(item)[2] cb wasn't triggered!")
G_cb_counter = 0
tree.open("ROOT", 1);
if G_cb_counter == 0:
fl_alert("FAILED 'ON' TEST\n open(path) cb wasn't triggered!")
G_cb_counter = 0
tree.close("ROOT", 1)
if G_cb_counter == 0:
fl_alert("FAILED 'ON' TEST\n close(path) cb wasn't triggered!")
tree.open(root,0) # leave root open
# select/deselect: Make sure these methods don't trigger cb
G_cb_counter = 0
tree.select(root, 1)
if G_cb_counter == 0:
fl_alert("FAILED 'ON' TEST\n select(item) cb wasn't triggered!")
G_cb_counter = 0
tree.deselect(root, 1)
if G_cb_counter == 0:
fl_alert("FAILED 'ON' TEST\n deselect(item) cb wasn't triggered!")
G_cb_counter = 0
tree.select_toggle(root, 1)
if G_cb_counter == 0:
fl_alert("FAILED 'ON' TEST\n select_toggle(item) cb wasn't triggered!")
G_cb_counter = 0
tree.deselect("ROOT", 1)
if G_cb_counter == 0:
fl_alert("FAILED 'ON' TEST\n deselect(path) cb wasn't triggered!")
G_cb_counter = 0
tree.select("ROOT", 1)
if G_cb_counter == 0:
fl_alert("FAILED 'ON' TEST\n select(path) cb wasn't triggered!")
tree.deselect("ROOT") # leave deselected
# "default" TEST (should be same as 'on'
# open/close: Make sure these methods don't trigger cb
G_cb_counter = 0
tree.close(root)
if G_cb_counter == 0:
fl_alert("FAILED 'DEFAULT' TEST: close(item) cb wasn't triggered!")
G_cb_counter = 0
tree.open(root)
if G_cb_counter == 0:
fl_alert("FAILED 'DEFAULT' TEST: open(item) cb wasn't triggered!")
G_cb_counter = 0
tree.open_toggle(root)
if G_cb_counter == 0:
fl_alert("FAILED 'DEFAULT' TEST: open_toggle(item) cb wasn't triggered!")
G_cb_counter = 0
tree.open("ROOT")
if G_cb_counter == 0:
fl_alert("FAILED 'DEFAULT' TEST: open(path) cb wasn't triggered!")
G_cb_counter = 0
tree.close("ROOT")
if G_cb_counter == 0:
fl_alert("FAILED 'DEFAULT' TEST: close(path) cb wasn't triggered!")
tree.open(root,0) # leave root open
# select/deselect: Make sure these methods don't trigger cb
G_cb_counter = 0
tree.select(root)
if G_cb_counter == 0:
fl_alert("FAILED 'DEFAULT' TEST\n select(item) cb wasn't triggered!")
G_cb_counter = 0
tree.deselect(root)
if G_cb_counter == 0:
fl_alert("FAILED 'DEFAULT' TEST\n deselect(item) cb wasn't triggered!")
G_cb_counter = 0
tree.select_toggle(root)
if G_cb_counter == 0:
fl_alert("FAILED 'DEFAULT' TEST\n select_toggle(item) cb wasn't triggered!")
G_cb_counter = 0
tree.deselect("ROOT")
if G_cb_counter == 0:
fl_alert("FAILED 'DEFAULT' TEST\n deselect(path) cb wasn't triggered!")
G_cb_counter = 0
tree.select("ROOT")
if G_cb_counter == 0:
fl_alert("FAILED 'DEFAULT' TEST\n select(path) cb wasn't triggered!")
tree.deselect("ROOT") # leave deselected
fl_alert("TEST COMPLETED\n If you didn't see any error dialogs, test PASSED.")
if __name__ == '__main__':
window = Fl_Double_Window(580, 695, "tree")
# tree
tree = Fl_Tree(15, 15, 550, 390)
tree.box(FL_DOWN_BOX)
tree.color(55)
tree.selection_color(FL_BACKGROUND_COLOR)
tree.labeltype(FL_NORMAL_LABEL)
tree.labelfont(0)
tree.labelsize(14)
tree.labelcolor(FL_FOREGROUND_COLOR)
tree.callback(cb_tree, 1234)
tree.align(FL_ALIGN_TOP)
tree.when(FL_WHEN_RELEASE)
tree.end()
# margintop_slider
margintop_slider = Fl_Value_Slider(190, 414, 240, 16, "margintop()")
margintop_slider.tooltip("Changes the top margin for the tree widget")
margintop_slider.type(1)
margintop_slider.labelsize(12)
margintop_slider.step(0.01)
margintop_slider.textsize(12)
margintop_slider.callback(cb_margintop_slider, tree)
margintop_slider.align(FL_ALIGN_LEFT)
margintop_slider.value(tree.margintop())
margintop_slider.range(0.0, 100.0)
margintop_slider.step(1.0)
margintop_slider.color(46)
margintop_slider.selection_color(FL_RED)
# marginleft_slider
marginleft_slider = Fl_Value_Slider(190, 434, 240, 16, "marginleft()")
marginleft_slider.tooltip("Changes the left margin for the tree widget")
marginleft_slider.type(1)
marginleft_slider.labelsize(12)
marginleft_slider.step(0.01)
marginleft_slider.textsize(12)
marginleft_slider.callback(cb_marginleft_slider, tree)
marginleft_slider.align(FL_ALIGN_LEFT)
marginleft_slider.value(tree.marginleft())
marginleft_slider.range(0.0, 100.0)
marginleft_slider.step(1.0)
marginleft_slider.color(46)
marginleft_slider.selection_color(FL_RED)
# openchild_marginbottom_slider
openchild_marginbottom_slider = Fl_Value_Slider(190, 454, 240, 16, "openchild_marginbottom()")
openchild_marginbottom_slider.tooltip("Changes the vertical space below an open child tree")
openchild_marginbottom_slider.type(1)
openchild_marginbottom_slider.labelsize(12)
openchild_marginbottom_slider.step(0.01)
openchild_marginbottom_slider.textsize(12)
openchild_marginbottom_slider.callback(cb_openchild_marginbottom_slider, tree)
openchild_marginbottom_slider.align(FL_ALIGN_LEFT)
openchild_marginbottom_slider.value(tree.openchild_marginbottom())
openchild_marginbottom_slider.range(0.0, 100.0)
openchild_marginbottom_slider.step(1.0)
openchild_marginbottom_slider.color(46)
openchild_marginbottom_slider.selection_color(FL_RED)
# labelsize_slider
labelsize_slider = Fl_Value_Slider(190, 474, 240, 16, "Text size")
labelsize_slider.tooltip("Changes the font size of the selected items\nIf none selected, all are changed")
labelsize_slider.type(1)
labelsize_slider.labelsize(12)
labelsize_slider.step(0.01)
labelsize_slider.textsize(12)
labelsize_slider.callback(cb_labelsize_slider, tree)
labelsize_slider.align(FL_ALIGN_LEFT)
labelsize_slider.value(tree.labelsize())
labelsize_slider.range(5.0, 200.0)
labelsize_slider.step(1.0)
labelsize_slider.color(46)
labelsize_slider.selection_color(FL_RED)
# connectorwidth_slider
connectorwidth_slider = Fl_Value_Slider(190, 494, 240, 16, "Connector width")
connectorwidth_slider.tooltip("Tests Fl_Tree::connectorwidth()")
connectorwidth_slider.type(1)
connectorwidth_slider.labelsize(12)
connectorwidth_slider.step(0.01)
connectorwidth_slider.textsize(12)
connectorwidth_slider.callback(cb_connectorwidth_slider, tree)
connectorwidth_slider.align(FL_ALIGN_LEFT)
connectorwidth_slider.value(tree.connectorwidth())
connectorwidth_slider.range(1.0, 100.0)
connectorwidth_slider.step(1.0)
connectorwidth_slider.color(46)
connectorwidth_slider.selection_color(FL_RED)
# usericon_radio
usericon_radio = Fl_Check_Button(90, 525, 130, 16, "Enable user icons?")
usericon_radio.tooltip("Tests Fl_Tree_Item::usericon()")
usericon_radio.down_box(FL_DOWN_BOX)
usericon_radio.labelsize(11)
usericon_radio.callback(cb_usericon_radio, tree)
# showroot_radio
showroot_radio = Fl_Check_Button(90, 542, 130, 16, "Show root?")
showroot_radio.tooltip("Tests Fl_Tree_Item::usericon()")
showroot_radio.down_box(FL_DOWN_BOX)
showroot_radio.labelsize(11)
showroot_radio.callback(cb_showroot_radio, tree)
onoff = tree.showroot()
showroot_radio.value(onoff)
# visiblefocus_checkbox
visiblefocus_checkbox = Fl_Check_Button(90, 559, 130, 16, "Visible focus?")
visiblefocus_checkbox.tooltip("Toggles the tree\'s visible_focus()\nThis toggles the visible \'focus box\'")
visiblefocus_checkbox.down_box(FL_DOWN_BOX)
visiblefocus_checkbox.labelsize(11)
visiblefocus_checkbox.callback(cb_visiblefocus_checkbox, tree)
onoff = tree.visible_focus()
visiblefocus_checkbox.value(onoff)
# collapseicons_chooser
collapseicons_chooser = Fl_Choice(115, 589, 110, 16, "Collapse icons")
collapseicons_chooser.tooltip("Tests Fl_Tree::openicon() and Fl_Tree::closeicon()")
collapseicons_chooser.down_box(FL_BORDER_BOX)
collapseicons_chooser.labelsize(11)
collapseicons_chooser.textsize(11)
collapseicons_chooser.callback(cb_collapseicons_chooser, tree)
collapseicons_chooser.menu(menu_collapseicons_chooser)
# connectorstyle_chooser
connectorstyle_chooser = Fl_Choice(115, 609, 110, 16, "Line style")
connectorstyle_chooser.tooltip("Tests connectorstyle() bit flags")
connectorstyle_chooser.down_box(FL_BORDER_BOX)
connectorstyle_chooser.labelsize(11)
connectorstyle_chooser.textsize(11)
connectorstyle_chooser.callback(cb_connectorstyle_chooser, tree)
connectorstyle_chooser.menu(menu_connectorstyle_chooser)
if tree.connectorstyle() == FL_TREE_CONNECTOR_NONE:
connectorstyle_chooser.value(0)
elif tree.connectorstyle() == FL_TREE_CONNECTOR_DOTTED:
connectorstyle_chooser.value(1)
elif tree.connectorstyle() == FL_TREE_CONNECTOR_SOLID:
connectorstyle_chooser.value(2)
# labelcolor_chooser
labelcolor_chooser = Fl_Choice(115, 629, 110, 16, "Item Text Color")
labelcolor_chooser.tooltip("Changes the label color for the selected items\nIf no items selected, all are\changed")
labelcolor_chooser.down_box(FL_BORDER_BOX)
labelcolor_chooser.labelsize(11)
labelcolor_chooser.textsize(11)
labelcolor_chooser.callback(cb_labelcolor_chooser, tree)
labelcolor_chooser.menu(menu_labelcolor_chooser)
# selectmode_chooser
selectmode_chooser = Fl_Choice(115, 649, 110, 16, "Selection Mode")
selectmode_chooser.tooltip("Sets how Fl_Tree handles mouse selection of tree items")
selectmode_chooser.down_box(FL_BORDER_BOX)
selectmode_chooser.labelsize(11)
selectmode_chooser.textsize(11)
selectmode_chooser.callback(cb_selectmode_chooser, tree)
selectmode_chooser.menu(menu_selectmode_chooser)
selectmode_chooser.value(1)
cb_selectmode_chooser(selectmode_chooser, tree)
# whenmode_chooser
whenmode_chooser = Fl_Choice(115, 669, 110, 16, "When")
whenmode_chooser.tooltip("Sets when() the tree\'s callback is invoked")
whenmode_chooser.down_box(FL_BORDER_BOX)
whenmode_chooser.labelsize(11)
whenmode_chooser.textsize(11)
whenmode_chooser.callback(cb_whenmode_chooser, tree)
whenmode_chooser.menu(menu_whenmode_chooser)
whenmode_chooser.value(1)
cb_whenmode_chooser(whenmode_chooser, tree)
# showitem_box
showitem_box = Fl_Box(480, 425, 70, 82, "show_item()\n")
showitem_box.box(FL_GTK_DOWN_BOX)
showitem_box.color(FL_DARK1)
showitem_box.labelsize(11)
showitem_box.align(FL_ALIGN_TOP)
show_btn = Fl_Button(495, 434, 40, 17, "Show")
show_btn.tooltip("Tests show_item() with no position specified.\nMakes the selected item visibl\e IF it is off-screen.\nNo change made if it is not off-screen.")
show_btn.labelsize(11)
show_btn.callback(cb_Show, tree)
top_btn = Fl_Button(495, 451, 40, 16, "Top")
top_btn.tooltip("Test show_item_top().\nScrolls selected item to the top of the display\n(only\ works if scrollbar showing)\nTo use:\n1) open \'500 items\'\n2) select item 0\010\n3) Hit Top/Mid/Bot")
top_btn.labelsize(11)
top_btn.callback(cb_Top, tree)
mid_btn = Fl_Button(495, 467, 40, 16, "Mid")
mid_btn.tooltip("Tests show_item_middle().\nScrolls the selected item to the middle of the dis\play\nTo use:\n 1) open \'500 items\'\n 2) select \'item 0010\'\n 3) Hit To\p/Mid/Bot")
mid_btn.labelsize(11)
mid_btn.callback(cb_Mid, tree)
bot_btn = Fl_Button(495, 483, 40, 16, "Bot")
bot_btn.tooltip("Tests show_item_bottom().\nScrolls the selected item to the bottom of the dis\play\nTo use:\n 1) open \'500 items\'\n 2) select \'item 0010\'\n 3) Hit To\p/Mid/Bot")
bot_btn.labelsize(11)
bot_btn.callback(cb_Bot, tree)
docallback_box = Fl_Box(245, 527, 320, 77, "Selection State Changes")
docallback_box.box(FL_GTK_DOWN_BOX)
docallback_box.color(FL_DARK1)
docallback_box.labelsize(12)
docallback_box.align(FL_ALIGN_TOP)
selectall_button = Fl_Button(260, 539, 75, 16, "Select All")
selectall_button.tooltip("Selects all items in the tree")
selectall_button.labelsize(9)
selectall_button.callback(cb_selectall_button, tree)
deselectall_button = Fl_Button(260, 559, 75, 16, "Deselect All")
deselectall_button.tooltip("Deselects all items in the tree")
deselectall_button.labelsize(9)
deselectall_button.callback(cb_deselectall_button, tree)
bbbselect_toggle = Fl_Light_Button(350, 540, 95, 15, " Select Bbb")
bbbselect_toggle.tooltip("Toggle selection of just the /Bbb item\n(Not children)")
bbbselect_toggle.selection_color(1)
bbbselect_toggle.labelsize(9)
bbbselect_toggle.callback(cb_bbbselect_toggle, tree)
bbbselect2_toggle = Fl_Light_Button(350, 560, 95, 15, " Select Bbb+")
bbbselect2_toggle.tooltip("Toggle selection of the /Bbb item and its children")
bbbselect2_toggle.selection_color(1)
bbbselect2_toggle.labelsize(9)
bbbselect2_toggle.callback(cb_bbbselect2_toggle, tree)
bbbchild02select_toggle = Fl_Light_Button(350, 579, 95, 16, " Toggle child-02")
bbbchild02select_toggle.tooltip("Toggle the single item /Bbb/child-02")
bbbchild02select_toggle.selection_color(1)
bbbchild02select_toggle.labelsize(9)
bbbchild02select_toggle.callback(cb_bbbchild02select_toggle, tree)
rootselect_toggle = Fl_Light_Button(460, 540, 90, 15, "Select ROOT")
rootselect_toggle.tooltip("Toggle selection of the ROOT item")
rootselect_toggle.selection_color(1)
rootselect_toggle.labelsize(9)
rootselect_toggle.callback(cb_rootselect_toggle, tree)
rootselect2_toggle = Fl_Light_Button(460, 560, 90, 15, "Select ROOT+")
rootselect2_toggle.tooltip("Toggle selection of the ROOT item and all children")
rootselect2_toggle.selection_color(1)
rootselect2_toggle.labelsize(9)
rootselect2_toggle.callback(cb_rootselect2_toggle, tree)
deactivate_toggle = Fl_Light_Button(280, 634, 90, 16, " Deactivate")
deactivate_toggle.tooltip("Toggle the deactivation state of the selected items.\nIf none are selected, a\ll are set.")
deactivate_toggle.selection_color(1)
deactivate_toggle.labelsize(9)
deactivate_toggle.callback(cb_deactivate_toggle, tree)
bold_toggle = Fl_Light_Button(280, 654, 90, 16, " Bold Font")
bold_toggle.tooltip("Toggles bold font for selected items\nIf nothing selected, all are changed")
bold_toggle.selection_color(1)
bold_toggle.labelsize(9)
bold_toggle.callback(cb_bold_toggle, tree)
loaddb_button = Fl_Button(380, 614, 90, 16, "Load Database...")
loaddb_button.tooltip("Load the contents of an Fl_Preferences database into the tree view")
loaddb_button.labelsize(9)
loaddb_button.callback(cb_loaddb_button, tree)
insertabove_button = Fl_Button(380, 634, 90, 16, "Insert Above")
insertabove_button.tooltip("Inserts three items above the selected items")
insertabove_button.labelsize(9)
insertabove_button.callback(cb_insertabove_button, tree)
rebuildtree_button = Fl_Button(380, 654, 90, 16, "Rebuild Tree")
rebuildtree_button.tooltip("Rebuilds the tree with defaults")
rebuildtree_button.labelsize(9)
rebuildtree_button.callback(cb_rebuildtree_button, tree)
showpathname_button = Fl_Button(380, 674, 90, 16, "Show Pathname")
showpathname_button.tooltip("Show the pathname for the selected item. Tests the Fl_Tree::item_pathname() m\ethod.")
showpathname_button.labelsize(8)
showpathname_button.callback(cb_showpathname_button, tree)
showselected_button = Fl_Button(475, 614, 90, 16, "Show Selected")
showselected_button.tooltip("Clears the selected items")
showselected_button.labelsize(9)
showselected_button.callback(cb_showselected_button, tree)
clearselected_button = Fl_Button(475, 634, 90, 16, "Remove Selected")
clearselected_button.tooltip("Removes the selected items")
clearselected_button.labelsize(9)
clearselected_button.callback(cb_clearselected_button, tree)
clearall_button = Fl_Button(475, 654, 90, 16, "Clear All")
clearall_button.tooltip("Clears all items\nTests Fl_Tree::clear()")
clearall_button.labelsize(9)
clearall_button.callback(cb_clearall_button, tree)
testcallbackflag_button = Fl_Button(475, 674, 90, 16, "Test Callback Flag")
testcallbackflag_button.tooltip("Test the \'docallback\' argument can disable callbacks.")
testcallbackflag_button.labelsize(8)
testcallbackflag_button.callback(cb_testcallbackflag_button, tree)
window.end()
tree.root_label("ROOT")
RebuildTree(tree)
window.resizable(window)
window.size_range(window.w(), window.h(), 0, 0)
if tree.when() == FL_WHEN_CHANGED:
whenmode_chooser.value(0)
elif tree.when() == FL_WHEN_RELEASE:
whenmode_chooser.value(1)
elif tree.when() == FL_WHEN_NEVER:
whenmode_chooser.value(2)
window.show(sys.argv)
Fl.run()
|