Subversion Repositories basico

Rev

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

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

from enum import IntEnum
import traceback as tb
from cgi import escape

import gi
gi.require_version('Gdk', '3.0')
gi.require_version('Gtk', '3.0')
from gi.repository import Gdk
from gi.repository import Gio
from gi.repository import Gtk
from gi.repository import Pango
from gi.repository.GdkPixbuf import Pixbuf
from gi.repository import Pango
from datetime import datetime
from dateutil import parser as dateparser

from .log import get_logger


#~ Enum(value='Column', names=<...>, *, module='...', qualname='...', type=<mixed-in class>, start=1)

class Column(IntEnum):
    rowtype = 0
    checkbox = 1
    icon = 2
    component = 3
    category = 4
    type = 5
    id = 6
    title = 7
    priority = 8
    language = 9
    released = 10


class SAPNoteView(Gtk.TreeView):
    def __init__(self, app):
        self.app = app
        LOG_FILE = self.app.get_file('LOG')
        LOG_NAME = self.__class__.__name__
        self.log = get_logger(LOG_NAME, LOG_FILE)
        self.get_services()
        self.toggled = 0
        self.selected = set()
        self.count = 0


        # Setup treeview and model
        Gtk.TreeView.__init__(self)
        self.model = Gtk.TreeStore(
            str,            # RowType@RowId
            bool,           # CheckBox
            Pixbuf,         # Icon
            str,            # Component key
            str,            # Category
            str,            # Type
            str,            # SAP Note Id
            str,            # Title
            str,            # Priority
            str,            # Language
            str             # Release date
        )
        self.set_model(self.model)

        # Setup columns
        # RowType
        self.renderer_rowtype = Gtk.CellRendererText()
        self.column_rowtype = Gtk.TreeViewColumn('', self.renderer_rowtype, text=Column.rowtype.value)
        self.column_rowtype.set_visible(False)
        self.column_rowtype.set_expand(False)
        self.column_rowtype.set_clickable(False)
        self.column_rowtype.set_sort_indicator(False)
        self.append_column(self.column_rowtype)

        # Checkbox
        self.renderer_checkbox = Gtk.CellRendererToggle()
        #~ self.renderer_checkbox.connect("toggled", self.on_cell_toggled)
        self.column_checkbox = Gtk.TreeViewColumn('', self.renderer_checkbox, active=1)
        self.column_checkbox.set_sizing(Gtk.TreeViewColumnSizing.AUTOSIZE)
        self.column_checkbox.set_visible(False)
        self.column_checkbox.set_expand(False)
        self.column_checkbox.set_clickable(False)
        self.column_checkbox.set_sort_indicator(False)
        self.append_column(self.column_checkbox)
        #~ self.column_checkbox.set_cell_data_func(self.renderer_checkbox, self.cell_data_func)

        # Icon
        self.renderer_icon = Gtk.CellRendererPixbuf()
        self.renderer_icon.set_alignment(0.0, 0.5)
        self.column_icon = Gtk.TreeViewColumn('', self.renderer_icon, pixbuf=2)
        self.column_icon.set_sizing(Gtk.TreeViewColumnSizing.AUTOSIZE)
        self.column_icon.set_visible(False)
        self.column_icon.set_expand(False)
        self.column_icon.set_clickable(False)
        self.column_icon.set_sort_indicator(False)
        self.append_column(self.column_icon)

        # Component key
        self.renderer_compkey = Gtk.CellRendererText()
        self.renderer_compkey.set_property('background', 'Lemon Chiffon')
        self.column_component = Gtk.TreeViewColumn('SAP Notes', self.renderer_compkey, markup=3)
        self.column_component.set_visible(True)
        self.column_component.set_sizing(Gtk.TreeViewColumnSizing.AUTOSIZE)
        self.column_component.set_clickable(True)
        self.column_component.set_sort_indicator(True)
        self.column_component.set_sort_column_id(3)
        self.column_component.set_sort_order(Gtk.SortType.ASCENDING)
        self.column_component.set_expand(True)
        self.append_column(self.column_component)
        expander_column = self.column_component

        # Category
        self.renderer_cat = Gtk.CellRendererText()
        self.column_cat = Gtk.TreeViewColumn('Category', self.renderer_cat, markup=4)
        self.column_cat.set_sizing(Gtk.TreeViewColumnSizing.AUTOSIZE)
        self.column_cat.set_visible(False)
        self.column_cat.set_expand(False)
        self.column_cat.set_clickable(True)
        self.column_cat.set_sort_indicator(True)
        self.column_cat.set_sort_column_id(4)
        self.column_cat.set_sort_order(Gtk.SortType.ASCENDING)
        self.append_column(self.column_cat)

        # Type
        self.renderer_sntype = Gtk.CellRendererText()
        self.column_sntype = Gtk.TreeViewColumn('Type', self.renderer_sntype, markup=5)
        self.column_sntype.set_sizing(Gtk.TreeViewColumnSizing.AUTOSIZE)
        self.column_sntype.set_visible(False)
        self.column_sntype.set_expand(False)
        self.column_sntype.set_clickable(True)
        self.column_sntype.set_sort_indicator(True)
        self.column_sntype.set_sort_column_id(5)
        self.column_sntype.set_sort_order(Gtk.SortType.ASCENDING)
        self.append_column(self.column_sntype)

        # SAP Note Id
        self.renderer_sid = Gtk.CellRendererText()
        self.renderer_sid.set_alignment(1.0, 0.5)
        self.column_sid = Gtk.TreeViewColumn('SAP Note', self.renderer_sid, markup=6)
        self.column_sid.set_visible(False)
        self.column_sid.set_expand(False)
        self.column_sid.set_clickable(True)
        self.column_sid.set_sort_indicator(True)
        self.column_sid.set_sort_column_id(6)
        self.column_sid.set_sort_order(Gtk.SortType.ASCENDING)
        self.append_column(self.column_sid)

        # Title
        self.renderer_title = Gtk.CellRendererText()
        self.renderer_title.set_property('ellipsize', Pango.EllipsizeMode.MIDDLE)
        self.column_title = Gtk.TreeViewColumn('Title', self.renderer_title, markup=7)
        self.column_title.set_visible(False)
        self.column_title.set_expand(True)
        self.column_title.set_clickable(True)
        self.column_title.set_sort_indicator(True)
        self.column_title.set_sort_column_id(7)
        self.column_title.set_sort_order(Gtk.SortType.ASCENDING)
        self.append_column(self.column_title)

        # Priority
        self.renderer_priority = Gtk.CellRendererText()
        self.column_priority = Gtk.TreeViewColumn('Priority', self.renderer_priority, markup=8)
        self.column_priority.set_sizing(Gtk.TreeViewColumnSizing.AUTOSIZE)
        self.column_priority.set_visible(True)
        self.column_priority.set_expand(False)
        self.column_priority.set_clickable(True)
        self.column_priority.set_sort_indicator(True)
        self.column_priority.set_sort_column_id(8)
        self.column_priority.set_sort_order(Gtk.SortType.ASCENDING)
        self.append_column(self.column_priority)

        # Language
        self.renderer_lang = Gtk.CellRendererText()
        self.column_lang = Gtk.TreeViewColumn('Language', self.renderer_lang, markup=9)
        self.column_lang.set_sizing(Gtk.TreeViewColumnSizing.AUTOSIZE)
        self.column_lang.set_visible(False)
        self.column_lang.set_expand(False)
        self.column_lang.set_clickable(True)
        self.column_lang.set_sort_indicator(True)
        self.column_lang.set_sort_column_id(9)
        self.column_lang.set_sort_order(Gtk.SortType.ASCENDING)
        self.append_column(self.column_lang)

        # Release date
        self.renderer_reldate = Gtk.CellRendererText()
        self.column_rel = Gtk.TreeViewColumn('Released on', self.renderer_reldate, markup=10)
        self.column_rel.set_sizing(Gtk.TreeViewColumnSizing.AUTOSIZE)
        self.column_rel.set_visible(False)
        self.column_rel.set_expand(False)
        self.column_rel.set_clickable(True)
        self.column_rel.set_sort_indicator(True)
        self.column_rel.set_sort_column_id(10)
        self.column_rel.set_sort_order(Gtk.SortType.ASCENDING)
        self.append_column(self.column_rel)

        # TreeView common
        #~ self.set_level_indentation(6)
        self.set_can_focus(True)
        self.set_headers_visible(False)
        self.set_enable_search(True)
        self.set_hover_selection(False)
        self.set_grid_lines(Gtk.TreeViewGridLines.NONE)
        self.set_search_entry(self.gui.get_widget('stySearchInfo'))
        self.set_search_column(3)
        #~ self.set_row_separator_func(self.row_separator_func)

        # Selection
        self.selection = self.get_selection()
        #~ self.selection.set_select_function(self.select_function)
        self.selection.set_mode(Gtk.SelectionMode.SINGLE)

        # Font
        font_desc = Pango.FontDescription('Monospace 10')
        if font_desc:
            self.modify_font(font_desc)

        # Go live
        self.connect('button_press_event', self.single_click)
        self.connect('row-activated', self.double_click)
        self.connect('cursor-changed', self.row_changed)

        # Custom method to be implemented.
        self.prepare()

        self.show_all()


    def get_services(self):
        self.gui = self.app.get_service("GUI")
        self.cb = self.app.get_service('Callbacks')
        self.menu = self.app.get_service("Menus")
        self.sap = self.app.get_service('SAP')
        self.im = self.app.get_service('IM')
        self.settings = self.app.get_service('Settings')
        self.plugins = self.app.get_service('Plugins')
        self.db = self.app.get_service('DB')