Page 5 of 7

Re: PB2Web -- A PureBasic to JavaScript-Converter

Posted: Fri Jan 17, 2014 12:36 am
by Kiffi
A new version (2014-01-16) is online: http://pb2web.de/download/

Add: EventMenu() (see MenuTest.pb in the examples-folder)
Add: BindGadgetEvent() for ButtonImageGadget()
Add: OpenFileRequester()

OpenFileRequester() opens a file-upload-dialog and starts immidiately the
upload when the user press the ok-button. On server-side there must be
a component (php, asp, ...) which is able to receive the uploaded file(s).
ServerCode is not able to receive files yet.

OpenFileRequester() is not tested on mobile devices (Android, iOS, etc).

For more informations see: OpenFileRequesterTest.pb in the examples folder
(there is also a 'upload.php' - file available for a simple demonstration).

Fixed: Shorthand-Operators (posted by [blendman])
Fixed: Select-Case-Bug (posted by [blendman] and falsam)

Greetings ... Kiffi

Re: PB2Web -- A PureBasic to JavaScript-Converter

Posted: Fri Jan 17, 2014 12:40 am
by falsam
Thanks ++++++ Where is your paypal button ? :)

Re: PB2Web -- A PureBasic to JavaScript-Converter

Posted: Fri Jan 17, 2014 9:05 am
by [blendman]
Great news !
Thank you very much ;). Kiffi, you're just a master (of the univers, of course, like Fred ^^)!

I will try it today, and improve my painting program. I will create a little game too in some days.

EDIT :
I have tried to create an "offline" version with pb2web.
Why ? to use it offline on Chromebook, proprietay system/PC like Hercule Ecafe, or to create Application multi-platform without compile on all platform ^^ and it works great !

On my netbook Hercule Ecafe (system based on ubuntu, modified by hercules), it works on chromium, but not in firefox (7.0.1 I think).
I have those error :

Code: Select all

Purepaint :
uncaught exception: [Exception... "Could not convert JavaScript argument arg 0 [nsIDOMCanvasRenderingContext2D.fillStyle]"  nsresult: "0x80570009 (NS_ERROR_XPC_BAD_CONVERT_JS)"  location: "JS frame :: http://www.dracaena-studio.com/purebasic/paint/libraries/pb2web/pb2web.js :: <TOP_LEVEL> :: line 7757"  data: no]

Canvas on Pb2web.de :
uncaught exception: [Exception... "Could not convert JavaScript argument - 0 was passed, expected object. Did you mean null? arg 0 [nsIDOMCanvasRenderingContext2D.strokeStyle]"  nsresult: "0x80570035 (NS_ERROR_XPC_BAD_CONVERT_JS_ZERO_ISNOT_NULL)"  location: "JS frame :: http://pb2web.de/demos/canvasgadget/libraries/pb2web/pb2web.js :: <TOP_LEVEL> :: line 229"  data: no]
I don't know if it's usefull for you, Kiffi ;).

Purepaint - version 0.1 Offline (I have change some lines on some files to use it offline) 1.8 Mo :
http://www.dracaena-studio.com/purebasi ... ffline.zip


EDIT :

OpenFileRequester()
I have tried, but I have an error with your example :
debug error :

Code: Select all

12:57:51.040: PB_Event_Upload_Complete: <?php
	
if (isset($_FILES['P2W_Upload'])) {

	echo "Message From PHP:\n";

	echo "Following file(s) received:\n";

	print_r($_FILES['P2W_Upload']);

}

?>
12:57:51.036: PB_Event_Upload_Error: ERROR: unable to upload files
12:57:50.898: PB_Event_Upload_BeforeSend: 
I have place the upload.php in the folder of pb2web, is that correct ?

How I do to open for example an image or a text file ?
The code :

Code: Select all

XIncludeFile "..\p2w.pbi"

P2W_Converter_SetProfile("pb2webtest")

UseJPEGImageDecoder()
UsePNGImageDecoder()

