Author Topic: Lets create a PCLinuxOS webkit browser (python)  (Read 28248 times)

Offline Sproggy

  • Hero Member
  • *****
  • Posts: 1484
Re: Lets create a PCLinuxOS webkit browser (python)
« Reply #120 on: April 01, 2011, 03:56:31 PM »
i have and it wont launch

Code: [Select]
[kori@localhost PCLinuxOS Hammer]$ ./PCLinuxOS-Hammer.py
Traceback (most recent call last):
  File "./PCLinuxOS-Hammer.py", line 17, in <module>
    import hammer_tab
ImportError: No module named hammer_tab
[kori@localhost PCLinuxOS Hammer]$

any ideas??

hammer_tab is a python module, so it should be in /usr/bin as hammer_tab.py. While a python script can be executed if the .py extension is not used, a python module must have the .py extension or python will not detect and use it.

From my post above:
Quote
Save this as hammer_tab.py to /usr/bin. Add import hammer_tab to line 17 of hammer...

Once you add that line (should be the last of the "import" lines), just click "save." Then launch hammer as you normally would.


Hi Neal ...

nope i still get this issue

Code: [Select]
Traceback (most recent call last):
  File "/usr/bin/pclinuxos-hammer.py", line 17, in <module>
    import hammer_tab
ImportError: No module named hammer_tab

This is the amendment i made to Hammer

Code: [Select]
import pygtk
pygtk.require('2.0')
import gtk
import pango
#you need to import webkit and gobject, gobject is needed for threads
import webkit
import gobject
import hammer_tab

and i have it saved with a .py extension

Kori





Offline Neal ManBear

  • Administrator
  • Super Villain
  • *****
  • Posts: 15847
  • LXDE! Coffee, Bacon and Cheesecake!
Re: Lets create a PCLinuxOS webkit browser (python)
« Reply #121 on: April 01, 2011, 03:57:13 PM »
Currently seeing how its possible to remove 'whitespace' ie 'spaces' and convert it to tabulation as it kills the script dead otherwise

I remember kwrite can convert spaces to tab - not seeing that in DrPython or the other gtk text editors I have tried so far

Jase

Maybe I'm tired, but you completely lost me here. ??? Are you saying that hammer_tabs has spaces that prevent its working?

Offline Neal ManBear

  • Administrator
  • Super Villain
  • *****
  • Posts: 15847
  • LXDE! Coffee, Bacon and Cheesecake!
Re: Lets create a PCLinuxOS webkit browser (python)
« Reply #122 on: April 01, 2011, 03:58:11 PM »
Kori,
Is hammer_tab.py marked as executable?

Offline Sproggy

  • Hero Member
  • *****
  • Posts: 1484
Re: Lets create a PCLinuxOS webkit browser (python)
« Reply #123 on: April 01, 2011, 03:58:56 PM »
Kori,
Is hammer_tab.py marked as executable?


yes Bud ... but it would help if i named it correctly lol ... guess it's getting late here and the tramadol is doing it's stuff lol
« Last Edit: April 01, 2011, 04:01:33 PM by Sproggy »

Offline Hootiegibbon

  • Hero Member
  • *****
  • Posts: 4151
Re: Lets create a PCLinuxOS webkit browser (python)
« Reply #124 on: April 01, 2011, 04:06:34 PM »
Currently seeing how its possible to remove 'whitespace' ie 'spaces' and convert it to tabulation as it kills the script dead otherwise

I remember kwrite can convert spaces to tab - not seeing that in DrPython or the other gtk text editors I have tried so far

Jase

Maybe I'm tired, but you completely lost me here. ??? Are you saying that hammer_tabs has spaces that prevent its working?



As I copy/pasted the indentations turned into spaces, that are read as ascii characters - which seems to mess with the script - nnd gives an error,
I am looking at a way to 'treat' the script by replacing the 'whitre space - in some editors the space bar marks are highlighted in white (!)  to convert them into tab marks ... Kwrite has that ability (highlihght all convert whitespave to tabs or similar, althogh i am not on a qt'ised system here atm

Jase


I am Hootiegibbon, undisputed champion fo the typo

My .dotfiles

Offline Neal ManBear

  • Administrator
  • Super Villain
  • *****
  • Posts: 15847
  • LXDE! Coffee, Bacon and Cheesecake!
Re: Lets create a PCLinuxOS webkit browser (python)
« Reply #125 on: April 01, 2011, 04:08:56 PM »
Kori,
Is hammer_tab.py marked as executable?

yes Bud ... but it would help if i named it correctly lol ... guess it's getting late here and the tramadol is doing it's stuff lol

LOL Typos happen. ;) :D

Offline Neal ManBear

  • Administrator
  • Super Villain
  • *****
  • Posts: 15847
  • LXDE! Coffee, Bacon and Cheesecake!
Re: Lets create a PCLinuxOS webkit browser (python)
« Reply #126 on: April 01, 2011, 04:14:35 PM »
Currently seeing how its possible to remove 'whitespace' ie 'spaces' and convert it to tabulation as it kills the script dead otherwise

I remember kwrite can convert spaces to tab - not seeing that in DrPython or the other gtk text editors I have tried so far

Jase


Maybe I'm tired, but you completely lost me here. ??? Are you saying that hammer_tabs has spaces that prevent its working?


As I copy/pasted the indentations turned into spaces, that are read as ascii characters - which seems to mess with the script - nnd gives an error,
I am looking at a way to 'treat' the script by replacing the 'whitre space - in some editors the space bar marks are highlighted in white (!)  to convert them into tab marks ... Kwrite has that ability (highlihght all convert whitespave to tabs or similar, althogh i am not on a qt'ised system here atm

Jase


I think I see. Hmm...... got an idea. ---
Try this:
http://nbrks.com/hammer/hammer_tab.py.tar.xz

Offline Sproggy

  • Hero Member
  • *****
  • Posts: 1484
Re: Lets create a PCLinuxOS webkit browser (python)
« Reply #127 on: April 01, 2011, 04:35:44 PM »
ok i have found a similar project which i do believe is dead now ... but the guy has made a browser with tabs and alot of other goodies heres the code

Code: [Select]
#!/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.

#  fastPATX by PATX | Driver: Neil Wallace
# Version Evergreen | Questions? patx44@gmail.com

import sys
import urllib
from PyQt4 import QtCore, QtGui, QtWebKit

class patx_tab(QtGui.QWidget):
   
    def __init__(self, index, parent=None):
        super(QtGui.QWidget, self).__init__(parent)
        self.mainUi = parent
        self.index = index
        print "making new tab with index",index
        self.browser = QtWebKit.QWebView(self)
        self.connect(self.browser, QtCore.SIGNAL('linkClicked (const QUrl&)'),
            self.updateLineEdit)
        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.current_url = QtCore.QUrl("http://www.google.com/")
        self.browser.setUrl(self.current_url)
        self.horizontalLayout = QtGui.QHBoxLayout(self)
        self.horizontalLayout.addWidget(self.browser)
       
    def GoLink(self, url):
        self.current_url = url
        self.browser.load(url)
        page = self.browser.page()
        page.setLinkDelegationPolicy(QtWebKit.QWebPage.DelegateAllLinks)
       
    def loadStarted(self):
        print "loading page...",

    def loadFinished(self,arg):
        print "load finished...",
        if arg:
            print "sucess"
            self.mainUi.tabWidget.setTabText(self.index, self.browser.title())
        else:
            print "failed"
            self.tellFailLoad()

    def updateLineEdit(self,url):
        self.current_url = url
        if self.index == self.mainUi.tabWidget.currentIndex():
            self.mainUi.updateLineEdit(url)

    def tellFailLoad(self):
        self.browser.setHtml('<p>This page could not be rendered/loaded.</p>')

