Skip to content

Instantly share code, notes, and snippets.

@mudgen
Created July 29, 2013 23:33
Show Gist options
  • Select an option

  • Save mudgen/6108837 to your computer and use it in GitHub Desktop.

Select an option

Save mudgen/6108837 to your computer and use it in GitHub Desktop.
Right click menu popup functionality
def getDirectoryPopup(event):
from com.inductiveautomation.ignition.client.images import PathIcon
from java.awt import Insets,Dimension,FlowLayout,Component,BorderLayout
from javax.swing import SwingConstants,JMenuItem,BorderFactory,JPopupMenu,JLabel
tree = event.source
selItem = tree.selectedItem
selPath = tree.selectedPath
def addRecipe(event):
app.directories.addRecipe(tree)
def deleteRecipe(event):
app.directories.deleteRecipe(tree)
def addFolder(event):
app.directories.addFolder(tree)
def renameFolder(event):
pass
def deleteFolder(event):
app.directories.deleteFolder(tree)
menu = system.gui.createPopupMenu([],[])
insets = Insets(2,-15,2,2)
if selItem == -1:
menuItem = JMenuItem("Add Recipe",actionPerformed=addRecipe)
menuItem.setIcon(PathIcon(menu, "RMS/document_add.png", 16, 16))
menuItem.setMargin(insets)
menu.add(menuItem)
menu.addSeparator()
menuItem = JMenuItem("Add Folder",actionPerformed=addFolder)
menuItem.setIcon(PathIcon(menu, "RMS/folder_add.png", 16, 16))
menuItem.setMargin(insets)
menu.add(menuItem)
menuItem = JMenuItem("Rename Folder",actionPerformed=renameFolder)
menuItem.setIcon(PathIcon(menu, "RMS/folder_edit.png", 16, 16))
menuItem.setMargin(insets)
menu.add(menuItem)
menuItem = JMenuItem("Delete Folder",actionPerformed=deleteFolder)
menuItem.setIcon(PathIcon(menu, "RMS/folder_delete.png", 16, 16))
menuItem.setMargin(insets)
menuItem.setEnabled(False)
for row in system.dataset.toPyDataSet(tree.data):
if row["path"] == selPath and row["leafType"] == "empty":
menuItem.setEnabled(True)
break
menu.add(menuItem)
elif tree.data.getValueAt(selItem,"leafType") == "recipe":
menuItem = JMenuItem("Delete Recipe",actionPerformed=deleteRecipe)
menuItem.setIcon(PathIcon(menu, "RMS/document_delete.png", 16, 16))
menuItem.setMargin(insets)
menu.add(menuItem)
menu.show(event)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment