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 <bjoern@hoehrmann.de>//// 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[1],sys.argv[2])c.capture()app.exec_()
I'm one of the speakers for the free python courses in FM La Tribu, in Buenos Aires.
Every saturday you can learn something from one of the best python programmers in a thousand miles, or from me.
I'll be teaching about virtualenv, buildout, nose and other things on August 21, about GUI stuff on September 25 and October 2, and about PyQt in October 30.
This is all for free, and I hope lots of people show up!
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
I make a living working with free software (BTW, if you need sysadmins that know what they do, contact us: http://www.netmanagers.com.ar)
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.
I only did a very simple algorithm, based on transluscent triangles, but it did work... for some definition of work!
You can even see the local minimum that doesn't let her right eye form right :-)
Evoluto has a library of algorithms (currently empty) and you can edit and reapply on-the-fly the one you want, and see the generations change on-screen.
It would take some work to make it a polished program, but it does work.
I folled around a bit with creating a nice PDF presentation player but it's still very early:
In what's perhaps my most established project, rst2pdf. I have fixed a bunch of bugs, and a release is a bit overdue:
Issue 186: Text not wrapping around images when specified
I fixed this by adding a new CLI option, so behaviour was not changed, but now you can have images with text flowing beside it. It will not look great but it works.
Issue 307: Replace directive doesn't replace text in header/footer in some cases
This was an interesting problem! It was very entertaining.
Made it work with Sphinx 1.*
There is a piece broken still, but what I fixed was not terribly hard.
Unbroken bookrest
I need to work much more with this, but at least what worked before works again. If you don't know what bookrest is, it's a rst2pdf graphical frontend / word processor, here's a taste: