Jump to content
Developer Wiki and Function Reference Links ×

Remove choices from popup in Dialog


DomC

Recommended Posts

Hello
Would be great if anybody could help me. At the end result I want to be able to exchange a popup's choices. What I am trying to do is, that I delete the items with vs.RemoveChoice()
and build it new with a loop through my choices. I think I make something wrong by indexing with "AddChoice" or "RemoveChoice" just remove the string not shorten the Choice Numbers.

My script:
 


choices1 = ['choice1', 'choice2', 'choice3', 'choice4']
choices2 = ['choiceA', 'choiceB']



def CreateMyDialog():
	vs.dialogid = vs.CreateLayout('Dialog Name', 0, 'OK', 'Cancel')
	dialogID = vs.dialogid
	vs.CreateStaticText(dialogID, 10, 'Popup', 60 )

	vs.CreatePullDownMenu(dialogID, 11, 40)
	vs.CreateCheckBox(dialogID, 12, 'Change Popup')
	
	vs.SetFirstLayoutItem(dialogID, 10)
	vs.SetBelowItem(dialogID, 10, 11, 0, 1)
	vs.SetBelowItem(dialogID, 11, 12, 0, 1)
	
	return vs.RunLayoutDialogN(dialogID, Dialog_Handler, 0)

def Dialog_Handler(item, data):
	dialogID = vs.dialogid
			
	if item == 12255:  # enter Dialog 12255  -> 12256 exit dialog
		for i in range(len(choices1)):
			vs.AddChoice(dialogID, 11, choices1[i], i)

	if item == 12: #checkbox
		if data: #checkbox True
			num_choices = vs.GetChoiceCount(dialogID, 11)
			for i in range(num_choices):
				vs.RemoveChoice(dialogID, 11, i)
			
			for i in range(len(choices2)):
				vs.AddChoice(dialogID, 11, choices2[i], i)	
				
		if not data: #checkbox False
			num_choices = vs.GetChoiceCount(dialogID, 11)
			for i in range(num_choices):
				vs.RemoveChoice(dialogID, 11, i)
			
			for i in range(len(choices1)):
				vs.AddChoice(dialogID, 11, choices1[i], i)	



result = CreateMyDialog()

 

Link to comment

Hello
Solved by searching the Forum. Seems we need backward indexing to delete the choices. Here the working popup Dialog.

 


choices1 = ['choice1', 'choice2', 'choice3', 'choice4']
choices2 = ['choiceA', 'choiceB']



def CreateMyDialog():
	vs.dialogid = vs.CreateLayout('Dialog Name', 0, 'OK', 'Cancel')
	dialogID = vs.dialogid
	vs.CreateStaticText(dialogID, 10, 'Popup', 60 )

	vs.CreatePullDownMenu(dialogID, 11, 40)
	vs.CreateCheckBox(dialogID, 12, 'Change Popup')
	
	vs.SetFirstLayoutItem(dialogID, 10)
	vs.SetBelowItem(dialogID, 10, 11, 0, 1)
	vs.SetBelowItem(dialogID, 11, 12, 0, 1)
	
	return vs.RunLayoutDialogN(dialogID, Dialog_Handler, 0)

def Dialog_Handler(item, data):
	dialogID = vs.dialogid
			
	if item == 12255:  # enter Dialog 12255  -> 12256 exit dialog
		for i in range(len(choices1)):
			vs.AddChoice(dialogID, 11, choices1[i], i)

	if item == 12: #checkbox
		num_choices = vs.GetChoiceCount(dialogID, 11)
		for i in range(num_choices, -1, -1):
			vs.RemoveChoice(dialogID, 11, i)
				
		if data: #checkbox True
			for i in range(len(choices2)):
				vs.AddChoice(dialogID, 11, choices2[i], i)	
				
		if not data: #checkbox False
			for i in range(len(choices1)):
				vs.AddChoice(dialogID, 11, choices1[i], i)	



result = CreateMyDialog()

 

Edited by DomC
  • Like 1
Link to comment

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...