Problem porting from PC to Mac

Mac OSX specific forum
User avatar
Columbo
Enthusiast
Enthusiast
Posts: 303
Joined: Wed Sep 10, 2014 7:17 am
Location: Ontario Canada
Contact:

Problem porting from PC to Mac

Post by Columbo »

First of all, I am totally new to the Mac OS. I picked up a Macbook Pro and have Catalina OS installed. I wrote a program in Purebasic on my PC that I wanted to port over to the Mac. I copied it over to the Mac but it doesn’t want to run. While there may be some commands that are not compatible with the Mac it seems to be having a problem finding an image.
I checked the box in the compiler options to 'create temporary executable in the source directory'.

On the Mac I have the all of the files for the program in a folder on the desktop called PrehistoricLife. In that folder I have another folder called images, which of course contains all images for the program.

On the PC, I use the following:

Code: Select all

path$ = GetPathPart(ProgramFilename())
   imagePath3 =  path$ + "images\header.jpg"
   LoadImage(#img3,imagePath3) 
   ImageGadget(#headerimg,0, 28,1280,190,ImageID(#Img3))
If I do a debug of path$ on the PC I get ‘C:\PrehistoricLife/’
A debug of imagePath3 gives me ‘C:\PrehistoricLife/images/header.jpg’
That works fine.

On the Mac when I do a debug of path$ I get:
‘/Users/myname/Desktop/PrehistoricLife/Purebasic.app/Contents/MacOS/’

A debug of imagePath3 gives me ‘/Users/myname/Desktop/PrehistoricLife/Purebasic.app/Contents/MacOS/images/header.jpg’

This is giving me a file not initialized error. I don’t know where the ‘Purebasic.app/Contents/MacOS/’ is coming from in the path. Is there anyone who uses Purebasic on a Mac who can give me a hint as to what is going on here? (totally confused).
http://www.oldtimeradiotoday.com - Listen to or download classic old time radio broadcasts.
User avatar
robertfern
User
User
Posts: 23
Joined: Fri Feb 02, 2018 10:33 pm
Location: New Jersey

Re: Problem porting from PC to Mac

Post by robertfern »

The mac (& unix) use "/" (slash) for directory delimiters, whereas Windows uses "\" (backslash)

change

imagePath3 = path$ + "images\header.jpg"

to

imagePath3 = path$ + "images/header.jpg"

also Mac Programs are really a special directory called a "bundle".
inside this application "Bundle" are subdirectories containing the actual executable and other mac resources.
ProgramFileName() returns the path to the executable inside the "Bundle"
you should place your files in a directory one level up, and go down into "Resources"
But this will only work when the program is fully compiled as a standalone app.
While developing put the files you want in the same folder with the source code file
Mac OSX Ventura & Windows 10, PB 6.04
User avatar
Columbo
Enthusiast
Enthusiast
Posts: 303
Joined: Wed Sep 10, 2014 7:17 am
Location: Ontario Canada
Contact:

Re: Problem porting from PC to Mac

Post by Columbo »

Thank you for the response. I changed the imagePath3 to 'images/header.jpg but still get same error. As mentioned above, I have all of my required files, (source, images folder and SQLite database) located in a folder called PrehistoricLife on the desktop. Should it be somewhere else?
http://www.oldtimeradiotoday.com - Listen to or download classic old time radio broadcasts.
User avatar
Tenaja
Addict
Addict
Posts: 1948
Joined: Tue Nov 09, 2010 10:15 pm

Re: Problem porting from PC to Mac

Post by Tenaja »

You'll need to look it up, but there's a PB constant for file path separaters.

If you build those constant path strings at compile time into constants instead of strings, it'll resolve that aspect.
IdeasVacuum
Always Here
Always Here
Posts: 6425
Joined: Fri Oct 23, 2009 2:33 am
Location: Wales, UK
Contact:

Re: Problem porting from PC to Mac

Post by IdeasVacuum »

It might be better to store the images as Data (unless there are 100s)
IdeasVacuum
If it sounds simple, you have not grasped the complexity.
User avatar
Columbo
Enthusiast
Enthusiast
Posts: 303
Joined: Wed Sep 10, 2014 7:17 am
Location: Ontario Canada
Contact:

Re: Problem porting from PC to Mac

Post by Columbo »

I looked in the help file and found this"

Code: Select all

CompilerSelect #PB_Compiler_OS
    CompilerCase #PB_OS_MacOS
      ; some Mac OS X specific code    
  CompilerEndSelect
I added it to my code like this:

Code: Select all

CompilerSelect #PB_Compiler_OS
    CompilerCase #PB_OS_MacOS
   path$ = GetPathPart(ProgramFilename())
   imagePath3 =  path$ + "images/header.jpg"
  CompilerEndSelect
Doesn't work!

Here is the program code: The code raising the error is in the Procedure setupScreen()

Code: Select all

;---------------------------------------------
; Prehistoric Life - Version 2.0
; Author: J. Coones - PBLabs
; March 22, 2017
;--------------------------------------------

;---------------------------------------------------------
; Initialize the database & Image plugins
;---------------------------------------------------------
UseSQLiteDatabase()
UseJPEGImageDecoder()
UseGIFImageDecoder()

;------------------------------------
; Set up constants
;------------------------------------

Enumeration MainWindow
  ; Windows
  #MainWindow
EndEnumeration

Enumeration Databases 100
  ;Databases
  #dbaseID
EndEnumeration 

Enumeration FormGadgets 200
  ; Buttons
  #searchBtn
  #getRecBtn
  #prevBtn
  #nextBtn
  #exitBtn
  EndEnumeration 
 
  Enumeration LabelGadgets 300
  ; Labels
  #header
  #footer
  #labelName
  #labelMeaning
  #labelPronounce
  #labelPeriod
  #labelGroup
  #labelSize
  #labelLived
  #labelDiet
  #labelFossils
  #labelFactfile
  #labelPicture
  #labelCompare
  EndEnumeration 

  Enumeration TextGadgets 400
  ;Text Boxes
  #name
  #meaning
  #pronounce
  #period
  #group
  #size
  #lived
  #diet
  #fossils
  #factFile
  #title
 
  ;Edit Box
  #search
EndEnumeration

Enumeration Images 500
  ; Images
  #img0
  #img1
  #img2
  #img3
  #img4
  #img5
  #headerImg
  #footerimg
  #titlebarimg
  #searchIcon
EndEnumeration

Enumeration Other 700
  ; Miscellaneous
  #headerFont
  #footerFont
  #titleFont
  #kbdSearch
  #RecNo 
 EndEnumeration

#SS_CENTERIMAGE=512    ;Used to vertically align text in a TextGadget
;#EC_LEFTMARGIN = 1     ;Used similar to cellspacing for left margin in an EditorGadget
;EC_RIGHTMARGIN = 2    ;Used similar to cellspacing for right margin in an EditorGadget
;#EM_SETMARGINS =179     ;Was 211

;-----------------------------------
; Global Variables
;-----------------------------------
Global recno.l = 1
Global startpath.s = ""
Global path.s
Global imagePath1.s
Global imagePath2.s
Global imagePath3.s
Global imagePath4.s
Global imagePath5.s
Global iconPath.s
Global dbselected.s
Global filename1.s
Global filename2.s
Global maxRec.l
Global searchIcon
Global searchString.s
Global winWidth = 1280
Global winHeight = 700
Global headerwidth = 1280 
Global headerheight = 50
Global footerwidth = 1280 
Global footerheight = 30
Global newWidth
Global newHeight
Global footerY = 670
Global change = 0
Global resW.s
Global resH.s
Global resChange = 0
Global header$ = Chr(13) + "   Prehistoric Life"
Global footer$ = "   Information on prehistoric life from its beginning up to the appearance of man."

Procedure checkRes()
  ExamineDesktops()
  resW = Str(DesktopWidth(0))
  resH = Str(DesktopHeight(0))
  
  If resW <> Str(1280)
    resChange = 1
    #DM_BITSPERPEL=$40000
    #DM_PELSWIDTH=$80000
    #DM_PELSHEIGHT=$100000
    
    res.DEVMODE
    
    res\dmSize=SizeOf(DEVMODE)
    res\dmBitsPerPel=32
    res\dmPelsWidth=1280
    res\dmPelsHeight=720
    res\dmDisplayFrequency=60
    res\dmFields=#DM_BITSPERPEL|#DM_PELSWIDTH|#DM_PELSHEIGHT 
    
    ChangeDisplaySettings_(@res.DEVMODE,0)    
  EndIf   
EndProcedure

;<-------[ Load Font ]------------->
LoadFont(#headerFont, "Arial", 14)
LoadFont(#footerFont, "Arial", 9)
boldFont=LoadFont(#PB_Any, "Arial", 14, #PB_Font_Bold)

LoadFont(#titleFont, "Arial", 10, #PB_Font_Bold)

 Procedure getSearchIcon()
  path$ = GetPathPart(ProgramFilename())
  iconPath = path$ + "images\search-icon.gif"
  LoadImage(#img0, iconPath)
  ;LoadImage(#searchIcon,iconPath)   
 ;imgID = ImageID(#img0)
  
  ButtonImageGadget(#searchIcon, 1145, 193, 20, 20, ImageID(#img0))
   
EndProcedure

; -----------------[ Display Images ]-----------------
Procedure displayImages()
  filename1 = dbselected
  filename2 = dbselected
  
  path = GetPathPart(ProgramFilename())  
  imagePath1 = path + "dino_images\" + filename1 + ".jpg"
  imagePath2 = path + "dinosize\" + filename2 + "_size" + ".jpg" 
  
  LoadImage(1,imagePath1)
  LoadImage(2,imagePath2)
  PanelGadget(10, 885, 240, 355, 280)
   AddGadgetItem(10, -1, "Dinosaur Picture", 0)
    ImageGadget(1, 15, 10, 425, 260, ImageID(1))
   AddGadgetItem(10, -1, "Size Comaprison", 0)
    ImageGadget(2, 15, 10, 425, 260, ImageID(2))
    CloseGadgetList()
    
SetGadgetState(1, ImageID(1))
SetGadgetState(2, ImageID(2))
   
EndProcedure

; -----------------[ Search and Display Record ]-----------------
Procedure displayData(searchString.s)
  ; Routine To see if name contains any spaces
   getString.s = LCase(Trim(GetGadgetText(#search)))   ;Get the string value in the #Search box.
   Length.l = Len(getString)  ;Get the length of the name string
   
   chnum = 0   ;variable to hold number of characters in name
   For i = 1 To length    ;Loop through the name looking for spaces
     ch.s = Mid(getString, i, 1)
    If ch = " "    ;If a space is encountered then...
      chnum = i    ;assign the character number to chnum   
    EndIf    
  Next
  
  ;Routine to change the first character of searchString to upper case
   rightnum = length - chnum
   rightside.s = Right(getString, rightnum)
   rightcap.s = UCase(Left(rightside, 1))      ; Change first Character of first word to Upper case
   rightnum = rightnum - 1
   rightside.s = Right(getString, rightnum)
   rightString.s = rightcap + rightside
        
   leftside.s = Left(getstring, chnum)
   resultr.s = UCase(Left(leftside, 1))   ; Change first Character second word to Upper case
   chnum = chnum - 1
   
   resultl.s = LCase(Right(leftside, chnum))
   leftString.s = resultr + resultl
       
   searchString.s = leftString + rightString      ;join right string & left string
     
   If DatabaseQuery(#dbaseID,"SELECT * FROM dino WHERE name = '"+ searchString +"'")
     While NextDatabaseRow(#dbaseID)
       SetGadgetText(#RecNo, GetDatabaseString(#dbaseID, dbColumn))  ;Display record number in RecNo box.
       
       recNum.s = GetDatabaseString(#dbaseID, dbColumn)  ;Get the current record number
       recno = Val(recNum)            ;Set reno to current record number.
       
       If recno = maxRec
         DisableGadget(#nextBtn, 1)   ;If at the last record then disable the 'Next' button.
       Else
         DisableGadget(#nextBtn, 0)   ;Else enable the 'Next' button.
       EndIf
         
       If recno = 1
         DisableGadget(#prevBtn, 1)   ;If at the first record then disable the 'Prev' button. 
       Else
         DisableGadget(#prevBtn, 0)   ;Else enable the 'Prev' button.
       EndIf
         
       dbColumn +1                    ;Move to the next field in the database.
       
      spacer.s = Space(2)
      For populate = #Name To #FactFile   ;Fill in the fields with the corresponding data
        If populate = #FactFile
          spacer = ""
        EndIf
          SetGadgetText(populate, spacer + GetDatabaseString(#dbaseID, dbColumn))
        If dbcolumn = 1
          dbselected = GetDatabaseString(#dbaseID, dbColumn) ;Get the name of the dino to load images.
        EndIf
        
     dbColumn + 1  ;Increment the column
    Next
      
     displayImages()                   ;Get and display the associated images.
     FinishDatabaseQuery(#dbaseID)     ;Disconnect from database but does not close it.
   Wend
 EndIf 
   SetGadgetText(#search, "")          ;Clear the last search string from search box.
 EndProcedure
 
; -----------------[  Get Database Record & Display it ]-----------------
Procedure getRecord(recno)
  If DatabaseQuery(#dbaseID,"SELECT * FROM dino WHERE record = '"+ recno +"'")   ;Find the record
    While NextDatabaseRow(#dbaseID)   ;Start loop to go through fields.
       SetGadgetText(#RecNo, GetDatabaseString(#dbaseID, dbColumn))  ;Display record number in RecNo box.
       
      dbColumn + 1     ;Move to the next field in the database.
    
    spacer.s = Space(2)
    For populate = #Name To #FactFile    ;Fill in the fields with the corresponding data
        If populate = #FactFile
          spacer = ""
        EndIf
        SetGadgetText(populate, spacer + GetDatabaseString(#dbaseID, dbColumn))
        
        SendMessage_(GadgetID(#FactFile), #EM_SCROLL, #SB_TOP, 0)      ; Froce scrollbar to top of page.
      
       If dbColumn = 1   ;Check to see if we are in the 'Name' field.
         dbselected = GetDatabaseString(#dbaseID, dbColumn)   ;Get the dino's name from the name field.
       EndIf
       
       dbColumn + 1     ;Move to the next column.
      Next
       
   
   If recno = maxRec                            ; See if we are at the last record.
         DisableGadget(#nextBtn, 1)    ;If at the last record then disable the 'Next' button.
       Else
         DisableGadget(#nextBtn, 0)    ;If not at last record then enable the 'Next' button.
       EndIf
         
       If recno = 1
         DisableGadget(#prevBtn, 1)    ;If at the fisrt record then disable the 'Prev' button.
       Else
         DisableGadget(#prevBtn, 0)    ;If not at first record then enable the 'Prev' button.
       EndIf
       
       displayImages()                   ;Get and display the associated images.
       
     FinishDatabaseQuery(#dbaseID)     ;Disconnect from database but does not close it.
   Wend    ; End of loop
 EndIf 
  SetActiveGadget(#Search)
 
 EndProcedure

; -----------------[  Setup Screen]-----------------; Procedure to set up Main GUI
;---------------------------------------------
 Procedure setupScreen()
  path$ = GetPathPart(ProgramFilename())
   imagePath3 =  path$ + "images\header.jpg"
   LoadImage(#img3,imagePath3) 
   ImageGadget(#headerimg,0, 28,1280,190,ImageID(#Img3))
  DisableGadget(#headerimg,1) 
   
   ;----------------{ Setup Labels ]----------------
   TextGadget(#labelName, 90, 235, 45, 20, "Name : ")
   TextGadget(#labelMeaning, 80, 282, 50, 20, "Meaning : ")
   TextGadget(#labelPronounce, 50, 335, 85, 20, "Pronounciation : ")
   TextGadget(#labelPeriod, 92, 383, 50, 20, "Period : ")
   TextGadget(#labelGroup, 68, 433, 70, 20, "Main Group : ")
   TextGadget(#labelSize, 103, 484, 30, 20, "Size : ")
   TextGadget(#labelLived, 98, 533, 40, 20, "Lived : ")
   TextGadget(#labelDiet, 105, 582, 30, 20, "Diet : ")
   TextGadget(#labelFossils, 95, 628, 50, 20, "Fossils : ")
   TextGadget(#labelFactfile, 585, 657, 55, 20, "Fact File")
   
   For colorGadgets = #labelName To #labelFactFile
      SetGadgetColor(colorGadgets, #PB_Gadget_BackColor, RGB(226,222,214))      ;May need changing
      SetGadgetColor(colorGadgets, #PB_Gadget_FrontColor, RGB(62, 34, 7))
   Next 
    
   ;---------------{ Setup Data Fields ]-----------------
   TextGadget(#name, 145, 232, 200, 20, "",  #PB_Text_Border | #SS_CENTERIMAGE)
   TextGadget(#meaning, 145, 280, 200, 20, "",  #PB_Text_Border | #SS_CENTERIMAGE)
   TextGadget(#pronounce, 145, 332, 200, 20, "", #PB_Text_Border | #SS_CENTERIMAGE)
   TextGadget(#period, 145, 381, 200, 20, "",  #PB_Text_Border | #SS_CENTERIMAGE)
   TextGadget(#group, 145, 430, 200, 20, "",  #PB_Text_Border | #SS_CENTERIMAGE)
   TextGadget(#size, 145, 480, 200, 20, "",  #PB_Text_Border | #SS_CENTERIMAGE)
   TextGadget(#lived, 145, 530, 200, 20, "",  #PB_Text_Border | #SS_CENTERIMAGE)
   TextGadget(#diet, 145, 578, 202, 20, "",  #PB_Text_Border | #SS_CENTERIMAGE)
   TextGadget(#fossils, 145, 628, 200, 20, "",  #PB_Text_Border | #SS_CENTERIMAGE)
   EditorGadget(#FactFile, 375, 230, 480, 420, #PB_Editor_WordWrap | #PB_Editor_ReadOnly)
   
  
   
   boldFont=LoadFont(#PB_Any, "Arial", 10)
   SetGadgetFont(#FactFile, FontID(boldFont))
   
  margin = 15
  With editArea.RECT
    \left = margin
    \top = margin
    \right = GadgetWidth(#Factfile) - margin
    \bottom = GadgetHeight(#Factfile) - margin
  EndWith
  
   margin = 10
   SendMessage_(GadgetID(#Factfile), #EM_SETRECT, 0, editArea)
   
     ;-----------------[ Setup Search Box & Record Number Box ]---------------
   StringGadget(#search, 985, 193, 150, 20, "", #SS_CENTERIMAGE)     ;Search Box  (At top right of screen)
   StringGadget(#RecNo, 1036, 540, 70, 20, "", #SS_CENTERIMAGE)    ; Get Record Box (above the Prev and Next buttons)
   
   For colorGadgets = #name To #FactFile
     SetGadgetColor(colorGadgets, #PB_Gadget_BackColor, RGB(212,208,203))
     SetGadgetColor(colorGadgets, #PB_Gadget_FrontColor, RGB(44,23,3))    
   Next
   
   SetActiveGadget(#Search)
   
   ;---{ Setup Buttons ]---
   ButtonGadget(#getRecBtn, 1036, 570, 71, 20, "Get Record")
   ButtonGadget(#prevBtn, 1000, 605, 60, 20, "Prev")
   ButtonGadget(#nextBtn, 1090, 605, 60, 20, "Next")
   ButtonGadget(#exitBtn, 1048, 640, 60, 20, "Exit") 
   
   imagePath4 =  path$ + "images\footer.jpg"
   LoadImage(#img4,imagePath4)
   ImageGadget(#footerimg, 0, 692, 1280, 30, ImageID(#Img4))  ;Was 650
   DisableGadget(#footerimg,1) 
   
   imagePath5 =  path$ + "images\titlebar.jpg"
   LoadImage(#img5,imagePath5)
   ImageGadget(#titlebarimg, 0, 0, 1280, 30, ImageID(#Img5))
   DisableGadget(#titlebarimg,1) 
  EndProcedure
 
 ;-----------------[ Search Routine ]---------------
 Procedure searchRecord()
   searchString = GetGadgetText(#search)
   
    ; Routine To see if name contains any spaces
   getString.s = LCase(Trim(GetGadgetText(#search)))   ;Get the string value in the #Search box.
   Length.l = Len(getString)  ;Get the length of the name string
   
   chnum = 0   ;variable to hold number of characters in name
   For i = 1 To length    ;Loop through the name looking for spaces
     ch.s = Mid(getString, i, 1)
    If ch = " "    ;If a space is encountered then...
      chnum = i    ;assign the character number to chnum   
    EndIf    
  Next
  
  ;Routine to change the first character of searchString to upper case
   rightnum = length - chnum
   rightside.s = Right(getString, rightnum)
   rightcap.s = UCase(Left(rightside, 1))      ; Change first Character of first word to Upper case
   rightnum = rightnum - 1
   rightside.s = Right(getString, rightnum)
   rightString.s = rightcap + rightside
        
   leftside.s = Left(getstring, chnum)
   resultr.s = UCase(Left(leftside, 1))   ; Change first Character second word to Upper case
   chnum = chnum - 1
   
   resultl.s = LCase(Right(leftside, chnum))
   leftString.s = resultr + resultl       
   searchString.s = leftString + rightString      ;join right string & left string
   
   result = DatabaseQuery(#dbaseID, "SELECT * FROM dino WHERE name LIKE '%" + searchString + "%'")    ;try to find the search string
   
   While NextDatabaseRow(#dbaseID)
       SetGadgetText(#RecNo, GetDatabaseString(#dbaseID, dbColumn))  ;Display record number in RecNo box.
       
       recNum.s = GetDatabaseString(#dbaseID, dbColumn)  ;Get the current record number
       recno = Val(recNum)            ;Set reno to current record number.
       
       If recno = maxRec
         DisableGadget(#nextBtn, 1)   ;If at the last record then disable the 'Next' button.
       Else
         DisableGadget(#nextBtn, 0)   ;Else enable the 'Next' button.
       EndIf
         
       If recno = 1
         DisableGadget(#prevBtn, 1)   ;If at the first record then disable the 'Prev' button. 
       Else
         DisableGadget(#prevBtn, 0)   ;Else enable the 'Prev' button.
       EndIf
         
       dbColumn +1                    ;Move to the next field in the database.
       
      spacer.s = Space(2)
      For populate = #Name To #FactFile   ;Fill in the fields with the corresponding data
        If populate = #FactFile
          spacer = ""
        EndIf
          SetGadgetText(populate, spacer + GetDatabaseString(#dbaseID, dbColumn))
        If dbcolumn = 1
          dbselected = GetDatabaseString(#dbaseID, dbColumn) ;Get the name of the dino to load images.
        EndIf
        
     dbColumn + 1  ;Increment the column
    Next
      
     displayImages()                   ;Get and display the associated images.
     FinishDatabaseQuery(#dbaseID)     ;Disconnect from database but does not close it.
   Wend
   SetGadgetText(#search, "")          ;Clear the last search string from search box.
   SetActiveGadget(#Search)
   
 EndProcedure  

;-------------------[ Open the database & Main Window ]--------------------
 If OpenDatabase(#dbaseID, "dinobase.db", "", "")          ;Open the database
   DatabaseQuery(#dbaseID, "SELECT count(*) FROM dino")    ;Get the number of records in database
   NextDatabaseRow(#dbaseID)                               ;Move to the next record.
   maxRec = Val(GetDatabaseString(#dbaseID, 0))            ;Give maxRec the number of the last record
    
  ;wFlags = #PB_Window_BorderLess | #PB_Window_SystemMenu | #PB_Window_MinimizeGadget | #PB_Window_MaximizeGadget | #PB_Window_ScreenCentered | #PB_Window_Maximize  ;Window flags
   wFlags = #PB_Window_BorderLess | #PB_Window_Maximize  ;Window flags
   
  OpenWindow(#MainWindow, 0, 0, 1280, 678, "Prehistoric Life", wFlags)  ;Open GUI  Was at 678
  SetWindowColor(#MainWindow, RGB(226,222,213))
  AddKeyboardShortcut(#MainWindow, #PB_Shortcut_Return, #kbdSearch)    ;Trap keyboard input
  
  ;checkRes()
  setupScreen()          ;Setup the main screen.
  getSearchIcon()        ;Get the icon for the search button.
  getRecord(recno)       ;Display the first record on startup.
  
  
  ;--------------------------------------
  ; Wait for window event
  ;--------------------------------------
  Repeat
    Select WaitWindowEvent()      ;Wait for an event
      Case #PB_Event_CloseWindow  ;Close window if "X" is clicked.
        run = 1                   ;Set run flag to 1
        
        Case #PB_Event_MaximizeWindow
         ; setHeaderFooterSize()
          ;ResizeGadget(#header, 0, 0, headerWidth, headerHeight) 
         ;ResizeGadget(#footer, 0, footerY, footerWidth, footerHeight)
        
        Case #PB_Event_RestoreWindow          
         ; setHeaderFooterSize()
          ;ResizeGadget(#header, 0, 0, headerWidth, headerHeight)
          ;ResizeGadget(#footer, 0, footerY, footerWidth, footerHeight)
          
        Case #PB_Event_Menu
            Select EventMenu()
                Case #kbdSearch                   ;Check for keyboard event.
                  If GetActiveGadget() = #RecNo   ;Check if RecNo box is being used.
                    recno = Val(Trim(GetGadgetText(#RecNo)))  ;Get the number user entered into RecNo box.
                  ElseIf GetActiveGadget() = #search          ;See if the search box is being used. 
                      searchRecord()
                  EndIf
              EndSelect
              
        Case #PB_Event_Gadget      ;Check for gadget event
          Select EventGadget()
              
            Case #searchIcon
             ; dbselected = GetGadgetText(#search)
              displayimages()
              ; displayData(LCase(Trim(GetGadgetText(#Search))))
              searchRecord()
              
            Case #nextBtn        ;If the 'Next' button is pressed, get the next record
                  recno + 1          ;Increase record number by 1.
                  getRecord(recno)
                  
            Case #prevBtn        ;If the 'Prev' button is pressed, get the previous record
                  recno - 1          ;Reduce record number by 1.
                  getRecord(recno)   ;Find the record in database and display it.
              
            Case #getRecBtn
              recno = Val(Trim(GetGadgetText(#RecNo)))  ;Get number from RecNo box.
              
              getRecord(recno)
              
              
            Case #exitBtn        ;Close window If "Exit" button is pressed.
                  run = 1            ;Set run flag to 1
              EndSelect
   EndSelect           
                  
         Until run = 1    ;If run = 1 close the program.
            
         CloseDatabase(#dbaseID)    ;close the database.
         
      ;If resChange = 1
        ;#DM_BITSPERPEL=$40000
        ;#DM_PELSWIDTH=$80000
        ;#DM_PELSHEIGHT=$100000
      
        ;res.DEVMODE
      
        ;res\dmSize=SizeOf(DEVMODE)
        ;res\dmBitsPerPel=32
        ;res\dmPelsWidth=Val(resW)
        ;res\dmPelsHeight=Val(resH)
        ;res\dmDisplayFrequency=60
        ;res\dmFields=#DM_BITSPERPEL|#DM_PELSWIDTH|#DM_PELSHEIGHT 
      
        ;ChangeDisplaySettings_(@res.DEVMODE,0)
      ;EndIf
EndIf
                  
http://www.oldtimeradiotoday.com - Listen to or download classic old time radio broadcasts.
IdeasVacuum
Always Here
Always Here
Posts: 6425
Joined: Fri Oct 23, 2009 2:33 am
Location: Wales, UK
Contact:

Re: Problem porting from PC to Mac

Post by IdeasVacuum »

In the Procedure:
Change

Code: Select all

imagePath3 =  path$ + "images\header.jpg"
To

Code: Select all

imagePath3 =  path$ + "images/header.jpg"
Debug imagePath3 - are all the "/" correct?
IdeasVacuum
If it sounds simple, you have not grasped the complexity.
User avatar
Columbo
Enthusiast
Enthusiast
Posts: 303
Joined: Wed Sep 10, 2014 7:17 am
Location: Ontario Canada
Contact:

Re: Problem porting from PC to Mac

Post by Columbo »

Yes. The debug gives me '/Users/myname/Desktop/PrehistoricLife.pb/Purebasci.app/Contents/MacOS/images/header.jpg'
http://www.oldtimeradiotoday.com - Listen to or download classic old time radio broadcasts.
IdeasVacuum
Always Here
Always Here
Posts: 6425
Joined: Fri Oct 23, 2009 2:33 am
Location: Wales, UK
Contact:

Re: Problem porting from PC to Mac

Post by IdeasVacuum »

Does the image display OK now?
IdeasVacuum
If it sounds simple, you have not grasped the complexity.
User avatar
Columbo
Enthusiast
Enthusiast
Posts: 303
Joined: Wed Sep 10, 2014 7:17 am
Location: Ontario Canada
Contact:

Re: Problem porting from PC to Mac

Post by Columbo »

No. Still getting the error.
http://www.oldtimeradiotoday.com - Listen to or download classic old time radio broadcasts.
User avatar
deseven
Enthusiast
Enthusiast
Posts: 362
Joined: Wed Jan 12, 2011 3:48 pm
Location: Serbia
Contact:

Re: Problem porting from PC to Mac

Post by deseven »

If your resources are outside of the bundle (which is wrong, but a completely different topic), instead of using GetPathPart(ProgramFilename()) use bundlePath method of NSBundle.

Code: Select all

path$ = PeekS(CocoaMessage(0,CocoaMessage(0,CocoaMessage(0,0,"NSBundle mainBundle"),"bundlePath"),"UTF8String"),-1,#PB_UTF8)
imagePath3$ =  path$ + "/images/header.jpg"
Or just go up a couple of dirs:

Code: Select all

path$ = GetPathPart(ProgramFilename()) + "../../"
imagePath3$ =  path$ + "/images/header.jpg"
User avatar
mk-soft
Always Here
Always Here
Posts: 5313
Joined: Fri May 12, 2006 6:51 pm
Location: Germany

Re: Problem porting from PC to Mac

Post by mk-soft »

In macOS, a MyProg.APP is a folder. You can view the folder by opening the package content on the app with the right mouse button.
The programme is in the *.app/Contens/MacOS folder.
Data belongs in the folder *.app/Contens/Resources.

To get the data into the package on fly I wrote a small tool for the IDE. This is configured twice as a tool in the IDE. When compiling and running, when creating the execute.
This copies a folder (MyAppData) into the *app/Contents folder.

Link: IDE Tool MyAppData

Then a few more help functions to get to the folders
viewtopic.php?f=19&t=61638#p562634
My Projects ThreadToGUI / OOP-BaseClass / EventDesigner V3
PB v3.30 / v5.75 - OS Mac Mini OSX 10.xx - VM Window Pro / Linux Ubuntu
Downloads on my Webspace / OneDrive
User avatar
TI-994A
Addict
Addict
Posts: 2512
Joined: Sat Feb 19, 2011 3:47 am
Location: Singapore
Contact:

Re: Problem porting from PC to Mac

Post by TI-994A »

Columbo wrote:...I don’t know where the ‘Purebasic.app/Contents/MacOS/’ is coming from in the path.
Hi John. Like the others have mentioned, this is the standard anatomy of MacOs apps:

source: Apple Documentation - Bundle Structures

Code: Select all

MyApp.app               (main app bundle)
- Contents              (main app folder)
-- Info.plist           (properties file)
-- Resources            (resources folder)
-- MacOS                (executable folder)
--- MyApp executable    (executable file)
The GetCurrentDirectory() function should be used to obtain file paths relative to the app itself.

Code: Select all

imageFile.s = GetCurrentDirectory() + "images/header.jpg"
While debugging, the images subfolder should reside in the same folder as the app.

However, once compiled, the images subfolder must be copied into the app bundle. This is done as follows:
1. right click the images subfolder and select Copy "images"
2. right click on the compiled app and select Show Package Contents
4. select the Contents folder
5. right click anywhere in the folder window and select Paste Item
Texas Instruments TI-99/4A Home Computer: the first home computer with a 16bit processor, crammed into an 8bit architecture. Great hardware - Poor design - Wonderful BASIC engine. And it could talk too! Please visit my YouTube Channel :D
Lebostein
Addict
Addict
Posts: 807
Joined: Fri Jun 11, 2004 7:07 am

Re: Problem porting from PC to Mac

Post by Lebostein »

There is a PureBasic constant for the path separator:

#PS$

contains "/" in the Mac and "\" in the Windows Version. The opposite separator you find in the constant

#NPS$
collectordave
Addict
Addict
Posts: 1309
Joined: Fri Aug 28, 2015 6:10 pm
Location: Portugal

Re: Problem porting from PC to Mac

Post by collectordave »

I had similar problems when starting on the MAC!


The problem here is this line:-

path$ = GetPathPart(ProgramFilename())

When you compile/run your application path$ points to a location inside your application!

Such as:-

/Users/myname/Desktop/PrehistoricLife.pb/Purebasci.app/Contents/MacOS/images/header.jpg

The Purebasci.app part is your actual application.

At compile time the 'images/header.jpg' folder and image are not in your application they are in your desktop folder. To use them this way you need to copy the files to the location inside your application (for another time).

If you change these lines to:-

path$ = GetUserDirectory(#PB_Directory_Desktop)
imagePath3 = path$ + "PrehistoricLife.pb/images/header.jpg"

The only thing then is the 'PrehistoricLife.pb' folder confusing to use an extension in a folder name.

This may work however:

As a first exercise follow these steps:

1. Navigate to your Documents folder in finder.

2. Create a folder called 'PrehistoricLife'

3. Create a folder 'Images' inside the 'PrehistoricLife' folder.

4. Copy the 'header.jpg' file to this folder.


The path to that file is then 'Your Documents/PrehistoricLife/Images/header.jpg'

with PB you can then use :-

path$ = GetUserDirectory(#PB_Directory_Documents) + "PrehistoricLife/Images/"

imagePath3 = path$ + "header.jpg"

LoadImage(#img3,imagePath3)

Using the documents folder is best as the location is not changed when you compile.

Just one more small note. I see from your code you are making extensive use of enumerations, very useful at times but can cause some weird effects if your application becomes quite large.

Better to use variables in a lot of cases such as:

Global HeaderImage.i

HeaderImage = LoadImage(#PB_Any,imagePath3)
ImageGadget(#headerimg,0, 28,1280,190,ImageID(HeaderImage))

Note the use of #PB_Any, this ensures that the value assigned to the variable HeaderImage is unique.
Any intelligent fool can make things bigger and more complex. It takes a touch of genius — and a lot of courage to move in the opposite direction.
Post Reply