Subversion Repositories basico

Rev

Rev 126 | Rev 131 | 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)
57
 
58
 
59
    def get_node_sapnote(self, sid):
60
        sapnotes = self.db.get_notes()
61
        sapnote = sapnotes[sid]
122 t00mlabs 62
        #~ compkey = escape(sapnote['componentkey'])
63
        #~ icon_note = self.im.get_icon('fingerprint', 32, 32)
64
        #~ icon_fav = self.im.get_icon('bookmark', 32, 32)
65
        #~ compkey = escape(sapnote['componentkey'])
66
        #~ compkey = escape(sapnote['componentkey'])
67
        #~ catname = escape(sapnote['category'])
68
        #~ sid = "0"*(10 - len(sid)) + sid
113 t00mlabs 69
 
70
        return sapnote
71
 
72
 
73
    def show_infobox(self, button, revealer):
74
        revealed = revealer.get_reveal_child()
75
        revealer.set_reveal_child(not revealed)
76
 
77
 
78
    def get_row(self, sid):
79
        sapnote = self.get_node_sapnote(sid)
80
 
81
        # Container
82
        container = Gtk.VBox()
83
 
84
        # SAP Note Infobox
85
        infobox = Gtk.Revealer()
86
        infobox.set_reveal_child(False)
87
        label = Gtk.Label(sid)
88
        label.set_selectable(True)
89
        infobox.add(label)
90
 
91
        # row widget
92
        row = Gtk.HBox()
93
        #~ row.modify_bg(Gtk.StateType.NORMAL, Gdk.color_parse("Gold"))
94
        row.set_hexpand(True)
95
 
96
        # row items widgets
97
        checkbox = Gtk.CheckButton()
98
        row.pack_start(checkbox, False, False, 6)
99
 
100
        label = Gtk.Label()
101
        label.set_markup('<big>❤</big>')
102
        bookmark = Gtk.ToggleButton()
103
        bookmark.set_relief(Gtk.ReliefStyle.NONE)
104
        bookmark.get_style_context().add_class(Gtk.STYLE_CLASS_DESTRUCTIVE_ACTION)
105
        bookmark.add(label)
106
        row.pack_start(bookmark, False, False, 6)
107
 
108
        lblsid = Gtk.Label()
109
        title = escape("%s - %s" % (sid, sapnote['title']))
110
        lblsid.set_markup("%s" % title)
111
        lblsid.set_justify(Gtk.Justification.LEFT)
112
        lblsid.set_xalign(0.0)
113
        lblsid.set_selectable(True)
114
        lblsid.set_hexpand(False)
115
        lblsid.set_property('ellipsize', Pango.EllipsizeMode.MIDDLE)
116
        lblsid.modify_font(Pango.FontDescription('Monospace 10'))
117
        row.pack_start(lblsid, True, True, 6)
118
 
119
        button = Gtk.Button()
120
        button.set_relief(Gtk.ReliefStyle.NONE)
121
        button.set_alignment (0.0, 0.0)
122
        button.set_hexpand(False)
123
        button.get_style_context().add_class(Gtk.STYLE_CLASS_SUGGESTED_ACTION)
124
        label = Gtk.Label()
125
        label.set_markup('<big>❓</big>')
126
        button.add(label)
127
        button.connect('clicked', self.show_infobox, infobox)
128
        row.pack_start(button, False, False, 6)
129
 
130
        button = Gtk.Button()
131
        button.set_relief(Gtk.ReliefStyle.NONE)
132
        button.set_alignment (0.0, 0.0)
133
        button.set_hexpand(False)
134
        button.get_style_context().add_class(Gtk.STYLE_CLASS_DESTRUCTIVE_ACTION)
135
        label = Gtk.Label()
136
        label.set_markup('<big>🔗</big>')
137
        button.add(label)
138
        button.connect('clicked', self.show_infobox, infobox)
139
        row.pack_start(button, False, False, 6)
140
 
141
        button = Gtk.Button()
142
        button.set_relief(Gtk.ReliefStyle.NONE)
143
        button.set_alignment (0.0, 0.0)
144
        button.set_hexpand(False)
145
        label = Gtk.Label()
146
        label.set_markup('<big>✍</big>')
147
        button.add(label)
148
        button.connect('clicked', self.show_infobox, infobox)
149
        row.pack_start(button, False, False, 6)
150
 
151
        app = self.gui.get_app()
152
        actions_menu = Gio.Menu()
153
        actions_menu.append_item(self.uif.create_item('Import Basico Package', 'app.actions-import-basico', 'document-open'))
