Help with script: Adding Columns to main panel

So I’ve figured out how to add colums to the main panel (thanks to the add_album_column script that is in the repo. And my initial goal was to add columns that displayed the album date, the track disc # and disc subtitle. Mission accomplished, or at least partially. The columns show up and work at the track level, but i need date to work at the album level so that albums are sortable by date…

The code is below:

PLUGIN_NAME = u"Add ExtraColumn"
PLUGIN_AUTHOR = u"Lawrence Winston"
PLUGIN_DESCRIPTION = "Add a few extra columns to the main window panel."

PLUGIN_VERSION = "1.0"
PLUGIN_API_VERSIONS = ["1.4.0"]
PLUGIN_LICENSE = "GPLv3"
PLUGIN_LICENSE_URL = "http://www.gnu.org/licenses/"

from picard.ui.itemviews import MainPanel
MainPanel.columns.append((N_('Date'), 'date'))
MainPanel.columns.append((N_('Disc #'), 'discnumber'))
MainPanel.columns.append((N_('Disc Title'), 'discsubtitle'))

furthermore I’d like these colums only to be added to the scanned album tree view if that is at all possible

1 Like

Why is there no docuentation on what you can access and how to do things via scripting? Even digging through the code itself doesn’t help me figure out how to do this and apparently anyone who does know how to get things done could care less about helping me… DOCUMENTATION PLEASE???, because the “example scripts” are as good as a “Hello World” script it shows you how to do only the simplest of things. I mean I create the columns in the main panel but apparently they don’t get filled at the ALBUM level and noone can (or will) tell me why.

I have no answers for you, but thanks for bringing this feature to my attention.

First I agree we should have better plugin coding documentation somewhere.

But having said this the only really proper plugins API functions are the register_* functions described at the Plugins API documentation. But due to the nature of how Picard handles plugins and how Python behaves in general, plugins can basically access and modify all of Picard’s internals.

That’s basically what your plugin is doing: It’s accessing Picard’s internals directly to add some column. The reason you did not get an answer yet is probably nobody really knows it without digging into the code themselves (also I actually did not see your original post). Also note how this plugin will not behave as expected: It does not matter whether it gets enabled or not, it will always add those columns because the plugin code gets executed on loading time, not on plugin activation.

There have been talks about replacing the current plugin system with a new one to address some of the shortcomings, but nothing concrete yet.

To give some answer to your question: You code works for tracks and files, because those have implemented the column function to return the actual metadata of the same name as the column name, see e.g. track.py#L138. But Album.column does not do this.

To fix this you would have to monkey patch Album.column with something like this:

from picard.album import Album

orig_album_column = Album.column

def album_column(self, column):
    val = orig_album_column(self, column)
    if not val:
        val = self.metadata[column]
    return val

Album.column = album_column

Again be aware that this is messing around with Picard internals. There is no guarantee this will work after a Picard update. In the worst case it could break something.

3 Likes