Saving filename to image of print stack

Getting into LiveCode for iOS? Ask your questions here.

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

Post Reply
quailcreek
Posts: 746
Joined: Sun Feb 04, 2007 11:01 pm

Saving filename to image of print stack

Post by quailcreek » Thu Oct 22, 2015 1:17 am

Hi,
This has been driving me buggy for a few days now.

Here's the explanation:
This is an iPhone app. I have a separate PrintStack for printing a hardcopy. On this PrintStack there is an image where the user can set a logo that will show on the hardcopy. The code below work perfectly in the sim. and when printed the logo is also printed. However, when I send the app to my device, the image doesn't show on the hardcopy. It seem like setting the fileName of the image on the printStack could be the problem. I'm testing on an iPhone4 with iOS 7.1.1 but that shouldn't make a difference. I thought maybe the problem was from using pngs, but I use pngs all overt this stack.

Any help is appreciated.

This code is on a card where the user is able to choose and save the logo from their phone.

Code: Select all

on preOpenCard
   if environment() is not "mobile" then exit preOpenCard
   
   put "1" into tSettingsID ## the Logo is stored with the quote settings
   put "SELECT Logo FROM MySettings WHERE SettingsID = :1" into tSQLStatement
   put revDataFromQuery(tab,cr, the uDatabaseID of this stack ,tSQLStatement,"tSettingsID") into tData
   put tData into tLogoName
   
   if tLogoName is not empty then
      put specialFolderPath("documents") & "/TrickPics/" & tLogoName into tLogoPath
      set the filename of image "Logo" to tLogoPath
   end if
end preOpenCard

on addEditSettings
   local tLogo
   
   if environment() is not "mobile" then exit addEditSettings
   
   if the uPhotoChanged of this cd is true then
      put "Logo_" & the seconds & ".png" into tLogo ## build a unique name for the pic file
      
      put specialFolderPath("documents") & "/TrickPics/" & tLogo into tPicTest
      if there is a file tPicTest then
         delete file tPicTest
         
         if there is a file tPicTest then
            answer "Still Here"
         end if
      end if   
      export image "Logo" to URL("binfile:" & specialfolderpath("documents") & "/TrickPics/" & tLogo) as PNG
   end if
   
   updateLogo tLogo
end addEditSettings

command updateLogo pLogo
   put "1" into SQLArray[1]
   
   if the uPhotoChanged of this cd is true then
      put pLogo into SQLArray[2]
      
      put "UPDATE MySettings SET Logo = :2 WHERE SettingsID = :1" into tSQLStatement
      revExecuteSQL the uDatabaseID of this stack, tSQLStatement, "SQLArray"
      
      if the result is an integer then
         put specialFolderPath("documents") & "/TrickPics/" & pLogo into tLogoPath
         put specialFolderPath("documents") & "/PrintQuote.livecode" into tPrintQuotePath
         open inv stack tPrintQuotePath
         
         if there is an image ID 1014 of cd 1 of stack tPrintQuotePath then
            set the filename of image ID 1014 of cd 1 of stack tPrintQuotePath to tLogoPath
            save stack tPrintQuotePath
            close stack tPrintQuotePath
            answer "Logo successfully saved."
         else
            answer "Sorry no Image element on card."
         end if
      else
         answer "Sorry, there was an error saving the Logo."
      end if
   end if
end updateLogo
Tom
MacBook Pro OS Mojave 10.14

quailcreek
Posts: 746
Joined: Sun Feb 04, 2007 11:01 pm

Re: Saving filename to image of print stack

Post by quailcreek » Thu Oct 22, 2015 11:20 pm

I think I've narrowed the problem down to the PrintStack not being saved. The saved changes are there only while the app remains open. If I close the app in the sim or on the device the changes are not there when it's relaunched. Is there something wrong with the code below that would cause the PrintStack to not be saved? Everything seems to run fine because it get the answer at the end. I have also tried putting some text into one of the flds on the PrintStack and then checking to see if it's there later. The results are the same as for the image fileName.

Code: Select all

put specialFolderPath("documents") & "/TrickPics/" & pLogo into tLogoPath
         put specialFolderPath("documents") & "/PrintQuote.livecode" into tPrintQuotePath
         open inv stack tPrintQuotePath
         
         if there is an image ID 1014 of cd 1 of stack tPrintQuotePath then
            set the filename of image ID 1014 of cd 1 of stack tPrintQuotePath to tLogoPath
            save stack tPrintQuotePath
            close stack tPrintQuotePath
            answer "Logo successfully saved."
          end if
Tom
MacBook Pro OS Mojave 10.14

quailcreek
Posts: 746
Joined: Sun Feb 04, 2007 11:01 pm

Re: Saving filename to image of print stack

Post by quailcreek » Fri Oct 23, 2015 1:12 am

Finally found the culprit. In a preOpenStack handler I have the code below. The intention is to check the versions of the 2 stacks. What I had to add to the code was the 2 close stack lines. The one pointing to the stack in the engine folder was causing the rest of the code to go wonkie until I added the close stack line. Whoda thunk.
put specialFolderPath("engine") & "/PrintQuote.livecode" into tQuoteEnginePath
put the uVersion of stack tQuoteEnginePath into tNewStackVersion
close stack tQuoteEnginePath
put the uVersion of stack tPrintQuotePath into tOldStackVersion
close stack tPrintQuotePath
Tom
MacBook Pro OS Mojave 10.14

