1 # -*- coding: utf-8; -*-
3 #This Class contains Code from http://cheeseshop.python.org/pypi/sprinkles
4 # License :: OSI Approved :: MIT License
5 # Author: Andy Smith <sprinkles_py at anarkystic com>
6 # Home Page: http://an9.org/w/SprinklesPy
14 #Prototype, subclass it to creat a Plugin
15 class SidebarPlugin(gtk
.VBox
):
16 name
= "Default Name, forgot to set it?"
17 def __init__(self
, ui
):
18 gtk
.VBox
.__init
__(self
)
22 pass #to be overwritten
23 def on_connection(self
):
26 class ResultViewPlugin(gtk
.HBox
):
28 def __init__(self
, ui
, result
):
29 gtk
.HBox
.__init
__(self
)
34 raise Exception( "Plugin:: update() should be overwritten" )
37 print "on_init should be overwritten"
39 class QueryViewPlugin(gtk
.HBox
):
41 def __init__(self
, db
, result
):
42 gtk
.HBox
.__init
__(self
)
49 for root
, dirs
, files
in os
.walk(path
, topdown
=False):
51 if not str(file).startswith(".") and str(file).endswith(".py"):
52 ret
.append(os
.path
.join(root
, file))
55 def fromPath(path
, subclass
=None):
57 return issubclass(item
, subclass
)
59 print "Plugins: "+'Looking for sprinkles in path: %s...'%(path)
62 files
= get_files(path
)
64 print "Plugins: "+'Found file: %s'%(f)
65 loaded
= fromFile(os
.path
.dirname(f
), os
.path
.basename(f
))
68 print "Plugins: "+'Filtering with %s'%(subclass)
69 o
= filter(filterer
, o
)
70 print "Plugins: Passed: %s"%(o)
73 def fromFile(path
, filename
, filterer
=None):
75 mod_name
= os
.path
.splitext(filename
)[0]
78 fp
, pathname
, desc
= imp
.find_module(mod_name
,[path
])
80 new_mod
= imp
.load_module(mod_name
,fp
,pathname
,desc
)
81 print "Plugins: "+'Loaded: %s'%(new_mod)
84 except ImportError, err
:
85 print "Plugins: "+'Failed to import %s, %s'%(mod_name
, err
)
88 o
= fromModule(new_mod
)
90 o
= filter(filterer
, o
)
93 def fromModule(mod
, filterer
=None):
95 if type(mod
) is type(""):
97 if hasattr(mod
, "EXPORTS"):
98 s
= getattr(mod
, "EXPORTS")
100 #s = [getattr(mod, x) for x in dir(mod)]
102 #s = filter(lambda _: (type(_) is type(object)), s)
103 #o = filter(SidebarPlugin.implementedBy, s)
105 #print "Plugins: "+"Found sprinkles: %s"%(o)
107 # print "Plugins: "+'Filtering %s with %s'%(o, filterer)
108 # o = filter(filterer, o)