De Vicenzo: un mini browser más copado
Si no querés leer eso de nuevo, la idea es ver cuánto código falta para convertir el motor WebKit de Qt en un browser "en serio".
Para ello, me puse una meta completamente arbitraria de 128 líneas de código. En este momento lo declaro feature-complete (pero buggy).
Los nuevos features son:
Tabbed browsing (se puede agregar/sacar tabs)
Bookmarks (se pueden agregar/sacar y elegir de una lista)
Esto es lo que ya funcionaba:
Zoom in (Ctrl++)
Zoom out (Ctrl+-)
Reset Zoom (Ctrl+=)
Buscar (Ctrl+F)
Esconder búsqueda (Esc)
Botones de atrás/adelante y recargar
Entrada de URL que coincide con la página + autocompletado desde la historia + arregla la URL puesta a mano (agrega http://, esas cosas)
Plugins (incluído flash, que hay que bajar aparte ;-)
El título de la ventana muestra el título de la página (sin propaganda del browser)
Barra de progreso para la carga de la página
Barra de estado que muestra el destino de los links cuando pasas el mouse
Toma una URL en la línea de comando (o abre http://python.org
Multiplataforma (funciona donde funciona QtWebKit)
Y cuanto código es eso? 87 LINEAS.
O si preferís la versión que cumple con la PEP8: 115 LINEAS.
Me atajo antes que alguien lo diga: sí, el motor de rendering y el toolkit son enormes. Lo que escribí es el "chrome" alrededor de eso, igual que hacen Arora, Rekonq, Galeon, Epiphany, y muchos otros browsers.
Es un chrome simple y minimalista, pero funciona bastante bien, creo yo.
Aquí está el demo (buggy):
Mas o menos hace lo que esperaba que se puediera lograr, pero le faltan arreglos.
Para ver el código, vayan a su home page: http://devicenzo.googlecode.com
Why Ctrl+= for Reset Zoom instead of Ctrl+0 like in every other browser? :-)
Good question :-)
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?
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.
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. :)
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.
Chrome/mium didn't have printing support for a while.. soo.. ;-)
I seriously underestimated Qt. Full print support is done, including previewing and printing to PDF: 2 lines ;-)
Full printing support (PDFs and real printers) and persistent cookies are now on SVN. They added about 10 lines of code :-)
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:
http://pastebin.com/y11LdrQU
Y está es la versión que yo había hecho, esta el código tanto para C++ y Python:
http://utopia555.blogspot.c...
Saludos!