class fastpatx(QtGui.QMainWindow):
    def __init__(self, parent=None):
        super(QtGui.QMainWindow, self).__init__(parent)
        self.resize(800, 600)
        centralwidget = QtGui.QWidget(self)
        self.toolbar = QtGui.QToolBar(centralwidget)
        self.lineEdit = QtGui.QLineEdit(centralwidget)
        self.GoButton = QtGui.QPushButton(centralwidget)
        self.tabWidget = QtGui.QTabWidget(centralwidget)
        self.tabWidget.setElideMode(QtCore.Qt.ElideRight)

        self.tb = self.tabWidget.tabBar()
        self.tb.hide()
        self.addNewTab()
        gridLayout = QtGui.QGridLayout(centralwidget)
        gridLayout.setObjectName("gridLayout")
        gridLayout.setSpacing(3)
        gridLayout.setContentsMargins(3,3,3,3)
        gridLayout.addWidget(self.toolbar, 0, 0, 1, 2)
        gridLayout.addWidget(self.tabWidget, 2, 0, 1, 2)
        gridLayout.addWidget(self.lineEdit, 1, 0, 1, 1)
        gridLayout.addWidget(self.GoButton, 1, 1, 1, 1)
       
        self.setCentralWidget(centralwidget)
        menubar = QtGui.QMenuBar(self)
        menubar.setGeometry(QtCore.QRect(0, 0, 800, 23))
        self.setMenuBar(menubar)
        self.statusbar = QtGui.QStatusBar(self)
        self.setStatusBar(self.statusbar)

        self.add_labels()

        self.homeButton = QtGui.QPushButton('Home')
        self.goBck = QtGui.QPushButton('Go Back')
        self.srcButton = QtGui.QPushButton('View Source')
        self.bookmark = QtGui.QPushButton('Bookmark Page')
        self.bookmarks = QtGui.QPushButton('Your Bookmarks')
        self.downloadb = QtGui.QPushButton('Download Page')
        self.addTabBtn = QtGui.QPushButton('New Tab')
        self.delTabBtn = QtGui.QPushButton('Close Tab')
        self.fpAbout = QtGui.QPushButton('About')
        self.goFwd = QtGui.QPushButton('Go Forward')

        self.toolbar.addWidget(self.homeButton)
        self.toolbar.addWidget(self.goBck)
        self.toolbar.addWidget(self.goFwd)
        self.toolbar.addWidget(self.bookmark)
        self.toolbar.addWidget(self.bookmarks)
        self.toolbar.addWidget(self.srcButton)
        self.toolbar.addWidget(self.downloadb)
        self.toolbar.addWidget(self.addTabBtn)
        self.toolbar.addWidget(self.delTabBtn)
        self.toolbar.addWidget(self.fpAbout)

        self.connect(self.lineEdit,
        QtCore.SIGNAL('returnPressed()'), self.lineEdited)

        self.connect(self.GoButton,
        QtCore.SIGNAL('clicked()'), self.lineEdited)

        self.connect(self.tabWidget,
        QtCore.SIGNAL('currentChanged(int)'), self.tabChanged)

        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.bookmarks, QtCore.SIGNAL('clicked()'),
            self.bookmarksfun)
        self.connect(self.downloadb, QtCore.SIGNAL('clicked()'),
            self.offerDownload)
        self.connect(self.addTabBtn, QtCore.SIGNAL('clicked()'),
            self.addNewTab)
        self.connect(self.delTabBtn, QtCore.SIGNAL('clicked()'),
            self.delOldTab)
        self.connect(self.goFwd, QtCore.SIGNAL('clicked()'),
            self.goForward)
        self.connect(self.goBck, QtCore.SIGNAL('clicked()'),
            self.goBack)
        self.connect(self.fpAbout, QtCore.SIGNAL('clicked()'),
            self.About)

    def goForward(self):
        self.currentBrowser().forward()

    def goBack(self):
        self.currentBrowser().back()

    def About(self):
        QtGui.QMessageBox.information(self, "fastPATX",'''
<p><a href="http://patx.me/fastpatx">fastPATX - Evergreen</a></p>
<p>Owner: Harrison Erd ([url=http://www.patx.me]www.patx.me[/url])</p>
<p>Driver: Neil Wallace (rowinggolfer.blogspot.com)</p>
<p>License: Zlib (http://patx.me/publications)</p>
<p>Current Version Codename: Evergreen</p>
        ''')

    def add_labels(self):
        self.setWindowTitle("fastPATX")
        self.GoButton.setText("Go")

    def currentBrowser(self):
        widget = self.tabWidget.currentWidget()
        if widget is not None:
            return widget.browser

    def addNewTab(self):
        i = self.renumberTabs()
        newtab = patx_tab(i, self)
        self.tabWidget.addTab(newtab, '(untitled)')
        self.tabWidget.setCurrentWidget(newtab)
        if self.tabWidget.count() > 1:
            self.tb.show()

    def renumberTabs(self):
        i = 0
        while i < self.tabWidget.count():
            self.tabWidget.widget(i).index = i
            i += 1
        return i

    def tabChanged(self, index):
        self.updateLineEdit(self.tabWidget.currentWidget().current_url)

    def delOldTab(self):
        if self.tabWidget.count() == 1:
            return
        widget = self.tabWidget.currentWidget()
        if widget is not None:
            self.tabWidget.removeTab(self.tabWidget.indexOf(widget))
            widget.deleteLater()
            if self.renumberTabs() < 2:
                self.tb.hide()
       
    def bookmarksfun(self):
        try:
           bookread = open("fastpatx_faves.txt", 'r')
           self.currentBrowser().setHtml(bookread.read())
           bookread.close()       
        except IOError, e:
           self.currentBrowser().setHtml("Favourites file not found.")
           
    def bookmarkfun(self):
        link1 = '<a href="'
        link2 = '">%s</a><br>'%self.lineEdit.text()
        bookurl = ("%s%s%s"%(link1,self.lineEdit.text(),link2)).encode('ascii')
        hpaste = open('fastpatx_faves.txt', 'a').write('%s'%(bookurl))
        bookwn = QtGui.QMessageBox.question(self,"fastPATX",
        "The page has been bookmarked.",
        QtGui.QMessageBox.Ok)

    def viewSrc(self):
        html = self.currentBrowser().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.currentBrowser().setUrl(QtCore.QUrl("http://www.google.com"))

    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:
            url = str(self.lineEdit.text())
            filename, headers = urllib.urlretrieve(url)
            print "Downloaded: %s - Location: %s" % (url, filename)
            QtGui.QMessageBox.information(self,"fastPATX",
            """
<title>Downloads</title> <h1>Downloading your file to %s...</h1><hr>
<h2>Info on fastPATX Downloads:</h2>
If you wish to view this file go to %s. If you wish to save the file
go to %s and save, otherwise when browser is exited, you will lose the
file.<hr>Powered by <a href="http://patx.me/projects">fastPATX</a>.
"""%(filename,filename,filename))
    def lineEdited(self):
        self.tabWidget.currentWidget().GoLink(QtCore.QUrl(self.lineEdit.text()))
    def updateLineEdit(self,url):
        self.lineEdit.setText(url.toString())

