Message sent when object placed onto card

Got a LiveCode personal license? Are you a beginner, hobbyist or educator that's new to LiveCode? This forum is the place to go for help getting started. Welcome!

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller

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

Re: Message sent when object placed onto card

Post by jacque » Fri Mar 17, 2023 5:30 pm

If you're using drag/drop handlers you can get info about the object when it's dropped and send a custom message from there. In a dragDrop handler, get the dragData and act on it. See the last paragraph in the dragdrop dictionary entry.
Jacqueline Landman Gay | jacque at hyperactivesw dot com
HyperActive Software | http://www.hyperactivesw.com

marksmithhfx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 931
Joined: Thu Nov 13, 2008 6:48 am

Re: Message sent when object placed onto card

Post by marksmithhfx » Sun Mar 19, 2023 6:52 pm

dunbarx wrote:
Thu Mar 16, 2023 1:51 pm
Is it possible you are trying to send that sort of message when you pull a control from the tools palette? Those messages are not sent when you do that.

Craig
Yes Craig, you are exactly right. I'm developing a tutorial stack and it's participatory... the user gets to add objects to the cards. Sometimes I would like to augment the controls functionality by adding a script to it. While it's not impossible to manage this without having a message sent when the user adds a control, it would HUGELY simplify my task if I knew when objects are being added. But I've found ways to work around this limitation so all is good for now. Would it be of some use to others to have a feature like that (ie. a message sent to the card in pointer mode when a control is added)? If so I don't mind making a feature request.

Best,
Mark
Last edited by marksmithhfx on Sun Mar 19, 2023 9:39 pm, edited 2 times in total.
macOS 12.6.5 (Monterey), Xcode 14.2, LC 10.0.0, iOS 15.6.1
Targets: Mac, iOS

marksmithhfx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 931
Joined: Thu Nov 13, 2008 6:48 am

Re: Message sent when object placed onto card

Post by marksmithhfx » Sun Mar 19, 2023 8:46 pm

jacque wrote:
Fri Mar 17, 2023 5:30 pm
If you're using drag/drop handlers you can get info about the object when it's dropped and send a custom message from there. In a dragDrop handler, get the dragData and act on it. See the last paragraph in the dragdrop dictionary entry.
Yes Jacque, there is a drag and drop involved. A picture being worth a thousand words I've included two. As you can see there is table of SQL column attributes on the right. The user is instructed to drag a polygrid onto the card and then populate it with columns by dragging objects from the SQL attributes table to the PG. This all works really well. My drop code is in the card so the populating of columns does not require any PG handler. However, the last part of the instruction "Click on a PolyGrid row to edit the record" does. The 2nd image demonstrates what this looks like, and its handled by adding this code to the PG.

Code: Select all

on cellClick pColumnNumber, pRowNumber, pCellRect
   set the pgInternalPointer of me to pRowNumber
   put the pgDataOfRow of me into lmyArray
   set the dialogData to lmyArray
   set the visible of stack "Edit User" to true
   modal stack "Edit User"
   -- on return...
   if the dialogData is not empty then
      put the dialogdata into lmyArray
      set the pgDataOfRow of me to dialogData
      updateSQLrecord
   end if
end cellClick
I've taken to piggy-backing onto the drop handler (in the card) to insert this handler into the PG, but that is not an ideal place for it. Better would be to insert the script of the PG when the control is added to the card (I think).

