Merge pull request #10 from philipdexter/master

Add the ability to rearrange modules
This commit is contained in:
enkore 2013-03-16 04:35:57 -07:00
commit 1457f0ab17
4 changed files with 18 additions and 3 deletions

View File

@ -23,7 +23,9 @@ class Status:
"""Register a new module.""" """Register a new module."""
if module: if module:
self.modules.append(module, *args, **kwargs) return self.modules.append(module, *args, **kwargs)
else:
return None
def run_command_endpoint(self): def run_command_endpoint(self):
for command in io.JSONIO(io=io.IOHandler(sys.stdin, open(os.devnull,"w")), skiplines=1).read(): for command in io.JSONIO(io=io.IOHandler(sys.stdin, open(os.devnull,"w")), skiplines=1).read():

View File

@ -3,6 +3,7 @@ import time
from .settings import SettingsBase from .settings import SettingsBase
from .threading import Manager from .threading import Manager
from .util import convert_position
__all__ = [ __all__ = [
"Module", "AsyncModule", "IntervalModule", "Module", "AsyncModule", "IntervalModule",
@ -10,6 +11,7 @@ __all__ = [
class Module(SettingsBase): class Module(SettingsBase):
output = None output = None
position = 0
def registered(self, status_handler): def registered(self, status_handler):
"""Called when this module is registered with a status handler""" """Called when this module is registered with a status handler"""
@ -19,7 +21,7 @@ class Module(SettingsBase):
if "name" not in self.output: if "name" not in self.output:
self.output["name"] = self.__name__ self.output["name"] = self.__name__
self.output["instance"] = str(id(self)) self.output["instance"] = str(id(self))
json.insert(0, self.output) json.insert(convert_position(self.position, json), self.output)
def on_click(self, button): def on_click(self, button):
if button == 1: # Left mouse button if button == 1: # Left mouse button
@ -27,6 +29,9 @@ class Module(SettingsBase):
elif button == 3: # Right mouse button elif button == 3: # Right mouse button
self.on_rightclick() self.on_rightclick()
def move(self, position):
self.position = position
def on_leftclick(self): def on_leftclick(self):
pass pass

View File

@ -46,6 +46,7 @@ class ModuleList(collections.UserList):
module = self.finder.instanciate_class_from_module(module, *args, **kwargs) module = self.finder.instanciate_class_from_module(module, *args, **kwargs)
module.registered(self.status_handler) module.registered(self.status_handler)
super().append(module) super().append(module)
return module
def get_by_id(self, find_id): def get_by_id(self, find_id):
find_id = int(find_id) find_id = int(find_id)
@ -94,3 +95,8 @@ class KeyConstraintDict(collections.UserDict):
def missing(self): def missing(self):
return self.required_keys - (self.seen_keys & self.required_keys) return self.required_keys - (self.seen_keys & self.required_keys)
def convert_position(pos, json):
if pos < 0:
pos = len(json) + (pos+1)
return pos

View File

@ -21,7 +21,7 @@ class IMAP(Backend):
required = ("host", "username", "password") required = ("host", "username", "password")
port = 993 port = 993
ssl = False ssl = True
imap_class = imaplib.IMAP4 imap_class = imaplib.IMAP4
connection = None connection = None
@ -51,3 +51,5 @@ class IMAP(Backend):
conn = self.get_connection() conn = self.get_connection()
if conn: if conn:
return len(conn.search(None,"UnSeen")[1][0].split()) return len(conn.search(None,"UnSeen")[1][0].split())
else:
sys.stderr.write("no connection")