Home Download Buy Blog Forum Support

Events are not triggered

Events are not triggered

Postby Dr.Gigabit on Fri Feb 03, 2012 5:19 pm

Hi there,

I am playing with events, created the following simple plugin:

Code: Select all
import sublime, sublime_plugin

class EventDump(sublime_plugin.EventListener):
    def onNew(view):
        print "new file"
        view.insert(edit, 0, "Hello, World!")
   def on_activated(view):
      print "got focus"
   def on_selection_modified(view):
      print "on_selection_modified"


Saved it here ~/Library/Application Support/Sublime Text 2/Packages/EventDump/eventDump.py

But I don't see any relevant output on the console. Looks like events are not triggered.
Dr.Gigabit
 
Posts: 2
Joined: Fri Feb 03, 2012 5:13 pm

Re: Events are not triggered

Postby facelessuser on Fri Feb 03, 2012 5:36 pm

I see that you are new to Python, and you are new to the ST2 API. Hopefully this will clear some things up for you.

This works:
Code: Select all
import sublime, sublime_plugin


class EventDump(sublime_plugin.EventListener):
    def on_new(self, view):
        print "new file"
        edit = view.begin_edit()
        view.insert(edit, 0, "Hello, World!")
        view.end_edit(edit)

    def on_activated(self, view):
        print "got focus"

    def on_selection_modified(self, view):
        print "on_selection_modified"
facelessuser
 
Posts: 1567
Joined: Tue Apr 05, 2011 7:38 pm

Re: Events are not triggered

Postby Dr.Gigabit on Fri Feb 03, 2012 5:42 pm

facelessuser wrote:I see that you are new to Python, and you are new to the ST2 API. Hopefully this will clear some things up for you.

Both true :-)

Following your advise, I changed my code into:
Code: Select all
import sublime, sublime_plugin

class EventDump(sublime_plugin.EventListener):
    def onNew(self, view):
        print "new file"
        edit = view.begin_edit()
        view.insert(edit, 0, "Hello, World!")
        view.end_edit(edit)


By clicking ctrl+N (new buffer) - I should see "Hello, World!", right? But I don't see anything.
Should the "print" actually print something to the console?
Dr.Gigabit
 
Posts: 2
Joined: Fri Feb 03, 2012 5:13 pm

Re: Events are not triggered

Postby facelessuser on Fri Feb 03, 2012 5:48 pm

There are some subtleties you are missing.

The event is called on_new not onNew. If you copy exactly what I posted, you will see my code works.
facelessuser
 
Posts: 1567
Joined: Tue Apr 05, 2011 7:38 pm

Re: Events are not triggered

Postby Cjkjvfnby on Fri Feb 03, 2012 9:24 pm

Dr.Gigabit wrote:But I don't see any relevant output on the console. Looks like events are not triggered.


Sublime Text 2 api
http://www.sublimetext.com/docs/2/api_reference.html
Cjkjvfnby
 
Posts: 20
Joined: Wed Feb 01, 2012 11:35 am


Return to Plugin Development

Who is online

Users browsing this forum: No registered users and 6 guests