在前面的系列文章中基本介绍完了PyGobject中的布局容器,接下来的文章将重点介绍常用的一些部件。
本文主要介绍Gtk.Widget这个抽象类

Gtk.Widget

Gtk.Widget是Gtk+中其它部件的父类,它负责管理部件的生命周期、状态和显示风格

继承关系

这里写图片描述

Methods

方法修饰词方法名及参数
staticget_default_direction ()
staticget_default_style ()
staticpop_composite_child ()
staticpush_composite_child ()
staticset_default_direction (dir)
activate ()
add_accelerator (accel_signal, accel_group, accel_key, accel_mods, accel_flags)
add_device_events (device, events)
add_events (events)
add_mnemonic_label (label)
add_tick_callback (callback, *user_data)
can_activate_accel (signal_id)
child_focus (direction)
child_notify (child_property)
class_path ()
compute_expand (orientation)
create_pango_context ()
create_pango_layout (text)
destroy ()
destroyed (widget_pointer)
device_is_shadowed (device)
drag_begin (targets, actions, button, event)
drag_begin_with_coordinates (targets, actions, button, event, x, y)
drag_check_threshold (start_x, start_y, current_x, current_y)
drag_dest_add_image_targets ()
drag_dest_add_text_targets ()
drag_dest_add_uri_targets ()
drag_dest_find_target (context, target_list)
drag_dest_get_target_list ()
drag_dest_get_track_motion ()
drag_dest_set (flags, targets, actions)
drag_dest_set_proxy (proxy_window, protocol, use_coordinates)
drag_dest_set_target_list (target_list)
drag_dest_set_track_motion (track_motion)
drag_dest_unset ()
drag_get_data (context, target, time_)
drag_highlight ()
drag_source_add_image_targets ()
drag_source_add_text_targets ()
drag_source_add_uri_targets ()
drag_source_get_target_list ()
drag_source_set (start_button_mask, targets, actions)
drag_source_set_icon_gicon (icon)
drag_source_set_icon_name (icon_name)
drag_source_set_icon_pixbuf (pixbuf)
drag_source_set_icon_stock (stock_id)
drag_source_set_target_list (target_list)
drag_source_unset ()
drag_unhighlight ()
draw (cr)
ensure_style ()
error_bell ()
event (event)
freeze_child_notify ()
get_accessible ()
get_action_group (prefix)
get_allocated_baseline ()
get_allocated_height ()
get_allocated_size ()
get_allocated_width ()
get_allocation ()
get_ancestor (widget_type)
get_app_paintable ()
get_can_default ()
get_can_focus ()
get_child_requisition ()
get_child_visible ()
get_clip ()
get_clipboard (selection)
get_composite_name ()
get_device_enabled (device)
get_device_events (device)
get_direction ()
get_display ()
get_double_buffered ()
get_events ()
get_focus_on_click ()
get_font_map ()
get_font_options ()
get_frame_clock ()
get_halign ()
get_has_tooltip ()
get_has_window ()
get_hexpand ()
get_hexpand_set ()
get_mapped ()
get_margin_bottom ()
get_margin_end ()
get_margin_left ()
get_margin_right ()
get_margin_start ()
get_margin_top ()
get_modifier_mask (intent)
get_modifier_style ()
get_name ()
get_no_show_all ()
get_opacity ()
get_pango_context ()
get_parent ()
get_parent_window ()
get_path ()
get_pointer ()
get_preferred_height ()
get_preferred_height_and_baseline_for_width (width)
get_preferred_height_for_width (width)
get_preferred_size ()
get_preferred_width ()
get_preferred_width_for_height (height)
get_realized ()
get_receives_default ()
get_request_mode ()
get_requisition ()
get_root_window ()
get_scale_factor ()
get_screen ()
get_sensitive ()
get_settings ()
get_size_request ()
get_state ()
get_state_flags ()
get_style ()
get_style_context ()
get_support_multidevice ()
get_template_child (widget_type, name)
get_tooltip_markup ()
get_tooltip_text ()
get_tooltip_window ()
get_toplevel ()
get_valign ()
get_valign_with_baseline ()
get_vexpand ()
get_vexpand_set ()
get_visible ()
get_visual ()
get_window ()
grab_add ()
grab_default ()
grab_focus ()
grab_remove ()
has_default ()
has_focus ()
has_grab ()
has_rc_style ()
has_screen ()
has_visible_focus ()
hide ()
hide_on_delete ()
in_destruction ()
init_template ()
input_shape_combine_region (region)
insert_action_group (name, group)
intersect (area, intersection)
is_ancestor (ancestor)
is_composited ()
is_drawable ()
is_focus ()
is_sensitive ()
is_toplevel ()
is_visible ()
keynav_failed (direction)
list_accel_closures ()
list_action_prefixes ()
list_mnemonic_labels ()
map ()
mnemonic_activate (group_cycling)
modify_base (state, color)
modify_bg (state, color)
modify_cursor (primary, secondary)
modify_fg (state, color)
modify_font (font_desc)
modify_style (style)
modify_text (state, color)
override_background_color (state, color)
override_color (state, color)
override_cursor (cursor, secondary_cursor)
override_font (font_desc)
override_symbolic_color (name, color)
path ()
queue_allocate ()
queue_compute_expand ()
queue_draw ()
queue_draw_area (x, y, width, height)
queue_draw_region (region)
queue_resize ()
queue_resize_no_redraw ()
realize ()
region_intersect (region)
register_window (window)
remove_accelerator (accel_group, accel_key, accel_mods)
remove_mnemonic_label (label)
remove_tick_callback (id)
render_icon (stock_id, size, detail)
render_icon_pixbuf (stock_id, size)
reparent (new_parent)
reset_rc_styles ()
reset_style ()
send_expose (event)
send_focus_change (event)
set_accel_path (accel_path, accel_group)
set_allocation (allocation)
set_app_paintable (app_paintable)
set_can_default (can_default)
set_can_focus (can_focus)
set_child_visible (is_visible)
set_clip (clip)
set_composite_name (name)
set_device_enabled (device, enabled)
set_device_events (device, events)
set_direction (dir)
set_double_buffered (double_buffered)
set_events (events)
set_focus_on_click (focus_on_click)
set_font_map (font_map)
set_font_options (options)
set_halign (align)
set_has_tooltip (has_tooltip)
set_has_window (has_window)
set_hexpand (expand)
set_hexpand_set (set)
set_mapped (mapped)
set_margin_bottom (margin)
set_margin_end (margin)
set_margin_left (margin)
set_margin_right (margin)
set_margin_start (margin)
set_margin_top (margin)
set_name (name)
set_no_show_all (no_show_all)
set_opacity (opacity)
set_parent (parent)
set_parent_window (parent_window)
set_realized (realized)
set_receives_default (receives_default)
set_redraw_on_allocate (redraw_on_allocate)
set_sensitive (sensitive)
set_size_request (width, height)
set_state (state)
set_state_flags (flags, clear)
set_style (style)
set_support_multidevice (support_multidevice)
set_tooltip_markup (markup)
set_tooltip_text (text)
set_tooltip_window (custom_window)
set_valign (align)
set_vexpand (expand)
set_vexpand_set (set)
set_visible (visible)
set_visual (visual)
set_window (window)
shape_combine_region (region)
show ()
show_all ()
show_now ()
size_allocate (allocation)
size_allocate_with_baseline (allocation, baseline)
size_request ()
style_attach ()
style_get_property (property_name, value=None)
thaw_child_notify ()
translate_coordinates (dest_widget, src_x, src_y)
trigger_tooltip_query ()
unmap ()
unparent ()
unrealize ()
unregister_window (window)
unset_state_flags (flags)

