Home Download Buy Blog Forum Support

[solved] Add notification to input panel.

Re: Add notification to input panel.

Postby agibsonsw on Thu Feb 23, 2012 9:52 pm

No worries ;) although I'm still interested to know how to refer to the input panel's Region directly (within the on_change event)..?

Using default text ('Not found:') in

Code: Select all
self.the_input = self.window.show_input_panel('Andy>','Not found:', self.on_done,
   self.on_change, self.on_cancel)

triggers the on_change event, and then referring to 'the_input' (within the event) causes an error because it doesn't yet exist. If I move the reference to 'the_input' further into the code then the problem doesn't arise:

Code: Select all
def on_change(self, text):
   if self.ignore:
      return 
   try:
      if text == '' or len(text) == 0:
         return
      if text[-3:] == 'bob' and text[0:3] == 'Not':
         self.sel = self.the_input.sel()[0]
         self.sel_line =self.the_input.line(self.sel)
         edit = self.the_input.begin_edit()

Alternatively, I could create a flag called 'first_call' and return directly if this is True.

When I've got this sussed I might write a short intro. guide myself (as there doesn't seem to be a straight-forward one available). Andy.
"I'm here to save your life. But if I'm going to do that, I'll need total uninanonynymity." Me Myself & Irene.
agibsonsw
 
Posts: 901
Joined: Fri Jan 27, 2012 9:11 pm

Re: Add notification to input panel.

Postby Cjkjvfnby on Fri Feb 24, 2012 10:49 pm

Thanks to everyone.

Code: Select all
class SetMabPathCommand(sublime_plugin.TextCommand):
    def __init__(self, *args, **kwargs):
        sublime_plugin.TextCommand.__init__(self, *args, **kwargs)
        self.settings = sublime.load_settings('Mab.sublime-settings')

    def run(self, edit, key='', val='', save=True):
        path = self.settings.get('mab_path')
        self.input = sublime.active_window().show_input_panel('input',
            path, self.on_done, self.on_change, None)
        self.on_change(path) # call it to colorify input
   
    def on_done(self, text):
        if os.path.exists(text):
            self.settings.set('mab_path', text)
            sublime.save_settings('Mab.sublime-settings')
        else:
            sublime.error_message('Path %s does not exists' % text)
   
    def on_change(self, text):
        if os.path.exists(text):
            scope = 'constant'
        else:
            scope= 'constant.character.escape'
        self.input.add_regions('regs', [sublime.Region(0, self.input.size())], scope)

Note: If I try to open input when input opened I get traceback in console.
Code: Select all
AttributeError: 'SetMabPathCommand' object has no attribute 'input'

But I do nothing. I need only one input at single time.
Cjkjvfnby
 
Posts: 20
Joined: Wed Feb 01, 2012 11:35 am

Re: [solved] Add notification to input panel.

Postby agibsonsw on Sat Feb 25, 2012 12:45 am

Note: If I try to open input when input opened I get traceback in console.


That sounds very much like the error I was discussing.
"I'm here to save your life. But if I'm going to do that, I'll need total uninanonynymity." Me Myself & Irene.
agibsonsw
 
Posts: 901
Joined: Fri Jan 27, 2012 9:11 pm

Re: [solved] Add notification to input panel.

Postby Cjkjvfnby on Sat Feb 25, 2012 11:26 am

agibsonsw wrote:
Note: If I try to open input when input opened I get traceback in console.


That sounds very much like the error I was discussing.



Yes. But it appears only if panel opened and does not affect opened panel.

Pseudocode:
Code: Select all
class Plugin(sublime_plugin....):
    input = None

def run(....)
    if not self.input:
         self.input = show_input(....)

def on_close_on_done():
     .....
     self.input = None

def on_change(...):
   if self.input:
       dooo


Code: Select all
class SetMabPathCommand(sublime_plugin.TextCommand):
    _input = None
    settings = sublime.load_settings('Mab.sublime-settings')

    def run(self, edit, key='', val='', save=True):
        if not self._input:
            path = self.settings.get('mab_path')
            self._input = sublime.active_window().show_input_panel('input',
                path, self.on_done, self.on_change, self.on_close)
            self.on_change(path)
   
    def on_done(self, text):
        if os.path.exists(text):
            self.settings.set('mab_path', text)
            sublime.save_settings('Mab.sublime-settings')
        else:
            sublime.error_message('Path %s does not exists' % text)

    def on_close(self):
        self._input = None

    def on_change(self, text):
        if self._input:
            if os.path.exists(text):
                scope = 'constant'
            else:
                scope= 'constant.character.escape'
            self._input.add_regions('regs', [sublime.Region(0, self._input.size())], scope)
Cjkjvfnby
 
Posts: 20
Joined: Wed Feb 01, 2012 11:35 am

Previous

Return to Plugin Development

Who is online

Users browsing this forum: No registered users and 6 guests