Monday, November 24th, 2008 | Author: eagle

The new Amarok scripting interface only supports Qt script. But with the help of Qt Bindings, you can ultimate the scripting usage. Here’s a simple example of using .ui files in a script.

From My ScreenShot

A clip from my encoding fixer script, you can grab the full version from amarok/playground/src/script/encoding_fixer/:

Importer.loadQtBinding( “qt.core” );
Importer.loadQtBinding( “qt.gui” );
Importer.loadQtBinding( “qt.uitools” ); //load the qt binding

function readConfiguration()
{
if ( Amarok.Script.readConfig( “simple_Chinese”, “false” ) == “false” )
mainWindow.children()[1].children()[1].checked = false; //uncheck the checkbox
else
mainWindow.children()[1].children()[1].checked = true; //check the checkbox
}

function onConfigure()
{
mainWindow.show();
}

var UIloader = new QUiLoader( this );
var uifile = new QFile ( Amarok.Info.scriptPath() + “/main.ui” );
uifile.open( QIODevice.ReadOnly );
mainWindow = UIloader.load( uifile, this); //load the ui file
uifile.close();

readConfiguration();
mainWindow.children()[0].accepted.connect( saveConfiguration ); //when OK button is clicked
mainWindow.children()[0].rejected.connect( readConfiguration ); //call the function when Cancel button is clicked

Amarok.Window.addSettingsMenu( “configencoding”, “Encoding Fixer Settings…” ); //add the configuration menu
Amarok.Window.SettingsMenu.configencoding.triggered.connect( onConfigure ); //add a signal

Heads up! Amarok 2.0 is about to release. :)
I will be really happy to see more scripts ready on kde-apps.org. And I am impressed that there are 10+ scripts out there already even before the release of our RC version.

Category: Uncategorized
You can follow any responses to this entry through the RSS 2.0 feed. You can skip to the end and leave a response. Pinging is currently not allowed.

7 Responses

  1. uitools is pretty cumbersome to use as you can see there. Someone should write a uic for QtScript.

  2. 2
    Mark Kretschmann 
    Monday, 24. November 2008

    Great informative blog, Peter. Thanks :)

    PS: You did a fantastic job with the scripting system, but I told you that already.

  3. 3
    Richard Moore 
    Monday, 24. November 2008

    @Ian if you use my wrapper API for it then it’s a one liner - I’d suggest you should include that binding not rely on the generated one for loading ui files.

  4. Well, I was trying to make a new version of my Amalyp script for Amarok 2. But I noticed that the function to get the current position in the song in milliseconds is again missing (or not documented). So I’m stuck there.

  5. @Tim De Graeve: Please use Amarok.Engine.trackPosition()

  6. found your post really informative.

    can you talk me through how you are referencing objects from the .ui file in your script?

    for example is it possible to select objects by name rather than using .children() and the number?

    cheers :)

  7. @chris:
    the uitools is pretty cumbersome as Ian mentioned.

Leave a Reply