Subversion Repositories basico

Rev

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

Rev Author Line No. Line
254 t00m 1
#!/usr/bin/python
2
# -*- coding: utf-8 -*-
264 t00m 3
"""
254 t00m 4
# File: wdg_visor_toolbar.py
5
# Author: Tomás Vírseda
6
# License: GPL v3
7
# Description: SAPNoteViewVisorToolbar widgets
264 t00m 8
"""
254 t00m 9
 
10
 
11
import gi
12
gi.require_version('Gtk', '3.0')
13
from gi.repository import Gtk
14
from basico.widgets.wdg_cols import CollectionsMgtView
15
from basico.widgets.wdg_import import ImportWidget
16
 
17
 
18
class VisorToolbar(Gtk.HBox):
19
    def __init__(self, app):
20
        Gtk.Box.__init__(self, app)
21
        self.app = app
22
        self.get_services()
23
        self.set_homogeneous(False)
24
        self.tool_bar = Gtk.Toolbar()
25
        self.pack_start(self.tool_bar, False, True, 0)
26
        self.tool_bar.get_style_context().add_class(Gtk.STYLE_CLASS_PRIMARY_TOOLBAR)
27
        self.tool_bar.set_property('margin-bottom', 0)
28
 
29
        # Toggle Views button
272 t00m 30
        # ~ tool = self.srvgui.add_widget('gtk_toogletoolbutton_menu_view', Gtk.ToggleToolButton.new())
31
        # ~ tool.set_icon_name('gtk-select-color')
32
        # ~ tool.set_tooltip_markup('<b>Show/Hide menu view</b>')
33
        # ~ tool.connect('toggled', self.srvclb.gui_toggle_menu_view)
34
        # ~ tool.set_active(False)
35
        # ~ tool.set_hexpand(False)
36
        # ~ self.tool_bar.insert(tool, -1)
254 t00m 37
 
38
 
39
        # Import button
40
        tool = Gtk.ToolButton()
41
        tool.set_icon_name('basico-add')
271 t00m 42
        tool.set_tooltip_markup('<b>Download or find SAP Notes (if they were already downloaded)</b>')
254 t00m 43
        popover = self.srvgui.add_widget('gtk_popover_toolbutton_import', Gtk.Popover.new(tool))
44
        tool.connect('clicked', self.srvclb.gui_show_popover, popover)
45
        self.tool_bar.insert(tool, -1)
46
 
47
        ## Popover body
48
        box = Gtk.VBox(spacing = 0, orientation="vertical")
49
        box.set_property('margin', 3)
50
        widget_import = self.srvgui.add_widget('widget_import', ImportWidget(self.app))
51
        box.pack_start(widget_import, True, True, 6)
52
        popover.add(box)
53
 
54
        # Annotation button
55
        tool = Gtk.ToolButton()
56
        tool.set_icon_name('basico-annotation')
271 t00m 57
        tool.set_tooltip_markup('<b>Create a new annotation (not linked to any SAP Note)</b>')
254 t00m 58
        popover = self.srvgui.add_widget('gtk_popover_annotation', Gtk.Popover.new(tool))
59
        # ~ tool.connect('clicked', self.srvclb.gui_show_popover, popover)
60
        tool.connect('clicked', self.srvclb.gui_annotation_widget_show)
61
        self.tool_bar.insert(tool, -1)
62
 
63
        ## Popover body
64
        # ~ box = Gtk.VBox(spacing = 0, orientation="vertical")
65
        # ~ box.set_property('margin', 3)
66
        # ~ widget_import = self.srvgui.add_widget('widget_annotation', AnnotationWidget(self.app))
67
        # ~ box.pack_start(widget_import, True, True, 6)
68
        # ~ popover.add(box)
69
 
70
 
71
        # Filter entry
72
 
73
        ## Completion
74
        self.completion = self.srvgui.add_widget('gtk_entrycompletion_visor', Gtk.EntryCompletion())
75
        self.completion.set_match_func(self.completion_match_func)
76
        self.completion_model = Gtk.ListStore(str)
77
        self.completion.set_model(self.completion_model)
78
        self.completion.set_text_column(0)
79
 
80
        tool = Gtk.ToolItem.new()
81
 
82
        hbox = Gtk.HBox()
83
        entry = Gtk.Entry()
84
        entry.set_completion(self.completion)
85
        entry.connect('activate', self.srvclb.gui_filter_visor)
