Ejemplo n.º 1
0
def test_sort():
    ls = [1, 7, 4, 6, 15, 0, 8, 2, 4]
    lv = ListView(ls, lambda x: (1 < x < 4) or (7 > x > 4) or (x > 10))
    assert list(lv) == [6, 15, 2]
    lv.sort()
    assert list(lv) == [2, 6, 15]
    assert ls == [1, 7, 4, 2, 6, 0, 8, 15, 4]
Ejemplo n.º 2
0
def test_getitem_slice():
    ls = [1, 2, 3, 4, 5, 6, 7]
    lv = ListView(ls, lambda x: (1 < x < 4) or (7 > x > 4) or (x > 10))
    # lv: [2, 3, 5, 6]

    assert lv[:] == [2, 3, 5, 6]
    assert lv[1:] == [3, 5, 6]
 def __init__(self):
     self.one_close = app_theme.get_pixbuf("treeview/1-close.png")
     self.one_open = app_theme.get_pixbuf("treeview/1-open.png")
     self.two_close = app_theme.get_pixbuf("treeview/2-close.png")
     self.two_open = app_theme.get_pixbuf("treeview/2-open.png")
     self.three_close = app_theme.get_pixbuf("treeview/3-close.png")
     self.three_open = app_theme.get_pixbuf("treeview/3-open.png")
     #
     self.tree_view_open = app_theme.get_pixbuf("treeview/open.png")
     self.tree_view_close = app_theme.get_pixbuf("treeview/close.png")
     self.tree_view_right = app_theme.get_pixbuf("treeview/right.png")
     self.tree_view_bottom = app_theme.get_pixbuf("treeview/bottom.png")
     #
     self.listview_color = ui_theme.get_color("scrolledbar")
     self.play_list_vbox = gtk.VBox()
     #
     self.list_view_vbox = gtk.VBox()
     self.list_scroll_win = ScrolledWindow(0, 0)
     self.list_scroll_win.set_policy(gtk.POLICY_NEVER, gtk.POLICY_ALWAYS)
     self.list_view = ListView()
     #
     self.play_list_con = PlayListControl()
     #
     self.list_view_vbox.pack_start(self.list_scroll_win, True, True)
     self.list_view_vbox.pack_start(self.play_list_con, False, False)
     # 网络列表,搜索框.
     self.tree_scroll_win = ScrolledWindow(0, 0)
     self.tree_scroll_win.set_policy(gtk.POLICY_NEVER, gtk.POLICY_ALWAYS)
     self.tree_view_vbox = gtk.VBox()
     self.tree_view = TreeViewBase()
     self.search_ali = gtk.Alignment(0, 0, 1, 1)
     self.search = Search()
     self.search_ali.add(self.search)
     #
     self.search_ali.set_padding(7, 5, 12, 12)
     self.tree_view_vbox.pack_start(self.search_ali, False, False)
     self.tree_view_vbox.pack_start(self.tree_scroll_win, True, True)
     self.search_ali.connect("expose-event", self.search_ali_expose_event)
     #
     self.note_book = NoteBook()
     #
     self.list_view.on_draw_sub_item = self.__listview_on_draw_sub_item
     self.list_view.columns.add_range(["filename", "time"])
     self.list_view.columns[0].width = 120
     self.list_view.columns[1].width = 95
     #
     self.note_book.hide_title()
     self.tree_view.paint_nodes_event = self.__treeview_paint_nodes_event
     #
     self.list_scroll_win.add_with_viewport(self.list_view)
     self.tree_scroll_win.add_with_viewport(self.tree_view)
     #self.note_book.add_layout1(self.list_scroll_win)
     self.note_book.add_layout1(self.list_view_vbox)
     self.note_book.add_layout2(self.tree_view_vbox)
     #self.play_list_vbox.pack_start(self.scroll_win, True, True)
     self.play_list_vbox.pack_start(self.note_book, True, True)
Ejemplo n.º 4
0
def test_getitem_int():
    ls = [1, 2, 3, 4, 5, 6, 7]
    lv = ListView(ls, lambda x: (1 < x < 4) or (7 > x > 4) or (x > 10))
    # lv: [2, 3, 5, 6]

    # normal
    assert lv[2] == 5
    # out of range
    with pytest.raises(IndexError):
        print(lv[7])
Ejemplo n.º 5
0
def test_delitem_slice():
    ls = [1, 2, 3, 4, 5, 6, 7]
    lv = ListView(ls, lambda x: (1 < x < 4) or (7 > x > 4) or (x > 10))
    # lv: [2, 3, 5, 6]

    del lv[1:]
    assert list(lv) == [2]
    assert ls == [1, 2, 4, 7]

    del lv[:]
    assert list(lv) == []
    assert ls == [1, 4, 7]
