def test_app_store(self):
        # get a enquire object
        enquirer = AppEnquire(self.cache, self.db)
        enquirer.set_query(xapian.Query(""))

        # get a AppListStore and run functions on it
        model = AppListStore(self.db, self.cache, self.icons)

        # test if set from matches works
        self.assertEqual(len(model), 0)
        model.set_from_matches(enquirer.matches)
        self.assertTrue(len(model) > 0)
        # ensure the first row has a xapian doc type
        self.assertEqual(type(model[0][0]), xapian.Document)
        # lazy loading of the docs
        self.assertEqual(model[100][0], None)

        # test the load range stuff
        model.load_range(indices=[100], step=15)
        self.assertEqual(type(model[100][0]), xapian.Document)

        # ensure buffer_icons works and loads stuff into the cache
        model.buffer_icons()
        self.assertEqual(len(model.icon_cache), 0)
        while Gtk.events_pending():
            Gtk.main_iteration()
        self.assertTrue(len(model.icon_cache) > 0)

        # ensure clear works
        model.clear()
        self.assertEqual(model.current_matches, None)
 def test_lp872760(self):
     def monkey_(s):
         translations = { 
             "Painting & Editing" : "translation for Painting & "
                                        "Editing",
         }
         return translations.get(s, s)
     with patch("softwarecenter.ui.gtk3.models.appstore2._", new=monkey_):
         model = AppListStore(self.db, self.cache, self.icons)
         untranslated = "Painting & Editing"
         translated = model._category_translate(untranslated)
         self.assertNotEqual(untranslated, translated)
Exemplo n.º 3
0
def get_test_window():
    from softwarecenter.testutils import (get_test_db, get_test_pkg_info,
                                          get_test_gtk3_icon_cache,
                                          get_test_enquirer_matches)
    from softwarecenter.ui.gtk3.models.appstore2 import AppListStore

    db = get_test_db()
    cache = get_test_pkg_info()
    icons = get_test_gtk3_icon_cache()

    # create the view
    appview = AppView(db, cache, icons, show_ratings=True)
    liststore = AppListStore(db, cache, icons)
    appview.set_model(liststore)

    # do a simple query and display that
    appview.display_matches(get_test_enquirer_matches(db))

    # and put it in the window
    win = Gtk.Window()
    win.add(appview)
    win.set_data("appview", appview)

    win.connect("destroy", lambda x: Gtk.main_quit())
    win.set_size_request(600, 400)
    win.show_all()

    return win
Exemplo n.º 4
0
def get_test_window():
    import softwarecenter.log
    softwarecenter.log.root.setLevel(level=logging.DEBUG)
    softwarecenter.log.add_filters_from_string("performance")
    fmt = logging.Formatter("%(name)s - %(message)s", None)
    softwarecenter.log.handler.setFormatter(fmt)

    from softwarecenter.paths import XAPIAN_BASE_PATH
    xapian_base_path = XAPIAN_BASE_PATH
    pathname = os.path.join(xapian_base_path, "xapian")

    # the store
    from softwarecenter.db.pkginfo import get_pkg_info
    cache = get_pkg_info()
    cache.open()

    # the db
    from softwarecenter.db.database import StoreDatabase
    db = StoreDatabase(pathname, cache)
    db.open()

    # additional icons come from app-install-data
    icons = Gtk.IconTheme.get_default()
    icons.prepend_search_path("/usr/share/app-install/icons/")
    icons.prepend_search_path("/usr/share/software-center/icons/")

    # create a filter
    from softwarecenter.db.appfilter import AppFilter
    filter = AppFilter(db, cache)
    filter.set_supported_only(False)
    filter.set_installed_only(True)

    # appview
    from softwarecenter.ui.gtk3.models.appstore2 import AppListStore
    from softwarecenter.db.enquire import AppEnquire
    enquirer = AppEnquire(cache, db)
    store = AppListStore(db, cache, icons)

    from softwarecenter.ui.gtk3.views.appview import AppView
    view = AppView(db, cache, icons, show_ratings=True)
    view.set_model(store)

    entry = Gtk.Entry()
    entry.stamp = 0
    entry.connect("changed", on_entry_changed, (view, enquirer))
    entry.set_text("gtk3")

    scroll = Gtk.ScrolledWindow()
    box = Gtk.VBox()
    box.pack_start(entry, False, True, 0)
    box.pack_start(scroll, True, True, 0)

    win = Gtk.Window()
    win.connect("destroy", lambda x: Gtk.main_quit())
    scroll.add(view)
    win.add(box)
    win.set_size_request(600, 400)
    win.show_all()

    return win
