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

Offline Neal ManBear

  • Administrator
  • Super Villain
  • *****
  • Posts: 15847
  • LXDE! Coffee, Bacon and Cheesecake!
Re: Lets create a PCLinuxOS webkit browser (python)
« Reply #45 on: March 30, 2011, 01:08:31 AM »
For the menu entry:
Code: [Select]
[Desktop Entry]
Version=1.0
Name=PCLinuxOS Hammer
GenericName=PCLinuxOS Web Browser
Comment=Browse the Web
Exec=/usr/bin/PCLinuxOS_Hammer
Terminal=false
Type=Application
Categories=GTK;Network;WebBrowser;X-MandrivaLinux-Internet-WebBrowsers

No icon created - yet. :D

Offline Neal ManBear

  • Administrator
  • Super Villain
  • *****
  • Posts: 15847
  • LXDE! Coffee, Bacon and Cheesecake!
Re: Lets create a PCLinuxOS webkit browser (python)
« Reply #46 on: March 30, 2011, 01:12:48 AM »
Screenshot:


Offline Sproggy

  • Hero Member
  • *****
  • Posts: 1484
Re: Lets create a PCLinuxOS webkit browser (python)
« Reply #47 on: March 30, 2011, 01:24:40 AM »
Neal can you paste your code for this as my address bar is not next to my buttons ... im also thinking of the icon design ... something like the Thunar hammer layed on top of the PCLOS ring

Kori

Offline Sproggy

  • Hero Member
  • *****
  • Posts: 1484
Re: Lets create a PCLinuxOS webkit browser (python)
« Reply #48 on: March 30, 2011, 01:52:24 AM »
Ok here's the icon idea i have come up with so far ...





let me know what you think

Kori ;D ;D

PS. the hammer is just a stock hammer of the web ... all can be changed if need be ... as this is the draght and still a work in progress it can be altered at any time
« Last Edit: March 30, 2011, 02:02:39 AM by Sproggy »

Offline Neal ManBear

  • Administrator
  • Super Villain
  • *****
  • Posts: 15847
  • LXDE! Coffee, Bacon and Cheesecake!
Re: Lets create a PCLinuxOS webkit browser (python)
« Reply #49 on: March 30, 2011, 01:56:52 AM »
This the code you mean, Kori?
Code: [Select]
#!/usr/bin/env python
#
# [SNIPPET_NAME: Webkit Browser]
# [SNIPPET_CATEGORIES: Webkit, PyGTK]
# [SNIPPET_DESCRIPTION: Create a simple browser using the webkit API]
# [SNIPPET_AUTHOR: Andy Breiner <breinera@gmail.com>]
# [SNIPPET_LICENSE: GPL]
# [SNIPPET_DOCS: http://ardoris.wordpress.com/2009/04/26/a-browser-in-14-lines-using-python-and-webkit, http://www.aclevername.com/articles/python-webgui]

import pygtk
pygtk.require('2.0')
import gtk

#you need to import webkit and gobject, gobject is needed for threads
import webkit
import gobject

name = "PCLinuxOS Hammer"

