2012-04-25 22:29:19 +02:00
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
|
2014-01-10 18:47:21 +01:00
|
|
|
import warnings
|
|
|
|
|
2012-03-16 12:28:42 +01:00
|
|
|
|
2013-03-01 17:13:12 +01:00
|
|
|
from openslides.config.api import config
|
2012-11-07 21:12:52 +01:00
|
|
|
|
2014-01-10 18:47:21 +01:00
|
|
|
from .exceptions import ProjectorExceptionWarning
|
|
|
|
|
2012-06-11 13:43:48 +02:00
|
|
|
|
2013-04-15 10:40:47 +02:00
|
|
|
class Overlay(object):
|
|
|
|
"""
|
|
|
|
Represents an overlay which can be seen on the projector.
|
|
|
|
"""
|
2012-04-25 17:17:24 +02:00
|
|
|
|
2013-08-04 12:59:11 +02:00
|
|
|
def __init__(self, name, get_widget_html, get_projector_html,
|
|
|
|
get_javascript=None, allways_active=False):
|
2013-04-15 10:40:47 +02:00
|
|
|
self.name = name
|
|
|
|
self.widget_html_callback = get_widget_html
|
|
|
|
self.projector_html_callback = get_projector_html
|
2013-08-04 12:59:11 +02:00
|
|
|
self.javascript_callback = get_javascript
|
|
|
|
self.allways_active = allways_active
|
2012-04-25 17:17:24 +02:00
|
|
|
|
2014-01-10 18:47:21 +01:00
|
|
|
def __repr__(self):
|
|
|
|
return self.name
|
|
|
|
|
2013-04-15 10:40:47 +02:00
|
|
|
def get_widget_html(self):
|
2013-09-25 10:01:01 +02:00
|
|
|
"""
|
|
|
|
Returns the html code for the overlay widget.
|
|
|
|
|
|
|
|
Can return None, if the widget does not want to be in the widget.
|
|
|
|
"""
|
2013-08-04 12:59:11 +02:00
|
|
|
value = None
|
|
|
|
if self.widget_html_callback is not None:
|
|
|
|
value = self.widget_html_callback()
|
|
|
|
return value
|
2012-04-16 16:35:30 +02:00
|
|
|
|
2013-04-15 10:40:47 +02:00
|
|
|
def get_projector_html(self):
|
2013-09-25 10:01:01 +02:00
|
|
|
"""
|
|
|
|
Returns the html code for the projector.
|
|
|
|
"""
|
2013-11-24 17:19:14 +01:00
|
|
|
try:
|
|
|
|
value = self.get_html_wrapper(self.projector_html_callback())
|
|
|
|
except Exception as exception:
|
2014-01-10 18:47:21 +01:00
|
|
|
warnings.warn('%s in overlay "%s": %s'
|
|
|
|
% (type(exception).__name__, self, exception),
|
|
|
|
ProjectorExceptionWarning)
|
|
|
|
value = ''
|
2013-11-24 17:19:14 +01:00
|
|
|
return value
|
2013-08-04 12:59:11 +02:00
|
|
|
|
|
|
|
def get_javascript(self):
|
2013-09-25 10:01:01 +02:00
|
|
|
"""
|
|
|
|
Returns the java-script code for the projector.
|
|
|
|
"""
|
2013-08-04 12:59:11 +02:00
|
|
|
if self.javascript_callback is None:
|
|
|
|
value = {}
|
|
|
|
else:
|
|
|
|
value = self.javascript_callback()
|
|
|
|
return value
|
|
|
|
|
|
|
|
def get_html_wrapper(self, inner_html):
|
2013-09-25 10:01:01 +02:00
|
|
|
"""
|
|
|
|
Returns the inner_html wrapped in a div.
|
|
|
|
|
|
|
|
The html-id of the div is "overlay_OVERLAYNAME"
|
|
|
|
"""
|
2013-08-04 12:59:11 +02:00
|
|
|
full_html = ''
|
|
|
|
if inner_html is not None:
|
|
|
|
full_html = '<div id="overlay_%s">%s</div>' % (self.name, inner_html)
|
|
|
|
return full_html
|
2012-04-16 16:35:30 +02:00
|
|
|
|
2013-04-15 10:40:47 +02:00
|
|
|
def is_active(self):
|
2013-09-25 10:01:01 +02:00
|
|
|
"""
|
|
|
|
Returns True if the overlay is activated. False in other case.
|
|
|
|
"""
|
2013-08-04 12:59:11 +02:00
|
|
|
return self.allways_active or self.name in config['projector_active_overlays']
|
|
|
|
|
|
|
|
def set_active(self, active):
|
|
|
|
"""
|
2013-10-03 21:49:51 +02:00
|
|
|
Publish or depublish the overlay on the projector.
|
2013-08-04 12:59:11 +02:00
|
|
|
|
|
|
|
publish, if active is true,
|
|
|
|
depublish, if active is false.
|
|
|
|
"""
|
|
|
|
active_overlays = set(config['projector_active_overlays'])
|
|
|
|
if active:
|
|
|
|
active_overlays.add(self.name)
|
|
|
|
else:
|
|
|
|
active_overlays.discard(self.name)
|
|
|
|
config['projector_active_overlays'] = list(active_overlays)
|
2013-04-15 15:47:18 +02:00
|
|
|
|
|
|
|
def show_on_projector(self):
|
2013-09-25 10:01:01 +02:00
|
|
|
"""
|
|
|
|
Retruns True if the overlay should be shoun on the projector.
|
|
|
|
"""
|
2013-03-18 12:34:47 +01:00
|
|
|
return self.is_active() and self.get_projector_html() is not None
|