Initial import of StatusBar

This commit is contained in:
Andrew Resch 2007-09-23 02:24:18 +00:00
parent d80debfbea
commit 3270f23747
5 changed files with 138 additions and 2 deletions

View File

@ -326,6 +326,26 @@ class Core(dbus.service.Object):
"""Returns the active listen port""" """Returns the active listen port"""
return self.session.listen_port() return self.session.listen_port()
@dbus.service.method(dbus_interface="org.deluge_torrent.Deluge",
out_signature="i")
def get_num_connections(self):
"""Returns the current number of connections"""
return self.session.num_connections()
@dbus.service.method(dbus_interface="org.deluge_torrent.Deluge",
out_signature="d")
def get_download_rate(self):
"""Returns the payload download rate"""
# print self.session.status().payload_download_rate
return self.session.status().payload_download_rate
# return 0.0
@dbus.service.method(dbus_interface="org.deluge_torrent.Deluge",
out_signature="d")
def get_upload_rate(self):
"""Returns the payload upload rate"""
return self.session.status().payload_upload_rate
# Signals # Signals
@dbus.service.signal(dbus_interface="org.deluge_torrent.Deluge", @dbus.service.signal(dbus_interface="org.deluge_torrent.Deluge",
signature="s") signature="s")

View File

@ -44,6 +44,7 @@ from torrentview import TorrentView
from torrentdetails import TorrentDetails from torrentdetails import TorrentDetails
from preferences import Preferences from preferences import Preferences
from systemtray import SystemTray from systemtray import SystemTray
from statusbar import StatusBar
import deluge.common import deluge.common
from deluge.log import LOG as log from deluge.log import LOG as log
@ -78,6 +79,7 @@ class MainWindow:
self.torrentdetails = TorrentDetails(self) self.torrentdetails = TorrentDetails(self)
self.preferences = Preferences(self) self.preferences = Preferences(self)
self.systemtray = SystemTray(self) self.systemtray = SystemTray(self)
self.statusbar = StatusBar(self)
gobject.timeout_add(1000, self.update) gobject.timeout_add(1000, self.update)
@ -87,6 +89,7 @@ class MainWindow:
return True return True
self.torrentview.update() self.torrentview.update()
self.torrentdetails.update() self.torrentdetails.update()
self.statusbar.update()
return True return True
def show(self): def show(self):

View File

