~lottanzb/lottanzb/trunk-packaging-9.10

« back to all changes in this revision

Viewing changes to lottanzb/gui/info_bar.py

  • Committer: Severin Heiniger
  • Date: 2010-08-15 18:12:38 UTC
  • mfrom: (1212.1.150 trunk)
  • Revision ID: severinheiniger@gmail.com-20100815181238-yqzrdla3qyn6nxt7
Sync with main.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# Copyright (C) 2008-2010 LottaNZB Development Team
 
2
 
3
# This program is free software; you can redistribute it and/or modify
 
4
# it under the terms of the GNU General Public License as published by
 
5
# the Free Software Foundation; version 3.
 
6
 
7
# This program is distributed in the hope that it will be useful,
 
8
# but WITHOUT ANY WARRANTY; without even the implied warranty of
 
9
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
10
# GNU General Public License for more details.
 
11
 
12
# You should have received a copy of the GNU General Public License
 
13
# along with this program; if not, write to the Free Software
 
14
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
 
15
 
 
16
from lottanzb.core.component import depends_on
 
17
from lottanzb.core.environ import _
 
18
from lottanzb.util.signalmanager import SignalManager
 
19
from lottanzb.gui.framework import SlaveDelegateComponent
 
20
from lottanzb.backend.hubs.general import GeneralHub
 
21
 
 
22
__all__ = ["InfoBar"]
 
23
 
 
24
class InfoBar(SlaveDelegateComponent):
 
25
    builder_file = "info_bar"
 
26
    
 
27
    depends_on(GeneralHub)
 
28
    
 
29
    def __init__(self, component_manager):
 
30
        SlaveDelegateComponent.__init__(self, component_manager)
 
31
        
 
32
        general_hub = self._component_manager.get(GeneralHub)
 
33
        
 
34
        self._signal_manager = SignalManager()
 
35
        self._signal_manager.connect(general_hub, "notify::speed",
 
36
            self.on_speed_changed)
 
37
        self._signal_manager.connect(general_hub, "notify::size-left",
 
38
            self.on_remaining_changed)
 
39
        self._signal_manager.connect(general_hub, "notify::time-left",
 
40
            self.on_remaining_changed)
 
41
        
 
42
        self.on_speed_changed(general_hub)
 
43
        self.on_remaining_changed(general_hub)
 
44
    
 
45
    def on_speed_changed(self, general_hub, *args):
 
46
        self.speed.set_label(str(general_hub.speed))
 
47
    
 
48
    def on_remaining_changed(self, general_hub, *args):
 
49
        if general_hub.time_left:
 
50
            text = _("{0.size_left} left ({0.time_left.short})")
 
51
        else:
 
52
            text = _("{0.size_left} left")
 
53
        
 
54
        self.total_remaining.set_text(text.format(general_hub))