Re: [Rhythmbox-devel] Plugin Activation/Deactivation



Sure, but remember this is my first RB plugin and my first experience
with python.

Nicholas

On Wed, 2007-12-26 at 12:59 -0500, Andrew Conkling wrote:
> On Dec 26, 2007 12:24 PM, Nicholas S. Clarkson
> <nclarkson sporadicspeculations com> wrote:
>                I am writing a Rhythmbox plugin to save and restore the
>         playing song. I
>         have got my plugin to work through a menu option but I would
>         rather it
>         work on load and close. However, it appears that the db and
>         play
>         functions I am trying to use are not available to my plugin at
>         activation/deactivation. Is there a way to adjust the time at
>         which my
>         plugin is activate/deactivated so that the necessary functions
>         are
>         available?
> 
> Nice plugin idea. Would it be too much to ask you to post the source
> for your plugin? I don't have a ready answer to your question, but I'm
> wondering if we might be able to figure something clever out.
> 
> Off the top of my head, I'm wondering if we move the code from
> activate() to a new function if that'd make a difference.
> 
> Cheers,
> Andrew Conkling
> 
import rhythmdb, rb
import gobject, gtk
import gconf

ui_str = """
<ui>
	<menubar name="MenuBar">
		<menu name="ToolsMenu" action="Tools">
			<placeholder name="ToolsOps_6">
				<menuitem name="PythonSampleRestoreState" action="PythonSampleRestoreState"/>
				<menuitem name="PythonSampleSaveState" action="PythonSampleSaveState"/>
			</placeholder>
		</menu>
	</menubar>
</ui>
"""

class SamplePython(rb.Plugin):

	def __init__(self):
		rb.Plugin.__init__(self)
			
	def activate(self, shell):
		data = dict()
		manager = shell.get_player().get_property('ui-manager')

		data['action_group'] = gtk.ActionGroup('PythonSampleActions')

		action = gtk.Action('PythonSampleSaveState', _('_Save State'),_("Save playing song"), 'gnome-mime-text-x-python')
		action.connect('activate', self.save_state, shell)
		data['action_group'].add_action(action)

		action = gtk.Action('PythonSampleRestoreState', _('_Restore State'),_("Save playing song"), 'gnome-mime-text-x-python')
		action.connect('activate', self.restore_state, shell)
		data['action_group'].add_action(action)

		manager.insert_action_group(data['action_group'], 0)
		data['ui_id'] = manager.add_ui_from_string(ui_str)
		manager.ensure_update()

		shell.set_data('PythonSamplePluginInfo', data)
	
	def deactivate(self, shell):
		data = shell.get_data('PythonSamplePluginInfo')
		manager = shell.get_player().get_property('ui-manager')
		manager.remove_ui(data['ui_id'])
		manager.remove_action_group(data['action_group'])
		manager.ensure_update()
		shell.set_data('PythonSamplePluginInfo', None)

	def save_state(self, action, shell):
		db = shell.get_property ("db")
		client = gconf.client_get_default ()
		entry = shell.props.shell_player.get_playing_entry()
		id = db.entry_get (entry, rhythmdb.PROP_ENTRY_ID)
		client.set_int ("/apps/rhythmbox/plugins/sample-python/last_played_id", id)
		time_int = shell.props.shell_player.get_playing_time()
		client.set_int ("/apps/rhythmbox/plugins/sample-python/last_played_time_int", time_int)

	def restore_state(self, action, shell):
		db = shell.get_property ("db")
		client = gconf.client_get_default ()
		id = client.get_int ("/apps/rhythmbox/plugins/sample-python/last_played_id")
		time = client.get_int ("/apps/rhythmbox/plugins/sample-python/last_played_time_int")
		entry = db.entry_lookup_by_id (id);
		shell.props.shell_player.play_entry(entry)
		shell.props.shell_player.set_playing_time(time)

class PythonSource(rb.Source):
	def __init__(self):
		rb.Source.__init__(self)
		
gobject.type_register(PythonSource)


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]