Gtk.ToolPalette
Gtk.ToolPalette — A tool palette with categories
Object Hierarchy:
GObject
╰── GInitiallyUnowned
╰── Gtk.Widget
╰── Gtk.Container
╰── Gtk.ToolPalette
Functions:
- new
() -> Gtk.Widget
- get_exclusive
(self, group:Gtk.ToolItemGroup) -> bool
- set_exclusive
(self, group:Gtk.ToolItemGroup, exclusive:bool)
- get_expand
(self, group:Gtk.ToolItemGroup) -> bool
- set_expand
(self, group:Gtk.ToolItemGroup, expand:bool)
- get_group_position
(self, group:Gtk.ToolItemGroup) -> int
- set_group_position
(self, group:Gtk.ToolItemGroup, position:int)
- get_icon_size
(self) -> int
- set_icon_size
(self, icon_size:int)
- unset_icon_size
(self)
- get_style
(self) -> Gtk.ToolbarStyle
- set_style
(self, style:Gtk.ToolbarStyle)
- unset_style
(self)
- add_drag_dest
(self, widget:Gtk.Widget, flags:Gtk.DestDefaults, targets:Gtk.ToolPaletteDragTargets, actions:Gdk.DragAction)
- get_drag_item
(self, selection:Gtk.SelectionData) -> Gtk.Widget
- get_drag_target_group
() -> Gtk.TargetEntry
- get_drag_target_item
() -> Gtk.TargetEntry
- get_drop_group
(self, x:int, y:int) -> Gtk.ToolItemGroup
- get_drop_item
(self, x:int, y:int) -> Gtk.ToolItem
- set_drag_source
(self, targets:Gtk.ToolPaletteDragTargets)
- get_hadjustment
(self) -> Gtk.Adjustment
- get_vadjustment
(self) -> Gtk.Adjustment
Description:
A Gtk.ToolPaletter
allows you to add GtkToolItems to a palette-like container with different categories and drag and drop support.
A Gtk.ToolPaletter
is created with a call to Gtk.ToolPalette()
.
GtkToolItems cannot be added directly to a Gtk.ToolPaletter
- instead they are added to a Gtk.ToolItemGroup which can than be added to a GtkToolPalette. To add a Gtk.ToolItemGroup to a Gtk.ToolPalette
, use add()
.
toolpalette = Gtk.ToolPalette()
self.add(toolpalette)
toolitemgroup = Gtk.ToolItemGroup(label="Group 1")
toolpalette.add(toolitemgroup)
The easiest way to use drag and drop with Gtk.ToolPaletter
is to call Gtk.ToolPalette::add_drag_dest()
with the desired drag source palette
and the desired drag target widget
. Then Gtk.ToolPalette::get_drag_item()
can be used to get the dragged item in the [Gtk.Widget](/gtk-group/gtkwidget.md)::drag-data-received
signal handler of the drag target.
Function Details:
new()
new () -> Gtk.Widget
Creates a new tool palette.
Returns: a new Gtk.ToolPalette
Since: 2.20
get_exclusive()
get_exclusive (self, group:Gtk.ToolItemGroup) -> bool
Gets whether group
is exclusive or not.See Gtk.ToolPalette:set_exclusive()
.
Returns:
True
ifgroup
is exclusiveSince: 2.20
set_exclusive()
set_exclusive (self, group:Gtk.ToolItemGroup, exclusive:bool)
Sets whether the group should be exclusive or not.If an exclusive group is expanded all other groups are collapsed.
- Since: 2.20
get_expand()
get_expand (self, group:Gtk.ToolItemGroup) -> bool
Gets whether group should be given extra space.See Gtk.ToolPalette:set_expand()
.
Returns:
True
if group should be given extra space,FALSE
otherwiseSince: 2.20
set_expand()
set_expand (self, group:Gtk.ToolItemGroup, expand:bool)
Sets whether the group should be given extra space.
- Since: 2.20
get_group_position()
get_group_position (self, group:Gtk.ToolItemGroup) -> int
Gets the position of group
in palette
as index.See Gtk.ToolPalette:set_group_position()
.
Returns: the index of group or -1 if
group
is not a child ofpalette
Since: 2.20
set_group_position()
set_group_position (self, group:Gtk.ToolItemGroup, position:int)
Sets the position of the group as an index of the tool palette.If position is 0 the group will become the first child, if position is-1 it will become the last child.
- Since: 2.20
get_icon_size()
get_icon_size (self) -> int
Gets the size of icons in the tool palette.See Gtk.ToolPalette:set_icon_size()
.
Returns: the
Gtk.IconSize
of icons in the tool palette.Since: 2.20
set_icon_size()
set_icon_size (self, icon_size:int)
Sets the size of icons in the tool palette.
- Since: 2.20
unset_icon_size()
unset_icon_size (self)
Unsets the tool palette icon size set with Gtk.ToolPalette:set_icon_size()
,so that user preferences will be used to determine the icon size.
- Since: 2.20
get_style()
get_style (self) -> Gtk.ToolbarStyle
Gets the style (icons, text or both) of items in the tool palette.
Returns: the
Gtk.ToolbarStyle
of items in the tool palette.Since: 2.20
set_style()
set_style (self, style:Gtk.ToolbarStyle)
Sets the style (text, icons or both) of items in the tool palette.
- Since: 2.20
unset_style()
unset_style (self)
Unsets a toolbar style set with Gtk.ToolPalette:set_style()
,so that user preferences will be used to determine the toolbar style.
- Since: 2.20
add_drag_dest()
add_drag_dest (self, widget:Gtk.Widget, flags:Gtk.DestDefaults, targets:Gtk.ToolPaletteDragTargets, actions:Gdk.DragAction)
Sets palette
as drag source (see Gtk.ToolPalette:set_drag_source()
)and sets widget
as a drag destination for drags from palette
.See `Gtk.Drag:dest_set
()`.
- Since: 2.20
get_drag_item()
get_drag_item (self, selection:Gtk.SelectionData) -> Gtk.Widget
Get the dragged item from the selection.This could be a Gtk.ToolItem
or a Gtk.ToolItem
Group.
Returns: the dragged item in selection.
Since: 2.20
get_drag_target_group()
get_drag_target_group () -> Gtk.TargetEntry
Get the target entry for a dragged Gtk.ToolItemGroup
.
Returns: the
Gtk.TargetEntry
for a dragged group.Since: 2.20
get_drag_target_item()
get_drag_target_item () -> Gtk.TargetEntry
Gets the target entry for a dragged Gtk.ToolItem
.
Returns: the
Gtk.TargetEntry
for a dragged item.Since: 2.20
get_drop_group()
get_drop_group (self, x:int, y:int) -> Gtk.ToolItemGroup
Gets the group at position (x, y).
Returns: the
Gtk.ToolItemGroup
at position orNone
if there is no such group.Since: 2.20
get_drop_item()
get_drop_item (self, x:int, y:int) -> Gtk.ToolItem
Gets the item at position (x, y).See Gtk.ToolPalette:get_drop_group()
.
Returns: the
Gtk.ToolItem
at position orNone
if there is no such item.Since: 2.20
set_drag_source()
set_drag_source (self, targets:Gtk.ToolPaletteDragTargets)
Sets the tool palette as a drag source.Enables all groups and items in the tool palette as drag sourceson button 1 and button 3 press with copy and move actions.See `Gtk.Drag:source_set
()`.
- Since: 2.20
get_hadjustment()
get_hadjustment (self) -> Gtk.Adjustment
Gtk.ToolPalette:get_hadjustment
has been deprecated since version 3.0 and should not be used in newly-written code.
Use `Gtk.Scrollable:get_hadjustment
()`
Gets the horizontal adjustment of the tool palette.
Returns: the horizontal adjustment of
palette
.Since: 2.20
get_vadjustment()
get_vadjustment (self) -> Gtk.Adjustment
Gtk.ToolPalette:get_vadjustment
has been deprecated since version 3.0 and should not be used in newly-written code.
Use `Gtk.Scrollable:get_vadjustment
()`
Gets the vertical adjustment of the tool palette.
Returns: the vertical adjustment of
palette
.Since: 2.20
Example:
import gi
gi.require_version('Gtk', '3.0')
from gi.repository import Gtk
class ToolPalette(Gtk.Window):
def __init__(self):
Gtk.Window.__init__(self)
self.set_default_size(200, 200)
self.connect("destroy", Gtk.main_quit)
toolpalette = Gtk.ToolPalette()
self.add(toolpalette)
toolitemgroup = Gtk.ToolItemGroup(label="Group 1")
toolpalette.add(toolitemgroup)
toolbutton = Gtk.ToolButton()
toolbutton.set_icon_name("gtk-new")
toolitemgroup.insert(toolbutton, 0)
toolbutton = Gtk.ToolButton()
toolbutton.set_icon_name("gtk-open")
toolitemgroup.insert(toolbutton, 1)
toolbutton = Gtk.ToolButton()
toolbutton.set_icon_name("gtk-save")
toolitemgroup.insert(toolbutton, 2)
toolitemgroup = Gtk.ToolItemGroup(label="Group 2")
toolpalette.add(toolitemgroup)
toolbutton = Gtk.ToolButton()
toolbutton.set_icon_name("gtk-about")
toolitemgroup.insert(toolbutton, 0)
toolbutton = Gtk.ToolButton()
toolbutton.set_icon_name("gtk-preferences")
toolitemgroup.insert(toolbutton, 1)
window = ToolPalette()
window.show_all()
Gtk.main()