Some of my scripts for daily use on a linux desktop

Showing posts with label imlib. Show all posts
Showing posts with label imlib. Show all posts

Tuesday, April 27, 2010

Radio Box Widget

I like to listen to radio when I am working on my computer. Usually, I listen to FIP radio, the track information played by this radio are very cools and smooths (example for one day : here) but of course I don't use their ugly player or their information popup ...

Guess what, I want to display the tracks I'm listening on my desktop in a conky ;-)
But as there are more radios than "FIP radio" and because the script was not difficult to write, the conky came more "universal" (sorry, a big word for a little thing).
You need conky 1.8.0 because the script use cairo_text_extents_t structure for text alignment.

The script can be downloaded from ubuntu forums : here.




First, I said I don't want a ugly player, so I use vlc with the http interface, like this :

vlc --intf=http http://www.tv-radio.com/station/fip_mp3/fip_mp3-128k.m3u

there are others interfaces or others methods to hide a player but I like vlc!

I can control volume with my keyboard or with my browser at this address :
http://localhost:8080/





The conky itself doesn't get the track information. This is done by a bash script, (I made one for FIP here but for others radios, you have to work a little bit ...) which write the information in a text file.
So, the conky needs only this text file in input with at least one of the lines bellow (order doesn't matter):

radio:__FIP radio__
artist:Sonny Rollins
title:Come, Gone
album:Way out West
label:Contemporary
year:1957
cover:/tmp/radio-cover

I will call this file : /tmp/radio.txt

In the conkyrc, as usual, call the Lua script :

lua_load ~/scripts/radio-box.lua
lua_draw_hook_post main_radio_box /tmp/radio.txt
TEXT
${execi 15 ~/scripts/generate-track-information.sh}

You can see that the main_radio_box function needs one parameter : the track information file generated by the generate-track-information.sh.
In fact, the function can have 17 parameters but only the first one is mandatory.

If you run the script with only the first parameter, you get that :

useless, isn't it ?



Now, let's add some parameters on the main function :
The x, y coordinates of the top-left corner, to move the box :
lua_draw_hook_post main_radio_box /tmp/radio.txt 100 25



The font and the font size, to change the display :
lua_draw_hook_post main_radio_box /tmp/radio.txt 10 10 Purisa 15



The informations to display, in the form ATBLYR where :
A=Artist
T=Track
B=Album
L=Label
Y=Year
R=Radio

Example :
lua_draw_hook_post main_radio_box /tmp/radio.txt 10 10 Japan 15 RATBLY


Here you can see that the box auto-fit the text, both in height and width.

The cover.
If your script get the cover, you can display it, just set the path in the file /tmp/radio.txt. To display, the cover use 1, other caracter to not display.
lua_draw_hook_post main_radio_box /tmp/radio.txt 10 10 Japan 15 RATBLY 1


If there is less text to dispaly, the cover will resize to the height of the text frame, like this
lua_draw_hook_post main_radio_box /tmp/radio.txt 10 10 Japan 15 ATB 1



The border size :
(In a reel conky, you should write all the parameters on one single line)
lua_draw_hook_post main_radio_box /tmp/radio.txt 10 10 Japan 15 ATBY
1 7



The radius of the corners:
lua_draw_hook_post main_radio_box /tmp/radio.txt 10 10 Japan 15 ATBY
1 3 15


lua_draw_hook_post main_radio_box /tmp/radio.txt 10 10 Japan 15 ATB
1 0 0

Bye, Sonny...


The gap between the two frames:
lua_draw_hook_post main_radio_box /tmp/radio.txt 10 10 Japan 15 ATB
1 3 3 60



The light effect source, possibles values are :
nw : Nord-West (default)
nn : North-North
ne : North-East
ee : East-East
se : South-East
ss : South-South
sw : South-West
ww : West-West

Example for North-North :
lua_draw_hook_post main_radio_box /tmp/radio.txt 10 10 Japan 15 ATB
1 3 3 10 nn



The colors of the frame (it's a linear gradient but if the two values are the same, there is no more gradient):
lua_draw_hook_post main_radio_box /tmp/radio.txt 10 10 Japan 15 ATB
1 3 3 10 ee
FF0000 FFFF00 1 1



The colors of the text :
lua_draw_hook_post main_radio_box /tmp/radio.txt 10 10 Japan 15
ATB 1 3 3 10 ee
F00F00 FCFFC0 1 1 00FF00 00FFFF 1 1



The colors of the border (the same of the main frame if they are not defined, but inversed)
lua_draw_hook_post main_radio_box /tmp/radio.txt 10 10 Japan 15 ATB
1 5 5 10 sw
CCCCCC 000000 1 1 FFFF00 FFFFFF 1 1 000000 DDDDDD 1 1



More classical :
lua_draw_hook_post main_radio_box /tmp/radio.txt 10 10 Japan 15 ATB
1 2 0 10 ww
CCCCCC CCCCCC 1 1 000000 000000 1 1 000000 000000 1 1




While writing this note I add parameters for transparancy:
lua_draw_hook_post main_radio_box /tmp/radio.txt 10 10 Japan 15 ATBLY
1 5 5 10 nw
000000 FFFFFF 0.3 0.3 FF0000 FF0000 0.5 0.5 000000 000000 1 0.2



I think I will add some effects on the cover if I can in the future.

Wednesday, April 7, 2010

Square to Rounded image with Lua/imlib


I wanted to display Moon and Earth pictures on my conky but the only images I found where squares images with a black background and the Moon or the Earth in the middle.
So to display the image correctly in the conky, I had to set transparency of the background of the original image. Well, I've done that with imlib and post the resulting script here (or in french here).

I also post the script to get Earth or Moon images from this site :
http://www.fourmilab.ch/earthview/expert.html

Of course the images are updated every hour so the night area is reflecting the reality !
And of course again, there are a few parameters to set the latitude, longitude and so on ...

If you are inspired, you can have some amazing conkys like this one :


or that:



I also updated the clock and the calendar wheel (this one is now a widget and it is more easy to use it).
And I discover that the widgets can be called with the dofile() function in the Lua script. No more need to copy/paste the widget but to use a line like this :
dofile("/home/wlourf/calendar/calendar.lua")

Tuesday, January 19, 2010

Calendar wheel


Well, as I explore the conky a little bit deeper, I am very amazing of things we can draw with some lines of codes.
Last week I tried the Conky Contest of the Month with this "Calendar Wheel". We were only two guys to participate (too bad) but you can vote for my calendar if you like the conky I will now explain !! Edit: I won coool !

This script simply draw a circular calendar on the left side of the screen (I didn't try on the right side as text alignment is not easy with cairo).

The most difficult part of this script was to rotate the dates because cairo doesn't allow that: the trick was to draw each date on a separate image, rotate the image and then render the rotated image on the screen.
Customization can be done with colors, height and width and some text can be added (depending on the date) on the left side of the arc.

This is what I've done for the contest (and for learning myself Lua) !

After that, I added some improvements in version 1.1 :
- today's date can now be set anywere in the arc (not on only the horizontal line) : yoffset
- today's date can now have an offset (positive or negative) : xoffset
- the main thing is that the calendar is draw only at the start of the conky and when the date change (i.e. the calendar is saved in a PNG file and this is this file that will be displayed in the conky) or if the PNG file is deleted : so the conky become really really fast ...

And in version 1.2, the calendar can be drawn on the right side of the conky.

The script can be downloaded from ubuntu forums here.

Edit : how to set date in local language:
Here is what I've done for having dates according to my locale settings:
It your conkyrc, in the TEXT section, write
${time}
If you want to hide this date ,
use_xft yes
xftalpha 0
default_color 000000

It seems it works only for the black color .
I didn' manage to do that in Lua only

Happy Conkying !


More screenshots :




There is also a gallery on picasa

Sunday, January 3, 2010

Photo Album Stack


Hi,

This is my first attempt to use lua bindings in conky (> 1.7.2).
This script is based on londonali's Photo Album Script but it can display than more one image at a time and in a more messy way (if configured to).

In the conkyrc, don't forget the blank line after TEXT
To start with an empty photo album, delete the file created by the script :

rm /tmp/img.png & conky -c ~/scripts/conkyrc-album-stack &

Some improvments made in version 1.1 :
- little images are no more enlarged
- the filename of the image can be written in the frame or/and elsewhere in the conky.
- gray shadow on the bottom right side of each image can be added
(this is optional but has to be improved : the shadow has to be "blur" and shadows don't work for big pictures)
It can be used with the script get_deviation.sh (see this post) or any other script that get a random image from the web.


The scripts can be downloaded from ubuntu forums.

Another screenshot :



En français, soyons fous! Ce script affiche des images de son disque dur sur votre conky dans une façon un peu bordélique. Les dernières modifications sont :
- les petites images ne sont plus agrandies
- le nom de l'image peut être affiché dans le cadre ou n'importe où dans la fenêtre du conky
- une sorte d'ombre peut être ajoutée mais ceci devra être amélioré (il n'y a pas d'effet de flou et ça ne fonctionne pas bien pour les grandes images)
- le script peut être utilisé avec un autre script qui génère des images aléatoires comme get_deviation.sh que j'ai posté il y a quelques jours


Happy conkying!