Ir al contenido principal

Ralsina.Me — El sitio web de Roberto Alsina

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!

For the Win

Cover for For the Win

Review:

A re­al page turn­er. Tak­ing ad­van­tage of it be­ing CC, I think I may at­tempt trans­lat­ing it to span­ish (ar­gen­tini­an flavour)

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.

Fryupdale

Cover for Fryupdale

Review:

Some things were fun, but it's not my cup of tea.

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.


Contents © 2000-2024 Roberto Alsina