site  contact  subhomenews

Basic HTML viewer with buttons

March 11, 2009 — BarryK
Hey, I'm learning! The biggest problem is lack of documentation that spells out the basics, with examples. Anyway, I found bits of code examples and managed to create this:



The program is remarkably simple:

[indent=4]

uses
Gtk

init
Gtk.init (ref args)
var test = new HtmlViewerWindow ()
test.show_all ()
Gtk.main ();

class HtmlViewerWindow : Window
prop back_button: ToolButton
prop forward_button: ToolButton
prop quit_button: ToolButton
prop moz: MozEmbed

init
title = "ultra tiny html viewer"
default_height = 550
default_width = 550
window_position = WindowPosition.CENTER
create_widgets ()
connect_signals ()

def create_widgets () : void
var toolbar = new Toolbar ()
this.quit_button = new ToolButton.from_stock (STOCK_QUIT)
this.back_button = new ToolButton.from_stock (STOCK_GO_BACK)
this.forward_button = new ToolButton.from_stock (STOCK_GO_FORWARD)
toolbar.add (this.quit_button)
toolbar.add (this.back_button)
toolbar.add (this.forward_button)
this.moz = new MozEmbed ()
moz.load_url("file:///usr/share/doc/index.html")
var vbox = new VBox (false, 0)
vbox.pack_start (toolbar, false, true, 0)
vbox.add (this.moz)
add (vbox)

def connect_signals () : void
destroy += Gtk.main_quit
this.quit_button.clicked += Gtk.main_quit
this.back_button.clicked += this.moz.go_back
this.forward_button.clicked += this.moz.go_forward

def private update_buttons () : void
this.back_button.sensitive = this.moz.can_go_back ()
this.forward_button.sensitive = this.moz.can_go_forward ()


What I haven't figured out yet is how to implement the method to grey-out the buttons as appropriate. I somehow need to call update_buttons() when the window changes. I'll ask on the Vala mail-list. The executable is now 11KB.

I have uploaded the executable and code to ibiblio.

Comments

Programming Category
Username: Raffy
This seems to be the first case of Genie programming? Should it become one of your important projects (or at least a blog category)? Introducing an advanced programming environment in a sub-100 MB build (not 000 MBs), and executables in tens of KBs (not MBs) should be a novel project in education. There is an embedded webserver/IDE that I recently saw which uses C, and this is another good example of programming for embedded systems. (Will have to locate it, can't find it now.)

Commandline params
Username: BarryK
"I have added title, url, width, height commandline parameters: [code][indent=4] uses Gtk param_width : int param_height : int param_title : string param_url : string init param_title=args[1] if param_title == "--help" print "Usage: 'title' 'url' width height" return param_url=args[2] param_width=args[3].to_int() param_height=args[4].to_int() Gtk.init (ref args) var test = new HtmlViewerWindow () test.show_all () Gtk.main () class HtmlViewerWindow : Window prop back_button: ToolButton prop forward_button: ToolButton prop quit_button: ToolButton prop moz: MozEmbed init title = param_title default_height = param_height default_width = param_width window_position = WindowPosition.CENTER create_widgets () connect_signals () def create_widgets () : void var toolbar = new Toolbar () this.quit_button = new ToolButton.from_stock (STOCK_QUIT) this.back_button = new ToolButton.from_stock (STOCK_GO_BACK) this.forward_button = new ToolButton.from_stock (STOCK_GO_FORWARD) toolbar.add (this.quit_button) toolbar.add (this.back_button) toolbar.add (this.forward_button) this.moz = new MozEmbed () moz.load_url(param_url) var vbox = new VBox (false, 0) vbox.pack_start (toolbar, false, true, 0) vbox.add (this.moz) add (vbox) def connect_signals () : void destroy += Gtk.main_quit this.quit_button.clicked += Gtk.main_quit this.back_button.clicked += this.moz.go_back this.forward_button.clicked += this.moz.go_forward def private update_buttons () : void this.back_button.sensitive = this.moz.can_go_back () this.forward_button.sensitive = this.moz.can_go_forward ()[/code]

what's the link?
Username: dinky
"Great idea Barry. Where's this posted on ibiblio? Is this the vala pet, or something else?


Tags: woof