~elachuni/software-center/pep8-test-part15

« back to all changes in this revision

Viewing changes to softwarecenter/ui/gtk3/panes/historypane.py

  • Committer: Gary Lasker
  • Date: 2012-03-15 02:39:14 UTC
  • mfrom: (2851.1.4 pep8-test)
  • Revision ID: gary.lasker@canonical.com-20120315023914-119jlk0w2qoujnf3
  lp:~elachuni/software-center/pep8-test-part11,
  lp:~elachuni/software-center/pep8-test-part12:
    ui.gtk3.{views, widgets, session, panes}

Show diffs side-by-side

added added

removed removed

Lines of Context:
31
31
from softwarecenter.ui.gtk3.session.viewmanager import get_viewmanager
32
32
from softwarepane import DisplayState
33
33
 
 
34
 
34
35
class HistoryPane(Gtk.VBox, BasePane):
35
36
 
36
37
    __gsignals__ = {
37
 
        "app-list-changed" : (GObject.SignalFlags.RUN_LAST,
38
 
                              None, 
39
 
                              (int, ),
40
 
                             ),
41
 
        "history-pane-created" : (GObject.SignalFlags.RUN_FIRST,
42
 
                                  None,
43
 
                                  ()),
 
38
        "app-list-changed": (GObject.SignalFlags.RUN_LAST,
 
39
                             None,
 
40
                             (int, ),
 
41
                            ),
 
42
        "history-pane-created": (GObject.SignalFlags.RUN_FIRST,
 
43
                                 None,
 
44
                                 ()),
44
45
    }
45
46
 
46
47
    (COL_WHEN, COL_ACTION, COL_PKG) = range(3)
50
51
 
51
52
    ICON_SIZE = 32
52
53
    PADDING = 6
53
 
    
 
54
 
54
55
    # pages for the spinner notebook
55
56
    (PAGE_HISTORY_VIEW,
56
57
     PAGE_SPINNER) = range(2)
84
85
        self.toolbar.set_style(Gtk.ToolbarStyle.TEXT)
85
86
        self.pack_start(self.toolbar, False, True, 0)
86
87
 
87
 
        all_action = Gtk.RadioAction('filter_all', _('All Changes'), None, None, self.ALL)
 
88
        all_action = Gtk.RadioAction('filter_all', _('All Changes'), None,
 
89
            None, self.ALL)
88
90
        all_action.connect('changed', self.change_filter)
89
91
        all_button = all_action.create_tool_item()
90
92
        self.toolbar.insert(all_button, 0)
91
93
 
92
 
        installs_action = Gtk.RadioAction('filter_installs', _('Installations'), None, None, self.INSTALLED)
 
94
        installs_action = Gtk.RadioAction('filter_installs',
 
95
            _('Installations'), None, None, self.INSTALLED)
93
96
        installs_action.join_group(all_action)
94
97
        installs_button = installs_action.create_tool_item()
95
98
        self.toolbar.insert(installs_button, 1)
118
121
                                      Gtk.PolicyType.AUTOMATIC)
119
122
        self.history_view.show()
120
123
        self.history_view.add(self.view)
121
 
        
 
124
 
122
125
        # make a spinner to display while history is loading
123
126
        self.spinner_notebook = SpinnerNotebook(
124
127
            self.history_view, _('Loading history'))
125
 
        
 
128
 
126
129
        self.pack_start(self.spinner_notebook, True, True, 0)
127
130
 
128
131
        self.store = Gtk.TreeStore(*self.COL_TYPES)
132
135
        self.view.set_model(self.store_filter)
133
136
        all_action.set_active(True)
134
137
        self.last = None
135
 
        
 
138
 
136
139
        # to save (a lot of) time at startup we load history later, only when
137
140
        # it is selected to be viewed
138
141
        self.history = None
145
148
        self.cell_text = Gtk.CellRendererText()
146
149
        self.column.pack_start(self.cell_text, True)
147
150
        self.column.set_cell_data_func(self.cell_text, self.render_cell_text)
148
 
        
 
151
 
149
152
        # busy cursor
150
153
        self.busy_cursor = Gdk.Cursor.new(Gdk.CursorType.WATCH)
151
154
 
152
155
    def init_view(self):
153
156
        if self.history == None:
154
 
            # if the history is not yet initialized we have to load and parse it
155
 
            # show a spinner while we do that
 
157
            # if the history is not yet initialized we have to load and parse
 
158
            # it show a spinner while we do that
156
159
            self.realize()
157
160
            window = self.get_window()
158
161
            window.set_cursor(self.busy_cursor)
171
174
        cr.set_source_rgba(color.red, color.green, color.blue, 0.5)
172
175
        cr.set_line_width(1)
173
176
        cr.move_to(0.5, a.height - 0.5)
174
 
        cr.rel_line_to(a.width-1, 0)
 
177
        cr.rel_line_to(a.width - 1, 0)
175
178
        cr.stroke()
176
 
        return
177
179
 
178
180
    def _get_emblems(self, icons):
179
181
        from softwarecenter.enums import USE_PACKAGEKIT_BACKEND
189
191
        for i, emblem in enumerate(emblem_names):
190
192
            pb = icons.load_icon(emblem, self.ICON_SIZE, 0)
191
193
            self._emblems[i + 1] = pb
192
 
        return
193
194
 
194
195
    def _set_actions_sensitive(self, sensitive):
195
196
        for action in self._actions_list:
198
199
    def _reset_icon_cache(self, theme=None):
199
200
        self._app_icon_cache.clear()
200
201
        try:
