Python gi.repository.Gtk 模块,ToolItem() 实例源码

我们从Python开源项目中,提取了以下7个代码示例,用于说明如何使用gi.repository.Gtk.ToolItem()

项目:bokken    作者:thestr4ng3r    | 项目源码 | 文件源码
def do_create_tool_item(self):
        return Gtk.ToolItem()
项目:lightdm-settings    作者:linuxmint    | 项目源码 | 文件源码
def __init__(self, title):
        Gtk.Frame.__init__(self)
        self.set_shadow_type(Gtk.ShadowType.IN)
        frame_style = self.get_style_context()
        frame_style.add_class("view")
        self.size_group = Gtk.SizeGroup()
        self.size_group.set_mode(Gtk.SizeGroupMode.VERTICAL)

        self.box = Gtk.Box(orientation=Gtk.Orientation.VERTICAL)
        self.add(self.box)

        toolbar = Gtk.Toolbar.new()
        toolbar_context = toolbar.get_style_context()
        Gtk.StyleContext.add_class(Gtk.Widget.get_style_context(toolbar), "cs-header")

        label = Gtk.Label.new()
        label.set_markup("<b>%s</b>" % title)
        title_holder = Gtk.ToolItem()
        title_holder.add(label)
        toolbar.add(title_holder)
        self.box.add(toolbar)

        toolbar_separator = Gtk.Separator(orientation=Gtk.Orientation.HORIZONTAL)
        self.box.add(toolbar_separator)
        separator_context = toolbar_separator.get_style_context()
        frame_color = frame_style.get_border_color(Gtk.StateFlags.NORMAL).to_string()
        # css_provider = Gtk.CssProvider()
        # css_provider.load_from_data(".separator { -GtkWidget-wide-separators: 0; \
        #                                            color: %s;                    \
        #                                         }" % frame_color)
        # separator_context.add_provider(css_provider, Gtk.STYLE_PROVIDER_PRIORITY_APPLICATION)

        self.list_box = Gtk.ListBox()
        self.list_box.set_selection_mode(Gtk.SelectionMode.NONE)
        self.list_box.set_header_func(list_header_func, None)
        self.box.add(self.list_box)
项目:x-mario-center    作者:fossasia    | 项目源码 | 文件源码
def _insert_as_tool_item(self, widget, pos):
        item = Gtk.ToolItem()
        item.add(widget)
        self.insert(item, pos)
        return item
项目:x-mario-center    作者:fossasia    | 项目源码 | 文件源码
def _insert_as_tool_item(self, widget, pos):
        item = Gtk.ToolItem()
        item.add(widget)
        self.insert(item, pos)
        return item
项目:bokken    作者:thestr4ng3r    | 项目源码 | 文件源码
def create(toolbar):
    '''Set of instructions to create the search widget in a toolbar.'''

    # Search components
    toolbar.search_combo_tb = Gtk.ToolItem()
    toolbar.search_combo_align = Gtk.Alignment.new(0, 0.5, 0, 0)
    store = Gtk.ListStore(GdkPixbuf.Pixbuf, str)
    toolbar.search_combo = Gtk.ComboBox.new_with_model(store)
    rendererText = Gtk.CellRendererText()
    rendererPix = Gtk.CellRendererPixbuf()
    toolbar.search_combo.pack_start(rendererPix, False)
    toolbar.search_combo.pack_start(rendererText, True)
    toolbar.search_combo.add_attribute(rendererPix, 'pixbuf', 0)
    toolbar.search_combo.add_attribute(rendererText, 'text', 1)

    options = {
        'String':GdkPixbuf.Pixbuf.new_from_file(datafile_path('icon_string_16.png')),
        'String no case':GdkPixbuf.Pixbuf.new_from_file(datafile_path('icon_string_no_case_16.png')),
        'Hexadecimal':GdkPixbuf.Pixbuf.new_from_file(datafile_path('icon_hexadecimal_16.png')),
        'Regexp':GdkPixbuf.Pixbuf.new_from_file(datafile_path('icon_regexp_16.png'))
    }

    for option in options.keys():
        store.append([options[option], option])
    toolbar.search_combo.set_active(0)
    toolbar.search_combo_align.add(toolbar.search_combo)
    toolbar.search_combo_tb.add(toolbar.search_combo_align)
    toolbar.main_tb.insert(toolbar.search_combo_tb, -1)

    # Separator
    toolbar.sep = Gtk.SeparatorToolItem()
    toolbar.sep.set_draw(False)
    toolbar.main_tb.insert(toolbar.sep, -1)

    toolbar.search_entry_tb = Gtk.ToolItem()
    toolbar.search_entry = Gtk.Entry()
    toolbar.search_entry.set_max_length(100)
    toolbar.search_entry.set_text('Text to search')
    toolbar.search_entry.set_icon_from_stock(1, Gtk.STOCK_FIND)
    toolbar.search_entry.set_icon_tooltip_text(1, 'Search')
    toolbar.search_entry.connect("activate", toolbar.search)
    toolbar.search_entry.connect("icon-press", toolbar.search)
    toolbar.search_entry.connect('focus-in-event', toolbar._clean, 'in')
    toolbar.search_entry.connect('focus-out-event', toolbar._clean, 'out')
    toolbar.search_entry_tb.add(toolbar.search_entry)
    # We use the AccelGroup object from the main window.
    my_accel = Gtk.accel_groups_from_object(toolbar.main.window)[0]
    key, mod = Gtk.accelerator_parse('<Control>F')
    toolbar.search_entry.set_tooltip_text('Control-F to search')
    toolbar.search_entry.add_accelerator('grab-focus', my_accel, key, mod, Gtk.AccelFlags.MASK)
    toolbar.main_tb.insert(toolbar.search_entry_tb, -1)