154
        app.add_action(self.uif.create_action("actions-import-basico"))
155
        actions_menu.append_item(self.uif.create_item('Import JSON file', 'app.actions-import-json', 'document-open'))
156
        app.add_action(self.uif.create_action("actions-import-json"))
157
        actions_menu.append_item(self.uif.create_item('Import SAP Notes from SAP Launchpad', 'app.actions-import-launchpad', 'download'))
158
        app.add_action(self.uif.create_action("actions-import-launchpad"))
159
        btnactions = Gtk.MenuButton()
160
        btnactions.set_always_show_image(True)
161
        btnactions.set_property("use-popover", True)
162
        btnactions.set_menu_model(actions_menu)
163
        row.pack_start(btnactions, False, False, 6)
164
 
165
        container.pack_start(row, False, False, 0)
166
        container.pack_start(infobox, False, False, 0)
117 t00mlabs 167
        container.modify_bg(Gtk.StateType.NORMAL, Gdk.color_parse("Gray"))
113 t00mlabs 168
 
169
        return container
170
 
171
 
117 t00mlabs 172
    def get_toggled(self):
173
        flowbox = self.gui.get_widget('flowbox')
130 t00mlabs 174
        mnubtnactions = self.gui.get_widget('mnuBtnActions')
117 t00mlabs 175
 
176
        toggled = set()
177
        def foreach_row(item):
178
            row = item.get_children()[0]
179
            active = row.get_checkbox_is_active()
180
            if active:
181
                sid = row.get_sid()
182
                toggled.add(sid)
183
                #~ self.log.debug("%s -> %s" % (row, active))
184
 
185
        flowbox.foreach(foreach_row)
130 t00mlabs 186
 
117 t00mlabs 187
        lsid = list(toggled)
130 t00mlabs 188
        if len(lsid) > 0:
189
            lsid.sort()
190
            mnubtnactions.set_no_show_all(False)
191
            mnubtnactions.show_all()
192
        else:
193
            mnubtnactions.set_no_show_all(True)
194
            mnubtnactions.hide()
117 t00mlabs 195
 
196
        return lsid
197
 
198
 
199
    def get_bag(self):
200
        return self.bag
201
 
202
 
203
    def filter_by_bookmark(self, item):
204
        row = item.get_children()[0]
205
        return row.is_bookmark()
206
 
207
 
113 t00mlabs 208
    def populate(self, bag):
117 t00mlabs 209
        self.bag = bag
210
        mnubtnactions = self.gui.get_widget('mnuBtnActions')
211
        mnubtnactions.set_no_show_all(False)
212
        mnubtnactions.show_all()
213
        visor = self.gui.get_widget('visor')
116 t00mlabs 214
        lblSelectedNotes = self.gui.get_widget('lblSelectedNotes')
113 t00mlabs 215
        flowbox = Gtk.FlowBox()
216
        flowbox.set_valign(Gtk.Align.START)
217
        flowbox.set_max_children_per_line(1)
218
        flowbox.set_selection_mode(Gtk.SelectionMode.NONE)
118 t00mlabs 219
        #~ flowbox.set_filter_func(self.filter_by_bookmark)
117 t00mlabs 220
        self.gui.add_widget('flowbox', flowbox)
113 t00mlabs 221
 
222
        self.hide()
223
        icon_bookmark = self.im.get_icon('bookmark')
224
 
225
        sapnotes = self.db.get_notes()
226
 
227
        lbag = []
228
        for sid in bag:
229
            lbag.append(sid)
230
        lbag.sort()
231
 
232
        for sid in lbag:
233
            row = SAPNoteViewRow(self.app, sid)
234
            flowbox.add(row)
235
 
236
        lblcount = self.gui.get_widget("lblSAPNoteViewCount")
130 t00mlabs 237
        self.log.debug("lblcount: %s (%s)"% (str(lblcount), str(type(lblcount))))
238
        #~ lblcount.set_markup("<span size=\"30000\">%d</span>" % len(bag))
113 t00mlabs 239
        self.gui.swap_widget(self, flowbox)
116 t00mlabs 240
 
130 t00mlabs 241
        #~ toggled = self.get_toggled()
242
        #~ lblSelectedNotes.set_markup('<b><small>%d</small>/%d of <big>%d</big></b>' % (len(toggled), len(bag), self.db.get_total()))
117 t00mlabs 243
 
113 t00mlabs 244
        self.show_all()
245
 
246
 
247