Pygobject (54) Toolpalette of layout container

Source: Internet
Author: User
Tags gtk

Gtktoolpalette inheritance Relationship Methods Virtual Methods Properties Signals Example

Gtk.toolpalette

Gtk.toolpalette tool palette Layout inheritance Relationships

Gtk.toolpalette is a direct subclass of Gtk.container
Methods

method Modifier method name and parameter
Tatic Get_drag_target_group ()
Static Get_drag_target_item ()
Static New ()
Add_drag_dest (widget, flags, targets, actions)
Get_drag_item (selection)
Get_drop_group (x, y)
Get_drop_item (x, y)
Get_exclusive (Group)
Get_expand (Group)
Get_group_position (Group)
Get_hadjustment ()
Get_icon_size ()
Get_style ()
Get_vadjustment ()
Set_drag_source (Targets)
Set_exclusive (group, Exclusive)
Set_expand (Group, expand)
Set_group_position (group, position)
Set_icon_size (Icon_size)
Set_style (Style)
Unset_icon_size ()
Unset_style ()
Virtual Methods
Properties Short
Name Type FlagsDescription
Icon-size Gtk.iconsize r/w/en Size of icons in this tool palette
Icon-size-set bool r/w/en Whether the Icon-size property has been set
Toolbar-style Gtk.toolbarstyle r/w/en Style of items in the tool palette
Signals Short
NameDescription
Example


Code:

#!/usr/bin/env Python3 # Created by Xiaosanyu in 16/7/18 # section 071 # author:xiaosanyu # website:yuxiaosan.tk # HTTP://BLOG.CSDN.NET/A87B01C14 # CREATED:16/7/18 TITLE = "Toolpalette" DESCRIPTION = "" "A Gtk.toolpalette Allo
WS to add Gtk.toolitems to a palette-like container with different categories and drag and drop support. 
    "" "Import gi gi.require_version (' Gtk ', ' 3.0 ') from gi.repository import GTK, GdK class Toolpalettewindow (Gtk.window): def __init__ (self): gtk.window.__init__ (Self, title= "Toolpalette Example") Hbox = Gtk.hbox (spacing=6 ) Self.palette = Gtk.toolpalette () group1 = Gtk.toolitemgroup (label= "Test Category") Self.palette.
        Add (group1) item = Gtk.toolbutton () item.set_icon_name ("Document-open") Group1.insert (item,-1) group2 = Gtk.toolitemgroup (label= "Edit") Self.palette.add (group2) item = Gtk.toolbutton () it
        Em.set_icon_name ("Edit-cut")Group2.insert (item,-1) item = Gtk.toolbutton () item.set_icon_name ("Edit-paste") Group2.insert (ite M,-1) item = Gtk.toolbutton () item.set_icon_name ("Edit-copy") Group2.insert (item,-1) HBO X.add (self.palette) contents = Gtk.drawingarea () contents.set_size_request (+) Hbox.add (con Tents) contents.set_app_paintable (True) contents.connect ("drag-data-received", Self.passive_canvas_drag_d

        ata_received) Contents.connect ("Draw", Self.on_draw) contents.connect ("Delete-event", Gtk.main_quit)
                                   Self.palette.add_drag_dest (contents, Gtk.DestDefaults.ALL, Gtk.ToolPaletteDragTargets.ITEMS, Gdk.DragAction.COPY) Self.add (hbox def passive_canvas_drag_data_received (self, widget, drag_context, x, y, data, info, time): Widget.item = SE Lf.palette.get_drag_item(data) Widget.x = x widget.y = y Widget.queue_draw () @staticmethod def on_draw (widget, CR ): Cr.set_source_rgb (1, 1, 1) cr.paint () if hasattr (widget, "item"): Pixbuf = Gtk.icon Theme.get_default (). Load_icon (Widget.item.get_icon_name (), 0) Gdk.cairo_set_source_pixbuf (CR, Pixbuf, WIDG Et.x, Widget.y) Cr.paint () def main (): win = Toolpalettewindow () win.connect ("Delete-event", Gtk.mai
 N_quit) Win.show_all () Gtk.main () if __name__ = = "__main__": Main ()

Code resolution:

Hbox = Gtk.hbox (spacing=6)

Create a level of Hbox

Self.palette = Gtk.toolpalette ()

Create a Gtk.toolpalette

group1 = Gtk.toolitemgroup (label= "Test Category")
Self.palette.add (group1)

Create the first Gtk.toolitemgroup group and add it to the Gtk.toolpalette.

TEM = Gtk.toolbutton ()
item.set_icon_name ("Document-open")
Group1.insert (item,-1)

Create a Gtk.toolbutton, set its picture, and then add it to the group

Similarly create a second group

group2 = Gtk.toolitemgroup (label= "Edit")

Added three Gtk.toolbutton to it

Contents = Gtk.drawingarea ()
contents.set_size_request ()
hbox.add (contents)
Contents.set_app_ Paintable (True)

contents.connect ("drag-data-received", self.passive_canvas_drag_data_received)
Contents.connect ("Draw", Self.on_draw)

Then a gtk.drawingarea is created, connecting the "drag-data-received" and "draw" signals.

Self.palette.add_drag_dest (contents,
                                   Gtk.DestDefaults.ALL,
                                   Gtk.ToolPaletteDragTargets.ITEMS,
                                   Gdk.DragAction.COPY)

Set the drag and drop destinations for Toolpalette

def passive_canvas_drag_data_received (self, widget, drag_context, x, y, data, info, time):
        Widget.item = Self.palette.get_drag_item (data)
        widget.x = x
        widget.y = y
        widget.queue_draw ()

"Drag-data-received" signals, captures the drag-and-drop target, sets the drag target and the current position. Then request Drawingarea to redraw

def on_draw (widget, CR):
    Cr.set_source_rgb (1, 1, 1)
    cr.paint ()
    if hasattr (widget, "item"):
        pixbuf = Gtk.IconTheme.get_default (). Load_icon (Widget.item.get_icon_name (), 0)
        Gdk.cairo_set_source_pixbuf (CR, Pixbuf, Widget.x, Widget.y)
        Cr.paint ()




Code Download Address: http://download.csdn.net/detail/a87b01c14/9594728

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.