
---------------------------------------------------------
--# Plug and Socket Demo <span color='red'><b>Run sock.ex , not this file!!</b></span>
---------------------------------------------------------
-- Run eui sock.ex
-- This will open a window and show a Socket ID.
-- sock.ex will then execute plug.ex, passing
-- the Socket ID to it. 
-- Plug will open a small window containing a 
-- FileChooserButton. Use this to select images.
-- The selected image should be shown in the sock window.
----------------------------------------------------------

include GtkEngine.e

object cmd = command_line()

integer sock_id = 0
if length(cmd) > 2 then
	sock_id = to_number(cmd[3])
end if

constant win1 = create(GtkWindow,{
	{"border width",10},
	{"default size",200,50},	
	{"icon","~/demos/thumbnails/applications-development.svg"},
	{"position",GTK_WIN_POS_CENTER},
	{"connect","destroy","Quit"}})

constant panel = create(GtkBox,VERTICAL)
	add(win1,panel)

constant filter = create(GtkFileFilter,{
	{"name","Images"},
	{"add mime type","image/*"}})
	
constant btn = create(GtkFileChooserButton,"Open")
	pack_end(panel,btn)
	set(btn,"add filter",filter)
	connect(btn,"file-set","NewPix")
	
constant plug = create(GtkPlug,sock_id)

constant img = create(GtkImage,"~/demos/thumbnails/mongoose.png")
	add(plug,img)
	show_all(plug)

show_all(win1)
main()

------------------------
global function NewPix()
------------------------
object fn = get(btn,"filename")
object pb = create(GdkPixbuf,fn,500,500,1)
if file_exists(fn) then
	display(fn)
	set(img,"from pixbuf",pb)
end if
return 1
end function
