Gtk.ActionBar
继承关系
Gtk.ActionBar被设计为呈现上下文动作。
通常水平放置在主要内容的下方
Gtk.ActionBar是Gtk.Bin的直接子类
Methods
方法修饰词 | 方法名及参数 |
---|---|
static | new () |
get_center_widget () | |
pack_end (child) | |
pack_start (child) | |
set_center_widget (center_widget) |
Virtual Methods
Properties
Name | Type | Flags | Short Description |
---|
Signals
Name | Short Description |
---|
例子
代码:
#!/usr/bin/env python3
# Created by xiaosanyu at 16/7/7
# section 019
TITLE = "ActionBar"
DESCRIPTION = """
Gtk.ActionBar is designed to present contextual actions.
It is expected to be displayed below the content and expand horizontally to fill the area
"""
import gi
gi.require_version("Gtk", "3.0")
from gi.repository import Gtk
icons = ["edit-cut", "edit-paste", "edit-copy"]
class ActionBarWindow(Gtk.Window):
def __init__(self):
Gtk.Window.__init__(self, title="ActionBar Example")
self.set_size_request(250, 200)
box = Gtk.VBox()
ab = Gtk.ActionBar()
theme = Gtk.IconTheme.get_default()
for i, icon in enumerate(icons):
if theme.has_icon(icon):
image = Gtk.Image.new_from_icon_name(icon, Gtk.IconSize.MENU)
button = Gtk.Button()
button.add(image)
if i == 0:
ab.pack_start(button)
elif i == 1:
ab.set_center_widget(button)
elif i == 2:
ab.pack_end(button)
box.pack_end(ab, False, False, 0)
box.pack_start(Gtk.TextView(), True, True, 0)
self.add(box)
def main():
win = ActionBarWindow()
win.connect("delete-event", Gtk.main_quit)
win.show_all()
Gtk.main()
if __name__ == "__main__":
main()
分析主要代码
创建Gtk.ActionBar
ab = Gtk.ActionBar()
创建三个图片按钮,第一个放在最左边,第二个放在中间,第三个放在最末尾
icons = ["edit-cut", "edit-paste", "edit-copy"]
theme = Gtk.IconTheme.get_default()
for i, icon in enumerate(icons):
if theme.has_icon(icon):
image = Gtk.Image.new_from_icon_name(icon, Gtk.IconSize.MENU)
button = Gtk.Button()
button.add(image)
if i == 0:
ab.pack_start(button)
elif i == 1:
ab.set_center_widget(button)
elif i == 2:
ab.pack_end(button)