Home Download Buy Blog Forum Support

[solved] Add notification to input panel.

[solved] Add notification to input panel.

Postby Cjkjvfnby on Tue Feb 21, 2012 9:58 pm

I use input panel to insert path. (change path in settings)

On on_change I want to show user if this path is valid. (os.paht exists)

Any Ideas how to do it?
Make text/background green/red
Add some text to begining of panel (close and reopen on on change? how can I close It?)
Other way?
Last edited by Cjkjvfnby on Fri Feb 24, 2012 10:50 pm, edited 1 time in total.
Cjkjvfnby
 
Posts: 20
Joined: Wed Feb 01, 2012 11:35 am

Re: Add notification to input panel.

Postby agibsonsw on Tue Feb 21, 2012 10:51 pm

I'm v.new to this but..

Code: Select all
self.window.active_view().run_command("hide_panel")


would/should(?) hide the panel - but this would trigger the 'on-done' event. I'm guessing that, as the input panel is also a View, then it would be possible to add text to it. Say adding ' xx' at the end of the line, until the path is found, then removing this text. But you could probably add text at the beginning of the line as well..

I'm also guessing that we can't change the text colour in the panel :?:. Hopefully someone will confirm or deny this. 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 agibsonsw on Tue Feb 21, 2012 11:46 pm

I got the following to work - it might be helpful 8-). If I type 'bob' in the input panel it precedes it with 'xx '. So it would need to be modified to start with 'Not found:', switch to 'Found:<four spaces> ', replacing the text each time.

Code: Select all
import sublime, sublime_plugin

class AndyOutput(sublime_plugin.WindowCommand):
    ignore = False
    the_input = None
    def run(self):
        self.the_input = self.window.show_input_panel('Andy>','', self.on_done, self.on_change, None)

    def on_done(self, text):
      pass

    def on_change(self, text):
        if self.ignore:
            return 
        try:
            if text == '':
                return
            if text[-3:] == 'bob':
                edit = self.the_input.begin_edit()
                self.the_input.insert(edit, 0, 'xx ')
                self.ignore = True
                self.the_input.end_edit(edit)
                self.ignore = False
        except ValueError:
            pass
"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 agibsonsw on Wed Feb 22, 2012 9:39 pm

I've had no response to my previous post as yet but, nevertheless, I'm pursuing this subject. The following opens the input panel beginning with the term 'Not found:'. If I eventually type 'bob' then the beginning text is replaced with 'Found: '. It then reverts to 'Not found:' until 'bob' appears again. It should be easy to replace 'bob' with the result of a file/path search.

Code: Select all
class AndyOutput(sublime_plugin.WindowCommand):
    ignore = False
    the_input = None
    def run(self):
        self.the_input = self.window.show_input_panel('Andy>','Not found:', self.on_done,
            self.on_change, None)
        self.ignore = False

    def on_done(self, text):
      pass

    def on_change(self, text):
        if self.ignore:
            return 
        try:
            if text == '':
                return
            sel = self.the_input.sel()[0]    ######### AttributeError
            sel_line =self.the_input.line(sel)
           
            if text[-3:] == 'bob' and text[0:3] == 'Not':
                edit = self.the_input.begin_edit()
                self.the_input.replace(edit, sublime.Region(sel_line.begin(),
                    sel_line.begin()+10), 'Found:    ')
                self.ignore = True
                self.the_input.end_edit(edit)
                self.ignore = False
            elif text[0:5] == 'Found':
                edit = self.the_input.begin_edit()
                self.the_input.replace(edit, sublime.Region(sel_line.begin(),
                    sel_line.begin()+10), 'Not Found:')
                self.ignore = True
                self.the_input.end_edit(edit)
                self.ignore = False
        except ValueError:
            pass

I do get an AttributeError: 'NoneType' object has no attribute 'sel' - at the line indicated, but the code still works (oddly). But.. I'm new to Python :D
"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 agibsonsw on Wed Feb 22, 2012 10:30 pm

The attribute error in my recent post is really bugging me. It only occurs when the file is first run. If anyone has an idea why this is happening, that would be great :D
"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 jps on Thu Feb 23, 2012 3:47 am

You can use sublime.status_message() to do this, which is what happens in the find panel if an invalid regex is entered
jps
Site Admin
 
Posts: 3071
Joined: Wed Mar 19, 2008 12:33 pm

Re: Add notification to input panel.

Postby agibsonsw on Thu Feb 23, 2012 9:29 am

jps wrote:You can use sublime.status_message() to do this, which is what happens in the find panel if an invalid regex is entered

Hello, and thank you.

Still learning, so I haven't wasted my time :lol:. I still need to know about this attribute error, but I figure I need to gen up on static and instance variables/attributes a bit.

Regards, 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 jps on Thu Feb 23, 2012 12:20 pm

The attribute error likely comes from 'the_input' being None, as on_change may be getting called once before show_input_panel returns
jps
Site Admin
 
Posts: 3071
Joined: Wed Mar 19, 2008 12:33 pm

Re: Add notification to input panel.

Postby agibsonsw on Thu Feb 23, 2012 1:15 pm

jps wrote:The attribute error likely comes from 'the_input' being None, as on_change may be getting called once before show_input_panel returns


Hello and thank you. I shouldn't have to initialize to None, so I'll re-examine my code a bit later.

Regards, 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 agibsonsw on Thu Feb 23, 2012 8:49 pm

I can get round my error with a simple 'except: return', which ignores the error first time around, but this is not good.

How can I obtain the Region of the input panel? Currently, I'm using a reference to the panel as 'the_input' but this creates the problem just discussed:

Code: Select all
def on_change(self, text):
    self.sel = self.the_input.sel()[0]    # the_input refers to the input panel (a self-reference)

How can I amend this to refer to the input panel, without using 'the_input' pl?

I appreciate that status_message() is the way to go - it's intended for this purpose :). But I know that it's possible to amend (edit) the input panel's text. But 'self.view.sel()[0]' doesn't work?!

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

Next

Return to Plugin Development

Who is online

Users browsing this forum: No registered users and 4 guests