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.
6
6
# This file is available under one of two license agreements.
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.
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.
17
17
# Author: Benjamin Kampmann <benjamin@fluendo.com>
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
24
from elisa.plugins.poblesec.widgets.loading_animation import LoadingAnimation
22
from elisa.plugins.pigment.graph.image import Image
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__()
42
# FIXME: hardcoded widget styles
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
43
self._create_widgets()
44
self.update_style_properties(self.style.get_items())
46
def _create_widgets(self):
47
self.background = Image()
48
self.background.visible = True
49
self.add(self.background)
51
self.horizontal_layout = HBox()
52
self.horizontal_layout.visible = True
53
self.add(self.horizontal_layout)
56
self.icon.visible = True
57
self.horizontal_layout.pack_start(self.icon)
59
self.labels = Widget()
60
self.labels.visible = True
61
self.horizontal_layout.pack_start(self.labels)
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
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)
63
67
self.subtext = Text()
64
self.add(self.subtext)
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
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)
76
# to be able to be more verbose on statistics
77
self._currently_scanning = None
69
self.labels.add(self.subtext)
80
71
def running__set(self, running):
81
self.loading_animation.activate(running)
109
100
currently_scanning = property(fset=currently_scanning__set)
111
102
def files_scanned__set(self, counter):
112
if not self._currently_scanning.files_total:
103
total = self._currently_scanning.files_total
113
105
# there seem to be no total amount. we can't calculate
116
percent = int(counter * 100. / self._currently_scanning.files_total)
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:
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)
125
115
files_scanned = property(fset=files_scanned__set)
128
121
self.subtext.clean()
129
122
self.subtext = None
130
123
self.text.clean()
132
self.loading_animation.clean()
133
self.loading_animation = None
134
125
return super(ScannerWidget, self).clean()