Ir al contenido principal

Ralsina.Me — El sitio web de Roberto Alsina

Publicaciones sobre python (publicaciones antiguas, página 66)

Diálogo de progreso muy pythónico

Este es un ejemplo que te muestra suficiente para usar progressbar:

progress = ProgressBar()
for i in progress(range(80)):
    time.sleep(0.01)

Sí, eso es to­do, te­nés una lin­da ba­rra de pro­gre­so AS­CII que cru­za la ter­mi­na­l, so­por­ta que la cam­bies de ta­ma­ño y se mue­ve mien­tras ite­rás de 0 a 79.

El módulo progressbar incluso tiene cosas mejores como ETA o velocidades de transferencia, y todo es así de fácil.

¿E­se có­di­go­... no es­tá bue­no? ¿Que­rés una ba­rra de pro­gre­so pa­ra ese lo­op? ¡Lo "en­vol­vé­s" y lis­to! Y por su­pues­to, co­mo yo pro­gra­mo con Py­Q­t, quie­ro que Py­Qt ten­ga al­go igual de bue­no.

Así se ve el re­sul­ta­do:

progress

Es­to lo po­dés ha­cer con cual­quier toolki­t, y pro­ba­ble­men­te de­be­ría­s. Tie­ne un fea­tu­re ex­tra: po­dés in­te­rrum­pir la ite­ra­ció­n, y es­te es el (po­co) có­di­go:

# -*- coding: utf-8 -*-
import sys, time
from PyQt4 import QtCore, QtGui

def progress(data, *args):
    it=iter(data)
    widget = QtGui.QProgressDialog(*args+(0,it.__length_hint__()))
    c=0
    for v in it:
        QtCore.QCoreApplication.instance().processEvents()
        if widget.wasCanceled():
            raise StopIteration
        c+=1
        widget.setValue(c)
        yield(v)

if __name__ == "__main__":
    app = QtGui.QApplication(sys.argv)

    # Do something slow
    for x in progress(xrange(50),"Show Progress", "Stop the madness!"):
        time.sleep(.2)

Di­viér­tan­se!

Salió el primer número de PET en inglés!


He­ll yeah! It has been a lot of wo­rk but it's out at http://­re­vis­ta.­p­y­tho­n.or­g.ar

So­me arti­cle­s:

  • PyA­­r, The His­­to­­­ry

  • from gc im­­port co­­­m­­mo­n­sen­­se - Fi­­nish Hi­­m!

  • Pai­n­­le­ss Co­n­­cu­­rren­­c­­y: The mu­l­­ti­­pro­­­ce­s­­sing Mo­­­du­­le

  • In­­tro­­­du­c­­tion to Unit Tes­­ting wi­­th Py­­thon

  • Taint Mo­­­de in Py­­thon

  • Applied Dy­­na­­mism

  • De­­co­­­ra­­ting co­­­de (Part 1)

  • We­­b2­­Py for Eve­­r­­y­­body

It's avai­la­ble in pre­tty mu­ch eve­ry for­mat an­yo­ne can rea­d, and if your fa­vou­ri­te is not the­re, we wi­ll make it for you or may I be smo­te by the fl­ying spa­ghe­tti mons­te­r's nood­ly appen­da­ge!

AFAIK the­re is no other Py­thon ma­ga­zi­ne being pu­blis­hed (feel free to co­rrect me), so it's kind of a big thing for us in PyAr (the Ar­gen­ti­na Py­thon co­m­mu­ni­ty) that we are doing one, and in two lan­gua­ges.

But why stop he­re? Want it to be avai­la­ble in your lan­gua­ge? Con­tact us at re­vis­ta­p­ya­r@­ne­t­ma­na­ger­s.­co­m.ar it may be doa­ble!

And of cour­se, ve­ry soon the­re wi­ll be a ca­ll for arti­cles for Is­sue 2, and trust me: that one's going to be epic: this one was just a war­mu­p.

Making deployment of desktop Python apps trivial: an idea

Di­ce google que di­ce es­to.

Proprietor and printer in front of Schwartz Print Shop in Minneapolis

He­re's what I'm thi­nkin­g: how hard could it be to make Py­Qt app de­plo­y­ment ab­so­lu­te­ly ea­s­y? We­ll, I am gues­sin­g: not ve­ry har­d.

He­re's the tri­ck: see what wo­rks in the real worl­d, and adopt it.

Ques­tio­n: what has de­plo­yed bi­llions of apps and has its users ha­pp­y? An­swe­r: pho­nes app sto­res.

Ques­tio­n: how do they wo­rk? An­swe­r: we­ll, tha­t's not that shor­t, so le­t's start ex­plai­nin­g.

As I see it, a rea­so­na­ble app sto­re has the fo­llo­wing com­po­nen­ts:

A Stable Deployment Target

