I'm again stuck in the middle of total incomprehension of how images work in SpiderBasic.
I have created an application (well, at least started to migrate very functional one from PureBasic on desktop): https://www.banelli.biz/dev/tmp/logo/
Now here's my current problem - the image that gets loaded on beginning is called logo.png. After you write something in the EditorGadget and click preview, CGI script creates another image, logo1.png and now SpiderBasic should reload picture and show logo1.png; or if you repeat that multiple times, show new version of logo1.png
So here's relevant code:
Code: Select all
Procedure Loaded(Type, Filename$, ObjectId)
Debug Type
Debug ObjectId
Debug Filename$
ImageGadget(#Gadget_Image_Preview, 10, GadgetHeight(#Gadget_Frame_Option) + 20, WindowWidth(#Window_Main) - 20, WindowWidth(#Window_Main) - GadgetHeight(#Gadget_Frame_Option) - 20, ImageID(ObjectId))
EndProcedure
Procedure LoadingError(Type, Filename$, ObjectId)
Debug Filename$ + ": loading error"
EndProcedure
Procedure PreviewImage()
If IsImage(#Image_Preview)
FreeImage(#Image_Preview)
SetGadgetState(#Gadget_Image_Preview, #Null)
EndIf
LoadImage(#Image_Preview, "upload/logo1.png")
ProcedureReturn
EndProcedure
Procedure CGI_GeneratePreview(Success, Result$, UserData)
If Success
PreviewImage()
SetGadgetText(#Gadget_Editor_Text, Result$)
Else
SetGadgetText(#Gadget_Editor_Text, "HTTPRequest(): Error")
EndIf
EndProcedure
Procedure GeneratePreview()
Protected previewJSON.previewParameters
If CreateJSON(0)
previewJSON\DelimiterChar = GetGadgetText(#Gadget_String_Delimiter)
previewJSON\GrabbedText = GetGadgetText(#Gadget_Editor_Text)
previewJSON\ParagraphAlignment = 0
InsertJSONStructure(JSONValue(0), @previewJSON, previewParameters)
previewParsedJSON = ComposeJSON(0, #PB_JSON_PrettyPrint)
Debug previewParsedJSON
HTTPRequest(#PB_HTTP_Post, "generatePreview.cgi", previewParsedJSON, @CGI_GeneratePreview(), @previewParsedJSON)
FreeJSON(0)
EndIf
ProcedureReturn
EndProcedure
...
BindEvent(#PB_Event_Loading, @Loaded())
BindEvent(#PB_Event_LoadingError, @LoadingError())
BindEvent(#PB_Event_Gadget, @GeneratePreview(), #Window_Main, #Gadget_Button_Preview, #PB_EventType_LeftClick)
LoadImage(#Image_Preview, "upload/logo.png")
Now, what happens (very bizarre from my point of view) is the following - when you click preview, you will get correct image. However, every other input and clicking on preview will display the same image. Now comes the fun part, by refreshing the application (Ctrl+F5) and entering new text and clicking on preview will get you PREVIOUS image, not the actual one.
Here's the video from Lubuntu - very similar thing happens on Chrome on Windows, but it actually shows only the "last" picture Chrome remembers. Crazy.
Any clues what am I (obviously) doing wrong? PreviewImage() is called after If Success in HTTP callback and picture is finished by the time CGI reports back, so I would guess that it is not the issue of CGI script