PyGobject(八十三)Gtk.SizeGroup

Gtk.SizeGroup

将一组小部件组织到一起,使它们拥有相同的高度或者宽度,由set_mode(Gtk.SizeGroupMode)来设置

这里写图片描述

Methods

方法修饰词方法名及参数
staticnew (mode)
add_widget (widget)
get_ignore_hidden ()
get_mode ()
get_widgets ()
remove_widget (widget)
set_ignore_hidden (ignore_hidden)
set_mode (mode)

Virtual Methods

Properties

NameTypeFlagsShort Description
ignore-hiddenboolr/w/enIf True, unmapped widgets are ignored when determining the size of the group
modeGtk.SizeGroupModer/w/enThe directions in which the size group affects the requested sizes of its component widgets

Signals

NameShort Description

例子

这里写图片描述
代码:

#!/usr/bin/env python3
# Created by xiaosanyu at 16/7/21
# section 131

# 
# author: xiaosanyu
# website: yuxiaosan.tk \
#          http://blog.csdn.net/a87b01c14
# created: 16/7/21

TITLE = "SizeGroup"
DESCRIPTION = """
GtkSizeGroup provides a mechanism for grouping a number of
widgets together so they all request the same amount of space.
This is typically useful when you want a column of widgets to
have the same size, but you can't use a GtkTable widget.

Note that size groups only affect the amount of space requested,
not the size that the widgets finally receive. If you want the
widgets in a GtkSizeGroup to actually be the same size, you need
to pack them in such a way that they get the size they request
and not more. For example, if you are packing your widgets
into a table, you would not include the GTK_FILL flag.
"""
import gi

gi.require_version("Gtk", "3.0")
from gi.repository import Gtk, Gdk, GdkPixbuf, GLib

color_options = ["Red", "Green", "Blue"]

dash_options = ["Solid", "Dashed", "Dotted"]

end_options = ["Square", "Round", "Double Arrow"]


class SizeGroupWindow(Gtk.Window):
    def __init__(self):
        Gtk.Window.__init__(self, title="SizeGroup demo")
        self.set_resizable(False)
        vbox = Gtk.VBox(spacing=5)
        self.add(vbox)
        vbox.set_border_width(5)

        size_group = Gtk.SizeGroup.new(Gtk.SizeGroupMode.HORIZONTAL)

        # Create one frame holding color options
        frame = Gtk.Frame.new("Color Options")
        vbox.pack_start(frame, True, True, 0)

        grid = Gtk.Grid()
        grid.set_border_width(5)
        grid.set_row_spacing(5)
        grid.set_column_spacing(10)
        frame.add(grid)

        self.add_row(grid, 0, size_group, "_Foreground", color_options)
        self.add_row(grid, 1, size_group, "_Background", color_options)

        # And another frame holding line style options
        frame = Gtk.Frame.new("Line Options")
        vbox.pack_start(frame, False, False, 0)

        grid = Gtk.Grid()
        grid.set_border_width(5)
        grid.set_row_spacing(5)
        grid.set_column_spacing(10)
        frame.add(grid)

        self.add_row(grid, 0, size_group, "_Dashing", dash_options)
        self.add_row(grid, 1, size_group, "_Line ends", end_options)

        # And a check button to turn grouping on and off
        check_button = Gtk.CheckButton.new_with_mnemonic("_Enable grouping")
        vbox.pack_start(check_button, False, False, 0)

        check_button.set_active(True)
        check_button.connect("toggled", self.toggle_grouping, size_group)

    @staticmethod
    def create_combo_box(strings):
        combo_box = Gtk.ComboBoxText()
        for s in strings:
            combo_box.append_text(s)

        combo_box.set_active(0)

        return combo_box

    def add_row(self, grid, row, size_group, label_text, options):
        label = Gtk.Label.new_with_mnemonic(label_text)
        label.set_halign(Gtk.Align.START)
        label.set_valign(Gtk.Align.BASELINE)
        label.set_hexpand(True)
        grid.attach(label, 0, row, 1, 1)

        combo_box = self.create_combo_box(options)
        label.set_mnemonic_widget(combo_box)
        combo_box.set_halign(Gtk.Align.END)
        combo_box.set_valign(Gtk.Align.BASELINE)
        size_group.add_widget(combo_box)
        grid.attach(combo_box, 1, row, 1, 1)

    @staticmethod
    def toggle_grouping(check_button, size_group):
        # GTK_SIZE_GROUP_NONE is not generally useful, but is useful
        # here to show the effect of GTK_SIZE_GROUP_HORIZONTAL by
        # contrast.
        if check_button.get_active():
            new_mode = Gtk.SizeGroupMode.HORIZONTAL
        else:
            new_mode = Gtk.SizeGroupMode.NONE

        size_group.set_mode(new_mode)


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


if __name__ == "__main__":
    main()





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

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

打赏作者

sanxiaochengyu

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

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

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

打赏作者

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

抵扣说明:

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

余额充值