Skip to main content

Ralsina.Me — Roberto Alsina's website

Posts about python (old posts, page 78)

The Future of PyQt by Example

Three years ago, I start­ed a se­ries of long posts called "PyQt by Ex­am­ple". It reached five posts be­fore I aban­doned for a se­ries of rea­sons that don't mat­ter any­more. That se­ries is com­ing back start­ing next week, rewrit­ten, im­proved and ex­tend­ed.

It will do so in a new site, and the "old" posts will be re­tired to an ar­chive page. Why? Well, the tech­nolo­gies used in some of them are ob­so­lete or don't quite work nowa­days. So, the new ver­sions will be the pre­ferred ones.

And while I am not promis­ing any­thing, I have enough writ­ten to make this some­thing quite longer, more nice­ly lay­out­ed, more in­ter­est­ing and make it cov­er more ground. BUT, while do­ing some checks on the traf­fic sta­tis­tics for the old post­s, some things popped out.

This was very popular

About 60% of my site's traf­fic goes to those five post­s. Out of about 1200 posts over 12 years, 60% of the view­ers go to the 0.4% of the pages. That is a lot.

It's a long tail

The traf­fic has not de­creased in three years. If any­thing, it has in­creased

A long and tall tail.

So, all this means there is a de­sire for PyQt doc­u­men­ta­tion that is not sat­is­fied. I am not sur­prised: PyQt is great, and the rec­om­mend­ed book is not free, so there is bound to be a lot of de­mand.

And, here's the not-­so-rosy bit: I had un­ob­tru­sive, rel­e­van­t, out­-of-the-way-but-vis­i­ble ads in those pages for more than two years. Of the 70000 unique vis­i­tors, not even one clicked on an ad. Don't wor­ry, I was not ex­pect­ing to get mon­ey out of them (although I would love to some day col­lect a $100 check in­stead of hav­ing google hold my mon­ey for me ad eter­num).

But re­al­ly? Not even one ad click? In more than two years, thou­sands of peo­ple? I have to won­der if I just at­tract cheap peo­ple ;-)

PyCamp Starts This Week

This fri­day marks the be­gin­ning of the 2012 Py­Cam­p. What's Py­Cam­p? It's a lot of python pro­gram­mers (this year, about 50) gath­er­ing in an iso­lat­ed place for a long week­end, with noth­ing to do ex­cept code. We will have our meals catered, there are no TVs, there is hard­ly any­thing with­in walk­ing dis­tance, and it's go­ing to be very cold.

So, it's go­ing to be awe­some. It's a rare chance for me to spend a few days hack­ing at my own per­son­al pro­ject­s, un­in­ter­rupt­ed by more im­por­tant things like fam­i­ly, work, cook­ing, or so­cial­iz­ing ex­cept be­tween nerd­s.

Sure, there is the oc­ca­sion­al mono­cy­cle rid­ing, or jug­gling lesson, or shoot­ing prac­tice, but re­al­ly, three or four sol­id days of hack­ing.

I in­tend to work on projects re­lat­ed to Niko­la my stat­ic site gen­er­a­tor, so if you are in­ter­est­ed in that and go­ing to py­cam­p, I want to talk with you.

And if you are in­ter­est­ed but not go­ing to py­cam­p, there is no rea­son not to join in a vir­tu­al sprint. We'll have in­ter­net. There is IR­C. I will have time. It's a week­end! Please share any in­ter­est­ing ideas you have about stat­ic site gen­er­a­tors in the niko­la-dis­cuss group and we'll see how much can get im­ple­ment­ed or at least start­ed.

A Simple Nikola Link Checker

One of the most im­por­tant things when you are build­ing a stat­ic site gen­er­a­tor like Niko­la is that your site should not be bro­ken. So, I re­al­ly should have done this ear­li­er ;-)

This is a very sim­ple link check­er that en­sures the pages Niko­la gen­er­ates have no bro­ken links. I will make it part of Niko­la prop­er once it's more pol­ished and doit sup­ports get­ting a list of tar­gets

To try it, get it and run it from the same place where you have your, right after you run doit.

import os
import urllib
from urlparse import urlparse

import lxml.html

def analyze(filename):
        # Use LXML to parse the HTML
        d = lxml.html.fromstring(open(filename).read())
        for l in d.iterlinks():
            # Get the target link
            target = l[0].attrib[l[1]]
            if target == "#":  # These are always valid
            parsed = urlparse(target)
            # We only handle relative links.
            # TODO: check if the URL points to inside the generated
            # site and check it anyway
            if parsed.scheme:
            # Ignore the fragment, since the link will still work
            # TODO: check that the fragment is valid
            if parsed.fragment:
                target = target.split('#')[0]
            # Calculate what file or folder this points to
            target_filename = os.path.abspath(
                os.path.join(os.path.dirname(filename), urllib.unquote(target)))
            # Check if it exists, or report it
            if not os.path.exists(target_filename):
                print "In %s broken link: " % filename, target
    except Exception as exc:
        # Something bad happened, report
        print "Error with:", filename, exc

