Iām participating in the process of learning how to create Sublime Text 2 plugins. One of the things I would like to do is to take any selected text, check if the site will return 200 to this address, and then put some information in the quick access panel (and yes I know that I have to do the url look in the stream so that it does not block the main user interface). I currently have:
import sublime import sublime_plugin import urllib2 class CheckUrlPanel(sublime_plugin.WindowCommand): def quick_panel(self, messages, flags): self.window.show_quick_panel(messages, None, flags) class CheckUrlsCommand(sublime_plugin.TextCommand): def run(self, edit): urls = [] selections = self.view.sel() for selection in selections: urls.append(self.view.substr(selection)) messages = self.validate_urls(urls) panel = CheckUrlPanel() panel.quick_panel(messages, sublime.MONOSPACE_FONT) def validate_urls(self, urls): messages = [] for url in urls: try: request = urllib2.Request(url, headers={ "User-Agent" : "Sublime URL Checker" }) response = urllib2.urlopen(request, timeout=3) message = '"%s" is a valid URL.' % url except Exception as (e): message = '"%s" is an invalid URL.' % url messages.append(message) return messages
The error I am getting is:
Traceback (most recent call last): File "./sublime_plugin.py", line 362, in run_ File "./CheckUrls.py", line 19, in run panel = CheckUrlPanel() TypeError: __init__() takes exactly 2 arguments (1 given)
The problem is that I do not know how to properly initialize the WindowCommand class, and I can not find the documentation for it. Any help or tips here would be greatly appreciated.
source share