Gtk.Toolbar


Gtk.Toolbar — Create bars of buttons and other widgets

Object Hierarchy:

    GObject
    ╰── GInitiallyUnowned
        ╰── Gtk.Widget
            ╰── Gtk.Container
                ╰── Gtk.Toolbar

See also:

Gtk.ToolItem


Functions:


Signals:

  • “focus-home-or-end” (toolbar, focus_home, user_data)
  • “orientation-changed” (toolbar, orientation, user_data)
  • “popup-context-menu” (toolbar, x, y, button, user_data)

Description:

A toolbar is created with a call to Gtk.Toolbar::new().

A toolbar can contain instances of a subclass of Gtk.ToolItem. To add a Gtk.ToolItem to the a toolbar, use Gtk.Toolbar::insert(). To remove an item from the toolbar use Gtk.Container::remove(). To add a button to the toolbar, add an instance of Gtk.ToolButton.

Toolbar items can be visually grouped by adding instances of Gtk.SeparatorToolItem to the toolbar. If the GtkToolbar child property expand is True and the property Gtk.SeparatorToolItem::draw is set to False, the effect is to force all following items to the end of the toolbar.

Creating a context menu for the toolbar can be done by connecting to the “popup-context-menu” signal.


Function Details:

new()

new () -> Gtk.Widget

Creates a new toolbar.

  • Returns: the newly-created toolbar.

insert()

insert (self, item:Gtk.ToolItem, pos:int)

Insert a Gtk.ToolItem into the toolbar at position pos. If pos is0 the item is prepended to the start of the toolbar. If pos isnegative, the item is appended to the end of the toolbar.

  • Since: 2.4

get_item_index()

get_item_index (self, item:Gtk.ToolItem) -> int

Returns the position of item on the toolbar, starting from 0.It is an error if item is not a child of the toolbar.

  • Returns: the position of item on the toolbar.

  • Since: 2.4


get_n_items()

get_n_items (self) -> int

Returns the number of items on the toolbar.

  • Returns: the number of items on the toolbar

  • Since: 2.4


get_nth_item()

get_nth_item (self, n:int) -> Gtk.ToolItem

Returns the n'th item on toolbar, or None if thetoolbar does not contain an n'th item.

  • Returns: The n'th Gtk.ToolItem on toolbar,or None if there isn’t an n'th item.

  • Since: 2.4


get_drop_index()

get_drop_index (self, x:int, y:int) -> int

Returns the position corresponding to the indicated point ontoolbar. This is useful when dragging items to the toolbar:this function returns the position a new item should beinserted. x and y are in toolbar coordinates.

  • Returns: The position corresponding to the point (x, y) on the toolbar.

  • Since: 2.4


set_drop_highlight_item()

set_drop_highlight_item (self, tool_item:Gtk.ToolItem=None, index_:int)

Highlights toolbar to give an idea of what it would look likeif item was added to toolbar at the position indicated by index_.If item is None, highlighting is turned off. In that case index_ is ignored. The tool_item passed to this function must not be part of any widgethierarchy. When an item is set as drop highlight item it can notadded to any widget hierarchy or used as highlight item for anothertoolbar.

  • Since: 2.4

set_show_arrow()

set_show_arrow (self, show_arrow:bool)

Sets whether to show an overflow menu whentoolbar doesn’t have room for all items on it. If True,items that there are not room are available through anoverflow menu.

  • Since: 2.4

unset_icon_size()

unset_icon_size (self)

Unsets toolbar icon size set with Gtk.Toolbar:set_icon_size(), so thatuser preferences will be used to determine the icon size.


get_show_arrow()

get_show_arrow (self) -> bool

Returns whether the toolbar has an overflow menu.See Gtk.Toolbar:set_show_arrow().

  • Returns: True if the toolbar has an overflow menu.

  • Since: 2.4


get_style()

get_style (self) -> Gtk.ToolbarStyle

