gtkinfo.py 文件源码

python
阅读 18 收藏 0 点赞 0 评论 0

项目:python-3-for-absolute-begs 作者: Apress 项目源码 文件源码
def get_selection(self):
        """get_selection

        Creates text appropriate to choices
        """
        # get selection from listview
        self.choice = self.treeview1.get_selection()
        self.choice.set_mode(gtk.SELECTION_SINGLE)
        self.model, self.row_reference = self.choice.get_selected()
        self.choice = self.liststore.get_value(self.row_reference, 0)

        # Create command line
        command_ref = "self." + self.choice.replace(' ','_') + "_func"
        command = eval(command_ref)

        # GUI output
        # Make clean textbuffer
        self.textbuffer = gtk.TextBuffer(None)
        # Create headline style
        self.headline = self.textbuffer.create_tag('headline', 
                            weight=700, scale=pango.SCALE_LARGE)
        # navigate to start of buffer
        place = self.textbuffer.get_start_iter()
        # Create pixbuf icon reference
        icon = eval("self." + self.choice.replace(' ','_') + "_image")
        # Insert icon at top of page
        self.textbuffer.insert_pixbuf(place, icon)
        # Print appropriate text underneath
        text = " " + self.choice + ": \n\n" + commands.getoutput(command)
        self.textbuffer.insert_at_cursor(text)
        iter0 = self.textbuffer.get_iter_at_line(0)
        iter1 = self.textbuffer.get_iter_at_line(1)
        self.textbuffer.apply_tag(self.headline,iter0,iter1)
        self.textview1.set_buffer(self.textbuffer)
        return
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号