Skip to main content

Ralsina.Me — Roberto Alsina's website

Posts about programming (old posts, page 19)

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 :-)

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.

PHP is for lucre. Filthy, filthy lucre.

Got comis­sioned a small job for a cus­tomer:

  • Take a form done in an­­cient HTML us­ing dreamweaver.

  • Re­­do it in PH­P+MySQL

  • Make it work.

  • Add val­i­­da­­tion.

  • Make it look the same.

Ok, it's not ter­ri­bly hard, but it's not ter­ri­bly sim­ple, ei­ther, spe­cial­ly if you are not all that up­-­to-­date on PH­P.

But hey, us­ing HTM­L_Quick­Forms and Ren­der­er_Table­less, it's kin­da done.

But boy, do I now re­mem­ber how I don't like PH­P!

What I am plotting...

...noth­ing.

Ok, here's what I have been do­ing:

  • Dad­dy work. Lots of it. Fun!

  • Ac­­tu­al work. Lots of it. Fun, but not so much!

  • Worked a lit­­tle more in RA-Flip. Play/Stop/­­Pause is done. The ed­it­ing mode and open­ing/sav­ing files is pret­­ty much done, so it will be ful­­ly func­­tion­al as soon as I can spend an af­ter­noon in it.

  • To­bo­­gan (My slideshow soft­­ware). It works nice­­ly. There are many rough spots and it needs a few fea­­tures:

    • Some way to ed­it the CSS for in­­­di­vid­u­al slides in a nice man­n­er. Like set­t­ing back­­­­­grounds and colours (and not much else)

    • A nice way to save the slideshow so it ends all in a sin­­­gle fold­er.

    • Many UI de­­­tails

    • Docs

    • A site

  • Bartle­Blog: it has worked well for me for a long while, since I have been post­ing this blog us­ing it. And re­al­­ly, it's a nice blog, is­n't it? ;-) But of course, there is stuff to be done:

    • Many UI de­­­tails

    • De­­­cent flickr and openo­my up­­­load­­­er­s/­­­man­agers

    • Some ex­­­tra gad­gets I have in mind

    • Docs

    • A site

And that's all I have in mind right now. Ex­cept maybe a graph­i­cal Be­funge in­ter­preter, but that's not re­al­ly im­por­tant ;-)