Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

Maybe this is obvious and I am missing it, or maybe someone's already written a great guide and my (seeming exhaustive) googling is failing to turn it up, but I cannot figure out for the life of me how to get the darn python console in rhythmbox to do anything!

I've enabled it from the plugin menu, and then open it using Tools->Python Console.

It prints

You can access the main window through the 'shell' variable :
<rb.Shell object at 0xa6cdd24 (RBShell at 0xa14e000)>
>>> 

But anything I type at the prompt does nothing! I've tried help, I've tried exit(), I've tried print "hello world", nothing does anything!

All of these things work, of course, in a normal python console. I haven't a clue what the devil the difference is here! Am I supposed to do something other than hit enter?

share|improve this question
    
I just knew "rhythmbox-client -h" from terminal. +1 for making aware of this plugin. –  Rojan Sep 4 '10 at 16:08

3 Answers 3

The Rhythmbox Plugins Writing Guide has several examples of commands you can use in the Python console to control playback and modify Rhythmbox:

  • Play/Pause

    shell.props.shell_player.playpause()
    
  • Stop

    shell.props.shell_player.stop()
    
  • Next track

    shell.props.shell_player.do_next()
    
  • Add a song to the Play Queue

    shell.add_to_queue("file://awsome_song.ogg")
    
  • Display a visualization

    import gst
    goom = gst.element_factory_make ("goom")
    sink = gst.element_factory_make ("ximagesink")
    colour = gst.element_factory_make ("ffmpegcolorspace")
    b = gst.Bin()
    b.add (goom, colour, sink)
    b.add_pad(gst.GhostPad("sink", goom.get_pad("sink")))
    goom.link(colour)
    colour.link(sink)
    shell.get_player().props.player.add_tee(b)
    
share|improve this answer
    
This is helpful, and actually I had found this previously, however what I am looking for is how to actually use the console. Is it just like a regular python console; type a command and hit enter? If so, then mine is broken. When I type a command and hit enter, it just makes a newline, without executing the line of code. As long as I know it's broken, then I can seek out help to fix it; I just wanted to make sure I wasn't doing something dumb (and couldn't find any documented use of it!) –  TJ Ellis Sep 4 '10 at 16:28
    
That does indeed sound like something is broken. In rhythmbox-0.12.8-0ubuntu7 with no other plugins enabled, the console works just like a regular Python console, e.g. type in print "hello world" and then press Enter. I don't see this problem reported anywhere else yet, so you might consider opening a new bug in the Rhythmbox bug tracker. –  ændrük Sep 4 '10 at 19:30
1  
thank you! now that i know it is broken, i'll poke around a bit more and file a bug report. –  TJ Ellis Sep 5 '10 at 11:43
    
Note that at least as of Ubuntu Trusty tahr 14.04, rhythmbox embeds python 3.4.0. So the command 'print "hello world"' is a syntax error ;) Instead, use the new Python 3 print function: 'print("hello world")' –  nealmcb Jun 6 at 20:16

As with any Python object, you can find out a lot about it by using the dir() method on it. This will give you a good place to start.

You can access the main window through the 'shell' variable :
<rb.Shell object at 0x9e9675c (RBShell at 0x987b018)>
>>> dir(rb.Shell)
['__class__', '__cmp__', '__copy__', '__deepcopy__', '__delattr__', '__dict__',
'__doc__', '__format__', '__gdoc__', '__getattribute__', '__gobject_init__', 
'__grefcount__', '__gtype__', '__hash__', '__init__', '__module__', '__new__', 
'__reduce__', '__reduce_ex__', '__repr__', '__setattr__', '__sizeof__', '__str__',
'__subclasshook__', 'add_to_queue', 'add_uri', 'add_widget', 'append_source',
'chain', 'connect', 'connect_after', 'connect_object', 'connect_object_after',
'disconnect', 'disconnect_by_func', 'do_notify', 'emit', 'emit_stop_by_name',
'freeze_notify', 'get_data', 'get_party_mode', 'get_player',
'get_playlist_manager', 'get_properties', 'get_property',
'get_source_by_entry_type', 'get_ui_manager', 'guess_source_for_uri', 
'handler_block', 'handler_block_by_func', 'handler_disconnect',
'handler_is_connected','handler_unblock', 'handler_unblock_by_func', 'load_uri',
'notebook_set_page', 'notify', 'notify_custom', 'present', 'props',
'register_entry_type_for_source', 'remove_from_queue', 'remove_widget',
'set_data', 'set_properties', 'set_property', 'stop_emission', 'thaw_notify',
'toggle_visibility', 'weak_ref']

