issue47:command_conquor_pp._5-8
Différences
Ci-dessous, les différences entre deux révisions de la page.
Prochaine révision | Révision précédente | ||
issue47:command_conquor_pp._5-8 [2011/05/04 13:54] – créée auntiee | issue47:command_conquor_pp._5-8 [2011/05/09 14:23] (Version actuelle) – auntiee | ||
---|---|---|---|
Ligne 1: | Ligne 1: | ||
- | I realize that last month I said I was going to do an article on Zenity within a script. However, I couldn' | + | **I realize that last month I said I was going to do an article on Zenity within a script. However, I couldn' |
- | For those of you who aren't sure what I'm talking about, this screenshot on my DeviantArt profile is an example of what is possible with Conky: http:// | + | For those of you who aren't sure what I'm talking about, this screenshot on my DeviantArt profile is an example of what is possible with Conky: http:// |
- | First and foremost, make sure you have installed | + | Je me rends compte que le mois dernier j'ai dit que j' |
- | As for the widgets we'll be creating, I'm going for a simple MPD music widget, and a clock (the same widgets visible in the above screenshot). Also, since I felt no need to re-create the wheel (or, in this case, the ring), I will be using the following script as a basis for what we are doing now: http://londonali1010.deviantart.com/ | + | Pour ceux d'entre vous qui ne savent pas de quoi je parle, cette capture d'écran de mon profil DeviantArt est un exemple de ce qu'on peut faire avec Conky : http://lswest.deviantart.com/ |
- | Pre-coding | + | **First and foremost, make sure you have installed Conky (1.7.2 is in the repositories as of version 9.10 Karmic Koala). I will assume that everyone is using version 9.10 or higher. If you're using an older version, launchpad will probably have a PPA for you. |
- | Before we get started on the actual script, I ask you to decide if you want it in two separate Conky instances (my choice) or within | + | As for the widgets we'll be creating, I'm going for a simple MPD music widget, and a clock (the same widgets |
- | Also, to use the lua scripts, you must add in the following to your .conkyrc: | + | Tout d' |
+ | |||
+ | Concernant les widgets que nous allons créer, je vais faire un widget simple pour le lecteur de musique MPD et une horloge (les mêmes widgets visibles dans la capture d' | ||
+ | |||
+ | **Pre-coding | ||
+ | |||
+ | Before we get started on the actual script, I ask you to decide if you want it in two separate Conky instances (my choice) or within a single instance. The reason why I use two is quite simply because I have two other Conky instances on my desktop, and merging the widgets into one would have resulted in overlaps between Conky instances. If you wish to use only one, you will need to increase the minimum size, and adjust the x and y values for each widget to place them within the Conky window. The x and y relate to the relative position of Conky. For example, if Conky starts at (400,200) < | ||
+ | |||
+ | Pré-codage | ||
+ | |||
+ | Avant de commencer sur le script lui-même, je vous demande de décider si vous le voulez dans deux instances distinctes de Conky (mon choix) ou dans une instance unique. La raison pour laquelle j'en utilise deux est tout simplement parce que j'ai deux autres instances de Conky sur mon bureau et fusionner les widgets en un seul aurait donné lieu à des chevauchements entre les instances Conky. Si vous souhaitez en utiliser une seule, vous devrez augmenter la taille minimale et ajuster les valeurs x et y pour chaque widget afin de les placer dans la fenêtre de Conky. x et y se rapportent à la position relative de Conky. Par exemple, si Conky commence à la position (400, 200) < | ||
+ | |||
+ | **Also, to use the lua scripts, you must add in the following to your .conkyrc: | ||
lua_load / | lua_load / | ||
Ligne 17: | Ligne 29: | ||
lua_draw_hook_pre ring_stats | lua_draw_hook_pre ring_stats | ||
- | ...where the top line is, of course, the actual absolute path to the lua script, and the name below is the name of your main function (if you write conky_ring_stats, | + | ...where the top line is, of course, the actual absolute path to the lua script, and the name below is the name of your main function (if you write conky_ring_stats, |
+ | |||
+ | En outre, pour utiliser les scripts LUA, vous devez ajouter ce qui suit à votre .conkyrc : | ||
+ | |||
+ | lua_load / | ||
+ | |||
+ | lua_draw_hook_pre ring_stats | ||
+ | |||
+ | ... où la première ligne est, bien sûr, le chemin d' | ||
+ | |||
+ | **The script has comments to clarify the entries, but I'll quickly explain each as well. The name is actually the name of the Conky variable (i.e. ${time }), the args are the arguments (i.e. ${time %I}), and it is parsed by the script in lines 121-131 (on pastebin), within the local function setup_ring. It basically sends the command (after formatting it into ${name args}) to Conky, gets the result, and parses it. Then it's casted into a number, and the deviations (entered into the max variable) of the ring are calculated (so, if you say 360 divisions, then each division is exactly 1° of the ring, or if you have 12, then it's 2*pi/max (in radians)). It's not important if you don't understand this, just keep in mind that to have 12 hours within the ring, you must make 12 divisions. The 4 following variables are simply background and foreground colors, and their alpha (transparency) levels. The x and y variables make up your position vector, radius is the width of the ring, thickness is the size of the line, start_angle is where the circle starts (0°), and end_angle is where it stops (360°), so that we get a complete circle.** | ||
- | The script | + | Le script |
- | For those of you who know the formatting for the date command, you'll know that %I is the format for the hours with leading 0s (so 01...12). The format for a 12-hour clock, without leading 0s, is %l, but it doesn' | + | **For those of you who know the formatting for the date command, you'll know that %I is the format for the hours with leading 0s (so 01...12). The format for a 12-hour clock, without leading 0s, is %l, but it doesn' |
As you can see, it's fairly straightforward. If you're fine with the seconds ring counting off the seconds, and without the date in the center, you're finished. If you, like me, want the seconds to fill the innermost circle, then you'll need to add the following line before “cairo_arc(cr, | As you can see, it's fairly straightforward. If you're fine with the seconds ring counting off the seconds, and without the date in the center, you're finished. If you, like me, want the seconds to fill the innermost circle, then you'll need to add the following line before “cairo_arc(cr, | ||
- | if pt[' | + | if pt[' |
- | What this does is simply start at the angle_0 (12 o' | + | Pour ceux d' |
+ | |||
+ | Comme vous pouvez le voir, c'est assez simple. Si vous réussissez à faire compter les secondes au centre et sans la date au centre, vous avez terminé. Si vous voulez, comme moi, que les secondes soient sur le cercle intérieur, alors vous devrez ajouter la ligne suivante avant « cairo_arc(cr, | ||
+ | |||
+ | if pt[' | ||
+ | |||
+ | **What this does is simply start at the angle_0 (12 o' | ||
${goto 115}${voffset 150}${time %A} | ${goto 115}${voffset 150}${time %A} | ||
Ligne 33: | Ligne 61: | ||
${goto 115}${time %b %d %Y} | ${goto 115}${time %b %d %Y} | ||
- | The goto line shifts it over to the right (you can also use ${offset < | + | The goto line shifts it over to the right (you can also use ${offset < |
- | MPD Widget | + | Nous commençons simplement à l' |
+ | |||
+ | ${goto 115}${voffset 150}${time %A} | ||
+ | |||
+ | ${goto 115}${time %b %d %Y} | ||
+ | |||
+ | La ligne goto le déplace vers la droite (vous pouvez aussi utiliser ${offset < | ||
+ | |||
+ | **MPD Widget | ||
Now before we start this, the widget I describe here works only for MPD (Music Player Daemon), since Conky lacks variables for other music players. I'm sure you could get it working the same with some tricky coding, but I don't think it's worth it as most other music players have a “now-playing” widget of sorts. | Now before we start this, the widget I describe here works only for MPD (Music Player Daemon), since Conky lacks variables for other music players. I'm sure you could get it working the same with some tricky coding, but I don't think it's worth it as most other music players have a “now-playing” widget of sorts. | ||
Ligne 41: | Ligne 77: | ||
The settings_table entry for this one looks like the code shown on the next page, top left. | The settings_table entry for this one looks like the code shown on the next page, top left. | ||
- | As you can see, we're working with 100 divisions (since it's a percent, it will be a value between 0 and 100). Also, the arg variable is empty, which is important, since leaving it out entirely makes it incompatible with the functions we use later (missing argument). Once you've done this, I also altered the script so that the widget disappears when the music is paused. To do this, you need to make the following changes to the script: | + | As you can see, we're working with 100 divisions (since it's a percent, it will be a value between 0 and 100). Also, the arg variable is empty, which is important, since leaving it out entirely makes it incompatible with the functions we use later (missing argument). Once you've done this, I also altered the script so that the widget disappears when the music is paused. To do this, you need to make the following changes to the script:** |
- | Add this function to the beginning or end of the file: | + | Widget MPD |
+ | |||
+ | D' | ||
+ | |||
+ | L' | ||
+ | |||
+ | Comme vous pouvez le voir, nous travaillons avec 100 divisions (puisque c'est un pourcentage, | ||
+ | |||
+ | **Add this function to the beginning or end of the file: | ||
function conky_my_flag(my_arg) | function conky_my_flag(my_arg) | ||
flag = my_arg | flag = my_arg | ||
return "" | return "" | ||
- | end | + | end** |
- | Then, place the following text from the original script: | + | Ajoutez cette fonction au début ou à la fin du fichier : |
+ | |||
+ | function conky_my_flag(my_arg) | ||
+ | flag = my_arg | ||
+ | return "" | ||
+ | end | ||
+ | |||
+ | **Then, place the following text from the original script: | ||
local updates=conky_parse(' | local updates=conky_parse(' | ||
Ligne 68: | Ligne 119: | ||
cairo_destroy(cr) | cairo_destroy(cr) | ||
- | So that the last 11 or so lines of the file read as shown above right. | + | So that the last 11 or so lines of the file read as shown above right.** |
- | What the above changes do is simply to destroy the widget if MPD isn't running, and otherwise to run as normal. The function we created is so we can assign a value to the global variable flag that we use within the if-statement. Now, before this script works, you'll need to add in ${lua my_flag 0} and ${lua my_flag 1} into your .conkyrc so that the function is called and the flag variable is set to 0 or 1, depending on if MPD is stopped (0), or not (1). The TEXT section of my .conkyrc looks like the code shown above. | + | Placez ensuite le texte suivant du script original : |
+ | |||
+ | local updates=conky_parse(' | ||
+ | update_num=tonumber(updates) | ||
+ | |||
+ | if update_num> | ||
+ | for i in pairs(settings_table) do | ||
+ | setup_rings(cr, | ||
+ | end | ||
+ | end | ||
+ | |||
+ | dans l' | ||
+ | |||
+ | if tonumber(flag) == 1 then | ||
+ | <texte ci-dessus> | ||
+ | end | ||
+ | cairo_destroy(cr) | ||
+ | |||
+ | de façon à ce que les 11 dernières lignes du fichier ressemblent à ce qui est ci-dessus à droite. | ||
+ | |||
+ | **What the above changes do is simply to destroy the widget if MPD isn't running, and otherwise to run as normal. The function we created is so we can assign a value to the global variable flag that we use within the if-statement. Now, before this script works, you'll need to add in ${lua my_flag 0} and ${lua my_flag 1} into your .conkyrc so that the function is called and the flag variable is set to 0 or 1, depending on if MPD is stopped (0), or not (1). The TEXT section of my .conkyrc looks like the code shown above. | ||
What this does is set the flag variable to 0 when if_mpd_playing is false. Otherwise it gets set to 1. The rest of the settings display and position the album art, display “Paused” if MPD is paused, or the Artist and Song Title on two lines to the right of the ring if MPD is playing. The ${scroll 38 ${mpd_title}} section causes the title to scroll (so the text moves from right to left) if it's longer than 38 pixels. You can leave this out, but I put it in there to prevent the text from being longer than my Conky is wide. In order to display the image, you'll need to add the following two settings above the TEXT marker somewhere: | What this does is set the flag variable to 0 when if_mpd_playing is false. Otherwise it gets set to 1. The rest of the settings display and position the album art, display “Paused” if MPD is paused, or the Artist and Song Title on two lines to the right of the ring if MPD is playing. The ${scroll 38 ${mpd_title}} section causes the title to scroll (so the text moves from right to left) if it's longer than 38 pixels. You can leave this out, but I put it in there to prevent the text from being longer than my Conky is wide. In order to display the image, you'll need to add the following two settings above the TEXT marker somewhere: | ||
- | imlib_cache_size 0 | + | imlib_cache_size 0** |
- | Also, the mpd-cover script is below, in the Scripts section. The mpd-cover script is written for python 2.X, but you can always use the 2to3 program to re-write it for python 3. If you have issues, let me know. Be aware that some symbols can cause problems with the script. I have done very little editing (if any) to it, and it was originally from here: https:// | + | Les changements ci-dessus ne font que détruire le widget si MPD ne fonctionne pas et, sinon, le font fonctionner normalement. La fonction que nous avons créée permet d' |
+ | |||
+ | Elle permet de définir le drapeau à 0 lorsque if_mpd_playing est faux. Sinon, il est mis à 1. Le reste des paramètres gère l' | ||
+ | |||
+ | imlib_cache_size 0 | ||
+ | |||
+ | **Also, the mpd-cover script is below, in the Scripts section. The mpd-cover script is written for python 2.X, but you can always use the 2to3 program to re-write it for python 3. If you have issues, let me know. Be aware that some symbols can cause problems with the script. I have done very little editing (if any) to it, and it was originally from here: https:// | ||
Hopefully the majority of you have found this interesting, | Hopefully the majority of you have found this interesting, | ||
Ligne 85: | Ligne 162: | ||
http:// | http:// | ||
http:// | http:// | ||
- | http:// | + | http:// |
+ | |||
+ | De plus, le script mpd-couverture est ci-dessous, dans la section Scripts. Le script mpd-couverture est écrit pour Python 2.X, mais vous pouvez toujours utiliser le programme 2to3 pour le ré-écrire pour Python 3. Si vous avez des problèmes, faites-le moi savoir. Soyez conscient que certains symboles peuvent causer des problèmes avec le script. J'ai fait très peu (voire pas) de changements, | ||
+ | |||
+ | J' | ||
+ | |||
+ | Scripts : | ||
+ | http:// | ||
+ | http:// | ||
+ | http:// | ||
+ | http:// | ||
+ | http:// |
issue47/command_conquor_pp._5-8.1304510063.txt.gz · Dernière modification : 2011/05/04 13:54 de auntiee