Subversion Repositories basico

Rev

Rev 130 | Rev 133 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
113 t00mlabs 1
#!/usr/bin/python
2
# -*- coding: utf-8 -*-
3
# File: sapnoteviewvisor.py
4
# Author: Tomás Vírseda
5
# License: GPL v3
6
# Description: SAPNoteView GTK.TreeView widgets
7
 
8
from enum import IntEnum
9
import traceback as tb
10
from cgi import escape
11
 
12
import gi
13
gi.require_version('Gdk', '3.0')
14
gi.require_version('Gtk', '3.0')
15
from gi.repository import Gdk
16
from gi.repository import Gio
17
from gi.repository import Gtk
18
from gi.repository import Pango
19
from gi.repository.GdkPixbuf import Pixbuf
20
from gi.repository import Pango
21
from datetime import datetime
22
from dateutil import parser as dateparser
23
 
24
from .sapnoteviewrow import SAPNoteViewRow
25
from .log import get_logger
26
 
27
 
28
class SAPNoteViewVisor(Gtk.Box):
29
    def __init__(self, app):
30
        self.app = app
130 t00mlabs 31
        LOG_FILE = self.app.get_file('LOG')
32
        LOG_NAME = self.__class__.__name__
33
        self.log = get_logger(LOG_NAME, LOG_FILE)
113 t00mlabs 34
        self.get_services()
35
        self.toggled = 0
36
        self.selected = set()
37
        self.count = 0
38
        Gtk.Box.__init__(self)
39
 
40
 
41
    def get_services(self):
42
        self.gui = self.app.get_service("GUI")
43
        self.cb = self.app.get_service('Callbacks')
44
        self.menu = self.app.get_service("Menus")
45
        self.sap = self.app.get_service('SAP')
46
        self.im = self.app.get_service('IM')
47
        self.settings = self.app.get_service('Settings')
126 t00mlabs 48
        #~ self.plugins = self.app.get_service('Plugins')
113 t00mlabs 49
        self.db = self.app.get_service('DB')
50
        self.uif = self.app.get_service("UIF")
51
 
52
 
53
 
54
    def prepare(self):
55
        self.set_hexpand(True)
56
        self.set_property('fill', True)
131 t00mlabs 57
        self.modify_bg(Gtk.StateType.NORMAL, Gdk.color_parse("White"))
58
        for widget_name in ['boxVisor', 'scrVisor', 'vwpVisor']:
59
            widget = self.gui.get_widget(widget_name)
60
            widget.modify_bg(Gtk.StateType.NORMAL, Gdk.color_parse("White"))
113 t00mlabs 61
 
62
 
63
    def get_node_sapnote(self, sid):
64
        sapnotes = self.db.get_notes()
65
        sapnote = sapnotes[sid]
122 t00mlabs 66
        #~ compkey = escape(sapnote['componentkey'])
67
        #~ icon_note = self.im.get_icon('fingerprint', 32, 32)
68
        #~ icon_fav = self.im.get_icon('bookmark', 32, 32)
69
        #~ compkey = escape(sapnote['componentkey'])
70
        #~ compkey = escape(sapnote['componentkey'])
71
        #~ catname = escape(sapnote['category'])
72
        #~ sid = "0"*(10 - len(sid)) + sid
113 t00mlabs 73
 
74
        return sapnote
75
 
76
 
77
    def show_infobox(self, button, revealer):
78
        revealed = revealer.get_reveal_child()
79
        revealer.set_reveal_child(not revealed)
80
 
81
 
82
    def get_row(self, sid):
83
        sapnote = self.get_node_sapnote(sid)
84
 
85
        # Container
86
        container = Gtk.VBox()
87
 
88
        # SAP Note Infobox
89
        infobox = Gtk.Revealer()
90
        infobox.set_reveal_child(False)
91
        label = Gtk.Label(sid)
92
        label.set_selectable(True)
93
        infobox.add(label)
94
 
95
        # row widget
96
        row = Gtk.HBox()
131 t00mlabs 97
        row.modify_bg(Gtk.StateType.NORMAL, Gdk.color_parse("Gold"))
113 t00mlabs 98
        row.set_hexpand(True)
99
 
100
        # row items widgets
101
        checkbox = Gtk.CheckButton()
102
        row.pack_start(checkbox, False, False, 6)
103
 
104
        label = Gtk.Label()
105
        label.set_markup('<big>❤</big>')
106
        bookmark = Gtk.ToggleButton()
107
        bookmark.set_relief(Gtk.ReliefStyle.NONE)
108
        bookmark.get_style_context().add_class(Gtk.STYLE_CLASS_DESTRUCTIVE_ACTION)
109
        bookmark.add(label)
110
        row.pack_start(bookmark, False, False, 6)
111
 
112
        lblsid = Gtk.Label()
113
        title = escape("%s - %s" % (sid, sapnote['title']))
114
        lblsid.set_markup("%s" % title)
115
        lblsid.set_justify(Gtk.Justification.LEFT)
116
        lblsid.set_xalign(0.0)
117
        lblsid.set_selectable(True)
118
        lblsid.set_hexpand(False)
119
        lblsid.set_property('ellipsize', Pango.EllipsizeMode.MIDDLE)
120
        lblsid.modify_font(Pango.FontDescription('Monospace 10'))
121
        row.pack_start(lblsid, True, True, 6)
122
 
123
        button = Gtk.Button()
124
        button.set_relief(Gtk.ReliefStyle.NONE)
125
        button.set_alignment (0.0, 0.0)
126
        button.set_hexpand(False)
127
        button.get_style_context().add_class(Gtk.STYLE_CLASS_SUGGESTED_ACTION)
128
        label = Gtk.Label()
129
        label.set_markup('<big>❓</big>')
130
        button.add(label)
