PyGobject(八十三)Gtk.SizeGroup

来源:互联网 发布:陈百祥多隆 知乎 编辑:程序博客网 时间:2024/06/16 16:41

  • GtkSizeGroup
    • Methods
    • Virtual Methods
    • Properties
    • Signals
    • 例子

Gtk.SizeGroup

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

这里写图片描述

Methods

方法修饰词 方法名及参数 static new (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

Name Type Flags Short Description ignore-hidden bool r/w/en If True, unmapped widgets are ignored when determining the size of the group mode Gtk.SizeGroupMode r/w/en The directions in which the size group affects the requested sizes of its component widgets

Signals

Name Short 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/21TITLE = "SizeGroup"DESCRIPTION = """GtkSizeGroup provides a mechanism for grouping a number ofwidgets together so they all request the same amount of space.This is typically useful when you want a column of widgets tohave 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 thewidgets in a GtkSizeGroup to actually be the same size, you needto pack them in such a way that they get the size they requestand not more. For example, if you are packing your widgetsinto a table, you would not include the GTK_FILL flag."""import gigi.require_version("Gtk", "3.0")from gi.repository import Gtk, Gdk, GdkPixbuf, GLibcolor_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
原创粉丝点击