Ejemplo n.º 1
0
    def __init__(self):
        super().__init__()

        self.set_orientation(Gtk.Orientation.VERTICAL)
        self.set_valign(Gtk.Align.FILL)
        self.set_halign(Gtk.Align.FILL)
        self.set_vexpand(True)
        self.set_hexpand(True)
        self.set_name('ItemsViewBox')

        self._bound_history = None
        self._last_entered_item = None
        self._last_selected_index = None
        self._show_index = None
        self._autoscroll_timeout_id = 0

        self._histories_manager = HistoriesManager()

        placeholder = Gtk.Label()
        placeholder.set_markup('<span font-size="xx-large">%s</span>' %
                               _('Nothing'))
        placeholder.show()

        self._listbox = Gtk.ListBox()
        self._listbox.set_name('ItemsViewList')
        self._listbox.set_selection_mode(Gtk.SelectionMode.MULTIPLE)
        self._listbox.set_activate_on_single_click(False)
        self._listbox.set_placeholder(placeholder)
        self._listbox.connect('row-selected', self._on_row_selected)
        self._listbox.connect('row-activated', self._on_row_activated)
        self._listbox.connect('motion-notify-event', self._on_motion_event)
        self._listbox.connect('leave-notify-event', self._on_leave_event)
        self._listbox.connect('button-press-event',
                              self._on_button_press_event)
        self._listbox.connect('button-release-event',
                              self._on_button_release_event)

        self._items_counter = ItemsCounter(self._listbox)
        self._load_rest_btn = Gtk.LinkButton()
        self._load_rest_btn.set_label('load all history')
        self._load_rest_btn.set_no_show_all(True)
        self._load_rest_btn.connect('activate-link',
                                    lambda _: self.load_rest_items())
        self._load_rest_btn.hide()

        scrolled = Gtk.ScrolledWindow()
        scrolled.set_name('ItemsViewScrolledWindow')
        scrolled.set_vexpand(True)
        scrolled.set_hexpand(True)
        scrolled.add(self._listbox)

        bottom_box = Gtk.Box()
        bottom_box.set_orientation(Gtk.Orientation.HORIZONTAL)
        bottom_box.add(self._items_counter)
        bottom_box.add(self._load_rest_btn)
        bottom_box.add(self._histories_manager)

        box = Gtk.Box()
        box.set_orientation(Gtk.Orientation.VERTICAL)
        box.add(scrolled)
        box.add(bottom_box)

        self.add(box)
        self.show_all()