Ejemplo n.º 6
0
def test_delitem_int():
    ls = [1, 2, 3, 4, 5, 6, 7]
    lv = ListView(ls, lambda x: (1 < x < 4) or (7 > x > 4) or (x > 10))
    # lv: [2, 3, 5, 6]

    # normal
    del lv[2]
    assert list(lv) == [2, 3, 6]
    assert ls == [1, 2, 3, 4, 6, 7]

    # out of range
    with pytest.raises(IndexError):
        del lv[7]
Ejemplo n.º 7
0
def test_setitem_slice():
    ls = [1, 2, 3, 4, 5, 6, 7]
    lv = ListView(ls, lambda x: (1 < x < 4) or (7 > x > 4) or (x > 10))
    # lv: [2, 3, 5, 6]

    # normal
    lv[1:] = [15, 18, 21]
    assert list(lv) == [2, 15, 18, 21]
    assert ls == [1, 2, 15, 4, 18, 21, 7]

    # out of range
    with pytest.raises(IndexError):
        lv[4] = 100

    lv[:] = [18]
    assert list(lv) == [18]
    assert ls == [1, 18, 4, 7]
Ejemplo n.º 8
0
def test_setitem_int():
    ls = [1, 2, 3, 4, 5, 6, 7]
    lv = ListView(ls, lambda x: (1 < x < 4) or (7 > x > 4) or (x > 10))
    # lv: [2, 3, 5, 6]

    # normal
    lv[3] = 15
    assert list(lv) == [2, 3, 5, 15]
    assert ls == [1, 2, 3, 4, 5, 15, 7]

    # out of range
    with pytest.raises(IndexError):
        lv[4] = 100

    lv[-2] = 18
    assert list(lv) == [2, 3, 18, 15]
    assert ls == [1, 2, 3, 4, 18, 15, 7]
Ejemplo n.º 9
0
def test_insert():
    ls = [1, 2, 3, 4, 5, 6, 7]
    lv = ListView(ls, lambda x: (1 < x < 4) or (7 > x > 4))
    assert list(lv) == [2, 3, 5, 6]

    # unmatch value error
    with pytest.raises(ValueError):
        lv.insert(3, 999)
    assert ls == [1, 2, 3, 4, 5, 6, 7]
    assert list(lv) == [2, 3, 5, 6]

    # matched value error
    lv.insert(3, 5.5)
    assert ls == [1, 2, 3, 4, 5, 5.5, 6, 7]
    assert list(lv) == [2, 3, 5, 5.5, 6]

    lv.insert(0, 4.5)
    assert ls == [1, 4.5, 2, 3, 4, 5, 5.5, 6, 7]
    assert list(lv) == [4.5, 2, 3, 5, 5.5, 6]

    lv.insert(1000, 3.5)
    assert ls == [1, 4.5, 2, 3, 4, 5, 5.5, 6, 7, 3.5]
    assert list(lv) == [4.5, 2, 3, 5, 5.5, 6, 3.5]
