Subversion Repositories basico

Rev

Rev 117 | Rev 119 | 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
31
        LOG_FILE = self.app.get_file('LOG')
32
        LOG_NAME = self.__class__.__name__
117 t00mlabs 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')
48
        self.plugins = self.app.get_service('Plugins')
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]
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
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')
174
 
175
        toggled = set()
176
        def foreach_row(item):
177
            row = item.get_children()[0]
178
            active = row.get_checkbox_is_active()
179
            if active:
180
                sid = row.get_sid()
181
                toggled.add(sid)
182
                #~ self.log.debug("%s -> %s" % (row, active))
183
 
184
        flowbox.foreach(foreach_row)
185
        lsid = list(toggled)
186
        lsid.sort()
187
 
188
        return lsid
189
 
190
 
191
    def get_bag(self):
192
        return self.bag
193
 
194
 
195
    def filter_by_bookmark(self, item):
196
        row = item.get_children()[0]
197
        return row.is_bookmark()
198
 
199
 
113 t00mlabs 200
    def populate(self, bag):
117 t00mlabs 201
        self.bag = bag
202
        mnubtnactions = self.gui.get_widget('mnuBtnActions')
203
        mnubtnactions.set_no_show_all(False)
204
        mnubtnactions.show_all()
205
        visor = self.gui.get_widget('visor')
116 t00mlabs 206
        lblSelectedNotes = self.gui.get_widget('lblSelectedNotes')
113 t00mlabs 207
        flowbox = Gtk.FlowBox()
208
        flowbox.set_valign(Gtk.Align.START)
209
        flowbox.set_max_children_per_line(1)
210
        flowbox.set_selection_mode(Gtk.SelectionMode.NONE)
118 t00mlabs 211
        #~ flowbox.set_filter_func(self.filter_by_bookmark)
117 t00mlabs 212
        self.gui.add_widget('flowbox', flowbox)
113 t00mlabs 213
 
214
        self.hide()
215
        icon_bookmark = self.im.get_icon('bookmark')
216
 
217
        sapnotes = self.db.get_notes()
218
 
219
        lbag = []
220
        for sid in bag:
221
            lbag.append(sid)
222
        lbag.sort()
223
 
224
        for sid in lbag:
225
            row = SAPNoteViewRow(self.app, sid)
226
            flowbox.add(row)
227
 
228
        lblcount = self.gui.get_widget("lblSAPNoteViewCount")
229
        lblcount.set_markup("<span size=\"30000\">%d</span>" % len(bag))
230
        self.gui.swap_widget(self, flowbox)
116 t00mlabs 231
 
117 t00mlabs 232
        toggled = self.get_toggled()
233
        lblSelectedNotes.set_markup('<b><small>%d</small>/%d of <big>%d</big></b>' % (len(toggled), len(bag), self.db.get_total()))
234
 
113 t00mlabs 235
        self.show_all()
236
 
237
 
238