Source code for vinstall.core.render
#-*- coding: utf-8 -*-
"""The render module provides a Render class, which responsibility is to
allow access to the view objects at runtime.
"""
__author__ = "rbistolfi"
__all__ = ["Render"]
from .core import get_main_window, get_view
from .log import get_logger
LOG = get_logger(__name__)
[docs]class Render(object):
"""Given a set of model objects, find the proper view and setup window
properties.
"""
main_window_instance = None
def __init__(self, title, intro, *options):
"""Render initialization
"""
self.title = title
self.intro = intro
self.options = options
self.renderers = []
LOG.debug("Render instance created: title=%s intro=%s options=%s" %
(title, intro, options))
[docs] def get_renderer(self, model):
"""Given a model, return its view.
"""
ModelClass = type(model)
renderer = get_view(ModelClass)
renderer.window = self.main_window_instance
return renderer
@property
def main_window(self):
"""Lazy initialization of the main window object.
"""
if Render.main_window_instance is None:
LOG.debug("Creating main window instance")
MainWindowClass = get_main_window()
Render.main_window_instance = MainWindowClass()
return type(self).main_window_instance
[docs] def update_main_window(self):
"""Update the attributes of the main window instance and refresh the
view.
"""
LOG.debug("Main window initialized, setting up attributes")
self.main_window.title = self.title
self.main_window.intro = self.intro
self.main_window.widgets = self.get_widgets()
self.main_window.update()
LOG.debug("Main window configured: %s" % Render.main_window_instance)