Subversion Repositories basico

Rev

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

Rev Author Line No. Line
106 t00mlabs 1
#!/usr/bin/python
2
# -*- coding: utf-8 -*-
3
# File: sapnoteview.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
 
111 t00mlabs 12
import gi
13
gi.require_version('Gdk', '3.0')
14
gi.require_version('Gtk', '3.0')
108 t00mlabs 15
from gi.repository import Gdk
109 t00mlabs 16
from gi.repository import Gio
111 t00mlabs 17
from gi.repository import Gtk
18
from gi.repository import Pango
106 t00mlabs 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
 
113 t00mlabs 26
 
106 t00mlabs 27
#~ Enum(value='Column', names=<...>, *, module='...', qualname='...', type=<mixed-in class>, start=1)
28
 
29
class Column(IntEnum):
30
    rowtype = 0
31
    checkbox = 1
32
    icon = 2
33
    component = 3
34
    category = 4
35
    type = 5
36
    id = 6
37
    title = 7
38
    priority = 8
39
    language = 9
40
    released = 10
41
 
42
 
43
class SAPNoteView(Gtk.TreeView):
44
    def __init__(self, app):
45
        self.app = app
46
        LOG_FILE = self.app.get_file('LOG')
47
        LOG_NAME = self.__class__.__name__
48
        self.log = get_logger(LOG_NAME, LOG_FILE)
49
        self.get_services()
50
        self.toggled = 0
51
        self.selected = set()
52
        self.count = 0
53
 
54
 
55
        # Setup treeview and model
56
        Gtk.TreeView.__init__(self)
57
        self.model = Gtk.TreeStore(
58
            str,            # RowType@RowId
59
            bool,           # CheckBox
60
            Pixbuf,         # Icon
61
            str,            # Component key
62
            str,            # Category
63
            str,            # Type
64
            str,            # SAP Note Id
65
            str,            # Title
66
            str,            # Priority
67
            str,            # Language
68
            str             # Release date
69
        )
70
        self.set_model(self.model)
71
 
72
        # Setup columns
73
        # RowType
74
        self.renderer_rowtype = Gtk.CellRendererText()
75
        self.column_rowtype = Gtk.TreeViewColumn('', self.renderer_rowtype, text=Column.rowtype.value)
76
        self.column_rowtype.set_visible(False)
77
        self.column_rowtype.set_expand(False)
78
        self.column_rowtype.set_clickable(False)
79
        self.column_rowtype.set_sort_indicator(False)
80
        self.append_column(self.column_rowtype)
81
 
82
        # Checkbox
83
        self.renderer_checkbox = Gtk.CellRendererToggle()
113 t00mlabs 84
        #~ self.renderer_checkbox.connect("toggled", self.on_cell_toggled)
106 t00mlabs 85
        self.column_checkbox = Gtk.TreeViewColumn('', self.renderer_checkbox, active=1)
86
        self.column_checkbox.set_sizing(Gtk.TreeViewColumnSizing.AUTOSIZE)
87
        self.column_checkbox.set_visible(False)
88
        self.column_checkbox.set_expand(False)
89
        self.column_checkbox.set_clickable(False)
90
        self.column_checkbox.set_sort_indicator(False)
91
        self.append_column(self.column_checkbox)
113 t00mlabs 92
        #~ self.column_checkbox.set_cell_data_func(self.renderer_checkbox, self.cell_data_func)
106 t00mlabs 93
 
94
        # Icon
95
        self.renderer_icon = Gtk.CellRendererPixbuf()
96
        self.renderer_icon.set_alignment(0.0, 0.5)
97
        self.column_icon = Gtk.TreeViewColumn('', self.renderer_icon, pixbuf=2)
98
        self.column_icon.set_sizing(Gtk.TreeViewColumnSizing.AUTOSIZE)
99
        self.column_icon.set_visible(False)
100
        self.column_icon.set_expand(False)
101
        self.column_icon.set_clickable(False)
102
        self.column_icon.set_sort_indicator(False)
103
        self.append_column(self.column_icon)
104
 
105
        # Component key
106
        self.renderer_compkey = Gtk.CellRendererText()
107
        self.renderer_compkey.set_property('background', 'Lemon Chiffon')
108
        self.column_component = Gtk.TreeViewColumn('SAP Notes', self.renderer_compkey, markup=3)
109
        self.column_component.set_visible(True)
110
        self.column_component.set_sizing(Gtk.TreeViewColumnSizing.AUTOSIZE)
111
        self.column_component.set_clickable(True)
112
        self.column_component.set_sort_indicator(True)
113
        self.column_component.set_sort_column_id(3)
114
        self.column_component.set_sort_order(Gtk.SortType.ASCENDING)
115
        self.column_component.set_expand(True)
116
        self.append_column(self.column_component)
117
        expander_column = self.column_component
118
 
119
        # Category
120
        self.renderer_cat = Gtk.CellRendererText()
121
        self.column_cat = Gtk.TreeViewColumn('Category', self.renderer_cat, markup=4)
122
        self.column_cat.set_sizing(Gtk.TreeViewColumnSizing.AUTOSIZE)
123
        self.column_cat.set_visible(False)
124
        self.column_cat.set_expand(False)
125
        self.column_cat.set_clickable(True)
126
        self.column_cat.set_sort_indicator(True)
127
        self.column_cat.set_sort_column_id(4)
128
        self.column_cat.set_sort_order(Gtk.SortType.ASCENDING)
129
        self.append_column(self.column_cat)
130
 
131
        # Type
132
        self.renderer_sntype = Gtk.CellRendererText()
133
        self.column_sntype = Gtk.TreeViewColumn('Type', self.renderer_sntype, markup=5)
