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

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

项目:Ebook-Viewer    作者:michaldaniel    | 项目源码 | 文件源码
def __init__(self, data, chapter):
        """
        Holds data that is chapter name and chapter_link that is link to chapter file. For use as ListBox element.
        :param data:
        :param chapter:
        """
        super(Gtk.ListBoxRow, self).__init__()

        # Remember chapter name and file link
        self.data = data
        self.chapter_link = chapter

        # Just a bunch of label styling
        label = Gtk.Label(xalign=0)
        label.set_text(data)
        label.set_justify(Gtk.Justification.LEFT)
        try:
            label.set_margin_start(10)
        except AttributeError:
            label.set_margin_left(10)
        label.set_width_chars(20)
        label.set_ellipsize(Pango.EllipsizeMode.END)

        self.add(label)
项目:Gnome-Authenticator    作者:bil-elmoussaoui    | 项目源码 | 文件源码
def generate(self):
        Gtk.ListBox.__init__(self)
        self.get_style_context().add_class("applications-list")
        self.set_adjustment()
        self.set_selection_mode(Gtk.SelectionMode.SINGLE)

        count = len(self.accounts)

        for account in self.accounts:
            self.add(AccountRowList(self, self.window, account))

        if count != 0:
            self.select_row(self.get_row_at_index(0))
项目:Gnome-Authenticator    作者:bil-elmoussaoui    | 项目源码 | 文件源码
def add_apps(self):
        """
            Add database applications to the Gtk.ListBox
        """
        self.db = sorted(self.db, key=lambda k: k['name'].lower())
        logging.debug("Application list was ordered alphabetically")

        for app in self.db:
            img_path = app["img"]
            app_name = app["name"]
            self.listbox.add(ApplicationRow(app_name, img_path))

        if len(self.db) != 0:
            self.listbox.select_row(self.listbox.get_row_at_index(0))
项目:sbrick-controller    作者:wintersandroid    | 项目源码 | 文件源码
def __init__(self, configuration, channels):
        Gtk.Box.__init__(self, orientation=Gtk.Orientation.VERTICAL)
        self.set_homogeneous(False)

        self.tool_bar = Gtk.Toolbar()
        self.pack_start(self.tool_bar, False, True, 0)

        tool = Gtk.ToolButton.new(Gtk.Image.new_from_stock(Gtk.STOCK_ADD, Gtk.IconSize.BUTTON), "Add")
        tool.connect("clicked", self.on_add_clicked)
        self.tool_bar.insert(tool, -1)
        tool = Gtk.ToolButton.new(Gtk.Image.new_from_stock(Gtk.STOCK_DELETE, Gtk.IconSize.BUTTON), "Delete")
        tool.connect("clicked", self.on_delete_clicked)
        self.tool_bar.insert(tool, -1)
        self.content = Gtk.ListBox()

        self.scrollTree = Gtk.ScrolledWindow()
        self.scrollTree.set_policy(Gtk.PolicyType.NEVER, Gtk.PolicyType.AUTOMATIC)
        self.scrollTree.add_with_viewport(self.content)
        self.scrollTree.set_min_content_height(100)
        self.pack_start(self.scrollTree, True, True, 0)

        self.configuration = configuration
        self.channels = channels
        self.sbrick = None
        self.functionGroups = []

        for group in configuration:
            fg = FunctionGroupBox(group, channels)
            # self.pack_start(fg, False, True, 0)
            self.content.add(fg)
            self.functionGroups.append(fg)
