2009-11-24 23:47:32 +00:00
|
|
|
#!/usr/bin/python
|
|
|
|
# Terminator by Chris Jones <cmsj@tenshu.net>
|
|
|
|
# GPL v2 only
|
|
|
|
"""factory.py - Maker of objects"""
|
|
|
|
|
|
|
|
from borg import Borg
|
|
|
|
from util import dbg, err
|
|
|
|
|
2009-11-24 23:49:03 +00:00
|
|
|
# pylint: disable-msg=R0201
|
|
|
|
# pylint: disable-msg=W0613
|
2009-11-24 23:47:32 +00:00
|
|
|
class Factory(Borg):
|
|
|
|
"""Definition of a class that makes other classes"""
|
|
|
|
def __init__(self):
|
|
|
|
"""Class initialiser"""
|
2009-12-22 00:25:05 +00:00
|
|
|
Borg.__init__(self, self.__class__.__name__)
|
2009-11-24 23:47:32 +00:00
|
|
|
self.prepare_attributes()
|
|
|
|
|
|
|
|
def prepare_attributes(self):
|
|
|
|
"""Required by the borg, but a no-op here"""
|
|
|
|
pass
|
|
|
|
|
2009-11-25 00:37:29 +00:00
|
|
|
def isinstance(self, product, classtype):
|
|
|
|
"""Check if a given product is a particular type of object"""
|
2009-12-09 13:22:27 +00:00
|
|
|
types = {'Terminal': 'terminal',
|
|
|
|
'VPaned': 'paned',
|
|
|
|
'HPaned': 'paned',
|
|
|
|
'Paned': 'paned',
|
|
|
|
'Notebook': 'notebook',
|
2009-12-10 13:20:03 +00:00
|
|
|
'Container': 'container',
|
|
|
|
'Window': 'window'}
|
2009-12-09 13:22:27 +00:00
|
|
|
if classtype in types.keys():
|
2010-01-04 13:46:55 +00:00
|
|
|
# This is quite ugly, but we're importing from the current
|
|
|
|
# directory if that makes sense, otherwise falling back to
|
|
|
|
# terminatorlib. Someone with real Python skills should fix
|
|
|
|
# this to be less insane.
|
|
|
|
try:
|
|
|
|
module = __import__(types[classtype], None, None, [''])
|
|
|
|
except ImportError, ex:
|
|
|
|
module = __import__('terminatorlib.%s' % types[classtype],
|
|
|
|
None, None, [''])
|
2009-12-09 13:22:27 +00:00
|
|
|
return(isinstance(product, getattr(module, classtype)))
|
2009-11-25 00:37:29 +00:00
|
|
|
else:
|
|
|
|
err('Factory::isinstance: unknown class type: %s' % classtype)
|
|
|
|
return(False)
|
|
|
|
|
2009-11-24 23:47:32 +00:00
|
|
|
def make(self, product, *args):
|
|
|
|
"""Make the requested product"""
|
|
|
|
try:
|
|
|
|
func = getattr(self, 'make_%s' % product.lower())
|
|
|
|
except AttributeError:
|
|
|
|
err('Factory::make: requested object does not exist: %s' % product)
|
|
|
|
return(None)
|
|
|
|
|
|
|
|
dbg('Factory::make: created a %s' % product)
|
|
|
|
return(func(args))
|
|
|
|
|
2010-01-04 13:04:46 +00:00
|
|
|
def make_window(self, *args):
|
|
|
|
"""Make a Window"""
|
|
|
|
import window
|
2010-01-04 13:11:16 +00:00
|
|
|
return(window.Window())
|
2010-01-04 13:04:46 +00:00
|
|
|
|
2009-11-24 23:47:32 +00:00
|
|
|
def make_terminal(self, *args):
|
|
|
|
"""Make a Terminal"""
|
|
|
|
import terminal
|
2010-01-04 13:11:16 +00:00
|
|
|
return(terminal.Terminal())
|
2009-11-24 23:47:32 +00:00
|
|
|
|
|
|
|
def make_hpaned(self, *args):
|
|
|
|
"""Make an HPaned"""
|
|
|
|
import paned
|
|
|
|
return(paned.HPaned())
|
|
|
|
|
|
|
|
def make_vpaned(self, *args):
|
|
|
|
"""Make a VPaned"""
|
|
|
|
import paned
|
|
|
|
return(paned.VPaned())
|
|
|
|
|
|
|
|
def make_notebook(self, *args):
|
|
|
|
"""Make a Notebook"""
|
|
|
|
import notebook
|
|
|
|
return(notebook.Notebook(args[0][0]))
|
|
|
|
|