| Nic0's Sphere |
|
04/01/12 Clint, Command Line Library for PythonThis library is the kind I like, the kind which make your life easier, perfect for someone like me, who uses Python all the time. So, what can Clint do for you? Well, there are a bunch of tools that might come handy when you do some command line based programming, especially quick scripts. If you use Python as your primary langage, CLI stuff is always useful. ColorsHaving some colored output can be nice, but I don’t want to use some ncurses
interface to have a nice display. A common request is for text color to be
green for an expected result, and red otherwise. The highest ranked answer from
this stackoverflow’s question gives some Let’s see the simplest example possible:
How intuitive was that! At least, I don’t need to check on the documentation every time I want a red message! If you only need one word in different color, it’s as simple as a concatenation, here’s a quick example:
IndentationOne of the main feature of Clint, is to handle nicely indentations. It even managed nested indentation, a quote system, allow you to set some prefix chars, like quotes in emails for example. Here a quick example:
Once executed, the output gives:
Looks good without breaking a sweat! ArgumentsThere are ways to handle arguments, like the module
For a redistributed program that I take time over, I would probably use
Progress bar, files and pipesClint comes with more tools, which are easy to use. Let’s look at a progress bar with Clint:
Clint handles pipes, eg. Documentation and ConclusionThis post is not a review of every possible utility that Clint has to offer,
but more of a quick overview, and memo for myself. I really think Clint could
come in handy from time to time. Unfortunately, there is a lack of documentation, not
much more than the README from the github repository, as the Another thing that could bother you is, so far, Clint only works with python
2.x. Python 3 compatibility is include in the todo list, as is
documentations. I hope you enjoyed this quick review of Clint. Anyway, it’s in my toolbox now. (Lire la suite...) |
01/01/12 Changes on This BlogSince I started blogging, this is the biggest change I’ve done. So I felt like I own you an explanation. The main reason was to separate the English content from the French one. Well, at least, it’s what I’m telling myself, as I know I changed the blog engine for Jekyll, just because I like the way it works. I’m aware that it might sounds unreasonable to change of CMS like that, but I’m blogging for my pleasure, spending lots of time with, so it worth to change for a better system, that suite better my way about computers. About French ContentFirst time I said in this blog that I wanted to write in english was in this post, it was more than 9 months ago. It took me some time to find the courage to do so, as I started only a couple of months ago. Anyway, I moved the content to this link, I had to manage some redirections, as it isn’t a good idea to leaves 404 pages. I probably won’t use it that much now. I certainly only publish the Hacker Weekly News series, I did think about to stop it, but I like this series, helps me to classify information, and keep track of it. So I’ll should carry on the series on the French part of this site. So, if you still want follow the Hacker Weekly News series, you should add this feed on your reader. The main site, of this post, keep the same feed as before, so no need to change anything. About JekyllIf you never heard about Jekyll, is a static website generator, the main idea is to generate the entire site in plain HTML, with obviously some JavaScript, but no server side language such as PHP. I never really liked hack into Wordpress, at the opposite to Jekyll, witch is much easier to get into. You just need some Ruby background. I hesitated with blogofile as it’s written in Python. I won’t explain why Jekyll, or any static website generator, are nice to use, there is already lots of blog post around the web. About Github PagesI did want try this solution, Jekyll was build to works with Github pages, the idea is simply to push on the repository, and Github does the generation of the site. The problem is Github doesn’t allow any plugins. Fair enough, I can understand that they don’t want any arbitrary code to be run on them server, but it loose one of the main interest of it. No plugins, no hack, no interest, simple as that. So I’ll host myself, with some kind of rsync over ftp, seems like lftp does something like that with the mirror mode. I would think about Github pages if I haven’t used a plugin to generate all my redirection. I still have some stuffs and improvements to take care of. That’s all for now, see you soon with some real blog posts! (Lire la suite...) |
03/12/11 PhotoShow, Web gallery without SQLWhen it comes to web gallery, I usually choose Piwigo, a safe choice for a stable PHP gallery. Last week, I heard about a new project, called PhotoShow, a nice looking web gallery. A demo website is available. Here a quick functionalities review.
First, I have to warn you that PhotoShow still on a early stage of his developpment. It seems stable enough, the project should improve quickly in a near future, with probably some new features. So perhaps it isn’t ready for production, but should be fine for a personal use. Installation and configuration are straight forward, the easiest is use
Some would appreciate the drag n' drop system, I personally liked the disposition of thumbnails, compact as google galleries, managed well different size to find the optimal display, allow you to quickly see every photos of an album. I will keep an eye on this project for sure. At last, the code can be found on github, under the GNU GPLv3. (Lire la suite...) |
02/12/11 Manage automatically two dictionaries with FirefoxWhen your native language isn’t English, and when, like me, you spend time writing around the Internet, between comments from some news sites, blog posts and programming question-answer site, you have to deal with at least two languages, English, and whatever language you use at home. Unfortunately, I have trouble with grammar and spelling^1. I probably have done what everyone else with bad spelling would do in this case, add to Firefox a spell checker. It does what I want, but as I write across websites, I need to switch the spell checker from French to English, certainly more often that I even notice. Switching of dictionaries is annoying, but not enough to really do something about it. When you’re switching it, you think that perhaps you should try to google about it if there is any kind of shortcut or whatever would do the trick and save you some time, but you forget as soon as you switched the dictionary, and your mind focus on the answer/comment you’re writing. Same thing for asking to some geek friends, quickly forgotten to ask, every time. So I’d carry this problem who isn’t really one, and by chance, I found the perfect solution for what I’m asking for. It could be obvious to some persons, but after all, I’m not switching of dictionary for that long time ago. The answer I found is no more that a Firefox plugin, called dictionary switcher. This plugin recognize automatically the language you are taping of, and adapt the dictionary in function of it, few more options on it to do more precisely what you want. With a name link that, I could find it earlier, but the thing is I didn’t toke time to look for. Short blog post, for a quick trick, maybe it could be useful to someone else. (Lire la suite...) |
01/12/11 The missing newsletter of Arch LinuxMost of Linux distributions comes with newsletters, a short summary of what happen around distributions and the community himself. Interestingly enough, Arch Linux doesn’t have anymore one, as far as I know. It wasn’t always like this, here a quick review of what was done so far. y apologies if any informations was inaccurate. The newsletterFeb 2004 – Jul 2009 As the Arch community is growing, some of you may never heard about this old newsletter, start with weekly issue, quickly became a twice a month release, finished as a monthly issue. The information provide was good, but as I became an Arch user around this time, I haven’t the opportunity to read lots of them. For information, you still can read old archives on this link. Arch Linux Newsletters Archives I’m certainly not the only one, but I miss this newsletter. Arch User MagazineApr 2009 – Jun 2009 Unofficial project initiate by Ghost1227, in a paper magazine style, old issues can be grab in the same link as the Newsletters Archives. We can still read the bbs thread for the first released issue. Three issues was made, and it will be merge with the official newsletter, as the author doesn’t have the time to carry on the project as he wanted. Arch Linux MagazineAug 2009 – Mar 2010 The official newsletter, by Kensai, and the Arch User Magazine, by Ghost1227, will join their force together to provide a magazine available in both format html (newsletter format) and pdf (scribus/magazine format). Here is the bbs thread for nostalgic, about the first released announce by Kensai. I proudly translate issues with others French contributors in my language back this time. Unfortunately, a lack of contribution, and certainly of time as well, ended the magazine after 4 releases. But meanwhile, Kensai left for personal reasons. Rolling ReleaseSep 2010 – May 2011 (Until now?) Rolling Release is an official website that aimed to succeed the Arch Linux agazine, as it’s an e-zine, no need to have a regular issue, or even spend time with scribus to make a nice looking pdf. Here the forum announce of the official launch of the site. Technically, the website look nice, allows comments. Even someone, jdarnold, started for few weeks a weekly issue on this site. The website has nice posts for a while, but hasn’t published anything since May 2011, without any official reason that I’m aware of, other than the lack of time I guess. The missing newsletterAll this news was great informations, I’m very thankful for all the time that contributors spends on this, on their own time. But what’s now? I know what you think, “you want one? Do It Yourself!”, it’s absolutely true if I was following Arch Linux actuality enough, and a more fluent English. What I do know is that this kind of initiatives often come from one man, no more, after all, Arch Linux came from a one man project as well. So, maybe if you are close to the community, following forum or mailing list, you might consider start some kind of newsletter. It doesn’t need to be great, long, with lots informations. Few links in a paper, with a short description, a couple of tricks or applications taken from the forum, it’s all it need to start something, I’m sure the community would be thankful for this, well I’ll be thankful for sure. (Lire la suite...) |
30/11/11 Tyrs 0.6.0, ncurses Twitter client, first release with UrwidTyrs is a Twitter and Identi.ca client based on ncurses. This major release is the first one using the urwid library. It will improve greatly the user interface.
In many way the interaction with user is improve, and in many details. This release still in early stage of development of the urwid interface, this mean it’s usable, but some functionalities aren’t yet implements, and will be done soon. I always follow the release early, release often plan, and even everything isn’t ready yet, I believe the improvement worth a release. Some stuff that need to be done in further releases:
If you are using Arch Linux, the installation through the AUR package is easy:
You may find the latest code in the github repository, and find tarballs in the pypi page of the project. I hope you’ll enjoy it. As usually, any feedback is much appreciated. (Lire la suite...) |
29/11/11 HTML output screenshot with Urwid ncurses libraryUrwid is a ncurses library for Python, you may check older posts if you’re not familiar about it. So far, we’ve seen some useful functionalities and tricks, to run urwid, therefor, it’s time to see something (almost) useless but geek, and in the spirit of ncurses programs, as urwid allow to take “screenshots” of the application, with a HTML output. The problem with the reference guide of urwid, it’s that is not so easy to
figure out how to get things done as we want. This corresponds to the screen
capture part of the reference guide. But the easiest way to get started it’s
to check source code, and not the real code of urwid, but the code who
actually generate the tutorial of urwid, they do use this functionality for
this part. Check in the tarball, Let’s take our own example, based on the code we’ve done in earlier post, for
reminder, we obtain a list of item (couple title/description), in a
The ideaThe screenshot will be triggered by the s keystroke, the idea is to start over the main loop, and pass in arguments the sequence of keystroke wanted. Trick about screen sizeWe need to pass in the screenshot the size of the screen. It will be a tuple (y, x), it could be some random numbers, but it could be useful for the screenshot, and many other functionalities, to get the real size of the screen, and their is a variable for that.
About the outputThe output will come in a variable, but after every stroke we ask, their will be a screenshot, retrieve in a list, we need to choose the good one, probably the last one. The screenshot code
In this code, we prepare two functions.
The result it place in the file The resultselected: item 3: Cras a magna sit amet fel... item 0 Lorem ipsum dolor sit amet, consectetur adipiscing elit. item 1 Cras a magna sit amet felis fringilla lobortis. item 2 Sed sollicitudin, nulla id viverra pulvinar. item 3 Cras a magna sit amet felis fringilla lobortis. item 4 Lorem ipsum dolor sit amet, consectetur adipiscing elit. item 5 Sed sollicitudin, nulla id viverra pulvinar. item 6 Sed sollicitudin, nulla id viverra pulvinar. item 7 Lorem ipsum dolor sit amet, consectetur adipiscing elit. item 8 Cras a magna sit amet felis fringilla lobortis. item 9 Lorem ipsum dolor sit amet, consectetur adipiscing elit. item 10 Lorem ipsum dolor sit amet, consectetur adipiscing elit. item 11 Sed sollicitudin, nulla id viverra pulvinar. item 12 Sed sollicitudin, nulla id viverra pulvinar. item 13 Cras a magna sit amet felis fringilla lobortis. item 14 Cras a magna sit amet felis fringilla lobortis. item 15 Cras a magna sit amet felis fringilla lobortis. item 16 Sed sollicitudin, nulla id viverra pulvinar. item 17 Sed sollicitudin, nulla id viverra pulvinar. item 18 Lorem ipsum dolor sit amet, consectetur adipiscing elit. item 19 Lorem ipsum dolor sit amet, consectetur adipiscing elit. item 20 Cras a magna sit amet felis fringilla lobortis. item 21 Cras a magna sit amet felis fringilla lobortis. item 22 Sed sollicitudin, nulla id viverra pulvinar. item 23 Cras a magna sit amet felis fringilla lobortis. The full code
|
22/11/11 Footer Edit with Urwid, IRC-Client-like inputWe start with the code from Selectable List with Urwid for Python, check before the Signals with Urwid for Python for a small involvement of the code, for handling signals. So far, we have a selectable list containing two items each (title and description). We can go through it with up and down key arrows, and select one of them with the enter key. We use urwid.Frame witch give us an useful layout divided in three parts, header, body and footer. In the last post, we used the header to display the selected item, the body to display the list, and the footer wasn’t used at all. Now, what we want is to use the footer for an Edit widget, exactly like ncurses
IRC-client such as IRSSI or weechat. When we will press the In the following screenshot, the list was generated with random description. the 4th item was replaced with this editing process, and we’re about to replace the 5th item as well. It may seem not a big deal, but it still a good exercise to gain practice with urwid. Let’s talk about the code. The full code is at the end of the post.
The edit method is directly call when the
Once the edit is done, the edit_done function is called as a callback, with the content. Then we modify the content of the description in the list. And set back to None the footer, as we don’t want anything display anymore.
That’s it, in this example this code is used to manage a list, but it could be used for a large set of applications. Here the full code:
Hope it can help someone. (Lire la suite...) |
22/11/11 Several colored string with UrwidOK, this one is an easy and quick stuff, that I’m almost ashame to share. But the thing is, I search for it, and I wasn’t even sure where to look at it. The reason I put it here is because I trying to put together some trick about urwid, stuff I spend some time to looking for, even if it isn’t so much time. If someone need it, he should find it easily here. The idea is to highlight some worlds in a string. The answer was right in the
front of me from the start! As it was shown in the
This short example, witch is only a part of a code of course, shows a string
with the As I said, it isn’t a very exalting post, just a quick trick. (Lire la suite...) |
21/11/11 Signals with Urwid for PythonUrwid, a Ncurses library for Python, handle a signal system, witch is nice for a ncurses library. You may want to check others posts on urwid if needed. We’ll see two examples here. A first exampleLet’s start with the code from the last post, for reminder, it does a selectable list, with SimpleListWalker, and display the selected item every time Enter is pressed. It’s a simple code, that we’ll extend a little. What we want is to every time we move from the list, the selection is update to the header, showing the correct item, and we want have it working with a signal. Through, it would has other way to get it work, but it’s a way to start. The reference about signals isn’t so easy to get into, maybe the best
example from the tutorial is Events and listbox widget, but in this
example, the signal is connected to an Edit Widget, here, we doesn’t have
such thing, and we want use the list instead. If we try with the
Fine, as the SimpleListWalker extends to ListWalker, it seems that this
widget use the
Importants remarques:
That’s it, nothing complicated, we run it, and it works as expected, every time we move, the header is updated with the signal system. What about others signals?Their is no signal list in the documentation, so let’s find out some more
signal with the documentation. We’ll looking for
We find the the
vterm.py is more specific and exist only on the latest 1.0.0 version. Custom signal from scratchLet’s go deeper, and create a signal from scratch. The example will as simple as possible. We create an object, containing a function that raise a signal, on the other hand, an hello world that would change his message when it will receive the signal. I found another example from the mailing list but a bit more confusing maybe. Here the simplest example that I could came with.
First thing, don’t forget the import. Now, we create the The main function isn’t more difficult. I added some comments in case. The most important, it’s the callback to the update function and how it’s connected with:
That’s all for now, I hope it’ll give you some more very basics example to get started with signals and urwid, as the documentation isn’t always easy. To be continued… (Lire la suite...) |

