Some of my scripts for daily use on a linux desktop

Wednesday, July 14, 2010

Bargraph widget

This is a big update of the bargraph widget I wrote some weeks ago.

The script can be downloaded on my deviantArt page : here

The settings are now made through a table bars_settings and I add some news effects.
The bars_settings contains as many bars as you want:

bars_settings={
{settings for bar 1 here},
{settings for bar 2 here},
{settings for bar 3 here},
...
}



In this script, 3 parameters are madatory : name, arg and max

In a conky, you write: ${cpu cpu1}

In the script, you will write
bars_settings={
{
name="cpu",
arg="cpu1",
max=100,
--(max is set to 100 because maximum value of $cpu is 100%)
}
}

This 3 parameters will draw a single bar with 10 blocks in the middle of the conky window :


Of course, you can place the bar with x and y parameters, the dot (x,y) is the red dot in this image :


Line caps can be changed with cap parameter, values can be :
b for line cap "butt" (the default value)
s for line Cap "square"
r for line Cap "round"


Code for the second bar in the above picture :
{
name="cpu",
arg="cpu1",
max=100,
cap="s",
x=150,
y=200,
},



Some transformation can be added :
angle is the angle of rotation of the bar (0 is a vertical bar)
skew_x to skew around x axis
skew_y to skew around y axis
{
name="cpu",
arg="cpu1",
max=100,
x=100,
y=220,
angle=90,
},
{
name="cpu",
arg="cpu1",
max=100,
x=150,
y=200,
skew_x=-10
},

{
name="cpu",
arg="cpu1",
max=100,
x=200,
y=200,
skew_y=15
},



The shape and number of blocks can be set with
blocks : number of blocks (default = 10)
width : width of a block (default = 20 pixels)
height : height of a block (default = 10 pixels)
space : space betwwen two blocks (default = 2 pixels)


As you can see, a block is filled or empty, except for the special case where blocks=1, the bar will have a single block and this block will be partially filled.
Also a numerical value can be passed to the script (instead of a conky variable), with name="" and arg=30, second table bellow :
{
name="cpu",
arg="cpu1",
max=100,
angle=90,
blocks=1,
height=200,
width=10,
space=10,
x=10,
y=300
},

{
name="",
arg=30,
max=100,
angle=90,
blocks=1,
height=200,
width=10,
space=10,
x=10,
y=320
},



Also a bar can be ... a circle (well I know this is not clever !) with the angle_bar parameter.
With angle_bar, the parameter width is not used :
{
name="",
arg="50",
max=100,
angle=90,
blocks=20,
height=10,
space=1,
angle_bar=45,
},


and a radius can be applied like this:
{
name="",
arg="50",
max=100,
angle=90,
blocks=20,
height=10,
space=1,
angle_bar=45,
radius=50,
x=20,
y=200,
},

The red dot is the (x,y) dot :

Of course, some transformation can also be used, like skew_x and skew_y
{
name="",
arg="50",
max=100,
angle=90,
blocks=10,
height=5,
space=5,
angle_bar=45,
radius=50,
x=20,
y=400,
skew_y=20,
skew_x=20,
},




Let put some colours !
In this script, colors are defined in tables with two elements, coulour and alpha (opacity) :
{colour,alpha}

As you've noticed, there is actually two colours, one for the background (when a block is OFF), and when a block is "ON", call it foreground.
The names of the parameters are bg_colour and fg_colour.
{
name="",
arg="50",
max=100,
angle=90,
bg_colour={0x3300FF,0.7},
fg_colour={0xFF0033,0.7},
x=200,y=200
},
{
name="",
arg="50",
max=100,
bg_colour={0x0033FF,0},
fg_colour={0x00FF00,0.7},
blocks=1,
height=100,
x=200,y=300
},

The verical block has no background because alpha is set to 0.

Theses colours are "flat" isn't it ? So I add colours to create "LED" effects, each blocks is now define with is colour and a second colour (if desired)
The names of the parameters are bg_led and fg_led.

Theses parameters have no effect unless they are used with the led_effect parameter. Possible values are :
r for rounded effect in the middle of the block
a for parallel effect
e for perpendicular effect
{
name="",
arg="50",
max=100,
bg_colour={0x00ff00,0},
fg_colour={0xFF0000,0},
led_effect="r",
bg_led={0x00ff00,1},
fg_led={0xFF0000,1},
x=200,y=200
},
{
name="",
arg="50",
max=100,
bg_colour={0x00ff00,0},
fg_colour={0xFF0000,0},
led_effect="e",
bg_led={0x00ff00,1},
fg_led={0xFF0000,1},
x=250,y=200
},
{
name="",
arg="50",
max=100,
bg_colour={0x00ff00,0},
fg_colour={0xFF0000,0},
led_effect="a",
bg_led={0x00ff00,1},
fg_led={0xFF0000,1},
x=300,y=200
},