class Browser:
    default_site = "http://www.pclinuxos.com"

    def delete_event(self, widget, event, data=None):
        return False

    def destroy(self, widget, data=None):
        gtk.main_quit()

    def __init__(self):
        gobject.threads_init()
        self.window = gtk.Window(gtk.WINDOW_TOPLEVEL)
        self.window.set_resizable(True)
        self.window.set_default_size(950, 900)
        self.window.connect("delete_event", self.delete_event)
        self.window.connect("destroy", self.destroy)

        #webkit.WebView allows us to embed a webkit browser
        #it takes care of going backwards/fowards/reloading
        #it even handles flash
        self.web_view = webkit.WebView()
        self.web_view.open(self.default_site)
        self.window.set_title('%s' % name)

        toolbar = gtk.Toolbar()

        #create the back button and connect the action to
        #allow us to go backwards using webkit
        self.back_button = gtk.ToolButton(gtk.STOCK_GO_BACK)
        self.back_button.connect("clicked", self.go_back)

        #same idea for forward button
        self.forward_button = gtk.ToolButton(gtk.STOCK_GO_FORWARD)
        self.forward_button.connect("clicked", self.go_forward)

        #again for refresh
        refresh_button = gtk.ToolButton(gtk.STOCK_REFRESH)
        refresh_button.connect("clicked", self.refresh)

        #add the buttons to the toolbar
        toolbar.add(self.back_button)
        toolbar.add(self.forward_button)
        toolbar.add(refresh_button)

        #entry bar for typing in and display URLs, when they type in a site
        #and hit enter the on_active function is called
        self.url_bar = gtk.Entry()
        self.url_bar.connect("activate", self.on_active)
        entry_tool = gtk.ToolItem()
        entry_tool.set_expand(True)
        entry_tool.add(self.url_bar)
        self.url_bar.show()

        #anytime a site is loaded the update_buttons will be called
        self.web_view.connect("load_committed", self.update_buttons)

        scroll_window = gtk.ScrolledWindow(None, None)
        scroll_window.add(self.web_view)

        vbox = gtk.VBox(False, 0)
        vbox.pack_start(toolbar, False, True, 0)
        vbox.pack_start(self.url_bar, False, True, 0)
        vbox.add(scroll_window)

        self.window.add(vbox)
        self.window.show_all()

    def on_active(self, widge, data=None):
        '''When the user enters an address in the bar, we check to make
           sure they added the http://, if not we add it for them.  Once
           the url is correct, we just ask webkit to open that site.'''
        url = self.url_bar.get_text()
        try:
            url.index("://")
        except:
            url = "http://"+url
        self.url_bar.set_text(url)
        self.web_view.open(url)

    def go_back(self, widget, data=None):
        '''Webkit will remember the links and this will allow us to go
           backwards.'''
        self.web_view.go_back()

    def go_forward(self, widget, data=None):
        '''Webkit will remember the links and this will allow us to go
           forwards.'''
        self.web_view.go_forward()

    def refresh(self, widget, data=None):
        '''Simple makes webkit reload the current back.'''
        self.web_view.reload()

    def update_buttons(self, widget, data=None):
        '''Gets the current url entry and puts that into the url bar.
           It then checks to see if we can go back, if we can it makes the
           back button clickable.  Then it does the same for the foward
           button.'''
        self.url_bar.set_text( widget.get_main_frame().get_uri() )
        self.back_button.set_sensitive(self.web_view.can_go_back())
        self.forward_button.set_sensitive(self.web_view.can_go_forward())

    def main(self):
        gtk.main()

if __name__ == "__main__":
    browser = Browser()
    browser.main()
« Last Edit: March 30, 2011, 04:26:39 AM by Neal »

Offline Was_Just19

  • Hero Member
  • *****
  • Posts: 6852
  • MLU
Re: Lets create a PCLinuxOS webkit browser (python)
« Reply #50 on: March 30, 2011, 02:01:31 AM »
Couldn't resist   :)

How would it look if the entry bar was included inside the toolbar?

Code: [Select]
        #entry bar for typing in and display URLs, when they type in a site
        #and hit enter the on_active function is called
        self.url_bar = gtk.Entry()
        self.url_bar.connect("activate", self.on_active)
        entry_tool = gtk.ToolItem()
        entry_tool.set_expand(True)
        entry_tool.add(self.url_bar)
        self.url_bar.show()

        #add the buttons to the toolbar
        toolbar.add(self.back_button)
        toolbar.add(self.forward_button)
        toolbar.add(refresh_button)
        toolbar.add(entry_tool)

Just19
Try
Code: [Select]
self.window.set_title(('%s') % name)

Also, the code you posted above (reply #43) has an ASCII 160 character at the beginning of each indented line, followed by spaces.  It's an unprintable character so it appears to be a space, but it's messing things up for Python.  I don't know if it's your editor doing it or what, but it should be a space (ASCII 32).  Neal's code (reply #38) doesn't show that problem, so I don't think the forum is causing it.

I suspect it was the copy and paste action from the editor. I don't remember which editor I used to do this :(

The real reason I posted was to show the line entered .....  I had not considered anyone would use it for anything other than a reference to the added lines. ;)

« Last Edit: March 30, 2011, 02:04:02 AM by Just19 »

Offline Sproggy

  • Hero Member
  • *****
  • Posts: 1484
Re: Lets create a PCLinuxOS webkit browser (python)
« Reply #51 on: March 30, 2011, 02:06:17 AM »
well i am happy with this .... it just needs a home button and i think it's ready to rock and roll and be packaged for testing lol




Kori ;D ;D ;D

Offline Was_Just19

  • Hero Member
  • *****
  • Posts: 6852
  • MLU
Re: Lets create a PCLinuxOS webkit browser (python)
« Reply #52 on: March 30, 2011, 02:11:01 AM »
A question .......

