how to program a droplet?

Mac OSX specific forum
gekkonier
User
User
Posts: 78
Joined: Mon Apr 23, 2007 9:42 am

how to program a droplet?

Post by gekkonier »

Hi!
I'd like to program an app that behaves like a droplet.
The plan is to drop a folder or a stack of files onto the app. This should start the app where I can get the "parameters", but I'm not able to. I fiddled around with programparameters, but got no solution. My tesprograms did'nt accept items and were not startable this way, only if you started them regular. Can anyone direct me in a direction please? I know I could write a starter for pb functionality in a scripting language, but is there a native pb way to do this?
User avatar
J. Baker
Addict
Addict
Posts: 2196
Joined: Sun Apr 27, 2003 8:12 am
Location: USA
Contact:

Re: how to program a droplet?

Post by J. Baker »

gekkonier wrote:Hi!
I'd like to program an app that behaves like a droplet.
The plan is to drop a folder or a stack of files onto the app. This should start the app where I can get the "parameters", but I'm not able to. I fiddled around with programparameters, but got no solution. My tesprograms did'nt accept items and were not startable this way, only if you started them regular. Can anyone direct me in a direction please? I know I could write a starter for pb functionality in a scripting language, but is there a native pb way to do this?
Did you try... http://www.purebasic.com/documentation/ ... index.html
www.posemotion.com

PureBasic Tools for OS X: PureMonitor, plist Tool, Data Maker & App Chef


Even the vine knows it surroundings but the man with eyes does not.
WilliamL
Addict
Addict
Posts: 1259
Joined: Mon Aug 04, 2008 10:56 pm
Location: Seattle, USA

Re: how to program a droplet?

Post by WilliamL »

Fred said 'Draw&Drop' doesn't work on Cocoa... yet. You could try with Carbon.

If you want to start an app by double-clicking on files you could try this http://www.purebasic.fr/english/viewtop ... 49#p391349 (select files then select 'open') You can drag a file(s) on to the app and it will open and load using this method also.
MacBook Pro-M1 (2021), Tahoe 26.2, PB 6.30b6
User avatar
J. Baker
Addict
Addict
Posts: 2196
Joined: Sun Apr 27, 2003 8:12 am
Location: USA
Contact:

Re: how to program a droplet?

Post by J. Baker »

Hmm, my app Cafio is a 64bit Cocoa app and uses drag and drop. It's been on the Mac App Store for a while now.
www.posemotion.com

PureBasic Tools for OS X: PureMonitor, plist Tool, Data Maker & App Chef


Even the vine knows it surroundings but the man with eyes does not.
WilliamL
Addict
Addict
Posts: 1259
Joined: Mon Aug 04, 2008 10:56 pm
Location: Seattle, USA

Re: how to program a droplet?

Post by WilliamL »

J. Baker,

http://www.purebasic.fr/english/viewtop ... op#p390085

cool, does this example, from the help file work for you also? It doesn't for me.

Code: Select all

;
; ------------------------------------------------------------
;
;   PureBasic - Drag & Drop
;
;    (c) 2007 - Fantaisie Software
;
; ------------------------------------------------------------
;

#Window = 0

Enumeration    ; Images
  #ImageSource
  #ImageTarget
EndEnumeration

Enumeration    ; Gadgets
  #SourceText
  #SourceImage
  #SourceFiles
  #SourcePrivate
  #TargetText
  #TargetImage
  #TargetFiles
  #TargetPrivate1
  #TargetPrivate2
EndEnumeration



