Subversion Repositories basico

Rev

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

Rev 243 Rev 246
Line 1... Line 1...
1
#!/usr/bin/python
1
#!/usr/bin/python
-
 
2
"""
2
# -*- coding: utf-8 -*-
3
# -*- coding: utf-8 -*-
3
# File: collections.py
-
 
-
 
4
# File: wdg_cols.py
4
# Author: Tomás Vírseda
5
# Author: Tomás Vírseda
5
# License: GPL v3
6
# License: GPL v3
6
# Description: Collections Widget
7
# Description: Collections Widget
-
 
8
"""
7
9
8
from os.path import sep as SEP
-
 
9
from cgi import escape
-
 
10
import gi
10
import gi
11
gi.require_version('Gtk', '3.0')
-
 
12
gi.require_version('Gdk', '3.0')
-
 
13
from gi.repository import Gtk
11
from gi.repository import Gtk
14
from gi.repository import Gdk
-
 
15
from gi.repository import Pango
-
 
16
-
 
17
from basico.core.mod_env import ROOT, USER_DIR, APP, LPATH, GPATH, FILE
-
 
18
12
-
 
13
gi.require_version('Gtk', '3.0')
19
14
20
class CollectionsMgtView(Gtk.VBox):
15
class CollectionsMgtView(Gtk.VBox):
-
 
16
    """
-
 
17
    Missing class docstring (missing-docstring)
-
 
18
    """
21
    def __init__(self, app, sid, popover):
19
    def __init__(self, app, sid, popover):
22
        Gtk.VBox.__init__(self)
20
        Gtk.VBox.__init__(self)
23
        self.app = app
21
        self.app = app
24
        self.log = app.log
-
 
-
 
22
        self.error = self.app.error
25
        self.sid = sid
23
        self.sid = sid
26
        self.popover = popover
24
        self.popover = popover
27
        self.current_cid = None
25
        self.current_cid = None
28
        self.get_services()
26
        self.get_services()
29
        self.setup()
27
        self.setup()
30
        self.setup_treeview()
28
        self.setup_treeview()
31
        self.update()
29
        self.update()
32
30
33
31
34
    def get_services(self):
32
    def get_services(self):
35
        """Load services to be used in this class
-
 
36
        """
33
        """
37
        self.gui = self.app.get_service("GUI")
-
 
38
        self.im = self.app.get_service("IM")
-
 
39
        self.uif = self.app.get_service("UIF")
-
 
40
        self.clts = self.app.get_service('Collections')
-
 
-
 
34
        Load services to be used in this class
-
 
35
        """
-
 
36
        self.srvgui = self.app.get_service("GUI")
-
 
37
        self.srvicm = self.app.get_service("IM")
-
 
38
        self.srvuif = self.app.get_service("UIF")
-
 
39
        self.srvclt = self.app.get_service('Collections')
-
 
40
        self.srvdtb = self.app.get_service('DB')
41
41
42
42
43
    def setup(self):
43
    def setup(self):
-
 
44
        """
-
 
45
        Missing method docstring (missing-docstring)
-
 
46
        """
44
        # Setup Widget properties
47
        # Setup Widget properties
45
        self.set_size_request(400, 680)
48
        self.set_size_request(400, 680)
46
        self.set_property('margin', 3)
49
        self.set_property('margin', 3)
47
        self.set_hexpand(True)
50
        self.set_hexpand(True)
48
        self.set_vexpand(True)
51
        self.set_vexpand(True)
49
52
50
        # CollectionMgt Header
53
        # CollectionMgt Header
51
        header = Gtk.VBox()
54
        header = Gtk.VBox()
52
        hbox = Gtk.HBox()
55
        hbox = Gtk.HBox()
53
        icon = self.im.get_new_image_icon('basico-collection')
-
 
-
 
56
        icon = self.srvicm.get_new_image_icon('basico-collection')
54
        title = Gtk.Label()
57
        title = Gtk.Label()
55
        if self.sid != '0000000000':
58
        if self.sid != '0000000000':
56
            title.set_markup('<big><b>Collections for SAP Note %s</b></big>' % str(int(self.sid)))
59
            title.set_markup('<big><b>Collections for SAP Note %s</b></big>' % str(int(self.sid)))
57
        else:
60
        else:
58
            title.set_markup('<big><b>Manage collections</b></big>')
61
            title.set_markup('<big><b>Manage collections</b></big>')
Line 64... Line 67...
64
        header.pack_start(separator, False, False, 3)
67
        header.pack_start(separator, False, False, 3)
65
        self.pack_start(header, False, False, 3)
68
        self.pack_start(header, False, False, 3)
66
69
67
        # Entry Widget /  Delete entry button
70
        # Entry Widget /  Delete entry button
68
        hbox = Gtk.HBox()
71
        hbox = Gtk.HBox()
69
        self.entry = self.gui.add_widget('gtk_entry_collection_new', Gtk.Entry())
-
 
-
 
