Subversion Repositories basico

Rev

Rev 254 | Rev 264 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | Download | RSS feed

#!/usr/bin/python
# -*- coding: utf-8 -*-
# File: wdg_visor_toolbar.py
# Author: Tomás Vírseda
# License: GPL v3
# Description: SAPNoteViewVisorToolbar widgets


import gi
gi.require_version('Gtk', '3.0')
from gi.repository import Gtk
from basico.widgets.wdg_cols import CollectionsMgtView
from basico.widgets.wdg_import import ImportWidget


class VisorToolbar(Gtk.HBox):
    def __init__(self, app):
        Gtk.Box.__init__(self, app)
        self.app = app
        self.get_services()
        self.set_homogeneous(False)
        self.tool_bar = Gtk.Toolbar()
        self.pack_start(self.tool_bar, False, True, 0)
        self.tool_bar.get_style_context().add_class(Gtk.STYLE_CLASS_PRIMARY_TOOLBAR)
        self.tool_bar.set_property('margin-bottom', 0)

        # Toggle Views button
        tool = self.srvgui.add_widget('gtk_toogletoolbutton_menu_view', Gtk.ToggleToolButton.new())
        tool.set_icon_name('gtk-select-color')
        tool.connect('toggled', self.srvclb.gui_toggle_menu_view)
        tool.set_active(False)
        tool.set_hexpand(False)
        self.tool_bar.insert(tool, -1)

        # View combobox button/popover
        tool = Gtk.ToolItem.new()
        lhbox = Gtk.HBox()
        menuviews = self.srvgui.add_widget('gtk_button_menu_views', Gtk.Button())
        hbox = Gtk.HBox()
        label = self.srvgui.add_widget('gtk_label_current_view', Gtk.Label())
        label.set_xalign(0.0)
        image = self.srvgui.add_widget('gtk_image_current_view', Gtk.Image())
        hbox.pack_start(image, False, False, 3)
        hbox.pack_start(label, True, True, 3)
        menuviews.add(hbox)
        lhbox.pack_start(menuviews, True, True, 3)
        lhbox.show_all()
        tool.add(lhbox)
        tool.set_expand(False)
        self.tool_bar.insert(tool, -1)

        ### Popover menuviews
        popover = self.srvgui.add_widget('gtk_popover_button_menu_views', Gtk.Popover.new(menuviews))
        menuviews.connect('clicked', self.srvclb.gui_show_popover, popover)
        box = Gtk.Box(spacing = 0, orientation="vertical")
        popover.add(box)


        # ~ box.pack_start(self.srvuif.create_menuview_button('annotation'), False, False, 0)
        box.pack_start(self.srvuif.create_menuview_button('collection'), False, False, 0)
        separator = Gtk.Separator(orientation = Gtk.Orientation.HORIZONTAL)
        box.pack_start(separator, False, False, 0)
        box.pack_start(self.srvuif.create_menuview_button('component'), False, False, 0)
        box.pack_start(self.srvuif.create_menuview_button('description'), False, False, 0)
        box.pack_start(self.srvuif.create_menuview_button('bookmarks'), False, False, 0)
        box.pack_start(self.srvuif.create_menuview_button('category'), False, False, 0)
        box.pack_start(self.srvuif.create_menuview_button('chronologic'), False, False, 0)
        box.pack_start(self.srvuif.create_menuview_button('priority'), False, False, 0)
        box.pack_start(self.srvuif.create_menuview_button('type'), False, False, 0)

        # Import button
        tool = Gtk.ToolButton()
        tool.set_icon_name('basico-add')
        popover = self.srvgui.add_widget('gtk_popover_toolbutton_import', Gtk.Popover.new(tool))
        tool.connect('clicked', self.srvclb.gui_show_popover, popover)
        self.tool_bar.insert(tool, -1)

        ## Popover body
        box = Gtk.VBox(spacing = 0, orientation="vertical")
        box.set_property('margin', 3)
        widget_import = self.srvgui.add_widget('widget_import', ImportWidget(self.app))
        box.pack_start(widget_import, True, True, 6)
        popover.add(box)

        # Annotation button
        tool = Gtk.ToolButton()
        tool.set_icon_name('basico-annotation')
        popover = self.srvgui.add_widget('gtk_popover_annotation', Gtk.Popover.new(tool))
        # ~ tool.connect('clicked', self.srvclb.gui_show_popover, popover)
        tool.connect('clicked', self.srvclb.gui_annotation_widget_show)
        self.tool_bar.insert(tool, -1)

        ## Popover body
        # ~ box = Gtk.VBox(spacing = 0, orientation="vertical")
        # ~ box.set_property('margin', 3)
        # ~ widget_import = self.srvgui.add_widget('widget_annotation', AnnotationWidget(self.app))
        # ~ box.pack_start(widget_import, True, True, 6)
        # ~ popover.add(box)


        # Filter entry

        ## Completion
        self.completion = self.srvgui.add_widget('gtk_entrycompletion_visor', Gtk.EntryCompletion())
        self.completion.set_match_func(self.completion_match_func)
        self.completion_model = Gtk.ListStore(str)
        self.completion.set_model(self.completion_model)
        self.completion.set_text_column(0)

        tool = Gtk.ToolItem.new()

        hbox = Gtk.HBox()
        entry = Gtk.Entry()
        entry.set_completion(self.completion)
        entry.connect('activate', self.srvclb.gui_filter_visor)
        self.srvgui.add_widget('gtk_entry_filter_visor', entry)

        icon = self.srvicm.get_pixbuf_icon('basico-find')
        entry.set_icon_from_pixbuf(Gtk.EntryIconPosition.PRIMARY, icon)
        entry.set_icon_sensitive(Gtk.EntryIconPosition.PRIMARY, True)
        entry.set_icon_tooltip_markup (Gtk.EntryIconPosition.PRIMARY, "Search in the whole database")

        icon = self.srvicm.get_pixbuf_icon('basico-filter')
        entry.set_icon_from_pixbuf(Gtk.EntryIconPosition.SECONDARY, icon)
        entry.set_icon_sensitive(Gtk.EntryIconPosition.SECONDARY, True)
        entry.set_icon_tooltip_markup (Gtk.EntryIconPosition.SECONDARY, "Click here to filter results")
        entry.set_placeholder_text("Filter results...")

        def on_icon_pressed(entry, icon_pos, event):
            if icon_pos == Gtk.EntryIconPosition.PRIMARY:
                self.srvclb.action_search(entry)
            elif icon_pos == Gtk.EntryIconPosition.SECONDARY:
                self.srvclb.gui_filter_visor(entry)

        entry.connect('changed', self.srvclb.gui_filter_visor)
        entry.connect("icon-press", on_icon_pressed)
        hbox.pack_start(entry, True, True, 0)
        tool.add(hbox)
        tool.set_expand(True)
        self.tool_bar.insert(tool, -1)

        # ~ Separator
        tool = Gtk.SeparatorToolItem.new()
        tool.set_draw(False)
        tool.set_expand(True)
        self.tool_bar.insert(tool, -1)

        # Button Total SAP Notes
        tool = Gtk.ToolItem()
        tool.set_expand(False)
        label = self.srvgui.add_widget('gtk_label_total_notes', Gtk.Label())
        hbox = Gtk.HBox()
        hbox.pack_start(label, False, False, 0)
        tool.add(hbox)
        self.tool_bar.insert(tool, -1)
        # ~ button = self.srvgui.add_widget('gtk_button_total_notes', Gtk.Button())
        # ~ button.set_relief(Gtk.ReliefStyle.NONE)
        # ~ popover = self.srvgui.add_widget('gtk_popover_button_total_notes', Gtk.Popover.new(button)
        # ~ button.add(hbox)
        # ~ button.connect('clicked', self.srvclb.gui_show_popover, popover)
        ## Popover body
        # ~ box = self.build_popover(popover)
        # ~ popover.add(box)

        # Fullscreen toggle button
        tool = Gtk.ToolItem()
        tool.set_expand(False)
        icon = self.srvicm.get_new_image_icon('basico-fullscreen', 24, 24)
        box = self.srvgui.add_widget('gtk_box_container_icon_fullscreen', Gtk.Box())
        box.pack_start(icon, False, False, 0)
        button = Gtk.ToggleButton()
        button.set_relief(Gtk.ReliefStyle.NONE)
        button.connect('toggled', self.srvclb.gui_toggle_fullscreen)
        button.add(box)
        tool.add(button)
        self.tool_bar.insert(tool, -1)

        # Toolbar initial settings
        self.set_visible(True)
        self.set_no_show_all(False)
        self.tool_bar.set_hexpand(True)


    def get_services(self):
        self.srvgui = self.app.get_service("GUI")
        self.srvclb = self.app.get_service('Callbacks')
        self.srvsap = self.app.get_service('SAP')
        self.srvicm = self.app.get_service('IM')
        self.srvstg = self.app.get_service('Settings')
        self.srvdtb = self.app.get_service('DB')
        self.srvuif = self.app.get_service("UIF")


    def completion_match_func(self, completion, key, iter):
        model = completion.get_model()
        text = model.get_value(iter, 0)
        if key.upper() in text.upper():
            return True
        return False



    def build_popover(self, popover):
        box = Gtk.Box(spacing = 3, orientation="vertical")
        sid = '0000000000'

        def get_popover_button(text, icon_name):
            button = Gtk.Button()
            button.set_relief(Gtk.ReliefStyle.NONE)
            hbox = Gtk.HBox()
            icon = self.srvicm.get_new_image_icon(icon_name, 24, 24)
            lbltext = Gtk.Label()
            lbltext.set_xalign(0.0)
            lbltext.set_markup('%s' % text)
            hbox.pack_start(icon, False, False, 3)
            hbox.pack_start(lbltext, True, True, 3)
            button.add(hbox)
            return button

        # Popover button "Bookmark"
        button = get_popover_button("(Un)bookmark SAP Notes", 'basico-bookmarks')
        button.connect('clicked', self.srvclb.switch_bookmark_current_set, popover)
        box.pack_start(button, False, False, 0)

        # Separator
        separator = Gtk.Separator(orientation = Gtk.Orientation.HORIZONTAL)
        box.pack_start(separator, True, True, 0)

        # Popover button Collection Management
        button = get_popover_button("Manage collections", 'basico-collection')
        box.pack_start(button, False, False, 0)
        self.popcollections = self.srvgui.add_widget('gtk_popover_button_manage_collections_selected_notes', Gtk.Popover.new(button))
        self.popcollections.set_position(Gtk.PositionType.RIGHT)
        button.connect('clicked', self.srvclb.gui_show_popover, self.popcollections)
        self.popcollections.add(CollectionsMgtView(self.app, sid, self.popcollections))

        # Separator
        separator = Gtk.Separator(orientation = Gtk.Orientation.HORIZONTAL)
        box.pack_start(separator, True, True, 0)


        # Popover button "Delete SAP Notes"
        button = get_popover_button("Delete SAP Notes", 'basico-delete')
        button.connect('clicked', self.srvclb.sapnote_delete, sid)
        box.pack_start(button, False, False, 0)

        return box