项目:sbrick-controller    作者:wintersandroid    | 项目源码 | 文件源码
def __init__(self, configuration, sbrick_communications_store):
        Gtk.Box.__init__(self, orientation=Gtk.Orientation.VERTICAL, spacing=3, margin=0)
        self.set_homogeneous(False)
        self.configuration = configuration
        self.sbrick_communications_store = sbrick_communications_store

        self.tool_bar = Gtk.Toolbar()
        self.pack_start(self.tool_bar, False, True, 0)

        self.action_play_all = Gtk.ToolButton.new(Gtk.Image.new_from_stock(Gtk.STOCK_MEDIA_PLAY, Gtk.IconSize.BUTTON),
                                                  "Play All")
        self.action_play_all.connect("clicked", self.on_play_all_clicked)
        self.tool_bar.insert(self.action_play_all, -1)
        self.action_stop_all = Gtk.ToolButton.new(Gtk.Image.new_from_stock(Gtk.STOCK_MEDIA_STOP, Gtk.IconSize.BUTTON),
                                                  "Stop All")
        self.action_stop_all.connect("clicked", self.on_stop_all_clicked)
        self.tool_bar.insert(self.action_stop_all, -1)
        self.content = Gtk.ListBox()

        self.scrollTree = Gtk.ScrolledWindow()
        self.scrollTree.set_policy(Gtk.PolicyType.NEVER, Gtk.PolicyType.AUTOMATIC)
        self.scrollTree.add_with_viewport(self.content)
        self.scrollTree.set_min_content_height(100)
        self.pack_start(self.scrollTree, True, True, 0)

        self.sequence_count = 0
        if self.configuration is not None:
            for sbrick in self.configuration:
                stepbox = SequencePlayerBox(sbrick, sbrick_communications_store)
                stepbox.connect("sequence_finished", self.on_sequence_finished)
                self.content.add(stepbox)
                self.sequence_count = self.sequence_count + 1
        self.playing = False
        self.playing_sequence = None
        self.playing_index = -1
项目:Ebook-Viewer    作者:michaldaniel    | 项目源码 | 文件源码
def __init__(self, window):
        """
        Provides the List Box with chapters index and navigation based around them
        :param window: Main application window reference, serves as communication hub
        """
        super(Gtk.ListBox, self).__init__()
        self.__window = window
        # Only one chapter can be selected at a time
        # set_current_chapter() method relies on this
        self.set_selection_mode(Gtk.SelectionMode.SINGLE)
        self.connect('row_activated', self.__on_listbox_row_activated)
        self.__populate_listbox()
项目:ibus-typing-booster    作者:mike-fabian    | 项目源码 | 文件源码
def _fill_listbox_font(self, filter_text):
        '''
        Fill the listbox of fonts to choose from

        :param filter_text: The filter text to limit the
                            fonts listed. Only fonts which
                            contain the the filter text as
                            a substring (ignoring case and spaces)
                            are listed.
        :type filter_text: String
        '''
        if _ARGS.debug:
            sys.stdout.write(
                '_fill_listbox_font() filter_text = %s\n'
                %filter_text)
        for child in self._font_popover_scroll.get_children():
            self._font_popover_scroll.remove(child)
        self._font_popover_listbox = Gtk.ListBox()
        self._font_popover_scroll.add(self._font_popover_listbox)
        self._font_popover_listbox.set_visible(True)
        self._font_popover_listbox.set_vexpand(True)
        self._font_popover_listbox.set_selection_mode(Gtk.SelectionMode.SINGLE)
        self._font_popover_listbox.set_activate_on_single_click(True)
        self._font_popover_listbox.connect(
            'row-selected', self.on_font_selected)
        fonts = [
            font
            for font in self._list_font_names()
            if filter_text.replace(' ', '').lower()
            in font.replace(' ', '').lower()]
        for font in fonts:
            label = Gtk.Label(font)
            label.set_xalign(0)
            margin = 1
            label.set_margin_start(margin)
            label.set_margin_end(margin)
            label.set_margin_top(margin)
            label.set_margin_bottom(margin)
            self._font_popover_listbox.insert(label, -1)
        for row in self._font_popover_listbox.get_children():
            row.get_style_context().add_class('font')
        self._font_popover.show_all()
项目:ibus-typing-booster    作者:mike-fabian    | 项目源码 | 文件源码
def on_font_selected(self, dummy_listbox, listbox_row):
        '''
        Signal handler for selecting a font

        :param dummy_listbox: The list box used to select a font
        :type dummy_listbox: Gtk.ListBox object
        :param listbox_row: A row containing a font name
        :type listbox_row: Gtk.ListBoxRow object
        '''
        font = listbox_row.get_child().get_text().split(' ')[0]
        if _ARGS.debug:
            sys.stdout.write(
                'on_font_selected() font = %s\n' %repr(font))
        if font == '':
            font = 'emoji'
        if font != self._font and font == 'emoji':
            self._fallback = True
            self._fallback_check_button.set_active(True)
        else:
            self._fallback = False
            self._fallback_check_button.set_active(False)
        if GTK_VERSION >= (3, 22, 0):
            self._font_popover.popdown()
        self._font_popover.hide()
        self._font = font
        self._font_button.set_label(self._font)
        self._save_options()
        self._busy_start()
        GLib.idle_add(self._change_flowbox_font)
