Commit d8bfa602 authored by Frank Scholz's avatar Frank Scholz
Browse files

* make ''transition'' and ''display_time'' configurable

* add a ''cross-fading'' transition to the Clutter backend
parent 09eb00c7
......@@ -74,6 +74,18 @@ class Cadre(log.Loggable):
'no_thread_needed':True,
'name':name}
kwargs['transition'] = 'NONE'
try:
if self.config['transition'].upper() in self.get_available_transitions():
kwargs['transition'] = self.config['transition'].upper()
self.set_transition(self.config['transition'].upper())
except:
pass
try:
kwargs['display_time'] = int(self.config['display_time'])
except:
pass
self.canvas.set_title(name)
......@@ -173,6 +185,16 @@ class Cadre(log.Loggable):
def quit(self):
reactor.stop()
def get_available_transitions(self):
try:
return self.canvas.get_available_transitions()
except:
return ['NONE']
def set_transition(self,transition):
if transition in self.get_available_transitions():
self.canvas.transition = transition
def walk(self, path):
containers = []
filepath = FilePath(path)
......
......@@ -44,9 +44,20 @@ class CadreRenderer(log.Loggable):
self.controller = kwargs['controller']
try:
self.display_time = kwargs['display_time']
except KeyError:
self.display_time = 20
try:
self.display_transition = kwargs['transition']
except KeyError:
self.display_transition = 'NONE'
self.playcontainer = None
self.auto_next_image = None
self.display_loop = None
self.dlna_caps = ['playcontainer-0-1']
......@@ -63,7 +74,7 @@ class CadreRenderer(log.Loggable):
self.stop_auto_next_image()
connection_id = self.server.connection_manager_server.lookup_avt_id(self.current_connection_id)
if self.server.av_transport_server.get_variable('CurrentPlayMode').value in ['REPEAT_ALL']:
reactor.callLater(self.display_time, self.upnp_Next,InstanceID=0)
self.display_loop = reactor.callLater(self.display_time, self.upnp_Next,InstanceID=0)
def stop_auto_next_image(self):
if self.auto_next_image:
......@@ -387,6 +398,10 @@ class CadreRenderer(log.Loggable):
NewDisplayTime = int(kwargs['NewDisplayTime'])
if 0 <= NewDisplayTime <= 65535:
self.display_time = NewDisplayTime
try:
self.display_loop.delay(self.display_time)
except:
pass
if self.server:
self.server.av_transport_server.set_variable(InstanceID, 'X_COHERENCE_DisplayTime', self.display_time)
return {}
......@@ -398,6 +413,7 @@ class CadreRenderer(log.Loggable):
supported_transition_modes = self.server.av_transport_server.get_variable('X_COHERENCE_DisplayTransition',instance=InstanceID).allowed_values
if NewDisplayTransition in supported_transition_modes:
self.display_transition = NewDisplayTransition
self.controller.set_transition(NewDisplayTransition)
if self.server:
self.server.av_transport_server.set_variable(InstanceID, 'X_COHERENCE_DisplayTransition', self.display_transition)
return {}
......@@ -405,8 +421,6 @@ class CadreRenderer(log.Loggable):
def upnp_init(self):
self.current_connection_id = None
self.display_time = 20
self.display_transition = 'NONE'
self.server.connection_manager_server.set_variable(0, 'SinkProtocolInfo',
['http-get:*:image/jpeg:*',
'http-get:*:image/png:*',
......@@ -426,7 +440,7 @@ class CadreRenderer(log.Loggable):
self.server.av_transport_server.register_vendor_variable('X_COHERENCE_DisplayTransition',
evented='yes',
data_type='string',default_value=self.display_transition,
allowed_values=['NONE',])
allowed_values=self.controller.get_available_transitions())
self.server.av_transport_server.register_vendor_action('X_COHERENCE_SetDisplayTransition','optional',
(('InstanceID','in','A_ARG_TYPE_InstanceID'),('NewDisplayTransition','in','X_COHERENCE_DisplayTransition')))
self.server.av_transport_server.register_vendor_action('X_COHERENCE_GetDisplayTransition','optional',
......
......@@ -97,6 +97,8 @@ class Canvas(log.Loggable):
def __init__(self, fullscreen=1):
self.fullscreen = fullscreen
self.transition = 'FADE'
self.stage = clutter.Stage()
if self.fullscreen == 1:
self.stage.set_fullscreen(True)
......@@ -113,29 +115,165 @@ class Canvas(log.Loggable):
if self.fullscreen == 1:
self.stage.connect('button-press-event', lambda x,y: reactor.stop())
self.stage.connect('destroy', lambda x: reactor.stop())
group = clutter.Group()
self.stage.add(group)
self.texture = clutter.Texture()
self.texture.set_keep_aspect_ratio(True)
self.texture.set_size(display_width,display_height)
reflect = TextureReflection(self.texture)
reflect.set_reflection_height(display_height/3)
reflect.set_opacity(100)
x_pos = float((self.stage.get_width() - self.texture.get_width()) / 2)
group.add(self.texture, reflect)
group.set_position(x_pos, 20.0)
reflect.set_position(0.0, (self.texture.get_height() + 20))
#self.stage.connect('key-press-event', self.process_key)
self.texture_group = clutter.Group()
self.stage.add(self.texture_group)
self.texture_1 = clutter.Texture()
self.texture_1.set_opacity(0)
self.texture_1.set_keep_aspect_ratio(True)
self.texture_1.set_size(display_width,display_height)
self.texture_1.haz_image = False
self.texture_2 = clutter.Texture()
self.texture_2.set_opacity(0)
self.texture_2.set_keep_aspect_ratio(True)
self.texture_2.set_size(display_width,display_height)
self.texture_2.haz_image = False
self.texture_1.reflection = TextureReflection(self.texture_1)
self.texture_1.reflection.set_reflection_height(display_height/3)
self.texture_1.reflection.set_opacity(100)
self.texture_2.reflection = TextureReflection(self.texture_2)
self.texture_2.reflection.set_reflection_height(display_height/3)
self.texture_2.reflection.set_opacity(0)
x_pos = float((self.stage.get_width() - self.texture_1.get_width()) / 2)
self.texture_group.add(self.texture_1, self.texture_1.reflection)
self.texture_group.add(self.texture_2, self.texture_2.reflection)
self.texture_group.set_position(x_pos, 20.0)
self.texture_1.reflection.set_position(0.0, (self.texture_1.get_height() + 20))
self.texture_2.reflection.set_position(0.0, (self.texture_2.get_height() + 20))
def timeline_out_1_comleted(x):
self.info("timeline_out_1_comleted")
def timeline_out_2_comleted(x):
self.info("timeline_out_2_comleted")
def timeline_in_1_comleted(x):
self.info("timeline_in_1_comleted")
def timeline_in_2_comleted(x):
self.info("timeline_in_2_comleted")
self.texture_1.transition_fade_out_timeline = clutter.Timeline(2000)
self.texture_1.transition_fade_out_timeline.connect('completed',timeline_out_1_comleted)
alpha=clutter.Alpha(self.texture_1.transition_fade_out_timeline, clutter.EASE_OUT_SINE)
self.fade_out_texture_behaviour_1 = clutter.BehaviourOpacity(alpha=alpha, opacity_start=255, opacity_end=0)
self.fade_out_texture_behaviour_1.apply(self.texture_1)
self.fade_out_reflection_behaviour_1 = clutter.BehaviourOpacity(alpha=alpha, opacity_start=100, opacity_end=0)
self.fade_out_reflection_behaviour_1.apply(self.texture_1.reflection)
self.texture_1.transition_fade_out_timeline.add_marker_at_time('out_nearly_finished', 500)
self.texture_1.transition_fade_in_timeline = clutter.Timeline(2000)
self.texture_1.transition_fade_in_timeline.connect('completed',timeline_in_1_comleted)
alpha=clutter.Alpha(self.texture_1.transition_fade_in_timeline, clutter.EASE_OUT_SINE)
self.fade_in_texture_behaviour_1 = clutter.BehaviourOpacity(alpha=alpha, opacity_start=0, opacity_end=255)
self.fade_in_texture_behaviour_1.apply(self.texture_1)
self.fade_in_reflection_behaviour_1 = clutter.BehaviourOpacity(alpha=alpha, opacity_start=0, opacity_end=100)
self.fade_in_reflection_behaviour_1.apply(self.texture_1.reflection)
self.texture_2.transition_fade_out_timeline = clutter.Timeline(2000)
self.texture_2.transition_fade_out_timeline.connect('completed',timeline_out_2_comleted)
alpha=clutter.Alpha(self.texture_2.transition_fade_out_timeline, clutter.EASE_OUT_SINE)
self.fade_out_texture_behaviour_2 = clutter.BehaviourOpacity(alpha=alpha, opacity_start=255, opacity_end=0)
self.fade_out_texture_behaviour_2.apply(self.texture_2)
self.fade_out_reflection_behaviour_2 = clutter.BehaviourOpacity(alpha=alpha, opacity_start=100, opacity_end=0)
self.fade_out_reflection_behaviour_2.apply(self.texture_2.reflection)
self.texture_2.transition_fade_out_timeline.add_marker_at_time('out_nearly_finished', 500)
self.texture_2.transition_fade_in_timeline = clutter.Timeline(2000)
self.texture_2.transition_fade_in_timeline.connect('completed',timeline_in_2_comleted)
alpha=clutter.Alpha(self.texture_2.transition_fade_in_timeline, clutter.EASE_OUT_SINE)
self.fade_in_texture_behaviour_2 = clutter.BehaviourOpacity(alpha=alpha, opacity_start=0, opacity_end=255)
self.fade_in_texture_behaviour_2.apply(self.texture_2)
self.fade_in_reflection_behaviour_2 = clutter.BehaviourOpacity(alpha=alpha, opacity_start=0, opacity_end=100)
self.fade_in_reflection_behaviour_2.apply(self.texture_2.reflection)
self.texture_1.fading_score = clutter.Score()
self.texture_1.fading_score.append(timeline=self.texture_2.transition_fade_out_timeline)
self.texture_1.fading_score.append_at_marker(timeline=self.texture_1.transition_fade_in_timeline,parent=self.texture_2.transition_fade_out_timeline,marker_name='out_nearly_finished')
def score_1_started(x):
self.info("score_1_started")
def score_1_completed(x):
self.info("score_1_completed")
self.texture_1.fading_score.connect('started', score_1_started)
self.texture_1.fading_score.connect('completed', score_1_completed)
self.texture_2.fading_score = clutter.Score()
self.texture_2.fading_score.append(timeline=self.texture_1.transition_fade_out_timeline)
self.texture_2.fading_score.append_at_marker(timeline=self.texture_2.transition_fade_in_timeline,parent=self.texture_1.transition_fade_out_timeline,marker_name='out_nearly_finished')
def score_2_started(x):
self.info("score_2_started")
def score_2_completed(x):
self.info("score_2_completed")
self.texture_2.fading_score.connect('started', score_2_started)
self.texture_2.fading_score.connect('completed', score_2_completed)
self.in_texture = self.texture_1
self.out_texture = self.texture_2
self.stage.show()
def set_title(self,title):
self.stage.set_title(title)
def process_key(self,stage,event):
print "process_key", stage,event
def get_available_transitions(self):
return [str(x.replace('_transition_','')) for x in dir(self) if x.startswith('_transition_')]
def _transition_NONE(self):
self.in_texture.set_opacity(255)
self.in_texture.reflection.set_opacity(100)
self.out_texture.set_opacity(0)
self.out_texture.reflection.set_opacity(0)
self.out_texture,self.in_texture = self.in_texture,self.out_texture
def _transition_FADE(self):
if self.out_texture.haz_image == True:
self.texture_group.lower_child(self.out_texture)
self.texture_group.lower_child(self.out_texture.reflection)
self.in_texture.fading_score.start()
self.out_texture,self.in_texture = self.in_texture,self.out_texture
else:
self._transition_NONE()
def load_the_new_one(self,image,title):
self.warning("show image %r" % title)
if image.startswith("file://"):
filename = image[7:]
else:
#FIXME - we have the image as data already, there has to be
# a better way to get it into the texture
from tempfile import mkstemp
fp,filename = mkstemp()
os.write(fp,image)
os.close(fp)
remove_file_after_loading = True
#self.texture.set_load_async(True)
self.warning("loading image from file %r" % filename)
self.in_texture.set_from_file(filename=filename)
self.in_texture.haz_image = True
self.set_title(title)
try:
if remove_file_after_loading:
os.unlink(filename)
except:
pass
def show_image(self,image,title=''):
self.load_the_new_one(image,title)
function = getattr(self, "_transition_%s" % self.transition, None)
if function:
function()
return
self._transition_NONE()
def add_overlay(self,overlay):
screen_width,screen_height = self.stage.get_size()
texture = clutter.Texture()
......@@ -168,26 +306,4 @@ class Canvas(log.Loggable):
position_y = get_position(overlay['position_y'],overlay['width'])
print position_x, position_y
texture.set_position(position_x, position_y)
self.stage.add(texture)
def show_image(self,image,title=''):
#FIXME - we have the image as data already, there has to be
# a better way to get it into the texture
self.warning("show image %r" % title)
if image.startswith("file://"):
filename = image[7:]
else:
from tempfile import mkstemp
fp,filename = mkstemp()
os.write(fp,image)
os.close(fp)
remove_file_after_loading = True
#self.texture.set_load_async(True)
self.warning("loading image from file %r" % filename)
self.texture.set_from_file(filename=filename)
self.set_title(title)
try:
if remove_file_after_loading:
os.unlink(filename)
except:
pass
\ No newline at end of file
self.stage.add(texture)
\ No newline at end of file
......@@ -5,5 +5,7 @@
<autostart>yes</autostart>
<shuffle>yes</shuffle>
<fullscreen>no</fullscreen>
<transition>none</transition>
<display_time>10</display_time>
<repeat>yes</repeat>
</config>
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment