fastpatx

By PATX on Jul 15, 2009

fastpatx version codename fawn
new features by patx & azazel

OLDER VERSIONS ARE AT HTTP://BITBUCKET.ORG/PATX/FASTPATX!!!!!!!

what you need to run:
1 buzhug -- http://buzhug.sf.net
2 pyqt4 -- apt-get install python-qt4
3 wget -- comes with ubuntu. windows, mac > google it.

what you need to do to run:
1 Unzip fastpatx-fawn.zip
2 $ python fastpatx-fawn.py

where to get the code:
1 http://bitbucket.org/patx/fastpatx/downloads/fastpatx-fawn.zip
2 $ wget http://bitbucket.org/patx/fastpatx/downloads/fastpatx-fawn.zip
3 $ hg clone http://bitbucket.org/patx/fastpatx

where to report bugs:
1 http://bitbucket.org/patx/fastpatx/issues

#!/usr/bin/env python
'''
Copyright (c) 2009 Harrison Erd

This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
arising from the use of this software.

Permission is granted to anyone to use this software for any purpose,
including commercial applications, and to alter it and redistribute it
freely, subject to the following restrictions:

    1. The origin of this software must not be misrepresented; you must not
    claim that you wrote the original software. If you use this software
    in a product, an acknowledgment in the product documentation would be
    appreciated but is not required.

    2. Altered source versions must be plainly marked as such, and must not be
    misrepresented as being the original software.

    3. This notice may not be removed or altered from any source
    distribution.
'''
# by patx | driver rowinggolfer 
# version fawn (alpha) | zlib license
# patx44.appspot.com/fastpatx
# other helpers azazel, trsh, 
# and people from #pyqt on freenode.

import sys
import time
import subprocess
from buzhug import Base
from PyQt4 import QtCore, QtGui
from PyQt4 import QtWebKit

class fastpatx(QtGui.QWidget):

    def bookmarksfun(self):
        bookread = open("faves/url", 'r')
        self.browser.setHtml(bookread.read())
        bookread.close()

    def bookmarkfun(self):
    link1 = '<a href="'
    link2 = '">%s</a> <br>'%self.lineEdit.text()
    bookurl = ("%s%s%s"%(link1,self.lineEdit.text(),link2)).encode('ascii')
    bookdb = Base('faves').create(('url',str),mode='open')
    bookdb.insert(url=bookurl)
    bookwn = QtGui.QMessageBox.question(self,"fastPATX",
        "The page has been bookmarked.",
        QtGui.QMessageBox.Ok)

    def viewSrc(self):
    html = self.browser.page().mainFrame().toHtml()
        dialog = QtGui.QDialog(self)
        text = QtGui.QPlainTextEdit(dialog)
        text.setPlainText(html)
        ok = QtGui.QPushButton(dialog)
        ok.setText('&Ok')
        ok.setDefault(True)
        self.connect(ok, QtCore.SIGNAL('clicked()'),
             dialog.accept)
        layout = QtGui.QVBoxLayout()
        layout.addWidget(text)
        layout.addWidget(ok)
        dialog.setLayout(layout)
        dialog.exec_()

    def goHome(self):
        self.browser.setUrl(QtCore.QUrl("http://www.google.com"))   

    def setCurl(self,url):
        self.curl=url
        self.urlString=url.toString()

    def GoLink(self):
        self.browser.load(self.curl)
        self.page=self.browser.page()
        self.page.setLinkDelegationPolicy(
        QtWebKit.QWebPage.DelegateAllLinks)

    def linkClicked(self,url):
        self.setCurl(url)
        self.GoLink()

    def loadStarted(self):
        print "loading page...",

    def loadFinished(self,arg):
        print "load finished...",
        if arg:
            print "sucess"
        else:
            print "failed"
            self.offerDownload()

    def offerDownload(self):
        result=QtGui.QMessageBox.question(self,"Download File",
        "download file <br />%s"%self.urlString,
        QtGui.QMessageBox.Yes,QtGui.QMessageBox.No)

        if result == QtGui.QMessageBox.Yes:
            p=subprocess.Popen(['wget',self.urlString])
            self.browser.setHtml("""
<h2>Downloading your file...</h2>
<hr>Powered by <a href="http://patx44.appspot.com/fastpatx">fastPATX</a>.
""")
            time.sleep(2)

    def lineEdited(self):
        self.setCurl(QtCore.QUrl(self.lineEdit.text()))
        self.GoLink()

    def updateLineEdit(self,url):
        self.setCurl(url)
        self.lineEdit.setText(self.curl.toString())

    def __init__(self):
        QtGui.QWidget.__init__(self)

        self.setCurl(QtCore.QUrl("http://www.google.com"))

        self.lineEdit = QtGui.QLineEdit()
        self.pushButton = QtGui.QPushButton('Go')
        self.homeButton = QtGui.QPushButton('Home')
    self.srcButton = QtGui.QPushButton('Source')
    self.bookmark = QtGui.QPushButton('Bookmark Page')
    self.bookmarks = QtGui.QPushButton('Your Bookmarks')
        self.browser = QtWebKit.QWebView()

        tab = QtGui.QGridLayout()
        tab.setSpacing(3)

        tab.addWidget(self.homeButton, 2, 5)
    tab.addWidget(self.bookmark, 2, 3)
    tab.addWidget(self.bookmarks, 2, 4)
    tab.addWidget(self.srcButton, 2, 2)
        tab.addWidget(self.browser, 1, 0, 1, 6)
        tab.addWidget(self.lineEdit, 2, 0)
        tab.addWidget(self.pushButton, 2, 1)

        self.setLayout(tab)
        self.setWindowTitle('fastPATX')

        self.connect(self.lineEdit, QtCore.SIGNAL('returnPressed()'),
            self.lineEdited)
        self.connect(self.pushButton, QtCore.SIGNAL('clicked()'),
            self.lineEdited)
    self.connect(self.homeButton, QtCore.SIGNAL('clicked()'),
        self.goHome)
    self.connect(self.srcButton, QtCore.SIGNAL('clicked()'),
        self.viewSrc)
    self.connect(self.bookmark, QtCore.SIGNAL('clicked()'),
        self.bookmarkfun)
        self.connect(self.browser, QtCore.SIGNAL('linkClicked (const QUrl&)'),
            self.linkClicked)
        self.connect(self.browser, QtCore.SIGNAL('urlChanged (const QUrl&)'),
            self.updateLineEdit)
        self.connect(self.browser, QtCore.SIGNAL('loadStarted ()'),
            self.loadStarted)
        self.connect(self.browser, QtCore.SIGNAL('loadFinished (bool)'),
            self.loadFinished)
    self.connect(self.bookmarks, QtCore.SIGNAL('clicked()'),
        self.bookmarksfun)

        self.GoLink()

app = QtGui.QApplication(sys.argv)

win = fastpatx()

win.show()

sys.exit(app.exec_())

Comments

Sign in to comment.
PATX   -  Sep 02, 2009

need somebody to py2app this for me?

 Respond  
PATX   -  Jul 20, 2009

ok.

 Respond  
Hawkee   -  Jul 18, 2009

It was coming up when the links ended with a /, for example the URL for this snippet, http://www.hawkee.com/snippet/6429/. Thanks for the tip on the right click, but I think you need a more obvious solution like a close button.

 Respond  
PATX   -  Jul 18, 2009

Yeah, I am still working out the bugs. The "download file" link however is very very very necessary however because that is the current substitute for a real download manager. If that box is coming up when you click on a link, then that it a bug :/ If you could, give me an example of what links. As for it crashing randomly the error Python is giving me is "Segmentation fault". I am having my driver take a look at this while I am adding tabs :) And the bookmarks thing, if you right click you will see a menu to go back.

Thanks for the feedback.

 Respond  
Hawkee   -  Jul 15, 2009

Neat little snippet, but I did have some issues. The "download file?" prompt is a bit unnecessary as it kept coming up when I'd enter a URL or click a link. Also, the bookmark screen needs an exit or close button to go back to the page. I went to Hawkee, bookmarked the homepage and couldn't close the bookmark screen, so I clicked the bookmark to return to the site and the app crashed. It also crashed randomly when clicking a link on this site. Nice example of how to do a basic Python GUI though.

 Respond  
PATX   -  Jul 15, 2009

tell me what you think?

 Respond  
Are you sure you want to unfollow this person?
Are you sure you want to delete this?
Click "Unsubscribe" to stop receiving notices pertaining to this post.
Click "Subscribe" to resume notices pertaining to this post.