Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Moved generic functions out of main module

  • Loading branch information...
commit 36a1b06ba5977e08416bf903a398e95ac3f392a7 1 parent ff47c08
@johtso authored
Showing with 48 additions and 44 deletions.
  1. +1 −44 snipplr.py
  2. +47 −0 utils.py
View
45 snipplr.py
@@ -1,5 +1,4 @@
import os
-import threading
from xmlrpclib import ServerProxy, Error
import HTMLParser
from itertools import groupby
@@ -7,15 +6,7 @@
import sublime, sublime_plugin
-class Worker(threading.Thread):
- """A simple worker thread that stores the task result as a parameter."""
- def __init__(self, f):
- self.f = f
- self.result = None
- threading.Thread.__init__(self)
-
- def run(self):
- self.result = self.f()
+from utils import Worker, status, handle_thread
def get_api_key():
"""Loads API key from settings."""
@@ -27,40 +18,6 @@ def get_api_key():
return api_key
-def status(msg, thread=False):
- """Displays a message in status bar.
-
- thread - set to True if displaying message from a separate thread to use
- callback.
-
- """
- if not thread:
- sublime.status_message(msg)
- else:
- sublime.set_timeout(lambda: status(msg), 0)
-
-def handle_thread(thread, msg=None, cb=None, i=0, direction=1, width=8):
- """Displays an animated notification in the status bar while thread executes.
-
- msg - message to be displayed in status bar.
- cb - optional callback to be executed when thread completes.
-
- """
- if thread.is_alive():
- next = i + direction
- if next > width:
- direction = -1
- elif next < 0:
- direction = 1
- bar = [' ']*(width + 1)
- bar[i] = '='
- i += direction
- status('%s [%s]' % (msg, ''.join(bar)))
- sublime.set_timeout(lambda: handle_thread(thread, msg, cb, i,
- direction, width), 100)
- else:
- cb()
-
class SnipplrInsertCommand(sublime_plugin.TextCommand):
"""Search for snippet and insert it into document at cursor position."""
View
47 utils.py
@@ -0,0 +1,47 @@
+import threading
+
+import sublime
+
+class Worker(threading.Thread):
+ """A simple worker thread that stores the task result as a parameter."""
+ def __init__(self, f):
+ self.f = f
+ self.result = None
+ threading.Thread.__init__(self)
+
+ def run(self):
+ self.result = self.f()
+
+def status(msg, thread=False):
+ """Displays a message in status bar.
+
+ thread - set to True if displaying message from a separate thread to use
+ callback.
+
+ """
+ if not thread:
+ sublime.status_message(msg)
+ else:
+ sublime.set_timeout(lambda: status(msg), 0)
+
+def handle_thread(thread, msg=None, cb=None, i=0, direction=1, width=8):
+ """Displays an animated notification in the status bar while thread executes.
+
+ msg - message to be displayed in status bar.
+ cb - optional callback to be executed when thread completes.
+
+ """
+ if thread.is_alive():
+ next = i + direction
+ if next > width:
+ direction = -1
+ elif next < 0:
+ direction = 1
+ bar = [' ']*(width + 1)
+ bar[i] = '='
+ i += direction
+ status('%s [%s]' % (msg, ''.join(bar)))
+ sublime.set_timeout(lambda: handle_thread(thread, msg, cb, i,
+ direction, width), 100)
+ else:
+ cb()
Please sign in to comment.
Something went wrong with that request. Please try again.