@ -0,0 +1,107 @@
#
# statusbar.py
#
# Copyright (C) 2007 Andrew Resch ('andar') <andrewresch@gmail.com>
#
# Deluge is free software.
#
# You may 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.
#
# deluge 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 deluge. If not, write to:
# The Free Software Foundation, Inc.,
# 51 Franklin Street, Fifth Floor
# Boston, MA 02110-1301, USA.
#
# In addition, as a special exception, the copyright holders give
# permission to link the code of portions of this program with the OpenSSL
# library.
# You must obey the GNU General Public License in all respects for all of
# the code used other than OpenSSL. If you modify file(s) with this
# exception, you may extend this exception to your version of the file(s),
# but you are not obligated to do so. If you do not wish to do so, delete
# this exception statement from your version. If you delete this exception
# statement from all source files in the program, then also delete it here.
import gtk
import deluge.common
import deluge.ui.functions as functions
class StatusBar:
def __init__(self, window):
self.window = window
self.statusbar = self.window.main_glade.get_widget("statusbar")
self.core = functions.get_core()
# Add a HBox to the statusbar after removing the initial label widget
self.hbox = gtk.HBox()
self.hbox.set_spacing(5)
frame = self.statusbar.get_children()[0]
frame.remove(frame.get_children()[0])
frame.add(self.hbox)
# Add in images and labels
image = gtk.Image()
image.set_from_stock(gtk.STOCK_NETWORK, gtk.ICON_SIZE_MENU)
self.hbox.pack_start(image, expand=False, fill=False)
self.label_connections = gtk.Label()
self.hbox.pack_start(self.label_connections, expand=False, fill=False)
image = gtk.Image()
image.set_from_file(deluge.common.get_pixmap("downloading16.png"))
self.hbox.pack_start(image, expand=False, fill=False)
self.label_download_speed = gtk.Label()
self.hbox.pack_start(self.label_download_speed,
expand=False, fill=False)
image = gtk.Image()
image.set_from_file(deluge.common.get_pixmap("seeding16.png"))
self.hbox.pack_start(image, expand=False, fill=False)
self.label_upload_speed = gtk.Label()
self.hbox.pack_start(self.label_upload_speed,
expand=False, fill=False)
# Update once before showing
self.update()
self.statusbar.show_all()
def update(self):
# Set the max connections label
max_connections = functions.get_config_value("max_connections_global",
core=self.core)
if max_connections < 0:
max_connections = _("Unlimited")
self.label_connections.set_text("%s (%s)" % (
self.core.get_num_connections(), max_connections))
# Set the download speed label
max_download_speed = functions.get_config_value("max_download_speed",
core=self.core)
if max_download_speed < 0:
max_download_speed = _("Unlimited")
else:
max_download_speed = "%s %s" % (max_download_speed, _("KiB/s"))
self.label_download_speed.set_text("%s/s (%s)" % (
deluge.common.fsize(self.core.get_download_rate()),
max_download_speed))
# Set the upload speed label
max_upload_speed = functions.get_config_value("max_upload_speed",
core=self.core)
if max_upload_speed < 0:
max_upload_speed = _("Unlimited")
else:
max_upload_speed = "%s %s" % (max_upload_speed, _("KiB/s"))
self.label_upload_speed.set_text("%s/s (%s)" % (
deluge.common.fsize(self.core.get_upload_rate()),
max_upload_speed))

View File

@ -153,7 +153,8 @@ char const* session_set_max_half_open_connections_doc =
"-1 as the limit, means to have no limit. When limiting the number of\n" "-1 as the limit, means to have no limit. When limiting the number of\n"
"simultaneous connection attempts, peers will be put in a queue waiting\n" "simultaneous connection attempts, peers will be put in a queue waiting\n"
"for their turn to get connected."; "for their turn to get connected.";
char const* session_num_connections_doc =
"";
char const* session_set_settings_doc = char const* session_set_settings_doc =
""; "";
char const* session_set_pe_settings_doc = char const* session_set_pe_settings_doc =

View File

@ -44,6 +44,7 @@ extern char const* session_upload_rate_limit_doc;
extern char const* session_set_max_uploads_doc; extern char const* session_set_max_uploads_doc;
extern char const* session_set_max_connections_doc; extern char const* session_set_max_connections_doc;
extern char const* session_set_max_half_open_connections_doc; extern char const* session_set_max_half_open_connections_doc;
extern char const* session_num_connections_doc;
extern char const* session_set_settings_doc; extern char const* session_set_settings_doc;
extern char const* session_set_pe_settings_doc; extern char const* session_set_pe_settings_doc;
extern char const* session_get_pe_settings_doc; extern char const* session_get_pe_settings_doc;
@ -209,6 +210,10 @@ void bind_session()
"set_max_half_open_connections", allow_threads(&session::set_max_half_open_connections) "set_max_half_open_connections", allow_threads(&session::set_max_half_open_connections)
, session_set_max_half_open_connections_doc , session_set_max_half_open_connections_doc
) )
.def(
"num_connections", allow_threads(&session::num_connections)
, session_num_connections_doc
)
.def("set_settings", allow_threads(&session::set_settings), session_set_settings_doc) .def("set_settings", allow_threads(&session::set_settings), session_set_settings_doc)
.def("set_pe_settings", allow_threads(&session::set_pe_settings), session_set_pe_settings_doc) .def("set_pe_settings", allow_threads(&session::set_pe_settings), session_set_pe_settings_doc)
.def("get_pe_settings", allow_threads(&session::get_pe_settings), return_value_policy<copy_const_reference>()) .def("get_pe_settings", allow_threads(&session::get_pe_settings), return_value_policy<copy_const_reference>())