本文整理汇总了Python中deluge.configmanager.ConfigManager.register_set_function方法的典型用法代码示例。如果您正苦于以下问题:Python ConfigManager.register_set_function方法的具体用法?Python ConfigManager.register_set_function怎么用?Python ConfigManager.register_set_function使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类deluge.configmanager.ConfigManager
的用法示例。
在下文中一共展示了ConfigManager.register_set_function方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: AutoAdd
# 需要导入模块: from deluge.configmanager import ConfigManager [as 别名]
# 或者: from deluge.configmanager.ConfigManager import register_set_function [as 别名]
class AutoAdd(component.Component):
def __init__(self):
component.Component.__init__(self, "AutoAdd", depend=["TorrentManager"], interval=5)
# Get the core config
self.config = ConfigManager("core.conf")
# A list of filenames
self.invalid_torrents = []
# Filename:Attempts
self.attempts = {}
# Register set functions
self.config.register_set_function("autoadd_enable",
self._on_autoadd_enable, apply_now=True)
self.config.register_set_function("autoadd_location",
self._on_autoadd_location)
def update(self):
if not self.config["autoadd_enable"]:
# We shouldn't be updating because autoadd is not enabled
component.pause("AutoAdd")
return
# Check the auto add folder for new torrents to add
if not os.path.isdir(self.config["autoadd_location"]):
log.warning("Invalid AutoAdd folder: %s", self.config["autoadd_location"])
component.pause("AutoAdd")
return
for filename in os.listdir(self.config["autoadd_location"]):
try:
filepath = os.path.join(self.config["autoadd_location"], filename)
except UnicodeDecodeError, e:
log.error("Unable to auto add torrent due to improper filename encoding: %s", e)
continue
if os.path.isfile(filepath) and filename.endswith(".torrent"):
try:
filedump = self.load_torrent(filepath)
except (RuntimeError, Exception), e:
# If the torrent is invalid, we keep track of it so that we
# can try again on the next pass. This is because some
# torrents may not be fully saved during the pass.
log.debug("Torrent is invalid: %s", e)
if filename in self.invalid_torrents:
self.attempts[filename] += 1
if self.attempts[filename] >= MAX_NUM_ATTEMPTS:
os.rename(filepath, filepath + ".invalid")
del self.attempts[filename]
self.invalid_torrents.remove(filename)
else:
self.invalid_torrents.append(filename)
self.attempts[filename] = 1
continue
# The torrent looks good, so lets add it to the session
component.get("TorrentManager").add(filedump=filedump, filename=filename)
os.remove(filepath)
示例2: MainWindow
# 需要导入模块: from deluge.configmanager import ConfigManager [as 别名]
# 或者: from deluge.configmanager.ConfigManager import register_set_function [as 别名]
class MainWindow(component.Component):
def __init__(self):
component.Component.__init__(self, "MainWindow", interval=2)
self.config = ConfigManager("gtkui.conf")
self.gtk_builder_signals_holder = _GtkBuilderSignalsHolder()
self.main_builder = gtk.Builder()
# Patch this GtkBuilder to avoid connecting signals from elsewhere
#
# Think about splitting up the main window gtkbuilder file into the necessary parts
# in order not to have to monkey patch GtkBuilder. Those parts would then need to
# be added to the main window "by hand".
self.main_builder.prev_connect_signals = copy.deepcopy(self.main_builder.connect_signals)
def patched_connect_signals(*a, **k):
raise RuntimeError(
"In order to connect signals to this GtkBuilder instance please use "
"'component.get(\"MainWindow\").connect_signals()'"
)
self.main_builder.connect_signals = patched_connect_signals
# Get the gtk builder file for the main window
self.main_builder.add_from_file(
deluge.common.resource_filename("deluge.ui.gtkui", os.path.join("glade", "main_window.ui"))
)
# The new release dialog
self.main_builder.add_from_file(
deluge.common.resource_filename("deluge.ui.gtkui", os.path.join("glade", "main_window.new_release.ui"))
)
# The move storage dialog
self.main_builder.add_from_file(
deluge.common.resource_filename("deluge.ui.gtkui", os.path.join("glade", "main_window.move_storage.ui"))
)
# The tabs
self.main_builder.add_from_file(
deluge.common.resource_filename("deluge.ui.gtkui", os.path.join("glade", "main_window.tabs.ui"))
)
# The tabs file menu
self.main_builder.add_from_file(
deluge.common.resource_filename("deluge.ui.gtkui", os.path.join("glade", "main_window.tabs.menu_file.ui"))
)
# The tabs peer menu
self.main_builder.add_from_file(
deluge.common.resource_filename("deluge.ui.gtkui", os.path.join("glade", "main_window.tabs.menu_peer.ui"))
)
self.window = self.main_builder.get_object("main_window")
self.window.set_icon(common.get_deluge_icon())
self.vpaned = self.main_builder.get_object("vpaned")
self.initial_vpaned_position = self.config["window_pane_position"]
# Load the window state
self.load_window_state()
# Keep track of window's minimization state so that we don't update the
# UI when it is minimized.
self.is_minimized = False
self.window.drag_dest_set(gtk.DEST_DEFAULT_ALL, [("text/uri-list", 0, 80)], gtk.gdk.ACTION_COPY)
# Connect events
self.window.connect("window-state-event", self.on_window_state_event)
self.window.connect("configure-event", self.on_window_configure_event)
self.window.connect("delete-event", self.on_window_delete_event)
self.window.connect("drag-data-received", self.on_drag_data_received_event)
self.vpaned.connect("notify::position", self.on_vpaned_position_event)
self.window.connect("expose-event", self.on_expose_event)
self.config.register_set_function("show_rate_in_title", self._on_set_show_rate_in_title, apply_now=False)
client.register_event_handler("NewVersionAvailableEvent", self.on_newversionavailable_event)
client.register_event_handler("TorrentFinishedEvent", self.on_torrentfinished_event)
def connect_signals(self, mapping_or_class):
self.gtk_builder_signals_holder.connect_signals(mapping_or_class)
def first_show(self):
if not (self.config["start_in_tray"] and self.config["enable_system_tray"]) and not self.window.get_property(
"visible"
):
log.debug("Showing window")
self.main_builder.prev_connect_signals(self.gtk_builder_signals_holder)
self.show()
while gtk.events_pending():
gtk.main_iteration(False)
self.vpaned.set_position(self.initial_vpaned_position)
def show(self):
try:
component.resume("TorrentView")
component.resume("StatusBar")
component.resume("TorrentDetails")
except:
pass
self.window.show()
def hide(self):
#.........这里部分代码省略.........
示例3: MainWindow
# 需要导入模块: from deluge.configmanager import ConfigManager [as 别名]
# 或者: from deluge.configmanager.ConfigManager import register_set_function [as 别名]
class MainWindow(component.Component):
def __init__(self):
if wnck:
self.screen = wnck.screen_get_default()
component.Component.__init__(self, "MainWindow", interval=2)
self.config = ConfigManager("gtkui.conf")
# Get the glade file for the main window
self.main_glade = gtk.glade.XML(
pkg_resources.resource_filename("deluge.ui.gtkui",
"glade/main_window.glade"))
self.window = self.main_glade.get_widget("main_window")
self.window.set_icon(common.get_deluge_icon())
self.vpaned = self.main_glade.get_widget("vpaned")
self.initial_vpaned_position = self.config["window_pane_position"]
# Load the window state
self.load_window_state()
# Keep track of window's minimization state so that we don't update the
# UI when it is minimized.
self.is_minimized = False
self.window.drag_dest_set(gtk.DEST_DEFAULT_ALL, [('text/uri-list', 0,
80)], gtk.gdk.ACTION_COPY)
# Connect events
self.window.connect("window-state-event", self.on_window_state_event)
self.window.connect("configure-event", self.on_window_configure_event)
self.window.connect("delete-event", self.on_window_delete_event)
self.window.connect("drag-data-received", self.on_drag_data_received_event)
self.vpaned.connect("notify::position", self.on_vpaned_position_event)
self.window.connect("expose-event", self.on_expose_event)
self.config.register_set_function("show_rate_in_title", self._on_set_show_rate_in_title, apply_now=False)
client.register_event_handler("NewVersionAvailableEvent", self.on_newversionavailable_event)
client.register_event_handler("TorrentFinishedEvent", self.on_torrentfinished_event)
def first_show(self):
if not(self.config["start_in_tray"] and \
self.config["enable_system_tray"]) and not \
self.window.get_property("visible"):
log.debug("Showing window")
self.show()
while gtk.events_pending():
gtk.main_iteration(False)
self.vpaned.set_position(self.initial_vpaned_position)
def show(self):
try:
component.resume("TorrentView")
component.resume("StatusBar")
component.resume("TorrentDetails")
except:
pass
self.window.show()
def hide(self):
component.pause("TorrentView")
component.get("TorrentView").save_state()
component.pause("StatusBar")
component.pause("TorrentDetails")
# Store the x, y positions for when we restore the window
self.window_x_pos = self.window.get_position()[0]
self.window_y_pos = self.window.get_position()[1]
self.window.hide()
def present(self):
def restore():
# Restore the proper x,y coords for the window prior to showing it
try:
if self.window_x_pos == -32000 or self.window_y_pos == -32000:
self.config["window_x_pos"] = 0
self.config["window_y_pos"] = 0
else:
self.config["window_x_pos"] = self.window_x_pos
self.config["window_y_pos"] = self.window_y_pos
except:
pass
try:
component.resume("TorrentView")
component.resume("StatusBar")
component.resume("TorrentDetails")
except:
pass
self.window.present()
self.load_window_state()
if self.config["lock_tray"] and not self.visible():
dialog = PasswordDialog(_("Enter your password to show Deluge..."))
def on_dialog_response(response_id):
if response_id == gtk.RESPONSE_OK:
if self.config["tray_password"] == sha(dialog.get_password()).hexdigest():
restore()
dialog.run().addCallback(on_dialog_response)
else:
#.........这里部分代码省略.........
示例4: TorrentManager
# 需要导入模块: from deluge.configmanager import ConfigManager [as 别名]
# 或者: from deluge.configmanager.ConfigManager import register_set_function [as 别名]
class TorrentManager(component.Component):
"""
TorrentManager contains a list of torrents in the current libtorrent
session. This object is also responsible for saving the state of the
session for use on restart.
"""
def __init__(self):
component.Component.__init__(self, "TorrentManager", interval=5, depend=["CorePluginManager"])
log.debug("TorrentManager init..")
# Set the libtorrent session
self.session = component.get("Core").session
# Set the alertmanager
self.alerts = component.get("AlertManager")
# Get the core config
self.config = ConfigManager("core.conf")
# Make sure the state folder has been created
if not os.path.exists(os.path.join(get_config_dir(), "state")):
os.makedirs(os.path.join(get_config_dir(), "state"))
# Create the torrents dict { torrent_id: Torrent }
self.torrents = {}
self.queued_torrents = set()
# This is a list of torrent_id when we shutdown the torrentmanager.
# We use this list to determine if all active torrents have been paused
# and that their resume data has been written.
self.shutdown_torrent_pause_list = []
# self.num_resume_data used to save resume_data in bulk
self.num_resume_data = 0
# Keep track of torrents finished but moving storage
self.waiting_on_finish_moving = []
# Keeps track of resume data that needs to be saved to disk
self.resume_data = {}
# Workaround to determine if TorrentAddedEvent is from state file
self.session_started = False
# Register set functions
self.config.register_set_function("max_connections_per_torrent",
self.on_set_max_connections_per_torrent)
self.config.register_set_function("max_upload_slots_per_torrent",
self.on_set_max_upload_slots_per_torrent)
self.config.register_set_function("max_upload_speed_per_torrent",
self.on_set_max_upload_speed_per_torrent)
self.config.register_set_function("max_download_speed_per_torrent",
self.on_set_max_download_speed_per_torrent)
# Register alert functions
self.alerts.register_handler("torrent_finished_alert",
self.on_alert_torrent_finished)
self.alerts.register_handler("torrent_paused_alert",
self.on_alert_torrent_paused)
self.alerts.register_handler("torrent_checked_alert",
self.on_alert_torrent_checked)
self.alerts.register_handler("tracker_reply_alert",
self.on_alert_tracker_reply)
self.alerts.register_handler("tracker_announce_alert",
self.on_alert_tracker_announce)
self.alerts.register_handler("tracker_warning_alert",
self.on_alert_tracker_warning)
self.alerts.register_handler("tracker_error_alert",
self.on_alert_tracker_error)
self.alerts.register_handler("storage_moved_alert",
self.on_alert_storage_moved)
self.alerts.register_handler("storage_moved_failed_alert",
self.on_alert_storage_moved_failed)
self.alerts.register_handler("torrent_resumed_alert",
self.on_alert_torrent_resumed)
self.alerts.register_handler("state_changed_alert",
self.on_alert_state_changed)
self.alerts.register_handler("save_resume_data_alert",
self.on_alert_save_resume_data)
self.alerts.register_handler("save_resume_data_failed_alert",
self.on_alert_save_resume_data_failed)
self.alerts.register_handler("file_renamed_alert",
self.on_alert_file_renamed)
self.alerts.register_handler("metadata_received_alert",
self.on_alert_metadata_received)
self.alerts.register_handler("file_error_alert",
self.on_alert_file_error)
self.alerts.register_handler("file_completed_alert",
self.on_alert_file_completed)
def start(self):
# Get the pluginmanager reference
self.plugins = component.get("CorePluginManager")
# Run the old state upgrader before loading state
deluge.core.oldstateupgrader.OldStateUpgrader()
# Try to load the state from file
self.load_state()
# Save the state every 5 minutes
self.save_state_timer = LoopingCall(self.save_state)
#.........这里部分代码省略.........
示例5: SystemTray
# 需要导入模块: from deluge.configmanager import ConfigManager [as 别名]
# 或者: from deluge.configmanager.ConfigManager import register_set_function [as 别名]
class SystemTray(component.Component):
def __init__(self):
component.Component.__init__(self, "SystemTray", interval=4)
self.window = component.get("MainWindow")
self.config = ConfigManager("gtkui.conf")
# List of widgets that need to be hidden when not connected to a host
self.hide_widget_list = [
"menuitem_add_torrent",
"menuitem_pause_all",
"menuitem_resume_all",
"menuitem_download_limit",
"menuitem_upload_limit",
"menuitem_quitdaemon",
"separatormenuitem1",
"separatormenuitem2",
"separatormenuitem3",
"separatormenuitem4"
]
self.config.register_set_function("enable_system_tray", self.on_enable_system_tray_set)
# bit of a hack to prevent function from doing something on startup
self.__enabled_set_once = False
self.config.register_set_function("enable_appindicator", self.on_enable_appindicator_set)
self.max_download_speed = -1.0
self.download_rate = 0.0
self.max_upload_speed = -1.0
self.upload_rate = 0.0
self.config_value_changed_dict = {
"max_download_speed": self._on_max_download_speed,
"max_upload_speed": self._on_max_upload_speed
}
def enable(self):
"""Enables the system tray icon."""
self.builder = gtk.Builder()
self.builder.add_from_file(deluge.common.resource_filename(
"deluge.ui.gtkui", os.path.join("glade", "tray_menu.ui"))
)
self.builder.connect_signals({
"on_menuitem_show_deluge_activate": self.on_menuitem_show_deluge_activate,
"on_menuitem_add_torrent_activate": self.on_menuitem_add_torrent_activate,
"on_menuitem_pause_all_activate": self.on_menuitem_pause_all_activate,
"on_menuitem_resume_all_activate": self.on_menuitem_resume_all_activate,
"on_menuitem_quit_activate": self.on_menuitem_quit_activate,
"on_menuitem_quitdaemon_activate": self.on_menuitem_quitdaemon_activate
})
self.tray_menu = self.builder.get_object("tray_menu")
if appindicator and self.config["enable_appindicator"]:
log.debug("Enabling the Application Indicator..")
self.indicator = appindicator.Indicator (
"deluge", "deluge", appindicator.CATEGORY_APPLICATION_STATUS)
# Pass the menu to the Application Indicator
self.indicator.set_menu(self.tray_menu)
# Make sure the status of the Show Window MenuItem is correct
self._sig_win_hide = self.window.window.connect("hide", self._on_window_hide)
self._sig_win_show = self.window.window.connect("show", self._on_window_show)
if self.window.visible():
self.builder.get_object("menuitem_show_deluge").set_active(True)
else:
self.builder.get_object("menuitem_show_deluge").set_active(False)
# Show the Application Indicator
self.indicator.set_status(appindicator.STATUS_ACTIVE)
else:
log.debug("Enabling the system tray icon..")
if deluge.common.windows_check() or deluge.common.osx_check():
self.tray = gtk.status_icon_new_from_pixbuf(common.get_logo(32))
else:
try:
self.tray = gtk.status_icon_new_from_icon_name("deluge")
except:
log.warning("Update PyGTK to 2.10 or greater for SystemTray..")
return
self.tray.connect("activate", self.on_tray_clicked)
self.tray.connect("popup-menu", self.on_tray_popup)
# For some reason these icons do not display in appindicator
self.builder.get_object("download-limit-image").set_from_file(
deluge.common.get_pixmap("downloading16.png"))
self.builder.get_object("upload-limit-image").set_from_file(
deluge.common.get_pixmap("seeding16.png"))
client.register_event_handler("ConfigValueChangedEvent", self.config_value_changed)
if client.connected():
# We're connected so we need to get some values from the core
self.__start()
else:
# Hide menu widgets because we're not connected to a host.
for widget in self.hide_widget_list:
self.builder.get_object(widget).hide()
def __start(self):
if self.config["enable_system_tray"]:
#.........这里部分代码省略.........
示例6: MainWindow
# 需要导入模块: from deluge.configmanager import ConfigManager [as 别名]
# 或者: from deluge.configmanager.ConfigManager import register_set_function [as 别名]
class MainWindow(component.Component):
def __init__(self):
if wnck:
self.screen = wnck.screen_get_default()
component.Component.__init__(self, 'MainWindow', interval=2)
self.config = ConfigManager('gtkui.conf')
self.main_builder = gtk.Builder()
# Patch this GtkBuilder to avoid connecting signals from elsewhere
#
# Think about splitting up mainwindow gtkbuilder file into the necessary parts
# to avoid GtkBuilder monkey patch. Those parts would then need adding to mainwindow 'by hand'.
self.gtk_builder_signals_holder = _GtkBuilderSignalsHolder()
self.main_builder.prev_connect_signals = copy.deepcopy(self.main_builder.connect_signals)
def patched_connect_signals(*a, **k):
raise RuntimeError('In order to connect signals to this GtkBuilder instance please use '
'"component.get(\'MainWindow\').connect_signals()"')
self.main_builder.connect_signals = patched_connect_signals
# Get Gtk Builder files Main Window, New release dialog, and Tabs.
for filename in ('main_window.ui', 'main_window.new_release.ui', 'main_window.tabs.ui',
'main_window.tabs.menu_file.ui', 'main_window.tabs.menu_peer.ui'):
self.main_builder.add_from_file(
resource_filename('deluge.ui.gtkui', os.path.join('glade', filename)))
self.window = self.main_builder.get_object('main_window')
self.window.set_icon(deluge.ui.gtkui.common.get_deluge_icon())
self.vpaned = self.main_builder.get_object('vpaned')
self.initial_vpaned_position = self.config['window_pane_position']
# Keep a list of components to pause and resume when changing window state.
self.child_components = ['TorrentView', 'StatusBar', 'TorrentDetails']
# Load the window state
self.load_window_state()
# Keep track of window minimization state so we don't update UI when it is minimized.
self.is_minimized = False
self.restart = False
self.window.drag_dest_set(gtk.DEST_DEFAULT_ALL, [('text/uri-list', 0, 80)], ACTION_COPY)
# Connect events
self.window.connect('window-state-event', self.on_window_state_event)
self.window.connect('configure-event', self.on_window_configure_event)
self.window.connect('delete-event', self.on_window_delete_event)
self.window.connect('drag-data-received', self.on_drag_data_received_event)
self.vpaned.connect('notify::position', self.on_vpaned_position_event)
self.window.connect('expose-event', self.on_expose_event)
self.config.register_set_function('show_rate_in_title', self._on_set_show_rate_in_title, apply_now=False)
client.register_event_handler('NewVersionAvailableEvent', self.on_newversionavailable_event)
def connect_signals(self, mapping_or_class):
self.gtk_builder_signals_holder.connect_signals(mapping_or_class)
def first_show(self):
self.main_builder.prev_connect_signals(self.gtk_builder_signals_holder)
self.vpaned.set_position(self.initial_vpaned_position)
if not (
self.config['start_in_tray'] and self.config['enable_system_tray']
) and not self.window.get_property('visible'):
log.debug('Showing window')
self.show()
while gtk.events_pending():
gtk.main_iteration()
def show(self):
component.resume(self.child_components)
self.window.show()
def hide(self):
component.get('TorrentView').save_state()
component.pause(self.child_components)
# Store the x, y positions for when we restore the window
self.config['window_x_pos'], self.config['window_y_pos'] = self.window.get_position()
self.window.hide()
def present(self):
def restore():
# Restore the proper x,y coords for the window prior to showing it
component.resume(self.child_components)
self.window.present()
self.load_window_state()
if self.config['lock_tray'] and not self.visible():
dialog = PasswordDialog(_('Enter your password to show Deluge...'))
def on_dialog_response(response_id):
if response_id == gtk.RESPONSE_OK:
if self.config['tray_password'] == sha(dialog.get_password()).hexdigest():
restore()
dialog.run().addCallback(on_dialog_response)
else:
restore()
#.........这里部分代码省略.........
示例7: MainWindow
# 需要导入模块: from deluge.configmanager import ConfigManager [as 别名]
# 或者: from deluge.configmanager.ConfigManager import register_set_function [as 别名]
class MainWindow(component.Component):
def __init__(self):
component.Component.__init__(self, "MainWindow", interval=2)
self.config = ConfigManager("gtkui.conf")
# Get the glade file for the main window
self.main_glade = gtk.glade.XML(deluge.common.resource_filename(
"deluge.ui.gtkui", os.path.join("glade", "main_window.glade"))
)
self.window = self.main_glade.get_widget("main_window")
self.window.set_icon(common.get_deluge_icon())
self.vpaned = self.main_glade.get_widget("vpaned")
self.initial_vpaned_position = self.config["window_pane_position"]
# Load the window state
self.load_window_state()
# Keep track of window's minimization state so that we don't update the
# UI when it is minimized.
self.is_minimized = False
self.window.drag_dest_set(gtk.DEST_DEFAULT_ALL, [('text/uri-list', 0,
80)], gtk.gdk.ACTION_COPY)
# Connect events
self.window.connect("window-state-event", self.on_window_state_event)
self.window.connect("configure-event", self.on_window_configure_event)
self.window.connect("delete-event", self.on_window_delete_event)
self.window.connect("drag-data-received", self.on_drag_data_received_event)
self.vpaned.connect("notify::position", self.on_vpaned_position_event)
self.window.connect("expose-event", self.on_expose_event)
self.config.register_set_function("show_rate_in_title", self._on_set_show_rate_in_title, apply_now=False)
client.register_event_handler("NewVersionAvailableEvent", self.on_newversionavailable_event)
client.register_event_handler("TorrentFinishedEvent", self.on_torrentfinished_event)
def first_show(self):
if not(self.config["start_in_tray"] and \
self.config["enable_system_tray"]) and not \
self.window.get_property("visible"):
log.debug("Showing window")
self.show()
while gtk.events_pending():
gtk.main_iteration(False)
self.vpaned.set_position(self.initial_vpaned_position)
def show(self):
try:
component.resume("TorrentView")
component.resume("StatusBar")
component.resume("TorrentDetails")
except:
pass
self.window.show()
def hide(self):
component.pause("TorrentView")
component.get("TorrentView").save_state()
component.pause("StatusBar")
component.pause("TorrentDetails")
# Store the x, y positions for when we restore the window
self.window_x_pos = self.window.get_position()[0]
self.window_y_pos = self.window.get_position()[1]
self.window.hide()
def present(self):
# Restore the proper x,y coords for the window prior to showing it
try:
self.config["window_x_pos"] = self.window_x_pos
self.config["window_y_pos"] = self.window_y_pos
except:
pass
try:
component.resume("TorrentView")
component.resume("StatusBar")
component.resume("TorrentDetails")
except:
pass
self.window.present()
self.load_window_state()
def active(self):
"""Returns True if the window is active, False if not."""
return self.window.is_active()
def visible(self):
"""Returns True if window is visible, False if not."""
return self.window.get_property("visible")
def get_glade(self):
"""Returns a reference to the main window glade object."""
return self.main_glade
def quit(self, shutdown=False):
#.........这里部分代码省略.........
示例8: StatusTab
# 需要导入模块: from deluge.configmanager import ConfigManager [as 别名]
# 或者: from deluge.configmanager.ConfigManager import register_set_function [as 别名]
class StatusTab(Tab):
def __init__(self):
super(StatusTab, self).__init__('Status', 'status_tab', 'status_tab_label')
self.config = ConfigManager('gtkui.conf')
self.progressbar = self.main_builder.get_object('progressbar')
self.piecesbar = None
self.add_tab_widget('summary_availability', fratio, ('distributed_copies',))
self.add_tab_widget('summary_total_downloaded', ftotal_sized,
('all_time_download', 'total_payload_download'))
self.add_tab_widget('summary_total_uploaded', ftotal_sized,
('total_uploaded', 'total_payload_upload'))
self.add_tab_widget('summary_download_speed', fspeed_max,
('download_payload_rate', 'max_download_speed'))
self.add_tab_widget('summary_upload_speed', fspeed_max,
('upload_payload_rate', 'max_upload_speed'))
self.add_tab_widget('summary_seeds', fpeer, ('num_seeds', 'total_seeds'))
self.add_tab_widget('summary_peers', fpeer, ('num_peers', 'total_peers'))
self.add_tab_widget('summary_eta', ftime_or_dash, ('eta',))
self.add_tab_widget('summary_share_ratio', fratio, ('ratio',))
self.add_tab_widget('summary_active_time', ftime_or_dash, ('active_time',))
self.add_tab_widget('summary_seed_time', ftime_or_dash, ('seeding_time',))
self.add_tab_widget('summary_seed_rank', fseed_rank_or_dash, ('seed_rank', 'seeding_time'))
self.add_tab_widget('progressbar', fpcnt, ('progress', 'state', 'message'))
self.add_tab_widget('summary_last_seen_complete', fdate_or_never, ('last_seen_complete',))
self.add_tab_widget('summary_last_transfer', ftime_or_dash, ('time_since_transfer',))
self.config.register_set_function('show_piecesbar', self.on_show_piecesbar_config_changed, apply_now=True)
def update(self):
# Get the first selected torrent
selected = component.get('TorrentView').get_selected_torrent()
if not selected:
# No torrent is selected in the torrentview
self.clear()
return
# Get the torrent status
status_keys = self.status_keys
if self.config['show_piecesbar']:
status_keys.extend(['pieces', 'num_pieces'])
component.get('SessionProxy').get_torrent_status(
selected, status_keys).addCallback(self._on_get_torrent_status)
def _on_get_torrent_status(self, status):
# Check to see if we got valid data from the core
if not status:
return
# Update all the label widgets
for widget in self.tab_widgets.values():
txt = self.widget_status_as_fstr(widget, status)
if widget[0].get_text() != txt:
widget[0].set_text(txt)
# Update progress bar seperately as it's a special case (not a label).
fraction = status['progress'] / 100
if self.config['show_piecesbar']:
if self.piecesbar.get_fraction() != fraction:
self.piecesbar.set_fraction(fraction)
if status['state'] != 'Checking' and self.piecesbar.get_pieces() != status['pieces']:
# Skip pieces assignment if checking torrent.
self.piecesbar.set_pieces(status['pieces'], status['num_pieces'])
self.piecesbar.update()
else:
if self.progressbar.get_fraction() != fraction:
self.progressbar.set_fraction(fraction)
def on_show_piecesbar_config_changed(self, key, show):
if show:
self.show_piecesbar()
else:
self.hide_piecesbar()
def show_piecesbar(self):
if self.piecesbar is None:
self.piecesbar = PiecesBar()
self.main_builder.get_object(
'status_progress_vbox').pack_start(self.piecesbar, False, False, 0)
self.tab_widgets['piecesbar'] = TabWidget(self.piecesbar, fpcnt, ('progress', 'state', 'message'))
self.piecesbar.show()
self.progressbar.hide()
def hide_piecesbar(self):
self.progressbar.show()
if self.piecesbar:
self.piecesbar.hide()
self.tab_widgets.pop('piecesbar', None)
self.piecesbar = None
def clear(self):
for widget in self.tab_widgets.values():
widget[0].set_text('')
if self.config['show_piecesbar']:
#.........这里部分代码省略.........
示例9: MenuBar
# 需要导入模块: from deluge.configmanager import ConfigManager [as 别名]
# 或者: from deluge.configmanager.ConfigManager import register_set_function [as 别名]
#.........这里部分代码省略.........
## Help Menu
"on_menuitem_homepage_activate": self.on_menuitem_homepage_activate,
"on_menuitem_faq_activate": self.on_menuitem_faq_activate,
"on_menuitem_community_activate": \
self.on_menuitem_community_activate,
"on_menuitem_about_activate": self.on_menuitem_about_activate,
"on_menuitem_sidebar_zero_toggled":self.on_menuitem_sidebar_zero_toggled,
"on_menuitem_sidebar_trackers_toggled":self.on_menuitem_sidebar_trackers_toggled
})
self.torrentmenu_glade.signal_autoconnect({
## Torrent Menu
"on_menuitem_pause_activate": self.on_menuitem_pause_activate,
"on_menuitem_resume_activate": self.on_menuitem_resume_activate,
"on_menuitem_updatetracker_activate": \
self.on_menuitem_updatetracker_activate,
"on_menuitem_edittrackers_activate": \
self.on_menuitem_edittrackers_activate,
"on_menuitem_remove_activate": \
self.on_menuitem_remove_activate,
"on_menuitem_recheck_activate": self.on_menuitem_recheck_activate,
"on_menuitem_open_folder_activate": self.on_menuitem_open_folder_activate,
"on_menuitem_move_activate": self.on_menuitem_move_activate,
"on_menuitem_queue_top_activate": self.on_menuitem_queue_top_activate,
"on_menuitem_queue_up_activate": self.on_menuitem_queue_up_activate,
"on_menuitem_queue_down_activate": self.on_menuitem_queue_down_activate,
"on_menuitem_queue_bottom_activate": self.on_menuitem_queue_bottom_activate
})
self.change_sensitivity = [
"menuitem_addtorrent"
]
self.config.register_set_function("classic_mode", self._on_classic_mode)
client.register_event_handler("TorrentStateChangedEvent", self.on_torrentstatechanged_event)
client.register_event_handler("TorrentResumedEvent", self.on_torrentresumed_event)
client.register_event_handler("SessionPausedEvent", self.on_sessionpaused_event)
client.register_event_handler("SessionResumedEvent", self.on_sessionresumed_event)
def start(self):
for widget in self.change_sensitivity:
self.window.main_glade.get_widget(widget).set_sensitive(True)
# Hide the Open Folder menuitem and separator if not connected to a
# localhost.
non_remote_items = [
"menuitem_open_folder",
"separator4"
]
if not client.is_localhost():
for widget in non_remote_items:
self.torrentmenu_glade.get_widget(widget).hide()
self.torrentmenu_glade.get_widget(widget).set_no_show_all(True)
else:
for widget in non_remote_items:
self.torrentmenu_glade.get_widget(widget).set_no_show_all(False)
if not self.config["classic_mode"]:
self.window.main_glade.get_widget("separatormenuitem").show()
self.window.main_glade.get_widget("menuitem_quitdaemon").show()
# Show the Torrent menu because we're connected to a host
self.menu_torrent.show()
if client.get_auth_level() == deluge.common.AUTH_LEVEL_ADMIN:
示例10: SystemTray
# 需要导入模块: from deluge.configmanager import ConfigManager [as 别名]
# 或者: from deluge.configmanager.ConfigManager import register_set_function [as 别名]
class SystemTray(component.Component):
def __init__(self):
component.Component.__init__(self, 'SystemTray', interval=4)
self.mainwindow = component.get('MainWindow')
self.config = ConfigManager('gtkui.conf')
# List of widgets that need to be hidden when not connected to a host
self.hide_widget_list = [
'menuitem_add_torrent',
'menuitem_pause_session',
'menuitem_resume_session',
'menuitem_download_limit',
'menuitem_upload_limit',
'menuitem_quitdaemon',
'separatormenuitem1',
'separatormenuitem2',
'separatormenuitem3',
'separatormenuitem4'
]
self.config.register_set_function('enable_system_tray', self.on_enable_system_tray_set)
# bit of a hack to prevent function from doing something on startup
self.__enabled_set_once = False
self.config.register_set_function('enable_appindicator', self.on_enable_appindicator_set)
self.max_download_speed = -1.0
self.download_rate = 0.0
self.max_upload_speed = -1.0
self.upload_rate = 0.0
self.config_value_changed_dict = {
'max_download_speed': self._on_max_download_speed,
'max_upload_speed': self._on_max_upload_speed
}
def enable(self):
"""Enables the system tray icon."""
self.builder = Builder()
self.builder.add_from_file(resource_filename('deluge.ui.gtkui', os.path.join(
'glade', 'tray_menu.ui')))
self.builder.connect_signals(self)
self.tray_menu = self.builder.get_object('tray_menu')
if appindicator and self.config['enable_appindicator']:
log.debug('Enabling the Application Indicator...')
self.indicator = appindicator.Indicator('deluge', 'deluge',
appindicator.CATEGORY_APPLICATION_STATUS)
try:
self.indicator.set_property('title', _('Deluge'))
except TypeError:
# Catch 'title' property error for previous appindicator versions
pass
# Pass the menu to the Application Indicator
self.indicator.set_menu(self.tray_menu)
# Make sure the status of the Show Window MenuItem is correct
self._sig_win_hide = self.mainwindow.window.connect('hide', self._on_window_hide)
self._sig_win_show = self.mainwindow.window.connect('show', self._on_window_show)
if self.mainwindow.visible():
self.builder.get_object('menuitem_show_deluge').set_active(True)
else:
self.builder.get_object('menuitem_show_deluge').set_active(False)
# Show the Application Indicator
self.indicator.set_status(appindicator.STATUS_ACTIVE)
else:
log.debug('Enabling the system tray icon..')
if windows_check():
self.tray = status_icon_new_from_pixbuf(get_logo(32))
else:
self.tray = status_icon_new_from_icon_name('deluge')
self.tray.connect('activate', self.on_tray_clicked)
self.tray.connect('popup-menu', self.on_tray_popup)
self.builder.get_object('download-limit-image').set_from_file(get_pixmap('downloading16.png'))
self.builder.get_object('upload-limit-image').set_from_file(get_pixmap('seeding16.png'))
client.register_event_handler('ConfigValueChangedEvent', self.config_value_changed)
if client.connected():
# We're connected so we need to get some values from the core
self.__start()
else:
# Hide menu widgets because we're not connected to a host.
for widget in self.hide_widget_list:
self.builder.get_object(widget).hide()
def __start(self):
if self.config['enable_system_tray']:
if self.config['standalone']:
try:
self.hide_widget_list.remove('menuitem_quitdaemon')
self.hide_widget_list.remove('separatormenuitem4')
except ValueError:
pass
self.builder.get_object('menuitem_quitdaemon').hide()
self.builder.get_object('separatormenuitem4').hide()
#.........这里部分代码省略.........
示例11: TorrentManager
# 需要导入模块: from deluge.configmanager import ConfigManager [as 别名]
# 或者: from deluge.configmanager.ConfigManager import register_set_function [as 别名]
class TorrentManager(component.Component):
"""
TorrentManager contains a list of torrents in the current libtorrent
session. This object is also responsible for saving the state of the
session for use on restart.
"""
def __init__(self):
component.Component.__init__(self, "TorrentManager", interval=5,
depend=["CorePluginManager", "AlertManager"])
log.debug("TorrentManager init..")
# Set the libtorrent session
self.session = component.get("Core").session
# Set the alertmanager
self.alerts = component.get("AlertManager")
# Get the core config
self.config = ConfigManager("core.conf")
# Make sure the state folder has been created
if not os.path.exists(os.path.join(get_config_dir(), "state")):
os.makedirs(os.path.join(get_config_dir(), "state"))
# Create the torrents dict { torrent_id: Torrent }
self.torrents = {}
self.queued_torrents = set()
# This is a map of torrent_ids to Deferreds used to track needed resume data.
# The Deferreds will be completed when resume data has been saved.
self.waiting_on_resume_data = {}
# Keeps track of resume data
self.resume_data = {}
self.torrents_status_requests = []
self.status_dict = {}
self.last_state_update_alert_ts = 0
# Register set functions
self.config.register_set_function("max_connections_per_torrent",
self.on_set_max_connections_per_torrent)
self.config.register_set_function("max_upload_slots_per_torrent",
self.on_set_max_upload_slots_per_torrent)
self.config.register_set_function("max_upload_speed_per_torrent",
self.on_set_max_upload_speed_per_torrent)
self.config.register_set_function("max_download_speed_per_torrent",
self.on_set_max_download_speed_per_torrent)
# Register alert functions
self.alerts.register_handler("torrent_finished_alert",
self.on_alert_torrent_finished)
self.alerts.register_handler("torrent_paused_alert",
self.on_alert_torrent_paused)
self.alerts.register_handler("torrent_checked_alert",
self.on_alert_torrent_checked)
self.alerts.register_handler("tracker_reply_alert",
self.on_alert_tracker_reply)
self.alerts.register_handler("tracker_announce_alert",
self.on_alert_tracker_announce)
self.alerts.register_handler("tracker_warning_alert",
self.on_alert_tracker_warning)
self.alerts.register_handler("tracker_error_alert",
self.on_alert_tracker_error)
self.alerts.register_handler("storage_moved_alert",
self.on_alert_storage_moved)
self.alerts.register_handler("torrent_resumed_alert",
self.on_alert_torrent_resumed)
self.alerts.register_handler("state_changed_alert",
self.on_alert_state_changed)
self.alerts.register_handler("save_resume_data_alert",
self.on_alert_save_resume_data)
self.alerts.register_handler("save_resume_data_failed_alert",
self.on_alert_save_resume_data_failed)
self.alerts.register_handler("file_renamed_alert",
self.on_alert_file_renamed)
self.alerts.register_handler("metadata_received_alert",
self.on_alert_metadata_received)
self.alerts.register_handler("file_error_alert",
self.on_alert_file_error)
self.alerts.register_handler("file_completed_alert",
self.on_alert_file_completed)
self.alerts.register_handler("state_update_alert",
self.on_alert_state_update)
def start(self):
# Get the pluginmanager reference
self.plugins = component.get("CorePluginManager")
# Run the old state upgrader before loading state
deluge.core.oldstateupgrader.OldStateUpgrader()
# Try to load the state from file
self.load_state()
# Save the state periodically
self.save_state_timer = LoopingCall(self.save_state)
self.save_state_timer.start(200, False)
self.save_resume_data_timer = LoopingCall(self.save_resume_data)
self.save_resume_data_timer.start(190, False)
# Force update for all resume data a bit less frequently
self.save_all_resume_data_timer = LoopingCall(self.save_resume_data, self.torrents.keys())
#.........这里部分代码省略.........
示例12: ToolBar
# 需要导入模块: from deluge.configmanager import ConfigManager [as 别名]
# 或者: from deluge.configmanager.ConfigManager import register_set_function [as 别名]
class ToolBar(component.Component):
def __init__(self):
component.Component.__init__(self, "ToolBar")
log.debug("ToolBar Init..")
self.window = component.get("MainWindow")
self.toolbar = self.window.main_glade.get_widget("toolbar")
self.config = ConfigManager("gtkui.conf")
### Connect Signals ###
self.window.main_glade.signal_autoconnect({
"on_toolbutton_add_clicked": self.on_toolbutton_add_clicked,
"on_toolbutton_remove_clicked": self.on_toolbutton_remove_clicked,
"on_toolbutton_pause_clicked": self.on_toolbutton_pause_clicked,
"on_toolbutton_resume_clicked": self.on_toolbutton_resume_clicked,
"on_toolbutton_preferences_clicked": \
self.on_toolbutton_preferences_clicked,
"on_toolbutton_connectionmanager_clicked": \
self.on_toolbutton_connectionmanager_clicked,
"on_toolbutton_queue_up_clicked": self.on_toolbutton_queue_up_clicked,
"on_toolbutton_queue_down_clicked": self.on_toolbutton_queue_down_clicked
})
self.change_sensitivity = [
"toolbutton_add",
"toolbutton_remove",
"toolbutton_pause",
"toolbutton_resume",
"toolbutton_queue_up",
"toolbutton_queue_down"
]
self.config.register_set_function("classic_mode", self._on_classic_mode, True)
# Hide if necessary
self.visible(self.config["show_toolbar"])
def start(self):
if not self.config["classic_mode"]:
self.window.main_glade.get_widget("toolbutton_connectionmanager").show()
for widget in self.change_sensitivity:
self.window.main_glade.get_widget(widget).set_sensitive(True)
def stop(self):
for widget in self.change_sensitivity:
self.window.main_glade.get_widget(widget).set_sensitive(False)
def visible(self, visible):
if visible:
self.toolbar.show()
else:
self.toolbar.hide()
self.config["show_toolbar"] = visible
def add_toolbutton(self, callback, label=None, image=None, stock=None,
tooltip=None):
"""Adds a toolbutton to the toolbar"""
# Create the button
toolbutton = gtk.ToolButton()
if stock is not None:
toolbutton.set_stock_id(stock)
if label is not None:
toolbutton.set_label(label)
if image is not None:
toolbutton.set_icon_widget(image)
# Set the tooltip
if tooltip is not None:
toolbutton.set_tooltip_text(tooltip)
# Connect the 'clicked' event callback
toolbutton.connect("clicked", callback)
# Append the button to the toolbar
self.toolbar.insert(toolbutton, -1)
# Show the new toolbutton
toolbutton.show_all()
return toolbutton
def add_separator(self, position=None):
"""Adds a separator toolitem"""
sep = gtk.SeparatorToolItem()
if position is not None:
self.toolbar.insert(sep, position)
else:
# Append the separator
self.toolbar.insert(sep, -1)
sep.show()
return sep
def remove(self, widget):
"""Removes a widget from the toolbar"""
self.toolbar.remove(widget)
### Callbacks ###
def on_toolbutton_add_clicked(self, data):
log.debug("on_toolbutton_add_clicked")
# Use the menubar's callback
component.get("MenuBar").on_menuitem_addtorrent_activate(data)
#.........这里部分代码省略.........