the link on the top of the forum page - news

http://tinyurl.com/4fcgj4z

does not seem to be regarded as active ......  clicking on it does nothing ..... is it just here or generally ? ? ? EDIT: it does look like it is active when hovered over, but clicking does nothing ...

The new layout looks good here too .......  I would like to see a means of deleting the existing text from the location bar with a small press-button as in Konqueror.

regards.
« Last Edit: March 30, 2011, 02:16:45 AM by Just19 »

Offline Neal ManBear

  • Administrator
  • Super Villain
  • *****
  • Posts: 15847
  • LXDE! Coffee, Bacon and Cheesecake!
Re: Lets create a PCLinuxOS webkit browser (python)
« Reply #53 on: March 30, 2011, 02:28:09 AM »
Ok here's the icon idea i have come up with so far ...





let me know what you think

Kori ;D ;D

PS. the hammer is just a stock hammer of the web ... all can be changed if need be ... as this is the draght and still a work in progress it can be altered at any time


That's good, Kori. :D

How's this:


Offline Neal ManBear

  • Administrator
  • Super Villain
  • *****
  • Posts: 15847
  • LXDE! Coffee, Bacon and Cheesecake!
Re: Lets create a PCLinuxOS webkit browser (python)
« Reply #54 on: March 30, 2011, 03:42:27 AM »
A question .......

the link on the top of the forum page - news

http://tinyurl.com/4fcgj4z

does not seem to be regarded as active ......  clicking on it does nothing ..... is it just here or generally ? ? ? EDIT: it does look like it is active when hovered over, but clicking does nothing ...

The new layout looks good here too .......  I would like to see a means of deleting the existing text from the location bar with a small press-button as in Konqueror.

regards.


Yes, it seems we have no support for tinyurl.com at this time. Every other link I've tested works fine, though.

ongoto

  • Guest
Re: Lets create a PCLinuxOS webkit browser (python)
« Reply #55 on: March 30, 2011, 04:14:38 AM »
This thing went together pretty fast...and it runs fast too.   :)

Neal
These lines (59-62) could be deleted from your code because they are repeated a few paragraphs down.
Code: [Select]
        #add the buttons to the toolbar
        toolbar.add(self.back_button)
        toolbar.add(self.forward_button)
        toolbar.add(refresh_button)

Offline Neal ManBear

  • Administrator
  • Super Villain
  • *****
  • Posts: 15847
  • LXDE! Coffee, Bacon and Cheesecake!
Re: Lets create a PCLinuxOS webkit browser (python)
« Reply #56 on: March 30, 2011, 04:25:55 AM »
This thing went together pretty fast...and it runs fast too.   :)

Neal
These lines (59-62) could be deleted from your code because they are repeated a few paragraphs down.
Code: [Select]
       #add the buttons to the toolbar
        toolbar.add(self.back_button)
        toolbar.add(self.forward_button)
        toolbar.add(refresh_button)

 :o Oh bother! I missed those in my editing of the script. ??? ::)

Edit: Fixed in my post above.
« Last Edit: March 30, 2011, 04:29:06 AM by Neal »

Offline AndrzejL

  • PCLinuxOS Tester
  • Super Villain
  • *******
  • Posts: 12797
  • RLU #490933
    • Wordpress On The Wardrobe...
Re: Lets create a PCLinuxOS webkit browser (python)
« Reply #57 on: March 30, 2011, 04:57:26 AM »
Ok here's the icon idea i have come up with so far ...


let me know what you think

Kori ;D ;D


I love it.

How about this :P


@ Neal. I love Your icon too. So I decided to add an icon to Your icon so You can't touch this...

Errr forget it ;).


TeeHee. Had nothing to do this morning :P.

Hope You like my makeovers :P.

Andy

« Last Edit: March 30, 2011, 05:20:14 AM by AndrzejL »

Offline daniel

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 3735
  • God knows, i'm not an Angel!
    • Tipps und Tricks
Re: Lets create a PCLinuxOS webkit browser (python)
« Reply #58 on: March 30, 2011, 10:25:33 AM »
What is now the latest code?

Offline Was_Just19

  • Hero Member
  • *****
  • Posts: 6852
  • MLU
Re: Lets create a PCLinuxOS webkit browser (python)
« Reply #59 on: March 30, 2011, 10:40:26 AM »
This is what I have ......  I made a size change to the page, which I think is the only change I made.
I also am not sure about the copy & paste result ...  if it copies well so check it ...