Virtual Methods

do_adjust_baseline_allocation (baseline)
do_adjust_baseline_request (minimum_baseline, natural_baseline)
do_adjust_size_allocation (orientation, minimum_size, natural_size, allocated_pos, allocated_size)
do_adjust_size_request (orientation, minimum_size, natural_size)
do_button_press_event (event)
do_button_release_event (event)
do_can_activate_accel (signal_id)
do_child_notify (child_property)
do_composited_changed ()
do_compute_expand (hexpand_p, vexpand_p)
do_configure_event (event)
do_damage_event (event)
do_delete_event (event)
do_destroy ()
do_destroy_event (event)
do_direction_changed (previous_direction)
do_dispatch_child_properties_changed (n_pspecs, pspecs)
do_drag_begin (context)
do_drag_data_delete (context)
do_drag_data_get (context, selection_data, info, time_)
do_drag_data_received (context, x, y, selection_data, info, time_)
do_drag_drop (context, x, y, time_)
do_drag_end (context)
do_drag_failed (context, result)
do_drag_leave (context, time_)
do_drag_motion (context, x, y, time_)
do_draw (cr)
do_enter_notify_event (event)
do_event (event)
do_focus (direction)
do_focus_in_event (event)
do_focus_out_event (event)
do_get_accessible ()
do_get_preferred_height ()
do_get_preferred_height_and_baseline_for_width (width)
do_get_preferred_height_for_width (width)
do_get_preferred_width ()
do_get_preferred_width_for_height (height)
do_get_request_mode ()
do_grab_broken_event (event)
do_grab_focus ()
do_grab_notify (was_grabbed)
do_hide ()
do_hierarchy_changed (previous_toplevel)
do_key_press_event (event)
do_key_release_event (event)
do_keynav_failed (direction)
do_leave_notify_event (event)
do_map ()
do_map_event (event)
do_mnemonic_activate (group_cycling)
do_motion_notify_event (event)
do_move_focus (direction)
do_parent_set (previous_parent)
do_popup_menu ()
do_property_notify_event (event)
do_proximity_in_event (event)
do_proximity_out_event (event)
do_query_tooltip (x, y, keyboard_tooltip, tooltip)
do_queue_draw_region (region)
do_realize ()
do_screen_changed (previous_screen)
do_scroll_event (event)
do_selection_clear_event (event)
do_selection_get (selection_data, info, time_)
do_selection_notify_event (event)
do_selection_received (selection_data, time_)
do_selection_request_event (event)
do_show ()
do_show_all ()
do_show_help (help_type)
do_size_allocate (allocation)
do_state_changed (previous_state)
do_state_flags_changed (previous_state_flags)
do_style_set (previous_style)
do_style_updated ()
do_touch_event (event)
do_unmap ()
do_unmap_event (event)
do_unrealize ()
do_visibility_notify_event (event)
do_window_state_event (event)