I used same colors for fg and bg led and fg and bg colour but with differents alpha.
Here's the same with different colours and same alpha :
{
name="",
arg="50",
max=100,
bg_colour={0xffff00,1},
fg_colour={0xffff00,1},
led_effect="r",
bg_led={0xff0000,1},
fg_led={0x0000ff,1},
x=200,y=200
},
{
name="",
arg="50",
max=100,
bg_colour={0xffff00,1},
fg_colour={0xffff00,1},
led_effect="e",
bg_led={0x0000660,1},
fg_led={0x660066,1},
x=250,y=200
},
{
name="",
arg="50",
max=100,
bg_colour={0xffff00,1},
fg_colour={0xffff00,1},
led_effect="a",
bg_led ={0x0000ff,1},
fg_led ={0xff0000,1},
x=300,y=200
},>



A third colour : with a threshold alarm, the color of a block can change if value is over threshold.
Colour can be defined with alarm_colour
{
name="",
arg="80",
max=100,
alarm=70,
bg_colour={0x00ff00,0.5},
fg_colour={0x00ff00,1},
alarm_colour={0xff0000,1},
x=200,y=200,
blocks=10,
cap="r",
angle=90,
},


Led effect can also be applied on alarm color with alarm_led.
In this example, led effect is applied only on the alarm values:
{
name="",
arg="80",
max=100,
alarm=70,
bg_colour={0x00ff00,0.5},
fg_colour={0x00ff00,1},
alarm_colour={0xff0000,0},
alarm_led={0xff0000,1},
led_effect="r",
x=200,y=200,
blocks=10,
cap="r",
angle=90,
},



Another interesting parameter is smooth.
This one create a gradient from bottom (with fg_colour) to top (with alarm_colour) of the bar.
Default value is false and when used, led_effect is inoperate
{
name="",
arg=20,
max=100,
alarm=80,
bg_colour={0x00ff00,0.25},
fg_colour={0x00ff00,1},
alarm_colour={0xff0000,1},
smooth=true,
led_effect="r",
x=200,y=200,
blocks=10,
cap="r",
angle=90,
},
{
name="",
arg=50,
max=100,
alarm=80,
bg_colour={0x00ff00,0.25},
fg_colour={0x00ff00,1},
alarm_colour={0xff0000,1},
smooth=true,
led_effect="r",
x=200,y=250,
blocks=10,
cap="r",
angle=90,
},
{
name="",
arg=95,
max=100,
alarm=80,
bg_colour={0x00ff00,0.25},
fg_colour={0x00ff00,1},
alarm_colour={0xff0000,1},
smooth=true,
led_effect="r",
x=200,y=300,
blocks=10,
cap="r",
angle=90,
},




But if you think that 2 colours are not enough for a gradient, you can add some colours with mid_colour.
mid_colour is a table containing one or more sub-table of three values.
Example:
mid_colour= {{0.5,0xFF0000,1}}
mid_colour= {{0.25,0xFF0000,1},
{0.75,0x00FF00,1}}

First line will add some red with opacity of 1 at 50 % in the gradient
Second line will add some red at 25% and some green at 75%.
{
name="",
arg=20,
max=100,
alarm=80,
bg_colour={0x00ff00,0.25},
fg_colour={0x00ff00,1},
alarm_colour={0xff0000,1},
mid_colour={{0.25,0xffff00,1},
{0.5,0x00ffff,1},
{0.75,0xffff00,1}
},
smooth=true,
x=20,y=200,
blocks=20,
height=20,width=20,
angle=90,
},
{
name="",
arg=50,
max=100,
alarm=80,
bg_colour={0x00ff00,0.25},
fg_colour={0x00ff00,1},
alarm_colour={0xff0000,1},
mid_colour={{0.25,0xffff00,1},
{0.5,0x00ffff,1},
{0.75,0xffff00,1}
},
smooth=true,
x=20,y=222,
blocks=20,
height=20,width=20,
angle=90,
},
{
name="",
arg=95,
max=100,
alarm=80,
bg_colour={0x00ff00,0.25},
fg_colour={0x00ff00,1},
alarm_colour={0xff0000,1},
mid_colour={{0.25,0xffff00,1},
{0.5,0x00ffff,1},
{0.75,0xffff00,1}
},
smooth=true,
x=20,y=244,
blocks=20,
height=20,width=20,
angle=90,
},
{
name="",
arg=77,
max=100,
alarm=80,
bg_colour={0x00ff00,0.25},
fg_colour={0x00ff00,1},
alarm_colour={0xff0000,1},
mid_colour={{0.25,0xffff00,1},
{0.5,0x00ffff,1},
{0.75,0xffff00,1}
},
smooth=true,
x=10,y=256,
blocks=1,
height=438,width=20,
angle=90,
},




Finally, reflection can be added with (only for bars) :
reflection_alpha set the alpha at the beginning of the reflection (ends with alpha=0)
reflection_length set the length of the reflection, a percentage of the original bar (values 0 to 1)
reflection_scale set the scale of the reflection, a percentage of the original bar (values 0 to 1)