134
        self.column_sntype.set_sizing(Gtk.TreeViewColumnSizing.AUTOSIZE)
135
        self.column_sntype.set_visible(False)
136
        self.column_sntype.set_expand(False)
137
        self.column_sntype.set_clickable(True)
138
        self.column_sntype.set_sort_indicator(True)
139
        self.column_sntype.set_sort_column_id(5)
140
        self.column_sntype.set_sort_order(Gtk.SortType.ASCENDING)
141
        self.append_column(self.column_sntype)
142
 
143
        # SAP Note Id
144
        self.renderer_sid = Gtk.CellRendererText()
145
        self.renderer_sid.set_alignment(1.0, 0.5)
146
        self.column_sid = Gtk.TreeViewColumn('SAP Note', self.renderer_sid, markup=6)
147
        self.column_sid.set_visible(False)
148
        self.column_sid.set_expand(False)
149
        self.column_sid.set_clickable(True)
150
        self.column_sid.set_sort_indicator(True)
151
        self.column_sid.set_sort_column_id(6)
152
        self.column_sid.set_sort_order(Gtk.SortType.ASCENDING)
153
        self.append_column(self.column_sid)
154
 
155
        # Title
156
        self.renderer_title = Gtk.CellRendererText()
157
        self.renderer_title.set_property('ellipsize', Pango.EllipsizeMode.MIDDLE)
158
        self.column_title = Gtk.TreeViewColumn('Title', self.renderer_title, markup=7)
159
        self.column_title.set_visible(False)
160
        self.column_title.set_expand(True)
161
        self.column_title.set_clickable(True)
162
        self.column_title.set_sort_indicator(True)
163
        self.column_title.set_sort_column_id(7)
164
        self.column_title.set_sort_order(Gtk.SortType.ASCENDING)
165
        self.append_column(self.column_title)
166
 
167
        # Priority
168
        self.renderer_priority = Gtk.CellRendererText()
169
        self.column_priority = Gtk.TreeViewColumn('Priority', self.renderer_priority, markup=8)
170
        self.column_priority.set_sizing(Gtk.TreeViewColumnSizing.AUTOSIZE)
171
        self.column_priority.set_visible(True)
172
        self.column_priority.set_expand(False)
173
        self.column_priority.set_clickable(True)
174
        self.column_priority.set_sort_indicator(True)
175
        self.column_priority.set_sort_column_id(8)
176
        self.column_priority.set_sort_order(Gtk.SortType.ASCENDING)
177
        self.append_column(self.column_priority)
178
 
179
        # Language
180
        self.renderer_lang = Gtk.CellRendererText()
181
        self.column_lang = Gtk.TreeViewColumn('Language', self.renderer_lang, markup=9)
182
        self.column_lang.set_sizing(Gtk.TreeViewColumnSizing.AUTOSIZE)
183
        self.column_lang.set_visible(False)
184
        self.column_lang.set_expand(False)
185
        self.column_lang.set_clickable(True)
186
        self.column_lang.set_sort_indicator(True)
187
        self.column_lang.set_sort_column_id(9)
188
        self.column_lang.set_sort_order(Gtk.SortType.ASCENDING)
189
        self.append_column(self.column_lang)
190
 
191
        # Release date
192
        self.renderer_reldate = Gtk.CellRendererText()
193
        self.column_rel = Gtk.TreeViewColumn('Released on', self.renderer_reldate, markup=10)
194
        self.column_rel.set_sizing(Gtk.TreeViewColumnSizing.AUTOSIZE)
195
        self.column_rel.set_visible(False)
196
        self.column_rel.set_expand(False)
197
        self.column_rel.set_clickable(True)
198
        self.column_rel.set_sort_indicator(True)
199
        self.column_rel.set_sort_column_id(10)
200
        self.column_rel.set_sort_order(Gtk.SortType.ASCENDING)
201
        self.append_column(self.column_rel)
202
 
203
        # TreeView common
204
        #~ self.set_level_indentation(6)
205
        self.set_can_focus(True)
206
        self.set_headers_visible(False)
207
        self.set_enable_search(True)
208
        self.set_hover_selection(False)
209
        self.set_grid_lines(Gtk.TreeViewGridLines.NONE)
210
        self.set_search_entry(self.gui.get_widget('stySearchInfo'))
211
        self.set_search_column(3)
212
        #~ self.set_row_separator_func(self.row_separator_func)
213
 
214
        # Selection
215
        self.selection = self.get_selection()
113 t00mlabs 216
        #~ self.selection.set_select_function(self.select_function)
106 t00mlabs 217
        self.selection.set_mode(Gtk.SelectionMode.SINGLE)
218
 
219
        # Font
220
        font_desc = Pango.FontDescription('Monospace 10')
221
        if font_desc:
222
            self.modify_font(font_desc)
223
 
224
        # Go live
113 t00mlabs 225
        self.connect('button_press_event', self.single_click)
106 t00mlabs 226
        self.connect('row-activated', self.double_click)
227
        self.connect('cursor-changed', self.row_changed)
228
 
229
        # Custom method to be implemented.
230
        self.prepare()
231
 
232
        self.show_all()
233
 
234
 
235
    def get_services(self):
236
        self.gui = self.app.get_service("GUI")
237
        self.cb = self.app.get_service('Callbacks')
238
        self.menu = self.app.get_service("Menus")
239
        self.sap = self.app.get_service('SAP')
240
        self.im = self.app.get_service('IM')
241
        self.settings = self.app.get_service('Settings')
242
        self.plugins = self.app.get_service('Plugins')
243
        self.db = self.app.get_service('DB')
244
 
245
 
246
 
247
 
248
 
249
 
250
 
251