~gary-lasker/software-center/recommendations-opt-out

« back to all changes in this revision

Viewing changes to softwarecenter/ui/gtk3/views/appview.py

  • Committer: Gary Lasker
  • Date: 2012-03-15 01:57:16 UTC
  • mfrom: (2844.2.7 tweaks)
  • Revision ID: gary.lasker@canonical.com-20120315015716-x2txlto6exaap6du
merge with trunk to get latest

Show diffs side-by-side

added added

removed removed

Lines of Context:
29
29
from softwarecenter.ui.gtk3.models.appstore2 import AppPropertiesHelper
30
30
from softwarecenter.utils import ExecutionTime
31
31
 
32
 
LOG=logging.getLogger(__name__)
 
32
LOG = logging.getLogger(__name__)
 
33
 
33
34
 
34
35
class AppView(Gtk.VBox):
35
36
 
38
39
                                None,
39
40
                                (GObject.TYPE_PYOBJECT, ),
40
41
                                ),
41
 
        "application-activated" : (GObject.SignalFlags.RUN_LAST,
42
 
                                   None,
43
 
                                   (GObject.TYPE_PYOBJECT, ),
44
 
                                  ),
45
 
        "application-selected" : (GObject.SignalFlags.RUN_LAST,
46
 
                                   None,
47
 
                                   (GObject.TYPE_PYOBJECT, ),
48
 
                                  ),
 
42
        "application-activated": (GObject.SignalFlags.RUN_LAST,
 
43
                                  None,
 
44
                                  (GObject.TYPE_PYOBJECT, ),
 
45
                                 ),
 
46
        "application-selected": (GObject.SignalFlags.RUN_LAST,
 
47
                                  None,
 
48
                                  (GObject.TYPE_PYOBJECT, ),
 
49
                                 ),
49
50
        }
50
 
    
 
51
 
51
52
    (INSTALLED_MODE, AVAILABLE_MODE, DIFF_MODE) = range(3)
52
53
 
