ribar.py 文件源码

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

项目:sc-controller 作者: kozec 项目源码 文件源码
def __init__(self, label, message_type=Gtk.MessageType.INFO,
                                                        infobar=None, *buttons):
        """
        ... where label can be Gtk.Widget or str and buttons are tuples
        of (Gtk.Button, response_id)
        """
        # Init
        Gtk.Revealer.__init__(self)
        self._infobar = infobar or Gtk.InfoBar()
        self._values = {}
        self._label = None
        # Icon
        if infobar is None:
            icon_name = "dialog-information"
            if message_type == Gtk.MessageType.ERROR:
                icon_name = "dialog-error"
            elif message_type == Gtk.MessageType.WARNING:
                icon_name = "dialog-warning"
            icon = Gtk.Image()
            icon.set_from_icon_name(icon_name, Gtk.IconSize.DIALOG)
            self._infobar.get_content_area().pack_start(icon, False, False, 1)
            # Label
            if isinstance(label, Gtk.Widget):
                self._infobar.get_content_area().pack_start(label, True, True, 0)
                self._label = label
            else:
                self._label = Gtk.Label()
                self._label.set_size_request(300, -1)
                self._label.set_markup(label)
                self._label.set_alignment(0, 0.5)
                self._label.set_line_wrap(True)
                self._infobar.get_content_area().add(self._label)
        # Buttons
        for button, response_id in buttons:
            self.add_button(button, response_id)
        # Signals
        self._infobar.connect("close", self._cb_close)
        self._infobar.connect("response", self._cb_response)
        # Settings
        self._infobar.set_message_type(message_type)
        if hasattr(self._infobar, "set_show_close_button"):
            # GTK >3.8
            self._infobar.set_show_close_button(True)
        else:
            self.add_button(Gtk.Button("X"), 0)
        self.set_reveal_child(False)
        # Packing
        self.add(self._infobar)
        self.show_all()
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号