gnocl::webKit

WJG (06/Jan/10) The Webkit [L1 ] opensource project provides powerful web browser engine which is easily wrapped to produce a Gnocl package. Here's a screenshot of it in action.

http://lh3.ggpht.com/_yaFgKvuZ36o/S0RuD-VzRoI/AAAAAAAAAMY/3jzsfq6ODvs/s800/Screenshot-Gnocl%20WebKit%20Demo.png

The following script shows how to get it running. As can be seen, rather than using a Tcl/Gnocl script to build the UI, this is now handled by loading a GtkBuilder XML description file create in Glade [L2 ].

#---------------
# test-webkit.tcl
#---------------
# Created by William J Giddings
# 06-Jan-10
#---------------
# Description:
#
#---------------

#!/bin/sh
# the next line restarts using tclsh \
exec tclsh "$0" "$@"

package require Gnocl
package require GnoclWebKit

set builderFile "browser.xml"
set builderFileObjects [gnocl::builder file $builderFile]
#---------------
# Register the widgets using their glade names.
#---------------
foreach item $builderFileObjects {
    foreach {gnocl builder} $item {}
    set $builder $gnocl
}

# create browser widget
set wk1 [gnocl::webKit -url "http://www.google.com"]

$hbox1 add $wk1 -fill {1 1} -expand 1

$window1 configure \
    -defaultHeight 400 \
    -defaultWidth 640 \
    -title "Gnocl WebKit Demo" \
    -onDestroy { exit }

$window1 show

gnocl::mainLoop

And, of course, the Glade builder file.

<?xml version="1.0"?>
<interface>
  <requires lib="gtk+" version="2.12"/>
  <object class="GtkWindow" id="window1">
    <property name="window_position">GTK_WIN_POS_CENTER</property>
    <child>
      <object class="GtkHBox" id="hbox1">
        <property name="visible">True</property>
        <child>
          <placeholder/>
        </child>
      </object>
    </child>
  </object>
</interface>

If anyone is interested in working on extending the functionality of the gnoclWebkit package then please let me know, I'd be happy to give whatever support is needed. The package is ready for download from the usual Sourceforge Gnocl repository [L3 ].

jys OMG, this is so f*cking awesome! I'm really happy to finally see access to modern tools like WebKit in Tcl.


tb - 2011-03-24

Hi! I just tried out GnoclWebKit and found the -url option not working as expected. It simply isn't handled, as the C code reveals. The last time I programmed GUI stuff in C was when XView.h (OpenLook, OpenView) was en vogue, so I'm not really fit for completing GnomeWebKit's source to a more usable state. Allthough I tried to mimic the code pattern from GnomeSourceView.c for GnomeWebKit.c, I haven't got the clue yet. Maybe there is a brief introduction into interfacing the Gtk libs the way Gnocl does it? More specific, I need some documentation about implementing the configure command and option handling.

WJG (26/03/11) Looking at the GnoclSourceView package as a way of analysiing how the modules work is a good method. This is how I started when I began building on Peter Baum's orginal work. The WebKit binding is a little more complex, however. It is not a true GtkWidget but the WebKit libraries with a Gtk Wrap, onto which a further layer is wrapped for the Tcl binding. The basic options are straight forward to implement, those which provide choices more complicated.The decision at times needs to be made as to which api functions become options and those commands. It took me quite some time to get to grips with the code and the workflow.


WJG (25/03/11) At this point in the time the package uploaded to SourceForge is basically a stub. I'll give it some TLC this weekend and properly implement the various options.

tb - 2011-03-26 Aahh, mmmhhh... :) - Fantastic! - I'd like to do some web scraping with tdom and need an advanced renderer like WebKit. Thanks a lot.


WJG (26/03/2011) I've just uploaded a version of the code with some the barest options and commands. The WebKitGtk binding is quite complex and has a whole raft of signals and properties to be 'tied-in'. When it first loads a page on my machine, a whole pile of 'smoke' pumps out to the console telling me that some plugins (OpenOffice and a couple of others) are not running. Next follows a long trail of further debugging smoke. This is not an issue related to the Tcl binding, its something coming from WebkitGtk itself. Unfortunately you will have to clear away a couple of dialogs before the first page completes loading. Having said that, it runs. I've been watching the BBC iPlayer on it today...

