Subversion Repositories basico

Rev

Rev 239 | Rev 243 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 239 Rev 241
Line 23... Line 23...
23
        Gtk.VBox.__init__(self)
23
        Gtk.VBox.__init__(self)
24
        self.app = app
24
        self.app = app
25
        self.log = app.log
25
        self.log = app.log
26
        self.sid = sid
26
        self.sid = sid
27
        self.popover = popover
27
        self.popover = popover
28
        self.current_tid = None
-
 
-
 
28
        self.current_cid = None
29
        self.get_services()
29
        self.get_services()
30
        self.setup()
30
        self.setup()
31
        self.setup_treeview()
31
        self.setup_treeview()
32
        self.update()
32
        self.update()
33
33
Line 51... Line 51...
51
        # CollectionMgt Header
51
        # CollectionMgt Header
52
        header = Gtk.VBox()
52
        header = Gtk.VBox()
53
        hbox = Gtk.HBox()
53
        hbox = Gtk.HBox()
54
        icon = self.im.get_new_image_icon('basico-collection')
54
        icon = self.im.get_new_image_icon('basico-collection')
55
        title = Gtk.Label()
55
        title = Gtk.Label()
56
        title.set_markup('<big><b>Collections for SAP Note %s</b></big>' % str(int(self.sid)))
-
 
-
 
56
        if self.sid != '0000000000':
-
 
57
            title.set_markup('<big><b>Collections for SAP Note %s</b></big>' % str(int(self.sid)))
-
 
58
        else:
-
 
59
            title.set_markup('<big><b>Manage collections</b></big>')
57
        title.set_xalign(0.0)
60
        title.set_xalign(0.0)
58
        hbox.pack_start(icon, False, False, 6)
61
        hbox.pack_start(icon, False, False, 6)
59
        hbox.pack_start(title, True, True, 0)
62
        hbox.pack_start(title, True, True, 0)
60
        separator = Gtk.Separator()
63
        separator = Gtk.Separator()
61
        header.pack_start(hbox, False, False, 0)
64
        header.pack_start(hbox, False, False, 0)
Line 64... Line 67...
64
67
65
        # Entry Widget /  Delete entry button
68
        # Entry Widget /  Delete entry button
66
        hbox = Gtk.HBox()
69
        hbox = Gtk.HBox()
67
        self.entry = self.gui.add_widget('gtk_entry_collection_new', Gtk.Entry())
70
        self.entry = self.gui.add_widget('gtk_entry_collection_new', Gtk.Entry())
68
        self.entry.connect('activate', self.update)
71
        self.entry.connect('activate', self.update)
-
 
72
        self.entry.connect('changed', self.filter)
69
        delete = self.uif.create_button('basico-delete', 24, 24, '')
73
        delete = self.uif.create_button('basico-delete', 24, 24, '')
70
        delete.connect('clicked', self.delete)
74
        delete.connect('clicked', self.delete)
71
        hbox.pack_start(self.entry, True, True, 6)
75
        hbox.pack_start(self.entry, True, True, 6)
72
        hbox.pack_start(delete, False, False, 0)
76
        hbox.pack_start(delete, False, False, 0)
73
        self.pack_start(hbox, False, False, 0)
77
        self.pack_start(hbox, False, False, 0)
Line 149... Line 153...
149
        # Selection
153
        # Selection
150
        self.selection = self.treeview.get_selection()
154
        self.selection = self.treeview.get_selection()
151
        self.selection.set_mode(Gtk.SelectionMode.SINGLE)
155
        self.selection.set_mode(Gtk.SelectionMode.SINGLE)
152
        self.selection.connect('changed', self.row_changed)
156
        self.selection.connect('changed', self.row_changed)
153
157
154
        self.treeview.set_model(self.model)
-
 
-
 
158
        # Filter
-
 
159
        self.visible_filter = self.model.filter_new()
-
 
160
        self.visible_filter.set_visible_func(self.visible_function)
-
 
161
-
 
162
        self.treeview.set_model(self.visible_filter)
155
163
156
        self.show_all()
164
        self.show_all()
157
165
158
166
159
    def toggle_checkbox(self, cell, path):
