示例#1
0
文件: topbar.py 项目: zero804/mypaint
 def _realize_cb(self, widget):
     """Assorted setup when the widget is realized"""
     assert self.menubar is not None
     assert self.toolbar1 is not None
     assert self.toolbar2 is not None
     # Packing details for Grid
     self.menubar.set_hexpand(True)
     self.toolbar1.set_hexpand(True)
     self.toolbar2.set_hexpand(False)
     self._fs_menubutton.set_hexpand(False)
     # Specialized styles
     prov = Gtk.CssProvider()
     prov.load_from_data(b"""
             .topbar {
                 padding: 0px; /* required by toolbars */
                 margin: 0px;  /* required by menubar */
             }
         """)
     bars = [self.toolbar1, self.toolbar2, self.menubar]
     for b in bars:
         style = b.get_style_context()
         style.add_provider(prov, Gtk.STYLE_PROVIDER_PRIORITY_APPLICATION)
         style.add_class("topbar")
     # Initial packing; assume a non-fullscreened state
     self.attach(self.menubar, 0, 0, 2, 1)
     self.attach(self.toolbar1, 0, 1, 1, 1)
     self.attach(self.toolbar2, 1, 1, 1, 1)
     # Track state transitions of the window's toplevel
     toplevel = self.get_toplevel()
     assert toplevel is not None
     toplevel.connect("window-state-event", self._toplevel_state_event_cb)
示例#2
0
def borderless_button(stock_id=None,
                      icon_name=None,
                      size=ICON_SIZE_SMALL,
                      tooltip=None,
                      action=None):
    """Create a button styled to be borderless.

    >>> borderless_button(icon_name="mypaint")  # doctest: +ELLIPSIS
    <Gtk.Button...>

    """
    button = Gtk.Button()
    if stock_id is not None:
        image = Gtk.Image()
        image.set_from_stock(stock_id, size)
        set_margins(image, 0)
        button.add(image)
    elif icon_name is not None:
        image = Gtk.Image()
        image.set_from_icon_name(icon_name, size)
        set_margins(image, 0)
        button.add(image)
    elif action is not None:
        button.set_related_action(action)
        if button.get_child() is not None:
            button.remove(button.get_child())
        img = action.create_icon(size)
        img.set_padding(4, 4)
        set_margins(img, 0)
        button.add(img)
    button.set_relief(Gtk.ReliefStyle.NONE)
    button.set_can_default(False)
    button.set_can_focus(False)
    set_margins(button, 0)
    if tooltip is not None:
        button.set_tooltip_text(tooltip)
    elif action is not None:
        button.set_tooltip_text(action.get_tooltip())
    cssprov = Gtk.CssProvider()
    cssprov.load_from_data(b"GtkButton { padding: 0px; margin: 0px; }")
    style = button.get_style_context()
    style.add_provider(cssprov, Gtk.STYLE_PROVIDER_PRIORITY_APPLICATION)
    button.set_has_tooltip(tooltip is not None)
    return button