131
        button.connect('clicked', self.show_infobox, infobox)
132
        row.pack_start(button, False, False, 6)
133
 
134
        button = Gtk.Button()
135
        button.set_relief(Gtk.ReliefStyle.NONE)
136
        button.set_alignment (0.0, 0.0)
137
        button.set_hexpand(False)
138
        button.get_style_context().add_class(Gtk.STYLE_CLASS_DESTRUCTIVE_ACTION)
139
        label = Gtk.Label()
140
        label.set_markup('<big>🔗</big>')
141
        button.add(label)
142
        button.connect('clicked', self.show_infobox, infobox)
143
        row.pack_start(button, False, False, 6)
144
 
145
        button = Gtk.Button()
146
        button.set_relief(Gtk.ReliefStyle.NONE)
147
        button.set_alignment (0.0, 0.0)
148
        button.set_hexpand(False)
149
        label = Gtk.Label()
150
        label.set_markup('<big>✍</big>')
151
        button.add(label)
152
        button.connect('clicked', self.show_infobox, infobox)
153
        row.pack_start(button, False, False, 6)
154
 
155
        app = self.gui.get_app()
156
        actions_menu = Gio.Menu()
157
        actions_menu.append_item(self.uif.create_item('Import Basico Package', 'app.actions-import-basico', 'document-open'))
158
        app.add_action(self.uif.create_action("actions-import-basico"))
159
        actions_menu.append_item(self.uif.create_item('Import JSON file', 'app.actions-import-json', 'document-open'))
160
        app.add_action(self.uif.create_action("actions-import-json"))
161
        actions_menu.append_item(self.uif.create_item('Import SAP Notes from SAP Launchpad', 'app.actions-import-launchpad', 'download'))
162
        app.add_action(self.uif.create_action("actions-import-launchpad"))
163
        btnactions = Gtk.MenuButton()
164
        btnactions.set_always_show_image(True)
165
        btnactions.set_property("use-popover", True)
166
        btnactions.set_menu_model(actions_menu)
167
        row.pack_start(btnactions, False, False, 6)
168
 
169
        container.pack_start(row, False, False, 0)
170
        container.pack_start(infobox, False, False, 0)
171
 
131 t00mlabs 172
        #~ container.modify_bg(Gtk.StateType.NORMAL, Gdk.color_parse("Red"))
173
 
113 t00mlabs 174
        return container
175
 
176
 
117 t00mlabs 177
    def get_toggled(self):
178
        flowbox = self.gui.get_widget('flowbox')
130 t00mlabs 179
        mnubtnactions = self.gui.get_widget('mnuBtnActions')
117 t00mlabs 180
 
181
        toggled = set()
182
        def foreach_row(item):
183
            row = item.get_children()[0]
184
            active = row.get_checkbox_is_active()
185
            if active:
186
                sid = row.get_sid()
187
                toggled.add(sid)
188
                #~ self.log.debug("%s -> %s" % (row, active))
189
 
190
        flowbox.foreach(foreach_row)
130 t00mlabs 191
 
117 t00mlabs 192
        lsid = list(toggled)
130 t00mlabs 193
        if len(lsid) > 0:
194
            lsid.sort()
195
            mnubtnactions.set_no_show_all(False)
196
            mnubtnactions.show_all()
197
        else:
198
            mnubtnactions.set_no_show_all(True)
199
            mnubtnactions.hide()
117 t00mlabs 200
 
201
        return lsid
202
 
203
 
204
    def get_bag(self):
205
        return self.bag
206
 
207
 
208
    def filter_by_bookmark(self, item):
209
        row = item.get_children()[0]
210
        return row.is_bookmark()
211
 
212
 
113 t00mlabs 213
    def populate(self, bag):
117 t00mlabs 214
        self.bag = bag
215
        mnubtnactions = self.gui.get_widget('mnuBtnActions')
216
        mnubtnactions.set_no_show_all(False)
217
        mnubtnactions.show_all()
218
        visor = self.gui.get_widget('visor')
116 t00mlabs 219
        lblSelectedNotes = self.gui.get_widget('lblSelectedNotes')
113 t00mlabs 220
        flowbox = Gtk.FlowBox()
221
        flowbox.set_valign(Gtk.Align.START)
222
        flowbox.set_max_children_per_line(1)
223
        flowbox.set_selection_mode(Gtk.SelectionMode.NONE)
118 t00mlabs 224
        #~ flowbox.set_filter_func(self.filter_by_bookmark)
117 t00mlabs 225
        self.gui.add_widget('flowbox', flowbox)
113 t00mlabs 226
 
227
        self.hide()
228
        icon_bookmark = self.im.get_icon('bookmark')
229
 
230
        sapnotes = self.db.get_notes()
231
 
232
        lbag = []
233
        for sid in bag:
234
            lbag.append(sid)
235
        lbag.sort()
236
 
237
        for sid in lbag:
238
            row = SAPNoteViewRow(self.app, sid)
239
            flowbox.add(row)
240
 
131 t00mlabs 241
        #~ lblcount = self.gui.get_widget("lblSAPNoteViewCount")
242
        #~ self.log.debug("lblcount: %s (%s)"% (str(lblcount), str(type(lblcount))))
130 t00mlabs 243
        #~ lblcount.set_markup("<span size=\"30000\">%d</span>" % len(bag))
113 t00mlabs 244
        self.gui.swap_widget(self, flowbox)
116 t00mlabs 245
 
130 t00mlabs 246
        #~ toggled = self.get_toggled()
247
        #~ lblSelectedNotes.set_markup('<b><small>%d</small>/%d of <big>%d</big></b>' % (len(toggled), len(bag), self.db.get_total()))
117 t00mlabs 248
 
113 t00mlabs 249
        self.show_all()
250
 
251
 
252