# Path: deluge/component.py
# class ComponentAlreadyRegistered(Exception):
# class Component(object):
# class ComponentRegistry(object):
#     def __init__(self, name, interval=1, depend=None):
#     def _component_start_timer(self):
#     def _component_start(self):
#         def on_start(result):
#         def on_start_fail(result):
#     def _component_stop(self):
#         def on_stop(result):
#     def _component_pause(self):
#         def on_pause(result):
#     def _component_resume(self):
#         def on_resume(result):
#     def _component_shutdown(self):
#         def on_stop(result):
#     def __init__(self):
#     def register(self, obj):
#     def deregister(self, name):
#             def on_stop(result, name):
#     def start(self, names=[]):
#         def on_depends_started(result, name):
#     def stop(self, names=[]):
#     def pause(self, names=[]):
#     def resume(self, names=[]):
#     def shutdown(self):
#     def update(self):
# def get(name):
# 
# Path: deluge/ui/client.py
# RPC_RESPONSE = 1
# RPC_ERROR = 2
# RPC_EVENT = 3
# def format_kwargs(kwargs):
#     def __init__(self, method, args, kwargs, exception_type, exception_msg, traceback):
#     def __repr__(self):
#     def format_message(self):
#     def connectionMade(self):
#     def dataReceived(self, data):
#     def send_request(self, request):
#     def __init__(self, daemon, event_handlers):
#     def startedConnecting(self, connector):
#     def clientConnectionFailed(self, connector, reason):
#     def clientConnectionLost(self, connector, reason):
#     def __init__(self, event_handlers={}):
#     def connect(self, host, port, username, password):
#     def disconnect(self):
#     def call(self, method, *args, **kwargs):
#     def pop_deferred(self, request_id):
#     def register_event_handler(self, event, handler):
#     def deregister_event_handler(self, event, handler):
#     def __rpcError(self, error_data):
#     def __on_connect(self, result, username, password):
#     def __on_connect_fail(self, reason):
#     def __on_login(self, result, username):
#     def __on_login_fail(self, result):
#     def set_disconnect_callback(self, cb):
#     def get_bytes_recv(self):
#     def get_bytes_sent(self):
#     def __init__(self, event_handlers={}):
#     def disconnect(self):
#     def call(self, method, *args, **kwargs):
#     def register_event_handler(self, event, handler):
#     def deregister_event_handler(self, event, handler):
#     def __init__(self, daemon, method):
#     def __call__(self, *args, **kwargs):
#     def __getattr__(self, name):
#     def __call__(self, *args, **kwargs):
#     def __init__(self):
#     def connect(self, host="127.0.0.1", port=58846, username="", password=""):
#         def on_connect_fail(result):
#     def disconnect(self):
#     def start_classic_mode(self):
#     def start_daemon(self, port, config):
#     def is_localhost(self):
#     def is_classicmode(self):
#     def connected(self):
#     def connection_info(self):
#     def register_event_handler(self, event, handler):
#     def deregister_event_handler(self, event, handler):
#     def force_call(self, block=False):
#     def __getattr__(self, method):
#     def set_disconnect_callback(self, cb):
#     def __on_disconnect(self):
#     def get_bytes_recv(self):
#     def get_bytes_sent(self):
# class DelugeRPCError(object):
# class DelugeRPCRequest(object):
# class DelugeRPCProtocol(Protocol):
# class DelugeRPCClientFactory(ClientFactory):
# class DaemonProxy(object):
# class DaemonSSLProxy(DaemonProxy):
# class DaemonClassicProxy(DaemonProxy):
# class DottedObject(object):
# class RemoteMethod(DottedObject):
# class Client(object):


import os
import pkg_resources    # access plugin egg
import gtk, gobject
from deluge.log import LOG as log
from deluge import component    # for systray
from deluge.ui.client import client
    def __init__(self):
        gtk.MenuItem.__init__(self, _("Label"))

        self.sub_menu = gtk.Menu()
        self.set_submenu(self.sub_menu)
        self.items = []

        #attach..
        torrentmenu = component.get("MenuBar").torrentmenu
        self.sub_menu.connect("show", self.on_show, None)

    def get_torrent_ids(self):
        return component.get("TorrentView").get_selected_torrents()

    def on_show(self, widget=None, data=None):
        log.debug("label-on-show")
        client.label.get_labels().addCallback(self.cb_labels)

    def cb_labels(self, labels):
        for child in self.sub_menu.get_children():
            self.sub_menu.remove(child)
        for label in [NO_LABEL] + list(labels):
            item = gtk.MenuItem(label.replace("_","__"))
            item.connect("activate", self.on_select_label, label)
            self.sub_menu.append(item)
        self.show_all()

    def on_select_label(self, widget=None, label_id=None):
        log.debug("select label:%s,%s" % (label_id ,self.get_torrent_ids()) )
        for torrent_id in self.get_torrent_ids():

