PyGobject(八十三)Gtk.SizeGroup

本文介绍GtkSizeGroup组件的使用方法,通过Python示例代码展示如何将一组小部件的高度或宽度统一,实现美观一致的界面布局。

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.youkuaiyun.com/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.youkuaiyun.com/detail/a87b01c14/9594728

关于 阿里云盘CLI。仿 Linux shell 文件处理命令的阿里云盘命令行客户端,支持JavaScript插件,支持同步备份功能,支持相册批量下载。 特色 多平台支持, 支持 Windows, macOS, linux(x86/x64/arm), android, iOS 等 阿里云盘多用户支持 支持备份盘,资源库无缝切换 下载网盘内文件, 支持多个文件或目录下载, 支持断点续传和单文件并行下载。支持软链接(符号链接)文件。 上传本地文件, 支持多个文件或目录上传,支持排除指定文件夹/文件(正则表达式)功能。支持软链接(符号链接)文件。 同步备份功能支持备份本地文件到云盘,备份云盘文件到本地,双向同步备份保持本地文件和网盘文件同步。常用于嵌入式或者NAS等设备,支持docker镜像部署。 命令和文件路径输入支持Tab键自动补全,路径支持通配符匹配模式 支持JavaScript插件,你可以按照自己的需要定制上传/下载中关键步骤的行为,最大程度满足自己的个性化需求 支持共享相册的相关操作,支持批量下载相册所有普通照片、实况照片文件到本地 支持多用户联合下载功能,对下载速度有极致追求的用户可以尝试使用该选项。详情请查看文档多用户联合下载 如果大家有打算开通阿里云盘VIP会员,可以使用阿里云盘APP扫描下面的优惠推荐码进行开通。 注意:您需要开通【三方应用权益包】,这样使用本程序下载才能加速,否则下载无法提速。 Windows不第二步打开aliyunpan命令行程序,任何云盘命令都有类似如下日志输出 如何登出和下线客户端 阿里云盘单账户最多只允许同时登录 10 台设备 当出现这个提示:你账号已超出最大登录设备数量,请先下线一台设备,然后重启本应用,才可以继续使用 说明你的账号登录客户端已经超过数量,你需要先登出其他客户端才能继续使用,如下所示
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

打赏作者

sanxiaochengyu

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

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

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

打赏作者

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

抵扣说明:

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

余额充值