/lib/pwiki/customtreectrl.py
Python | 6065 lines | 5857 code | 74 blank | 134 comment | 14 complexity | 6184bada91d2c01aab5636d1e5082b99 MD5 | raw file
Possible License(s): LGPL-2.1
Large files files are truncated, but you can click here to view the full file
- # --------------------------------------------------------------------------------- #
- # CUSTOMTREECTRL wxPython IMPLEMENTATION
- # Inspired By And Heavily Based On wxGenericTreeCtrl.
- #
- # Andrea Gavana, @ 17 May 2006
- # Latest Revision: 16 Apr 2007, 11.00 CET
- #
- #
- # TODO List
- #
- # Almost All The Features Of wx.TreeCtrl Are Available, And There Is Practically
- # No Limit In What Could Be Added To This Class. The First Things That Comes
- # To My Mind Are:
- #
- # 1. Implement The Style TR_EXTENDED (I Have Never Used It, But It May Be Useful).
- #
- # 2. Add Support For 3-State CheckBoxes (Is That Really Useful?).
- #
- # 3. Try To Implement A More Flicker-Free Background Image In Cases Like
- # Centered Or Stretched Image (Now CustomTreeCtrl Supports Only Tiled
- # Background Images).
- #
- # 4. Try To Mimic Windows wx.TreeCtrl Expanding/Collapsing behaviour: CustomTreeCtrl
- # Suddenly Expands/Collapses The Nodes On Mouse Click While The Native Control
- # Has Some Kind Of "Smooth" Expanding/Collapsing, Like A Wave. I Don't Even
- # Know Where To Start To Do That.
- #
- # 5. Speed Up General OnPaint Things? I Have No Idea, Here CustomTreeCtrl Is Quite
- # Fast, But We Should See On Slower Machines.
- #
- #
- # For All Kind Of Problems, Requests Of Enhancements And Bug Reports, Please
- # Write To Me At:
- #
- # gavana@kpo.kz
- # andrea.gavana@gmail.com
- #
- # Or, Obviously, To The wxPython Mailing List!!!
- #
- #
- # Modifications by Michael Butscher (mbutscher@gmx.de) based on
- # rev. 1.14 in wxWidgets repository
- #
- # Modifications by Michael Butscher Jan. 2007:
- #
- # - Expand buttons at the same place where they are on Windows tree
- # - No button for root element
- # - Expansion near the bottom scrolls tree appropriately
- # - Flicker-free expansion/collapse (not tested with background image)
- # - Unselect also works on single-select tree
- # - Option to set image list without generation of grayed icons (faster)
- #
- # Modifications by Michael Butscher May 2007:
- # - Tooltip if label is broader than window
- #
- # Modifications by Michael Butscher May 2010:
- # - Parameter in SelectItem() to suppress event generation
- #
- #
- # End Of Comments
- # --------------------------------------------------------------------------------- #
-
-
- """
- Description
- ===========
-
- CustomTreeCtrl is a class that mimics the behaviour of wx.TreeCtrl, with almost the
- same base functionalities plus some more enhancements. This class does not rely on
- the native control, as it is a full owner-drawn tree control.
- Apart of the base functionalities of CustomTreeCtrl (described below), in addition
- to the standard wx.TreeCtrl behaviour this class supports:
-
- * CheckBox-type items: checkboxes are easy to handle, just selected or unselected
- state with no particular issues in handling the item's children;
-
- * RadioButton-type items: since I elected to put radiobuttons in CustomTreeCtrl, I
- needed some way to handle them, that made sense. So, I used the following approach:
- - All peer-nodes that are radiobuttons will be mutually exclusive. In other words,
- only one of a set of radiobuttons that share a common parent can be checked at
- once. If a radiobutton node becomes checked, then all of its peer radiobuttons
- must be unchecked.
- - If a radiobutton node becomes unchecked, then all of its child nodes will become
- inactive.
-
- * Hyperlink-type items: they look like an hyperlink, with the proper mouse cursor on
- hovering.
-
- * Multiline text items.
-
- * Enabling/disabling items (together with their plain or grayed out icons).
-
- * Whatever non-toplevel widget can be attached next to an item.
-
- * Default selection style, gradient (horizontal/vertical) selection style and Windows
- Vista selection style.
-
- * Customized drag and drop images built on the fly.
-
- * Setting the CustomTreeCtrl item buttons to a personalized imagelist.
-
- * Setting the CustomTreeCtrl check/radio item icons to a personalized imagelist.
-
- * Changing the style of the lines that connect the items (in terms of wx.Pen styles).
-
- * Using an image as a CustomTreeCtrl background (currently only in "tile" mode).
-
- And a lot more. Check the demo for an almost complete review of the functionalities.
-
-
- Base Functionalities
- ====================
-
- CustomTreeCtrl supports all the wx.TreeCtrl styles, except:
- - TR_EXTENDED: supports for this style is on the todo list (Am I sure of this?).
-
- Plus it has 3 more styles to handle checkbox-type items:
- - TR_AUTO_CHECK_CHILD : automatically checks/unchecks the item children;
- - TR_AUTO_CHECK_PARENT : automatically checks/unchecks the item parent;
- - TR_AUTO_TOGGLE_CHILD: automatically toggles the item children.
-
- All the methods available in wx.TreeCtrl are also available in CustomTreeCtrl.
-
-
- Events
- ======
-
- All the events supported by wx.TreeCtrl are also available in CustomTreeCtrl, with
- a few exceptions:
-
- - EVT_TREE_GET_INFO (don't know what this means);
- - EVT_TREE_SET_INFO (don't know what this means);
- - EVT_TREE_ITEM_MIDDLE_CLICK (not implemented, but easy to add);
- - EVT_TREE_STATE_IMAGE_CLICK: no need for that, look at the checking events below.
-
- Plus, CustomTreeCtrl supports the events related to the checkbutton-type items:
-
- - EVT_TREE_ITEM_CHECKING: an item is being checked;
- - EVT_TREE_ITEM_CHECKED: an item has been checked.
-
- And to hyperlink-type items:
-
- - EVT_TREE_ITEM_HYPERLINK: an hyperlink item has been clicked (this event is sent
- after the EVT_TREE_SEL_CHANGED event).
-
-
- Supported Platforms
- ===================
-
- CustomTreeCtrl has been tested on the following platforms:
- * Windows (Windows XP);
- * GTK (Thanks to Michele Petrazzo);
- * Mac OS (Thanks to John Jackson).
-
-
- Latest Revision: Andrea Gavana @ 16 Apr 2007, 11.00 CET
- Version 1.0
-
- """
-
-
- import wx
- import zlib
- import cStringIO
- import types
- import traceback
-
-
- # ----------------------------------------------------------------------------
- # Constants
- # ----------------------------------------------------------------------------
-
- _NO_IMAGE = -1
- _PIXELS_PER_UNIT = 10
-
- # Bug workaround: In wxPython 2.6 these constants weren't defined
- # in 2.8 they are defined under a different name and with different values
-
- try:
- wxWINDOWS_NT = wx.OS_WINDOWS_NT
- except AttributeError:
- wxWINDOWS_NT = 18 # For wxGetOsVersion(), this includes NT 4.0, 2000, XP
-
- try:
- wxWIN95 = wx.OS_WINDOWS_9X
- except AttributeError:
- wxWIN95 = 20 # For wx.GetOsVersion(), this includes also Win 98 and ME
-
-
-
- # Start editing the current item after half a second (if the mouse hasn't
- # been clicked/moved)
- _DELAY = 500
-
- # ----------------------------------------------------------------------------
- # Constants
- # ----------------------------------------------------------------------------
-
- # Enum for different images associated with a treectrl item
- TreeItemIcon_Normal = 0 # not selected, not expanded
- TreeItemIcon_Selected = 1 # selected, not expanded
- TreeItemIcon_Expanded = 2 # not selected, expanded
- TreeItemIcon_SelectedExpanded = 3 # selected, expanded
-
- TreeItemIcon_Checked = 0 # check button, checked
- TreeItemIcon_NotChecked = 1 # check button, not checked
- TreeItemIcon_Flagged = 2 # radio button, selected
- TreeItemIcon_NotFlagged = 3 # radio button, not selected
-
- # ----------------------------------------------------------------------------
- # CustomTreeCtrl flags
- # ----------------------------------------------------------------------------
-
- TR_NO_BUTTONS = wx.TR_NO_BUTTONS # for convenience
- TR_HAS_BUTTONS = wx.TR_HAS_BUTTONS # draw collapsed/expanded btns
- TR_NO_LINES = wx.TR_NO_LINES # don't draw lines at all
- TR_LINES_AT_ROOT = wx.TR_LINES_AT_ROOT # connect top-level nodes
- TR_TWIST_BUTTONS = wx.TR_TWIST_BUTTONS # still used by wxTreeListCtrl
-
- TR_SINGLE = wx.TR_SINGLE # for convenience
- TR_MULTIPLE = wx.TR_MULTIPLE # can select multiple items
- TR_EXTENDED = wx.TR_EXTENDED # TODO: allow extended selection
- TR_HAS_VARIABLE_ROW_HEIGHT = wx.TR_HAS_VARIABLE_ROW_HEIGHT # what it says
-
- TR_EDIT_LABELS = wx.TR_EDIT_LABELS # can edit item labels
- TR_ROW_LINES = wx.TR_ROW_LINES # put border around items
- TR_HIDE_ROOT = wx.TR_HIDE_ROOT # don't display root node
-
- TR_FULL_ROW_HIGHLIGHT = wx.TR_FULL_ROW_HIGHLIGHT # highlight full horz space
-
- TR_AUTO_CHECK_CHILD = 0x04000 # only meaningful for checkboxes
- TR_AUTO_TOGGLE_CHILD = 0x08000 # only meaningful for checkboxes
- TR_AUTO_CHECK_PARENT = 0x10000 # only meaningful for checkboxes
-
- TR_DEFAULT_STYLE = wx.TR_DEFAULT_STYLE # default style for the tree control
-
- # Values for the `flags' parameter of CustomTreeCtrl.HitTest() which determine
- # where exactly the specified point is situated:
-
- TREE_HITTEST_ABOVE = wx.TREE_HITTEST_ABOVE
- TREE_HITTEST_BELOW = wx.TREE_HITTEST_BELOW
- TREE_HITTEST_NOWHERE = wx.TREE_HITTEST_NOWHERE
- # on the button associated with an item.
- TREE_HITTEST_ONITEMBUTTON = wx.TREE_HITTEST_ONITEMBUTTON
- # on the bitmap associated with an item.
- TREE_HITTEST_ONITEMICON = wx.TREE_HITTEST_ONITEMICON
- # on the indent associated with an item.
- TREE_HITTEST_ONITEMINDENT = wx.TREE_HITTEST_ONITEMINDENT
- # on the label (string) associated with an item.
- TREE_HITTEST_ONITEMLABEL = wx.TREE_HITTEST_ONITEMLABEL
- # on the right of the label associated with an item.
- TREE_HITTEST_ONITEMRIGHT = wx.TREE_HITTEST_ONITEMRIGHT
- # on the label (string) associated with an item.
- TREE_HITTEST_ONITEMSTATEICON = wx.TREE_HITTEST_ONITEMSTATEICON
- # on the left of the CustomTreeCtrl.
- TREE_HITTEST_TOLEFT = wx.TREE_HITTEST_TOLEFT
- # on the right of the CustomTreeCtrl.
- TREE_HITTEST_TORIGHT = wx.TREE_HITTEST_TORIGHT
- # on the upper part (first half) of the item.
- TREE_HITTEST_ONITEMUPPERPART = wx.TREE_HITTEST_ONITEMUPPERPART
- # on the lower part (second half) of the item.
- TREE_HITTEST_ONITEMLOWERPART = wx.TREE_HITTEST_ONITEMLOWERPART
- # on the check icon, if present
- TREE_HITTEST_ONITEMCHECKICON = 0x4000
- # anywhere on the item
- TREE_HITTEST_ONITEM = TREE_HITTEST_ONITEMICON | TREE_HITTEST_ONITEMLABEL | TREE_HITTEST_ONITEMCHECKICON
-
-
- # Background Image Style
- _StyleTile = 0
- _StyleStretch = 1
-
- # Windows Vista Colours
- _rgbSelectOuter = wx.Colour(170, 200, 245)
- _rgbSelectInner = wx.Colour(230, 250, 250)
- _rgbSelectTop = wx.Colour(210, 240, 250)
- _rgbSelectBottom = wx.Colour(185, 215, 250)
- _rgbNoFocusTop = wx.Colour(250, 250, 250)
- _rgbNoFocusBottom = wx.Colour(235, 235, 235)
- _rgbNoFocusOuter = wx.Colour(220, 220, 220)
- _rgbNoFocusInner = wx.Colour(245, 245, 245)
-
- # Flags for wx.RendererNative
- _CONTROL_EXPANDED = 8
- _CONTROL_CURRENT = 16
-
- # Version Info
- __version__ = "0.8"
-
-
- # ----------------------------------------------------------------------------
- # CustomTreeCtrl events and binding for handling them
- # ----------------------------------------------------------------------------
-
- wxEVT_TREE_BEGIN_DRAG = wx.wxEVT_COMMAND_TREE_BEGIN_DRAG
- wxEVT_TREE_BEGIN_RDRAG = wx.wxEVT_COMMAND_TREE_BEGIN_RDRAG
- wxEVT_TREE_BEGIN_LABEL_EDIT = wx.wxEVT_COMMAND_TREE_BEGIN_LABEL_EDIT
- wxEVT_TREE_END_LABEL_EDIT = wx.wxEVT_COMMAND_TREE_END_LABEL_EDIT
- wxEVT_TREE_DELETE_ITEM = wx.wxEVT_COMMAND_TREE_DELETE_ITEM
- wxEVT_TREE_GET_INFO = wx.wxEVT_COMMAND_TREE_GET_INFO
- wxEVT_TREE_SET_INFO = wx.wxEVT_COMMAND_TREE_SET_INFO
- wxEVT_TREE_ITEM_EXPANDED = wx.wxEVT_COMMAND_TREE_ITEM_EXPANDED
- wxEVT_TREE_ITEM_EXPANDING = wx.wxEVT_COMMAND_TREE_ITEM_EXPANDING
- wxEVT_TREE_ITEM_COLLAPSED = wx.wxEVT_COMMAND_TREE_ITEM_COLLAPSED
- wxEVT_TREE_ITEM_COLLAPSING = wx.wxEVT_COMMAND_TREE_ITEM_COLLAPSING
- wxEVT_TREE_SEL_CHANGED = wx.wxEVT_COMMAND_TREE_SEL_CHANGED
- wxEVT_TREE_SEL_CHANGING = wx.wxEVT_COMMAND_TREE_SEL_CHANGING
- wxEVT_TREE_KEY_DOWN = wx.wxEVT_COMMAND_TREE_KEY_DOWN
- wxEVT_TREE_ITEM_ACTIVATED = wx.wxEVT_COMMAND_TREE_ITEM_ACTIVATED
- wxEVT_TREE_ITEM_RIGHT_CLICK = wx.wxEVT_COMMAND_TREE_ITEM_RIGHT_CLICK
- wxEVT_TREE_ITEM_MIDDLE_CLICK = wx.wxEVT_COMMAND_TREE_ITEM_MIDDLE_CLICK
- wxEVT_TREE_END_DRAG = wx.wxEVT_COMMAND_TREE_END_DRAG
- wxEVT_TREE_STATE_IMAGE_CLICK = wx.wxEVT_COMMAND_TREE_STATE_IMAGE_CLICK
- wxEVT_TREE_ITEM_GETTOOLTIP = wx.wxEVT_COMMAND_TREE_ITEM_GETTOOLTIP
- wxEVT_TREE_ITEM_MENU = wx.wxEVT_COMMAND_TREE_ITEM_MENU
- wxEVT_TREE_ITEM_CHECKING = wx.NewEventType()
- wxEVT_TREE_ITEM_CHECKED = wx.NewEventType()
- wxEVT_TREE_ITEM_HYPERLINK = wx.NewEventType()
-
- EVT_TREE_BEGIN_DRAG = wx.EVT_TREE_BEGIN_DRAG
- EVT_TREE_BEGIN_RDRAG = wx.EVT_TREE_BEGIN_RDRAG
- EVT_TREE_BEGIN_LABEL_EDIT = wx.EVT_TREE_BEGIN_LABEL_EDIT
- EVT_TREE_END_LABEL_EDIT = wx.EVT_TREE_END_LABEL_EDIT
- EVT_TREE_DELETE_ITEM = wx.EVT_TREE_DELETE_ITEM
- EVT_TREE_GET_INFO = wx.EVT_TREE_GET_INFO
- EVT_TREE_SET_INFO = wx.EVT_TREE_SET_INFO
- EVT_TREE_ITEM_EXPANDED = wx.EVT_TREE_ITEM_EXPANDED
- EVT_TREE_ITEM_EXPANDING = wx.EVT_TREE_ITEM_EXPANDING
- EVT_TREE_ITEM_COLLAPSED = wx.EVT_TREE_ITEM_COLLAPSED
- EVT_TREE_ITEM_COLLAPSING = wx.EVT_TREE_ITEM_COLLAPSING
- EVT_TREE_SEL_CHANGED = wx.EVT_TREE_SEL_CHANGED
- EVT_TREE_SEL_CHANGING = wx.EVT_TREE_SEL_CHANGING
- EVT_TREE_KEY_DOWN = wx.EVT_TREE_KEY_DOWN
- EVT_TREE_ITEM_ACTIVATED = wx.EVT_TREE_ITEM_ACTIVATED
- EVT_TREE_ITEM_RIGHT_CLICK = wx.EVT_TREE_ITEM_RIGHT_CLICK
- EVT_TREE_ITEM_MIDDLE_CLICK = wx.EVT_TREE_ITEM_MIDDLE_CLICK
- EVT_TREE_END_DRAG = wx.EVT_TREE_END_DRAG
- EVT_TREE_STATE_IMAGE_CLICK = wx.EVT_TREE_STATE_IMAGE_CLICK
- EVT_TREE_ITEM_GETTOOLTIP = wx.EVT_TREE_ITEM_GETTOOLTIP
- EVT_TREE_ITEM_MENU = wx.EVT_TREE_ITEM_MENU
- EVT_TREE_ITEM_CHECKING = wx.PyEventBinder(wxEVT_TREE_ITEM_CHECKING, 1)
- EVT_TREE_ITEM_CHECKED = wx.PyEventBinder(wxEVT_TREE_ITEM_CHECKED, 1)
- EVT_TREE_ITEM_HYPERLINK = wx.PyEventBinder(wxEVT_TREE_ITEM_HYPERLINK, 1)
-
-
- def GetFlaggedData():
- return zlib.decompress(
- 'x\xda\x012\x02\xcd\xfd\x89PNG\r\n\x1a\n\x00\x00\x00\rIHDR\x00\x00\x00\r\x00\
- \x00\x00\r\x08\x06\x00\x00\x00r\xeb\xe4|\x00\x00\x00\x04sBIT\x08\x08\x08\x08\
- |\x08d\x88\x00\x00\x01\xe9IDAT(\x91u\x92\xd1K\xd3a\x14\x86\x9f\xef|J2J\xc3%\
- \x85\x8e\x1cb\x93Hl\xd9,\x06F]4\x10\tD3\x83\x88\xc8\xbf\xc0\xb4\xaeBP1\xe9\
- \xa2(\xec\xaan\xc3\x82pD\xa1\x84\xb0\x88@3\x8c\xc9\xa2bT\xa2^\x8c\x81V3\xb6\
- \xb5\x9f\xce9\xbe.j\xb20\xdf\xeb\xf7\xe19\x07^\xa5D\x93\x9f\x9ea\xbf\t\x04\
- \xbf\x12\x8b[\xd8Kl\xf8<.\xeet\xb5\xab\xfc\x8e\xca\x87*ZzM\xf3\xb1j|G\xab\
- \xf0\xd4\x94\x13\x9a_&0\xbb\xc8\xd8\xf4g\xa2\xcfo\xa8-P\xc7\xf5\x07\xa6\xedD\
- \r\x8d\xb5\xfb\x11\x11\xb4\xd6\x88h\xb4\xd6L}\x8a\xf0\xe4\xd5G\x1e\rt*\x00\
- \xc9\x19\xb6\x03D4\xa7\xdcU\\8\xed\xa6\xa2\xa5\xd7\x00\xe8\xab\xf7\x9e\x9a\
- \xca\xb2\x9d\\\xf2\xd5!"dT\x86\xc9\xe4\x14\x83s\x83HF\xe3\xdc\xe5\xa4\xa8\
- \xb0\x88\xaa\xf2=D\x7f$il>\xdf\xafSe\xf5\xfd\x9dM\x87\xa9\xdc\xb7\x1b\xad5\
- \x93\xc9)\xfc\xe9Q\x12\xe9\x04\x13\x0b\x13\x94\xaaR\xdc{\x8f "\xec(,\xe0\xfe\
- \xb3\xb7H,a\xe1\xa9)\xdf<e$2Ble\x85\x94e\xb1\x96\xcep\xfb\xdd-D\x04\xa5\x14\
- \xdeZ\'\xb1\x84\x85\xd8\x8bm\x84\xe6\x977\x7f8kog)\xba\xc4\xb7\xe5\xef$\xe2?\
- \xe9\xa9\xbf\x86R\n\x11a&\x1c\xc1^lC|\r.\x02\xb3\x8b\x9b\xa6&G\x13W\xaa\xbb\
- \x91_\x05\x0c\x1d\xbfI\xc7\xa1\x8e\xbf&a|:\x8c\xaf\xc1\x05J4\x8e\xd6>36\x192\
- \xc9d\xdc\xa4RI\xb3\xbaj\x99tz\xcd\xac\xaf\xa7\xcd\xc6F\xc6d\xb3Y\xf32\xf8\
- \xc58Z\xfb\x8c\x12\xfd\x07R\xa2\xb98\xf0\xd0\xbcx\xf3a[\xe0\xf2\xd0c\x93\xeb\
- nYD\xdb\xc9:\xcex\x0f\xe2\xadu2\x13\x8e0>\x1d\xc6\xff\xfa\xfd\xff\x17\x91K\
- \xf7\xf0\xa8\t\x04\xe7X\x89[\x94\x96\xd8\xf0y\x0ep\xb7\xeb\xdc?\xdb\xfb\r|\
- \xd0\xd1]\x98\xbdm\xdc\x00\x00\x00\x00IEND\xaeB`\x82\x91\xe2\x08\x8f' )
-
- def GetFlaggedBitmap():
- return wx.BitmapFromImage(GetFlaggedImage())
-
- def GetFlaggedImage():
- stream = cStringIO.StringIO(GetFlaggedData())
- return wx.ImageFromStream(stream)
-
- #----------------------------------------------------------------------
- def GetNotFlaggedData():
- return zlib.decompress(
- 'x\xda\x01\xad\x01R\xfe\x89PNG\r\n\x1a\n\x00\x00\x00\rIHDR\x00\x00\x00\r\x00\
- \x00\x00\r\x08\x06\x00\x00\x00r\xeb\xe4|\x00\x00\x00\x04sBIT\x08\x08\x08\x08\
- |\x08d\x88\x00\x00\x01dIDAT(\x91\x95\xd21K\x82a\x14\x86\xe1\xe7=\xef798\xb8\
- \x89\x0e"|Cd\x94\x88\x83\x065\x88\x108\x88Q\x8b-\xd1\x1f\x88\x9a\n\x04\x11j\
- \x8eh\x08\xdaZ\x84(\x82\xc2 0\xc1 $\xb4P\xa1\x10\x11D\xb061\xd4\xd4\xcc\xe44\
- \x84 \xa8Hg~.\xcer\x0bA\x12\x83\xb7ux\xce\xd1T\x01\xd5z\x0b:\xad\x06n\xbb\
- \x8a\x83\xcdU1\xb8\x11\x83\xc8\xe0\r\xf0\x92\xdd\x0c\x97\xd5\x04\x9b\xaaG\
- \xb6XA,]B\xe41\x8f\xf7\xab=1\x84Vv\x8e\xd97\xaf\xc29m\x04\x91\x84\x94\n\xa4\
- \x94P\x14\x05\x89\xd77\x9c\xc5_\x10\x0em\x08\x00\xa0\xfe\x87q@J\x89\xc593\
- \xfc\xaeY\x18\xbc\x01\x06\x00\xb1}t\xc9\xf5F\x03\x01\xbfs$ \x92 "\x10I\xec\
- \x9e\xdcBQ\x08\x14M\x15\xe0\xb2\x9a&\x02"\x82\xc71\x85h\xaa\x00\xaa\xd6[\xb0\
- \xa9\xfa\x89\x80\x88\xe0\xb0\x98P\xad\xb7@:\xad\x06\xd9be" "$se\xe8\xb4\x1a\
- \x90\xdb\xae"\x96.M\x04D\x84H"\x07\xb7]\x05\x04I\x18}A\xbe\xbe\x7f\xe6Z\xed\
- \x83\x1b\x8d\x1a7\x9b\x9f\xdcn\xb7\xb8\xd3\xf9\xe2n\xf7\x9b{\xbd\x1f\xbe{\
- \xca\xb3\xd1\x17dA\xf2\x0f\t\x92X\x0b\x9d\xf2\xcdCf,X\xdf\x0fs\x7f;T\xc4\xf2\
- \xc2\x0c<\x8e)8,&$seD\x129\\\xc43\xa3\x8b\xf8O{\xbf\xf1\xb5\xa5\x990\x0co\
- \xd6\x00\x00\x00\x00IEND\xaeB`\x82&\x11\xab!' )
-
- def GetNotFlaggedBitmap():
- return wx.BitmapFromImage(GetNotFlaggedImage())
-
- def GetNotFlaggedImage():
- stream = cStringIO.StringIO(GetNotFlaggedData())
- return wx.ImageFromStream(stream)
-
- #----------------------------------------------------------------------
- def GetCheckedData():
- return zlib.decompress(
- "x\xda\xeb\x0c\xf0s\xe7\xe5\x92\xe2b``\xe0\xf5\xf4p\t\x02\xd1 \xcc\xc1\x06$\
- \x8b^?\xa9\x01R,\xc5N\x9e!\x1c@P\xc3\x91\xd2\x01\xe4\xaf\xf4tq\x0c\xd1\x98\
- \x98<\x853\xe7\xc7y\x07\xa5\x84\xc4\x84\x84\x04\x0b3C1\xbd\x03'N\x1c9p\x84\
- \xe5\xe0\x993gx||\xce\x14\xcc\xea\xec\xect4^7\xbf\x91\xf3&\x8b\x93\xd4\x8c\
- \x19\n\xa7fv\\L\xd8p\x90C\xebx\xcf\x05\x17\x0ff \xb8c\xb6Cm\x06\xdb\xea\xd8\
- \xb2\x08\xd3\x03W\x0c\x8c\x8c\x16e%\xa5\xb5E\xe4\xee\xba\xca\xe4|\xb8\xb7\
- \xe35OOO\xcf\n\xb3\x83>m\x8c1R\x12\x92\x81s\xd8\x0b/\xb56\x14k|l\\\xc7x\xb4\
- \xf2\xc4\xc1*\xd5'B~\xbc\x19uNG\x98\x85\x85\x8d\xe3x%\x16\xb2_\xee\xf1\x07\
- \x99\xcb\xacl\x99\xc9\xcf\xb0\xc0_.\x87+\xff\x99\x05\xd0\xd1\x0c\x9e\xae~.\
- \xeb\x9c\x12\x9a\x00\x92\xccS\x9f" )
-
- def GetCheckedBitmap():
- return wx.BitmapFromImage(GetCheckedImage())
-
- def GetCheckedImage():
- stream = cStringIO.StringIO(GetCheckedData())
- return wx.ImageFromStream(stream)
-
- #----------------------------------------------------------------------
- def GetNotCheckedData():
- return zlib.decompress(
- "x\xda\xeb\x0c\xf0s\xe7\xe5\x92\xe2b``\xe0\xf5\xf4p\t\x02\xd1 \xcc\xc1\x06$\
- \x8b^?\xa9\x01R,\xc5N\x9e!\x1c@P\xc3\x91\xd2\x01\xe4\xe7z\xba8\x86hL\x9c{\
- \xe9 o\x83\x01\x07\xeb\x85\xf3\xed\x86w\x0ed\xdaT\x96\x8a\xbc\x9fw\xe7\xc4\
- \xd9/\x01\x8b\x97\x8a\xd7\xab*\xfar\xf0Ob\x93^\xf6\xd5%\x9d\x85A\xe6\xf6\x1f\
- \x11\x8f{/\x0b\xf8wX+\x9d\xf2\xb6:\x96\xca\xfe\x9a3\xbeA\xe7\xed\x1b\xc6%\
- \xfb=X3'sI-il\t\xb9\xa0\xc0;#\xd4\x835m\x9a\xf9J\x85\xda\x16.\x86\x03\xff\
- \xee\xdcc\xdd\xc0\xce\xf9\xc8\xcc(\xbe\x1bh1\x83\xa7\xab\x9f\xcb:\xa7\x84&\
- \x00\x87S=\xbe" )
-
- def GetNotCheckedBitmap():
- return wx.BitmapFromImage(GetNotCheckedImage())
-
- def GetNotCheckedImage():
- stream = cStringIO.StringIO(GetNotCheckedData())
- return wx.ImageFromStream(stream)
-
-
- def GrayOut(anImage):
- """
- Convert the given image (in place) to a grayed-out version,
- appropriate for a 'disabled' appearance.
- """
-
- factor = 0.7 # 0 < f < 1. Higher Is Grayer
-
- if anImage.HasMask():
- maskColor = (anImage.GetMaskRed(), anImage.GetMaskGreen(), anImage.GetMaskBlue())
- else:
- maskColor = None
-
- data = map(ord, list(anImage.GetData()))
-
- for i in range(0, len(data), 3):
-
- pixel = (data[i], data[i+1], data[i+2])
- pixel = MakeGray(pixel, factor, maskColor)
-
- for x in range(3):
- data[i+x] = pixel[x]
-
- anImage.SetData(''.join(map(chr, data)))
-
- return anImage
-
-
- def MakeGray((r,g,b), factor, maskColor):
- """
- Make a pixel grayed-out. If the pixel matches the maskcolor, it won't be
- changed.
- """
-
- if (r,g,b) != maskColor:
- return map(lambda x: int((230 - x) * factor) + x, (r,g,b))
- else:
- return (r,g,b)
-
-
- def DrawTreeItemButton(win, dc, rect, flags):
- """ A simple replacement of wx.RendererNative.DrawTreeItemButton. """
-
- # white background
- dc.SetPen(wx.GREY_PEN)
- dc.SetBrush(wx.WHITE_BRUSH)
- dc.DrawRectangleRect(rect)
-
- # black lines
- xMiddle = rect.x + rect.width/2
- yMiddle = rect.y + rect.height/2
-
- # half of the length of the horz lines in "-" and "+"
- halfWidth = rect.width/2 - 2
- dc.SetPen(wx.BLACK_PEN)
- dc.DrawLine(xMiddle - halfWidth, yMiddle,
- xMiddle + halfWidth + 1, yMiddle)
-
- if not flags & _CONTROL_EXPANDED:
-
- # turn "-" into "+"
- halfHeight = rect.height/2 - 2
- dc.DrawLine(xMiddle, yMiddle - halfHeight,
- xMiddle, yMiddle + halfHeight + 1)
-
-
- #---------------------------------------------------------------------------
- # DragImage Implementation
- # This Class Handles The Creation Of A Custom Image In Case Of Item Drag
- # And Drop.
- #---------------------------------------------------------------------------
-
- class DragImage(wx.DragImage):
- """
- This class handles the creation of a custom image in case of item drag
- and drop.
- """
-
- def __init__(self, treeCtrl, item):
- """
- Default class constructor.
- For internal use: do not call it in your code!
- """
-
- text = item.GetText()
- font = item.Attr().GetFont()
- colour = item.Attr().GetTextColour()
- if not colour:
- colour = wx.BLACK
- if not font:
- font = treeCtrl._normalFont
-
- backcolour = treeCtrl.GetBackgroundColour()
- r, g, b = int(backcolour.Red()), int(backcolour.Green()), int(backcolour.Blue())
- backcolour = ((r >> 1) + 20, (g >> 1) + 20, (b >> 1) + 20)
- backcolour = wx.Colour(backcolour[0], backcolour[1], backcolour[2])
- self._backgroundColour = backcolour
-
- tempdc = wx.ClientDC(treeCtrl)
- tempdc.SetFont(font)
- width, height, dummy = tempdc.GetMultiLineTextExtent(text + "M")
-
- image = item.GetCurrentImage()
-
- image_w, image_h = 0, 0
- wcheck, hcheck = 0, 0
- itemcheck = None
- itemimage = None
- ximagepos = 0
- yimagepos = 0
- xcheckpos = 0
- ycheckpos = 0
-
- if image != _NO_IMAGE:
- if treeCtrl._imageListNormal:
- image_w, image_h = treeCtrl._imageListNormal.GetSize(image)
- image_w += 4
- itemimage = treeCtrl._imageListNormal.GetBitmap(image)
-
- checkimage = item.GetCurrentCheckedImage()
-
- if checkimage is not None:
- if treeCtrl._imageListCheck:
- wcheck, hcheck = treeCtrl._imageListCheck.GetSize(checkimage)
- wcheck += 4
- itemcheck = treeCtrl._imageListCheck.GetBitmap(checkimage)
-
- total_h = max(hcheck, height)
- total_h = max(image_h, total_h)
-
- if image_w:
- ximagepos = wcheck
- yimagepos = ((total_h > image_h) and [(total_h-image_h)/2] or [0])[0]
-
- if checkimage is not None:
- xcheckpos = 2
- ycheckpos = ((total_h > image_h) and [(total_h-image_h)/2] or [0])[0] + 2
-
- extraH = ((total_h > height) and [(total_h - height)/2] or [0])[0]
-
- xtextpos = wcheck + image_w
- ytextpos = extraH
-
- total_h = max(image_h, hcheck)
- total_h = max(total_h, height)
-
- if total_h < 30:
- total_h += 2 # at least 2 pixels
- else:
- total_h += total_h/10 # otherwise 10% extra spacing
-
- total_w = image_w + wcheck + width
-
- self._total_w = total_w
- self._total_h = total_h
- self._itemimage = itemimage
- self._itemcheck = itemcheck
- self._text = text
- self._colour = colour
- self._font = font
- self._xtextpos = xtextpos
- self._ytextpos = ytextpos
- self._ximagepos = ximagepos
- self._yimagepos = yimagepos
- self._xcheckpos = xcheckpos
- self._ycheckpos = ycheckpos
- self._textwidth = width
- self._textheight = height
- self._extraH = extraH
-
- self._bitmap = self.CreateBitmap()
-
- wx.DragImage.__init__(self, self._bitmap)
-
-
- def CreateBitmap(self):
- """Actually creates the dnd bitmap."""
-
- memory = wx.MemoryDC()
-
- bitmap = wx.EmptyBitmap(self._total_w, self._total_h)
- memory.SelectObject(bitmap)
-
- memory.SetTextBackground(self._backgroundColour)
- memory.SetBackground(wx.Brush(self._backgroundColour))
- memory.SetFont(self._font)
- memory.SetTextForeground(self._colour)
- memory.Clear()
-
- if self._itemimage:
- memory.DrawBitmap(self._itemimage, self._ximagepos, self._yimagepos, True)
-
- if self._itemcheck:
- memory.DrawBitmap(self._itemcheck, self._xcheckpos, self._ycheckpos, True)
-
- textrect = wx.Rect(self._xtextpos, self._ytextpos+self._extraH, self._textwidth, self._textheight)
- memory.DrawLabel(self._text, textrect)
-
- memory.SelectObject(wx.NullBitmap)
-
- return bitmap
-
-
- # ----------------------------------------------------------------------------
- # TreeItemAttr: a structure containing the visual attributes of an item
- # ----------------------------------------------------------------------------
-
- class TreeItemAttr:
- """Creates the item attributes (text colour, background colour and font)."""
-
- def __init__(self, colText=wx.NullColour, colBack=wx.NullColour, font=wx.NullFont):
- """
- Default class constructor.
- For internal use: do not call it in your code!
- """
-
- self._colText = colText
- self._colBack = colBack
- self._font = font
-
- # setters
- def SetTextColour(self, colText):
- """Sets the attribute text colour."""
-
- self._colText = colText
-
-
- def SetBackgroundColour(self, colBack):
- """Sets the attribute background colour."""
-
- self._colBack = colBack
-
-
- def SetFont(self, font):
- """Sets the attribute font."""
-
- self._font = font
-
-
- # accessors
- def HasTextColour(self):
- """Returns whether the attribute has text colour."""
-
- return self._colText != wx.NullColour
-
-
- def HasBackgroundColour(self):
- """Returns whether the attribute has background colour."""
-
- return self._colBack != wx.NullColour
-
-
- def HasFont(self):
- """Returns whether the attribute has font."""
-
- return self._font != wx.NullFont
-
-
- # getters
- def GetTextColour(self):
- """Returns the attribute text colour."""
-
- return self._colText
-
-
- def GetBackgroundColour(self):
- """Returns the attribute background colour."""
-
- return self._colBack
-
-
- def GetFont(self):
- """Returns the attribute font."""
-
- return self._font
-
-
- # ----------------------------------------------------------------------------
- # CommandTreeEvent Is A Special Subclassing Of wx.PyCommandEvent
- #
- # NB: Note That Not All The Accessors Make Sense For All The Events, See The
- # Event Description Below.
- # ----------------------------------------------------------------------------
-
- class CommandTreeEvent(wx.PyCommandEvent):
- """
- CommandTreeEvent is a special subclassing of wx.PyCommandEvent.
- NB: note that not all the accessors make sense for all the events, see the
- event description for every method in this class.
- """
-
- def __init__(self, type, id, item=None, evtKey=None, point=None,
- label=None, **kwargs):
- """
- Default class constructor.
- For internal use: do not call it in your code!
- """
-
- wx.PyCommandEvent.__init__(self, type, id, **kwargs)
- self._item = item
- self._evtKey = evtKey
- self._pointDrag = point
- self._label = label
-
-
- def GetItem(self):
- """
- Gets the item on which the operation was performed or the newly selected
- item for EVT_TREE_SEL_CHANGED/ING events.
- """
-
- return self._item
-
-
- def SetItem(self, item):
- """
- Sets the item on which the operation was performed or the newly selected
- item for EVT_TREE_SEL_CHANGED/ING events.
- """
-
- self._item = item
-
-
- def GetOldItem(self):
- """For EVT_TREE_SEL_CHANGED/ING events, gets the previously selected item."""
-
- return self._itemOld
-
-
- def SetOldItem(self, item):
- """For EVT_TREE_SEL_CHANGED/ING events, sets the previously selected item."""
-
- self._itemOld = item
-
-
- def GetPoint(self):
- """
- Returns the point where the mouse was when the drag operation started
- (for EVT_TREE_BEGIN(R)DRAG events only) or the click position.
- """
-
- return self._pointDrag
-
-
- def SetPoint(self, pt):
- """
- Sets the point where the mouse was when the drag operation started
- (for EVT_TREE_BEGIN(R)DRAG events only) or the click position.
- """
-
- self._pointDrag = pt
-
-
- def GetKeyEvent(self):
- """Keyboard data (for EVT_TREE_KEY_DOWN only)."""
-
- return self._evtKey
-
-
- def GetKeyCode(self):
- """Returns the integer key code (for EVT_TREE_KEY_DOWN only)."""
-
- return self._evtKey.GetKeyCode()
-
-
- def SetKeyEvent(self, evt):
- """Keyboard data (for EVT_TREE_KEY_DOWN only)."""
-
- self._evtKey = evt
-
-
- def GetLabel(self):
- """Returns the label-itemtext (for EVT_TREE_BEGIN|END_LABEL_EDIT only)."""
-
- return self._label
-
-
- def SetLabel(self, label):
- """Sets the label-itemtext (for EVT_TREE_BEGIN|END_LABEL_EDIT only)."""
-
- self._label = label
-
-
- def IsEditCancelled(self):
- """Returns the edit cancel flag (for EVT_TREE_BEGIN|END_LABEL_EDIT only)."""
-
- return self._editCancelled
-
-
- def SetEditCanceled(self, editCancelled):
- """Sets the edit cancel flag (for EVT_TREE_BEGIN|END_LABEL_EDIT only)."""
-
- self._editCancelled = editCancelled
-
-
- def SetToolTip(self, toolTip):
- """Sets the tooltip for the item (for EVT_TREE_ITEM_GETTOOLTIP events)."""
-
- self._label = toolTip
-
-
- def GetToolTip(self):
- """Gets the tooltip for the item (for EVT_TREE_ITEM_GETTOOLTIP events)."""
-
- return self._label
-
-
- # ----------------------------------------------------------------------------
- # TreeEvent is a special class for all events associated with tree controls
- #
- # NB: note that not all accessors make sense for all events, see the event
- # descriptions below
- # ----------------------------------------------------------------------------
-
- class TreeEvent(CommandTreeEvent):
-
- def __init__(self, type, id, item=None, evtKey=None, point=None,
- label=None, **kwargs):
- """
- Default class constructor.
- For internal use: do not call it in your code!
- """
-
- CommandTreeEvent.__init__(self, type, id, item, evtKey, point, label, **kwargs)
- self.notify = wx.NotifyEvent(type, id)
-
-
- def GetNotifyEvent(self):
- """Returns the actual wx.NotifyEvent."""
-
- return self.notify
-
-
- def IsAllowed(self):
- """Returns whether the event is allowed or not."""
-
- return self.notify.IsAllowed()
-
-
- def Veto(self):
- """Vetos the event."""
-
- self.notify.Veto()
-
-
- def Allow(self):
- """The event is allowed."""
-
- self.notify.Allow()
-
-
- # -----------------------------------------------------------------------------
- # Auxiliary Classes: TreeRenameTimer
- # -----------------------------------------------------------------------------
-
- class TreeRenameTimer(wx.Timer):
- """Timer used for enabling in-place edit."""
-
- def __init__(self, owner):
- """
- Default class constructor.
- For internal use: do not call it in your code!
- """
-
- wx.Timer.__init__(self)
- self._owner = owner
-
-
- def Notify(self):
- """The timer has expired."""
-
- self._owner.OnRenameTimer()
-
-
- # -----------------------------------------------------------------------------
- # Auxiliary Classes: TreeTextCtrl
- # This Is The Temporary wx.TextCtrl Created When You Edit The Text Of An Item
- # -----------------------------------------------------------------------------
-
- class TreeTextCtrl(wx.TextCtrl):
- """Control used for in-place edit."""
-
- def __init__(self, owner, item=None):
- """
- Default class constructor.
- For internal use: do not call it in your code!
- """
-
- self._owner = owner
- self._itemEdited = item
- self._startValue = item.GetText()
- self._finished = False
- self._aboutToFinish = False
-
- w = self._itemEdited.GetWidth()
- h = self._itemEdited.GetHeight()
-
- wnd = self._itemEdited.GetWindow()
- if wnd:
- w = w - self._itemEdited.GetWindowSize()[0]
- h = 0
-
- x, y = self._owner.CalcScrolledPosition(item.GetX(), item.GetY())
-
- image_h = 0
- image_w = 0
-
- image = item.GetCurrentImage()
-
- if image != _NO_IMAGE:
-
- if self._owner._imageListNormal:
- image_w, image_h = self._owner._imageListNormal.GetSize(image)
- image_w += 4
-
- else:
-
- raise Exception("\n ERROR: You Must Create An Image List To Use Images!")
-
- checkimage = item.GetCurrentCheckedImage()
-
- if checkimage is not None:
- wcheck, hcheck = self._owner._imageListCheck.GetSize(checkimage)
- wcheck += 4
- else:
- wcheck = 0
-
- if wnd:
- h = max(hcheck, image_h)
- dc = wx.ClientDC(self._owner)
- h = max(h, dc.GetTextExtent("Aq")[1])
- h = h + 2
-
- # FIXME: what are all these hardcoded 4, 8 and 11s really?
- x += image_w + wcheck
- w -= image_w + 4 + wcheck
-
- wx.TextCtrl.__init__(self, self._owner, wx.ID_ANY, self._startValue,
- wx.Point(x - 4, y), wx.Size(w + 15, h))
- 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()
-
- 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
- self._owner.OnRenameCancelled(self._itemEdited)
- return True
-
- if not self._owner.OnRenameAccept(self._itemEdited, value):
- # vetoed by the user
- return False
-
- # accepted, do rename the item
- self._owner.SetItemText(self._itemEdited, value)
-
- return True
-
-
- def Finish(self):
- """Finish editing."""
-
- if not self._finished:
-
- ## wxPendingDelete.Append(this)
- self._finished = True
- self._owner.SetFocusIgnoringChildren()
- self._owner.ResetTextControl()
-
-
- def OnChar(self, event):
- """Handles the wx.EVT_CHAR event for TreeTextCtrl."""
-
- keycode = event.GetKeyCode()
-
- if keycode == wx.WXK_RETURN:
- self._aboutToFinish = True
- # 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 TreeTextCtrl."""
-
- if not self._finished:
-
- # auto-grow the textctrl:
- parentSize = self._owner.GetSize()
- myPos = self.GetPosition()
- mySize = self.GetSize()
-
- sx, sy = self.GetTextExtent(self.GetValue() + "M")
- if myPos.x + sx > parentSize.x:
- sx = parentSize.x - myPos.x
- if mySize.x > sx:
- sx = mySize.x
-
- self.SetSize((sx, -1))
-
- event.Skip()
-
-
- def OnKillFocus(self, event):
- """Handles the wx.EVT_KILL_FOCUS event for TreeTextCtrl."""
-
- # I commented out those lines, and everything seems to work fine.
- # But why in the world are these lines of code here? Maybe GTK
- # or MAC give troubles?
-
- ## 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.OnRenameCancelled(self._itemEdited)
-
- # We must let the native text control handle focus, too, otherwise
- # it could have problems with the cursor (e.g., in wxGTK).
- event.Skip()
-
-
- def StopEditing(self):
- """Suddenly stops the editing."""
-
- self._owner.OnRenameCancelled(self._itemEdited)
- self.Finish()
-
-
- def item(self):
- """Returns the item currently edited."""
-
- return self._itemEdited
-
-
- # -----------------------------------------------------------------------------
- # Auxiliary Classes: TreeFindTimer
- # Timer Used To Clear CustomTreeCtrl._findPrefix If No Key Was Pressed For A
- # Sufficiently Long Time.
- # -----------------------------------------------------------------------------
-
- class TreeFindTimer(wx.Timer):
- """
- Timer used to clear CustomTreeCtrl._findPrefix if no key was pressed
- for a sufficiently long time.
- """
-
- def __init__(self, owner):
- """
- Default class constructor.
- For internal use: do not call it in your code!
- """
-
- wx.Timer.__init__(self)
- self._owner = owner
-
-
- def Notify(self):
- """The timer has expired."""
-
- self._owner._findPrefix = ""
-
-
- # -----------------------------------------------------------------------------
- # GenericTreeItem Implementation.
- # This Class Holds All The Information And Methods For Every Single Item In
- # CustomTreeCtrl.
- # -----------------------------------------------------------------------------
-
- class GenericTreeItem:
- """
- This class holds all the information and methods for every single item in
- CustomTreeCtrl. No wx based.
- """
-
- def __init__(self, parent, text="", ct_type=0, wnd=None, image=-1, selImage=-1, data=None):
- """
- Default class constructor.
- For internal use: do not call it in your code!
- """
-
- # since there can be very many of these, we save size by chosing
- # the smallest representation for the elements and by ordering
- # the members to avoid padding.
- assert isinstance(text, types.StringTypes)
- self._text = text # label to be rendered for item
- self._data = data # user-provided data
-
- self._children = [] # list of children
- self._parent = parent # parent of this item
-
- self._attr = None # attributes???
-
- # tree ctrl images for the normal, selected, expanded and
- # expanded+selected states
- self._images = [-1, -1, -1, -1]
- self._images[TreeItemIcon_Normal] = image
- self._images[TreeItemIcon_Selected] = selImage
- self._images[TreeItemIcon_Expanded] = _NO_IMAGE
- self._images[TreeItemIcon_SelectedExpanded] = _NO_IMAGE
-
- self._checkedimages = [None, None, None, None]
-
- self._x = 0 # (virtual) offset from top
- self._y = 0 # (virtual) offset from left
- self._width = 0 # width of this item
- self._height = 0 # height of this item
-
- self._isCollapsed = True
- self._hasHilight = False # same as focused
- self._hasPlus = False # used for item which doesn't have
- # children but has a [+] button
- self._isBold = False # render the label in bold font
- self._isItalic = False # render the label in italic font
- self._ownsAttr = False # delete attribute when done
- self._type = ct_type # item type: 0=normal, 1=check, 2=radio
- self._checked = False # only meaningful for check and radio
- self._enabled = True # flag to enable/disable an item
- self._hypertext = False # indicates if the item is hypertext
- self._visited = False # visited state for an hypertext item
-
- if self._type > 0:
- # do not construct the array for normal items
- self._checkedimages[TreeItemIcon_Checked] = 0
- self._checkedimages[TreeItemIcon_NotChecked] = 1
- self._checkedimages[TreeItemIcon_Flagged] = 2
- self._checkedimages[TreeItemIcon_NotFlagged] = 3
-
- if parent:
- if parent.GetType() == 2 and not parent.IsChecked():
- # if the node parent is a radio not enabled, we are disabled
- self._enabled = False
-
- self._wnd = wnd # are we holding a window?
-
- if wnd:
- self.SetWindow(wnd)
-
-
- def IsOk(self):
- """
- Returns whether the item is ok or not. Useless on Python, but added for
- backward compatibility with the C++ implementation.
- """
-
- return True
-
-
- def GetChildren(self):
- """Returns the item's children."""
-
- return self._children
-
-
- def GetText(self):
- """Returns the item text."""
-
- return self._text
-
-
- def GetImage(self, which=TreeItemIcon_Normal):
- """Returns the item image for a particular state."""
-
- return self._images[which]
-
-
- def GetCheckedImage(self, which=TreeItemIcon_Checked):
- """Returns the item check image. Meaningful only for radio & check items."""
-
- return self._checkedimages[which]
-
-
- def GetData(self):
- """Returns the data associated to this item."""
-
- return self._data
-
-
- def SetImage(self, image, which):
- """Sets the item image."""
-
- self._images[which] = image
-
-
- def SetData(self, data):
- """Sets the data associated to this item."""
-
- self._data = data
-
-
- def SetHasPlus(self, has=True):
- """Sets whether an item has the 'plus' button."""
-
- self._hasPlus = has
-
-
- def SetBold(self, bold):
- """Sets the item font bold."""
-
- self._isBold = bold
-
-
- def SetItalic(self, italic):
- """Sets the item font italic."""
-
- self._isItalic = italic
-
-
- def GetX(self):
- """Returns the x position on an item in the ScrolledWindow."""
-
- return self._x
-
-
- def GetY(self):
- """Returns the y position on an item in the ScrolledWindow."""
-
- return self._y
-
-
- def SetX(self, x):
- """Sets the x position on an item in the ScrolledWindow."""
-
- self._x = x
-
-
- def SetY(self, y):
- """Sets the y position on an item in the ScrolledWindow."""
-
- self._y = y
-
-
- def GetHeight(self):
- """Returns the height of the item."""
-
- return self._height
-
-
- def GetWidth(self):
- """Returns the width of the item."""
-
- return self._width
-
-
- def SetHeight(self, h):
- """Sets the height of the item."""
-
- self._height = h
-
-
- def SetWidth(self, w):
- """Sets the width of the item."""
-
- self._width = w
-
-
- def SetWindow(self, wnd):
- """Sets the window associated to the item."""
-
- self._wnd = wnd
-
- if wnd.GetSizer(): # the window is a complex one hold by a sizer
- size = wnd.GetBestSize()
- else: # simple window, without sizers
- size = wnd.GetSize()
-
- # We have to bind the wx.EVT_SET_FOCUS for the associated window
- # No other solution to handle the focus changing from an item in
- # CustomTreeCtrl and the window associated to an item
- # Do better strategies exist?
- self._wnd.Bind(wx.EVT_SET_FOCUS, self.OnSetFocus)
-
- self._height = size.GetHeight() + 2
- self._width = size.GetWidth()
- self._windowsize = size
-
- # We don't show the window if the item is collapsed
- if self._isCollapsed:
- self._wnd.Show(False)
-
- # The window is enabled only if the item is enabled
- self._wnd.Enable(self._enabled)
- self._windowenabled = self._enabled
-
-
- def GetWindow(self):
- """Returns the window associated to the item."""
-
- return self._wnd
-
-
- def DeleteWindow(self):
- """Deletes the window associated to the item (if any)."""
-
- if self._wnd:
- self._wnd.Destroy()
- self._wnd = None
-
-
- def GetWindowEnabled(self):
- """Returns whether the associated window is enabled or not."""
-
- if not self._wnd:
- raise Exception("\nERROR: This Item Has No Window Associated")
-
- return self._windowenabled
-
-
- def SetWindowEnabled(self, enable=True):
- """Sets whether the associated window is enabled or not."""
-
- if not self._wnd:
- raise Exception("\nERROR: This Item Has No Window Associated")
-
- self._windowenabled = enable
- self._wnd.Enable(enable)
-
-
- def GetWindowSize(self):
- """Returns the associated window size."""
-
- return self._windowsize
-
-
- def OnSetFocus(self, event):
- """Handles the wx.EVT_SET_FOCUS event for the associated window."""
-
- treectrl = self._wnd.GetParent()
- select = treectrl.GetSelection()
-
- # If the window is associated to an item that currently is selected
- # (has focus) we don't kill the focus. Otherwise we do it.
- if select != self:
- treectrl._hasFocus = False
- else:
- treectrl._hasFocus = True
-
- event.Skip()
-
-
- def GetType(self):
- """
- Returns the item type. It should be one of:
- 0: normal items
- 1: checkbox item
- 2: radiobutton item
- """
-
- return self._type
-
-
- def SetHyperText(self, hyper=True):
- """Sets whether the item is hypertext or not."""
-
- self._hypertext = hyper
-
-
- def SetVisited(self, visited=True):
- """Sets whether an hypertext item was visited or not."""
-
- self._visited = visited
-
-
- def GetVisited(self):
- """Returns whether an hypertext item was visited or not."""
-
- return self._visited
-
-
- def IsHyperText(self):
- """Returns whether the item is hypetext or not."""
-
- return self._hypertext
-
-
- def GetParent(self):
- """Gets the item parent."""
-
- return self._parent
-
-
- def Insert(self, child, index):
- """Inserts an item in the item children."""
-
- self._children.insert(index, child)
-
-
- def Expand(self):
- """Expand the item."""
-
- self._isCollapsed = False
-
-
- def Collapse(self):
- """Collapse the item."""
-
- self._isCollapsed = True
-
-
- def SetHilight(self, set=True):
- """Sets the item focus/unfocus."""
-
- self._hasHilight = set
-
-
- def HasChildr…
Large files files are truncated, but you can click here to view the full file