167
    def toggle_checkbox(self, cell, path):
Line 162... Line 170...
162
170
163
    def accept(self, button):
171
    def accept(self, button):
164
        db = self.app.get_service('DB')
172
        db = self.app.get_service('DB')
165
        selected = []
173
        selected = []
166
        def get_linked_collections(model, path, itr):
174
        def get_linked_collections(model, path, itr):
167
            tid = model.get(itr, 0)[0]
-
 
-
 
175
            cid = model.get(itr, 0)[0]
168
            linked = model.get(itr, 1)[0]
176
            linked = model.get(itr, 1)[0]
169
            if linked:
177
            if linked:
170
                selected.append(tid)
-
 
-
 
178
                selected.append(cid)
171
179
172
        self.model.foreach(get_linked_collections)
180
        self.model.foreach(get_linked_collections)
173
        if self.sid != '0000000000':
181
        if self.sid != '0000000000':
174
            db.set_collections(self.sid, selected)
182
            db.set_collections(self.sid, selected)
175
        else:
183
        else:
Line 183... Line 191...
183
191
184
    def row_changed(self, selection):
192
    def row_changed(self, selection):
185
        model, treeiter = selection.get_selected() #_rows()
193
        model, treeiter = selection.get_selected() #_rows()
186
        visor = self.gui.get_widget('visor')
194
        visor = self.gui.get_widget('visor')
187
        try:
195
        try:
188
            self.current_tid = model[treeiter][0]
-
 
-
 
196
            self.current_cid = model[treeiter][0]
189
            title = model[treeiter][2]
197
            title = model[treeiter][2]
190
            self.entry.set_text(title)
198
            self.entry.set_text(title)
191
        except TypeError:
199
        except TypeError:
192
            pass
200
            pass
193
        except Exception as error:
201
        except Exception as error:
Line 203... Line 211...
203
            name = entry.get_text()
211
            name = entry.get_text()
204
            self.clts.create(name)
212
            self.clts.create(name)
205
213
206
        self.model.clear()
214
        self.model.clear()
207
        collections = self.clts.get_all()
215
        collections = self.clts.get_all()
208
        for tid in collections:
-
 
209
            name = collections[tid]
-
 
210
            if tid in linked:
-
 
211
                self.model.append([tid, 1, name])
-
 
-
 
216
        for cid in collections:
-
 
217
            name = collections[cid]
-
 
218
            if cid in linked:
-
 
219
                self.model.append([cid, 1, name])
212
            else:
220
            else:
213
                self.model.append([tid, 0, name])
-
 
214
        self.current_tid = None
-
 
-
 
221
                self.model.append([cid, 0, name])
-
 
222
        self.current_cid = None
215
223
216
224
217
    def delete(self, button):
225
    def delete(self, button):
218
        self.debug("Deleting collection with id: %s" % self.current_tid)
-
 
219
        res = self.clts.delete(self.current_tid)
-
 
220
        if res:
-
 
221
            self.update()
-
 
-
 
226
        self.debug("Deleting collection with id: %s" % self.current_cid)
-
 
227
        deleted = self.clts.delete(self.current_cid)
-
 
228
        if deleted:
-
 
229
            viewmenu = self.gui.get_widget('viewmenu')
-
 
230
            viewmenu.refresh()
-
 
231
            viewmenu.grab_focus()
-
 
232
        else:
-
 
233
            colname = self.clts.get_name_by_cid(self.current_cid)
-
 
234
            title = "Collection '%s' not deleted" % colname
-
 
235
            message = "Make sure there are not SAP Notes linked to this collection"
-
 
236
            self.uif.dialog_info(title, message)
-
 
237
-
 
238
    def filter(self, *args):
-
 
239
        self.debug("Filtering")
-
 
240
        self.visible_filter.refilter()
-
 
241
-
 
242
-
 
243
    def visible_function(self, model, itr, data):
-
 
244
        entry = self.gui.get_widget('gtk_entry_collection_new')
-
 
245
        text = entry.get_text()
-
 
246
        title = model.get(itr, 2)[0]
-
 
247
        match = text.upper() in title.upper()
-
 
248
        return match