#!/usr/bin/env python
#
# [SNIPPET_NAME: Webkit Browser]
# [SNIPPET_CATEGORIES: Webkit, PyGTK]
# [SNIPPET_DESCRIPTION: Create a simple browser using the webkit API]
# [SNIPPET_AUTHOR: Andy Breiner <breinera@gmail.com>]
# [SNIPPET_LICENSE: GPL]
# [SNIPPET_DOCS: http://ardoris.wordpress.com/2009/04/26/a-browser-in-14-lines-using-python-and-webkit, http://www.aclevername.com/articles/python-webgui]

import pygtk
pygtk.require('2.0')
import gtk

#you need to import webkit and gobject, gobject is needed for threads
import webkit
import gobject

name = "PCLinuxOS Hammer"

class Browser:
    default_site = "http://www.pclinuxos.com"

    def delete_event(self, widget, event, data=None):
        return False

    def destroy(self, widget, data=None):
        gtk.main_quit()

    def __init__(self):
        gobject.threads_init()
        self.window = gtk.Window(gtk.WINDOW_TOPLEVEL)
        self.window.set_resizable(True)
        self.window.set_default_size(1100, 950)
        self.window.connect("delete_event", self.delete_event)
        self.window.connect("destroy", self.destroy)

        #webkit.WebView allows us to embed a webkit browser
        #it takes care of going backwards/fowards/reloading
        #it even handles flash
        self.web_view = webkit.WebView()
        self.web_view.open(self.default_site)
        self.window.set_title('%s' % name)

        toolbar = gtk.Toolbar()

        #create the back button and connect the action to
        #allow us to go backwards using webkit
        self.back_button = gtk.ToolButton(gtk.STOCK_GO_BACK)
        self.back_button.connect("clicked", self.go_back)

        #same idea for forward button
        self.forward_button = gtk.ToolButton(gtk.STOCK_GO_FORWARD)
        self.forward_button.connect("clicked", self.go_forward)

        #again for refresh
        refresh_button = gtk.ToolButton(gtk.STOCK_REFRESH)
        refresh_button.connect("clicked", self.refresh)

        #entry bar for typing in and display URLs, when they type in a site
        #and hit enter the on_active function is called
        self.url_bar = gtk.Entry()
        self.url_bar.connect("activate", self.on_active)
        entry_tool = gtk.ToolItem()
        entry_tool.set_expand(True)
        entry_tool.add(self.url_bar)
        self.url_bar.show()

        #anytime a site is loaded the update_buttons will be called
        self.web_view.connect("load_committed", self.update_buttons)

        scroll_window = gtk.ScrolledWindow(None, None)
        scroll_window.add(self.web_view)

        #add the buttons to the toolbar
        toolbar.add(self.back_button)
        toolbar.add(self.forward_button)
        toolbar.add(refresh_button)
        toolbar.add(entry_tool)
       

        vbox = gtk.VBox(False, 0)
        vbox.pack_start(toolbar, False, True, 0)
        vbox.pack_start(self.url_bar, False, True, 0)
        vbox.add(scroll_window)

        self.window.add(vbox)
        self.window.show_all()

    def on_active(self, widge, data=None):
        '''When the user enters an address in the bar, we check to make
           sure they added the http://, if not we add it for them.  Once
           the url is correct, we just ask webkit to open that site.'''
        url = self.url_bar.get_text()
        try:
            url.index("://")
        except:
            url = "http://"+url
        self.url_bar.set_text(url)
        self.web_view.open(url)

    def go_back(self, widget, data=None):
        '''Webkit will remember the links and this will allow us to go
           backwards.'''
        self.web_view.go_back()

    def go_forward(self, widget, data=None):
        '''Webkit will remember the links and this will allow us to go
           forwards.'''
        self.web_view.go_forward()

    def refresh(self, widget, data=None):
        '''Simple makes webkit reload the current back.'''
        self.web_view.reload()

    def update_buttons(self, widget, data=None):
        '''Gets the current url entry and puts that into the url bar.
           It then checks to see if we can go back, if we can it makes the
           back button clickable.  Then it does the same for the foward
           button.'''
        self.url_bar.set_text( widget.get_main_frame().get_uri() )
        self.back_button.set_sensitive(self.web_view.can_go_back())
        self.forward_button.set_sensitive(self.web_view.can_go_forward())

    def main(self):
        gtk.main()

if __name__ == "__main__":
    browser = Browser()
    browser.main()