当前位置: 首页>>代码示例>>Python>>正文


Python PaletteMenuItem.get_preferred_size方法代码示例

本文整理汇总了Python中sugar3.graphics.palettemenu.PaletteMenuItem.get_preferred_size方法的典型用法代码示例。如果您正苦于以下问题:Python PaletteMenuItem.get_preferred_size方法的具体用法?Python PaletteMenuItem.get_preferred_size怎么用?Python PaletteMenuItem.get_preferred_size使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在sugar3.graphics.palettemenu.PaletteMenuItem的用法示例。


在下文中一共展示了PaletteMenuItem.get_preferred_size方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: set_palette_list

# 需要导入模块: from sugar3.graphics.palettemenu import PaletteMenuItem [as 别名]
# 或者: from sugar3.graphics.palettemenu.PaletteMenuItem import get_preferred_size [as 别名]
def set_palette_list(instrument_list):
    text_label = instrument_list[0]['instrument_desc']
    file_name = instrument_list[0]['file_name']
    _menu_item = PaletteMenuItem(text_label=text_label,
                                 file_name=file_name)
    req2 = _menu_item.get_preferred_size()[1]
    menuitem_width = req2.width
    menuitem_height = req2.height

    palette_width = Gdk.Screen.width() - style.GRID_CELL_SIZE * 3
    palette_height = Gdk.Screen.height() - style.GRID_CELL_SIZE * 3

    nx = min(int(palette_width / menuitem_width), MAX_PALETTE_WIDTH)
    ny = min(int(palette_height / menuitem_height), len(instrument_list) + 1)
    if ny >= len(instrument_list):
        nx = 1
        ny = len(instrument_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

    for item in sorted(instrument_list,
                       cmp=lambda x, y: cmp(x['instrument_desc'],
                                            y['instrument_desc'])):
        menu_item = PaletteMenuItem(text_label=item['instrument_desc'],
                                    file_name=item['file_name'])
        menu_item.connect('button-release-event', item['callback'], item)

        # menu_item.connect('button-release-event', lambda x: x, 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
开发者ID:godiard,项目名称:music-keyboard-activity,代码行数:56,代码来源:activity.py

示例2: set_palette_list

# 需要导入模块: from sugar3.graphics.palettemenu import PaletteMenuItem [as 别名]
# 或者: from sugar3.graphics.palettemenu.PaletteMenuItem import get_preferred_size [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
开发者ID:sugarlabs,项目名称:words-activity,代码行数:54,代码来源:wordsactivity.py

示例3: set_palette_list

# 需要导入模块: from sugar3.graphics.palettemenu import PaletteMenuItem [as 别名]
# 或者: from sugar3.graphics.palettemenu.PaletteMenuItem import get_preferred_size [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
开发者ID:AbrahmAB,项目名称:sugar,代码行数:74,代码来源:journaltoolbox.py


注:本文中的sugar3.graphics.palettemenu.PaletteMenuItem.get_preferred_size方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。