Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
path: root/ep_page_status.py
blob: b66ae393a4be4b53d284a1536e70c0accfc655fd (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
# coding: UTF-8
# Copyright 2009, 2010 Thomas Jourdan
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA

import gtk
import gtk.gdk
import gobject
import ka_status
import ka_debug

_STATUS_PAGE_NUMBER = 5

class StatusController(object):
    """
    inv: self._widget_tree is not None
    inv: self._statusview is not None
    inv: self._status is not None
    """

    def __init__(self, controller, init_widget_tree):
        """
        pre: init_widget_tree is not None
        """
        self._widget_tree = init_widget_tree
        self._my_page = False
        self._visible = False
        self._statusview = self._widget_tree.get_widget('statusTextview')
        self._status = ka_status.Status.instance()

    def close(self):
        """Clean up"""
        pass

    def autoconnect_events(self):
        """Auto connect status view."""
        #Create a dictionary to connect events
        events = {
                'on_statustextview_visibility_notify_event' : 
                                   self.on_statuspage_visibility_notify_event,
                'on_notebook_switch_page' : self.on_notebook_switch_page,
                 }
        self._widget_tree.signal_autoconnect(events)
        gobject.timeout_add(1000, self.on_timer)
        
    def localize(self):
        """A dummy"""
        pass

    def show(self):
        """A dummy"""
        pass

    def refresh(self):
        """Replace status text completely."""
        buf = self._statusview.get_buffer()
        buf.delete(buf.get_start_iter(), buf.get_end_iter())
        buf.insert(buf.get_end_iter(), self._status.recall())

    def on_timer(self, *args):
        """Process next update cycle."""
        if self._visible and self._my_page:
            self.refresh()
        gobject.timeout_add(1000, self.on_timer)

    def on_statuspage_visibility_notify_event(self, *args):
        """
        pre: len(args) >= 2
        pre: isinstance(args[1], gtk.gdk.Event)
        """
#        ka_debug.info('on_statuspage_visibility_notify_event %s' % (args[1].state))
        self._visible = not args[1].state == gtk.gdk.VISIBILITY_FULLY_OBSCURED
        return False

    def on_notebook_switch_page(self, *args):
        """Test if status page will be displayed.
        pre: len(args) >= 3
        """
#        ka_debug.info('on_notebook_switch_page %s' % (args[2]))
        self._my_page = args[2] == _STATUS_PAGE_NUMBER