Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
path: root/src/view/launchwindow.py
blob: ee3ccfae7f10effb9e80a15d8b170405de1b49e6 (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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
# Copyright (C) 2008, Red Hat, Inc.
#
# 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 2 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 hippo
import gobject
import logging

from sugar.graphics import style
from sugar.graphics import animator
from sugar.graphics.xocolor import XoColor

from model import shellmodel
from view.pulsingicon import CanvasPulsingIcon

class LaunchWindow(hippo.CanvasWindow):
    def __init__(self):
        gobject.GObject.__init__(
                self, type_hint=gtk.gdk.WINDOW_TYPE_HINT_SPLASHSCREEN)

        self._box = LaunchBox()
        self.set_root(self._box)

        self.connect('focus-out-event', self.__focus_out_event_cb)

        screen = gtk.gdk.screen_get_default()
        screen.connect('size-changed', self.__size_changed_cb)

        self._update_size()

    def show(self):
        self.present()
        self._box.zoom_in()

    def _update_size(self):
        self.resize(gtk.gdk.screen_width(), gtk.gdk.screen_height())

    def __focus_out_event_cb(self, widget, event):
        self.hide()
        
    def __size_changed_cb(self, screen):
        self._update_size()

class LaunchBox(hippo.CanvasBox):
    def __init__(self):
        gobject.GObject.__init__(self, orientation=hippo.ORIENTATION_VERTICAL,
                                 background_color=style.COLOR_WHITE.get_int())

        self._activity_icon = CanvasPulsingIcon()
        self.append(self._activity_icon, hippo.PACK_EXPAND)

        # FIXME support non-xo colors in CanvasPulsingIcon
        self._activity_icon.props.base_color = \
            XoColor('%s,%s' % (style.COLOR_BUTTON_GREY.get_svg(),
                               style.COLOR_TRANSPARENT.get_svg()))

        self._animator = animator.Animator(1.0)

        self._home = shellmodel.get_instance().get_home()
        self._home.connect('active-activity-changed',
                           self.__active_activity_changed_cb)
        self._home.connect('launch-failed', self.__launch_ended_cb)
        self._home.connect('launch-completed', self.__launch_ended_cb)

        self._update_icon()

    def zoom_in(self):
        logging.debug('zooming in to activity')

        self._activity_icon.props.size = style.STANDARD_ICON_SIZE

        self._animator.remove_all()
        self._animator.add(_Animation(self._activity_icon,
                                      style.STANDARD_ICON_SIZE,
                                      style.XLARGE_ICON_SIZE))
        self._animator.start()

        logging.debug('starting pulse')

        self._activity_icon.props.pulsing = True

    def suspend(self):
        self._activity_icon.props.paused = True

    def resume(self):
        self._activity_icon.props.paused = False

    def _update_icon(self):
        activity = self._home.get_active_activity()
        if activity is not None:
            self._activity_icon.props.file_name = activity.get_icon_path()
            self._activity_icon.props.pulse_color = activity.get_icon_color()
        else:
            self._activity_icon.props.file_name = None

        if activity is not None and activity.props.launching:
            self.resume()
        else:
            self.suspend()

    def __active_activity_changed_cb(self, model, activity):
        self._update_icon()

    def __launch_ended_cb(self, model, activity):
        self._update_icon()

class _Animation(animator.Animation):
    def __init__(self, icon, start_size, end_size):
        animator.Animation.__init__(self, 0.0, 1.0)

        self._icon = icon
        self.start_size = start_size
        self.end_size = end_size

    def next_frame(self, current):
        d = (self.end_size - self.start_size) * current
        self._icon.props.size = self.start_size + d