Home Download Buy Blog Forum Support

'module' object has no attribute 'Plugin'

'module' object has no attribute 'Plugin'

Postby rsk82 on Thu Oct 10, 2013 10:06 pm

I try to learn how to write a ST3 plugin. I tried with code from this page: http://www.sublimetext.com/docs/plugin-examples #Events.

The first error that pops up is "invalid syntax" at print command. Ok, I realized that this is python3 so I added the brackets.
Then next error emerges: No module named 'sublimeplugin'. So I remember in some examples that people use the underscore in this name. Ok, that killed this one.
But then comes the third: 'module' object has no attribute 'Plugin' - and I don't know what to do next.
So at the end I looked into 'sublime_plugin' module by dir command and, indeed there was no any Plugin class, but I saw something called "EventListener", so I renamed it. And the result is that the code does not show any error messages but the print statements also won't show up.

ST version - 3047

Code: Select all
import sublime, sublime_plugin 
 
class EventDump(sublime_plugin.EventListener): 
    def onLoad(self, view): 
        print(view.fileName(), "just got loaded")
 
    def onPreSave(self, view): 
        print(view.fileName(), "is about to be saved")
 
    def onPostSave(self, view): 
        print(view.fileName(), "just got saved")
         
    def onNew(self, view): 
        print("new file")
 
    def onModified(self, view): 
        print(view.fileName(), "modified")
 
    def onActivated(self, view): 
        print(view.fileName(), "is now the active view")
 
    def onClose(self, view): 
        print(view.fileName(), "is no more")
 
    def onClone(self, view): 
        print(view.fileName(), "just got cloned")
rsk82
 
Posts: 8
Joined: Sat Feb 09, 2013 6:43 pm

Re: 'module' object has no attribute 'Plugin'

Postby sublimator on Fri Oct 11, 2013 1:51 pm

Code: Select all
    def onModified(self, view): 
        print(view.fileName(), "modified")

Has become

Code: Select all
    def on_modified(self, view): 
        print(view.file_name(), "modified")
 


The API in version 2+ of ST conforms to the PEP8 python naming conventions, for example there is now under_score instead of camelCase.
See: https://readthedocs.org/projects/sublim ... mentation/
It is better to remain silent and be thought a fool, than to speak out and remove all doubt
sublimator
 
Posts: 649
Joined: Thu Mar 20, 2008 5:41 am


Return to Plugin Development

Who is online

Users browsing this forum: Exabot [Bot] and 8 guests