53
54
    _SORT_METHOD_INDEX = (SortMethods.BY_ALPHABET,
97
98
        self._handler = self.sort_methods_combobox.connect(
98
99
                                    "changed",
99
100
                                    self.on_sort_method_changed)
100
 
        return
101
101
 
102
102
    #~ def on_draw(self, w, cr):
103
103
        #~ cr.set_source_rgb(1,1,1)
104
104
        #~ cr.paint()
105
105
 
106
106
    def _append_appcount(self, appcount, mode=AVAILABLE_MODE):
107
 
#~ 
 
107
#~
108
108
        #~ if mode == self.INSTALLED_MODE:
109
109
            #~ text = gettext.ngettext("%(amount)s item installed",
110
110
                                    #~ "%(amount)s items installed",
112
112
        #~ elif mode == self.DIFF_MODE:
113
113
            #~ text = gettext.ngettext("%(amount)s item",
114
114
                                    #~ "%(amount)s items",
115
 
                                    #~ appcount) % { 'amount' : appcount, }        
 
115
                                    #~ appcount) % { 'amount' : appcount, }
116
116
        #~ else:
117
117
            #~ text = gettext.ngettext("%(amount)s item available",
118
118
                                    #~ "%(amount)s items available",
119
119
                                    #~ appcount) % { 'amount' : appcount, }
120
 
#~ 
 
120
#~
121
121
        #~ if not self.appcount:
122
122
            #~ self.appcount = Gtk.Label()
123
123
            #~ self.appcount.set_alignment(0.5, 0.5)
127
127
            #~ self.vbox.pack_start(self.appcount, False, False, 0)
128
128
        #~ self.appcount.set_text(text)
129
129
        #~ self.appcount.show()
130
 
        return
 
130
        pass
131
131
 
132
132
    def on_sort_method_changed(self, *args):
133
133
        self.user_defined_sort_method = True
134
134
        self.vadj = 0.0
135
135
        self.emit("sort-method-changed", self.sort_methods_combobox)
136
 
        return
137
136
 
138
137
    def _get_sort_methods_combobox(self):
139
138
        combo = Gtk.ComboBoxText.new()
151
150
        if self._get_combo_children() == 4:
152
151
            return
153
152
        self.sort_methods_combobox.append_text(_("By Relevance"))
154
 
        return
155
153
 
156
154
    def _use_combobox_without_sort_by_search_ranking(self):
157
155
        if self._get_combo_children() == 3:
158
156
            return
159
157
        self.sort_methods_combobox.remove(self._SORT_BY_SEARCH_RANKING)
160
158
        self.set_sort_method_with_no_signal(self._SORT_BY_TOP_RATED)
161
 
        return
162
159
 
163
160
    def set_sort_method_with_no_signal(self, sort_method):
164
161
        combo = self.sort_methods_combobox
165
162
        combo.handler_block(self._handler)
166
163
        combo.set_active(sort_method)
167
164
        combo.handler_unblock(self._handler)
168
 
        return
169
165
 
170
166
    def set_allow_user_sorting(self, do_allow):
171
167
        self.sort_methods_combobox.set_visible(do_allow)
172
 
        return
173
168
 
174
169
    def set_header_labels(self, first_line, second_line):
175
170
        if second_line:
180
175
 
181
176
    def set_model(self, model):
182
177
        self.tree_view.set_model(model)
183
 
        return
184
178
 
185
179
    def display_matches(self, matches, is_search=False):
186
180
        # FIXME: installedpane handles display of the trees intimately,
210
204
 
211
205
        self.tree_view_scroll.get_vadjustment().set_lower(self.vadj)
212
206
        self.tree_view_scroll.get_vadjustment().set_value(self.vadj)
213
 
        return
214
207
 
215
208
    def clear_model(self):
216
209
        return self.tree_view.clear_model()
218
211
    def get_sort_mode(self):
219
212
        active_index = self.sort_methods_combobox.get_active()
220
213
        return self._SORT_METHOD_INDEX[active_index]
221
 
        
 
214
 
222
215
    def get_app_icon_details(self):
223
216
        """ helper for unity dbus support to provide details about the
224
217
            application icon as it is displayed on-screen
239
232
            else:
240
233
                icon_size = pb.get_height()
241
234
        return icon_size
242
 
                
 
235
 
243
236
    def _get_app_icon_xy_position_on_screen(self):
244
237
        """ helper for unity dbus support to get the x,y position of
245
238
            the application icon as it is displayed on-screen
251
244
        # get toplevel window position
252
245
        (px, py) = parent.get_position()
253
246
        # and return the coordinate values
254
 
        return (px+self.tree_view.selected_row_renderer.icon_x_offset,
255
 
                py+self.tree_view.selected_row_renderer.icon_y_offset)
256
 
 
257
 
 
258
 
 
 
247
        return (px + self.tree_view.selected_row_renderer.icon_x_offset,
 
248
                py + self.tree_view.selected_row_renderer.icon_y_offset)
259
249
 
260
250
 
261
251
# ----------------------------------------------- testcode
262
252
from softwarecenter.enums import NonAppVisibility
263
253
 
 
254
 
264
255
def get_query_from_search_entry(search_term):
265
256
    import xapian
266
257
    if not search_term:
269
260
    user_query = parser.parse_query(search_term)
270
261
    return user_query
271
262
 
 
263
 
272
264
def on_entry_changed(widget, data):
273
265
 
274
266
    def _work():
278
270
        with ExecutionTime("total time"):
279
271
            with ExecutionTime("enquire.set_query()"):
280
272
                enquirer.set_query(get_query_from_search_entry(new_text),
281
 
                                  limit=100*1000,
282
 
                                  nonapps_visible=NonAppVisibility.ALWAYS_VISIBLE)
 
273
                    limit=100 * 1000,
 
274
                    nonapps_visible=NonAppVisibility.ALWAYS_VISIBLE)
283
275
 
284
276
            store = view.tree_view.get_model()
285
277
            with ExecutionTime("store.clear()"):
293
285
                    Gtk.main_iteration()
294
286
        return
295
287
 
296
 
    if widget.stamp: 
 
288
    if widget.stamp:
297
289
        GObject.source_remove(widget.stamp)
298
290
    widget.stamp = GObject.timeout_add(250, _work)
299
291
 
 
292
 
300
293
def get_test_window():
301
294
    import softwarecenter.log
302
295
    softwarecenter.log.root.setLevel(level=logging.DEBUG)