{"id":93,"date":"2018-08-16T20:14:43","date_gmt":"2018-08-16T12:14:43","guid":{"rendered":"http:\/\/172.81.211.114\/?p=93"},"modified":"2018-08-16T20:14:43","modified_gmt":"2018-08-16T12:14:43","slug":"wxpython-%e6%a0%b9%e6%8d%aeitem%e7%9a%84%e5%90%8d%e5%ad%97%e6%89%be%e5%88%b0tree_ctrl%e5%af%b9%e5%ba%94%e7%9a%84%e8%8a%82%e7%82%b9","status":"publish","type":"post","link":"https:\/\/www.yinyubo.com\/?p=93","title":{"rendered":"wxpython \u6839\u636eitem\u7684\u540d\u5b57\u627e\u5230tree_ctrl\u5bf9\u5e94\u7684\u8282\u70b9"},"content":{"rendered":"<p>\u4e1a\u52a1\u573a\u666f\uff0c\u9700\u8981\u5728\u4e00\u4e2atree_ctrl\u4e2d\u627e\u5230\u4e00\u4e2a\u8282\u70b9\uff0c\u5e76\u4e14\u7ed9\u8be5\u8282\u70b9\u6dfb\u52a0\u5b50\u8282\u70b9<\/p>\n<pre class=\"hljs ruby\"><code class=\"ruby\"><span class=\"hljs-function\"><span class=\"hljs-keyword\">def<\/span> <span class=\"hljs-title\">get_item_by_label<\/span><span class=\"hljs-params\">(<span class=\"hljs-keyword\">self<\/span>, tree, search_text, root_item)<\/span><\/span>:\n    item, cookie = tree.GetFirstChild(root_item)\n    <span class=\"hljs-keyword\">while<\/span> item.IsOk():\n        text = tree.GetItemText(item)\n        <span class=\"hljs-keyword\">if<\/span> text.lower() == search_text.lower():\n            <span class=\"hljs-keyword\">return<\/span> item\n        <span class=\"hljs-keyword\">if<\/span> tree.ItemHasChildren(item):\n            match = <span class=\"hljs-keyword\">self<\/span>.get_item_by_label(tree, search_text, item)\n            <span class=\"hljs-keyword\">if<\/span> match.IsOk():\n                <span class=\"hljs-keyword\">return<\/span> match\n        item, cookie = tree.GetNextChild(root_item, cookie)\n    <span class=\"hljs-keyword\">return<\/span> wx.TreeItemId()\nresult = get_item_by_label(tree, <span class=\"hljs-string\">'\u5df2\u6709\u8282\u70b9'<\/span>, tree.GetRootItem())\n<span class=\"hljs-keyword\">if<\/span> result.IsOk():\n    print(<span class=\"hljs-string\">'We have a match!'<\/span>)\n    new_item = tree.AppendItem(result , <span class=\"hljs-string\">\"\u65b0\u8282\u70b9\"<\/span>)<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>\u4e1a\u52a1\u573a\u666f\uff0c\u9700\u8981\u5728\u4e00\u4e2atree_ctrl\u4e2d\u627e\u5230\u4e00\u4e2a\u8282\u70b9\uff0c\u5e76\u4e14\u7ed9\u8be5\u8282\u70b9\u6dfb\u52a0\u5b50\u8282\u70b9 def get_item_by_ [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[5],"tags":[12],"class_list":["post-93","post","type-post","status-publish","format-standard","hentry","category-python","tag-wxpython"],"_links":{"self":[{"href":"https:\/\/www.yinyubo.com\/index.php?rest_route=\/wp\/v2\/posts\/93","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.yinyubo.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.yinyubo.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.yinyubo.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.yinyubo.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=93"}],"version-history":[{"count":0,"href":"https:\/\/www.yinyubo.com\/index.php?rest_route=\/wp\/v2\/posts\/93\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.yinyubo.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=93"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.yinyubo.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=93"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.yinyubo.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=93"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}