# This is hackish: we use doit to get a list of all
# generated files. Minor modifications would let you check
# the non-generated files as well.

for task in os.popen('doit list --all', 'r').readlines():
    task = task.strip()
    if task.split(':')[0] in (
        'render_site') and '.html' in task:
            # It looks like a generated HTML file

On Politeness, Street Signs, and Codes of Conduct

When I grow up, I want a pink car. Girls like pink.

—Ta­to (my son, age 4 at the time)

There has been a lot of talk late­ly about codes of con­duct in con­fer­ences. I don't have an­swers to much, but I do have a lot of ques­tions in my head, and some things seem to come to my mind be­cause of that, so I will do a lit­tle head dump­ing, and let's see if clar­i­ty ap­pears.

So. The main thing seems to be that the pro­posed codes of con­duct aim at mak­ing events in­clu­sive, and more di­verse, and wel­com­ing to peo­ple who may have felt un­wel­come in the past. That these groups in­volve wom­en should be a call of at­ten­tion. Wom­en? Wom­en are half the world, and ap­par­ent­ly we have been ex­clud­ing them, whether in­ten­tion­al­ly or not.

So, in prin­ci­ple, if adopt­ing a code of con­duct helps that, I am all for it. Same about gays, les­bian­s, tran­sex­u­al­s, etc. They are not 50% of the world, but they are about 10% of it, so it's a very large amount of peo­ple, and adding them to our groups is an­oth­er easy op­ti­miza­tion.

How­ev­er, it con­cerns me a bit that these codes of con­duct con­tain lan­guage like this:

Ha­rass­ment in­cludes of­fen­sive ver­bal com­ments re­lat­ed to gen­der, sex­u­al ori­en­ta­tion, dis­abil­i­ty, phys­i­cal ap­pear­ance, body size, race, re­li­gion, sex­u­al im­ages in pub­lic spaces, de­lib­er­ate in­tim­i­da­tion, stalk­ing, fol­low­ing, unau­tho­rized or in­ap­pro­pri­ate pho­tog­ra­phy or record­ing, sus­tained dis­rup­tion of talks or oth­er events, in­ap­pro­pri­ate phys­i­cal con­tac­t, and un­wel­come sex­u­al at­ten­tion.

Some are com­plete­ly ob­vi­ous, peo­ple who dis­rupt the speak­ers at con­fer­ences are to be thrown out, in­tim­i­da­tion is abom­inable, stalk­ing is creep­y, etc. But "of­fen­sive ver­bal com­ments re­lat­ed to [ev­ery­thing]"?

And here, I have to make a small de­tour and talk about street sign­s. When I vis­it­ed Lon­don, one thing that called my at­ten­tion was the lan­guage in street sign­s. Here's an ex­am­ple:

In oth­er coun­tries it would say "No dogs", would­n't it?

So, why do they have signs like this? It's prob­a­bly be­cause they are very po­lite peo­ple. Al­so, it may be be­cause of­fen­sive signs are pun­ish­able by jail.

I have a com­plete­ly un­found­ed sus­pi­cion that the po­lite­ness came first, and then came the right not to be of­fend­ed, which end­ed en­cod­ed in­to law, and now you just have to be po­lite, or else.

I am quite loud­ly athe­ist, yet I on­ly men­tion it out­side this blog if some­one men­tions his re­li­gion. So, for ex­am­ple, if some­one says "god asks less and yet he for­gives", I may say "that's be­cause he does­n't ex­ist", as a joke. I am now as­sum­ing that say­ing that in a con­fer­ence with that kind of code of con­duct is go­ing to be con­sid­ered of­fen­sive be­hav­iour. And let's say I am ok with that, I can still go for a few hours with­out of­fend­ing peo­ple. Have not tried it late­ly, but I am sure I can do it.

And I know that at a pri­vate even­t, like a con­fer­ence, there is no in­her­ent free­dom of speech, be­cause there is the right of ad­mis­sion, and I can just be kicked out with­out any ex­pla­na­tion, and I am al­so fine with that, be­cause I re­serve the right to kick peo­ple out of my own home, too.

So, sure, let's keep re­li­gion out of it. It has no place in a tech­ni­cal con­fer­ence one way or an­oth­er, and in any case, I will wear my in­vis­i­ble pink uni­corn shirt as an out­ward sign of my athe­ism (it looks just like a gray v-­neck t-shirt).

And I am to­tal­ly fine about not mock­ing or ha­rass­ing peo­ple be­cause of their gen­der or sex­u­al pref­er­ences. I am old and pro­vin­cial enough that when two men start kiss­ing next to me, I feel awk­ward. Luck­i­ly, I am enough of an adult that I just think to my­self, "dude, you are a pro­vin­cial prude" and look the oth­er way. Af­ter al­l, I have seen peo­ple take ex­cep­tion to me kiss­ing my wife in pub­lic, so, live and let live, what­ev­er. I like wom­en, my wife likes men, so I can un­der­stand you lik­ing ei­ther.

