118 lines
3.3 KiB
Elixir
118 lines
3.3 KiB
Elixir
|
|
||
|
----------------------------------------------------------------
|
||
|
--# Links in labels
|
||
|
-- can open webpages or local resources. this tests connectivity
|
||
|
-- every 2 sec. and indicates status. Click Network button to get
|
||
|
-- current address.
|
||
|
----------------------------------------------------------------
|
||
|
|
||
|
include GtkEngine.e
|
||
|
include std/net/dns.e
|
||
|
get_net_address()
|
||
|
|
||
|
constant text = sprintf(`<u><b>Web Links in labels</b></u>
|
||
|
|
||
|
Here are some interesting links:
|
||
|
|
||
|
<a href='http://OpenEuphoria.org'>OpenEu</a>
|
||
|
download Euphoria, get help on the forum!
|
||
|
<a href='http://Gtk.org'>GTK</a>
|
||
|
get the GTK documentation.
|
||
|
<a href='file://%s'>Readme</a>
|
||
|
view a local file.
|
||
|
|
||
|
`,
|
||
|
{canonical_path(locate_file("documentation/README.html"))})
|
||
|
|
||
|
constant bkgnd = create(GtkImage,canonical_path(locate_file("thumbnails/internet_trans.png")))
|
||
|
|
||
|
constant win = create(GtkWindow,"name=main,border_width=10,position=1,$destroy=Quit")
|
||
|
|
||
|
constant panel = create(GtkBox,"orientation=VERTICAL")
|
||
|
add(win,panel)
|
||
|
add(panel,bkgnd)
|
||
|
|
||
|
constant bar = create(GtkButtonBox,"margin-bottom=10")
|
||
|
pack_start(panel,bar)
|
||
|
|
||
|
object net_img, web_img
|
||
|
constant
|
||
|
net_img_on = create(GdkPixbuf,"thumbnails/network-wired.png",20,0,1),
|
||
|
net_img_off = create(GdkPixbuf,"thumbnails/network-wired-disconnected.png",20,0,1),
|
||
|
web_img_on = create(GdkPixbuf,"thumbnails/emblem-web-on.png",20,0,1),
|
||
|
web_img_off = create(GdkPixbuf,"thumbnails/emblem-web-off.png",20,0,1)
|
||
|
|
||
|
constant netbtn = create(GtkButton,"thumbnails/network-wired-disconnected.png#Network")
|
||
|
set(netbtn,"sensitive=0")
|
||
|
connect(netbtn,"clicked",_("ShowIP"))
|
||
|
add(bar,netbtn)
|
||
|
|
||
|
constant webbtn = create(GtkButton,"thumbnails/emblem-web-off.png#Internet")
|
||
|
set(webbtn,"sensitive=0")
|
||
|
add(bar,webbtn)
|
||
|
|
||
|
constant lbl = create(GtkLabel)
|
||
|
connect(lbl,"activate-link","onLinkActivate")
|
||
|
set(lbl,"markup",text)
|
||
|
add(panel,lbl)
|
||
|
|
||
|
constant box = create(GtkButtonBox),
|
||
|
btn = create(GtkButton,"gtk-quit","Quit")
|
||
|
pack(panel,-box)
|
||
|
add(box,btn)
|
||
|
|
||
|
constant tick = create(GTimeout,2000,call_back(routine_id("update_connectivity")))
|
||
|
|
||
|
show_all(win)
|
||
|
main()
|
||
|
|
||
|
-------------------------------------------------------------
|
||
|
global function onLinkActivate(atom lbl, object uri)
|
||
|
-------------------------------------------------------------
|
||
|
uri = peek_string(uri) display("URI []",{uri})
|
||
|
if match("http:",uri) then
|
||
|
if not inet_connected() then
|
||
|
Info(win,,"Sorry",
|
||
|
"I'm not connected to\nthe Internets right now",,
|
||
|
"face-sad",64)
|
||
|
return 1 -- returning 1 will do nothing
|
||
|
end if
|
||
|
else
|
||
|
ifdef WINDOWS then
|
||
|
system("explorer " & uri,0)
|
||
|
return 1
|
||
|
end ifdef
|
||
|
return 0 -- returning 0 will allow UNIX uri handler to do its thing
|
||
|
end if
|
||
|
return 1
|
||
|
end function
|
||
|
|
||
|
------------------------------------------
|
||
|
function update_connectivity()
|
||
|
------------------------------------------
|
||
|
|
||
|
if networked() then
|
||
|
set(netbtn,"image",net_img_on)
|
||
|
set(netbtn,"sensitive",1)
|
||
|
else
|
||
|
set(netbtn,"image",net_img_off)
|
||
|
set(netbtn,"sensitive",0)
|
||
|
end if
|
||
|
if inet_connected() then
|
||
|
set(webbtn,"image",web_img_on)
|
||
|
set(webbtn,"sensitive",1)
|
||
|
else
|
||
|
set(webbtn,"image",web_img_off)
|
||
|
set(webbtn,"sensitive",0)
|
||
|
end if
|
||
|
|
||
|
return 1
|
||
|
end function
|
||
|
|
||
|
--------------------------------------
|
||
|
function ShowIP()
|
||
|
--------------------------------------
|
||
|
Info(,"Network Address",get_net_address())
|
||
|
return 1
|
||
|
end function
|