Fermat618's Blog

Happy coding

Gtk Tree View 子节点乱跑的问题

Fermat618 posted @ 2014年4月26日 10:28 in 未分类 with tags gtk python , 2263 阅读

pida 有个 ctags 插件,可以从 ctags 分析出来的文件中,新建 tags. 但有时,会发现 tags 乱跑的问题,即某一个父节点的子节点,跑到其它地方去了。

ctags 输出的文件,在程序内部,经分析后,成一个一个的元素。每一个元素,有一个指向父节点的指针。在把这些分立的节点插入进 tree view 的时候,如果子节点先插入,插入时其父节点还未被插入,那么,那些父节点在插入后,不会自动把以前的子节点收进来。

解决这个问题的一个办法,是在插入 tree view 之前,先调整顺序,把一个节点的所有父节点,都放在自身的前面。因为节点可以有分级,父有子,子有孙,递归和 Python 的生成器恰好派上用场,程序看起来就很简洁明了了。

        items = list(....)

        def pop_parent_first(item):
            p = item.parent
            if p is not None and p in items:
                for i in pop_parent_first(p):
                    yield i
            else:
                items.remove(item)
                yield item
        while len(items) != 0:
            item = items[0]
            for x in pop_parent_first(item):
                yield x

第一行,是把原来的元素,做成一个列表。pop_parent_first(item) 函数,在弹出一个对象前,检查有没有父对象,如果有,延后自身弹出,先把它的父对象弹出来。

在 anjuta 中,我又发现了这个问题,觉得很可能是上面这个原因。可惜的是 anjuta 用 C 写的(而不是vala),难找到有用的信息,看了一会,也没找到出错点。

Osmose. Technology 说:
2022年8月08日 01:02

OSMOSE technology private ltd is a Pune-based organisation that provides multiple services platforms for individuals. Technology services such as gaming, eCommerce, social media platforms, and more similar are provided by OSMOSE technology. In this article we do bring some information about how to log in to the website and do bring some important information about these OSMOSE technology pvt ltd. Osmose. Technology Individuals have to visit the official cPanel page to access the services from this portal. the information technology company, engaged to develop and maintain networking applications, mobile applications, web-based applications, and they also undertake outsourcing services related to information technology to provide extended support to individuals.

NCERT Term 2 Sample 说:
2022年9月16日 23:00

Session 2 of the Course is called Term 2, and the Class 2nd Standard students who prepared for their examination tests can download the NCERT 2nd Term Question Paper 2023 Pdf with Answers for all Languages and Subjects of the Course. Every Central Board and other Schools have conducted their examination tests as per the revised syllabus and curriculum designed and published by NCERT.NCERT Term 2 Sample Paper Class 2 Every year the NCERT has published the study and learning material for every 2nd class student studying at all locations of the country for both SA-2, FA3, FA-4 and Assignment exams to Hindi mediu.

Things to do 说:
2024年3月11日 18:05

Fill up your travel map with the help of things to do post - seize the opportunity to discover the world around you.


登录 *


loading captcha image...
(输入验证码)
or Ctrl+Enter