quailcreek
Posts: 746
Joined: Sun Feb 04, 2007 11:01 pm

Re: Saving filename to image of print stack

Post by quailcreek » Sat Oct 24, 2015 10:11 pm

Hello All,
I now have a separate but related problem. What I'm trying to do is check a user property, uVersion, in both PrintQuote stacks. One that was previously copied to the documents folder and the one in the engine folder. I have destroyStack and destroyWindow of the PrintQuote stack both checkmarked. It appears that the close stack is not taking the PrintQuote stack out of memory. The "answer" at the bottom of the script always shows the two values as being the same. The value shown in the "answer" is always that of the first PrintQuote stack interrogated. That's what makes me think the stack is not being removed from memory. Does iOS work differently with regards to removing a stack from memory or is there a more reliable way to check the version between the two stacks? Thanks for any help.

Code: Select all

on preOpenStack
   if the environment is not mobile then exit preOpenStack
   
   put specialFolderPath("documents") & "/PrintQuote.livecode" into tPrintQuotePath
   put specialFolderPath("engine") & "/PrintQuote.livecode" into tQuoteEnginePath
   
   if there is not a file tPrintQuotePath then
      put url("binfile:" & specialFolderPath("engine") & "/PrintQuote.livecode") into url("binfile:" & specialFolderPath("documents") & "/PrintQuote.livecode")
      answer "PrintQuote stack copied"
   else
      put the uVersion of stack tPrintQuotePath into tOldStackVersion
      close stack tPrintQuotePath
      
      put the uVersion of stack tQuoteEnginePath into tNewStackVersion
      close stack tQuoteEnginePath
      
      answer "tNewStackVersion =" && tNewStackVersion & cr & "tOldStackVersion =" && tOldStackVersion
      
      ## Check to see if a newer vrsion exists
      if tNewStackVersion > tOldStackVersion  then
         do some stuff
      end if
   end if
end preOpenStack
Last edited by quailcreek on Sun Oct 25, 2015 6:48 pm, edited 3 times in total.
Tom
MacBook Pro OS Mojave 10.14

jacque
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 7390
Joined: Sat Apr 08, 2006 8:31 pm
Contact:

Re: Saving filename to image of print stack

Post by jacque » Sun Oct 25, 2015 5:26 pm

I think the "else" should be an "end if". See if that fixes it.
Jacqueline Landman Gay | jacque at hyperactivesw dot com
HyperActive Software | http://www.hyperactivesw.com

quailcreek
Posts: 746
Joined: Sun Feb 04, 2007 11:01 pm

Re: Saving filename to image of print stack

Post by quailcreek » Sun Oct 25, 2015 7:54 pm

Hi Jacqueline. Thanks for the reply.

Sorry, I got a bit lazy when pasting in the code. There should have been an end if at the bottom. I've corrected this.

I'll try to clarify what's happening. The PrintQuote stack has a user prop uVersion which = 1. When the app is sent to the sim it checks to see if the PrintQuote stack has been copied to the documents folder. If not it copies it. If it has already been copied it checks the uVersion of both stacks to see if the one in the engine folder has a higher value. If the value is higher it should copy the newer version from the engine folder to the documents folder and do some additional things.

So... when the app is sent to the sim it copies the PrintQuote stack, with the uVersion = 1, to the documents folder. Now, in the IDE, I change the uVersion of the PrintQuote stack to 2. The answer that comes back is tOldStackVersion = 1 and tNewStackVersion = 1. However, if I reverse the order and "put the uVersion of stack tQuoteEnginePath into tNewStackVersion" is first, the answer comes back tOldStackVersion = 2 and tNewStackVersion = 2. If the code below is all that's in the preOpenStack handler the same thing happens. This is what makes me think the close stack is not removing the stack from memory.

Code: Select all

 
     put specialFolderPath("documents") & "/PrintQuote.livecode" into tPrintQuotePath
     put specialFolderPath("engine") & "/PrintQuote.livecode" into tQuoteEnginePath

      put the uVersion of stack tPrintQuotePath into tOldStackVersion
      close stack tPrintQuotePath
      
      put the uVersion of stack tQuoteEnginePath into tNewStackVersion
      close stack tQuoteEnginePath
      
      answer "tNewStackVersion =" && tNewStackVersion & cr & "tOldStackVersion =" && tOldStackVersion
Tom
MacBook Pro OS Mojave 10.14

jacque
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 7390
Joined: Sat Apr 08, 2006 8:31 pm
Contact:

Re: Saving filename to image of print stack

Post by jacque » Sun Oct 25, 2015 8:45 pm

I see now. It may be a bug, but I've never encountered it because I normally just remove stacks by script without relying on their property settings. Try replacing "close" with "delete":

Code: Select all

put the uVersion of stack tPrintQuotePath into tOldStackVersion
delete stack tPrintQuotePath
    
put the uVersion of stack tQuoteEnginePath into tNewStackVersion
delete stack tQuoteEnginePath
That will force them out of memory.
Jacqueline Landman Gay | jacque at hyperactivesw dot com
HyperActive Software | http://www.hyperactivesw.com

quailcreek
Posts: 746
Joined: Sun Feb 04, 2007 11:01 pm

Re: Saving filename to image of print stack

Post by quailcreek » Sun Oct 25, 2015 9:47 pm

Perfecto!! That did it! Thanks again, Jacqueline. You're the best.
Tom
MacBook Pro OS Mojave 10.14

Post Reply