# Path: deluge/component.py
# class ComponentAlreadyRegistered(Exception):
# class Component(object):
# class ComponentRegistry(object):
#     def __init__(self, name, interval=1, depend=None):
#     def _component_start_timer(self):
#     def _component_start(self):
#         def on_start(result):
#         def on_start_fail(result):
#     def _component_stop(self):
#         def on_stop(result):
#     def _component_pause(self):
#         def on_pause(result):
#     def _component_resume(self):
#         def on_resume(result):
#     def _component_shutdown(self):
#         def on_stop(result):
#     def __init__(self):
#     def register(self, obj):
#     def deregister(self, name):
#             def on_stop(result, name):
#     def start(self, names=[]):
#         def on_depends_started(result, name):
#     def stop(self, names=[]):
#     def pause(self, names=[]):
#     def resume(self, names=[]):
#     def shutdown(self):
#     def update(self):
# def get(name):
# 
# Path: deluge/ui/client.py
# RPC_RESPONSE = 1
# RPC_ERROR = 2
# RPC_EVENT = 3
# def format_kwargs(kwargs):
#     def __init__(self, method, args, kwargs, exception_type, exception_msg, traceback):
#     def __repr__(self):
#     def format_message(self):
#     def connectionMade(self):
#     def dataReceived(self, data):
#     def send_request(self, request):
#     def __init__(self, daemon, event_handlers):
#     def startedConnecting(self, connector):
#     def clientConnectionFailed(self, connector, reason):
#     def clientConnectionLost(self, connector, reason):
#     def __init__(self, event_handlers={}):
#     def connect(self, host, port, username, password):
#     def disconnect(self):
#     def call(self, method, *args, **kwargs):
#     def pop_deferred(self, request_id):
#     def register_event_handler(self, event, handler):
#     def deregister_event_handler(self, event, handler):
#     def __rpcError(self, error_data):
#     def __on_connect(self, result, username, password):
#     def __on_connect_fail(self, reason):
#     def __on_login(self, result, username):
#     def __on_login_fail(self, result):
#     def set_disconnect_callback(self, cb):
#     def get_bytes_recv(self):
#     def get_bytes_sent(self):
#     def __init__(self, event_handlers={}):
#     def disconnect(self):
#     def call(self, method, *args, **kwargs):
#     def register_event_handler(self, event, handler):
#     def deregister_event_handler(self, event, handler):
#     def __init__(self, daemon, method):
#     def __call__(self, *args, **kwargs):
#     def __getattr__(self, name):
#     def __call__(self, *args, **kwargs):
#     def __init__(self):
#     def connect(self, host="127.0.0.1", port=58846, username="", password=""):
#         def on_connect_fail(result):
#     def disconnect(self):
#     def start_classic_mode(self):
#     def start_daemon(self, port, config):
#     def is_localhost(self):
#     def is_classicmode(self):
#     def connected(self):
#     def connection_info(self):
#     def register_event_handler(self, event, handler):
#     def deregister_event_handler(self, event, handler):
#     def force_call(self, block=False):
#     def __getattr__(self, method):
#     def set_disconnect_callback(self, cb):
#     def __on_disconnect(self):
#     def get_bytes_recv(self):
#     def get_bytes_sent(self):
# class DelugeRPCError(object):
# class DelugeRPCRequest(object):
# class DelugeRPCProtocol(Protocol):
# class DelugeRPCClientFactory(ClientFactory):
# class DaemonProxy(object):
# class DaemonSSLProxy(DaemonProxy):
# class DaemonClassicProxy(DaemonProxy):
# class DottedObject(object):
# class RemoteMethod(DottedObject):
# class Client(object):


# Path: deluge/plugins/label/label/gtkui/submenu.py
import os
import pkg_resources    # access plugin egg
import gtk, gobject
from deluge.log import LOG as log
from deluge import component    # for systray
from deluge.ui.client import client

    def __init__(self):
        gtk.MenuItem.__init__(self, _("Label"))

        self.sub_menu = gtk.Menu()
        self.set_submenu(self.sub_menu)
        self.items = []

        #attach..
        torrentmenu = component.get("MenuBar").torrentmenu
        self.sub_menu.connect("show", self.on_show, None)

    def get_torrent_ids(self):
        return component.get("TorrentView").get_selected_torrents()

    def on_show(self, widget=None, data=None):
        log.debug("label-on-show")
        client.label.get_labels().addCallback(self.cb_labels)

    def cb_labels(self, labels):
        for child in self.sub_menu.get_children():
            self.sub_menu.remove(child)
        for label in [NO_LABEL] + list(labels):
            item = gtk.MenuItem(label.replace("_","__"))
            item.connect("activate", self.on_select_label, label)
            self.sub_menu.append(item)
        self.show_all()

    def on_select_label(self, widget=None, label_id=None):
        log.debug("select label:%s,%s" % (label_id ,self.get_torrent_ids()) )
        for torrent_id in self.get_torrent_ids():

            client.label.set_torrent(torrent_id, label_id)