SHARE
TWEET

Sublime example: Asking for multiple inputs

a guest May 1st, 2018 76 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import sublime
  2. import sublime_plugin
  3.  
  4.  
  5. class ExampleCommand(sublime_plugin.WindowCommand):
  6.     def handle_value(self, key_value, key_list, key_index, output_dict):
  7.         key = key_list[key_index]
  8.         output_dict[key] = key_value
  9.  
  10.         key_index += 1
  11.         if key_index < len(key_list):
  12.             self.handle_key(key_list, key_index, output_dict)
  13.         else:
  14.             print("Finished with: {}".format(output_dict))
  15.  
  16.     def handle_key(self, key_list, key_index, output_dict):
  17.         key = key_list[key_index]
  18.         self.window.show_input_panel(
  19.             "Value for {}".format(key),
  20.             output_dict.get(key, "foo"),
  21.             lambda v: self.handle_value(v, key_list, key_index, output_dict),
  22.             None, None)
  23.  
  24.     def run(self, my_dict):
  25.         keys = list(my_dict.keys())
  26.         if keys:
  27.             self.handle_key(keys, 0, my_dict)
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Top