If OpenWindow(#Window, 0, 0, 760, 310, "Drag & Drop", #PB_Window_SystemMenu|#PB_Window_ScreenCentered)
  
  ; Create some images for the image demonstration
  ; 
  CreateImage(#ImageSource, 136, 136)
  If StartDrawing(ImageOutput(#ImageSource))
    Box(0, 0, 136, 136, $FFFFFF)
    DrawText(5, 5, "Drag this image", $000000, $FFFFFF)        
    For i = 45 To 1 Step -1
      Circle(70, 80, i, Random($FFFFFF))
    Next i        
    
    StopDrawing()
  EndIf  
  
  CreateImage(#ImageTarget, 136, 136)
  If StartDrawing(ImageOutput(#ImageTarget))
    Box(0, 0, 136, 136, $FFFFFF)
    DrawText(5, 5, "Drop images here", $000000, $FFFFFF)
    StopDrawing()
  EndIf  
  
  
  ; Create and fill the source gadgets
  ;
  ListIconGadget(#SourceText,       10, 10, 140, 140, "Drag Text here", 130)   
  ImageGadget(#SourceImage,        160, 10, 140, 140, ImageID(#ImageSource), #PB_Image_Border) 
  ExplorerListGadget(#SourceFiles, 310, 10, 290, 140, GetHomeDirectory(), #PB_Explorer_MultiSelect)
  ListIconGadget(#SourcePrivate,   610, 10, 140, 140, "Drag private stuff here", 260)
     
  AddGadgetItem(#SourceText, -1, "hello world")
  AddGadgetItem(#SourceText, -1, "The quick brown fox jumped over the lazy dog")
  AddGadgetItem(#SourceText, -1, "abcdefg")
  AddGadgetItem(#SourceText, -1, "123456789")
  
  AddGadgetItem(#SourcePrivate, -1, "Private type 1")
  AddGadgetItem(#SourcePrivate, -1, "Private type 2")
  

  ; Create the target gadgets
  ;
  ListIconGadget(#TargetText,  10, 160, 140, 140, "Drop Text here", 130)
  ImageGadget(#TargetImage,    160, 160, 140, 140, ImageID(#ImageTarget), #PB_Image_Border) 
  ListIconGadget(#TargetFiles, 310, 160, 140, 140, "Drop Files here", 130)
  ListIconGadget(#TargetPrivate1, 460, 160, 140, 140, "Drop Private Type 1 here", 130)
  ListIconGadget(#TargetPrivate2, 610, 160, 140, 140, "Drop Private Type 2 here", 130)

  
  ; Now enable the dropping on the target gadgets
  ;
  EnableGadgetDrop(#TargetText,     #PB_Drop_Text,    #PB_Drag_Copy)
  EnableGadgetDrop(#TargetImage,    #PB_Drop_Image,   #PB_Drag_Copy)
  EnableGadgetDrop(#TargetFiles,    #PB_Drop_Files,   #PB_Drag_Copy)
  EnableGadgetDrop(#TargetPrivate1, #PB_Drop_Private, #PB_Drag_Copy, 1)
  EnableGadgetDrop(#TargetPrivate2, #PB_Drop_Private, #PB_Drag_Copy, 2)

  Repeat
    Event = WaitWindowEvent()
    
    ; DragStart event on the source gadgets, initiate a drag & drop
    ;
    If Event = #PB_Event_Gadget And EventType() = #PB_EventType_DragStart
      Select EventGadget()
      
        Case #SourceText
          Text$ = GetGadgetItemText(#SourceText, GetGadgetState(#SourceText))
          DragText(Text$)
        
        Case #SourceImage
          DragImage(ImageID(#ImageSource))
        
        Case #SourceFiles
          Files$ = ""       
          For i = 0 To CountGadgetItems(#SourceFiles)-1
            If GetGadgetItemState(#SourceFiles, i) & #PB_Explorer_Selected
              Files$ + GetGadgetText(#SourceFiles) + GetGadgetItemText(#SourceFiles, i) + Chr(10)
            EndIf
          Next i 
          If Files$ <> ""
            DragFiles(Files$)
          EndIf
        
        ; "Private" Drags only work within the program, everything else
        ; also works with other applications (Explorer, Word, etc)
        ;
        Case #SourcePrivate
          If GetGadgetState(#SourcePrivate) = 0
            DragPrivate(1)
          Else
            DragPrivate(2)
          EndIf
              
      EndSelect
    
    ; Drop event on the target gadgets, receive the dropped data
    ;
    ElseIf Event = #PB_Event_GadgetDrop
      Select EventGadget()
      
        Case #TargetText
          AddGadgetItem(#TargetText, -1, EventDropText())
        
        Case #TargetImage
          If EventDropImage(#ImageTarget)
            SetGadgetState(#TargetImage, ImageID(#ImageTarget))
          EndIf
        
        Case #TargetFiles
          Files$ = EventDropFiles()
          Count  = CountString(Files$, Chr(10)) + 1
          For i = 1 To Count
            AddGadgetItem(#TargetFiles, -1, StringField(Files$, i, Chr(10)))
          Next i
        
        Case #TargetPrivate1
          AddGadgetItem(#TargetPrivate1, -1, "Private type 1 dropped")
                
        Case #TargetPrivate2
          AddGadgetItem(#TargetPrivate2, -1, "Private type 2 dropped")
        
      EndSelect
    
    EndIf
    
  Until Event = #PB_Event_CloseWindow
EndIf

End
Last edited by WilliamL on Tue Feb 26, 2013 7:02 am, edited 1 time in total.
MacBook Pro-M1 (2021), Tahoe 26.2, PB 6.30b6
User avatar
J. Baker
Addict
Addict
Posts: 2196
Joined: Sun Apr 27, 2003 8:12 am
Location: USA
Contact:

Re: how to program a droplet?

Post by J. Baker »

After a quick look, I can drop files and images. But you will have to edit the code to prevent a red flag for outside images. Private and text didn't do anything for me. PureBasic 5.10 x64

Code: Select all

Case #TargetImage
          If EventDropType() = #PB_Drop_Image
           If EventDropImage(#ImageTarget)
             SetGadgetState(#TargetImage, ImageID(#ImageTarget))
           EndIf
          EndIf
www.posemotion.com

PureBasic Tools for OS X: PureMonitor, plist Tool, Data Maker & App Chef


Even the vine knows it surroundings but the man with eyes does not.
gekkonier
User
User
Posts: 78
Joined: Mon Apr 23, 2007 9:42 am

Re: how to program a droplet?

Post by gekkonier »

Hi!
Thank you all for your input.
I decided to write my program so that it doesn't rely on droplet functionality.
User avatar
fsw
Addict
Addict
Posts: 1603
Joined: Tue Apr 29, 2003 9:18 pm
Location: North by Northwest

Re: how to program a droplet?

Post by fsw »

The PureBasic - DragDrop help section says: Supported OS ... All

If this is incorrect or limited then it needs to say so in the help file.

The PureBasic drag'n-drop example doesn't work 100% as only the image can be dragged and dropped...

:cry:

Fred,
it would be nice if this would work, not only on Windows and Linux, but also on OSX.

Thanks

I am to provide the public with beneficial shocks.
Alfred Hitshock
Post Reply