Ejemplo n.º 10
0
    def _create_controls(self):
        self._download_content_length = 0
        self._download_content_type = None

        self.msg_label = Gtk.Label()

        self.list_box = Gtk.Box(orientation=Gtk.Orientation.HORIZONTAL)

        # Catalogs treeview
        self.catalog_listview = Gtk.TreeView()
        self.catalog_listview.headers_clickble = True
        self.catalog_listview.hover_expand = True
        self.catalog_listview.rules_hint = True
        self._catalog_changed_id = self.catalog_listview.connect(
            'row-activated', self.move_down_catalog)
        self.catalog_listview.set_activate_on_single_click(True)
        self.catalog_listview.set_enable_search(False)

        self.treemodel = Gtk.ListStore(str)
        self.treemodel.set_sort_column_id(0, Gtk.SortType.ASCENDING)
        self.catalog_listview.set_model(self.treemodel)

        renderer = Gtk.CellRendererText()
        renderer.set_property('wrap-mode', Pango.WrapMode.WORD)
        self.treecol = Gtk.TreeViewColumn(_('Catalogs'), renderer, text=0)
        self.treecol.set_property('clickable', True)
        self.treecol.connect('clicked', self.move_up_catalog)
        self.catalog_listview.append_column(self.treecol)
        self.bt_move_up_catalog = ButtonWithImage(_('Catalogs'))
        self.bt_move_up_catalog.hide_image()
        self.treecol.set_widget(self.bt_move_up_catalog)

        self.load_source_catalogs()

        self.tree_scroller = Gtk.ScrolledWindow(hadjustment=None,
                                                vadjustment=None)
        self.tree_scroller.set_policy(Gtk.PolicyType.NEVER,
                                      Gtk.PolicyType.AUTOMATIC)
        self.tree_scroller.add(self.catalog_listview)
        self.list_box.pack_start(self.tree_scroller,
                                 expand=False,
                                 fill=False,
                                 padding=0)
        self.separa = Gtk.VSeparator()
        self.list_box.pack_start(self.separa,
                                 expand=False,
                                 fill=False,
                                 padding=0)

        # books listview
        self.listview = ListView(self._lang_code_handler)
        self.selection_cb_id = self.listview.connect('selection-changed',
                                                     self.selection_cb)
        self.listview.set_enable_search(False)

        self.list_scroller = Gtk.ScrolledWindow(hadjustment=None,
                                                vadjustment=None)
        self.list_scroller.set_policy(Gtk.PolicyType.AUTOMATIC,
                                      Gtk.PolicyType.AUTOMATIC)
        vadjustment = self.list_scroller.get_vadjustment()
        vadjustment.connect('value-changed',
                            self.__vadjustment_value_changed_cb)
        self.list_scroller.add(self.listview)
        self.list_box.pack_start(self.list_scroller,
                                 expand=True,
                                 fill=True,
                                 padding=0)

        self.scrolled = Gtk.ScrolledWindow()
        self.scrolled.set_policy(Gtk.PolicyType.NEVER,
                                 Gtk.PolicyType.AUTOMATIC)
        self.scrolled.props.shadow_type = Gtk.ShadowType.NONE
        self.textview = Gtk.TextView()
        self.textview.set_editable(False)
        self.textview.set_cursor_visible(False)
        self.textview.set_wrap_mode(Gtk.WrapMode.WORD)
        self.textview.set_justification(Gtk.Justification.LEFT)
        self.textview.set_left_margin(20)
        self.textview.set_right_margin(20)
        self.scrolled.add(self.textview)
        self.list_box.show_all()
        self.separa.hide()
        self.tree_scroller.hide()

        vbox_download = Gtk.Box(orientation=Gtk.Orientation.VERTICAL)

        hbox_format = Gtk.Box(orientation=Gtk.Orientation.HORIZONTAL)
        format_label = Gtk.Label(label=_('Format:'))
        self.format_combo = ComboBox()
        for key in _MIMETYPES.keys():
            self.format_combo.append_item(_MIMETYPES[key], key)
        self.format_combo.set_active(0)
        self.format_combo.props.sensitive = False
        self.__format_changed_cb_id = \
                self.format_combo.connect('changed', self.__format_changed_cb)

        hbox_format.pack_start(format_label, False, False, 10)
        hbox_format.pack_start(self.format_combo, False, False, 10)
        vbox_download.pack_start(hbox_format, False, False, 10)

        self._download = Gtk.Button(_('Get Book'))
        self._download.set_image(Icon(icon_name='data-download'))
        self._download.props.sensitive = False
        self._download.connect('clicked', self.__get_book_cb)
        vbox_download.pack_start(self._download, False, False, 10)

        self.progressbox = Gtk.Box(spacing=20,
                                   orientation=Gtk.Orientation.HORIZONTAL)
        self.progressbar = Gtk.ProgressBar()
        self.progressbar.set_fraction(0.0)
        self.progressbox.pack_start(self.progressbar,
                                    expand=True,
                                    fill=True,
                                    padding=0)
        self.cancel_btn = Gtk.Button(stock=Gtk.STOCK_CANCEL)
        self.cancel_btn.set_image(Icon(icon_name='dialog-cancel'))
        self.cancel_btn.connect('clicked', self.__cancel_btn_clicked_cb)
        self.progressbox.pack_start(self.cancel_btn,
                                    expand=False,
                                    fill=False,
                                    padding=0)
        vbox_download.pack_start(self.progressbox, False, False, 10)

        bottom_hbox = Gtk.Box(orientation=Gtk.Orientation.HORIZONTAL)

        if self.show_images:
            self.__image_downloader = None
            self.image = Gtk.Image()
            self.add_default_image()
            bottom_hbox.pack_start(self.image, False, False, 10)
        bottom_hbox.pack_start(self.scrolled, True, True, 10)
        bottom_hbox.pack_start(vbox_download, False, False, 10)
        bottom_hbox.show_all()

        vbox = Gtk.Box(orientation=Gtk.Orientation.VERTICAL)
        vbox.pack_start(self.msg_label, False, False, 10)
        vbox.pack_start(self.list_box, True, True, 0)
        vbox.pack_start(bottom_hbox, False, False, 10)
        self.set_canvas(vbox)
        self.listview.show()
        vbox.show()
        self.list_scroller.show()
        self.progress_hide()
        self.show_message(
            _('Enter words from the Author or Title to begin search.'))

        self._books_toolbar.search_entry.grab_focus()
        if len(self.catalogs) > 0:
            self.bt_catalogs.set_active(True)
Ejemplo n.º 11
0
def test_len():
    ls = [1, 2, 3, 4, 5]
    lv = ListView(ls, lambda x: 1 < x < 5)
    assert list(lv) == [2, 3, 4]
    assert len(lv) == 3
Ejemplo n.º 12
0
def test_all_methods_added():
    dv = set(dir(ListView(None, None)))
    for k in dir([]):
        assert k in dv