Properties

NameTypeFlagsShort Description
app-paintableboolr/w/enWhether the application will paint directly on the widget
can-defaultboolr/w/enWhether the widget can be the default widget
can-focusboolr/w/enWhether the widget can accept the input focus
composite-childboolrWhether the widget is part of a composite widget
double-bufferedboold/r/w/enWhether the widget is double buffered deprecated
eventsGdk.EventMaskr/w/enThe event mask that decides what kind of GdkEvents this widget gets
expandboolr/wWhether widget wants to expand in both directions
focus-on-clickboolr/w/enWhether the widget should grab focus when it is clicked with the mouse
halignGtk.Alignr/w/enHow to position in extra horizontal space
has-defaultboolr/w/enWhether the widget is the default widget
has-focusboolr/w/enWhether the widget has the input focus
has-tooltipboolr/w/enWhether this widget has a tooltip
height-requestintr/w/enOverride for height request of the widget, or -1 if natural request should be used
hexpandboolr/w/enWhether widget wants more horizontal space
hexpand-setboolr/w/enWhether to use the hexpand property
is-focusboolr/wWhether the widget is the focus widget within the toplevel
marginintr/wPixels of extra space on all four sides
margin-bottomintr/w/enPixels of extra space on the bottom side
margin-endintr/w/enPixels of extra space on the end
margin-leftintd/r/w/enPixels of extra space on the left side deprecated
margin-rightintd/r/w/enPixels of extra space on the right side deprecated
margin-startintr/w/enPixels of extra space on the start
margin-topintr/w/enPixels of extra space on the top side
namestrr/wThe name of the widget
no-show-allboolr/w/enWhether Gtk.Widget.show_all() should not affect this widget
opacityfloatr/w/enThe opacity of the widget, from 0 to 1
parentGtk.Containerr/wThe parent widget of this widget. Must be a Container widget
receives-defaultboolr/w/enIf True, the widget will receive the default action when it is focused
scale-factorintrThe scaling factor of the window
sensitiveboolr/w/enWhether the widget responds to input
styleGtk.Styled/r/wThe style of the widget, which contains information about how it will look (colors etc) deprecated
tooltip-markupstrr/wThe contents of the tooltip for this widget
tooltip-textstrr/wThe contents of the tooltip for this widget
valignGtk.Alignr/w/enHow to position in extra vertical space
vexpandboolr/w/enWhether widget wants more vertical space
vexpand-setboolr/w/enWhether to use the vexpand property
visibleboolr/w/enWhether the widget is visible
width-requestintr/w/enOverride for width request of the widget, or -1 if natural request should be used
windowGdk.Window rThe widget’s window if it is realized