if __name__ == "__main__":
    app = QtGui.QApplication(sys.argv)
    ui = fastpatx()
    ui.show()
    sys.exit(app.exec_())

ive run it and it works well ... altho it uses QT dependencies ... im sure it will be a help to go forward with

Kori

Offline Neal ManBear

  • Administrator
  • Super Villain
  • *****
  • Posts: 15847
  • LXDE! Coffee, Bacon and Cheesecake!
Re: Lets create a PCLinuxOS webkit browser (python)
« Reply #128 on: April 01, 2011, 04:44:27 PM »
Interesting find, Kori. No tabs here. ??? Got tabs there?

Offline Sproggy

  • Hero Member
  • *****
  • Posts: 1484
Re: Lets create a PCLinuxOS webkit browser (python)
« Reply #129 on: April 01, 2011, 04:46:43 PM »
Interesting find, Kori. No tabs here. ??? Got tabs there?

i have tabs .... maximise the window .... you will see the extra buttons

Kori

Offline Neal ManBear

  • Administrator
  • Super Villain
  • *****
  • Posts: 15847
  • LXDE! Coffee, Bacon and Cheesecake!
Re: Lets create a PCLinuxOS webkit browser (python)
« Reply #130 on: April 01, 2011, 05:01:10 PM »
Thanks, Kori. :) I'll give it a good study and see what changes can be made to our code. :) :)

Offline Sproggy

  • Hero Member
  • *****
  • Posts: 1484
Re: Lets create a PCLinuxOS webkit browser (python)
« Reply #131 on: April 01, 2011, 05:05:24 PM »
Neal im sure you can chop this up to alter the code for Hammer to get it all working ... we have faith in you lolol

Offline Hootiegibbon

  • Hero Member
  • *****
  • Posts: 4151
Re: Lets create a PCLinuxOS webkit browser (python)
« Reply #132 on: April 01, 2011, 05:23:45 PM »
Sproggy,

It is a good find and i am sure Neal will do something with it, I will try it tomorrow on the Kids qt-infected AcerOne

lol

Jase



I am Hootiegibbon, undisputed champion fo the typo

My .dotfiles

Offline Neal ManBear

  • Administrator
  • Super Villain
  • *****
  • Posts: 15847
  • LXDE! Coffee, Bacon and Cheesecake!
Re: Lets create a PCLinuxOS webkit browser (python)
« Reply #133 on: April 01, 2011, 06:43:39 PM »
I hope I can do it, guys. I hope. But if any of you want to tackle it, please do. :)

Offline Mark342

  • Sr. Member
  • ****
  • Posts: 334
Re: Lets create a PCLinuxOS webkit browser (python)
« Reply #134 on: April 01, 2011, 09:15:11 PM »


Currently seeing how its possible to remove 'whitespace' ie 'spaces' and convert it to tabulation as it kills the script dead otherwise

I remember kwrite can convert spaces to tab - not seeing that in DrPython or the other gtk text editors I have tried so far

Jase
Code: [Select]
unexpand -t 4 filename > newfilenameShould work, for future reference.  ;)

Also, I had no idea you guys were making a web browser!
What a neat idea!
Good luck.  ;)
Anything worth doing is worth overdoing.

Registered Linux user #493318
Register yourself here: Linux Counter