Get selected date from equipment schedule

I’m trying to create a Vision window that shows scheduled events using the equipment schedule, which is pulling its dataset from a SQL table.
Displaying the data is all fine and dandy, but how on earth can we create a new event by interacting directly with the equipment schedule component?

The onPopupTrigger seems like the perfect place to define a “Create Event” function, but none of the attributes available are any use for doing so, as there is no reference to the date the mouse is clicking.
It only provides the itemId, which seems fairly useless.

I’m thinking along the lines of having the user being able to double click or right click an empty day in the scheduler, and for them to easily create a new event.

It’s possible, but non-obvious. Here’s code from an equipment schedule component that lets me add a row to a postgres table. The code toward the top calculates the point in time that was clicked (or, close enough for my purposes). It also calculates a minimum event width that’s based on the current time span of the component. The rest of the code is just gathering more info for packaging into the SQL row, should the popup option be clicked.

	s = event.source.getSize().width
	c = event.getX()
	rangeStart =
	rangeEnd =
	rangeMinutes =, rangeEnd)
	halfRangeNewEvent = rangeMinutes * .01
	timePointClicked =, int(((float(c)/s)*rangeMinutes)))
	newEventStart =, -1*(int(halfRangeNewEvent))),"yyyy-MM-dd HH:mm:ssX")
	newEventEnd =, int(halfRangeNewEvent)),"yyyy-MM-dd HH:mm:ssX")

	def addEvent(evt):
		db = 'postgres'
		#get segment for time stamp clicked
		segmentRunning = system.tag.queryTagHistory(paths=['[default]Tiny/BasicInfo/Current Segment'], startDate=timePointClicked, endDate=timePointClicked, returnSize=1, aggregationMode="LastValue", returnFormat='Wide')
		segmentRunning = int(segmentRunning.getValueAt(0,1))
		#get recipe number for segment running
		query = "SELECT COALESCE((SELECT recipe_number FROM tiny_recipes WHERE segment_range @> ?),99999)"
		args = [segmentRunning]
		currentRecipe = system.db.runPrepQuery(query, args, db)
		currentRecipe = currentRecipe.getValueAt(0,0)
		query = "INSERT INTO tiny_loads (equip_tagpath, recipe_running, load_timerange) VALUES (?,?,tstzrange(?::timestamptz,?::timestamptz));"
		args = [itemId, currentRecipe, newEventStart, newEventEnd]
		insertResult = system.db.runPrepUpdate(query, args, db)
		container = self.parent.getComponent('loadDetailsContainer')
		system.db.refresh(container, "LoadDetailsDataset")
	#if the newEventEnd date is in the past, show the popup menu
	#using newEventEnd instead of timePointClicked to avoid creating closed events in the future.  The other scripts expect to see a NULL value for currently occuring events.
	if < and "canEditFurnaceLoadHistory" in
		menu = system.gui.createPopupMenu(['Add Load Here'],[addEvent])