On the oth­er hand, I un­der­stand that the mere ex­is­tence and pres­ence of some peo­ple can be of­fen­sive to oth­er­s. I know peo­ple who would rather stand for 2 hours than sit next to a tran­sex­u­al. Or would rather get off the bus in­stead of be­ing there. And I am enough of an old, pro­vin­cial prude that I un­der­stand them. So, of­fend­ing is not the thing here, be­cause if of­fend­ing is the thing, then the mere pres­ence of some­one can of­fend oth­er­s, and that's the ex­act op­po­site of what we wan­t. We want them to ei­ther not be of­fend­ed, or be of­fend­ed and get over it, or be of­fend­ed and not care.

So, hand­ing out in­vi­ta­tions to three­somes to peo­ple in hall­ways is a bit too much (I nev­er in­vite peo­ple to three­somes be­fore the fourth date, it is gauche). Hit­ting on peo­ple in bars at night is prob­a­bly not too bad, un­less it's a con­stant thing that ru­ins the night for some­one (what do I know, I have nev­er hit on some­one or been hit on in a bar. Ex­cept by oth­er men. Just my luck­!) in which case I ex­pect a group of nice peo­ple to form a pro­tec­tive ring around the poor per­son who is just too at­trac­tive? (a­gain, what do I know, I have nev­er been atrac­tive).

The thing we want is po­lite­ness. We want to be nice to each oth­er. We want ev­ery­one to be as nice as they pos­si­bly can to as many peo­ple as they can. Spe­cial­ly, we want ev­ery­one to be ex­treme­ly nice to the peo­ple they like the least. Be­cause with peo­ple you get along with, you can do crazy stuff you can't do with oth­er­s.

On the oth­er hand, I sus­pect there is some­thing else here I am miss­ing. Be­cause tol­er­ance and re­spect is just not my thing. I am all for pros­eli­tiz­ing and dis­re­spec­t, for cre­ative an­noy­ance and push­ing peo­ple out­side their com­fort zones. But I try not to do it per­son­al­ly, I try to throw things to the crowd and see what they do with them.

I mean, I have been pho­tographed with­out my con­sen­t. I have even had my shirt scanned with­out ask­ing per­mis­sion (ok, I ad­mit hav­ing a QR code in a shirt is sort of an im­plic­it agree­men­t), I have been called names, but I know that, in the words of a sci­fi writer, I live life in the low dif­fi­cul­ty set­ting, be­cause I am a rather healthy white het­ero­sex­u­al male born in mid­dle class with a job, so again, I don't quite know what it's like to be in­sane­ly at­trac­tive, or gay, or in­sane­ly at­trac­tive to gays, or any­thing. I am not ha­rass­able. My face pro­tects me. I know oth­ers don't have such pow­er­ful de­fens­es.

So, while that kind of lan­guage does fill me with trep­i­da­tion, and makes me won­der what kind of com­mu­ni­ty I have been liv­ing in, obliv­i­ous to all these things I read about late­ly, I will ac­cept those codes and try to fol­low them. I have nev­er in­ten­tion­al­ly bro­ken them, even be­fore they ex­ist­ed (I did once take an in­ap­pro­pri­ate pic­ture, it was a joke, I on­ly showed it to one per­son, and I delet­ed it, and I re­al­ly am sor­ry and would not do it again, ok?)

So, I hope to see a lot of peo­ple I don't know in the next free soft­ware events I at­tend. Hope­ful­ly I will not of­fend any of them in a bad way. I will not be too brash. I will try to be in­clu­sive. I will try to be nice. But re­mem­ber. If I am very, very nice to you, it may be be­cause I can't stand you. You're wel­come.

Nikola 3.0.1 Available for Testing

Ver­sion 3.0.1 of Niko­la my stat­ic site gen­er­a­tor is ready for ini­tial us­er test­ing.

I have merged a bunch of patch­es from Kay Hayen and Kade­for:

  • dis­­qus_de­vel­op­er is gone

  • ad­dthis but­­tons are op­­tion­al (con­trolled by a new op­­tion)

  • You can have more than one stat­ic files fold­er to be merged in­­­to out­­put.

  • Im­age gal­­leries sup­­port up­­per­­case ex­ten­­sion­s.

  • Tem­­plates can not link to CSS that is em­p­­ty/mis­s­ing

  • Bet­ter Google Sitemaps

  • Pre­serve (some) meta­­da­­ta when copy­­ing files, like time­s­tamps

  • Don't over­write ex­ist­ing posts with doit new_­­post

  • Gen­er­ate valid URLs from uni­­code ti­­tles

So, if you want to try it out:


I will make it a re­al re­lease if noth­ing bad shows up be­fore sun­day or mon­day.

Contents © 2000-2023 Roberto Alsina