Subversion Repositories basico

Rev

Rev 126 | 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: sapnoteviewrow.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 .log import get_logger
25
 
26
 
27
class SAPNoteViewRow(Gtk.HBox):
28
    def __init__(self, app, sid):
29
        Gtk.HBox.__init__(self)
30
        self.app = app
131 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.setup_row(sid)
36
 
37
 
38
    def get_services(self):
39
        self.gui = self.app.get_service("GUI")
40
        self.cb = self.app.get_service('Callbacks')
41
        self.menu = self.app.get_service("Menus")
42
        self.sap = self.app.get_service('SAP')
43
        self.im = self.app.get_service('IM')
44
        self.settings = self.app.get_service('Settings')
126 t00mlabs 45
        #~ self.plugins = self.app.get_service('Plugins')
113 t00mlabs 46
        self.db = self.app.get_service('DB')
47
        self.uif = self.app.get_service("UIF")
48
 
49
 
117 t00mlabs 50
    def get_checkbox_is_active(self):
51
        return self.checkbox.get_active()
52
 
53
 
54
    def get_sid(self):
55
        return self.sid
56
 
57
 
58
    def toggle_checkbox(self, button):
59
        visor = self.gui.get_widget('visor')
60
        lblSelectedNotes = self.gui.get_widget('lblSelectedNotes')
61
        toggled = visor.get_toggled()
62
        bag = visor.get_bag()
63
        lblSelectedNotes.set_markup('<b><small>%d</small>/%d of <big>%d</big></b>' % (len(toggled), len(bag), self.db.get_total()))
131 t00mlabs 64
 
65
        reveal = self.revealer.get_reveal_child()
66
        self.revealer.set_reveal_child(not reveal)
67
        self.revealer.set_visible(True)
68
 
117 t00mlabs 69
        #~ self.log.debug("Toggled rows: %d" % len(toggled))
70
 
71
 
72
    def bookmark_switch(self, *args):
119 t00mlabs 73
        if self.bookmark.get_active():
74
            icon = self.im.get_pixbuf_icon('bookmark_on', 16, 16)
118 t00mlabs 75
            self.bookmark_image.set_from_pixbuf(icon)
76
            self.cb.bookmark([self.sid])
77
        else:
119 t00mlabs 78
            icon = self.im.get_pixbuf_icon('bookmark_off', 16, 16)
118 t00mlabs 79
            self.bookmark_image.set_from_pixbuf(icon)
80
            self.cb.unbookmark([self.sid])
117 t00mlabs 81
 
82
 
119 t00mlabs 83
    def dummy(self, *args):
84
        self.popover.hide()
118 t00mlabs 85
 
117 t00mlabs 86
 
113 t00mlabs 87
    def setup_row(self, sid):
117 t00mlabs 88
        self.sid = sid
113 t00mlabs 89
        sapnote = self.get_node_sapnote(sid)
131 t00mlabs 90
        vbox = Gtk.VBox()
91
        hboxup = Gtk.HBox()
92
        hboxdown = Gtk.HBox()
113 t00mlabs 93
 
131 t00mlabs 94
        #~ self.modify_bg(Gtk.StateType.NORMAL, Gdk.color_parse("White"))
113 t00mlabs 95
        self.set_hexpand(True)
131 t00mlabs 96
        hboxup.set_hexpand(True)
97
        hboxdown.set_hexpand(True)
98
        vbox.set_vexpand(False)
113 t00mlabs 99
 
100
        # row items widgets
119 t00mlabs 101
        # CHECKBOX BUTTON
117 t00mlabs 102
        self.checkbox = Gtk.CheckButton()
103
        self.checkbox.connect('toggled', self.toggle_checkbox)
131 t00mlabs 104
        hboxup.pack_start(self.checkbox, False, False, 6)
113 t00mlabs 105
 
119 t00mlabs 106
        # BOOKMARK BUTTON
117 t00mlabs 107
        icon = self.im.get_pixbuf_icon('bookmark_off', 16, 16)
108
        self.bookmark_image = Gtk.Image()
109
        self.bookmark_image.set_from_pixbuf(icon)
119 t00mlabs 110
        self.bookmark = Gtk.ToggleButton()
111
        self.bookmark.set_relief(Gtk.ReliefStyle.NONE)
112
        self.bookmark.set_active(sapnote['bookmark'])
113
        if self.bookmark.get_active():
117 t00mlabs 114
            icon = self.im.get_pixbuf_icon('bookmark_on', 16, 16)
115
            self.bookmark_image.set_from_pixbuf(icon)
116
        else:
117
            icon = self.im.get_pixbuf_icon('bookmark_off', 16, 16)
118
            self.bookmark_image.set_from_pixbuf(icon)
119 t00mlabs 119
        self.bookmark.add(self.bookmark_image)
120
        self.bookmark.connect('toggled', self.bookmark_switch)
131 t00mlabs 121
        hboxup.pack_start(self.bookmark, False, False, 0)
113 t00mlabs 122
 
122 t00mlabs 123
        # SAP NOTE ID
121 t00mlabs 124
        btnsid = Gtk.Button()
125
        btnsid.set_relief(Gtk.ReliefStyle.NONE)
122 t00mlabs 126
        btnsid.set_hexpand(False)
113 t00mlabs 127
        lblsid = Gtk.Label()
122 t00mlabs 128
        lblsid.set_hexpand(False)
121 t00mlabs 129
        lblsid.modify_font(Pango.FontDescription('Monospace 10'))
130
        title = "<b>%10s</b>" % str(int(sid))
