Drag and drop to list component

i am trying to drag and drop tag to list component. so i entered this script in mouse entered in list component.
but when i drag and drop single tag to list component its actually replacing the already existing tags in list component. i dont want to remove already existing tags from list when i drag and drop another tag from tag browser tree
please any one give me scripting idea to correct this issue

First, that is a very ‘loose’ definition of drag and drop. Drag and drop implies the user is holding the mouse button down while moving from the drop source to the drop target.

This script will execute anytime that the mouse enters the list component independent of if the user is trying to ‘drag’ a tag to the list or not. Which means that your going to be executing the script when you don’t need to. For instance, if you click on a tag release the mouse button move around the list component without entering and then move into the list component.

That being said you need to add the selected paths to the current dataset using something like system.dataset.addRows()

The list component is not a drop target. While in theory you could potentially do this from a scripting environment, it is well beyond what I would call non-trivial. More likely this crosses into module development with the SDK and pure java.

The method you described in this post to populate your list I would not recommend.

A better option here is to utilize a popupMenu to add tags to the list component. Is it as flashy as drag and drop? No probably not, but it is much more easily attainable.

In the mouseReleased event handler of your Tag Tree you can use something like the following to add a tag to the list component.

if event.button == event.BUTTON3:
    def addTagToList(event):
        selectedPaths = event.source.selectedPaths
        event.source.parent.getComponent('List').data = system.dataset.addRows(dataset = event.source.parent.getComponent('List').data, rows = selectedPaths)
    
    try:
        menu = system.gui.createPopupMenu(['Add Selected Tags'],[addTagToList])
        menu.show(event)
    except:
        pass

You should spend some time to go through the free training videos on Inductive University. There really is a wealth of information and examples available there particularly for vision.

The manual also has a lot of information available to you.

1 Like

While true, I'll also point out that you can use the Table or Power Table as a tag drop target pretty easily.
Huh, I could've sworn we added tag dropping to the tables...

Hi, yes I know easy chart and power tabel is easy to use. But my requirement what I mentioned is asked from customer end. For that can you have any idea

It is filtered to only show on a “Right” click.

OK I have to right click the tag correct?

Oh, I was thinking of an example I made years ago:

You're welcome to do that, but @lrose is absolutely correct - skipping drag and drop is going to be a lot more maintainable.

1 Like

You should be able to right click on any item in the tag tree and it show the popup menu. In the designer you will need to be in preview mode.

1 Like

I tired your project file in my local host, i cant able to move tags from tag tree browser to list in your project file. is there any changes need to be done. can you check and tell me know please

getting error in 7th line in script

one doubt whether you drag and drop tags from tag browser tree to list component ???

Perhaps you were correct?

This turned out to be a bit simpler than I was originally thinking. Not trivial, but not really painful either.

Add an extension function to your list component, I called mine addDropListener. Then in the script add the following script:

from java.awt.dnd import DropTargetAdapter, DropTarget
from com.inductiveautomation.ignition.client.tags.dnd import ListOfQualifiedPath
	
class customDragDropListener(DropTargetAdapter):
	_comp = None
	def __init__(self,comp):
		DropTargetAdapter.__init__(self)
		self._comp = comp
			
	def drop(self,e):
		e.acceptDrop(e.getDropAction())
		paths = [[path] for path in e.getTransferable().getTransferData(ListOfQualifiedPath.FLAVOR)]
		self._comp.data = system.dataset.addRows(self._comp.data,paths)
			
ddl = customDragDropListener(self)
DropTarget(self,ddl)

Then in the internalFrameActivated Event Handler on the window use the following script

NOTE: You will need to change the path for the component to be valid for your system.

tagList = system.gui.getParentWindow(event).getComponentForPath('Root Container.List')

if not tagList.getDropTarget():
    tagList.addDropListener()

Select any number of tags in the Tag Browse Tree component drop them on the list and they will be appended to the list's dataset. It doesn't validate incoming paths against pre-existing paths so you can add duplicates, if you want this functionality you'll need to add it to the drop function.

1 Like

I will check this scripts and revert you back



I tired your script. when i drag and drop tags from tag tree browser to list.

its not showing tag path in list, "list is empty"

Is there any thing to add in script???

please let me know

I assumed that you were adding this code to an existing window.

In order for the code to work the List’s dataset needs to have a defined column, which doesn’t happen until you either bind it to something or add a column.

Adding a String Column to your List’s dataset, should correct your issue.

Of course you could check the data property and either create the dataset or add rows to it.

Code which includes a check:

from java.awt.dnd import DropTargetAdapter, DropTarget
from com.inductiveautomation.ignition.client.tags.dnd import ListOfQualifiedPath
		
class customDragDropListener(DropTargetAdapter):
	_comp = None
	def __init__(self,comp):
		DropTargetAdapter.__init__(self)
		self._comp = comp
				
	def drop(self,e):
		e.acceptDrop(e.getDropAction())
		paths = [[path] for path in e.getTransferable().getTransferData(ListOfQualifiedPath.FLAVOR)]
		self._comp.data = system.dataset.addRows(self._comp.data,paths) if self._comp.data.columnCount > 0 else system.dataset.toDataSet(['Selected Tags'],paths)
				
ddl = customDragDropListener(self)
DropTarget(self,ddl)

If you make a change to this code, you will need to close the window in the designer in order to re-register the listener to the list component. Another, potentially easier option is to add a temporary button and add script there to register the listener. Otherwise the changes in the script will not take effect.

i used this script and i opened in client window.

still same issue list is empty when i drag and drop the tags

is there anything to change?

can you share me the project backup with you done this scripting ?

Did you add a column to the List's Data property?

yes

Since you have done that, have you saved, closed the window, and re-opened it?

Does the cursor change to the drop icon when you are over the List?

yes its changing to drop icon but tag path is not showing in list. pervious script also same issue list is empty even i drag and drop

yes i saved and closed client and opened again and checked too.