gu.py 文件源码

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

项目:Solfege 作者: RannyeriDev 项目源码 文件源码
def add_nonwrapped_text(self, text):
        self._make_primary_bold()
        self._parsep()
        sc = Gtk.ScrolledWindow()
        l = Gtk.Label()
        l.set_markup('<span font_family="monospace">%s</span>' % escape(text))
        l.set_line_wrap(False)
        l.set_alignment(0.0, 0.5)
        l.show()
        sc.add_with_viewport(l)
        self.msg_vbox.pack_start(sc, True, True, 0)
        sc.show_all()
        sc.set_policy(Gtk.PolicyType.AUTOMATIC, Gtk.PolicyType.NEVER)
        h = l.get_ancestor(Gtk.Viewport).size_request().height
        max_lines = 5
        lines = text.count("\n") + 1
        # This is the space the horizontal scrollbar takes
        scrollbar_height = (sc.get_hscrollbar().size_request().height
            + sc.style_get_property("scrollbar-spacing"))
        if lines <= max_lines:
            # make the scrollwin so high that it can display all lines
            sc.set_size_request(-1, h)

        else:
            sc.set_policy(Gtk.PolicyType.AUTOMATIC, Gtk.PolicyType.AUTOMATIC)
            sc.set_size_request(-1, int(h * max_lines / lines))
        adj = sc.get_hscrollbar().get_adjustment()

        def f(scrollbar, event):
            sc.set_size_request(-1, int(h * max_lines / lines) + scrollbar_height)
            scrollbar.disconnect(self._hscroll_expose_id)
        # f is called if the horizontal scrollbar is visible. This because we
        # need to allocate space for the scrollbar too.
        self._hscroll_expose_id = sc.get_hscrollbar().connect('expose-event', f)
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号