Subversion Repositories basico

Rev

Rev 131 | Rev 134 | 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
133 t00mlabs 6
# Description: SAPNoteViewVisor widget
113 t00mlabs 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
 
26
 
27
class SAPNoteViewVisor(Gtk.Box):
28
    def __init__(self, app):
29
        self.app = app
30
        self.get_services()
31
        self.toggled = 0
32
        self.selected = set()
33
        self.count = 0
34
        Gtk.Box.__init__(self)
35
 
36
 
37
    def get_services(self):
38
        self.gui = self.app.get_service("GUI")
39
        self.cb = self.app.get_service('Callbacks')
40
        self.menu = self.app.get_service("Menus")
41
        self.sap = self.app.get_service('SAP')
42
        self.im = self.app.get_service('IM')
43
        self.settings = self.app.get_service('Settings')
126 t00mlabs 44
        #~ self.plugins = self.app.get_service('Plugins')
113 t00mlabs 45
        self.db = self.app.get_service('DB')
46
        self.uif = self.app.get_service("UIF")
47
 
48
 
49
 
50
    def prepare(self):
51
        self.set_hexpand(True)
52
        self.set_property('fill', True)
131 t00mlabs 53
        self.modify_bg(Gtk.StateType.NORMAL, Gdk.color_parse("White"))
54
        for widget_name in ['boxVisor', 'scrVisor', 'vwpVisor']:
55
            widget = self.gui.get_widget(widget_name)
56
            widget.modify_bg(Gtk.StateType.NORMAL, Gdk.color_parse("White"))
113 t00mlabs 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()
131 t00mlabs 93
        row.modify_bg(Gtk.StateType.NORMAL, Gdk.color_parse("Gold"))
113 t00mlabs 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)
167
 
131 t00mlabs 168
        #~ container.modify_bg(Gtk.StateType.NORMAL, Gdk.color_parse("Red"))
169
 
113 t00mlabs 170
        return container
171
 
172
 
117 t00mlabs 173
    def get_toggled(self):
174
        flowbox = self.gui.get_widget('flowbox')
130 t00mlabs 175
        mnubtnactions = self.gui.get_widget('mnuBtnActions')
117 t00mlabs 176
 
177
        toggled = set()
178
        def foreach_row(item):
179
            row = item.get_children()[0]
180
            active = row.get_checkbox_is_active()
181
            if active:
182
                sid = row.get_sid()
183
                toggled.add(sid)
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
        self.gui.swap_widget(self, flowbox)
116 t00mlabs 237
 
113 t00mlabs 238
        self.show_all()
239
 
240
 
241