72
        self.entry = self.srvgui.add_widget('gtk_entry_collection_new', Gtk.Entry())
70
        self.entry.connect('activate', self.update)
73
        self.entry.connect('activate', self.update)
71
        self.entry.connect('changed', self.filter)
74
        self.entry.connect('changed', self.filter)
72
        delete = self.uif.create_button('basico-delete', 24, 24, '')
-
 
-
 
75
        delete = self.srvuif.create_button('basico-delete', 24, 24, '')
73
        delete.connect('clicked', self.delete)
76
        delete.connect('clicked', self.delete)
74
        hbox.pack_start(self.entry, True, True, 6)
77
        hbox.pack_start(self.entry, True, True, 6)
75
        hbox.pack_start(delete, False, False, 0)
78
        hbox.pack_start(delete, False, False, 0)
76
        self.pack_start(hbox, False, False, 0)
79
        self.pack_start(hbox, False, False, 0)
77
80
Line 89... Line 92...
89
        separator = Gtk.Separator()
92
        separator = Gtk.Separator()
90
        self.pack_start(separator, False, False, 0)
93
        self.pack_start(separator, False, False, 0)
91
94
92
        ## Buttons
95
        ## Buttons
93
        footer = Gtk.HBox()
96
        footer = Gtk.HBox()
94
        accept = self.uif.create_button('basico-check-ok', 24, 24, '<b>Apply changes</b>')
-
 
-
 
97
        accept = self.srvuif.create_button('basico-check-ok', 24, 24, '<b>Apply changes</b>')
95
        accept.connect('clicked', self.accept)
98
        accept.connect('clicked', self.accept)
96
        footer.pack_start(accept, True, False, 0)
99
        footer.pack_start(accept, True, False, 0)
97
        self.pack_start(footer, False, False, 3)
100
        self.pack_start(footer, False, False, 3)
98
101
99
102
100
    def setup_treeview(self):
103
    def setup_treeview(self):
-
 
104
        """
-
 
105
        Missing method docstring (missing-docstring)
-
 
106
        """
101
        # Setup model
107
        # Setup model
