PyGobject(三十八)布局容器之ScrolledWindow

Gtk.ScrolledWindow

Gtk.ScrolledWindow滚动布局

继承关系

Gtk.ScrolledWindow是Gtk.Window的直接子类
这里写图片描述
这里写图片描述

Methods

方法修饰词方法名及参数
staticnew (hadjustment, vadjustment)
add_with_viewport (child)
get_capture_button_press ()
get_hadjustment ()
get_hscrollbar ()
get_kinetic_scrolling ()
get_min_content_height ()
get_min_content_width ()
get_overlay_scrolling ()
get_placement ()
get_policy ()
get_shadow_type ()
get_vadjustment ()
get_vscrollbar ()
set_capture_button_press (capture_button_press)
set_hadjustment (hadjustment)
set_kinetic_scrolling (kinetic_scrolling)
set_min_content_height (height)
set_min_content_width (width)
set_overlay_scrolling (overlay_scrolling)
set_placement (window_placement)
set_policy (hscrollbar_policy, vscrollbar_policy)
set_shadow_type (type)
set_vadjustment (vadjustment)
unset_placement ()

Virtual Methods

do_move_focus_out (direction)
do_scroll_child (scroll, horizontal)

Properties

NameTypeFlagsShort Description
hadjustmentGtk.Adjustmentr/w/c水平方向的 Gtk.Adjustment
hscrollbar-policyGtk.PolicyTyper/w/en水平滚动条显示方式
kinetic-scrollingboolr/w/enKinetic scrolling mode.
min-content-heightintr/w/enThe minimum height that the scrolled window will allocate to its content
min-content-widthintr/w/enThe minimum width that the scrolled window will allocate to its content
overlay-scrollingboolr/w/enOverlay scrolling mode
shadow-typeGtk.ShadowTyper/w/en阴影样式
vadjustmentGtk.Adjustmentr/w/c垂直方向Gtk.Adjustment
vscrollbar-policyGtk.PolicyTyper/w/en垂直滚动条显示方式
window-placementGtk.CornerTyper/w/enWhere the contents are located with respect to the scrollbars.
window-placement-setboolr/w/enWhether “window-placement” should be used to determine the location of the contents with respect to the scrollbars. deprecated

Signals

NameShort Description
edge-overshotThe ::edge-overshot signal is emitted whenever user initiated scrolling makes the scrolledwindow firmly surpass (ie.
edge-reachedThe ::edge-reached signal is emitted whenever user-initiated scrolling makes the scrolledwindow exactly reaches the lower or upper limits defined by the adjustment in that orientation.
move-focus-outThe ::move-focus-out signal is a keybinding signal which gets emitted when focus is moved away from the scrolled window by a keybinding.
scroll-childThe ::scroll-child signal is a keybinding signal which gets emitted when a keybinding that scrolls is pressed.

例子

这里写图片描述
代码:

#!/usr/bin/env python3
# Created by xiaosanyu at 16/7/11
# section 055
# 
# author: xiaosanyu
# website: yuxiaosan.tk \
#          http://blog.csdn.net/a87b01c14
# created: 16/7/11

TITLE = "ScrolledWindow"
DESCRIPTION = """
Gtk.ScrolledWindow is a Gtk.Bin subclass: it’s a container the accepts a single child widget.
Gtk.ScrolledWindow adds scrollbars to the child widget and optionally draws a beveled frame around the child widget.

The scrolled window can work in two ways. Some widgets have native scrolling support;
these widgets implement the Gtk.Scrollable interface. Widgets with native scroll support include Gtk.TreeView, Gtk.TextView, and Gtk.Layout.

For widgets that lack native scrolling support, the Gtk.Viewport widget acts as an adaptor class,
implementing scrollability for child widgets that lack their own scrolling capabilities.
Use Gtk.Viewport to scroll child widgets such as Gtk.Grid, Gtk.Box, and so on.

If a widget has native scrolling abilities, it can be added to the Gtk.ScrolledWindow
with Gtk.Container.add(). If a widget does not, you must first add the widget to a Gtk.Viewport,
then add the Gtk.Viewport to the scrolled window. Gtk.Container.add() will do this for you for widgets
that don’t implement Gtk.Scrollable natively, so you can ignore the presence of the viewport
"""

import gi

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

HEIGHT = 20
NUM = 100


class ScrolledWindow(Gtk.Window):
    def __init__(self):
        super(ScrolledWindow, self).__init__(title="ScrolledWindow Demo")
        self.set_size_request(200, 200)
        self.layout = Gtk.Layout.new(None, None)
        # important Sets the size of the scrollable area of the layout.
        self.layout.set_size(200, NUM * HEIGHT)
        self.sw = Gtk.ScrolledWindow()
        self.sw.set_shadow_type(Gtk.ShadowType.ETCHED_IN)
        self.sw.set_policy(Gtk.PolicyType.AUTOMATIC, Gtk.PolicyType.AUTOMATIC)
        self.sw.add(self.layout)
        for i in range(NUM):
            self.layout.put(Gtk.Label("label" + str(i)), 20, HEIGHT * i)

        self.add(self.sw)


def main():
    win = ScrolledWindow()
    win.connect("delete-event", Gtk.main_quit)
    win.show_all()
    Gtk.main()


if __name__ == "__main__":
    main()

解析参见PyGobject(四十九)布局容器之Layout





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

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

sanxiaochengyu

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值