def get_test_window():
    import softwarecenter.log
    softwarecenter.log.root.setLevel(level=logging.DEBUG)
    softwarecenter.log.add_filters_from_string("performance")
    fmt = logging.Formatter("%(name)s - %(message)s", None)
    softwarecenter.log.handler.setFormatter(fmt)

    from softwarecenter.testutils import (get_test_db, get_test_pkg_info,
                                          get_test_gtk3_icon_cache)
    from softwarecenter.ui.gtk3.models.appstore2 import AppListStore

    db = get_test_db()
    cache = get_test_pkg_info()
    icons = get_test_gtk3_icon_cache()

    # create a filter
    from softwarecenter.db.appfilter import AppFilter
    filter = AppFilter(db, cache)
    filter.set_supported_only(False)
    filter.set_installed_only(True)

    # appview
    from softwarecenter.db.enquire import AppEnquire
    enquirer = AppEnquire(cache, db)
    store = AppListStore(db, cache, icons)

    from softwarecenter.ui.gtk3.views.appview import AppView
    view = AppView(db, cache, icons, show_ratings=True)
    view.set_model(store)

    entry = Gtk.Entry()
    entry.stamp = 0
    entry.connect("changed", on_entry_changed, (view, enquirer))

    box = Gtk.VBox()
    box.pack_start(entry, False, True, 0)
    box.pack_start(view, True, True, 0)

    win = Gtk.Window()
    win.set_data("appview", view)
    win.set_data("entry", entry)
    win.connect("destroy", lambda x: Gtk.main_quit())
    win.add(box)
    win.set_size_request(600, 400)
    win.show_all()

    return win
    def init_view(self):
        if self.view_initialized:
            return

        self.show_appview_spinner()

        window = self.get_window()
        if window is not None:
            window.set_cursor(self.busy_cursor)

        while Gtk.events_pending():
            Gtk.main_iteration()

        SoftwarePane.init_view(self)
        # set the AppTreeView model, available pane uses list models
        liststore = AppListStore(self.db, self.cache, self.icons)
        #~ def on_appcount_changed(widget, appcount):
        #~ self.subcategories_view._append_appcount(appcount)
        #~ self.app_view._append_appcount(appcount)
        #~ liststore.connect('appcount-changed', on_appcount_changed)
        self.app_view.set_model(liststore)
        liststore.connect("needs-refresh",
                          lambda helper, pkgname: self.app_view.queue_draw())

        # purchase view
        self.purchase_view = PurchaseView()
        app_manager = get_appmanager()
        app_manager.connect("purchase-requested", self.on_purchase_requested)
        self.purchase_view.connect("purchase-succeeded",
                                   self.on_purchase_succeeded)
        self.purchase_view.connect("purchase-failed", self.on_purchase_failed)
        self.purchase_view.connect("purchase-cancelled-by-user",
                                   self.on_purchase_cancelled_by_user)
        self.purchase_view.connect("terms-of-service-declined",
                                   self.on_terms_of_service_declined)
        self.purchase_view.connect("purchase-needs-spinner",
                                   self.on_purchase_needs_spinner)

        # categories, appview and details into the notebook in the bottom
        self.scroll_categories = Gtk.ScrolledWindow()
        self.scroll_categories.set_policy(Gtk.PolicyType.AUTOMATIC,
                                          Gtk.PolicyType.AUTOMATIC)
        self.cat_view = LobbyViewGtk(self.datadir, APP_INSTALL_PATH,
                                     self.cache, self.db, self.icons,
                                     self.apps_filter)
        self.scroll_categories.add(self.cat_view)
        self.notebook.append_page(self.scroll_categories,
                                  Gtk.Label(label="categories"))

        # sub-categories view
        self.subcategories_view = SubCategoryViewGtk(
            self.datadir,
            APP_INSTALL_PATH,
            self.cache,
            self.db,
            self.icons,
            self.apps_filter,
            root_category=self.cat_view.categories[0])
        self.subcategories_view.connect("category-selected",
                                        self.on_subcategory_activated)
        self.subcategories_view.connect("application-activated",
                                        self.on_application_activated)
        self.subcategories_view.connect("show-category-applist",
                                        self.on_show_category_applist)
        # FIXME: why do we have two application-{selected,activated] ?!?
        self.subcategories_view.connect("application-selected",
                                        self.on_application_selected)
        self.subcategories_view.connect("application-activated",
                                        self.on_application_activated)
        self.scroll_subcategories = Gtk.ScrolledWindow()
        self.scroll_subcategories.set_policy(Gtk.PolicyType.AUTOMATIC,
                                             Gtk.PolicyType.AUTOMATIC)
        self.scroll_subcategories.add(self.subcategories_view)
        self.notebook.append_page(self.scroll_subcategories,
                                  Gtk.Label(label=NavButtons.SUBCAT))

        # app list
        self.notebook.append_page(self.box_app_list,
                                  Gtk.Label(label=NavButtons.LIST))

        self.cat_view.connect("category-selected", self.on_category_activated)
        self.cat_view.connect("application-selected",
                              self.on_application_selected)
        self.cat_view.connect("application-activated",
                              self.on_application_activated)

        # details
        self.notebook.append_page(self.scroll_details,
                                  Gtk.Label(label=NavButtons.DETAILS))

        # purchase view
        self.notebook.append_page(self.purchase_view,
                                  Gtk.Label(label=NavButtons.PURCHASE))

        # install backend
        self.backend.connect("transaction-started",
                             self.on_transaction_started)
        self.backend.connect("transactions-changed",
                             self.on_transactions_changed)
        self.backend.connect("transaction-finished",
                             self.on_transaction_complete)
        self.backend.connect("transaction-cancelled",
                             self.on_transaction_cancelled)
        # a transaction error is treated the same as a cancellation
        self.backend.connect("transaction-stopped",
                             self.on_transaction_cancelled)

        # now we are initialized
        self.searchentry.set_sensitive(True)
        self.emit("available-pane-created")
        self.show_all()
        self.hide_appview_spinner()

        # consider the view initialized here already as display_page()
        # may run into a endless recurison otherwise (it will call init_view())
        # again (LP: #851671)
        self.view_initialized = True

        # important to "seed" the initial history stack (LP: #1005104)
        vm = get_viewmanager()
        vm.display_page(self, AvailablePane.Pages.LOBBY, self.state,
                        self.display_lobby_page)

        if window is not None:
            window.set_cursor(None)
 def test_lp971776(self):
     """ ensure that refresh is not called for invalid image files """
     model = AppListStore(self.db, self.cache, self.icons)
     model.emit = Mock()
     model._on_image_download_complete(None, "xxx", "software-center")
     self.assertFalse(model.emit.called)