项目:draobpilc    作者:awamper    | 项目源码 | 文件源码
def bind(self, list_box):
        if isinstance(list_box, Gtk.ListBox):
            self._list_box = list_box
            list_box.connect('add', lambda _, __: self.update())
            list_box.connect('remove', lambda _, __: self.update())
项目:indprog    作者:schlagenhauf    | 项目源码 | 文件源码
def generateParamBox(self):
        if len(self.procNode.getParams()) == 0:
            return

        sep = Gtk.Separator.new(Gtk.Orientation.HORIZONTAL)
        self.vbox.pack_start(sep, False, False, 0)

        self.expander = Gtk.Expander.new('Parameters')
        self.expander.set_resize_toplevel(True)

        self.paramBox = Gtk.ListBox()
        for k,v in self.procNode.getParams().items():
            hbox = Gtk.Box(Gtk.Orientation.HORIZONTAL, 0)
            label = Gtk.Label(k)
            label.set_xalign(0)
            hbox.pack_start(label, True, True, 0)
            entry = Gtk.Entry()
            entry.set_text(str(v))
            entry.set_alignment(1)
            entry.set_has_frame(False)
            entry.connect('changed', lambda w, d=None, key=k: self.__paramChanged(w, key))
            hbox.pack_start(entry, True, True, 0)
            row = Gtk.ListBoxRow()
            row.add(hbox)
            self.paramBox.add(row)

        self.expander.add(self.paramBox)
        self.vbox.pack_end(self.expander, True, True, 0)
项目: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)
项目:sbrick-controller    作者:wintersandroid    | 项目源码 | 文件源码
def __init__(self, configuration):
        Gtk.Box.__init__(self, orientation=Gtk.Orientation.VERTICAL)
        self.set_homogeneous(False)
        self.sequence_player = None

        self.tool_bar = Gtk.Toolbar()
        self.pack_start(self.tool_bar, False, True, 0)

        self.tool_add = Gtk.ToolButton.new(Gtk.Image.new_from_stock(Gtk.STOCK_ADD, Gtk.IconSize.BUTTON), "Add")
        self.tool_add.connect("clicked", self.on_add_clicked)
        self.tool_bar.insert(self.tool_add, -1)

        self.tool_delete = Gtk.ToolButton.new(Gtk.Image.new_from_stock(Gtk.STOCK_DELETE, Gtk.IconSize.BUTTON), "Delete")
        self.tool_delete.connect("clicked", self.on_delete_clicked)
        self.tool_bar.insert(self.tool_delete, -1)

        self.tool_bar.insert(Gtk.SeparatorToolItem.new(), -1)

        self.tool_up = Gtk.ToolButton.new(Gtk.Image.new_from_stock(Gtk.STOCK_GO_UP, Gtk.IconSize.BUTTON), "Add")
        self.tool_up.connect("clicked", self.on_up_clicked)
        self.tool_bar.insert(self.tool_up, -1)

        self.tool_down = Gtk.ToolButton.new(Gtk.Image.new_from_stock(Gtk.STOCK_GO_DOWN, Gtk.IconSize.BUTTON), "Add")
        self.tool_down.connect("clicked", self.on_down_clicked)
        self.tool_bar.insert(self.tool_down, -1)

        self.tool_bar.insert(Gtk.SeparatorToolItem.new(), -1)

        self.tool_play = Gtk.ToolButton.new(Gtk.Image.new_from_stock(Gtk.STOCK_MEDIA_PLAY, Gtk.IconSize.BUTTON), "Run")
        self.tool_play.connect("clicked", self.on_run_clicked)
        self.tool_bar.insert(self.tool_play, -1)
        self.enable_tools(True, False)

        self.content = Gtk.ListBox()

        self.scrollTree = Gtk.ScrolledWindow()
        self.scrollTree.set_policy(Gtk.PolicyType.NEVER, Gtk.PolicyType.AUTOMATIC)
        self.scrollTree.add_with_viewport(self.content)
        self.scrollTree.set_min_content_height(100)
        self.pack_start(self.scrollTree, True, True, 0)

        self.sbrickConfiguration = configuration
        self.sbrick = None
        self.sequenceSteps = []

        if "sequence" in self.sbrickConfiguration:
            for step in self.sbrickConfiguration["sequence"]:
                stepbox = SequenceStepBox(step, self.sbrickConfiguration["functions"])
                self.content.add(stepbox)
                self.sequenceSteps.append(stepbox)
        else:
            self.sbrickConfiguration["sequence"] = []