本文整理汇总了Python中sugar3.graphics.palettemenu.PaletteMenuItemSeparator.set_size_request方法的典型用法代码示例。如果您正苦于以下问题:Python PaletteMenuItemSeparator.set_size_request方法的具体用法?Python PaletteMenuItemSeparator.set_size_request怎么用?Python PaletteMenuItemSeparator.set_size_request使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类sugar3.graphics.palettemenu.PaletteMenuItemSeparator
的用法示例。
在下文中一共展示了PaletteMenuItemSeparator.set_size_request方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: set_palette_list
# 需要导入模块: from sugar3.graphics.palettemenu import PaletteMenuItemSeparator [as 别名]
# 或者: from sugar3.graphics.palettemenu.PaletteMenuItemSeparator import set_size_request [as 别名]
def set_palette_list(palette_list):
if 'icon' in palette_list[0]:
_menu_item = PaletteMenuItem(icon_name=palette_list[0]['icon'],
text_label=palette_list[0]['label'])
else:
_menu_item = PaletteMenuItem(text_label=palette_list[0]['label'])
req2 = _menu_item.get_preferred_size()[1]
menuitem_width = req2.width
menuitem_height = req2.height
palette_width = Gdk.Screen.width() - style.GRID_CELL_SIZE
palette_height = Gdk.Screen.height() - style.GRID_CELL_SIZE * 3
nx = min(_MAXIMUM_PALETTE_COLUMNS, int(palette_width / menuitem_width))
ny = min(int(palette_height / menuitem_height), len(palette_list) + 1)
if ny >= len(palette_list):
nx = 1
ny = len(palette_list)
grid = Gtk.Grid()
grid.set_row_spacing(style.DEFAULT_PADDING)
grid.set_column_spacing(0)
grid.set_border_width(0)
grid.show()
x = 0
y = 0
xo_color = XoColor('white')
for item in palette_list:
if 'separator' in item:
menu_item = PaletteMenuItemSeparator()
elif 'icon' in item:
menu_item = PaletteMenuItem(icon_name=item['icon'],
text_label=item['label'],
xo_color=xo_color)
elif 'file' in item:
menu_item = PaletteMenuItem(file_name=item['file'],
text_label=item['label'],
xo_color=xo_color)
else:
menu_item = PaletteMenuItem()
menu_item.set_label(item['label'])
menu_item.set_size_request(style.GRID_CELL_SIZE * 3, -1)
if 'separator' in item:
y += 1
grid.attach(menu_item, 0, y, nx, 1)
x = 0
y += 1
else:
menu_item.connect('button-release-event', item['callback'], item)
grid.attach(menu_item, x, y, 1, 1)
x += 1
if x == nx:
x = 0
y += 1
menu_item.show()
if palette_height < (y * menuitem_height + style.GRID_CELL_SIZE):
# if the grid is bigger than the palette, put in a scrolledwindow
scrolled_window = Gtk.ScrolledWindow()
scrolled_window.set_policy(Gtk.PolicyType.NEVER,
Gtk.PolicyType.AUTOMATIC)
scrolled_window.set_size_request(nx * menuitem_width,
(ny + 1) * menuitem_height)
scrolled_window.add_with_viewport(grid)
return scrolled_window
else:
return grid