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

Offline daniel

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 3729
  • God knows, i'm not an Angel!
    • Tipps und Tricks
Re: Lets create a PCLinuxOS webkit browser (python)
« Reply #60 on: March 30, 2011, 10:46:41 AM »
Many thanks  ;)

Offline Sproggy

  • Hero Member
  • *****
  • Posts: 1484
Re: Lets create a PCLinuxOS webkit browser (python)
« Reply #61 on: March 30, 2011, 11:01:35 AM »
any news on the home button??????

Offline daniel

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 3729
  • God knows, i'm not an Angel!
    • Tipps und Tricks
Re: Lets create a PCLinuxOS webkit browser (python)
« Reply #62 on: March 30, 2011, 11:10:41 AM »
any news on the home button??????

added to line 59
Code: [Select]
#again for home
        home_button = gtk.ToolButton(gtk.STOCK_HOME)
        home_button.connect("clicked", self.refresh)


Note self.refresh must change in  ???

and add to line 82
Code: [Select]
toolbar.add(home_button)
Button is now displayed, now i must see how could the command for default site ...

« Last Edit: March 30, 2011, 11:12:15 AM by Leiche »

Offline Sproggy

  • Hero Member
  • *****
  • Posts: 1484
Re: Lets create a PCLinuxOS webkit browser (python)
« Reply #63 on: March 30, 2011, 11:17:40 AM »
thats awesome ... now we just need to make it go home lol

Offline Hootiegibbon

  • Hero Member
  • *****
  • Posts: 4151
Re: Lets create a PCLinuxOS webkit browser (python)
« Reply #64 on: March 30, 2011, 11:27:10 AM »
Kori,

I am gonna put together a "to do" list

Two of the high priority ones are, activating bookmarks via webkit,  cookie handling, and being able to pass the :set and :map commands

Doing that via a. Dotfile would be cool

Jase


I am Hootiegibbon, undisputed champion fo the typo

My .dotfiles

Offline scoundrel

  • Administrator
  • Hero Member
  • *****
  • Posts: 4512
  • Philosophy= Bigger Hammer
Re: Lets create a PCLinuxOS webkit browser (python)
« Reply #65 on: March 30, 2011, 11:52:15 AM »
will there be any support for adblock ??
Please Donate Today..Or I Will Make You Wish You Had

Offline daniel

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 3729
  • God knows, i'm not an Angel!
    • Tipps und Tricks
Re: Lets create a PCLinuxOS webkit browser (python)
« Reply #66 on: March 30, 2011, 11:55:43 AM »
okay, not my workstation, but home button works now

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(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)
        
        #again for home
        home_button = gtk.ToolButton(gtk.STOCK_HOME)
        home_button.connect("clicked", self.go_home)

        #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(home_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 go_home(self, widget, data=None):
'''Returns to default site, Homepage'''
self.web_view.open(self.default_site)

    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())
        self.go_home.set_sensitive(self.web_view.can_default_site())

    def main(self):
        gtk.main()

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

Have fun
« Last Edit: March 30, 2011, 12:33:25 PM by Leiche »

Offline Was_Just19

  • Hero Member
  • *****
  • Posts: 6852
  • MLU
Re: Lets create a PCLinuxOS webkit browser (python)
« Reply #67 on: March 30, 2011, 12:15:28 PM »
any news on the home button??????

added to line 59
Code: [Select]
#again for home
        home_button = gtk.ToolButton(gtk.STOCK_HOME)
        home_button.connect("clicked", self.refresh)


Note self.refresh must change in  ???

and add to line 82
Code: [Select]
toolbar.add(home_button)
Button is now displayed, now i must see how could the command for default site ...



Addd the lines and Home button present abd correct.

Thanks.

Offline pags

  • Hero Member
  • *****
  • Posts: 2515
  • Keep it clean.
Re: Lets create a PCLinuxOS webkit browser (python)
« Reply #68 on: March 30, 2011, 12:15:59 PM »
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.


...but if you right-click the link, and select "Copy Link Location", and past that into the URL bar, it works!
???

Offline Was_Just19

  • Hero Member
  • *****
  • Posts: 6852
  • MLU
Re: Lets create a PCLinuxOS webkit browser (python)
« Reply #69 on: March 30, 2011, 12:29:20 PM »
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.


...but if you right-click the link, and select "Copy Link Location", and past that into the URL bar, it works!
???



Yes it does .......  as would copying any link .......  whether active or not ....  I do not know what you are getting at ......  is it you do not expect active links to operate?

Offline pags

  • Hero Member
  • *****
  • Posts: 2515
  • Keep it clean.
Re: Lets create a PCLinuxOS webkit browser (python)
« Reply #70 on: March 30, 2011, 12:34:06 PM »
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.


...but if you right-click the link, and select "Copy Link Location", and past that into the URL bar, it works!
???



Yes it does .......  as would copying any link .......  whether active or not ....  I do not know what you are getting at ......  is it you do not expect active links to operate?


...misplaced quote...I was actually thinking of what Neal had said:
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.



tinyurl.com works...just not the link to it in the forum...

???
Still confusing?

...Great job, so far, BTW!

Offline daniel

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 3729
  • God knows, i'm not an Angel!
    • Tipps und Tricks
Re: Lets create a PCLinuxOS webkit browser (python)
« Reply #71 on: March 30, 2011, 12:36:00 PM »
yes, indeed, some links will not open  ::) ???

Offline Was_Just19

  • Hero Member
  • *****
  • Posts: 6852
  • MLU
Re: Lets create a PCLinuxOS webkit browser (python)
« Reply #72 on: March 30, 2011, 12:46:42 PM »
yes, indeed, some links will not open  ::) ???

Yes it is only some links .....  such as the facebook Tex link on the front page as well as the TinyURL link

Offline Neal ManBear

  • Administrator
  • Super Villain
  • *****
  • Posts: 15845
  • LXDE! Coffee, Bacon and Cheesecake!
Re: Lets create a PCLinuxOS webkit browser (python)
« Reply #73 on: March 30, 2011, 01:51:36 PM »
Leiche,
Home button working great. :D Positioned in the expected place, too :D



Offline daniel

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 3729
  • God knows, i'm not an Angel!
    • Tipps und Tricks
Re: Lets create a PCLinuxOS webkit browser (python)
« Reply #74 on: March 30, 2011, 01:56:21 PM »
no problem, but python isn't my thing

Working on lxautostart, will spend a new design  ;D