Thursday, August 12, 2010

Vim buffer execution

Currently toying around with Vim's scripting language. Have to know your favorite editor, don't you?

Anyway, the script I just completed is saving and sourcing the current buffer. Should prove useful for further Vim script development cycles.

The actual function looks like this:

Tuesday, April 27, 2010

QT Widget StyleSheet image and QT Designer

QT (4.6) comes with a nice GUI designer. So now I created a nice GUI front-end for one of my applications. One of the widgets I added was a simple QWidget with the style set to have a background image loaded from a file. I added this with the GUI tools and the preview looked great, but when I compiled the application, the friggin' thing just did not show up.

After a lot of searching the Intertubes and cussing (as community troubleshooting and bug tracking for QT are abysmal) I took a closer look at what the designer fabricated there:

background-image: url(:/logo.png);

With some figuring the truth in the failure of the designer came to me: it forgot the quotes, making this an invalid css, for which it does not seem to care in the GUI preview, but breaks in the actual application (quietly I might add, not even an error message, the image just isn't there).

The correct CSS is:

background-image: url(":/logo.png");

This raises the question: does anyone test at least the basic functionality of these tools? Crap..

Sunday, September 13, 2009

How to play sound files recursively with mplayer in cli?

Ever wondered how to play your entire music archive with mplayer, preferably shuffled?

I finally got around and played a bit with the command line, and the result is:

find ~/Music \( -iname "*\.mp3" -o -iname "*.ogg" -o -iname "*.wma" \) -exec mplayer -shuffle '{}' +

This will do the magic, and play all your mp3's, ogg's and wma's shuffled in the ~/Music folder (change path to where your music folder is).

Tuesday, September 8, 2009

Manpage like formatter function

Was playing around with the CMD std module, and what bugged me was the non existent help function formatting.. so I wrote one for myself:

Thursday, July 16, 2009

mplayer notes

Mplayer is my favourite media player as it plays nearly every kind of media file and is the most powerful media player I know in terms of functionality (like filters) and flexibility. I also like the UI (command line and a simple window, no stupid controls, everything goes by the keyboard, I hate the GUI's for it). It just happens to have one of the longest manual pages I ever saw too, and it takes some time to find something in there. That's why I'm writing up the options that I happen to find useful, kind of like a filter for the manpage.

Setting aspect radio:
  • -aspect 16:9
  • -aspect 2.3
Setting deinterlancer:
  • -vf pp=lb
Rebuild index for partial videos:
  • -idx
  • -forceidx
Replay media in loops:
  • -loop
  • -loop 0 ## endless loop
  • -loop 5 ## repeat 5 times
Shuffle media:
  • -shuffle
Seek and cut specified position:
  • -ss 10 ## skip the first 10 seconds
  • -ss 1:30:00 ## seek to stream position 1:30:00
  • -endpos 50 ## stop after 50 seconds of playback
  • -endpos 1:40:00 ## stop at stream position 1:40:00
Play sound only (don't play video):
  • -vo null
Here is an example of how to extract only the sound track of a video file from position 0:24 to 1:54:
  • mplayer -vo null -ss 0:24 -endpos 1:32 [input-filename] -ao pcm:file=[out-filename]

Monday, July 13, 2009

Tkinter tidbit: login prompt

I wrote a tkinter login promt that looks like this:

It creates the window, adds the labels, entries and button, connects them with focus / confirm commands and then centres the screen. When the credentials are submitted, it calls the login method.

The source for it is:

Sunday, July 12, 2009

Python tkinter tidbit: centred window

This little application simply creates a window and centres it on the screen (gist):

1 #! /usr/bin/env python3
3 from tkinter import *
4 from tkinter.ttk import *
6 def centred_win(root, width=400, height=300):
7 screen_width = root.winfo_screenwidth()
8 screen_height = root.winfo_screenheight()
9 x = (screen_width/2) - (width/2)
10 y = (screen_height/2) - (height/2)
11 root.geometry('%dx%d+%d+%d' % (width, height, x, y))
13 root = Tk()
14 centred_win(root, 500, 300)
15 root.mainloop()