the piggy back happens here... (note this is a pretty custom drag drop handler which depends on mousemove and intersect to determine when the "field" control (created by dragging something out of the table) is over the PG. You can see where I've decided to update the PG script (and its ok there because there is nothing to click on until at least one column of data has been added).

Code: Select all

      else -- field is dropped
         if exists (card widget 1) then
            put the short name of widget 1 into tWidgetName
            get the pgBorderColor of widget tWidgetName
            if it is "0,255,0,255" then -- green with an extra 255 tacked on
               set the pgBorderColor of widget tWidgetName to black
               put the text of gMyNewControl into tColumnName
               addColumn2PolyGrid tWidgetName, tColumnName
            end if
         end if -- if exists
         delete gMyNewControl 
         put false into gHaveNewControl
         focus on nothing
         -- oh, and by the way, lets update the PG script while we are it.
         put the script of widget tWidgetName into tTest
         if tTest is empty then
            set the script of widget tWidgetName to the cScript37 of cd "Home"
         end if
      end if -- mouse is down
   end if -- have new control
end mousemove
Open to suggestions but short of having a message sent (in pointer mode) to indicate when a control is added I can't think of a better way.

mark

Image 1 https://www.dropbox.com/s/8meio7pdi0tv8 ... 1.png?dl=0

Image 2 https://www.dropbox.com/s/mnqwsj6lxthck ... 2.png?dl=0

PS increasing image size to 50% improves clarity and readability.
Last edited by marksmithhfx on Sun Mar 19, 2023 8:59 pm, edited 2 times in total.
macOS 12.6.5 (Monterey), Xcode 14.2, LC 10.0.0, iOS 15.6.1
Targets: Mac, iOS

richmond62
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 10094
Joined: Fri Feb 19, 2010 10:17 am

Re: Message sent when object placed onto card

Post by richmond62 » Sun Mar 19, 2023 8:50 pm

That's a funny way of including images.

marksmithhfx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 931
Joined: Thu Nov 13, 2008 6:48 am

Re: Message sent when object placed onto card

Post by marksmithhfx » Sun Mar 19, 2023 8:52 pm

richmond62 wrote:
Sun Mar 19, 2023 8:50 pm
That's a funny way of including images.
Yeah, I couldn't remember the name of the img url website, so improvised 8)
macOS 12.6.5 (Monterey), Xcode 14.2, LC 10.0.0, iOS 15.6.1
Targets: Mac, iOS

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 10317
Joined: Wed May 06, 2009 2:28 pm

Re: Message sent when object placed onto card

Post by dunbarx » Sun Mar 19, 2023 9:21 pm

Mark.

If you make a new control by any other method than dragging from the tools palette, the messages are sent. So if you are building a standalone app, you will always want to have some other action do that; users do not see the tools palette, so that limitation is IDE-only.

Craig

marksmithhfx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 931
Joined: Thu Nov 13, 2008 6:48 am

Re: Message sent when object placed onto card

Post by marksmithhfx » Sun Mar 19, 2023 9:35 pm

dunbarx wrote:
Sun Mar 19, 2023 9:21 pm
Mark.

If you make a new control by any other method than dragging from the tools palette, the messages are sent. So if you are building a standalone app, you will always want to have some other action do that; users do not see the tools palette, so that limitation is IDE-only.

Craig
Thanks Craig, noted. For the time being this demo stack is going to be limited to the IDE. If not the least because it is self-modifying and many cards are generated on the fly... I'm not sure if standalones are allowed to do that? Or is it just standalones distributed through the App Store that are constrained by that limitation?

Mark
macOS 12.6.5 (Monterey), Xcode 14.2, LC 10.0.0, iOS 15.6.1
Targets: Mac, iOS

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 10317
Joined: Wed May 06, 2009 2:28 pm

Re: Message sent when object placed onto card

Post by dunbarx » Sun Mar 19, 2023 9:38 pm

Standalone can do anything the IDE can.

Craig

Emily-Elizabeth
Posts: 101
Joined: Mon Jan 03, 2022 7:10 pm

Re: Message sent when object placed onto card

Post by Emily-Elizabeth » Mon Mar 20, 2023 2:36 am

marksmithhfx wrote:
Sun Mar 19, 2023 9:35 pm
If not the least because it is self-modifying and many cards are generated on the fly
If the stack is your standalone application, you won't be able to save the changes. But you can create a stack and save that with the changes and new cards.

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 10317
Joined: Wed May 06, 2009 2:28 pm

Re: Message sent when object placed onto card

Post by dunbarx » Mon Mar 20, 2023 4:13 am

Mark.

Emily is talking about the "Splash Stack" method, well discussed in this forum. It is what I do.

The only other way is to use external files.

Craig

marksmithhfx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 931
Joined: Thu Nov 13, 2008 6:48 am

Re: Message sent when object placed onto card

Post by marksmithhfx » Mon Mar 20, 2023 10:24 am

Emily-Elizabeth wrote:
Mon Mar 20, 2023 2:36 am
If the stack is your standalone application, you won't be able to save the changes. But you can create a stack and save that with the changes and new cards.
Thanks for that reminder Emily. I don't often use that technique but you are correct, creating a splash stack and then launching/creating other stacks from there would make them modifiable. I probably won't be turning this into a standalone (but as an exercise I might try just to see what changes, if any, are required). Just thinking about it, for one, I would lose access to the tool palette and this demo is about how we go about creating stacks in the first place so I think having the palette there is a necessary part of the demonstration. I'm building a stack to demo some ideas of how LC might go low code/no code (in some limited circumstances). The audience for this is obviously quite small although I'll probably ask a few people here to test it before it goes anywhere (I'm not necessarily any good at catching my own mistakes).

Best, and thanks again for the reminder.
Mark
macOS 12.6.5 (Monterey), Xcode 14.2, LC 10.0.0, iOS 15.6.1
Targets: Mac, iOS

richmond62
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 10094
Joined: Fri Feb 19, 2010 10:17 am

Re: Message sent when object placed onto card

Post by richmond62 » Mon Mar 20, 2023 11:06 am

Screen Shot 2023-03-20 at 12.04.57 pm.png
-
Screen Shot 2023-03-20 at 12.05.19 pm.png
-
Mark; can you please post your images inwith the body of a message as . . . .

marksmithhfx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 931
Joined: Thu Nov 13, 2008 6:48 am

Re: Message sent when object placed onto card

Post by marksmithhfx » Mon Mar 20, 2023 12:43 pm

richmond62 wrote:
Mon Mar 20, 2023 11:06 am
Mark; can you please post your images inwith the body of a message as . . . .
Hi Richmond,

Sorry about that, when I tested after posting them they just popped open for me so maybe that had something to do with them being in my own dropbox acct. Generally my images are too big to post here (these 2 are about .5 - 1.0 MB in size). I've moved them to postImages so please give the following a try and let me know if you are still having difficulty. Honestly, I wish I knew a better way to do this, but this is the best I've been able to come up with.

Thanks,
Mark

Image 1 https://postimg.cc/8fj8TB9K
Image 2 https://postimg.cc/c6HG70CR
macOS 12.6.5 (Monterey), Xcode 14.2, LC 10.0.0, iOS 15.6.1
Targets: Mac, iOS

Klaus
Posts: 14190
Joined: Sat Apr 08, 2006 8:41 am
Contact:

Re: Message sent when object placed onto card

Post by Klaus » Mon Mar 20, 2023 1:16 pm

I did not have any problems downloading and opening the images from your Dropbox on my Mac!?
I opened them in PREVIEW and saved as JPG, so the filesize went down.
image1.jpg
image2.jpg

marksmithhfx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 931
Joined: Thu Nov 13, 2008 6:48 am

Re: Message sent when object placed onto card

Post by marksmithhfx » Mon Mar 20, 2023 2:59 pm

Klaus wrote:
Mon Mar 20, 2023 1:16 pm
I did not have any problems downloading and opening the images from your Dropbox on my Mac!?
I opened them in PREVIEW and saved as JPG, so the filesize went down.
Remarkable. Did you use "Export..." (my Preview doesn't have a Save As... option) and what settings did you use? I could'nt get the images anywhere near that small (28k) in Preview (about 380k was the smallest I could make them with any decent resolution... yours are crystal clear :shock: ).

Mark
macOS 12.6.5 (Monterey), Xcode 14.2, LC 10.0.0, iOS 15.6.1
Targets: Mac, iOS

Post Reply