Devel 1.x: Registered components & core's export_functions

Suggest, post, or discuss plugins for Deluge
Post Reply
SGSeries2
Member
Member
Posts: 26
Joined: Sun Sep 07, 2008 1:56 am

Devel 1.x: Registered components & core's export_functions

Post by SGSeries2 »

I'm in the middle of creating a plugin in either trunk or the 1.0RC branch (I've tried this in both), and I was trying to access some of the functions in the core in my plugin's gtkui.py source file, primarily export_add_torrent_url and/or export_add_torrent_file, but I can't seem to figure out how to get to them. Am I missing something?

Here's some of my random code of the various things I've been trying (some, of which have been commented out):

Code: Select all

 
#unique_id = deluge.core.export_add_torrent_file(filename, fd, None)
#if component.get("Core") is None:
#    print 'there is no core!'
#self.core = self.plugin
components = component.getAll()
print components.keys()  
core = component.get('PluginManager').get_core()
#unique_id = component.get("Core").export_add_torrent_url(location, path, None)
#from deluge.plugins.coreclient import client
#unique_id = aclient.core_add_torrent_file(filename, fd, None)
#self.interface.torrent_model_append(unique_id)
#fileArray = {filename:filename}
#component.get('AddTorrentDialog').add_from_files(fileArray)
It's been driving me nuts. I noticed that the plugin blocklist has a reference to a registered component called "Core" (component.get("Core")), but that registered object doesn't seem to exist, and neither does TorrentManager for that matter. (I added a getAll function to component in order to dump the dictionary.) Are those supposed to be in there?
andar
Top Bloke
Top Bloke
Posts: 1050
Joined: Fri Jun 08, 2007 8:38 pm
Location: Victoria, BC
Contact:

Re: Devel 1.x: Registered components & core's export_functions

Post by andar »

SGSeries2 wrote:I'm in the middle of creating a plugin in either trunk or the 1.0RC branch (I've tried this in both), and I was trying to access some of the functions in the core in my plugin's gtkui.py source file, primarily export_add_torrent_url and/or export_add_torrent_file, but I can't seem to figure out how to get to them. Am I missing something?

Here's some of my random code of the various things I've been trying (some, of which have been commented out):

Code: Select all

 
#unique_id = deluge.core.export_add_torrent_file(filename, fd, None)
#if component.get("Core") is None:
#    print 'there is no core!'
#self.core = self.plugin
components = component.getAll()
print components.keys()  
core = component.get('PluginManager').get_core()
#unique_id = component.get("Core").export_add_torrent_url(location, path, None)
#from deluge.plugins.coreclient import client
#unique_id = aclient.core_add_torrent_file(filename, fd, None)
#self.interface.torrent_model_append(unique_id)
#fileArray = {filename:filename}
#component.get('AddTorrentDialog').add_from_files(fileArray)
It's been driving me nuts. I noticed that the plugin blocklist has a reference to a registered component called "Core" (component.get("Core")), but that registered object doesn't seem to exist, and neither does TorrentManager for that matter. (I added a getAll function to component in order to dump the dictionary.) Are those supposed to be in there?
What you need to remember is that the core/ui are separate, so you cannot access a core component directly.

To call core methods from the UI portion of the plugin do something like this:

Code: Select all

from deluge.ui.client import aclient as client
client.add_torrent_file(blah)
Remember that calling some methods with aclient will require a callback function since the call is done asynchronously. You could use sclient to simplify things, but I don't really recommend it's use for all things since it can cause UI interactivity issues.

Please read this for more information: http://dev.deluge-torrent.org/wiki/Development/UiClient
SGSeries2
Member
Member
Posts: 26
Joined: Sun Sep 07, 2008 1:56 am

Re: Devel 1.x: Registered components & core's export_functions

Post by SGSeries2 »

Ah, ok. Excellent. The core/ui structure is beginning to sink in. I was also originally going by the various random facts posted in the plugin section: (http://dev.deluge-torrent.org/wiki/Development/Plugins)
any "export_*" method in the core plugin is exposed as "plugin-name_*" in deluge.ui.client
and thought that maybe that might apply to the core's export functions as well (though it puzzled me as to how it would apply to the core, since the core wasn't technically a plugin). Now that I read the page you mentioned, my trail of thought was clearly off (although there are minor similarities).

Although it is linked from the development section, could we get the the 'deluge.ui.client' text mentioned above hyper-linked to the page you mentioned for any new-comers? New-comers may not be able to distinguish the correlation between Development/UiClient and deluge.ui.client.

With this new wealth of knowledge, I managed to get things working.

Thanks for the help and the quick reply!
Post Reply