Re: [Rhythmbox-devel] Plugin Activation/Deactivation
Is there any function available to a python plugin to close/exit rythmbox? I ask because since I cannot find a signal to inform my plugin that rhythmbox is closing, I figured I could just change my save_state function so that it closes RB after saving the current song. I did find rb.Player.close but I couldn't get it to work. Thanks Nicholas On Wed, 2007-12-26 at 12:21 -0700, Nicholas S. Clarkson wrote: > This does work but only for restoring the state. You would still have to > save the state manually. > > > On Wed, 2007-12-26 at 11:05 -0800, Adam Zimmerman wrote: > > > > On Dec 26, 2007 12:24 PM, Nicholas S. Clarkson > > > > <[EMAIL PROTECTED]> 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. > > > > A rather horrible approach would be to set a timeout in the activate() > > function for long enough that rhythmbox is *likely* to be ready... You'd > > have to catch an exception in the case that it wasn't ready (and > > presumably continue the timer instead of stopping it). > > > > If that's the approach you want to take, look at the gobject.timeout_add > > function. It's called like: > > > > gobject.timeout_add(6 * 60 * 60 * 1000, self.__update_catalogue) > > > > with the first argument being the number of milliseconds to wait, and > > the second being the function to call. If the function returns False > > then the timeout is discarded. If it returns anything else, then the > > timeout function is called again in another n milliseconds. > > > > Like I said, it's probably not a very "clean" way to do it, but it would > > likely work. > > > > -- > > Adam Zimmerman <[EMAIL PROTECTED]> > > > > CREATIVITY - > > http://mirrors.creativecommons.org/movingimages/Building_on_the_Past.mpg > > ALWAYS - http://www.musiccreators.ca/ > > BUILDS - http://www.ubuntu.com/ > > ON THE PAST - http://www.theopencd.org/ > > -- > > > > Work consists of whatever a body is obliged to do. > > Play consists of whatever a body is not obliged to do. > > -- Mark Twain > > > > ___ > > rhythmbox-devel mailing list > > rhythmbox-devel@gnome.org > > http://mail.gnome.org/mailman/listinfo/rhythmbox-devel > > > > ___ > rhythmbox-devel mailing list > rhythmbox-devel@gnome.org > http://mail.gnome.org/mailman/listinfo/rhythmbox-devel > ___ rhythmbox-devel mailing list rhythmbox-devel@gnome.org http://mail.gnome.org/mailman/listinfo/rhythmbox-devel
Re: [Rhythmbox-devel] Plugin Activation/Deactivation
This does work but only for restoring the state. You would still have to save the state manually. On Wed, 2007-12-26 at 11:05 -0800, Adam Zimmerman wrote: > > > On Dec 26, 2007 12:24 PM, Nicholas S. Clarkson > > > <[EMAIL PROTECTED]> 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. > > A rather horrible approach would be to set a timeout in the activate() > function for long enough that rhythmbox is *likely* to be ready... You'd > have to catch an exception in the case that it wasn't ready (and > presumably continue the timer instead of stopping it). > > If that's the approach you want to take, look at the gobject.timeout_add > function. It's called like: > > gobject.timeout_add(6 * 60 * 60 * 1000, self.__update_catalogue) > > with the first argument being the number of milliseconds to wait, and > the second being the function to call. If the function returns False > then the timeout is discarded. If it returns anything else, then the > timeout function is called again in another n milliseconds. > > Like I said, it's probably not a very "clean" way to do it, but it would > likely work. > > -- > Adam Zimmerman <[EMAIL PROTECTED]> > > CREATIVITY - > http://mirrors.creativecommons.org/movingimages/Building_on_the_Past.mpg > ALWAYS - http://www.musiccreators.ca/ > BUILDS - http://www.ubuntu.com/ > ON THE PAST - http://www.theopencd.org/ > -- > > Work consists of whatever a body is obliged to do. > Play consists of whatever a body is not obliged to do. > -- Mark Twain > > ___ > rhythmbox-devel mailing list > rhythmbox-devel@gnome.org > http://mail.gnome.org/mailman/listinfo/rhythmbox-devel > ___ rhythmbox-devel mailing list rhythmbox-devel@gnome.org http://mail.gnome.org/mailman/listinfo/rhythmbox-devel
Re: [Rhythmbox-devel] Plugin Activation/Deactivation
> > On Dec 26, 2007 12:24 PM, Nicholas S. Clarkson > > <[EMAIL PROTECTED]> 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. A rather horrible approach would be to set a timeout in the activate() function for long enough that rhythmbox is *likely* to be ready... You'd have to catch an exception in the case that it wasn't ready (and presumably continue the timer instead of stopping it). If that's the approach you want to take, look at the gobject.timeout_add function. It's called like: gobject.timeout_add(6 * 60 * 60 * 1000, self.__update_catalogue) with the first argument being the number of milliseconds to wait, and the second being the function to call. If the function returns False then the timeout is discarded. If it returns anything else, then the timeout function is called again in another n milliseconds. Like I said, it's probably not a very "clean" way to do it, but it would likely work. -- Adam Zimmerman <[EMAIL PROTECTED]> CREATIVITY - http://mirrors.creativecommons.org/movingimages/Building_on_the_Past.mpg ALWAYS - http://www.musiccreators.ca/ BUILDS - http://www.ubuntu.com/ ON THE PAST - http://www.theopencd.org/ -- Work consists of whatever a body is obliged to do. Play consists of whatever a body is not obliged to do. -- Mark Twain ___ rhythmbox-devel mailing list rhythmbox-devel@gnome.org http://mail.gnome.org/mailman/listinfo/rhythmbox-devel
Re: [Rhythmbox-devel] Plugin Activation/Deactivation
You could listen to a signal to see if Rhythmbox is ready, but I couldn't find a signal that can do that. You can put the song in the Queue (shell.add_to_queue) when your plugin is activated. On Dec 26, 2007 3:24 PM, Nicholas S. Clarkson < [EMAIL PROTECTED]> wrote: > Hello, >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? > > Thanks > Nicholas > > > ___ > rhythmbox-devel mailing list > rhythmbox-devel@gnome.org > http://mail.gnome.org/mailman/listinfo/rhythmbox-devel > -- Alexandre Rosenfeld ___ rhythmbox-devel mailing list rhythmbox-devel@gnome.org http://mail.gnome.org/mailman/listinfo/rhythmbox-devel
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 > <[EMAIL PROTECTED]> 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 = """ """ 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) ___ rhythmbox-devel mailing list rhythmbox-devel@gnome.org http://mail.gnome.org/mailman/listinfo/rhythmbox-devel
Re: [Rhythmbox-devel] Plugin Activation/Deactivation
On Dec 26, 2007 12:24 PM, Nicholas S. Clarkson < [EMAIL PROTECTED]> 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 ___ rhythmbox-devel mailing list rhythmbox-devel@gnome.org http://mail.gnome.org/mailman/listinfo/rhythmbox-devel