Skip to main content

Ralsina.Me — Roberto Alsina's website

Making your QTextBrowser show remote images

It's re­mark­ably easy to turn your QTextBrows­er in­to a lim­it­ed web browser, at least good enough to show im­ages from the we­b.

Here's all the code:

from PyQt4 import QtCore,QtGui
import urllib, os, md5

class PBrowser(QtGui.QTextBrowser):
    def loadResource(self, type, name):
        url=unicode(name.toString())
        ret=QtCore.QVariant()
        if url.startswith('http://'):
            dn=os.path.expanduser('~/.bartleblog/cache/')
            if not os.path.isdir(dn):
                os.mkdir(dn)
            m=md5.new()
            m.update(url)
            fn=os.path.join(dn,m.hexdigest())
            if not os.path.isfile(fn):
                urllib.urlretrieve(url, fn)
            ret=QtGui.QTextBrowser.loadResource(self, type, QtCore.QUrl(fn))
        else:
            ret=QtGui.QTextBrowser.loadResource(self, type, name)
        return ret

And here's bartle­blog tak­ing ad­van­tage of it:

bartleblog10.png

It even has a prim­i­tive cache and ev­ery­thing ;-)

PHP is for Lucre (II)

I prob­a­bly should have charged more.

Things I learned in this pro­jec­t:

  • If they tell you the de­sign is im­­por­­tan­t, it does­n't mat­ter that said de­sign in­­­cludes:

    • Fixed pix­el-height text in­­­puts (so when you re­­­size fonts you can't see what you write)

    • Mis­­­aligned fields and la­­­bels

    So, I need­ed to use Smar­­ty to gen­er­ate the ex­act same HT­M­L, work­ing just as bad as the orig­i­­nal. And it is thrice the work of do­ing it right.

  • If de­­ploy­­ment is on Win­­dows, re­­gard­­less of hav­ing the same ver­­sion of PH­P, you are go­ing to get in trou­ble one way or an­oth­er.

    In or­der to do it quick & cheap & good, I used PEAR mod­­ules ex­ten­­sive­­ly. And now I have to make sure all of them are in the serv­er... where there is no re­­mote ad­min so­lu­­tion us­able. So I have to be on­site to de­­ploy. I can't even re­mem­ber the last time I had to do such a thing :-(

So, I was cheap­er than the oth­er pro­pos­al­s, and maybe I was a bit too cheap. Live and learn :-)

Neat KDE style: Domino

To­day I was fid­dling with my desk­top and de­cid­ed to check what KDE styles were avail­able in Arch Lin­ux.

Then I test­ed Domi­no.

It's very, very, very nice.

domino.png domino2.png

I have no idea how good it is per­for­mance-­wise (my note­book is pret­ty brawny) but hey, I am a bor­ing guy, and I'm wowed.

Giving BartleBlog the push it needs

I found a cou­ple of hours to hack, and de­cid­ed to spend them on Bartle­Blog.

Here's what got done:

  • UI for blog pre­f­er­ences (still need to do maybe ten of these lit­­tle mod­­ules).

  • Search for files in rea­­son­able places (in­stead of us­ing the DB in the cur­rent fold­er, for ex­am­­ple).

  • Start­ed work on a first-use wiz­­ard

  • Start­ed work­ing on a orig­i­­nal and sim­­ple help sys­tem (re­­source files, yay! ;-).

  • Im­­ple­­men­t­ed (lame­­ly) post­ing of "s­­to­ries" which are stat­ic pages that are not part of the blog's flow.

I in­tend to spend a cou­ple of hours on it ev­ery day for the next ten days or so. Af­ter that, who knows, maybe a re­lease will be rea­son­able.

Why you don't have to take economists too seriously

I bet you have seen be­fore some ar­ti­cle about how some econ­o­mist cal­cu­lates the val­ue of things.

For ex­am­ple, if you pre­fer not to have health in­sur­ance worth $100 a year, and that means you are X% more like­ly to die in 20 years, then some num­ber-­mas­sag­ing will tell you you val­ue your life at $Y (the num­bers are not re­al­ly im­por­tan­t).

Here is an ex­am­ple in Slate mag­a­zine which in­cludes a rather clear ex­pla­na­tion of how this process work­s.

It shows that a Chica­go drug deal­er val­ues its life at be­tween $50000 and $100000.

Now, this is all based on the fact that that per­son choos­es to go on his life in a cer­tain way for a cer­tain amount of mon­ey. How­ev­er, I am pret­ty sure if of­fered $100000 or life, he would choose life.

Since that choice is just as his as the one used to reach that num­ber, it's clear that hu­man be­ings are in­co­her­en­t, or maybe that the dif­fer­ence in val­ue be­tween a 10% chance of death and a 100% chance of death is way larg­er than econ­o­mists es­ti­mate.

Per­son­al­ly, I can't even think of an amount of mon­ey that would make me take a 50% chance of death. But I am aware that, for ex­am­ple, my di­et caus­es me a cer­tain risk, maybe 1% or 10% (no idea).

How about you? Do you be­lieve in economist­s?


Contents © 2000-2023 Roberto Alsina