You can then dir() any of the interesting-looking properties, like 'get_player', perhaps.

Another good place to look is if you see a __doc__ attribute on the object.

>>> print rb.Shell.__doc__
Object RBShell

Signals from RBShell:
  visibility-changed (gboolean)
  visibility-changing (gboolean, gboolean) -> gboolean
  create-song-info (RBSongInfo, gboolean)
  removable-media-scan-finished ()
  notify-playing-entry (gboolean)
  notify-custom (guint, gchararray, gchararray, GdkPixbuf, gboolean)

Properties from RBShell:
  no-registration -> gboolean: no-registration
    Whether or not to register
  no-update -> gboolean: no-update
    Whether or not to update the library
  dry-run -> gboolean: dry-run
    Whether or not this is a dry run
  rhythmdb-file -> gchararray: rhythmdb-file
    The RhythmDB file to use
  playlists-file -> gchararray: playlists-file
    The playlists file to use
  selected-source -> RBSource: selected-source
    Source which is currently selected
  db -> RhythmDB: RhythmDB
    RhythmDB object
  ui-manager -> GtkUIManager: GtkUIManager
    GtkUIManager object
  clipboard -> RBShellClipboard: RBShellClipboard
    RBShellClipboard object
  playlist-manager -> RBPlaylistManager: RBPlaylistManager
    RBPlaylistManager object
  removable-media-manager -> RBRemovableMediaManager: RBRemovableMediaManager
    RBRemovableMediaManager object
  shell-player -> RBShellPlayer: RBShellPlayer
    RBShellPlayer object
  window -> GtkWindow: GtkWindow
    GtkWindow object
  prefs -> RBShellPreferences: RBShellPreferences
    RBShellPreferences object
  queue-source -> RBPlayQueueSource: queue-source
    Queue source
  library-source -> RBLibrarySource: library-source
    Library source
  sourcelist-model -> RBSourceListModel: sourcelist-model
    RBSourcelistModel
  sourcelist -> RBSourceList: sourcelist
    RBSourcelist
  source-header -> RBSourceHeader: source header widget
    RBSourceHeader
  visibility -> gboolean: visibility
    Current window visibility

Signals from GObject:
  notify (GParam)
share|improve this answer
    
that's handy, if i can get the gorram console to work at all! as it is, if i type, for example, dir(rb.Shell) and hit enter, it just adds a line break and does nothing... Did your shell work OOB? I have the default rhythmbox installation on Ubuntu 10.04.... I can't think of anything that I've changed that would break the shell. My regular python console (outside of rb) works just fine... –  TJ Ellis Sep 4 '10 at 19:32
    
Hm, yeah, my shell works fine with no modifications. –  brousch Sep 30 '10 at 19:24
up vote 1 down vote accepted

Holy crap, I just found out what the problem was (2.5 years later)—for some reason my "enter" key maps to two different key events depending on whether numlock is on or off. When numlock is on, it returns KP_ENTER, and when numlock is off, it returns Return. I always have numlock on, because I prefer entering numbers with the keypad.

Unfortunately, the python console in Rhythmbox only recognizes Return to run a command—the KP_ENTER event just enters a line break...

But easy fix, just turn off numlock when using the console. I've ran into this problem in a few other applications (usually games), so I'm going to look into a better long-term solution (maybe forcing both to map to Return somehow)...

share|improve this answer
    
In case someone else has this problem, I did find a long-term solution: xmodmap -pke > ~/.Xmodmap to create a custom layout, then at the end of that file add a line keysym KP_Enter = Return then run xmodmap ~/.Xmodmap to enable the new custom layout for this session. To make it autorun for the future, add the following to ~/.xinitrc: if [ -f $HOME/.Xmodmap ]; then /usr/bin/xmodmap $HOME/.Xmodmap fi –  TJ Ellis Jan 12 '13 at 15:27
    
curse comments and their lack of line breaks! the if statement added to .xinitrc needs to have line breaks after then and before fi. –  TJ Ellis Jan 12 '13 at 15:31
    
Why don't you use the return key instead of the numlock's enter key? –  Timo Jan 12 '13 at 15:39
    
I was using the main "Enter" key, not the one in the numpad; for some reason having numlock on/off made a difference for that one too. –  TJ Ellis Jan 20 '13 at 16:56

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.