Procedure OpenFileRequesterCallback(UploadEvent, Message.s)
	
	Select UploadEvent
			
		Case #PB_Event_Upload_BeforeSend
			Debug("PB_Event_Upload_BeforeSend: " + Message)
			
		Case #PB_Event_Upload_Complete
			Debug("PB_Event_Upload_Complete: " + Message)
			
		Case #PB_Event_Upload_Error
			Debug("PB_Event_Upload_Error: " + Message)
			
		Case #PB_Event_Upload_Success
			Debug("PB_Event_Upload_Success: " + Message)
			
		Case #PB_Event_Upload_UploadProgress
			Debug("PB_Event_Upload_UploadProgress: " + Message)
			
			;Message -> position + ";" + total + ";" + percentComplete
			
			Protected Position.s = StringField(Message, 1, ";")
			Protected Total.s = StringField(Message, 2, ";")
			Protected PercentageComplete.s = StringField(Message, 3, ";")
			
			Debug "Position: " + Position
			Debug "Total: " + Total
			Debug "PercentageComplete: " + PercentageComplete + "%"
			Debug "---"
			
	EndSelect
	
EndProcedure


Procedure OpenOpenFileRequester()
	
	; 1. Parameter: Ignored
	; 2. Parameter: Upload-URL ;"http://localhost/pb2webtest/upload.php",
	; 3. Parameter: Mime-Type (see: http://www.webmaster-toolkit.com/mime-types.shtml)
	; 4. Parameter: MaxFileSize in bytes
	; 5: 0 or #PB_Requester_MultiSelection (works only in browser with HTML5-Support)
	; 6: A callback to get the upload events
	
	
	OpenFileRequester("", 	                  
	                  "upload.php",
	                  "image/*", 
	                  10000,
	                  #PB_Requester_MultiSelection,
	                  @OpenFileRequesterCallback())
	
EndProcedure

LoadFont(0, "Arial", 14)

TextGadget(0, 10, 10, 250, 30, "Please copy 'upload.php' to your webserver before uploading.")

SetGadgetFont(0, 0)

FreeFont(0)

ButtonGadget(1, 10, 50, 250, 30, "OpenFileRequester()")

BindGadgetEvent(1, @OpenOpenFileRequester())
EventMenu() and BindGadgetEvent() for ButtonImageGadget() Works fine, thanks ;).

Re: PB2Web -- A PureBasic to JavaScript-Converter

Posted: Fri Jan 17, 2014 2:53 pm
by Kiffi
[blendman] wrote:

Code: Select all

Purepaint :
uncaught exception: [Exception... "Could not convert JavaScript argument arg 0 [nsIDOMCanvasRenderingContext2D.fillStyle]"  nsresult: "0x80570009 (NS_ERROR_XPC_BAD_CONVERT_JS)"  location: "JS frame :: http://www.dracaena-studio.com/purebasic/paint/libraries/pb2web/pb2web.js :: <TOP_LEVEL> :: line 7757"  data: no]
i will take a look...
[blendman] wrote:OpenFileRequester()
you must copy the 'upload.php'-Script to your webserver (your Server-Path in
the profile). The server must able to execute PHP-Scripts. What kind of server
do you have? IIS? Apache?

The 'upload.php'-Script ist very simple. It only shows informations about the
file(s) you have selected in the OpenFileRequester().
[blendman] wrote:How I do to open for example an image or a text file ?
After clicking OK in the OpenFileRequester() the selected file(s) were sending
to the Script you specified. This script must copy the uploaded files to the server.
After that you can access the Image with LoadImage().

Greetings ... Kiffi

Re: PB2Web -- A PureBasic to JavaScript-Converter

Posted: Fri Jan 17, 2014 4:08 pm
by falsam
Small feedback:

Javascript is enabled.

I tested a code containing a canvas. (Application A) and a code that allows you to enter data and save them in a file. (Application B)

Windows XP and Windows 7 Windows8 (Application A) and (Application B) no problem.

Android 2.2 (Application A) and (B Application) does not work: Window invisible.
Android 4.X (Application A) fixed windows. (Application B) No problem.

