1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
|
# Copyright (C) 2009 Canonical
#
# Authors:
# Michael Vogt
#
# This program is free software; you can redistribute it and/or modify it under
# the terms of the GNU General Public License as published by the Free Software
# Foundation; version 3.
#
# This program is distributed in the hope that it will be useful, but WITHOUT
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
# FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
# details.
#
# You should have received a copy of the GNU General Public License along with
# this program; if not, write to the Free Software Foundation, Inc.,
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
import apt
import gettext
import gtk
import logging
import os
import sys
import xapian
from gettext import gettext as _
from softwarecenter.enums import *
from appview import AppView, AppStore, AppViewFilter
from softwarepane import SoftwarePane, wait_for_apt_cache_ready
class InstalledPane(SoftwarePane):
"""Widget that represents the installed panel in software-center
It contains a search entry and navigation buttons
"""
(PAGE_APPLIST,
PAGE_APP_DETAILS) = range(2)
def __init__(self, cache, db, distro, icons, datadir):
# parent
SoftwarePane.__init__(self, cache, db, distro, icons, datadir, show_ratings=False)
# state
self.apps_filter = AppViewFilter(db, cache)
self.apps_filter.set_installed_only(True)
self.current_appview_selection = None
# UI
self._build_ui()
def _build_ui(self):
self.notebook.append_page(self.scroll_app_list, gtk.Label("installed"))
# details
self.notebook.append_page(self.scroll_details, gtk.Label("details"))
# initial refresh
self.search_terms = ""
self.refresh_apps()
def _show_installed_overview(self):
" helper that goes back to the overview page "
self.navigation_bar.remove_id("details")
self.notebook.set_current_page(self.PAGE_APPLIST)
#self.searchentry.show()
def _clear_search(self):
# remove the details and clear the search
self.searchentry.clear()
self.navigation_bar.remove_id("search")
@wait_for_apt_cache_ready
def refresh_apps(self):
"""refresh the applist after search changes and update the
navigation bar
"""
if self.search_terms:
query = self.db.get_query_list_from_search_entry(self.search_terms)
self.navigation_bar.add_with_id(_("Search Results"),
self.on_navigation_search,
"search")
else:
query = None
self.navigation_bar.add_with_id(_("Installed Software"),
self.on_navigation_list,
"list")
# *ugh* deactivate the old model because otherwise it keeps
# getting progress_changed events and eats CPU time until its
# garbage collected
old_model = self.app_view.get_model()
old_model.active = False
# get a new store and attach it to the view
new_model = AppStore(self.cache,
self.db,
self.icons,
query,
filter=self.apps_filter)
self.app_view.set_model(new_model)
self.emit("app-list-changed", len(new_model))
return False
def on_search_terms_changed(self, searchentry, terms):
"""callback when the search entry widget changes"""
logging.debug("on_search_terms_changed: '%s'" % terms)
self.search_terms = terms
if not self.search_terms:
self._clear_search()
self.refresh_apps()
self.notebook.set_current_page(self.PAGE_APPLIST)
def on_db_reopen(self, db):
self.refresh_apps()
self._show_installed_overview()
def on_navigation_search(self, pathbar, part):
logging.debug("on_navigation_search")
pass
def on_navigation_list(self, pathbar, part):
"""callback when the navigation button with id 'list' is clicked"""
if not pathbar.get_active():
return
self._clear_search()
self._show_installed_overview()
# only emit something if the model is there
model = self.app_view.get_model()
if model:
self.emit("app-list-changed", len(model))
def on_navigation_details(self, pathbar, part):
"""callback when the navigation button with id 'details' is clicked"""
if not pathbar.get_active():
return
self.notebook.set_current_page(self.PAGE_APP_DETAILS)
#self.searchentry.hide()
def on_application_selected(self, appview, app):
"""callback when an app is selected"""
logging.debug("on_application_selected: '%s'" % app)
self.current_appview_selection = app
def get_status_text(self):
"""return user readable status text suitable for a status bar"""
# no status text in the details page
if self.notebook.get_current_page() == self.PAGE_APP_DETAILS:
return ""
# otherwise, show status based on search or not
length = len(self.app_view.get_model())
if len(self.searchentry.get_text()) > 0:
return gettext.ngettext("%s matching item",
"%s matching items",
length) % length
else:
return gettext.ngettext("%s application installed",
"%s applications installed",
length) % length
def get_current_app(self):
"""return the current active application object applicable
to the context"""
return self.current_appview_selection
def is_category_view_showing(self):
# there is no category view in the installed pane
return False
if __name__ == "__main__":
#logging.basicConfig(level=logging.DEBUG)
xapian_base_path = XAPIAN_BASE_PATH
pathname = os.path.join(xapian_base_path, "xapian")
if len(sys.argv) > 1:
datadir = sys.argv[1]
elif os.path.exists("./data"):
datadir = "./data"
else:
datadir = "/usr/share/software-center"
db = xapian.Database(pathname)
icons = gtk.icon_theme_get_default()
icons.append_search_path("/usr/share/app-install/icons/")
cache = apt.Cache(apt.progress.OpTextProgress())
cache.ready = True
w = InstalledPane(cache, db, icons, datadir)
w.show()
win = gtk.Window()
win.add(w)
win.set_size_request(400, 600)
win.show_all()
gtk.main()
|