Re: Wxeuphoria network functionality

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

Jason Gade wrote:
> 
> Matt Lewis wrote:
> > 
> > 
> > The wxHTTP class doesn't work, but you can use wxURL and the socket classes.
> > 
> 
> Any good pointers on how to learn to do that? The wxwidgets docs are a bit
> thick
> for me.

I think the best way is to just keep trying.  Look at the code I've posted,
maybe at the code in the wxEuphoria files, and compare that to what you 
see in the wxWidgets docs.  As you go along, you'll probably start to 
pick up on things.  You can also ask me about things you run across.

My documentation is often a bit light.  If you can fill out the docs
in any place that gave you trouble, I'd appreciate it (and so would anyone
else who came after you).
 
> Say I wanted to download the file <a
> href="http://www.rapideuphoria.com/archive.zip">http://www.rapideuphoria.com/archive.zip</a>
> How would I do that, or where would I learn?
> 

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.

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 )


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

Search



Quick Links

User menu

Not signed in.

Misc Menu