(Application A): Windows RT Surface drawings are done with the mouse. (Application B) no problem.

Re: PB2Web -- A PureBasic to JavaScript-Converter

Posted: Fri Jan 17, 2014 4:16 pm
by falsam
With the new version of pb2web, it is possible to download a file. The condition is to put a "ugly php code" (c) Kiffi that you give with this new version. This code does not allow to upload files.

We must complete this code? I think the answer is yes :)

I will propose a code and tell me what you think.

Re: PB2Web -- A PureBasic to JavaScript-Converter

Posted: Fri Jan 17, 2014 6:56 pm
by [blendman]
Kiffi wrote:you must copy the 'upload.php'-Script to your webserver (your Server-Path in
the profile). The server must able to execute PHP-Scripts. What kind of server
do you have? IIS? Apache?
OK, It work on my website (dracaena-studio) ;).

For the "local mode", I use another technics ^^.
Is there a way in JS to open a sort of openfilerequester() but without PHP-Server installed ?
After clicking OK in the OpenFileRequester() the selected file(s) were sending
to the Script you specified. This script must copy the uploaded files to the server.
After that you can access the Image with LoadImage().
I have to create a PHP-script to copy the file received on my server ?

Re: PB2Web -- A PureBasic to JavaScript-Converter

Posted: Fri Jan 17, 2014 7:37 pm
by falsam
[blendman] wrote:I have to create a PHP-script to copy the file received on my server ?
yes.

Re: PB2Web -- A PureBasic to JavaScript-Converter

Posted: Fri Jan 17, 2014 7:41 pm
by falsam
Demonstration of Open File Requester.

:arrow: Test OpenFileRequester

-Click the Test button OpenFileRequester ()
-Choose one or more images.
-Once the download is complete, click an image name in the list to see the corresponding image.

My presentation is visually ugly, but it works :)


Windows [X] - Windows RT [X] - Android [ ]

Re: PB2Web -- A PureBasic to JavaScript-Converter

Posted: Fri Jan 17, 2014 7:49 pm
by Kwai chang caine
Yes works great :D
Congratulation FALSAM !!! you are too strong in HTML/JAVASCRIPT :mrgreen:

Re: PB2Web -- A PureBasic to JavaScript-Converter

Posted: Fri Jan 17, 2014 7:53 pm
by falsam
Kwaï chang caïne wrote:Yes works great :D
Congratulation FALSAM !!! you are too strong in JAVASCRIPT :mrgreen:
javascript ? What is this? :p Pb & Kiffi only :)

Re: PB2Web -- A PureBasic to JavaScript-Converter

Posted: Fri Jan 17, 2014 7:58 pm
by Kwai chang caine
Yes i know....have you see the --> " :mrgreen:"
Thanks to the kind KIFFY, now every PB coder can be the king of JS :D 8)

Re: PB2Web -- A PureBasic to JavaScript-Converter

Posted: Fri Jan 17, 2014 8:26 pm
by Kiffi
[blendman] wrote:Is there a way in JS to open a sort of openfilerequester() but without PHP-Server installed ?
i'll try to implement 'local' upload. Stay tuned...

Greetings ... Kiffi

Re: PB2Web -- A PureBasic to JavaScript-Converter

Posted: Fri Jan 17, 2014 10:00 pm
by falsam
@Kiffi : Can you test the 4th parameter (MaxFileSize in bytes) of your procedure OpenFileRequester ?

Code: Select all

OpenFileRequester("","upload.php", "image/*",10000, #PB_Requester_MultiSelection, @OpenFileRequesterCallback())
I loaded files > 10000 bytes

Re: PB2Web -- A PureBasic to JavaScript-Converter

Posted: Sat Jan 18, 2014 2:13 pm
by Kiffi
@all PB2Web-User:

Fred asked me to stop posting things about PB2Web. I accept that and would
like to draw attention to the PB2Web-Forum: http://pb2web.de/forum/

See you there...

Greetings ... Kiffi