Subversion Repositories basico

Rev

Rev 142 | Blame | Compare with Previous | Last modification | View Log | Download | RSS feed

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

from gi.repository import Gtk
from gi.repository import Pango
from .service import Service


class Statusbar(Gtk.HBox, Service):
    def __init__(self, app):
        Gtk.HBox.__init__(self)
        self.app = app
        self.get_services()
        self.setup()

    def setup(self):
        vbox = Gtk.VBox()
        hbox = Gtk.HBox()

        # Status bar
        #~ separator = Gtk.Separator(orientation = Gtk.Orientation.HORIZONTAL)
        #~ vbox.pack_start(separator, True, False, 3)
        viewport = Gtk.Viewport()
        viewport.set_shadow_type(Gtk.ShadowType.IN)
        self.statusbar = self.gui.add_widget('statusbar', Gtk.Label())
        self.statusbar.set_property('margin-left', 6)
        self.statusbar.set_property('margin-right', 6)
        self.statusbar.set_property('margin-top', 6)
        self.statusbar.set_property('margin-bottom', 6)
        self.statusbar.set_xalign(0.0)
        self.message("<b>Welcome to Basico</b>")
        viewport.add(self.statusbar)
        hbox.pack_start(viewport, True, True, 0)

        # Progressbar
        #~ self.progressbar = Gtk.ProgressBar()
        #~ hbox.pack_start(self.progressbar, False, False, 0)

        vbox.pack_start(hbox, True, False, 0)
        self.add(vbox)


    def get_services(self):
        """Load services to be used in this class
        """

        self.gui = self.app.get_service("GUI")


    def message(self, message):
        self.statusbar.set_markup(message)



class ListReview(Gtk.ScrolledWindow, Service):
    def __init__(self, app):
        Gtk.VBox.__init__(self)
        self.app = app
        self.log = self.app.log
        self.get_services()

        self.setup()
        # ~ self.fill()


    def get_services(self):
        """Load services to be used in this class
        """

        self.gui = self.app.get_service("GUI")


    def setup(self):
        self.set_policy(Gtk.PolicyType.AUTOMATIC, Gtk.PolicyType.AUTOMATIC)
        self.set_shadow_type(Gtk.ShadowType.IN)
        viewport = Gtk.Viewport()
        self.treeview = Gtk.TreeView()
        viewport.add(self.treeview)
        self.add(viewport)

        # Setup model
        self.model = Gtk.ListStore(
            str,        # SAP Note ID
            str,        # Title
            str         # RC
        )
        self.treeview.set_model(self.model)

        # Setup columns
        # SAP Note Id
        self.renderer_sid = Gtk.CellRendererText()
        self.column_sid = Gtk.TreeViewColumn('SAP Note', self.renderer_sid, markup=0)
        self.column_sid.set_visible(True)
        self.column_sid.set_expand(False)
        self.column_sid.set_clickable(False)
        self.column_sid.set_sort_indicator(False)
        self.treeview.append_column(self.column_sid)

        # SAP Note Title
        self.renderer_title = Gtk.CellRendererText()
        self.column_title = Gtk.TreeViewColumn('Title', self.renderer_title, markup=1)
        self.column_title.set_visible(True)
        self.column_title.set_expand(True)
        self.column_title.set_clickable(False)
        self.column_title.set_sort_indicator(False)
        self.treeview.append_column(self.column_title)

        # SAP Note RC
        self.renderer_rc = Gtk.CellRendererText()
        self.column_rc = Gtk.TreeViewColumn('RC', self.renderer_rc, markup=2)
        self.column_rc.set_visible(True)
        self.column_rc.set_expand(False)
        self.column_rc.set_clickable(False)
        self.column_rc.set_sort_indicator(False)
        self.treeview.append_column(self.column_rc)

        # TreeView common
        self.treeview.set_can_focus(False)
        self.treeview.set_headers_visible(True)
        self.treeview.set_enable_search(False)
        self.treeview.set_hover_selection(False)
        self.treeview.set_grid_lines(Gtk.TreeViewGridLines.HORIZONTAL)
        self.treeview.modify_font(Pango.FontDescription('Monospace 10'))

        # Selection
        self.selection = self.treeview.get_selection()
        self.selection.set_mode(Gtk.SelectionMode.NONE)

        # ~ viewport.add(self.treeview)
        # ~ scrolledwindow.add(viewport)
        # ~ vbox.pack_start(scrolledwindow, True, True, 0)
        # ~ self.add(vbox)
        self.show_all()
        self.debug("Hello")


    def fill(self, bag):
        iterdict = {}
        for sid in bag:
            riter = self.model.append([sid, 'Download not started yet', ''])
            iterdict[sid] = riter
        self.debug(iterdict)