Exemplo n.º 8
0
    def init_view(self):
        if self.view_initialized:
            return

        self.show_appview_spinner()

        window = self.get_window()
        if window is not None:
            window.set_cursor(self.busy_cursor)

        while Gtk.events_pending():
            Gtk.main_iteration()

        SoftwarePane.init_view(self)
        # set the AppTreeView model, available pane uses list models
        liststore = AppListStore(self.db, self.cache, self.icons)
        #~ def on_appcount_changed(widget, appcount):
            #~ self.subcategories_view._append_appcount(appcount)
            #~ self.app_view._append_appcount(appcount)
        #~ liststore.connect('appcount-changed', on_appcount_changed)
        self.app_view.set_model(liststore)
        liststore.connect("needs-refresh",
            lambda helper, pkgname: self.app_view.queue_draw())

        # purchase view
        self.purchase_view = PurchaseView()
        app_manager = get_appmanager()
        app_manager.connect("purchase-requested",
            self.on_purchase_requested)
        self.purchase_view.connect("purchase-succeeded",
            self.on_purchase_succeeded)
        self.purchase_view.connect("purchase-failed",
            self.on_purchase_failed)
        self.purchase_view.connect("purchase-cancelled-by-user",
            self.on_purchase_cancelled_by_user)
        self.purchase_view.connect("terms-of-service-declined",
            self.on_terms_of_service_declined)
        self.purchase_view.connect("purchase-needs-spinner",
            self.on_purchase_needs_spinner)

        # categories, appview and details into the notebook in the bottom
        self.scroll_categories = Gtk.ScrolledWindow()
        self.scroll_categories.set_policy(Gtk.PolicyType.AUTOMATIC,
                                        Gtk.PolicyType.AUTOMATIC)
        self.cat_view = LobbyViewGtk(self.datadir, APP_INSTALL_PATH,
                                       self.cache,
                                       self.db,
                                       self.icons,
                                       self.apps_filter)
        self.scroll_categories.add(self.cat_view)
        self.notebook.append_page(self.scroll_categories,
            Gtk.Label(label="categories"))

        # sub-categories view
        self.subcategories_view = SubCategoryViewGtk(self.datadir,
            APP_INSTALL_PATH,
            self.cache,
            self.db,
            self.icons,
            self.apps_filter,
            root_category=self.cat_view.categories[0])
        self.subcategories_view.connect(
            "category-selected", self.on_subcategory_activated)
        self.subcategories_view.connect(
            "application-activated", self.on_application_activated)
        self.subcategories_view.connect(
            "show-category-applist", self.on_show_category_applist)
        # FIXME: why do we have two application-{selected,activated] ?!?
        self.subcategories_view.connect(
            "application-selected", self.on_application_selected)
        self.subcategories_view.connect(
            "application-activated", self.on_application_activated)
        self.scroll_subcategories = Gtk.ScrolledWindow()
        self.scroll_subcategories.set_policy(
            Gtk.PolicyType.AUTOMATIC, Gtk.PolicyType.AUTOMATIC)
        self.scroll_subcategories.add(self.subcategories_view)
        self.notebook.append_page(self.scroll_subcategories,
                                    Gtk.Label(label=NavButtons.SUBCAT))

        # app list
        self.notebook.append_page(self.box_app_list,
                                    Gtk.Label(label=NavButtons.LIST))

        self.cat_view.connect(
            "category-selected", self.on_category_activated)
        self.cat_view.connect(
            "application-selected", self.on_application_selected)
        self.cat_view.connect(
            "application-activated", self.on_application_activated)

        # details
        self.notebook.append_page(self.scroll_details,
            Gtk.Label(label=NavButtons.DETAILS))

        # purchase view
        self.notebook.append_page(self.purchase_view,
            Gtk.Label(label=NavButtons.PURCHASE))

        # install backend
        self.backend.connect("transaction-started",
            self.on_transaction_started)
        self.backend.connect("transactions-changed",
            self.on_transactions_changed)
        self.backend.connect("transaction-finished",
            self.on_transaction_complete)
        self.backend.connect("transaction-stopped",
            self.on_transaction_complete)

        # now we are initialized
        self.searchentry.set_sensitive(True)
        self.emit("available-pane-created")
        self.show_all()
        self.hide_appview_spinner()

        # consider the view initialized here already as display_page()
        # may run into a endless recurison otherwise (it will call init_view())
        # again (LP: #851671)
        self.view_initialized = True

        if window is not None:
            window.set_cursor(None)