Re: Wxeuphoria network functionality

new topic     » goto parent     » topic index » view thread      » older message » newer message

Matt Lewis wrote:
> Here is a modified version of what I posted earlier.  It will download the
> file specified in the box and save it.  It just stores everything in one
> sequence and a single write.  To break it up, take a look at stream_read(),
> and you could put that into your own code, and dump the result to a file
> as you go.
> 
> }}}
<eucode>
> without warning
> include wxEuphoria.e
> include wxText.e
> include wxButton.e
> include wxNet.e
> 
> global constant
> main = create( wxFrame, {0, -1, "Download Demo", 0, 0, 419, 200,
> wxDEFAULT_FRAME_STYLE }),
> panel = create( wxPanel, main ),
> file_label = create( wxStaticText, {panel, -1, "File name:", 13, 34, 116, 22
> }),
> file_name = create( wxTextCtrl, {panel, -1,
> "http://www.rapideuphoria.com/index.html", 135, 34, 300,  23 }),
> download_button = create( wxButton, {panel, -1, "Download Now", 13, 126, 96,
> 30 })
> 
> 
> procedure on_click( atom this, atom event_type, atom id, atom event )
> 	atom wxurl, stream
> 	integer fn, ix
> 	sequence url, current, path
> 	url = get_text_value( file_name )
> 	path = reverse( url )
> 	ix = find( '/', path )
> 	if ix then
> 		path = reverse( path[1..ix-1] )
> 	
> 	else
> 		path = reverse( path )		
> 	end if
> 	
> 	wxurl = create( wxURL, url )
> 	stream = get_url_input( wxurl )
> 	if stream then
> 		fn = open( path, "w" )
> 		if fn = -1 then
> 			puts(2, "Could not open file!\n" )
> 		else
> 			current = stream_read( stream )
> 			puts( fn, current )
> 			delete_instance( stream )       			
> 			close(fn)
> 		end if
> 	else
> 		puts(2, "Stream failed!\n")
> 	end if
> 	delete_instance( wxurl )
> 	 
> 	
> end procedure
> set_event_handler( download_button, -1, wxEVT_COMMAND_BUTTON_CLICKED,
> routine_id("on_click"))
> 
> wxMain( main )
> </eucode>
{{{


Other than changing the open() call to "wb", this works great! Maybe you could
put it in your demos.

--
"The author regrets that he is unable to reconcile himself to the
thoughtful point of view you have expressed. However, it must be kept
in mind that being raised in different cultures and different places can
result in such differences of viewpoint between individuals.
The author is from planet Earth." [author unknown]

j.

new topic     » goto parent     » topic index » view thread      » older message » newer message

Search



Quick Links

User menu

Not signed in.

Misc Menu