本文整理汇总了Python中sugar3.graphics.palettemenu.PaletteMenuItem.set_size_request方法的典型用法代码示例。如果您正苦于以下问题:Python PaletteMenuItem.set_size_request方法的具体用法?Python PaletteMenuItem.set_size_request怎么用?Python PaletteMenuItem.set_size_request使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类sugar3.graphics.palettemenu.PaletteMenuItem
的用法示例。
在下文中一共展示了PaletteMenuItem.set_size_request方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: set_palette_list
# 需要导入模块: from sugar3.graphics.palettemenu import PaletteMenuItem [as 别名]
# 或者: from sugar3.graphics.palettemenu.PaletteMenuItem import set_size_request [as 别名]
def set_palette_list(self, options):
_menu_item = PaletteMenuItem(text_label=options[options.keys()[0]])
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(self._MAXIMUM_PALETTE_COLUMNS,
int(palette_width / menuitem_width))
ny = min(int(palette_height / menuitem_height), len(options) + 1)
if ny >= len(options):
nx = 1
ny = len(options)
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
for key in options.keys():
menu_item = PaletteMenuItem()
menu_item.set_label(options[key])
menu_item.set_size_request(style.GRID_CELL_SIZE * 3, -1)
menu_item.connect('button-release-event', self._option_selected,
key)
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