项目:x-mario-center    作者:fossasia    | 项目源码 | 文件源码
def __init__(self, view_manager, datadir, db, cache, icons):
        Gtk.Toolbar.__init__(self)
        context = self.get_style_context()
        context.add_class(Gtk.STYLE_CLASS_PRIMARY_TOOLBAR)

        # add nav history back/forward buttons...
        # note:  this is hacky, would be much nicer to make the custom
        # self/right buttons in BackForwardButton to be
        # Gtk.Activatable/Gtk.Widgets, then wire in the actions using e.g.
        # self.navhistory_back_action.connect_proxy(self.back_forward.left),
        # but couldn't seem to get this to work..so just wire things up
        # directly
        vm = get_viewmanager()
        self.back_forward = vm.get_global_backforward()
        self.back_forward.set_vexpand(False)
        self.back_forward.set_valign(Gtk.Align.CENTER)

        if self.get_direction() != Gtk.TextDirection.RTL:
            _widget_set_margins(self.back_forward,
                                left=StockEms.MEDIUM,
                                right=StockEms.MEDIUM + 2)
        else:
            _widget_set_margins(self.back_forward,
                                right=StockEms.MEDIUM,
                                left=StockEms.MEDIUM + 2)
        self._insert_as_tool_item(self.back_forward, 0)

        # this is what actually draws the All Software, Installed etc buttons
        self.view_switcher = ViewSwitcher(view_manager, datadir, db, cache,
            icons)
        self._insert_as_tool_item(self.view_switcher, 1)

        item = Gtk.ToolItem()
        item.set_expand(True)
        self.insert(item, -1)

        #~ self.init_atk_name(self.searchentry, "searchentry")
        self.searchentry = vm.get_global_searchentry()
        self._insert_as_tool_item(self.searchentry, -1)

        # spinner
        self.spinner = vm.get_global_spinner()
        self.spinner.set_size_request(StockEms.XLARGE, StockEms.XLARGE)
        self._insert_as_tool_item(self.spinner, -1)

        if self.get_direction() != Gtk.TextDirection.RTL:
            _widget_set_margins(self.searchentry, right=StockEms.MEDIUM)
        else:
            _widget_set_margins(self.searchentry, left=StockEms.MEDIUM)
项目:x-mario-center    作者:fossasia    | 项目源码 | 文件源码
def __init__(self, view_manager, datadir, db, cache, icons):
        Gtk.Toolbar.__init__(self)
        context = self.get_style_context()
        context.add_class(Gtk.STYLE_CLASS_PRIMARY_TOOLBAR)

        # add nav history back/forward buttons...
        # note:  this is hacky, would be much nicer to make the custom
        # self/right buttons in BackForwardButton to be
        # Gtk.Activatable/Gtk.Widgets, then wire in the actions using e.g.
        # self.navhistory_back_action.connect_proxy(self.back_forward.left),
        # but couldn't seem to get this to work..so just wire things up
        # directly
        vm = get_viewmanager()
        self.back_forward = vm.get_global_backforward()
        self.back_forward.set_vexpand(False)
        self.back_forward.set_valign(Gtk.Align.CENTER)

        if self.get_direction() != Gtk.TextDirection.RTL:
            _widget_set_margins(self.back_forward,
                                left=StockEms.MEDIUM,
                                right=StockEms.MEDIUM + 2)
        else:
            _widget_set_margins(self.back_forward,
                                right=StockEms.MEDIUM,
                                left=StockEms.MEDIUM + 2)
        self._insert_as_tool_item(self.back_forward, 0)

        # this is what actually draws the All Software, Installed etc buttons
        self.view_switcher = ViewSwitcher(view_manager, datadir, db, cache,
            icons)
        self._insert_as_tool_item(self.view_switcher, 1)

        item = Gtk.ToolItem()
        item.set_expand(True)
        self.insert(item, -1)

        #~ self.init_atk_name(self.searchentry, "searchentry")
        self.searchentry = vm.get_global_searchentry()
        self._insert_as_tool_item(self.searchentry, -1)

        # spinner
        self.spinner = vm.get_global_spinner()
        self.spinner.set_size_request(StockEms.XLARGE, StockEms.XLARGE)
        self._insert_as_tool_item(self.spinner, -1)

        if self.get_direction() != Gtk.TextDirection.RTL:
            _widget_set_margins(self.searchentry, right=StockEms.MEDIUM)
        else:
            _widget_set_margins(self.searchentry, left=StockEms.MEDIUM)