You can't de­ploy from the sto­re if you do­n't know what you are de­plo­ying in­to. If the tar­get pla­tform is shak­y, you just can't know how to de­ploy wi­thout user as­sis­tan­ce, and we are tr­ying to make this ea­sy for the use­r, whi­ch means tha­t's not ac­cep­ta­ble.

So, wha­t's a sta­ble de­plo­y­ment tar­get we can pro­vi­de?

  • Py­­Qt (so we can de­­ploy GUIs to all ma­­jor desk­­top pla­­tfo­r­­ms)

  • Py­­thon stan­­dard li­­bra­­ry

  • Se­­le­c­ted mo­­­du­­les

What can be (and should be) bund­led wi­th the app?

  • Pu­­re py­­thon mo­­­du­­les

  • Ar­­two­­­rk and other re­­sou­r­­ces

What may be bund­le­d:

  • Py­­thon mo­­­du­­les wri­­tten in C/­­C++, but you then ha­­ve to re­­do the app for ea­­ch pla­­tfo­r­­m, and that ki­n­­da su­­cks.

Deployment Services

  • Apps should be able to che­­ck if the­­re is a new ve­r­­sion of them in the sto­­­re, to ask for upgra­­des.

  • Apps should be added by the de­­plo­­­y­­ment pla­­tform ni­­ce­­ly in­­to the host sys­­te­­m's me­­nus, desk­­to­­­p, etc.

Monetization Services

  • So­­­me way to cha­r­­ge for app­s. Even for open sou­r­­ce app­s, you could ask for U$S0.99 if you in­s­­ta­­ll them th­­rou­­gh the sto­­­re. Op­­tio­­­na­­l, of cou­r­se, and up to the app ow­­ne­­r.

  • Ad pla­­tfo­r­­m? The­­re must be a good one for desk­­top apps so­­­mewhe­­re?

The Store Itself

  • A we­b­­si­­te that do­­wn­­loads a "pa­­cka­­ge" as­­so­­­ciated wi­­th a lo­­­cal de­­plo­­­y­­ment appli­­ca­­tio­­n.

  • A app sto­­­re app. In­s­­ta­­ll things not via we­­b, but via a desk­­top appli­­ca­­tio­­n.

I do­n't ex­pect a func­tio­nal ver­sion of this would take me mo­re than a week wo­rking fu­ll­ti­me to im­ple­men­t. Of cour­se then the­re are all sor­ts of usa­bi­li­ty, looks, etc. things to con­si­de­r.

An­d... I am going to do so­me­thing I ve­ry ra­re­ly do. I am going to ask for mo­ne­y.

As an ex­pe­ri­men­t, I ha­ve se­tup a pro­ject at http://www.in­die­go­go­.­co­m/­Q­t-S­hop and set a fun­ding goal of U$S 600.

The­re you can fund me. I pro­mi­se that if the pro­ject is to­ta­lly fun­de­d, I wi­ll de­li­ve­r. If it is­n'­t, I may de­li­ver an­ywa­y. I would pre­fer to ha­ve the mo­ney thou­gh.

The pla­tform would be re­lea­sed un­der GPL­v2 or la­te­r.

Por qué estamos acá.

Ayer el go­bierno ar­gen­tino anun­ció que van a re­ga­lar 3 mi­llo­nes de ne­tbooks a es­tu­dian­tes. Tam­bién anun­cia­ron que les van a dar la op­ción de Ubun­tu o Win­do­ws 7.

Por su­pues­to al ra­to em­pe­zó a cir­cu­lar la tí­pi­ca reac­ción del la­do FLO­SS: ¿por qué les dan Win­do­ws si Li­nux es me­jo­r? ¡Es injus­to que el go­bierno pa­gue Win­do­ws!

Mi mi­sión hoy es de­cir­les que crez­can y de­jen de ac­tuar co­mo ne­nes. Es­toy acá pa­ra de­cir­les que pa­ren de tra­tar a los de­más co­mo be­bé­s.

Creo que lo pue­do ha­cer por­que es­toy in­mu­ni­za­do contra las crí­ti­cas de la co­mu­ni­dad FLO­SS: soy miem­bro. Ten­go un his­to­rial bas­tan­te lin­do con el so­ftwa­re li­bre y open sour­ce, no uso na­da ex­cep­to Li­nux ha­ce 15 año­s.

Y ten­go la piel grue­sa y no me im­por­ta lo que di­gan los de­más a me­nos que me den mo­ti­vos y ra­zo­nes pa­ra que me im­por­te.

Ven­go a de­cir­les que si el úni­co mo­ti­vo pa­ra usar un so­ftwa­re es que es el más ba­ra­to, es­tás di­cien­do que ese so­ftwa­re es ma­lo.

No só­lo quie­ro que la gen­te use Li­nu­x, quie­ro que quie­ran usar­lo. Quie­ro que es­pe­ren an­sio­sos la si­guien­te ver­sión de Ubun­tu o Fi­re­fox o lo que sea.

