~gtg-user/gtg/port-to-gtk3

« back to all changes in this revision

Viewing changes to GTG/gtk/backends_dialog/backendstree.py

  • Committer: Izidor Matušov
  • Date: 2012-12-14 13:53:48 UTC
  • mfrom: (1240.1.17 trunk)
  • Revision ID: izidor.matusov@gmail.com-20121214135348-q7wn21y464xb1q2x
Merging trunk

Show diffs side-by-side

added added

removed removed

Lines of Context:
25
25
from GTG.backends.backendsignals import BackendSignals
26
26
 
27
27
 
28
 
 
29
28
class BackendsTree(Gtk.TreeView):
30
29
    '''
31
30
    Gtk.TreeView that shows the currently loaded backends.
44
43
        @param backends_dialog: a reference to the dialog in which this is
45
44
        loaded
46
45
        '''
47
 
        super(BackendsTree,self).__init__()
 
46
        super(BackendsTree, self).__init__()
48
47
        self.dialog = backendsdialog
49
48
        self.req = backendsdialog.get_requester()
50
49
        self._init_liststore()
61
60
        # 1, put default backend on top
62
61
        # 2, sort backends by human name
63
62
        backends = list(self.req.get_all_backends(disabled = True))
64
 
        backends = sorted(backends, key=lambda backend:(not backend.is_default(), backend.get_human_name()))
 
63
        backends = sorted(backends,
 
64
                      key=lambda backend: (not backend.is_default(),
 
65
                                          backend.get_human_name()))
65
66
 
66
67
        for backend in backends:
67
68
            self.add_backend(backend)
93
94
        @param backend_id: the id of the backend to add
94
95
        '''
95
96
        if backend:
96
 
            backend_iter = self.liststore.append([ \
97
 
                backend.get_id(), \
98
 
                self.dialog.get_pixbuf_from_icon_name(backend.get_name(), \
99
 
                                                      16), \
100
 
                backend.get_human_name(), \
101
 
                self._get_markup_for_tags(backend.get_attached_tags()), \
 
97
            backend_iter = self.liststore.append([
 
98
                backend.get_id(),
 
99
                self.dialog.get_pixbuf_from_icon_name(backend.get_name(),
 
100
                                                      16),
 
101
                backend.get_human_name(),
 
102
                self._get_markup_for_tags(backend.get_attached_tags()),
102
103
                ])
103
104
            self.backendid_to_iter[backend.get_id()] = backend_iter
104
105
 
105
 
 
106
106
    def on_backend_state_changed(self, sender, backend_id):
107
107
        '''
108
108
        Signal callback executed when a backend is enabled/disabled.
133
133
            self.liststore[b_path][self.COLUMN_TAGS] = new_tags
134
134
 
135
135
    def _get_markup_for_tags(self, tag_names):
136
 
        '''Given a list of tags names, generates the pango markup to render that
137
 
        list with the tag colors used in GTG
 
136
        '''Given a list of tags names, generates the pango markup to render
 
137
         that list with the tag colors used in GTG
138
138
 
139
139
        @param tag_names: the list of the tags (strings)
140
140
        @return str: the pango markup string
145
145
            tags_txt = get_colored_tags_markup(self.req, tag_names)
146
146
        return "<small>" + tags_txt + "</small>"
147
147
 
148
 
 
149
148
    def remove_backend(self, backend_id):
150
149
        ''' Removes a backend from the treeview, and selects the first (to show
151
150
        something in the configuration panel
197
196
                                    c in [" ", "-", "_"]))
198
197
        selected_iter = self.liststore.get_iter(path)
199
198
        # update the backend name
200
 
        backend_id = self.liststore.get_value(selected_iter, \
 
199
        backend_id = self.liststore.get_value(selected_iter,
201
200
                                              self.COLUMN_BACKEND_ID)
202
201
        backend = self.dialog.get_requester().get_backend(backend_id)
203
202
        if backend:
224
223
        '''
225
224
        Helper function to get the selected path
226
225
 
227
 
        @return Gtk.TreePath : returns exactly one path for the selected object or
228
 
                               None
 
226
        @return Gtk.TreePath : returns exactly one path for the selected object
 
227
                               or None
229
228
        '''
230
229
        selection = self.get_selection()
231
230
        if selection: