Subversion Repositories basico

Rev

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

Rev Author Line No. Line
340 t00mlabs 1
#!/usr/bin/python
2
# -*- coding: utf-8 -*-
3
"""
4
# File: wdg_visor_toolbar.py
5
# Author: Tomás Vírseda
6
# License: GPL v3
7
# Description: SAPNoteViewVisorToolbar widgets
8
"""
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
from basico.core.mod_wdg import BasicoWidget
17
 
18
 
19
class VisorToolbar(BasicoWidget, Gtk.HBox):
20
    def __init__(self, app):
21
        super().__init__(app, __class__.__name__)
22
        Gtk.Box.__init__(self)
23
        self.get_services()
24
        self.set_homogeneous(False)
25
        self.tool_bar = Gtk.Toolbar()
26
        self.pack_start(self.tool_bar, False, True, 0)
27
        self.tool_bar.get_style_context().add_class(Gtk.STYLE_CLASS_PRIMARY_TOOLBAR)
28
        self.tool_bar.set_property('margin-bottom', 0)
29
 
30
 
31
        # Import button
32
        tool = Gtk.ToolButton()
33
        tool.set_icon_name('basico-add')
34
        tool.set_tooltip_markup('<b>Download or find SAP Notes (if they were already downloaded)</b>')
35
        popover = self.srvgui.add_widget('gtk_popover_toolbutton_import', Gtk.Popover.new(tool))
36
        tool.connect('clicked', self.srvclb.gui_show_popover, popover)
37
        self.tool_bar.insert(tool, -1)
38
 
39
        ## Popover body
40
        box = Gtk.VBox(spacing = 0, orientation="vertical")
41
        box.set_property('margin', 3)
42
        widget_import = self.srvgui.add_widget('widget_import', ImportWidget(self.app))
43
        box.pack_start(widget_import, True, True, 6)
44
        popover.add(box)
45
 
46
        # Annotation button
47
        tool = Gtk.ToolButton()
48
        tool.set_icon_name('basico-annotation')
49
        tool.set_tooltip_markup('<b>Create a new annotation (not linked to any SAP Note)</b>')
50
        popover = self.srvgui.add_widget('gtk_popover_annotation', Gtk.Popover.new(tool))
51
        tool.connect('clicked', self.srvclb.gui_annotation_widget_show)
52
        self.tool_bar.insert(tool, -1)
53
 
353 t00mlabs 54
        # Attachment button
55
        tool = Gtk.ToolButton()
56
        tool.set_icon_name('basico-attachment')
57
        tool.set_tooltip_markup('<b>Attach any document to this annotation</b>')
58
        popover = self.srvgui.add_widget('gtk_button_main_toolbar_attachment', Gtk.Popover.new(tool))
356 t00mlabs 59
        tool.connect('clicked', self.srvclb.gui_attachment_add)
353 t00mlabs 60
        self.tool_bar.insert(tool, -1)
340 t00mlabs 61
 
62
        # Filter entry
63
 
64
        ## Completion
65
        self.completion = self.srvgui.add_widget('gtk_entrycompletion_visor', Gtk.EntryCompletion())
66
        self.completion.set_match_func(self.completion_match_func)
67
        self.completion_model = Gtk.ListStore(str)
68
        self.completion.set_model(self.completion_model)
69
        self.completion.set_text_column(0)
70
 
71
        tool = Gtk.ToolItem.new()
72
 
73
        hbox = Gtk.HBox()
74
        entry = Gtk.Entry()
75
        entry.set_completion(self.completion)
76
        entry.connect('activate', self.srvclb.gui_filter_visor)
77
        self.srvgui.add_widget('gtk_entry_filter_visor', entry)
78
 
79
        icon = self.srvicm.get_pixbuf_icon('basico-find')
80
        entry.set_icon_from_pixbuf(Gtk.EntryIconPosition.PRIMARY, icon)
81
        entry.set_icon_sensitive(Gtk.EntryIconPosition.PRIMARY, True)
82
        entry.set_icon_tooltip_markup (Gtk.EntryIconPosition.PRIMARY, "Search in the whole database")
83
 
84
        icon = self.srvicm.get_pixbuf_icon('basico-filter')
85
        entry.set_icon_from_pixbuf(Gtk.EntryIconPosition.SECONDARY, icon)
86
        entry.set_icon_sensitive(Gtk.EntryIconPosition.SECONDARY, True)
87
        entry.set_icon_tooltip_markup (Gtk.EntryIconPosition.SECONDARY, "Click here to filter results")
88
        entry.set_placeholder_text("Filter results...")
89
 
90
        def on_icon_pressed(entry, icon_pos, event):
91
            if icon_pos == Gtk.EntryIconPosition.PRIMARY:
92
                self.srvclb.action_search(entry)
93
            elif icon_pos == Gtk.EntryIconPosition.SECONDARY:
94
                self.srvclb.gui_filter_visor(entry)
95
 
96
        entry.connect('changed', self.srvclb.gui_filter_visor)
97
        entry.connect("icon-press", on_icon_pressed)
98
        hbox.pack_start(entry, True, True, 0)
99
        tool.add(hbox)
100
        tool.set_tooltip_markup('<b>Click left icon to search in all the annotations or just type to filter the current view</b>')
101
        tool.set_expand(True)
102
        self.tool_bar.insert(tool, -1)
103
 
104
        # Separator
105
        tool = Gtk.SeparatorToolItem.new()
106
        tool.set_draw(False)
107
        tool.set_expand(True)
108
        self.tool_bar.insert(tool, -1)
109
 
110
        # Button Total SAP Notes
111
        tool = Gtk.ToolItem()
112
        tool.set_expand(False)
113
        label = self.srvgui.add_widget('gtk_label_total_notes', Gtk.Label())
114
        hbox = Gtk.HBox()
115
        hbox.pack_start(label, False, False, 0)
116
        tool.add(hbox)
117
        self.tool_bar.insert(tool, -1)
118
 
119
        # Fullscreen toggle button
354 t00mlabs 120
        # ~ tool = Gtk.ToolItem()
121
        # ~ tool.set_expand(False)
122
        # ~ icon = self.srvicm.get_new_image_icon('basico-fullscreen', 24, 24)
123
        # ~ box = self.srvgui.add_widget('gtk_box_container_icon_fullscreen', Gtk.Box())
124
        # ~ box.pack_start(icon, False, False, 0)
125
        # ~ button = Gtk.ToggleButton()
126
        # ~ button.set_relief(Gtk.ReliefStyle.NONE)
127
        # ~ button.connect('toggled', self.srvclb.gui_toggle_fullscreen)
128
        # ~ button.add(box)
129
        # ~ tool.add(button)
130
        # ~ tool.set_tooltip_markup('<b>Fullscreen/Window mode</b>')
131
        # ~ self.tool_bar.insert(tool, -1)
340 t00mlabs 132
 
133
        # Toolbar initial settings
134
        self.set_visible(True)
135
        self.set_no_show_all(False)
136
        self.tool_bar.set_hexpand(True)
137
 
138
 
139
    def get_services(self):
140
        self.srvgui = self.get_service("GUI")
141
        self.srvclb = self.get_service('Callbacks')
142
        self.srvsap = self.get_service('SAP')
143
        self.srvicm = self.get_service('IM')
144
        self.srvstg = self.get_service('Settings')
145
        self.srvdtb = self.get_service('DB')
146
        self.srvuif = self.get_service("UIF")
147
 
148
 
149
    def completion_match_func(self, completion, key, iter):
150
        model = completion.get_model()
151
        text = model.get_value(iter, 0)
152
        if key.upper() in text.upper():
153
            return True
154
        return False