terminator/terminatorlib/factory.py

77 lines
2.3 KiB
Python
Raw Normal View History

#!/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
class Factory(Borg):
"""Definition of a class that makes other classes"""
def __init__(self):
"""Class initialiser"""
Borg.__init__(self)
self.prepare_attributes()
def prepare_attributes(self):
"""Required by the borg, but a no-op here"""
pass
def isinstance(self, product, classtype):
"""Check if a given product is a particular type of object"""
if classtype == 'Terminal':
import terminal
return(isinstance(product, terminal.Terminal))
elif classtype == 'VPaned':
import paned
return(isinstance(product, paned.VPaned))
elif classtype == 'HPaned':
import paned
return(isinstance(product, paned.HPaned))
elif classtype == 'Paned':
import paned
return(isinstance(product, paned.Paned))
elif classtype == 'Notebook':
import notebook
return(isinstance(product, notebook.Notebook))
elif classtype == 'Container':
import container
return(isinstance(product, container.Container))
else:
err('Factory::isinstance: unknown class type: %s' % classtype)
return(False)
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))
def make_terminal(self, *args):
"""Make a Terminal"""
import terminal
return(terminal.Terminal())
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]))