| 447 |
|
# CustomTreeCtrl Demo Implementation
|
| 448 |
|
#---------------------------------------------------------------------------
|
| 449 |
|
|
| 450 |
|
class CustomTreeCtrl(CT.CustomTreeCtrl):
|
| 451 |
|
|
| 452 |
|
def __init__(self, parent, id=wx.ID_ANY, pos=wx.DefaultPosition,
|
| 453 |
|
size=wx.DefaultSize,
|
| 454 |
|
style=wx.SUNKEN_BORDER,
|
| 455 |
|
ctstyle=CT.TR_HAS_BUTTONS | CT.TR_TWIST_BUTTONS | CT.TR_HAS_VARIABLE_ROW_HEIGHT,
|
| 456 |
|
log=None):
|
| 457 |
|
|
| 458 |
|
CT.CustomTreeCtrl.__init__(self, parent, id, pos, size, style, ctstyle)
|
| 459 |
|
|
| 460 |
|
self.log = log # the demo will write message to this file-like object
|
| 461 |
|
|
| 462 |
|
# build lists of tree styles and events
|
| 463 |
|
alldata = dir(CT)
|
| 464 |
|
|
| 465 |
|
treestyles = []
|
| 466 |
|
events = []
|
| 467 |
|
for data in alldata:
|
| 468 |
|
if data.startswith("TR_"):
|
| 469 |
|
treestyles.append(data)
|
| 470 |
|
elif data.startswith("EVT_"):
|
| 471 |
|
events.append(data)
|
| 472 |
|
|
| 473 |
|
self.events = events
|
| 474 |
|
self.styles = treestyles
|
| 475 |
|
|
| 476 |
|
self.item = None # what is this? - used to keep track of right clicked item??
|
| 477 |
|
|
| 478 |
|
# make a list of icons to label tree nodes
|
| 479 |
|
il = wx.ImageList(16, 16)
|
| 480 |
|
|
| 481 |
|
for items in ArtIDs[1:-1]:
|
| 482 |
|
bmp = wx.ArtProvider_GetBitmap(eval(items), wx.ART_TOOLBAR, (16, 16))
|
| 483 |
|
il.Add(bmp)
|
| 484 |
|
|
| 485 |
|
#smileidx = il.Add(images.getSmilesBitmap())
|
| 486 |
|
smileidx = il.Add(Menu.Bitmap("icons/New Project.bmp", wx.BITMAP_TYPE_ANY))
|
| 487 |
|
numicons = il.GetImageCount()
|
| 488 |
|
|
| 489 |
|
self.AssignImageList(il)
|
| 490 |
|
|
| 491 |
|
self.count = 0 # counts idle clicks for meter display - demo only
|
| 492 |
|
|
| 493 |
|
# NOTE: For some reason tree items have to have a data object in
|
| 494 |
|
# order to be sorted. Since our compare just uses the labels
|
| 495 |
|
# we don't need any real data, so we'll just use None below for
|
| 496 |
|
# the item data.
|
| 497 |
|
|
| 498 |
|
self.root = self.AddRoot("The Root Item")
|
| 499 |
|
|
| 500 |
|
if not(self.GetTreeStyle() & CT.TR_HIDE_ROOT):
|
| 501 |
|
self.SetPyData(self.root, None)
|
| 502 |
|
self.SetItemImage(self.root, 24, CT.TreeItemIcon_Normal)
|
| 503 |
|
self.SetItemImage(self.root, 13, CT.TreeItemIcon_Expanded)
|
| 504 |
|
|
| 505 |
|
## # controls attached to tree nodes for demo purposes
|
| 506 |
|
## textctrl = wx.TextCtrl(self, -1, "I Am A Simple\nMultiline wx.TexCtrl", style=wx.TE_MULTILINE)
|
| 507 |
|
## self.gauge = wx.Gauge(self, -1, 50, style=wx.GA_HORIZONTAL|wx.GA_SMOOTH)
|
| 508 |
|
## self.gauge.SetValue(0)
|
| 509 |
|
## combobox = wx.ComboBox(self, -1, choices=["That", "Was", "A", "Nice", "Holyday!"], style=wx.CB_READONLY|wx.CB_DROPDOWN)
|
| 510 |
|
##
|
| 511 |
|
## textctrl.Bind(wx.EVT_CHAR, self.OnTextCtrl)
|
| 512 |
|
## combobox.Bind(wx.EVT_COMBOBOX, self.OnComboBox)
|
| 513 |
|
|
| 514 |
|
# build the tree
|
| 515 |
|
#### db = Data._dbDatabase(Data.Database) # will get objects from this database
|
| 516 |
|
projects = Data.DBObject.GetList('Project')
|
| 517 |
|
for x in projects: # projects
|
| 518 |
|
## if x == 1:
|
| 519 |
|
## child = self.AppendItem(self.root, "Item %d" % x + "\nHello World\nHappy wxPython-ing!")
|
| 520 |
|
## self.SetItemBold(child, True)
|
| |
447 |
### CustomTreeCtrl Demo Implementation
|
| |
448 |
###---------------------------------------------------------------------------
|
| |
449 |
##
|
| |
450 |
##class CustomTreeCtrl(CT.CustomTreeCtrl):
|
| |
451 |
##
|
| |
452 |
## def __init__(self, parent, id=wx.ID_ANY, pos=wx.DefaultPosition,
|
| |
453 |
## size=wx.DefaultSize,
|
| |
454 |
## style=wx.SUNKEN_BORDER,
|
| |
455 |
## ctstyle=CT.TR_HAS_BUTTONS | CT.TR_TWIST_BUTTONS | CT.TR_HAS_VARIABLE_ROW_HEIGHT,
|
| |
456 |
## log=None):
|
| |
457 |
##
|
| |
458 |
## CT.CustomTreeCtrl.__init__(self, parent, id, pos, size, style, ctstyle)
|
| |
459 |
##
|
| |
460 |
## self.log = log # the demo will write message to this file-like object
|
| |
461 |
##
|
| |
462 |
## # build lists of tree styles and events
|
| |
463 |
## alldata = dir(CT)
|
| |
464 |
##
|
| |
465 |
## treestyles = []
|
| |
466 |
## events = []
|
| |
467 |
## for data in alldata:
|
| |
468 |
## if data.startswith("TR_"):
|
| |
469 |
## treestyles.append(data)
|
| |
470 |
## elif data.startswith("EVT_"):
|
| |
471 |
## events.append(data)
|
| |
472 |
##
|
| |
473 |
## self.events = events
|
| |
474 |
## self.styles = treestyles
|
| |
475 |
##
|
| |
476 |
## self.item = None # what is this? - used to keep track of right clicked item??
|
| |
477 |
##
|
| |
478 |
## # make a list of icons to label tree nodes
|
| |
479 |
## il = wx.ImageList(16, 16)
|
| |
480 |
##
|
| |
481 |
## for items in ArtIDs[1:-1]:
|
| |
482 |
## bmp = wx.ArtProvider_GetBitmap(eval(items), wx.ART_TOOLBAR, (16, 16))
|
| |
483 |
## il.Add(bmp)
|
| |
484 |
##
|
| |
485 |
## #smileidx = il.Add(images.getSmilesBitmap())
|
| |
486 |
## smileidx = il.Add(Menu.Bitmap("icons/New Project.bmp", wx.BITMAP_TYPE_ANY))
|
| |
487 |
## numicons = il.GetImageCount()
|
| |
488 |
##
|
| |
489 |
## self.AssignImageList(il)
|
| |
490 |
##
|
| |
491 |
## self.count = 0 # counts idle clicks for meter display - demo only
|
| |
492 |
##
|
| |
493 |
## # NOTE: For some reason tree items have to have a data object in
|
| |
494 |
## # order to be sorted. Since our compare just uses the labels
|
| |
495 |
## # we don't need any real data, so we'll just use None below for
|
| |
496 |
## # the item data.
|
| |
497 |
##
|
| |
498 |
## self.root = self.AddRoot("The Root Item")
|
| |
499 |
##
|
| |
500 |
## if not(self.GetTreeStyle() & CT.TR_HIDE_ROOT):
|
| |
501 |
## self.SetPyData(self.root, None)
|
| |
502 |
## self.SetItemImage(self.root, 24, CT.TreeItemIcon_Normal)
|
| |
503 |
## self.SetItemImage(self.root, 13, CT.TreeItemIcon_Expanded)
|
| |
504 |
##
|
| |
505 |
#### # controls attached to tree nodes for demo purposes
|
| |
506 |
#### textctrl = wx.TextCtrl(self, -1, "I Am A Simple\nMultiline wx.TexCtrl", style=wx.TE_MULTILINE)
|
| |
507 |
#### self.gauge = wx.Gauge(self, -1, 50, style=wx.GA_HORIZONTAL|wx.GA_SMOOTH)
|
| |
508 |
#### self.gauge.SetValue(0)
|
| |
509 |
#### combobox = wx.ComboBox(self, -1, choices=["That", "Was", "A", "Nice", "Holyday!"], style=wx.CB_READONLY|wx.CB_DROPDOWN)
|
| |
510 |
####
|
| |
511 |
#### textctrl.Bind(wx.EVT_CHAR, self.OnTextCtrl)
|
| |
512 |
#### combobox.Bind(wx.EVT_COMBOBOX, self.OnComboBox)
|
| |
513 |
##
|
| |
514 |
## # build the tree
|
| |
515 |
## #### db = Data._dbDatabase(Data.Database) # will get objects from this database
|
| |
516 |
## projects = Data.DBObject.GetList('Project')
|
| |
517 |
## for x in projects: # projects
|
| |
518 |
#### if x == 1:
|
| |
519 |
#### child = self.AppendItem(self.root, "Item %d" % x + "\nHello World\nHappy wxPython-ing!")
|
| |
520 |
#### self.SetItemBold(child, True)
|
| |
521 |
#### else:
|
| |
522 |
#### child = self.AppendItem(self.root, "Item %d" % x)
|
| |
523 |
## child = self.AppendItem(self.root, "%s" % x.Name, ct_type=1)
|
| |
524 |
## self.SetPyData(child, x)
|
| |
525 |
## self.SetItemImage(child, 24, CT.TreeItemIcon_Normal)
|
| |
526 |
## self.SetItemImage(child, 13, CT.TreeItemIcon_Expanded)
|
| |
527 |
##
|
| |
528 |
## reports = x.GetList('Report')
|
| |
529 |
## for y in reports: # reports
|
| |
530 |
#### if y == 0 and x == 1:
|
| |
531 |
#### last = self.AppendItem(child, "item %d-%s" % (x, chr(ord("a")+y)), ct_type=2)
|
| |
532 |
#### elif y == 1 and x == 2:
|
| |
533 |
#### last = self.AppendItem(child, "Item %d-%s" % (x, chr(ord("a")+y)), ct_type=1)
|
| |
534 |
#### elif 2 < y < 4:
|
| |
535 |
#### last = self.AppendItem(child, "item %d-%s" % (x, chr(ord("a")+y)))
|
| |
536 |
#### elif y == 4 and x == 1:
|
| |
537 |
#### last = self.AppendItem(child, "item %d-%s" % (x, chr(ord("a")+y)))
|
| |
538 |
#### else:
|
| |
539 |
#### last = self.AppendItem(child, "item %d-%s" % (x, chr(ord("a")+y)), ct_type=2)
|
| |
540 |
## last = self.AppendItem(child, "%s" % y.Name, ct_type=1)
|
| |
541 |
##
|
| |
542 |
## self.SetPyData(last, y)
|
| |
543 |
### self.SetItemImage(last, 24, CT.TreeItemIcon_Normal)
|
| |
544 |
## self.SetItemImage(last, 28, CT.TreeItemIcon_Normal)
|
| |
545 |
### self.SetItemImage(last, 13, CT.TreeItemIcon_Expanded)
|
| |
546 |
## self.SetItemImage(last, numicons-1, CT.TreeItemIcon_Selected)
|
| |
547 |
##
|
| |
548 |
#### for z in range(5):
|
| |
549 |
#### if z > 2:
|
| |
550 |
#### item = self.AppendItem(last, "item %d-%s-%d" % (x, chr(ord("a")+y), z), ct_type=1)
|
| |
551 |
#### elif 0 < z <= 2:
|
| |
552 |
#### item = self.AppendItem(last, "item %d-%s-%d" % (x, chr(ord("a")+y), z), ct_type=2)
|
| |
553 |
#### elif z == 0:
|
| |
554 |
#### item = self.AppendItem(last, "item %d-%s-%d" % (x, chr(ord("a")+y), z))
|
| |
555 |
#### self.SetItemHyperText(item, True)
|
| |
556 |
#### self.SetPyData(item, None)
|
| |
557 |
#### self.SetItemImage(item, 28, CT.TreeItemIcon_Normal)
|
| |
558 |
#### self.SetItemImage(item, numicons-1, CT.TreeItemIcon_Selected)
|
| |
559 |
##
|
| |
560 |
## self.Bind(wx.EVT_LEFT_DCLICK, self.OnLeftDClick)
|
| |
561 |
#### self.Bind(wx.EVT_IDLE, self.OnIdle)
|
| |
562 |
## self.Bind(CT.EVT_TREE_ITEM_CHECKED, self.OnItemCheck)
|
| |
563 |
##
|
| |
564 |
## self.eventdict = {
|
| |
565 |
## 'EVT_TREE_BEGIN_DRAG': self.OnBeginDrag,
|
| |
566 |
## 'EVT_TREE_BEGIN_LABEL_EDIT': self.OnBeginEdit,
|
| |
567 |
## 'EVT_TREE_BEGIN_RDRAG': self.OnBeginRDrag,
|
| |
568 |
## 'EVT_TREE_DELETE_ITEM': self.OnDeleteItem,
|
| |
569 |
## 'EVT_TREE_END_DRAG': self.OnEndDrag,
|
| |
570 |
## 'EVT_TREE_END_LABEL_EDIT': self.OnEndEdit,
|
| |
571 |
## 'EVT_TREE_ITEM_ACTIVATED': self.OnActivate,
|
| |
572 |
## 'EVT_TREE_ITEM_CHECKED': self.OnItemCheck,
|
| |
573 |
## 'EVT_TREE_ITEM_CHECKING': self.OnItemChecking,
|
| |
574 |
## 'EVT_TREE_ITEM_COLLAPSED': self.OnItemCollapsed,
|
| |
575 |
## 'EVT_TREE_ITEM_COLLAPSING': self.OnItemCollapsing,
|
| |
576 |
## 'EVT_TREE_ITEM_EXPANDED': self.OnItemExpanded,
|
| |
577 |
## 'EVT_TREE_ITEM_EXPANDING': self.OnItemExpanding,
|
| |
578 |
## 'EVT_TREE_ITEM_GETTOOLTIP': self.OnToolTip,
|
| |
579 |
## 'EVT_TREE_ITEM_MENU': self.OnItemMenu,
|
| |
580 |
## 'EVT_TREE_ITEM_RIGHT_CLICK': self.OnRightDown,
|
| |
581 |
## 'EVT_TREE_KEY_DOWN': self.OnKey,
|
| |
582 |
## 'EVT_TREE_SEL_CHANGED': self.OnSelChanged,
|
| |
583 |
## 'EVT_TREE_SEL_CHANGING': self.OnSelChanging,
|
| |
584 |
## "EVT_TREE_ITEM_HYPERLINK": self.OnHyperLink}
|
| |
585 |
##
|
| |
586 |
## mainframe = wx.GetTopLevelParent(self)
|
| |
587 |
##
|
| |
588 |
## if not hasattr(mainframe, "leftpanel"):
|
| |
589 |
## self.Bind(CT.EVT_TREE_ITEM_EXPANDED, self.OnItemExpanded)
|
| |
590 |
## self.Bind(CT.EVT_TREE_ITEM_COLLAPSED, self.OnItemCollapsed)
|
| |
591 |
## self.Bind(CT.EVT_TREE_SEL_CHANGED, self.OnSelChanged)
|
| |
592 |
## self.Bind(CT.EVT_TREE_SEL_CHANGING, self.OnSelChanging)
|
| |
593 |
## self.Bind(wx.EVT_RIGHT_DOWN, self.OnRightDown)
|
| |
594 |
## self.Bind(wx.EVT_RIGHT_UP, self.OnRightUp)
|
| |
595 |
## else:
|
| |
596 |
## for combos in mainframe.treeevents:
|
| |
597 |
## self.BindEvents(combos)
|
| |
598 |
##
|
| |
599 |
## if hasattr(mainframe, "leftpanel"):
|
| |
600 |
## self.ChangeStyle(mainframe.treestyles)
|
| |
601 |
##
|
| |
602 |
## if not(self.GetTreeStyle() & CT.TR_HIDE_ROOT):
|
| |
603 |
## self.SelectItem(self.root)
|
| |
604 |
## self.Expand(self.root)
|
| |
605 |
##
|
| |
606 |
##
|
| |
607 |
## def BindEvents(self, choice, recreate=False):
|
| |
608 |
##
|
| |
609 |
## value = choice.GetValue()
|
| |
610 |
## text = choice.GetLabel()
|
| |
611 |
##
|
| |
612 |
## evt = "CT." + text
|
| |
613 |
## binder = self.eventdict[text]
|
| |
614 |
##
|
| |
615 |
## if value == 1:
|
| |
616 |
## if evt == "CT.EVT_TREE_BEGIN_RDRAG":
|
| |
617 |
## self.Bind(wx.EVT_RIGHT_DOWN, None)
|
| |
618 |
## self.Bind(wx.EVT_RIGHT_UP, None)
|
| |
619 |
## self.Bind(eval(evt), binder)
|
| |
620 |
## else:
|
| |
621 |
## self.Bind(eval(evt), None)
|
| |
622 |
## if evt == "CT.EVT_TREE_BEGIN_RDRAG":
|
| |
623 |
## self.Bind(wx.EVT_RIGHT_DOWN, self.OnRightDown)
|
| |
624 |
## self.Bind(wx.EVT_RIGHT_UP, self.OnRightUp)
|
| |
625 |
##
|
| |
626 |
##
|
| |
627 |
## def ChangeStyle(self, combos):
|
| |
628 |
##
|
| |
629 |
## style = 0
|
| |
630 |
## for combo in combos:
|
| |
631 |
## if combo.GetValue() == 1:
|
| |
632 |
## style = style | eval("CT." + combo.GetLabel())
|
| |
633 |
##
|
| |
634 |
## if self.GetTreeStyle() != style:
|
| |
635 |
## self.SetTreeStyle(style)
|
| |
636 |
##
|
| |
637 |
##
|
| |
638 |
## def OnCompareItems(self, item1, item2):
|
| |
639 |
##
|
| |
640 |
## t1 = self.GetItemText(item1)
|
| |
641 |
## t2 = self.GetItemText(item2)
|
| |
642 |
##
|
| |
643 |
## self.log.write('compare: ' + t1 + ' <> ' + t2 + "\n")
|
| |
644 |
##
|
| |
645 |
## if t1 < t2:
|
| |
646 |
## return -1
|
| |
647 |
## if t1 == t2:
|
| |
648 |
## return 0
|
| |
649 |
##
|
| |
650 |
## return 1
|
| |
651 |
##
|
| |
652 |
##
|
| |
653 |
#### def OnIdle(self, event):
|
| |
654 |
####
|
| |
655 |
#### if self.gauge:
|
| |
656 |
#### try:
|
| |
657 |
#### if self.gauge.IsEnabled() and self.gauge.IsShown():
|
| |
658 |
#### self.count = self.count + 1
|
| |
659 |
####
|
| |
660 |
#### if self.count >= 50:
|
| |
661 |
#### self.count = 0
|
| |
662 |
####
|
| |
663 |
#### self.gauge.SetValue(self.count)
|
| |
664 |
####
|
| |
665 |
#### except:
|
| |
666 |
#### self.gauge = None
|
| |
667 |
####
|
| |
668 |
#### event.Skip()
|
| |
669 |
##
|
| |
670 |
##
|
| |
671 |
## def OnRightDown(self, event):
|
| |
672 |
##
|
| |
673 |
## pt = event.GetPosition()
|
| |
674 |
## item, flags = self.HitTest(pt)
|
| |
675 |
##
|
| |
676 |
## if item:
|
| |
677 |
## self.item = item
|
| |
678 |
## self.log.write("OnRightClick: %s, %s, %s" % (self.GetItemText(item), type(item), item.__class__) + "\n")
|
| |
679 |
## self.SelectItem(item)
|
| |
680 |
##
|
| |
681 |
##
|
| |
682 |
## def OnRightUp(self, event):
|
| |
683 |
##
|
| |
684 |
## item = self.item
|
| |
685 |
##
|
| |
686 |
## if not item:
|
| |
687 |
## event.Skip()
|
| |
688 |
## return
|
| |
689 |
##
|
| |
690 |
## if not self.IsEnabled(item):
|
| |
691 |
## event.Skip()
|
| |
692 |
## return
|
| |
693 |
##
|
| |
694 |
## # Item Text Appearance
|
| |
695 |
## ishtml = self.IsItemHyperText(item)
|
| |
696 |
## back = self.GetItemBackgroundColour(item)
|
| |
697 |
## fore = self.GetItemTextColour(item)
|
| |
698 |
## isbold = self.IsBold(item)
|
| |
699 |
## font = self.GetItemFont(item)
|
| |
700 |
##
|
| |
701 |
## # Icons On Item
|
| |
702 |
## normal = self.GetItemImage(item, CT.TreeItemIcon_Normal)
|
| |
703 |
## selected = self.GetItemImage(item, CT.TreeItemIcon_Selected)
|
| |
704 |
## expanded = self.GetItemImage(item, CT.TreeItemIcon_Expanded)
|
| |
705 |
## selexp = self.GetItemImage(item, CT.TreeItemIcon_SelectedExpanded)
|
| |
706 |
##
|
| |
707 |
## # Enabling/Disabling Windows Associated To An Item
|
| |
708 |
## haswin = self.GetItemWindow(item)
|
| |
709 |
##
|
| |
710 |
## # Enabling/Disabling Items
|
| |
711 |
## enabled = self.IsEnabled(item)
|
| |
712 |
##
|
| |
713 |
## # Generic Item's Info
|
| |
714 |
## children = self.GetChildrenCount(item)
|
| |
715 |
## itemtype = self.GetItemType(item)
|
| |
716 |
## text = self.GetItemText(item)
|
| |
717 |
## pydata = self.GetPyData(item)
|
| |
718 |
##
|
| |
719 |
## self.current = item
|
| |
720 |
## self.itemdict = {"ishtml": ishtml, "back": back, "fore": fore, "isbold": isbold,
|
| |
721 |
## "font": font, "normal": normal, "selected": selected, "expanded": expanded,
|
| |
722 |
## "selexp": selexp, "haswin": haswin, "children": children,
|
| |
723 |
## "itemtype": itemtype, "text": text, "pydata": pydata, "enabled": enabled}
|
| |
724 |
##
|
| |
725 |
## menu = wx.Menu()
|
| |
726 |
##
|
| |
727 |
## item1 = menu.Append(wx.ID_ANY, "Change Item Background Colour")
|
| |
728 |
## item2 = menu.Append(wx.ID_ANY, "Modify Item Text Colour")
|
| |
729 |
## menu.AppendSeparator()
|
| |
730 |
## if isbold:
|
| |
731 |
## strs = "Make Item Text Not Bold"
|
| |
732 |
## else:
|
| |
733 |
## strs = "Make Item Text Bold"
|
| |
734 |
## item3 = menu.Append(wx.ID_ANY, strs)
|
| |
735 |
## item4 = menu.Append(wx.ID_ANY, "Change Item Font")
|
| |
736 |
## menu.AppendSeparator()
|
| |
737 |
## if ishtml:
|
| |
738 |
## strs = "Set Item As Non-Hyperlink"
|
| |
739 |
## else:
|
| |
740 |
## strs = "Set Item As Hyperlink"
|
| |
741 |
## item5 = menu.Append(wx.ID_ANY, strs)
|
| |
742 |
## menu.AppendSeparator()
|
| |
743 |
## if haswin:
|
| |
744 |
## enabled = self.GetItemWindowEnabled(item)
|
| |
745 |
## if enabled:
|
| |
746 |
## strs = "Disable Associated Widget"
|
| 522 |
|
## child = self.AppendItem(self.root, "Item %d" % x)
|
| 523 |
|
child = self.AppendItem(self.root, "%s" % x.Name, ct_type=1)
|
| 524 |
|
self.SetPyData(child, x)
|
| 525 |
|
self.SetItemImage(child, 24, CT.TreeItemIcon_Normal)
|
| 526 |
|
self.SetItemImage(child, 13, CT.TreeItemIcon_Expanded)
|
| 527 |
|
|
| 528 |
|
reports = x.GetList('Report')
|
| 529 |
|
for y in reports: # reports
|
| 530 |
|
## if y == 0 and x == 1:
|
| 531 |
|
## last = self.AppendItem(child, "item %d-%s" % (x, chr(ord("a")+y)), ct_type=2)
|
| 532 |
|
## elif y == 1 and x == 2:
|
| 533 |
|
## last = self.AppendItem(child, "Item %d-%s" % (x, chr(ord("a")+y)), ct_type=1)
|
| 534 |
|
## elif 2 < y < 4:
|
| 535 |
|
## last = self.AppendItem(child, "item %d-%s" % (x, chr(ord("a")+y)))
|
| 536 |
|
## elif y == 4 and x == 1:
|
| 537 |
|
## last = self.AppendItem(child, "item %d-%s" % (x, chr(ord("a")+y)))
|
| 538 |
|
## else:
|
| 539 |
|
## last = self.AppendItem(child, "item %d-%s" % (x, chr(ord("a")+y)), ct_type=2)
|
| 540 |
|
last = self.AppendItem(child, "%s" % y.Name, ct_type=1)
|
| 541 |
|
|
| 542 |
|
self.SetPyData(last, y)
|
| 543 |
|
# self.SetItemImage(last, 24, CT.TreeItemIcon_Normal)
|
| 544 |
|
self.SetItemImage(last, 28, CT.TreeItemIcon_Normal)
|
| 545 |
|
# self.SetItemImage(last, 13, CT.TreeItemIcon_Expanded)
|
| 546 |
|
self.SetItemImage(last, numicons-1, CT.TreeItemIcon_Selected)
|
| 547 |
|
|
| 548 |
|
## for z in range(5):
|
| 549 |
|
## if z > 2:
|
| 550 |
|
## item = self.AppendItem(last, "item %d-%s-%d" % (x, chr(ord("a")+y), z), ct_type=1)
|
| 551 |
|
## elif 0 < z <= 2:
|
| 552 |
|
## item = self.AppendItem(last, "item %d-%s-%d" % (x, chr(ord("a")+y), z), ct_type=2)
|
| 553 |
|
## elif z == 0:
|
| 554 |
|
## item = self.AppendItem(last, "item %d-%s-%d" % (x, chr(ord("a")+y), z))
|
| 555 |
|
## self.SetItemHyperText(item, True)
|
| 556 |
|
## self.SetPyData(item, None)
|
| 557 |
|
## self.SetItemImage(item, 28, CT.TreeItemIcon_Normal)
|
| 558 |
|
## self.SetItemImage(item, numicons-1, CT.TreeItemIcon_Selected)
|
| 559 |
|
|
| 560 |
|
self.Bind(wx.EVT_LEFT_DCLICK, self.OnLeftDClick)
|
| 561 |
|
## self.Bind(wx.EVT_IDLE, self.OnIdle)
|
| 562 |
|
self.Bind(CT.EVT_TREE_ITEM_CHECKED, self.OnItemCheck)
|
| 563 |
|
|
| 564 |
|
self.eventdict = {
|
| 565 |
|
'EVT_TREE_BEGIN_DRAG': self.OnBeginDrag,
|
| 566 |
|
'EVT_TREE_BEGIN_LABEL_EDIT': self.OnBeginEdit,
|
| 567 |
|
'EVT_TREE_BEGIN_RDRAG': self.OnBeginRDrag,
|
| 568 |
|
'EVT_TREE_DELETE_ITEM': self.OnDeleteItem,
|
| 569 |
|
'EVT_TREE_END_DRAG': self.OnEndDrag,
|
| 570 |
|
'EVT_TREE_END_LABEL_EDIT': self.OnEndEdit,
|
| 571 |
|
'EVT_TREE_ITEM_ACTIVATED': self.OnActivate,
|
| 572 |
|
'EVT_TREE_ITEM_CHECKED': self.OnItemCheck,
|
| 573 |
|
'EVT_TREE_ITEM_CHECKING': self.OnItemChecking,
|
| 574 |
|
'EVT_TREE_ITEM_COLLAPSED': self.OnItemCollapsed,
|
| 575 |
|
'EVT_TREE_ITEM_COLLAPSING': self.OnItemCollapsing,
|
| 576 |
|
'EVT_TREE_ITEM_EXPANDED': self.OnItemExpanded,
|
| 577 |
|
'EVT_TREE_ITEM_EXPANDING': self.OnItemExpanding,
|
| 578 |
|
'EVT_TREE_ITEM_GETTOOLTIP': self.OnToolTip,
|
| 579 |
|
'EVT_TREE_ITEM_MENU': self.OnItemMenu,
|
| 580 |
|
'EVT_TREE_ITEM_RIGHT_CLICK': self.OnRightDown,
|
| 581 |
|
'EVT_TREE_KEY_DOWN': self.OnKey,
|
| 582 |
|
'EVT_TREE_SEL_CHANGED': self.OnSelChanged,
|
| 583 |
|
'EVT_TREE_SEL_CHANGING': self.OnSelChanging,
|
| 584 |
|
"EVT_TREE_ITEM_HYPERLINK": self.OnHyperLink}
|
| 585 |
|
|
| 586 |
|
mainframe = wx.GetTopLevelParent(self)
|
| 587 |
|
|
| 588 |
|
if not hasattr(mainframe, "leftpanel"):
|
| 589 |
|
self.Bind(CT.EVT_TREE_ITEM_EXPANDED, self.OnItemExpanded)
|
| 590 |
|
self.Bind(CT.EVT_TREE_ITEM_COLLAPSED, self.OnItemCollapsed)
|
| 591 |
|
self.Bind(CT.EVT_TREE_SEL_CHANGED, self.OnSelChanged)
|
| 592 |
|
self.Bind(CT.EVT_TREE_SEL_CHANGING, self.OnSelChanging)
|
| 593 |
|
self.Bind(wx.EVT_RIGHT_DOWN, self.OnRightDown)
|
| 594 |
|
self.Bind(wx.EVT_RIGHT_UP, self.OnRightUp)
|
| 595 |
|
else:
|
| 596 |
|
for combos in mainframe.treeevents:
|
| 597 |
|
self.BindEvents(combos)
|
| 598 |
|
|
| 599 |
|
if hasattr(mainframe, "leftpanel"):
|
| 600 |
|
self.ChangeStyle(mainframe.treestyles)
|
| 601 |
|
|
| 602 |
|
if not(self.GetTreeStyle() & CT.TR_HIDE_ROOT):
|
| 603 |
|
self.SelectItem(self.root)
|
| 604 |
|
self.Expand(self.root)
|
| 605 |
|
|
| 606 |
|
|
| 607 |
|
def BindEvents(self, choice, recreate=False):
|
| 608 |
|
|
| 609 |
|
value = choice.GetValue()
|
| 610 |
|
text = choice.GetLabel()
|
| 611 |
|
|
| 612 |
|
evt = "CT." + text
|
| 613 |
|
binder = self.eventdict[text]
|
| 614 |
|
|
| 615 |
|
if value == 1:
|
| 616 |
|
if evt == "CT.EVT_TREE_BEGIN_RDRAG":
|
| 617 |
|
self.Bind(wx.EVT_RIGHT_DOWN, None)
|
| 618 |
|
self.Bind(wx.EVT_RIGHT_UP, None)
|
| 619 |
|
self.Bind(eval(evt), binder)
|
| 620 |
|
else:
|
| 621 |
|
self.Bind(eval(evt), None)
|
| 622 |
|
if evt == "CT.EVT_TREE_BEGIN_RDRAG":
|
| 623 |
|
self.Bind(wx.EVT_RIGHT_DOWN, self.OnRightDown)
|
| 624 |
|
self.Bind(wx.EVT_RIGHT_UP, self.OnRightUp)
|
| 625 |
|
|
| 626 |
|
|
| 627 |
|
def ChangeStyle(self, combos):
|
| 628 |
|
|
| 629 |
|
style = 0
|
| 630 |
|
for combo in combos:
|
| 631 |
|
if combo.GetValue() == 1:
|
| 632 |
|
style = style | eval("CT." + combo.GetLabel())
|
| 633 |
|
|
| 634 |
|
if self.GetTreeStyle() != style:
|
| 635 |
|
self.SetTreeStyle(style)
|
| 636 |
|
|
| 637 |
|
|
| 638 |
|
def OnCompareItems(self, item1, item2):
|
| 639 |
|
|
| 640 |
|
t1 = self.GetItemText(item1)
|
| 641 |
|
t2 = self.GetItemText(item2)
|
| 642 |
|
|
| 643 |
|
self.log.write('compare: ' + t1 + ' <> ' + t2 + "\n")
|
| 644 |
|
|
| 645 |
|
if t1 < t2:
|
| 646 |
|
return -1
|
| 647 |
|
if t1 == t2:
|
| 648 |
|
return 0
|
| 649 |
|
|
| 650 |
|
return 1
|
| 651 |
|
|
| 652 |
|
|
| 653 |
|
## def OnIdle(self, event):
|
| |
748 |
## strs = "Enable Associated Widget"
|
| |
749 |
## else:
|
| |
750 |
## strs = "Enable Associated Widget"
|
| |
751 |
## item6 = menu.Append(wx.ID_ANY, strs)
|
| |
752 |
##
|
| |
753 |
## if not haswin:
|
| |
754 |
## item6.Enable(False)
|
| |
755 |
##
|
| |
756 |
## item7 = menu.Append(wx.ID_ANY, "Disable Item")
|
| |
757 |
##
|
| |
758 |
## menu.AppendSeparator()
|
| |
759 |
## item8 = menu.Append(wx.ID_ANY, "Change Item Icons")
|
| |
760 |
## menu.AppendSeparator()
|
| |
761 |
## item9 = menu.Append(wx.ID_ANY, "Get Other Information For This Item")
|
| |
762 |
## menu.AppendSeparator()
|
| |
763 |
##
|
| |
764 |
## item10 = menu.Append(wx.ID_ANY, "Delete Item")
|
| |
765 |
## if item == self.GetRootItem():
|
| |
766 |
## item10.Enable(False)
|
| |
767 |
## item11 = menu.Append(wx.ID_ANY, "Prepend An Item")
|
| |
768 |
## item12 = menu.Append(wx.ID_ANY, "Append An Item")
|
| |
769 |
##
|
| |
770 |
## self.Bind(wx.EVT_MENU, self.OnItemBackground, item1)
|
| |
771 |
## self.Bind(wx.EVT_MENU, self.OnItemForeground, item2)
|
| |
772 |
## self.Bind(wx.EVT_MENU, self.OnItemBold, item3)
|
| |
773 |
## self.Bind(wx.EVT_MENU, self.OnItemFont, item4)
|
| |
774 |
## self.Bind(wx.EVT_MENU, self.OnItemHyperText, item5)
|
| |
775 |
## self.Bind(wx.EVT_MENU, self.OnEnableWindow, item6)
|
| |
776 |
## self.Bind(wx.EVT_MENU, self.OnDisableItem, item7)
|
| |
777 |
## self.Bind(wx.EVT_MENU, self.OnItemIcons, item8)
|
| |
778 |
## self.Bind(wx.EVT_MENU, self.OnItemInfo, item9)
|
| |
779 |
## self.Bind(wx.EVT_MENU, self.OnItemDelete, item10)
|
| |
780 |
## self.Bind(wx.EVT_MENU, self.OnItemPrepend, item11)
|
| |
781 |
## self.Bind(wx.EVT_MENU, self.OnItemAppend, item12)
|
| |
782 |
##
|
| |
783 |
## self.PopupMenu(menu)
|
| |
784 |
## menu.Destroy()
|
| |
785 |
##
|
| |
786 |
##
|
| |
787 |
## def OnItemBackground(self, event):
|
| |
788 |
##
|
| |
789 |
## colourdata = wx.ColourData()
|
| |
790 |
## colourdata.SetColour(self.itemdict["back"])
|
| |
791 |
## dlg = wx.ColourDialog(self, colourdata)
|
| |
792 |
##
|
| |
793 |
## dlg.GetColourData().SetChooseFull(True)
|
| |
794 |
##
|
| |
795 |
## if dlg.ShowModal() == wx.ID_OK:
|
| |
796 |
## data = dlg.GetColourData()
|
| |
797 |
## col1 = data.GetColour().Get()
|
| |
798 |
## self.SetItemBackgroundColour(self.current, col1)
|
| |
799 |
## dlg.Destroy()
|
| |
800 |
##
|
| |
801 |
##
|
| |
802 |
## def OnItemForeground(self, event):
|
| |
803 |
##
|
| |
804 |
## colourdata = wx.ColourData()
|
| |
805 |
## colourdata.SetColour(self.itemdict["fore"])
|
| |
806 |
## dlg = wx.ColourDialog(self, colourdata)
|
| |
807 |
##
|
| |
808 |
## dlg.GetColourData().SetChooseFull(True)
|
| |
809 |
##
|
| |
810 |
## if dlg.ShowModal() == wx.ID_OK:
|
| |
811 |
## data = dlg.GetColourData()
|
| |
812 |
## col1 = data.GetColour().Get()
|
| |
813 |
## self.SetItemTextColour(self.current, col1)
|
| |
814 |
## dlg.Destroy()
|
| |
815 |
##
|
| |
816 |
##
|
| |
817 |
## def OnItemBold(self, event):
|
| |
818 |
##
|
| |
819 |
## self.SetItemBold(self.current, not self.itemdict["isbold"])
|
| |
820 |
##
|
| |
821 |
##
|
| |
822 |
## def OnItemFont(self, event):
|
| |
823 |
##
|
| |
824 |
## data = wx.FontData()
|
| |
825 |
## font = self.itemdict["font"]
|
| |
826 |
##
|
| |
827 |
## if font is None:
|
| |
828 |
## font = wx.SystemSettings_GetFont(wx.SYS_DEFAULT_GUI_FONT)
|
| |
829 |
##
|
| |
830 |
## data.SetInitialFont(font)
|
| |
831 |
##
|
| |
832 |
## dlg = wx.FontDialog(self, data)
|
| |
833 |
##
|
| |
834 |
## if dlg.ShowModal() == wx.ID_OK:
|
| |
835 |
## data = dlg.GetFontData()
|
| |
836 |
## font = data.GetChosenFont()
|
| |
837 |
## self.SetItemFont(self.current, font)
|
| |
838 |
##
|
| |
839 |
## dlg.Destroy()
|
| |
840 |
##
|
| |
841 |
##
|
| |
842 |
## def OnItemHyperText(self, event):
|
| |
843 |
##
|
| |
844 |
## self.SetItemHyperText(self.current, not self.itemdict["ishtml"])
|
| |
845 |
##
|
| |
846 |
##
|
| |
847 |
## def OnEnableWindow(self, event):
|
| |
848 |
##
|
| |
849 |
## enable = self.GetItemWindowEnabled(self.current)
|
| |
850 |
## self.SetItemWindowEnabled(self.current, not enable)
|
| |
851 |
##
|
| |
852 |
##
|
| |
853 |
## def OnDisableItem(self, event):
|
| |
854 |
##
|
| |
855 |
## self.EnableItem(self.current, False)
|
| |
856 |
##
|
| |
857 |
##
|
| |
858 |
## def OnItemIcons(self, event):
|
| |
859 |
##
|
| |
860 |
## bitmaps = [self.itemdict["normal"], self.itemdict["selected"],
|
| |
861 |
## self.itemdict["expanded"], self.itemdict["selexp"]]
|
| |
862 |
##
|
| |
863 |
## wx.BeginBusyCursor()
|
| |
864 |
## dlg = TreeIcons(self, -1, bitmaps=bitmaps)
|
| |
865 |
## wx.EndBusyCursor()
|
| |
866 |
## dlg.ShowModal()
|
| |
867 |
##
|
| |
868 |
##
|
| |
869 |
## def SetNewIcons(self, bitmaps):
|
| |
870 |
##
|
| |
871 |
## self.SetItemImage(self.current, bitmaps[0], CT.TreeItemIcon_Normal)
|
| |
872 |
## self.SetItemImage(self.current, bitmaps[1], CT.TreeItemIcon_Selected)
|
| |
873 |
## self.SetItemImage(self.current, bitmaps[2], CT.TreeItemIcon_Expanded)
|
| |
874 |
## self.SetItemImage(self.current, bitmaps[3], CT.TreeItemIcon_SelectedExpanded)
|
| |
875 |
##
|
| |
876 |
##
|
| |
877 |
## def OnItemInfo(self, event):
|
| |
878 |
##
|
| |
879 |
## itemtext = self.itemdict["text"]
|
| |
880 |
## numchildren = str(self.itemdict["children"])
|
| |
881 |
## itemtype = self.itemdict["itemtype"]
|
| |
882 |
## pydata = repr(type(self.itemdict["pydata"]))
|
| |
883 |
##
|
| |
884 |
## if itemtype == 0:
|
| |
885 |
## itemtype = "Normal"
|
| |
886 |
## elif itemtype == 1:
|
| |
887 |
## itemtype = "CheckBox"
|
| |
888 |
## else:
|
| |
889 |
## itemtype = "RadioButton"
|
| |
890 |
##
|
| |
891 |
## strs = "Information On Selected Item:\n\n" + "Text: " + itemtext + "\n" \
|
| |
892 |
## "Number Of Children: " + numchildren + "\n" \
|
| |
893 |
## "Item Type: " + itemtype + "\n" \
|
| |
894 |
## "Item Data Type: " + pydata + "\n"
|
| |
895 |
##
|
| |
896 |
## dlg = wx.MessageDialog(self, strs, "CustomTreeCtrlDemo Info", wx.OK | wx.ICON_INFORMATION)
|
| |
897 |
## dlg.ShowModal()
|
| |
898 |
## dlg.Destroy()
|
| |
899 |
##
|
| |
900 |
##
|
| |
901 |
## def OnItemDelete(self, event):
|
| |
902 |
##
|
| |
903 |
## strs = "Are You Sure You Want To Delete Item " + self.GetItemText(self.current) + "?"
|
| |
904 |
## dlg = wx.MessageDialog(None, s |