Retrieves whether the toolbar has text, icons, or both . SeeGtk.Toolbar:set_style().

  • Returns: the current style of toolbar

get_icon_size()

get_icon_size (self) -> Gtk.IconSize

Retrieves the icon size for the toolbar. See Gtk.Toolbar:set_icon_size().

  • Returns: the current icon size for the icons on the toolbar.

get_relief_style()

get_relief_style (self) -> Gtk.ReliefStyle

Returns the relief style of buttons on toolbar. See`Gtk.Button:set_relief()`.

  • Returns: The relief style of buttons on toolbar.

  • Since: 2.4


set_style()

set_style (self, style:Gtk.ToolbarStyle)

Alters the view of toolbar to display either icons only, text only, or both.


set_icon_size()

set_icon_size (self, icon_size:Gtk.IconSize)

This function sets the size of stock icons in the toolbar. Youcan call it both before you add the icons and after they’ve beenadded. The size you set will override user preferences for the defaulticon size. This should only be used for special-purpose toolbars, normalapplication toolbars should respect the user preferences for thesize of icons.


unset_style()

unset_style (self)

Unsets a toolbar style set with Gtk.Toolbar:set_style(), so thatuser preferences will be used to determine the toolbar style.


Example:

import gi
gi.require_version('Gtk', '3.0')
from gi.repository import Gtk

class Toolbar(Gtk.Window):
    def __init__(self):
        Gtk.Window.__init__(self)
        self.set_default_size(500, -1)
        self.connect("destroy", Gtk.main_quit)

        toolbar = Gtk.Toolbar()
        self.add(toolbar)

        toolbutton = Gtk.ToolButton()
        toolbutton.set_label("New")
        toolbutton.set_is_important(True)
        toolbutton.set_icon_name("gtk-new")
        toolbar.add(toolbutton)

        toggletoolbutton = Gtk.ToggleToolButton()
        toggletoolbutton.set_icon_name("gtk-media-play")
        toolbar.add(toggletoolbutton)

        open_menu = Gtk.Menu()

        #menuitem = Gtk.MenuItem(label="MenuItem A")
        #open_menu.append(menuitem)
        #menuitem1 = Gtk.MenuItem(label="MenuItem B")
        #open_menu.append(menuitem1)        
        #menuitem.show()
        #menuitem1.show()

        #menuitem2 = Gtk.MenuItem('Recent Items')
        #open_menu.append(menuitem2)
        #menuitem2.show()

        recentchoosermenu = Gtk.RecentChooserMenu()
        recentchoosermenu.connect('item-activated', self.on_item_activated)

        menutoolbutton = Gtk.MenuToolButton()
        menutoolbutton.set_menu(recentchoosermenu)
        menutoolbutton.set_icon_name("gtk-open")
        toolbar.add(menutoolbutton)

        separatortoolitem = Gtk.SeparatorToolItem()
        toolbar.add(separatortoolitem)

        radiotoolbutton1 = Gtk.RadioToolButton()
        radiotoolbutton1.set_icon_name("gtk-media-rewind")
        toolbar.add(radiotoolbutton1)
        radiotoolbutton2 = Gtk.RadioToolButton(group=radiotoolbutton1)
        radiotoolbutton2.set_icon_name("gtk-media-forward")
        toolbar.add(radiotoolbutton2)

        separatortoolitem = Gtk.SeparatorToolItem()
        toolbar.add(separatortoolitem)

        toolitem = Gtk.ToolItem()
        toolbar.add(toolitem)
        entry = Gtk.Entry()
        toolitem.add(entry)

    def on_item_activated(self, recentchoosermenu):
        item = recentchoosermenu.get_current_item()

        if item:
            print("Item selected:")
            print("Name:\t %s" % (item.get_display_name()))
            print("URI:\t %s" % (item.get_uri()))

window = Toolbar()
window.show_all()

Gtk.main()

results matching ""

    No results matching ""