Signals

NameShort Description
accel-closures-changed
button-press-eventThe ::button-press-event signal will be emitted when a button (typically from a mouse) is pressed.
button-release-eventThe ::button-release-event signal will be emitted when a button (typically from a mouse) is released.
can-activate-accelDetermines whether an accelerator that activates the signal identified by signal_id can currently be activated.
child-notifyThe ::child-notify signal is emitted for each ‘child property [child-properties]’ that has changed on an object.
composited-changedThe ::composited-changed signal is emitted when the composited status of widgets screen changes.
configure-eventThe ::configure-event signal will be emitted when the size, position or stacking of the widget‘s window has changed.
damage-eventEmitted when a redirected window belonging to widget gets drawn into.
delete-eventThe ::delete-event signal is emitted if a user requests that a toplevel window is closed.
destroySignals that all holders of a reference to the widget should release the reference that they hold.
destroy-eventThe ::destroy-event signal is emitted when a Gdk.Window is destroyed.
direction-changedThe ::direction-changed signal is emitted when the text direction of a widget changes.
drag-beginThe ::drag-begin signal is emitted on the drag source when a drag is started.
drag-data-deleteThe ::drag-data-delete signal is emitted on the drag source when a drag with the action Gdk.DragAction.MOVE is successfully completed.
drag-data-getThe ::drag-data-get signal is emitted on the drag source when the drop site requests the data which is dragged.
drag-data-receivedThe ::drag-data-received signal is emitted on the drop site when the dragged data has been received.
drag-dropThe ::drag-drop signal is emitted on the drop site when the user drops the data onto the widget.
drag-endThe ::drag-end signal is emitted on the drag source when a drag is finished.
drag-failedThe ::drag-failed signal is emitted on the drag source when a drag has failed.
drag-leaveThe ::drag-leave signal is emitted on the drop site when the cursor leaves the widget.
drag-motionThe ::drag-motion signal is emitted on the drop site when the user moves the cursor over the widget during a drag.
drawThis signal is emitted when a widget is supposed to render itself.
enter-notify-eventThe ::enter-notify-event will be emitted when the pointer enters the widget‘s window.
eventThe GTK+ main loop will emit three signals for each GDK event delivered to a widget: one generic ::event signal, another, more specific, signal that matches the type of event delivered (e.g.
event-afterAfter the emission of the Gtk.Widget ::event signal and (optionally) the second more specific signal, ::event-after will be emitted regardless of the previous two signals handlers return values.
focus
focus-in-eventThe ::focus-in-event signal will be emitted when the keyboard focus enters the widget‘s window.
focus-out-eventThe ::focus-out-event signal will be emitted when the keyboard focus leaves the widget‘s window.
grab-broken-eventEmitted when a pointer or keyboard grab on a window belonging to widget gets broken.
grab-focus
grab-notifyThe ::grab-notify signal is emitted when a widget becomes shadowed by a GTK+ grab (not a pointer or keyboard grab) on another widget, or when it becomes unshadowed due to a grab being removed.
hideThe ::hide signal is emitted when widget is hidden, for example with Gtk.Widget.hide().
hierarchy-changedThe ::hierarchy-changed signal is emitted when the anchored state of a widget changes.
key-press-eventThe ::key-press-event signal is emitted when a key is pressed.
key-release-eventThe ::key-release-event signal is emitted when a key is released.
keynav-failedGets emitted if keyboard navigation fails.
leave-notify-eventThe ::leave-notify-event will be emitted when the pointer leaves the widget‘s window.
mapThe ::map signal is emitted when widget is going to be mapped, that is when the widget is visible (which is controlled with Gtk.Widget.set_visible()) and all its parents up to the toplevel widget are also visible.
map-eventThe ::map-event signal will be emitted when the widget‘s window is mapped.
mnemonic-activate
motion-notify-eventThe ::motion-notify-event signal is emitted when the pointer moves over the widget’s Gdk.Window.
move-focus
parent-setThe ::parent-set signal is emitted when a new parent has been set on a widget.
popup-menuThis signal gets emitted whenever a widget should pop up a context menu.
property-notify-eventThe ::property-notify-event signal will be emitted when a property on the widget‘s window has been changed or deleted.
proximity-in-eventTo receive this signal the Gdk.Window associated to the widget needs to enable the Gdk.EventMask.PROXIMITY_IN_MASK mask.
proximity-out-eventTo receive this signal the Gdk.Window associated to the widget needs to enable the Gdk.EventMask.PROXIMITY_OUT_MASK mask.
query-tooltipEmitted when Gtk.Widget :has-tooltip is True and the hover timeout has expired with the cursor hovering “above” widget; or emitted when widget got focus in keyboard mode.
realizeThe ::realize signal is emitted when widget is associated with a Gdk.Window, which means that Gtk.Widget.realize() has been called or the widget has been mapped (that is, it is going to be drawn).
screen-changedThe ::screen-changed signal gets emitted when the screen of a widget has changed.
scroll-eventThe ::scroll-event signal is emitted when a button in the 4 to 7 range is pressed.
selection-clear-eventThe ::selection-clear-event signal will be emitted when the the widget‘s window has lost ownership of a selection.
selection-get
selection-notify-event
selection-received
selection-request-eventThe ::selection-request-event signal will be emitted when another client requests ownership of the selection owned by the widget‘s window.
showThe ::show signal is emitted when widget is shown, for example with Gtk.Widget.show().
show-help
size-allocate
state-changedThe ::state-changed signal is emitted when the widget state changes. deprecated
state-flags-changedThe ::state-flags-changed signal is emitted when the widget state changes, see Gtk.Widget.get_state_flags().
style-setThe ::style-set signal is emitted when a new style has been set on a widget. deprecated
style-updatedThe ::style-updated signal is emitted when the Gtk.StyleContext of a widget is changed.
touch-event
unmapThe ::unmap signal is emitted when widget is going to be unmapped, which means that either it or any of its parents up to the toplevel widget have been set as hidden.
unmap-eventThe ::unmap-event signal will be emitted when the widget‘s window is unmapped.
unrealizeThe ::unrealize signal is emitted when the Gdk.Window associated with widget is destroyed, which means that Gtk.Widget.unrealize() has been called or the widget has been unmapped (that is, it is going to be hidden).
visibility-notify-eventThe ::visibility-notify-event will be emitted when the widget‘s window is obscured or unobscured. deprecated
window-state-eventThe ::window-state-event will be emitted when the state of the toplevel window associated to the widget changes.




代码下载地址:http://download.csdn.net/detail/a87b01c14/9594728

Logo

权威|前沿|技术|干货|国内首个API全生命周期开发者社区

更多推荐