201
 
            missing = self.icons.load_icon(Icons.MISSING_APP, self.ICON_SIZE, 0)
 
202
            missing = self.icons.load_icon(Icons.MISSING_APP, self.ICON_SIZE,
 
203
                0)
202
204
        except GObject.GError:
203
205
            missing = None
204
206
        self._app_icon_cache[Icons.MISSING_APP] = missing
205
 
        
 
207
 
206
208
    def load_and_parse_history(self):
207
209
        from softwarecenter.db.history import get_pkg_history
208
210
        self.history = get_pkg_history()
234
236
                date = when.date()
235
237
                day = self.store.append(None, (date, self.ALL, None))
236
238
                last_row = None
237
 
            actions = {self.INSTALLED: trans.install, 
 
239
            actions = {self.INSTALLED: trans.install,
238
240
                       self.REMOVED: trans.remove,
239
241
                       self.UPGRADED: trans.upgrade,
240
242
                      }
247
249
 
248
250
    def get_current_page(self):
249
251
        # single page views can return None here
250
 
        return None
 
252
        pass
251
253
 
252
254
    def get_callback_for_page(self, page, state):
253
255
        # single page views can return None here
254
 
        return None
 
256
        pass
255
257
 
256
258
    def on_search_terms_changed(self, entry, terms):
257
259
        self.update_view()
277
279
 
278
280
        # Compute the number of visible changes
279
281
        # don't do this atm - the spec doesn't mention that the history pane
280
 
        # should have a status text and it gives us a noticable performance gain
281
 
        # if we don't calculate this
 
282
        # should have a status text and it gives us a noticable performance
 
283
        # gain if we don't calculate this
282
284
#        self.visible_changes = 0
283
285
 #       day = self.store_filter.get_iter_first()
284
286
  #      while day is not None:
285
287
   #         self.visible_changes += self.store_filter.iter_n_children(day)
286
288
    #        day = self.store_filter.iter_next(day)
287
 
            
 
289
 
288
290
        # Expand the most recent day
289
291
        day = self.store.get_iter_first()
290
292
        if day is not None:
291
 
                path = self.store.get_path(day)
292
 
                self.view.expand_row(path, False)
293
 
                self.view.scroll_to_cell(path)
 
293
            path = self.store.get_path(day)
 
294
            self.view.expand_row(path, False)
 
295
            self.view.scroll_to_cell(path)
294
296
 
295
297
#        self.emit('app-list-changed', self.visible_changes)
296
298
 
327
329
            action = store.get_value(iter, self.COL_ACTION)
328
330
            cell.set_property('pixbuf', self._emblems[action])
329
331
 
330
 
 
331
332
            #~ icon_name = Icons.MISSING_APP
332
333
            #~ for m in self.db.xapiandb.postlist("AP" + pkg):
333
334
                #~ doc = self.db.xapiandb.get_document(m.docid)
339
340
                #~ icon = self._app_icon_cache[icon_name]
340
341
            #~ else:
341
342
                #~ try:
342
 
                    #~ icon = self.icons.load_icon(icon_name, self.ICON_SIZE, 0)
 
343
                    #~ icon = self.icons.load_icon(icon_name, self.ICON_SIZE,
 
344
                        #~ 0)
343
345
                #~ except GObject.GError:
344
346
                    #~ icon = self._app_icon_cache[Icons.MISSING_APP]
345
347
                #~ self._app_icon_cache[icon_name] = icon
346
 
            
347
348
 
348
349
    def render_cell_text(self, column, cell, store, iter, user_data):
349
350
        when = store.get_value(iter, self.COL_WHEN)
352
353
            pkg = store.get_value(iter, self.COL_PKG)
353
354
            subs = {'pkgname': pkg,
354
355
                    'color': '#8A8A8A',
355
 
                    # Translators : time displayed in history, display hours (0-12), minutes and AM/PM. %H should be used instead of %I to display hours 0-24
 
356
                    # Translators : time displayed in history, display hours
 
357
                    # (0-12), minutes and AM/PM. %H should be used instead
 
358
                    # of %I to display hours 0-24
356
359
                    'time': when.time().strftime(_('%I:%M %p')),
357
360
                   }
358
361
            if action == self.INSTALLED:
359
 
                text = _('%(pkgname)s <span color="%(color)s">installed %(time)s</span>') % subs
 
362
                text = _('%(pkgname)s <span color="%(color)s">'
 
363
                    'installed %(time)s</span>') % subs
360
364
            elif action == self.REMOVED:
361
 
                text = _('%(pkgname)s <span color="%(color)s">removed %(time)s</span>') % subs
 
365
                text = _('%(pkgname)s <span color="%(color)s">'
 
366
                    'removed %(time)s</span>') % subs
362
367
            elif action == self.UPGRADED:
363
 
                text = _('%(pkgname)s <span color="%(color)s">updated %(time)s</span>') % subs
 
368
                text = _('%(pkgname)s <span color="%(color)s">'
 
369
                    'updated %(time)s</span>') % subs
364
370
        elif isinstance(when, datetime.date):
365
371
            today = datetime.date.today()
366
372
            monday = today - datetime.timedelta(days=today.weekday())
388
394
                                          )
389
395
    # needed because available pane will try to get it
390
396
    vm = get_test_gtk3_viewmanager()
391
 
    vm # make pyflakes happy
 
397
    vm  # make pyflakes happy
392
398
    db = get_test_db()
393
399
    cache = get_test_pkg_info()
394
400
    icons = get_test_gtk3_icon_cache()
409
415
if __name__ == '__main__':
410
416
    win = get_test_window()
411
417
    Gtk.main()
412