102
        self.model = Gtk.ListStore(
108
        self.model = Gtk.ListStore(
103
            str,        # key
109
            str,        # key
104
            int,        # checkbox
110
            int,        # checkbox
105
            str,        # title
111
            str,        # title
Line 130... Line 136...
130
        self.renderer_title = Gtk.CellRendererText()
136
        self.renderer_title = Gtk.CellRendererText()
131
        self.column_title = Gtk.TreeViewColumn('Collection', self.renderer_title, markup=2)
137
        self.column_title = Gtk.TreeViewColumn('Collection', self.renderer_title, markup=2)
132
        self.column_title.set_visible(True)
138
        self.column_title.set_visible(True)
133
        self.column_title.set_expand(True)
139
        self.column_title.set_expand(True)
134
        self.column_title.set_clickable(True)
140
        self.column_title.set_clickable(True)
135
        self.column_title
-
 
136
        self.column_title.set_sort_indicator(True)
141
        self.column_title.set_sort_indicator(True)
137
        self.model.set_sort_column_id(2, Gtk.SortType.ASCENDING)
142
        self.model.set_sort_column_id(2, Gtk.SortType.ASCENDING)
138
        self.treeview.append_column(self.column_title)
143
        self.treeview.append_column(self.column_title)
139
144
140
        # TreeView common
145
        # TreeView common
Line 162... Line 167...
162
167
163
        self.show_all()
168
        self.show_all()
164
169
165
170
166
    def toggle_checkbox(self, cell, path):
171
    def toggle_checkbox(self, cell, path):
-
 
172
        """
-
 
173
        Missing method docstring (missing-docstring)
-
 
174
        """
167
        self.model[path][1] = not self.model[path][1]
175
        self.model[path][1] = not self.model[path][1]
168
176
169
177
170
    def accept(self, button):
178
    def accept(self, button):
171
        db = self.app.get_service('DB')
-
 
-
 
179
        """
-
 
180
        Missing method docstring (missing-docstring)
-
 
181
        """
172
        selected = []
182
        selected = []
-
 
183
173
        def get_linked_collections(model, path, itr):
184
        def get_linked_collections(model, path, itr):
-
 
185
            """
-
 
186
            Missing method docstring (missing-docstring)
-
 
187
            """
174
            cid = model.get(itr, 0)[0]
188
            cid = model.get(itr, 0)[0]
175
            linked = model.get(itr, 1)[0]
189
            linked = model.get(itr, 1)[0]
176
            if linked:
190
            if linked:
177
                selected.append(cid)
191
                selected.append(cid)
178
192
179
        self.model.foreach(get_linked_collections)
193
        self.model.foreach(get_linked_collections)
180
        if self.sid != '0000000000':
194
        if self.sid != '0000000000':
181
            db.set_collections(self.sid, selected)
-
 
-
 
195
            self.srvdtb.set_collections(self.sid, selected)
182
        else:
196
        else:
183
            visor = self.gui.get_widget('visor')
-
 
-
 
197
            visor = self.srvgui.get_widget('visor')
184
            bag = visor.get_bag()
198
            bag = visor.get_bag()
185
            for sid in bag:
199
            for sid in bag:
186
                db.set_collections(sid, selected)
-
 
-
 
200
                self.srvdtb.set_collections(sid, selected)
187
201
188
        self.popover.hide()
202
        self.popover.hide()
189
203
190
204
191
    def row_changed(self, selection):
205
    def row_changed(self, selection):
-
 
206
        """
-
 
207
        Missing method docstring (missing-docstring)
-
 
208
        """
192
        model, treeiter = selection.get_selected() #_rows()
209
        model, treeiter = selection.get_selected() #_rows()
193
        visor = self.gui.get_widget('visor')
-
 
-
 
210
194
        try:
211
        try:
195
            self.current_cid = model[treeiter][0]
212
            self.current_cid = model[treeiter][0]
196
            title = model[treeiter][2]
213
            title = model[treeiter][2]
197
            self.entry.set_text(title)
214
            self.entry.set_text(title)
198
        except TypeError:
215
        except TypeError:
Line 201... Line 218...
201
            self.error("ERROR: collections->row_changed->error: %s" % error)
218
            self.error("ERROR: collections->row_changed->error: %s" % error)
202
            raise
219
            raise
203
220
204
221
205
    def update(self, entry=None):
222
    def update(self, entry=None):
206
        db = self.app.get_service('DB')
-
 
207
        linked = db.get_collections(self.sid)
-
 
-
 
223
        """
-
 
224
        Missing method docstring (missing-docstring)
-
 
225
        """
-
 
226
        linked = self.srvdtb.get_collections(self.sid)
208
227
209
        if entry is not None and isinstance(entry, Gtk.Entry):
228
        if entry is not None and isinstance(entry, Gtk.Entry):
210
            name = entry.get_text()
229
            name = entry.get_text()
211
            self.clts.create(name)
-
 
-
 
230
            self.srvclt.create(name)
212
231
213
        self.model.clear()
232
        self.model.clear()
214
        collections = self.clts.get_all()
-
 
-
 
233
        collections = self.srvclt.get_all()
215
        for cid in collections:
234
        for cid in collections:
216
            name = collections[cid]
235
            name = collections[cid]
217
            if cid in linked:
236
            if cid in linked:
218
                self.model.append([cid, 1, name])
237
                self.model.append([cid, 1, name])
219
            else:
238
            else:
220
                self.model.append([cid, 0, name])
239
                self.model.append([cid, 0, name])
221
        self.current_cid = None
240
        self.current_cid = None
222
241
223
242
224
    def delete(self, button):
243
    def delete(self, button):
-
 
244
        """
-
 
245
        Missing method docstring (missing-docstring)
-
 
246
        """
225
        self.debug("Deleting collection with id: %s" % self.current_cid)
247
        self.debug("Deleting collection with id: %s" % self.current_cid)
226
        deleted = self.clts.delete(self.current_cid)
-
 
-
 
248
        deleted = self.srvclt.delete(self.current_cid)
227
        if deleted:
249
        if deleted:
228
            viewmenu = self.gui.get_widget('viewmenu')
-
 
-
 
250
            viewmenu = self.srvgui.get_widget('viewmenu')
229
            viewmenu.refresh()
251
            viewmenu.refresh()
230
            viewmenu.grab_focus()
252
            viewmenu.grab_focus()
231
        else:
253
        else:
232
            colname = self.clts.get_name_by_cid(self.current_cid)
-
 
-
 
254
            colname = self.srvclt.get_name_by_cid(self.current_cid)
233
            title = "Collection '%s' not deleted" % colname
255
            title = "Collection '%s' not deleted" % colname
234
            message = "Make sure there are not SAP Notes linked to this collection"
256
            message = "Make sure there are not SAP Notes linked to this collection"
235
            self.uif.dialog_info(title, message)
-
 
-
 
257
            self.srvuif.dialog_info(title, message)
236
258
237
    def filter(self, *args):
259
    def filter(self, *args):
238
        self.debug("Filtering")
-
 
-
 
260
        """
-
 
261
        Missing method docstring (missing-docstring)
-
 
262
        """
239
        self.visible_filter.refilter()
263
        self.visible_filter.refilter()
240
264
241
265
242
    def visible_function(self, model, itr, data):
266
    def visible_function(self, model, itr, data):
243
        entry = self.gui.get_widget('gtk_entry_collection_new')
-
 
-
 
267
        """
-
 
268
        Missing method docstring (missing-docstring)
-
 
269
        """
-
 
270
        entry = self.srvgui.get_widget('gtk_entry_collection_new')
244
        text = entry.get_text()
271
        text = entry.get_text()
245
        title = model.get(itr, 2)[0]
272
        title = model.get(itr, 2)[0]
246
        match = text.upper() in title.upper()
273
        match = text.upper() in title.upper()
247
        return match
274
        return match