122 t00mlabs 131
        lblsid.set_markup("%10s" % title)
121 t00mlabs 132
        btnsid.add(lblsid)
131 t00mlabs 133
        hboxup.pack_start(btnsid, False, False, 0)
121 t00mlabs 134
 
122 t00mlabs 135
        # SAP NOTE TITLE
121 t00mlabs 136
        lblsid = Gtk.Label()
137
        title = escape("%s" % (sapnote['title']))
138
        lblsid.set_markup("%s" % title)
113 t00mlabs 139
        lblsid.set_justify(Gtk.Justification.LEFT)
140
        lblsid.set_xalign(0.0)
141
        lblsid.set_selectable(True)
131 t00mlabs 142
        lblsid.set_hexpand(True)
116 t00mlabs 143
        lblsid.set_property('ellipsize', Pango.EllipsizeMode.MIDDLE)
113 t00mlabs 144
        lblsid.modify_font(Pango.FontDescription('Monospace 10'))
131 t00mlabs 145
        hboxup.pack_start(lblsid, True, True, 0)
113 t00mlabs 146
 
121 t00mlabs 147
        # SAP NOTE INFO
131 t00mlabs 148
        # Popover button
149
        icon = self.im.get_pixbuf_icon('info', 16, 16)
150
        img = Gtk.Image()
151
        img.set_from_pixbuf(icon)
152
        button = Gtk.Button()
153
        button.add(img)
154
        button.set_relief(Gtk.ReliefStyle.NONE)
155
        button.set_alignment (0.0, 0.0)
156
        button.set_hexpand(False)
157
        self.popover = Gtk.Popover.new(button)
158
        button.connect('clicked', self.cb.show_popover, self.popover)
159
        hboxup.pack_start(button, False, False, 6)
121 t00mlabs 160
 
131 t00mlabs 161
        # Popover body
162
        box = Gtk.Box(spacing = 0, orientation="vertical")
163
        vboxfs = Gtk.Box(spacing = 3, orientation="vertical")
121 t00mlabs 164
 
131 t00mlabs 165
        # Properties
166
        propview = Gtk.TreeView()
167
        model = Gtk.ListStore(str, str, str)
168
        #~ ## key
169
        renderer = Gtk.CellRendererText()
170
        renderer.set_property('background', 'Lemon Chiffon')
171
        column = Gtk.TreeViewColumn('Id', renderer, text=0)
172
        column.set_visible(False)
173
        column.set_clickable(False)
174
        column.set_sort_indicator(False)
175
        propview.append_column(column)
121 t00mlabs 176
 
131 t00mlabs 177
        # Property
178
        renderer = Gtk.CellRendererText()
179
        renderer.set_property('background', 'Light Steel Blue')
180
        renderer.set_alignment(1.0, 0.5)
181
        column = Gtk.TreeViewColumn('Property', renderer, markup=1)
182
        column.set_visible(True)
183
        column.set_expand(False)
184
        column.set_clickable(False)
185
        #~ column.set_sort_indicator(True)
186
        propview.append_column(column)
121 t00mlabs 187
 
131 t00mlabs 188
        # Value
189
        renderer = Gtk.CellRendererText()
190
        renderer.set_property('background', 'White Smoke')
191
        renderer.set_alignment(0.0, 0.5)
192
        column = Gtk.TreeViewColumn('Value', renderer, markup=2)
193
        column.set_visible(True)
194
        column.set_expand(True)
195
        column.set_clickable(True)
196
        #~ column.set_sort_indicator(True)
197
        propview.append_column(column)
198
        propview.show_all()
121 t00mlabs 199
 
131 t00mlabs 200
        propview.set_headers_visible(True)
201
        propview.set_enable_search(False)
202
        propview.set_grid_lines(Gtk.TreeViewGridLines.HORIZONTAL)
203
        #~ propview.set_search_column(2)
204
        #~ trvprops.connect('row-activated', self.double_click)
205
        selection = propview.get_selection()
206
        selection.set_mode(Gtk.SelectionMode.SINGLE)
121 t00mlabs 207
 
131 t00mlabs 208
        for prop in ["id", "title", "componentkey", "componenttxt", "category",  "priority", "type", "language", "releaseon", "version", "feedupdate"]:
209
            model.append([prop, "<b>%s</b>" % prop.capitalize(), "%s" % sapnote[prop]])
121 t00mlabs 210
 
131 t00mlabs 211
        propview.set_model(model)
212
        vboxfs.pack_start(propview, False, False, 0)
213
        box.add(vboxfs)
214
        self.popover.add(box)
121 t00mlabs 215
 
131 t00mlabs 216
        #VBox down
217
        self.revealer = Gtk.Revealer()
218
        label = Gtk.Label("Label in a Revealer")
219
        self.revealer.add(label)
220
        self.revealer.set_reveal_child(False)
221
        self.revealer.set_visible(False)
222
        hboxdown.pack_start(self.revealer, False, False, 0)
223
 
224
        vbox.pack_start(hboxup, True, True, 0)
225
        vbox.pack_start(hboxdown, True, True, 0)
226
        self.pack_start(vbox, True, True, 0)
113 t00mlabs 227
        self.show_all()
131 t00mlabs 228
        #~ self.log.debug("Adios")
113 t00mlabs 229
 
119 t00mlabs 230
        #~ self.bookmark.get_style_context().add_class(Gtk.STYLE_CLASS_DESTRUCTIVE_ACTION)
113 t00mlabs 231
 
232
 
233
 
234
    def get_node_sapnote(self, sid):
235
        sapnotes = self.db.get_notes()
236
        return sapnotes[sid]