86
        self.srvgui.add_widget('gtk_entry_filter_visor', entry)
87
 
88
        icon = self.srvicm.get_pixbuf_icon('basico-find')
89
        entry.set_icon_from_pixbuf(Gtk.EntryIconPosition.PRIMARY, icon)
90
        entry.set_icon_sensitive(Gtk.EntryIconPosition.PRIMARY, True)
91
        entry.set_icon_tooltip_markup (Gtk.EntryIconPosition.PRIMARY, "Search in the whole database")
92
 
93
        icon = self.srvicm.get_pixbuf_icon('basico-filter')
94
        entry.set_icon_from_pixbuf(Gtk.EntryIconPosition.SECONDARY, icon)
95
        entry.set_icon_sensitive(Gtk.EntryIconPosition.SECONDARY, True)
96
        entry.set_icon_tooltip_markup (Gtk.EntryIconPosition.SECONDARY, "Click here to filter results")
97
        entry.set_placeholder_text("Filter results...")
98
 
99
        def on_icon_pressed(entry, icon_pos, event):
100
            if icon_pos == Gtk.EntryIconPosition.PRIMARY:
101
                self.srvclb.action_search(entry)
102
            elif icon_pos == Gtk.EntryIconPosition.SECONDARY:
103
                self.srvclb.gui_filter_visor(entry)
104
 
105
        entry.connect('changed', self.srvclb.gui_filter_visor)
106
        entry.connect("icon-press", on_icon_pressed)
107
        hbox.pack_start(entry, True, True, 0)
108
        tool.add(hbox)
271 t00m 109
        tool.set_tooltip_markup('<b>Click left icon to search in all the annotations or just type to filter the current view</b>')
254 t00m 110
        tool.set_expand(True)
111
        self.tool_bar.insert(tool, -1)
112
 
113
        # ~ Separator
114
        tool = Gtk.SeparatorToolItem.new()
115
        tool.set_draw(False)
116
        tool.set_expand(True)
117
        self.tool_bar.insert(tool, -1)
118
 
277 t00m 119
        # View combobox button/popover
120
        tool = Gtk.ToolItem.new()
121
        lhbox = Gtk.HBox()
122
        menuviews = self.srvgui.add_widget('gtk_button_menu_views', Gtk.Button())
123
        menuviews.set_relief(Gtk.ReliefStyle.NONE)
124
        hbox = Gtk.HBox()
125
        label = self.srvgui.add_widget('gtk_label_current_view', Gtk.Label())
126
        label.set_xalign(0.0)
127
        image = self.srvgui.add_widget('gtk_image_current_view', Gtk.Image())
128
        hbox.pack_start(image, False, False, 3)
129
        hbox.pack_start(label, True, True, 3)
130
        menuviews.add(hbox)
131
        lhbox.pack_start(menuviews, True, True, 3)
132
        lhbox.show_all()
133
        tool.add(lhbox)
134
        tool.set_tooltip_markup('<b>Choose another view</b>')
135
        tool.set_expand(False)
136
        self.tool_bar.insert(tool, -1)
137
 
138
        ### Popover menuviews
139
        popover = self.srvgui.add_widget('gtk_popover_button_menu_views', Gtk.Popover.new(menuviews))
140
        menuviews.connect('clicked', self.srvclb.gui_show_popover, popover)
141
        box = Gtk.Box(spacing = 0, orientation="vertical")
142
        popover.add(box)
143
 
144
        box.pack_start(self.srvuif.create_menuview_button('collection'), False, False, 0)
145
        separator = Gtk.Separator(orientation = Gtk.Orientation.HORIZONTAL)
146
        box.pack_start(separator, False, False, 0)
147
        box.pack_start(self.srvuif.create_menuview_button('component'), False, False, 0)
148
        box.pack_start(self.srvuif.create_menuview_button('description'), False, False, 0)
149
        box.pack_start(self.srvuif.create_menuview_button('bookmarks'), False, False, 0)
150
        box.pack_start(self.srvuif.create_menuview_button('category'), False, False, 0)
151
        box.pack_start(self.srvuif.create_menuview_button('chronologic'), False, False, 0)
152
        box.pack_start(self.srvuif.create_menuview_button('priority'), False, False, 0)
153
        box.pack_start(self.srvuif.create_menuview_button('type'), False, False, 0)
154
 
