~osomon/moovida/plugin_dependencies_graph

« back to all changes in this revision

Viewing changes to elisa-plugins/elisa/plugins/poblesec/scanning_widget.py

  • Committer: Olivier Tilloy
  • Date: 2009-06-04 10:32:06 UTC
  • mfrom: (1074.1.315 relook)
  • Revision ID: olivier@fluendo.com-20090604103206-6ql519mywkfcog6z
Merged the latest moovida.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
# -*- coding: utf-8 -*-
2
 
# Elisa - Home multimedia server
3
 
# Copyright (C) 2006-2008 Fluendo Embedded S.L. (www.fluendo.com).
 
2
# Moovida - Home multimedia server
 
3
# Copyright (C) 2006-2009 Fluendo Embedded S.L. (www.fluendo.com).
4
4
# All rights reserved.
5
5
#
6
6
# This file is available under one of two license agreements.
7
7
#
8
8
# This file is licensed under the GPL version 3.
9
9
# See "LICENSE.GPL" in the root of this distribution including a special
10
 
# exception to use Elisa with Fluendo's plugins.
 
10
# exception to use Moovida with Fluendo's plugins.
11
11
#
12
 
# The GPL part of Elisa is also available under a commercial licensing
 
12
# The GPL part of Moovida is also available under a commercial licensing
13
13
# agreement from Fluendo.
14
 
# See "LICENSE.Elisa" in the root directory of this distribution package
 
14
# See "LICENSE.Moovida" in the root directory of this distribution package
15
15
# for details on that license.
16
16
#
17
17
# Author: Benjamin Kampmann <benjamin@fluendo.com>
18
18
 
19
 
import pgm
20
 
 
21
19
from elisa.plugins.pigment.widgets.widget import Widget
 
20
from elisa.plugins.pigment.widgets.box import HBox, VBox
22
21
from elisa.plugins.pigment.graph.text import Text
23
 
 
24
 
from elisa.plugins.poblesec.widgets.loading_animation import LoadingAnimation
 
22
from elisa.plugins.pigment.graph.image import Image
25
23
 
26
24
 
27
25
from elisa.core.resource_manager import NoMatchingResourceProvider
38
36
class ScannerWidget(Widget):
39
37
    def __init__(self):
40
38
        super(ScannerWidget, self).__init__()
41
 
 
42
 
        # FIXME: hardcoded widget styles
43
 
 
44
 
        self.loading_animation = LoadingAnimation()
45
 
        self.add(self.loading_animation)
46
 
        self.loading_animation.visible = True
47
 
        self.loading_animation.position = (0.85, 0.0, 0.0)
48
 
        self.loading_animation.size = (0.189, 1.0)
 
39
        # to be able to be more verbose on statistics
 
40
        self._currently_scanning = None
 
41
        self._last_count = 0
 
42
 
 
43
        self._create_widgets()
 
44
        self.update_style_properties(self.style.get_items())
 
45
 
 
46
    def _create_widgets(self):
 
47
        self.background = Image()
 
48
        self.background.visible = True
 
49
        self.add(self.background)
 
50
 
 
51
        self.horizontal_layout = HBox()
 
52
        self.horizontal_layout.visible = True
 
53
        self.add(self.horizontal_layout)
 
54
 
 
55
        self.icon = Image()
 
56
        self.icon.visible = True
 
57
        self.horizontal_layout.pack_start(self.icon)
 
58
 
 
59
        self.labels = Widget()
 
60
        self.labels.visible = True
 
61
        self.horizontal_layout.pack_start(self.labels)
49
62
 
50
63
        self.text = Text()
51
 
        self.add(self.text)
52
 
        self.text.bg_a = 0
53
 
        self.text.font_family = "Liberation Sans"
54
 
        self.text.font_height = 1
55
 
        self.text.font_weight = pgm.TEXT_WEIGHT_BOLD
56
 
        self.text.alignment = pgm.TEXT_ALIGN_RIGHT
57
 
        self.text.y = 0.0
58
 
        self.text.width = 0.80
59
 
        self.text.height = 0.5
60
64
        self.text.visible = True
61
 
        self.text.fg_color = (130, 130, 130, 255)
 
65
        self.labels.add(self.text)
62
66
 
63
67
        self.subtext = Text()
64
 
        self.add(self.subtext)
65
 
        self.subtext.bg_a = 0
66
 
        self.subtext.font_family = "Liberation Sans"
67
 
        self.subtext.font_height = 1
68
 
        self.subtext.font_weight = pgm.TEXT_WEIGHT_LIGHT
69
 
        self.subtext.alignment = pgm.TEXT_ALIGN_RIGHT
70
 
        self.subtext.y = 0.5
71
 
        self.subtext.width = 0.80
72
 
        self.subtext.height = 0.42
73
68
        self.subtext.visible = True
74
 
        self.subtext.fg_color = (102, 102, 102, 255)
75
 
 
76
 
        # to be able to be more verbose on statistics
77
 
        self._currently_scanning = None
78
 
        self._percent = None
 
69
        self.labels.add(self.subtext)
79
70
 
80
71
    def running__set(self, running):
81
 
        self.loading_animation.activate(running)
82
72
        if running:
83
73
            self.opacity = 255
84
74
        else:
90
80
        if self._currently_scanning:
91
81
            # we have to unbind from the old one
92
82
            self.files_scanned = 0
 
83
            self._last_count = 0
93
84
            self._currently_scanning.unbind_object(self)
94
85
            self._currently_scanning = None
95
86
            self.text.label = ''
109
100
    currently_scanning = property(fset=currently_scanning__set)
110
101
 
111
102
    def files_scanned__set(self, counter):
112
 
        if not self._currently_scanning.files_total:
 
103
        total = self._currently_scanning.files_total
 
104
        if not total:
113
105
            # there seem to be no total amount. we can't calculate
114
106
            return
115
107
 
116
 
        percent = int(counter * 100. / self._currently_scanning.files_total)
117
 
 
118
 
        if self._percent == percent:
119
 
            # only update if the percent changed
 
108
        # update the display every 5 files
 
109
        if counter - self._last_count < 5:
120
110
            return
121
111
 
122
 
        self._percent = percent
123
 
        self.subtext.label = _('%d%% Complete') % self._percent
 
112
        self._last_count = counter
 
113
        self.subtext.label = _('File %d of %d') % (counter, total)
124
114
 
125
115
    files_scanned = property(fset=files_scanned__set)
126
116
 
 
117
    def set_focus(self):
 
118
        return False
 
119
 
127
120
    def clean(self):
128
121
        self.subtext.clean()
129
122
        self.subtext = None
130
123
        self.text.clean()
131
124
        self.text = None
132
 
        self.loading_animation.clean()
133
 
        self.loading_animation = None
134
125
        return super(ScannerWidget, self).clean()
135
126
 
136
127
 
143
134
        return defer.fail(e)
144
135
 
145
136
    widget = ScannerWidget()
146
 
    controller.widget.add(widget)
147
 
    widget.opacity = 0
148
137
    widget.visible = True
149
 
    widget.width = 0.35
150
 
    widget.height = 0.055
151
 
    widget.x = 0.63
152
 
    widget.y = 0.925
 
138
    controller.topbar.button_bar.pack_start(widget)
153
139
 
154
140
    model.bind('currently_scanning', widget, 'currently_scanning')
155
141