My previous post explained how to cache whole web pages as images. Now see it in action. This is a lightweight RSS reader, optimized for comic books (but it works for any feed) and for offline use (but it works online too, of course).
Not ready for public use yet, but if you look around you can find the code somewhere ;-)
For a small project I am doing I wanted the capability to see web pages offline. So, I started thinking of a way to do that, and all solutions were annoying or impractical.
So, I googled and found CutyCapt which uses Qt and WebKit to turn web pages into images. Good enough for me!
Since I wanted to use this from a PyQt app, it makes sense to do the same thing CutyCapt does, but as a python module/script, so here's a quick implementation that works for me, even if it lacks a bunch of CutyCapt's features.
With a little extra effort, it can even save as PDF or SVG, which would let you use it almost like a real web page.
# -*- coding: utf-8 -*-"""This tries to do more or less the same thing as CutyCapt, but as apython module.This is a derived work from CutyCapt: http://cutycapt.sourceforge.net///////////////////////////////////////////////////////////////////////// CutyCapt - A Qt WebKit Web Page Rendering Capture Utility//// Copyright (C) 2003-2010 Bjoern Hoehrmann <[email protected]>//// This program is free software; you can redistribute it and/or// modify it under the terms of the GNU General Public License// as published by the Free Software Foundation; either version 2// of the License, or (at your option) any later version.//// This program is distributed in the hope that it will be useful,// but WITHOUT ANY WARRANTY; without even the implied warranty of// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the// GNU General Public License for more details.//// $Id$//////////////////////////////////////////////////////////////////////"""importsysfromPyQt4importQtCore,QtGui,QtWebKitclassCapturer(object):"""A class to capture webpages as images"""def__init__(self,url,filename):self.url=urlself.filename=filenameself.saw_initial_layout=Falseself.saw_document_complete=FalsedefloadFinishedSlot(self):self.saw_document_complete=Trueifself.saw_initial_layoutandself.saw_document_complete:self.doCapture()definitialLayoutSlot(self):self.saw_initial_layout=Trueifself.saw_initial_layoutandself.saw_document_complete:self.doCapture()defcapture(self):"""Captures url as an image to the file specified"""self.wb=QtWebKit.QWebPage()self.wb.mainFrame().setScrollBarPolicy(QtCore.Qt.Horizontal,QtCore.Qt.ScrollBarAlwaysOff)self.wb.mainFrame().setScrollBarPolicy(QtCore.Qt.Vertical,QtCore.Qt.ScrollBarAlwaysOff)self.wb.loadFinished.connect(self.loadFinishedSlot)self.wb.mainFrame().initialLayoutCompleted.connect(self.initialLayoutSlot)self.wb.mainFrame().load(QtCore.QUrl(self.url))defdoCapture(self):self.wb.setViewportSize(self.wb.mainFrame().contentsSize())img=QtGui.QImage(self.wb.viewportSize(),QtGui.QImage.Format_ARGB32)painter=QtGui.QPainter(img)self.wb.mainFrame().render(painter)painter.end()img.save(self.filename)QtCore.QCoreApplication.instance().quit()if__name__=="__main__":"""Run a simple capture"""app=QtGui.QApplication(sys.argv)c=Capturer(sys.argv,sys.argv)c.capture()app.exec_()
The kind fellows at Packt Publishing have sent me a copy of this book to review, and I have been slow with it (flu doesn't help). In any case, while I finally start reading it, here's the usual free sample chapter
But that's not that big a deal, I could make a living doing something else. I am sure I would be competent at something else, even if I have no idea what that would be right now.
It does, however give me freedom to play, which is much more important. Therefore, this post is sort of a status update on things I play with. Not games, those are not really my thing, but things that I do for fun.
Yes, some of these may mean I am a very strange person.
I'll limit myself to the last couple of weeks or so.
There's been sort of a bump in interest in Marave, my distraction free editor and it's because it has been reviewed in Linux Journal!
I have read the article (sadly I can't link to it) and it was a super positive review, here are some choice quotes:
"marave makes the dull world of text editing romantic and immersive with beautiful minimalism"
"... it doesn't just have minimalism and simplicity, it has minimalism and simplicity combined with beauty and a palpable design ethic. marave has soul, and I love that."
So thanks for the kind words to the author, and something I noticed: you ran into a big bug in marave and didn't notice :-)
The "cricket bat" icon (it's a screwdriver ;-) should show you the config dialog. However, it seems in Ubuntu (and maybe in other distros, I don't know) the config is not visible,and all you see is the text move around a bit. This is what he should have seen:
I have never been able to reproduce it, but I am going to install a Ubuntu VM just for this, so maybe soon.
On related news, marave was also reviewed in a german magazine a couple of months ago, and I have not been able to get a copy of the article. (BTW, isn't it reasonable to send a copy of these to the author of the program you are reviewing? Neither magazine even mentioned it to me!)
In any case, if anyone has this magazine and can tell me what the article about distraction-free editors say, you will make my day:
On new projects (yes, I always have new projects), I ran into this awesome blog post by Roger Alsing about approaching Mona Lisa with just 50 polygons <http://rogeralsing.com/2008/12/07/genetic-programming-evolution-of-mona-lisa/
> and being a nerd and having awesome programming tools at my command... I wrote a framework to test that kind of algorithms.
A few days ago I finally got my 89 cents bluetooth dongle (now $1.85, but still with free shipping from china!) and got a bunch of pictures I had in my phone.
The quality is crap because my phone is crap, but trust me, there must be one thing here you have never seen before.
Here they are: weird stuff that made me take out my phone and grab a picture, with explanations.
This, from Mar del Plata, is the most badass popup book I ever saw.
I'm Mark Shuttleworth!
In a free software event in Buenos Aires, Canonical's boss and former space cargo was supposed to deliver the keynote. He canceled at the last minute. So Maddog Hall offered to replace him... in character.
Someone found a really, really awesome (and/or crappy!) astronaut costume, and Maddog gave a keynote shouting "I'm Mark Shuttleworth! I'm an astronaut!" and claiming to have come from the future to examine some slides recently found, written by some unknown dude named Maddog. Really funny stuff.
Python vs. Ruby
Same event, take a look:
Yes, I swear they are taken with less than 10 seconds of one another.
I was buying groceries in San Isidro's Disco supermarket. Yes, usually buying a large package of butter is cheaper per kilo than a small one. But here, a 200g package costed almost the same as a 100g! That's just stealing money from those who don't use much butter. Me? I'm not at risk.
This was a shop in Avenida Alem in Buenos Aires. It was unusual to see a "VISA is suspended, 20% discount" sign. Much more unusual was to see the small letters: "present your visa card". I mean, wasn't it suspended?
And then I saw the rest:
It says "present your visa card and pay using anything else".
That guy must really have been pissed off at Visa!
I am just not writing here. I am writing a book instead.
What book am I writing? A book about python programming, of course! It's called "Python No Muerde" (Python Doesn't Bite) and it's in spanish.
Now, I am the first to admin: I am not a great programmer. And I am not a great writer. But I have lots of things to say. If I can organize them correctly, they even make sense sometimes!
So, I am giving this write-long-stuff thing a try.
Of course since I am an open source nerd, I can't do things the usual way, therefore, the book is under Creative Commons. And because I am a programmer, I hacked together a (if I may say so myself) decent structure to handle book-writing.
I write in restructured text
I use rst2pdf to create PDFs both of individual chapters and the
I use rest2web to create a website
I use mercurial (at googlecode) to handle revision control and
I use make to control rebuilding of chapters when code changes, or images get updated, etc.
Of course it's more complicated than that, the PDFs are in the site, the site is uploaded via rsync, the uploads and rebuilds are triggered by hg push, and so on.
In any case, I may post a few times about how this whole thing works, here is the output of the machinery:
I will write about the only person who ever taught me programming, Claudia. I was young, so the earth was still lukewarm, the day we saw the dinosaur.
I was just a green sophomore in the School of Chemical Engineering where, paradoxically I would never take a chemistry class, being an applied math student and all that, and at the time "personal computers" were a novelty, a toy of the upper middle class.
We had spent the first two months of the semester learning how to program the obvious way: writing assembler for a fictional machine on paper by hand, when Claudia broke the news, we were going to see a real computer.
No, not a PC, not even an XT, but a real computer, the one real computer in all the university, and you could hear the type switching to bold as she spoke about it. Sadly it was not as real as the one at the research facility (A MiniVAX!) but it was a real enough PDP.
We would not be allowed to actually use it until the following year, but ... well, it was still something special.
I had been programming for years, even for a year before I saw my first (seriosuly not real) computer, I had followed BASIC programs in my head for days, imagining the space invaders float on the screen of my mind, and stepped into writing machine code inside REM statements in my Timex Sinclair 1000 onto the luxury of a C64, but never noone had taught me anything.
Our small class (maybe 10 students) spent endless hours doing things like traverse a matrix, first by rows, thn by columns, then in a spiral from the top-left, writing programs that followed our endless source of algorithms, the numerical solutions guide.
First assembler, then Fortran, we learned.
She was my Mr. Miyagi, I was a heterosexual Ralph Macchio, and I figured out the most important thing about programming: I was awful at it.
Over the next 20 years that situation has been slowly improving, but I never again had someone teach me programming. Claudia had already taught me everything I needed to know, that code can always improve, that there's more than one way to skin a cat.
That the dinosaur was real and that some day soon my computer would be faster and nicer than the dinosaur was then, and that programming was cool, and that if I could find a way to draw a polynomial graph horizontally on a printer without ever having the whole graph in memory (it didn't fit), those future computers would do awesome things, and that I was one of the many who would help bring that to reality.
That talking about code was fun in itself, that you could make a modest living and be happy about it, that you could in any case make jigsaw puzzles in your spare time and keep on teaching or whatever.
And later the dinosaur's bones were scavenged into a line of racks holding routers, and its glass terminals are destroyed, and the gold in its teeth was stolen and the rare bus cables sold, and its circuits scrapped, but I saw the dinosaur alive, and Claudia taught me how to make it jump, and for that, I will always be grateful.
I have now read it (sorry it took so long!) and here's my review.
It's a well-written book. The exposition is clear and the author knows the subject and what he wants to say.
I was impressed by the straightforward approach of Grok when compared to what I dimly remember of ancient Zope experiences. The idea of a modern, agile, simple framework over Zope's admittedly powerful foundation has a lot of merit.
OTOH, I am not really convinced that I should drop Django for the small web projects I have scheduled, but if you are looking for a framework, and are not heavily invested in another, Grok is certainly worth checking out.
And, if you want to learn Grok, this book does the trick.