22 |
__version__ = "$Revision$" |
__version__ = "$Revision$" |
23 |
|
|
24 |
# base imports |
# base imports |
25 |
import sys, os |
import sys, os, string |
26 |
# circus imports |
# circus imports |
27 |
import module, config, display |
import module, config, display |
28 |
# Xlib imports |
# Xlib imports |
37 |
display = None |
display = None |
38 |
screen = None |
screen = None |
39 |
events = None |
events = None |
40 |
module_events = [range(0, 36)] |
|
41 |
|
# Why do I need to declare this as a dict? |
42 |
|
modules = {"foo" : "bar"} |
43 |
|
|
44 |
|
# ...and this as an arry of array's... |
45 |
|
module_events = {} |
46 |
|
|
47 |
def __init__(self, d = None): |
def __init__(self, d = None): |
48 |
# FIXME: Do some work on the config defaults |
# FIXME: Do some work on the config defaults |
53 |
else: |
else: |
54 |
self.display = display.Display() |
self.display = display.Display() |
55 |
|
|
56 |
if self.display is not None: |
# Moved this to startup py script |
57 |
os.environ['DISPLAY'] = self.display.get_display_name() |
#if self.display: |
58 |
|
# os.environ['DISPLAY'] = self.display.get_display_name() |
59 |
|
|
60 |
self.screen = self.display.screen() |
self.screen = self.display.screen() |
61 |
|
|
62 |
# Setup event masks (events to listen for) |
# Setup event masks (events to listen for) |
63 |
|
# XXX: which do we really want? all? |
64 |
self.screen.root.change_attributes(event_mask = |
self.screen.root.change_attributes(event_mask = |
65 |
X.KeyPressMask | |
X.KeyPressMask | |
66 |
X.KeyReleaseMask | |
X.KeyReleaseMask | |
110 |
print "importing modules" |
print "importing modules" |
111 |
|
|
112 |
|
|
113 |
def load_module(self, module): |
def _import_name(self, modulename, name): |
114 |
for e in module.my_events: |
"""Used as: |
115 |
if self.module_events[e]: |
from <modulename> import <name> |
116 |
self.module_events[e] = module |
""" |
117 |
else: |
try: |
118 |
self.module_events[e].append(module) |
module = __import__(modulename, globals(), locals(), [name]) |
119 |
print "crap" |
print "HOLY CRAP IT WORKED" |
120 |
|
except ImportError: |
121 |
|
print "ImportError" |
122 |
|
return None |
123 |
|
return vars(module)[name] |
124 |
|
|
125 |
|
def load_module(self, module_name): |
126 |
|
|
127 |
|
# Load the module |
128 |
|
Module = self._import_name("Circus" + module_name + "." + string.lower(module_name), "MyModule") |
129 |
|
|
130 |
|
print Module |
131 |
|
|
132 |
|
# add it to our modules |
133 |
|
self.modules.setdefault(module_name, Module()) |
134 |
|
|
135 |
|
#self.modules.append(Module()) |
136 |
|
print self.modules |
137 |
|
print self.modules['Keybindings'] |
138 |
|
print dir(self.modules['Keybindings']) |
139 |
|
|
140 |
|
for e in self.modules[module_name].my_events: |
141 |
|
# Uh, this test should do something diff...heh |
142 |
|
print self.module_events |
143 |
|
print e |
144 |
|
|
145 |
|
self.module_events.setdefault(e, {})[module_name] = 1 |
146 |
|
|
147 |
|
#if self.module_events[e]: |
148 |
|
# self.module_events[e].append(self.modules[module_name].my_events) |
149 |
|
#else: |
150 |
|
# self.module_events[e].append(self.modules[module_name].my_events) |
151 |
|
# print "crap" |
152 |
|
|
153 |
# Could just use __init__ for this stuff in the module, but... |
# Could just use __init__ for this stuff in the module, but... |
154 |
module._load() |
self.modules[module_name]._load() |
155 |
|
|
156 |
|
|
157 |
def unload_module(self, module): |
def unload_module(self, module_name): |
158 |
# undo what we did in load_module |
# undo what we did in load_module |
159 |
# :) |
# :) |
160 |
|
|
161 |
module._unload() |
self.modules[module_name]._unload() |
162 |
|
|
163 |
|
|