{
name="",
arg=50,
max=100,
alarm=80,
bg_colour={0xff00ff,0.5},
fg_colour={0x00ff00,1},
alarm_colour={0xff0000,1},
mid_colour={{0.25,0xffff00,1},
{0.5,0x00ffff,1},
{0.75,0xffff00,1}
},
x=120,y=300,
blocks=10,
height=20,width=20,
reflection_alpha=0.5,
smooth=true,
},
{
name="",
arg=50,
max=100,
alarm=80,
bg_colour={0xff00ff,0.5},
fg_colour={0x00ff00,1},
alarm_colour={0xff0000,1},
mid_colour={{0.25,0xffff00,1},
{0.5,0x00ffff,1},
{0.75,0xffff00,1}
},
x=150,y=300,
blocks=10,
height=20,width=20,
reflection_alpha=0.5,
reflection_length=0.5,
smooth=true
},
{
name="",
arg=020,
max=100,
alarm=80,
bg_colour={0xff00ff,0.5},
fg_colour={0x00ff00,1},
alarm_colour={0xff0000,1},
mid_colour={{0.25,0xffff00,1},
{0.5,0x00ffff,1},
{0.75,0xffff00,1}
},
x=180,y=300,
blocks=10,
height=20,width=20,
reflection_alpha=0.5,
reflection_scale=0.5,
smooth=true
},





Last parameter is the position of the bar's reflection (reflection), it has four parameters b,t,l,r for bottom, top, left and right but theses parameters are always relative to a verical bar.
The next 2 bars have reflection="r" but the second has angle=90
{
name="",
arg=50,
max=100,
alarm=80,
bg_colour={0xff00ff,0.5},
fg_colour={0x00ff00,1},
alarm_colour={0xff0000,1},
x=150,y=300,
blocks=10,
height=20,width=20,
reflection_alpha=0.8,
smooth=true,
reflection="r",
},

{
name="",
arg=50,
max=100,
alarm=80,
bg_colour={0xff00ff,0.5},
fg_colour={0x00ff00,1},
alarm_colour={0xff0000,1},
x=220,y=300,
blocks=10,
height=20,width=20,
reflection_alpha=0.8,
smooth=true,
reflection="r",
angle=90
},



And now, some amazing setups :
{
name="",
arg=80,
max=100,
bg_colour={0x0000ff,0.5},
fg_colour={0x00ff00,1},
mid_colour={{0.25,0xFFFF00,1},{0.5,0xFFFFFF,1},{0.75,0xFF0000,1}},
x=25,y=300,
blocks=50,
space=1,
height=10,width=10,
angle=90,
smooth = true,
},




{
name="",
arg=80,
max=100,
bg_colour={0x0000ff,0.5},
fg_colour={0x00ff00,1},
mid_colour={{0.25,0xFFFF00,1},{0.5,0xFFFFFF,1},{0.75,0xFF0000,1}},
x=25,y=300,
blocks=50,
space=1,
height=10,width=0,
angle=90,
smooth = true,
cap="r",
},




{
name="",
arg=70,
max=100,
bg_colour={0xff00ff,0},
fg_colour={0x00ff00,0},
bg_led={0xff00ff,0.5},
fg_led={0x00ff00,1},
led_effect="r",
x=25,y=300,
blocks=10,
space=5,
height=50,width=40,
angle=90,
cap="r",
},


{
name="",
arg=70,
max=100,
bg_colour={0x00ffff,0},
fg_colour={0x00ffff,0},
bg_led={0xff0000,0.5},
fg_led={0xffff00,1},
led_effect="r",
x=50,y=300,
blocks=10,
space=1,
height=50,width=40,
angle=90,
cap="r",
},






{
name="",
arg=70,
max=100,
alarm=50,
bg_colour={0x00ff33,0},
fg_colour={0xffff00,0},
alarm_colour={0xFF0000,0},
bg_led={0x00ff33,0.5},
fg_led={0xffff00,1},
alarm_led={0xFF0000,1},
blocks=10,
space=1,
height=30,width=40,
angle=90,
cap="b",
angle_bar=45,
led_effect="a"
},





{
name="",
arg=70,
max=100,
alarm=50,
bg_colour={0x00ff33,0},
fg_colour={0xffff00,0},
alarm_colour={0xFF0000,0},
bg_led={0x00ff33,0.5},
fg_led={0xffff00,1},
alarm_led={0xFF0000,1},
blocks=10,
height=30,width=40,
angle=90-45/2,
cap="r",
angle_bar=45,
led_effect="a",
radius=30,
skew_y=25
}




{
name="",
arg=70,
max=100,
bg_colour={0x00ff33,0},
fg_colour={0xffff00,0},
bg_led={0x00ff33,0.5},
fg_led={0xffff00,1},
blocks=20,
y=300,
height=10,width=40,
angle=90,
led_effect="r",
reflection_alpha=1,
reflection="r"
},





{
name="",
arg=70,
max=100,
bg_colour={0x00ff33,0},
fg_colour={0xffff00,0},
bg_led={0x00ff33,0.5},
fg_led={0xffff00,1},
led_effect="r",
blocks=20,
y=300,
height=10,width=40,
angle=90,
led_effect="e",
reflection_alpha=1,
reflection="r",
space=0,
skew_x=15,
},






Enjoy ;-)

PS : a big setup with the text widget (too many effects in this one, I agree):