Archive for Python

Sublime Text 2 – rsync on save

// december 1st, 2011 // No Comments » // Development, plugin, Python

As I’m running an Ubuntu Server in a virtual machine as development test server and I develop on my local environment, I need to keep both repositories in sync.
Before, I shared the code on the development server to my local environment via NFS. The setup worked, but gave some complications with svn, and the auto mounting of the NFS-share after rebooting. So I started looking for a new way to keep all files in sync. I considered sharing via NFS the other way around, but that would make my test server very slow; all php files need to be loaded through NFS and all assets (images, css, javascript) too.
The easiest way to solve my problem was through the good old rsync. As I’m too lazy to run an rsync command every time before I want to load a page from my test-server, I wanted it to be done automatically when I saved a file.
As Sublime Text 2 is an awesome editor which supports plugins, I started surfing around looking for some examples which I then adapted for my own use..
This is the plugin I now use:

import sublime, sublime_plugin, subprocess

class RsyncOnSave(sublime_plugin.EventListener):
def on_post_save(self, view):

syncProject = “”"rsync -avz localpath remotepath &”"”
subprocess.call([syncProject],shell=True)

This code is put in a file named RsyncOnSave.py which is saved a folder named RsyncOnSave, in the Packages folder (for OSX thats: ~/Library/Application\ Support/Sublime\ Text\ 2/Packages/). The plugin should automatically be loaded when you (re-)start Sublime Text.
localpath and remotepath obviously are the paths in your case. Note the ampersand at the end of the sync command, which makes sure your editor doesn’t freeze while the command is being executed.

Make sure you’ve put your public ssh-key in the authorized_keys on your server, so you don’t have to give your password when rsyncing.

Vrt Internetradio Boxee plugin

// april 12th, 2010 // 3 Comments » // Boxee, Development, klara, mnm, Python, radio 1, radio 2, radio vlaanderen, stubru, vrt

So, I finally finished my second Boxee plugin. This time I can call it a real plugin, there are options, lists and dialogs. Hooray!

The plugin is called “Vrt Internetradio”, and it basicly plays internet streams from the VRT (Vlaamse Radio- en Televisieomroeporganisatie).
The VRT  owns several radio stations and they provide streams to listen to them via the internet. I took the opportunity to use those to make a Boxee plugin so we all can play them with our beloved Boxee.

There’s not that much functionality, but I tried to keep the layout simple and tried to give a good user experience (up/down buttons to right controls and such).

Screenshots (click for larger picture) and download link are below , don’t hesitate to comment ¬†and help me improve the plugin.

The main screen:
The main screen

Info about a particular station and substations to play:
Info about a particular station and substations to play

Starting a radiostation:
Starting a radiostation

The options dialog:
The options dialog

The about dialog:
The about dialog

Download here

Boxee python dev

// april 10th, 2010 // 3 Comments » // Boxee, Cuvedev, Python

Boxee may be “the best way to enjoy entertainment from the Internet and computer on your TV” (according tor their website), the developers documentation isn’t all that great. Not everything is well-documented and the (python) API doesn’t always do what’s expected, which makes developing own plugins not that easy.
It isn’t also always possible to find the right solution with Google. Maybe because not all that much people are developing plugins for Boxee (or the don’t care to share) or because Google doesn’t index it well.

So I decided to share the things I found. Let’s hope google indexes them well and I’m able to help some fellow developers.

Textbox + SetLabel:
If you have a textbox, it is not possible to change the label via python in an easy way.

mc.GetActiveWindow().GetLabel([id]).SetLabel('text')

and

mc.GetActiveWindow().GetControl([id]).SetLabel('text')

don’t work on a Textbox, and

GetTextbox([id])

doesn’t exist.
Setting the label can be done this way:

xbmc.executebuiltin('Control.SetLabel([id],[text])')

and you’ll have to replace every comma (,) with $COMMA

Onload-tag with a dialog
I’ve experienced some troubles with the onload-tag in windows with type=”dialog”. If you have a normal window, and load a dialog-window in a onclick method with this code, the onload of the dialog won’t work until you close the dialog:

 
<![CDATA[ mc.ActivateWindow(14001) ]]>

The way to solve this is to dump the python code to load the dialog and just do this:

	ActivateWindow(14001)

Python import gives errors:

It took me a while to figure out, but this error:

18:54:51 T:2963869696 M:410439680  NOTICE: --&gt;Python Interpreter Initialized&lt;--
18:54:51 T:2963869696 M:410439680  NOTICE: Traceback (most recent call last):
18:54:51 T:2963869696 M:410439680  NOTICE:   File "", line 2, in ?
18:54:51 T:2963869696 M:410439680  NOTICE: ImportError
18:54:51 T:2963869696 M:410439680  NOTICE: :
18:54:51 T:2963869696 M:410439680  NOTICE: No module named xxxxxxx
18:54:51 T:2963869696 M:410439680   ERROR: Scriptresult: Error

Was caused by a bad window-id. Boxee window-id’s should be between 14000 and 14099

Close a window with type=”dialog”:
If you have opened a window with type=”dialog”, it isn’t possible to close the window with this code:

CloseWindow(14001)

Instead you have to do this:

Dialog.Close(14001)

You can also add the “force” option (True/False), adding this option will skip all animations.