tb. I see that you're interesting in using tdom, there are API calls addressing this capability. I need to read-up more on the docs over before moving forward with this. As of today, the infrastructure to handle the processing of options and commands has been placed into the module and if you want to work on filling in the details, I'd be only too delighted to hear from you.

Here's my current test code with toolbar controlling browsing (WebKit maintains its own internal browsing history -nice).

#---------------
# test-webkit.tcl
#---------------
# Created by William J Giddings
# 26-Mar-11
#---------------
# Description:
#
#---------------

#!/bin/sh
# the next line restarts using tclsh \
exec tclsh "$0" "$@"

package require Gnocl
package require GnoclWebKit

#--------------
#
#--------------
proc gnocl::browser { {home webkit.org} } {

        # create container
        set bx [gnocl::box -orientation vertical]

        # global $bx.tbar
        global ${bx}.wk
        global ${bx}.tbar
        global ${bx}.ent

        global ${bx}.home

        set ${bx}.home $home

        # create key components, toolbar and browser
        set tbar [gnocl::toolBar]
        set wk [gnocl::webKit -transparent 1]

        set b [$tbar add item -icon %#GoBack -tooltip "Go Back"]
        set f [$tbar add item -icon %#GoForward  -tooltip "Go Forward"]
        set r [ $tbar add item -icon %#Refresh  -tooltip "Reload"]
        set s [$tbar add item -icon %#Cancel  -tooltip "Stop"]
        set h [$tbar add item -icon %#Home -tooltip "Home"]

        set ent [gnocl::entry -widthChars 85]
        $tbar add widget $ent

        # set toolbar behaviours
        $b configure -onClicked "$wk back"
        $f configure -onClicked "$wk forward"
        $r configure -onClicked "$wk reload"
        $s configure -onClicked "$wk stop"
        #$h configure -onClicked "$wk load http://$home"

        $h configure -onClicked  { set $browser.uri [loadPage $browser.wk [set $browser.home] ] }

        $ent configure \
                -onActivate { set $browser.uri [loadPage $browser.wk %t] } \
                -variable ${bx}.uri \


        # pack major components
        $bx add $tbar
        $bx add $wk -fill {1 1} -expand 1

        # create global access
        set ${bx}.wk $wk
        set ${bx}.tbar $tbar
        set ${bx}.ent $ent

        return $bx
}

#---------------
#
#---------------
proc loadPage {viewer page} {

        # string compare ?-nocase? ?-length int? string1 string2
        if { [string compare -length 7 "http://" $page] != 0 } {
                set page "http://$page"
        }

        [set $viewer] load $page

        return $page
}


set browser [gnocl::browser]

gnocl::window \
    -child $browser \
        -setSize 0.75 \
    -title "Gnocl WebKit Demo" \
    -onDestroy { exit }

gnocl::mainLoop

And a more up to date screenshot:

https://lh5.googleusercontent.com/_yaFgKvuZ36o/TY4SglzAe-I/AAAAAAAAA54/ijwsxJOUz8Y/s800/Screenshot-Gnocl%20WebKit%20Demo.png

PS> I've not created any docs yet

tb Wow! That's fast. It doesn't run here on Ubuntu (Karmic) x86. It complains about "GLib-ERROR **: The thread system is not yet initialized.".

I had to add:

    g_thread_init (NULL);

to Gnoclwebkit_Init ( Tcl_Interp *interp )

Just before...

    return TCL_OK;

Cheers...


WJG (26/03/11) You're welcome. I'm not certain why you needed to include g_thread_init (NULL). Looking at some of the discussions on the topic, the call is sometimes used to solve memory issues, but... I since added it to my sources and retried. It made no difference. I thought that it might have resolved some of the problems with loading the plugins mentioned above. Let me know how you go on. Perhaps you want to make postings to the gnocl google group . as most of the topics that will arise won't particularly be Tcl related.

tb 2001-03-26 - Hi, I have just released a little explorational tool at GnoWS - Gnocl Workspaces. It's quite handy to get used to Gnocl scripting and shows another use of Gnocl by itself of course.