Sublime Forum

2 show_input_panels in a row

#1

Hello, if I try to get two input panels to show in a row, only the second one is shown ( I know because of the caption).

what are my options here?
I need to get 2 or 3 values from the user.

0 Likes

#2

You would need to post some code for people to help. But one suggestion is to require three inputs separated by some delimiter. Then you only need one panel, but if you want three, I think people would need to see what you are doing.

0 Likes

#3

Hello,
code is pretty straight forward

[code] def run(self):
json_data=open(self.window.folders()[0]+’/deploy_vars.json’)
self.data = json.load(json_data)
json_data.close()
self.getOrg()
self.getUser(data)
def getOrg(self):
if self.data’org’]:
print(“got org”)
self.org = self.data’org’]
else:
print(“did not get org”)
self.window.show_input_panel(“Org name:”,"",self.done_org,None,self.cancel)

def getUser(self):
	if self.data'username']:
		print("got user")
		self.username = self.data'username']
	else:
		self.window.show_input_panel("User name:","",self.done_user,None,self.cancel)
def done_user(self,data):
	self.user = data
def done_org(self,data):
	self.org = data
def cancel(self):
	print("user canceled")[/code]

with this I get only the “User Name” captioned input dialog…

I need from one to three values depending on what values I have, I thought about delimiting them, but really it is very error prone…

0 Likes

#4

Your problem is simply a logic error. You are opening the second input panel before the first ever closes. And since only one can be open at once…

Here’s your fix:
[pre=#232628]import sublime
import sublime_plugin
import json

class TestCommand(sublime_plugin.WindowCommand):
def run(self):
json_data=open(self.window.folders()0]+’/deploy_vars.json’)
self.data = json.load(json_data)
json_data.close()
self.getOrg()

def getOrg(self):
if self.data’org’]:
print(“got org”)
self.org = self.data’org’]
self.getUser()
else:
print(“did not get org”)
self.window.show_input_panel(“Org name:”,"",self.done_org,None,self.cancel)

def getUser(self):
if self.data’username’]:
print(“got user”)
self.username = self.data’username’]
else:
self.window.show_input_panel(“User name:”,"",self.done_user,None,self.cancel)

def done_user(self,data):
self.user = data

def done_org(self,data):
self.org = data
self.getUser()

def cancel(self):
print(“user canceled”)[/pre]

0 Likes

#5

thank you for the reply
I tried chaining them like this, but it did not work ( that was before submiting to forum).
And sorry to say it does not work… invoking the self.getUser() method from done_org() does not display a new input field.

0 Likes

#6

Sigh…I have a lot of experience with Sublime plugins and I personally tested this on ST3 (minus reading in the json; I just created a dictionary with “org” and “username” set to “False”). It pops up a second input after the first and only if it is required by the logic you laid out. That is the only way this can and will work. You will never get two at the same time if that is what you are wanting. This way works just fine assuming your code doesn’t have other errors you are introducing.

Whatever though, good luck on your plugin.

0 Likes

#7

[quote=“facelessuser”]

Sigh…I have a lot of experience with Sublime plugins and I personally tested this on ST3 (minus reading in the json; I just created a dictionary with “org” and “username” set to “False”). It pops up a second input after the first and only if it is required by the logic you laid out. That is the only way this can and will work. You will never get two at the same time if that is what you are wanting. This way works just fine assuming your code doesn’t have other errors you are introducing.

Whatever though, good luck on your plugin.[/quote]

I’m not doubting your experience or expertise, however using the code I only see one of the input dialogs come up. And no I do not expect them to come at the same time.

Can you send me a link to the plugin as you tried it so I can reproduce here?
thank you for your help

0 Likes

#8

This is probably due to more logic issues. You will need to debug such things.

Sure, this works just fine. It forces the evaluation of self.data’org’] to be false and open the input and forces self.data’username’] to do the same:

[pre=#232628]import sublime
import sublime_plugin
import json

class TestCommand(sublime_plugin.WindowCommand):
def run(self):
# json_data=open(self.window.folders()[0]+’/deploy_vars.json’)
# self.data = json.load(json_data)
# json_data.close()
self.data = {“org”: False, “username”:False}
self.getOrg()

def getOrg(self):
if self.data’org’]:
print(“got org”)
self.org = self.data’org’]
self.getUser()
else:
print(“did not get org”)
self.window.show_input_panel(“Org name:”,"",self.done_org,None,self.cancel)

def getUser(self):
if self.data’username’]:
print(“got user”)
self.username = self.data’username’]
else:
self.window.show_input_panel(“User name:”,"",self.done_user,None,self.cancel)

def done_user(self,data):
self.user = data

def done_org(self,data):
self.org = data
self.getUser()

def cancel(self):
print(“user canceled”)[/pre]

0 Likes

#9

Awesome, you are right it was a logic error, thank you for your help.

0 Likes