Ir al contenido principal

Ralsina.Me — El sitio web de Roberto Alsina

De Vicenzo: un mini browser más copado

Si no que­rés leer eso de nue­vo, la idea es ver cuán­to có­di­go fal­ta pa­ra con­ver­tir el mo­tor We­bKit de Qt en un bro­w­ser "en se­rio­".

Pa­ra ello, me pu­se una me­ta com­ple­ta­men­te ar­bi­tra­ria de 128 lí­neas de có­di­go. En es­te mo­men­to lo de­cla­ro fea­tu­re-­com­ple­te (pe­ro bu­gg­y).

Los nue­vos fea­tu­res so­n:

  • Ta­­bbed bro­­w­­sing (se pue­­de agre­­ga­­r/s­a­­car ta­bs)

  • Book­­ma­­rks (se pue­­den agre­­ga­­r/s­a­­car y ele­­gir de una lis­­ta)

Es­to es lo que ya fun­cio­na­ba:

  • Zoom in (C­­tr­­l++)

  • Zoom out (C­­tr­­l+-)

  • Re­set Zoom (C­­tr­­l+=)

  • Bus­­car (C­­tr­­l+­­F)

  • Es­­co­n­­der bús­­que­­da (Es­­c)

  • Bo­­­to­­­nes de atrá­s/a­­de­­lan­­te y re­­ca­r­­gar

  • En­­tra­­da de URL que coi­n­­ci­­de con la pá­­gi­­na + au­­to­­­co­m­­ple­­ta­­do des­­de la his­­to­­­ria + arre­­gla la URL pues­­ta a ma­no (a­­gre­­ga http://, esas co­­sas)

  • Plu­­gins (i­n­­cluí­­do fla­s­h, que hay que ba­­jar apa­r­­te ;-)

  • El tí­­tu­­lo de la ven­­ta­­na mues­­tra el tí­­tu­­lo de la pá­­gi­­na (sin pro­­­pa­­gan­­da del bro­­w­se­­r)

  • Ba­­rra de pro­­­gre­­so pa­­ra la ca­r­­ga de la pá­­gi­­na

  • Ba­­rra de es­­ta­­do que mues­­tra el des­­tino de los li­nks cuan­­do pa­sas el mou­­se

  • To­­­ma una URL en la lí­­nea de co­­­man­­do (o abre http://­­p­­y­­tho­­

  • Mu­l­­ti­­pla­­ta­­fo­r­­ma (fun­­cio­­­na do­n­­de fun­­cio­­­na QtWe­­bKi­­t)

Y cuan­to có­di­go es eso? 87 LI­NEAS.

O si pre­fe­rís la ver­sión que cum­ple con la PE­P8: 115 LI­NEAS.

Me ata­jo an­tes que al­guien lo di­ga: sí, el mo­tor de ren­de­ring y el toolkit son enor­mes. Lo que es­cri­bí es el "ch­ro­me" al­re­de­dor de eso, igual que ha­cen Aro­ra, Rekon­q, Ga­leo­n, Epi­phan­y, y mu­chos otros bro­w­ser­s.

Es un ch­ro­me sim­ple y mi­ni­ma­lis­ta, pe­ro fun­cio­na bas­tan­te bien, creo yo.

Aquí es­tá el de­mo (bu­gg­y):

Mas o me­nos ha­ce lo que es­pe­ra­ba que se pue­die­ra lo­gra­r, pe­ro le fal­tan arre­glo­s.

Pa­ra ver el có­di­go, va­yan a su ho­me pa­ge: http://­de­vi­cen­zo­.­google­co­de.­com

El Barto / 2011-03-06 03:55:

Why Ctrl+= for Reset Zoom instead of Ctrl+0 like in every other browser? :-)

Roberto Alsina / 2011-03-06 11:03:

Good question :-)

Rodney Dawes / 2011-03-06 04:20:

You didn't write plug-in support. In fact, I did a lot of it. :)
Setting the WebSettings plugins_enabled to True doesn't count as a feature.

Does your URL entry autocomplete from bookmarks? Is it smart, or is it just dumb default Entry autocomplete behavior? Printing? Cookies? Keyring?

Roberto Alsina / 2011-03-06 11:07:

It completes from the WebView's URL history, so no, not default autocomplete behaviour . Right now it's buggy in that it completes only from that tab's history, but that's easy to fix, same as adding the bookmarks to the completer.
Having it complete from the web page titles is trickier.

Update: now there is a global autocompleter that also includes the bookmarks. It could be made much smarter, matching somewhere else than at the beginning of URLs, matching titles, etc, by reimplementing QStringListModel.match() but that's boring ;-)

Of course I know I did not write plug-in support, I did not claim I did either! (I am getting tired of everyone thinking they are clever by figuring out that I am using WebKit, really ;-)

Printing? Who prints things anymore? Niche feature!

It has cookies, but doesn't persiste them between sessions (should be doable).

It has no keyring support.

Rodney Dawes / 2011-03-06 15:06:

Well you are listing plug-in support as a feature amidst the other ones you did write. So it sort of implies that you are doing something special for it.

And people print things. Especially after checking in for a flight. Also, I always print receipts to PDF.

And persistent cookies is quite important. As is keyring password saving.

The only real way you're goign to get a totally feature full modern browser in 128 lines of Python, is if you do all the UI in JavaScript instead. :)

Roberto Alsina / 2011-03-06 15:13:

I specifically called that list "things that work", not "things I wrote". I don't see Safari or Chrome saying they don't have HTML4 rendering because that was already in KHTML before it was forked ;-)

I could implement printing the page to PDF in ... ok, maybe 10 more lines, and maybe another 15 for persistent cookies, so both are doable within the constraints. I will see if I have a moment later today :-)
updated: I added print to image, print to PDF is more or less the same.

Keyring support seems to be much more difficult.

Ramiro Algozino / 2011-03-06 15:37:

Chrome/mium didn't have printing support for a while.. soo.. ;-)

Roberto Alsina / 2011-03-06 16:14:

I seriously underestimated Qt. Full print support is done, including previewing and printing to PDF: 2 lines ;-)

Roberto Alsina / 2011-03-06 21:25:

Full printing support (PDFs and real printers) and persistent cookies are now on SVN. They added about 10 lines of code :-)

Diego Sarmentero / 2011-03-06 10:45:

Yo hace un tiempo había hecho un navegador web en Python+PyQt en 60 lineas, que tenia un par de cosas igual, por ahí podrías agregarle que cuando escribas palabras sueltas (que no tengan forma de url) en la barra de navegación, te haga la búsqueda en google derecho como hace chrome, acá tendrías ese código:

Y está es la versión que yo había hecho, esta el código tanto para C++ y Python:



Contents © 2000-2023 Roberto Alsina