254 t00m 155
        # Button Total SAP Notes
156
        tool = Gtk.ToolItem()
157
        tool.set_expand(False)
158
        label = self.srvgui.add_widget('gtk_label_total_notes', Gtk.Label())
159
        hbox = Gtk.HBox()
160
        hbox.pack_start(label, False, False, 0)
161
        tool.add(hbox)
162
        self.tool_bar.insert(tool, -1)
163
 
277 t00m 164
 
254 t00m 165
        # Fullscreen toggle button
166
        tool = Gtk.ToolItem()
167
        tool.set_expand(False)
168
        icon = self.srvicm.get_new_image_icon('basico-fullscreen', 24, 24)
169
        box = self.srvgui.add_widget('gtk_box_container_icon_fullscreen', Gtk.Box())
170
        box.pack_start(icon, False, False, 0)
171
        button = Gtk.ToggleButton()
172
        button.set_relief(Gtk.ReliefStyle.NONE)
173
        button.connect('toggled', self.srvclb.gui_toggle_fullscreen)
174
        button.add(box)
175
        tool.add(button)
271 t00m 176
        tool.set_tooltip_markup('<b>Fullscreen/Window mode</b>')
254 t00m 177
        self.tool_bar.insert(tool, -1)
178
 
179
        # Toolbar initial settings
180
        self.set_visible(True)
181
        self.set_no_show_all(False)
182
        self.tool_bar.set_hexpand(True)
183
 
184
 
185
    def get_services(self):
186
        self.srvgui = self.app.get_service("GUI")
187
        self.srvclb = self.app.get_service('Callbacks')
188
        self.srvsap = self.app.get_service('SAP')
189
        self.srvicm = self.app.get_service('IM')
190
        self.srvstg = self.app.get_service('Settings')
191
        self.srvdtb = self.app.get_service('DB')
192
        self.srvuif = self.app.get_service("UIF")
193
 
194
 
195
    def completion_match_func(self, completion, key, iter):
196
        model = completion.get_model()
197
        text = model.get_value(iter, 0)
198
        if key.upper() in text.upper():
199
            return True
200
        return False
201
 
202
 
203
    def build_popover(self, popover):
204
        box = Gtk.Box(spacing = 3, orientation="vertical")
205
        sid = '0000000000'
206
 
207
        def get_popover_button(text, icon_name):
208
            button = Gtk.Button()
209
            button.set_relief(Gtk.ReliefStyle.NONE)
210
            hbox = Gtk.HBox()
211
            icon = self.srvicm.get_new_image_icon(icon_name, 24, 24)
212
            lbltext = Gtk.Label()
213
            lbltext.set_xalign(0.0)
214
            lbltext.set_markup('%s' % text)
215
            hbox.pack_start(icon, False, False, 3)
216
            hbox.pack_start(lbltext, True, True, 3)
217
            button.add(hbox)
218
            return button
219
 
220
        # Popover button "Bookmark"
221
        button = get_popover_button("(Un)bookmark SAP Notes", 'basico-bookmarks')
222
        button.connect('clicked', self.srvclb.switch_bookmark_current_set, popover)
223
        box.pack_start(button, False, False, 0)
224
 
225
        # Separator
226
        separator = Gtk.Separator(orientation = Gtk.Orientation.HORIZONTAL)
227
        box.pack_start(separator, True, True, 0)
228
 
229
        # Popover button Collection Management
230
        button = get_popover_button("Manage collections", 'basico-collection')
231
        box.pack_start(button, False, False, 0)
232
        self.popcollections = self.srvgui.add_widget('gtk_popover_button_manage_collections_selected_notes', Gtk.Popover.new(button))
233
        self.popcollections.set_position(Gtk.PositionType.RIGHT)
234
        button.connect('clicked', self.srvclb.gui_show_popover, self.popcollections)
235
        self.popcollections.add(CollectionsMgtView(self.app, sid, self.popcollections))
236
 
237
        # Separator
238
        separator = Gtk.Separator(orientation = Gtk.Orientation.HORIZONTAL)
239
        box.pack_start(separator, True, True, 0)
240
 
241
 
242
        # Popover button "Delete SAP Notes"
243
        button = get_popover_button("Delete SAP Notes", 'basico-delete')
244
        button.connect('clicked', self.srvclb.sapnote_delete, sid)
245
        box.pack_start(button, False, False, 0)
246
 
247
        return box