Y el pri­mer pa­so ha­cia la ex­ce­len­cia es que­rer ser ex­ce­len­te. Si al no te­ner que pa­gar por Win­do­ws ni Ubun­tu es­ta­mos se­gu­ros que ga­na Win­do­ws, en­ton­ces Ubun­tu tie­ne pro­ble­mas y hay que arre­glar­lo­s. ¿La gen­te no lo quie­re ni gra­tis? En­ton­ces hay pro­ble­mas y en­con­trar­los es im­por­tan­te.

Pe­ro más im­por­tan­te que en­con­trar la pie­za que fal­ta es ver el agu­je­ro don­de de­be­ría es­tar esa pie­za. La co­mu­ni­dad Open Sour­ce se ha vuel­to com­pla­cien­te. Se ha vuel­to pa­ga­da de sí mis­ma, es un ado­les­cen­te, se­gu­ro de su gran­de­za e in­mor­ta­li­da­d.

Yo no creo en mu­chas co­sas, pe­ro creo en el li­bre al­be­drío. Creo que la gen­te no es idio­ta, creo que si pre­fie­ren Win­do­ws, es por al­go, hay al­go que ha­ce me­jo­r, y creo que sea lo que sea eso (que no lo co­noz­co­), se pue­de en­con­trar y me­jo­rar y reem­pla­za­r, y su­ma­do a otras co­sas va a lo­grar que sea el me­jor pro­duc­to y creo que la gen­te va a que­rer usar­lo.

Y si no lo ha­cen... bue­no, se dió una pe­lea ho­nes­ta, hi­ci­mos lo me­jor que pu­di­mo­s, abri­mos ca­mi­no­s, crea­mos co­sas in­te­re­san­tes, y los usua­rios es­tán me­jor que an­tes aún si no eli­gie­ron a nues­tro be­bé, por­que le­van­ta­mos el ni­vel ge­ne­ra­l.

Por ejem­plo, an­tes de Li­nu­x, Win­do­ws era una ba­zo­fia mu­cho peo­r, y creo que mu­chas de las me­jo­ras que tu­vo fue­ron gra­cias a Li­nux, y es­toy fe­liz que los usua­rios hoy ten­gan un sis­te­ma ope­ra­ti­vo más de­cen­te, aun­que no sea Li­nu­x.

Quie­ro que la gen­te use open sour­ce por­que es asom­bro­so, no por­que es ba­ra­to. Asom­bro­so y ba­ra­to es­tá bien. ¿Só­lo ba­ra­to? Es una mier­da.

Ya que es­ta­mo­s: ¿el cons­tan­te "u­san Win­do­ws por­que no tie­nen idea"? Es con­des­cen­dien­te y mu­y, muy mo­les­to. Y si me moes­ta a mí, que no soy el blan­co de la con­des­cen­den­cia, créan­me, mo­les­ta mu­cho más a los usua­rios de Win­do­ws, y mo­les­tar a la gen­te no la con­ven­ce de na­da, ex­cep­to de que sos mo­les­to.

Crez­can, mé­tan­le pa­ra ade­lan­te, em­pie­cen a ha­cer co­sas asom­bro­sas, mues­tren ca­li­da­d. Pa­ra eso es­ta­mos acá, no pa­ra ser la se­gun­da mar­ca de otro, no pa­ra ser la Go­liat co­la.

Goodreads+webcam+python+zbar == hackfun!

Leo mu­cho, y me gus­ta que pue­do ver las opi­nio­nes de otra gen­te an­tes de em­pe­zar un li­bro, y pue­do po­ner co­men­ta­rio­s, y que an­du­ve le­yen­do, y otras co­sas.

De he­cho, goodrea­ds va a ser una par­te im­por­tan­te de un pro­yec­to que es­ta­mos em­pe­zan­do con gen­te de PyA­r.

Una co­sa que no ven­go ha­cien­do es agre­gar los li­bros que ten­go en goodrea­d­s, por­que es mu­cho la­bu­ro.

Bue­no, ya no tan­to!

Así se ha­ce, al es­ti­lo ha­cke­r...

  1. In­s­­ta­­lá zbar

  2. Co­n­se­­gui­­te una we­­b­­cam ba­­ra­­ta

  3. Aga­­rrá un li­­bro

  4. Un pro­­­gra­­mi­­ta py­­thon de 7 lí­­neas (ver aba­­jo)

Y mi­rá el vi­deo­...

¿No es lin­do?

El pro­gra­ma:

import os

p=os.popen('/usr/bin/zbarcam','r')
while True:
    code = p.readline()
    print 'Got barcode:', code
    isbn = code.split(':')[1]
    os.system('chromium http://www.goodreads.com/search/search?q=%s'%isbn)

Contents © 2000-2023 Roberto Alsina