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 _run_channel_enquirer(self, persistent_duplicate_filter=True): xfilter = AppFilter(self.db, self.cache) xfilter.set_installed_only(True) if self.state.channel: self.enquirer.set_query( self.state.channel.query, sortmode=SortMethods.BY_ALPHABET, nonapps_visible=NonAppVisibility.MAYBE_VISIBLE, filter=xfilter, nonblocking_load=False, persistent_duplicate_filter=persistent_duplicate_filter)
def _do_search(self, terms): self.state.search_term = terms xfilter = AppFilter(self.db, self.cache) xfilter.set_installed_only(True) self.enquirer.set_query( self.get_query(), nonapps_visible=self.nonapps_visible, filter=xfilter, nonblocking_load=True ) self.visible_docids = self.enquirer.get_docids() self.visible_cats = self._get_vis_cats(self.visible_docids) self.treefilter.refilter() self.app_view.tree_view.expand_all()
def _do_search(self, terms): self.state.search_term = terms xfilter = AppFilter(self.db, self.cache) xfilter.set_installed_only(True) self.enquirer.set_query(self.get_query(), nonapps_visible=self.nonapps_visible, filter=xfilter, nonblocking_load=True) self.visible_docids = self.enquirer.get_docids() self.visible_cats = self._get_vis_cats(self.visible_docids) self.treefilter.refilter() self.app_view.tree_view.expand_all()
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, get_test_categories) cache = get_test_pkg_info() db = get_test_db() 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) # get the TREEstore from softwarecenter.ui.gtk3.models.appstore2 import AppTreeStore store = AppTreeStore(db, cache, icons) # populate from data cats = get_test_categories(db) for cat in cats[:3]: with ExecutionTime("query cat '%s'" % cat.name): docs = db.get_docs_from_query(cat.query) store.set_category_documents(cat, docs) # ok, this is confusing - the AppView contains the AppTreeView that # is a tree or list depending on the model from softwarecenter.ui.gtk3.views.appview import AppView app_view = AppView(db, cache, icons, show_ratings=True) app_view.set_model(store) box = Gtk.VBox() box.pack_start(app_view, True, True, 0) win = Gtk.Window() win.add(box) win.connect("destroy", lambda x: Gtk.main_quit()) 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, get_test_categories) cache = get_test_pkg_info() db = get_test_db() 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) # get the TREEstore from softwarecenter.ui.gtk3.models.appstore2 import AppTreeStore store = AppTreeStore(db, cache, icons) # populate from data cats = get_test_categories(db) for cat in cats[:3]: with ExecutionTime("query cat '%s'" % cat.name): docs = db.get_docs_from_query(cat.query) store.set_category_documents(cat, docs) # ok, this is confusing - the AppView contains the AppTreeView that # is a tree or list depending on the model from softwarecenter.ui.gtk3.views.appview import AppView app_view = AppView(db, cache, icons, show_ratings=True) app_view.set_model(store) box = Gtk.VBox() box.pack_start(app_view, True, True, 0) win = Gtk.Window() win.add(box) win.connect("destroy", lambda x: Gtk.main_quit()) 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 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 rebuild_oneconfview(): # FIXME for P: hide the search entry self.searchentry.hide() self.cat_docid_map = {} enq = self.enquirer query = xapian.Query("") if self.state.channel and self.state.channel.query: query = xapian.Query(xapian.Query.OP_AND, query, self.state.channel.query) i = 0 # First search: missing apps only xfilter = AppFilter(self.db, self.cache) xfilter.set_restricted_list(self.oneconf_additional_pkg) xfilter.set_not_installed_only(True) enq.set_query( query, sortmode=SortMethods.BY_ALPHABET, nonapps_visible=self.nonapps_visible, filter=xfilter, nonblocking_load=True, # we don't block this one for # better oneconf responsiveness persistent_duplicate_filter=(i > 0), ) L = len(enq.matches) if L: cat_title = utf8( ngettext( u"%(amount)s item on “%(machine)s” not on this computer", u"%(amount)s items on “%(machine)s” not on this computer", L, ) ) % {"amount": L, "machine": utf8(self.current_hostname)} i += L docs = enq.get_documents() self.cat_docid_map["missingpkg"] = set([doc.get_docid() for doc in docs]) model.set_nocategory_documents(docs, untranslated_name="additionalpkg", display_name=cat_title) # Second search: additional apps xfilter.set_restricted_list(self.oneconf_missing_pkg) xfilter.set_not_installed_only(False) xfilter.set_installed_only(True) enq.set_query( query, sortmode=SortMethods.BY_ALPHABET, nonapps_visible=self.nonapps_visible, filter=xfilter, nonblocking_load=False, persistent_duplicate_filter=(i > 0), ) L = len(enq.matches) if L: cat_title = utf8( ngettext( u"%(amount)s item on this computer not on “%(machine)s”", "%(amount)s items on this computer not on “%(machine)s”", L, ) ) % {"amount": L, "machine": utf8(self.current_hostname)} i += L docs = enq.get_documents() self.cat_docid_map["additionalpkg"] = set([doc.get_docid() for doc in docs]) model.set_nocategory_documents(docs, untranslated_name="additionalpkg", display_name=cat_title) if i: self.app_view.tree_view.set_cursor(Gtk.TreePath(), None, False) if i <= 10: self.app_view.tree_view.expand_all() # cache the installed app count self.installed_count = i self.app_view._append_appcount(self.installed_count, mode=AppView.DIFF_MODE) self.app_view.set_model(self.treefilter) if keep_state: self._restore_treeview_state(treeview_state) # hide the local spinner self.hide_installed_view_spinner() if window: window.set_cursor(None) self.emit("app-list-changed", i) return
def rebuild_categorised_view(): self.cat_docid_map = {} enq = self.enquirer i = 0 while Gtk.events_pending(): Gtk.main_iteration() xfilter = AppFilter(self.db, self.cache) xfilter.set_installed_only(True) for cat in self._all_cats: # for each category do category query and append as a new # node to tree_view if not self._use_category(cat): continue query = self.get_query_for_cat(cat) LOG.debug("xfilter.installed_only: %s" % xfilter.installed_only) enq.set_query( query, sortmode=SortMethods.BY_ALPHABET, nonapps_visible=self.nonapps_visible, filter=xfilter, nonblocking_load=False, persistent_duplicate_filter=(i > 0), ) L = len(enq.matches) if L: i += L docs = enq.get_documents() self.cat_docid_map[cat.untranslated_name] = set([doc.get_docid() for doc in docs]) model.set_category_documents(cat, docs) while Gtk.events_pending(): Gtk.main_iteration() # check for uncategorised pkgs if self.state.channel: self._run_channel_enquirer(persistent_duplicate_filter=(i > 0)) L = len(enq.matches) if L: # some foo for channels # if no categorised results but in channel, then use # the channel name for the category channel_name = None if not i and self.state.channel: channel_name = self.state.channel.display_name docs = enq.get_documents() tag = channel_name or "Uncategorized" self.cat_docid_map[tag] = set([doc.get_docid() for doc in docs]) model.set_nocategory_documents(docs, untranslated_name=tag, display_name=channel_name) i += L if i: self.app_view.tree_view.set_cursor(Gtk.TreePath(), None, False) if i <= 10: self.app_view.tree_view.expand_all() # cache the installed app count self.installed_count = i self.app_view._append_appcount(self.installed_count, mode=AppView.INSTALLED_MODE) self.app_view.set_model(self.treefilter) if keep_state: self._restore_treeview_state(treeview_state) # hide the local spinner self.hide_installed_view_spinner() if window: window.set_cursor(None) # reapply search if needed if self.state.search_term: self._do_search(self.state.search_term) self.emit("app-list-changed", i) return
def rebuild_oneconfview(): # FIXME for P: hide the search entry self.searchentry.hide() self.cat_docid_map = {} enq = self.enquirer query = xapian.Query("") if self.state.channel and self.state.channel.query: query = xapian.Query(xapian.Query.OP_AND, query, self.state.channel.query) i = 0 # First search: missing apps only xfilter = AppFilter(self.db, self.cache) xfilter.set_restricted_list(self.oneconf_additional_pkg) xfilter.set_not_installed_only(True) enq.set_query( query, sortmode=SortMethods.BY_ALPHABET, nonapps_visible=self.nonapps_visible, filter=xfilter, nonblocking_load=True, # we don't block this one for # better oneconf responsiveness persistent_duplicate_filter=(i > 0)) L = len(enq.matches) if L: cat_title = utf8( ngettext( u'%(amount)s item on “%(machine)s” not on this computer', u'%(amount)s items on “%(machine)s” not on this computer', L)) % { 'amount': L, 'machine': utf8(self.current_hostname) } i += L docs = enq.get_documents() self.cat_docid_map["missingpkg"] = set( [doc.get_docid() for doc in docs]) model.set_nocategory_documents( docs, untranslated_name="additionalpkg", display_name=cat_title) # Second search: additional apps xfilter.set_restricted_list(self.oneconf_missing_pkg) xfilter.set_not_installed_only(False) xfilter.set_installed_only(True) enq.set_query(query, sortmode=SortMethods.BY_ALPHABET, nonapps_visible=self.nonapps_visible, filter=xfilter, nonblocking_load=False, persistent_duplicate_filter=(i > 0)) L = len(enq.matches) if L: cat_title = utf8( ngettext( u'%(amount)s item on this computer not on “%(machine)s”', '%(amount)s items on this computer not on “%(machine)s”', L)) % { 'amount': L, 'machine': utf8(self.current_hostname) } i += L docs = enq.get_documents() self.cat_docid_map["additionalpkg"] = set( [doc.get_docid() for doc in docs]) model.set_nocategory_documents( docs, untranslated_name="additionalpkg", display_name=cat_title) if i: self.app_view.tree_view.set_cursor(Gtk.TreePath(), None, False) if i <= 10: self.app_view.tree_view.expand_all() # cache the installed app count self.installed_count = i self.app_view._append_appcount(self.installed_count, mode=AppView.DIFF_MODE) self.app_view.set_model(self.treefilter) if keep_state: self._restore_treeview_state(treeview_state) # hide the local spinner self.hide_installed_view_spinner() if window: window.set_cursor(None) self.emit("app-list-changed", i) return
def rebuild_categorised_view(): self.cat_docid_map = {} enq = self.enquirer i = 0 while Gtk.events_pending(): Gtk.main_iteration() xfilter = AppFilter(self.db, self.cache) xfilter.set_installed_only(True) for cat in self._all_cats: # for each category do category query and append as a new # node to tree_view if not self._use_category(cat): continue query = self.get_query_for_cat(cat) LOG.debug("xfilter.installed_only: %s" % xfilter.installed_only) enq.set_query(query, sortmode=SortMethods.BY_ALPHABET, nonapps_visible=self.nonapps_visible, filter=xfilter, nonblocking_load=False, persistent_duplicate_filter=(i > 0)) L = len(enq.matches) if L: i += L docs = enq.get_documents() self.cat_docid_map[cat.untranslated_name] = \ set([doc.get_docid() for doc in docs]) model.set_category_documents(cat, docs) while Gtk.events_pending(): Gtk.main_iteration() # check for uncategorised pkgs if self.state.channel: self._run_channel_enquirer(persistent_duplicate_filter=(i > 0)) L = len(enq.matches) if L: # some foo for channels # if no categorised results but in channel, then use # the channel name for the category channel_name = None if not i and self.state.channel: channel_name = self.state.channel.display_name docs = enq.get_documents() tag = channel_name or 'Uncategorized' self.cat_docid_map[tag] = set( [doc.get_docid() for doc in docs]) model.set_nocategory_documents(docs, untranslated_name=tag, display_name=channel_name) i += L if i: self.app_view.tree_view.set_cursor(Gtk.TreePath(), None, False) if i <= 10: self.app_view.tree_view.expand_all() # cache the installed app count self.installed_count = i self.app_view._append_appcount(self.installed_count, mode=AppView.INSTALLED_MODE) self.app_view.set_model(self.treefilter) if keep_state: self._restore_treeview_state(treeview_state) # hide the local spinner self.hide_installed_view_spinner() if window: window.set_cursor(None) # reapply search if needed if self.state.search_term: self._do_search(self.state.search_term) self.emit("app-list-changed", i) return