def __init__(self,**kwargs) :
            super(VideoPlayer,self).__init__(**kwargs)

            #new events
            self.register_event_type('on_mute')
            self.register_event_type('on_unmute')
            self.register_event_type('on_start')
            self.register_event_type('on_stop')
            self.register_event_type('on_fullscreen')
            self.register_event_type('on_leave_fullscreen')
            
            self.video = Video(source = self.source, play=self.play, options = self.options , size_hint = (1,1))
            #delay to load the video before launching it
            Clock.schedule_once(self.start,0.2)
            Clock.schedule_once(self.stop,2.4)             
            
            #buttons box
            self.buttons = BoxLayout(orientation = 'horizontal', size_hint = (None, None), size = (self.video.width, 30 ) )
            self.buttons.padding = 5 
            self.buttons.spacing = 5

            #play button
            self.play_button = SuperButton2(text ='', background_normal= 'video_player/style/1318898242_media-play.png', background_down= 'video_player/style/1318898242_media-play.png', size_hint = (None, None), size = (20, 20) )
            self.play_button.bind( on_press = self.start_stop_button )
            self.buttons.add_widget( self.play_button )
            #sound button
            self.sound_button = SuperButton2(text ='', background_normal = 'video_player/style/1318898261_media-volume-0.png', background_down = 'video_player/style/1318898261_media-volume-0.png', size_hint = (None, None), size = (20, 20) )
            self.sound_button.bind( on_press = self.mute_unmute_button )
            self.buttons.add_widget( self.sound_button )
            #fullscreen 
            self.fullscreen_button = SuperButton(text ='', background_normal = 'video_player/style/fullscreen-logo.png', background_down = 'video_player/style/fullscreen-logo.png', size_hint = (None, None), size = (20, 20) )
            self.fullscreen_button.bind(on_press = self.fullscreen_button_down )
            self.buttons.add_widget( self.fullscreen_button )
            #duration bar
            self.duration = -1
            self.progress_bar = ProgressBar( size_hint = (1, 1)  )
            self.progress_bar.bind(on_touch_move = self.move_to_position)
            self.buttons.add_widget( self.progress_bar )
            #manage appearance counter
            self.last_touch_down_time = 0
            #fullscreen status
            self.full_screen = False
            
            #main play button
            self.main_play_button = SuperButton(text ='', background_normal= 'video_player/style/A-play-T3.png', size_hint = (None, None), size = (50, 50) )
            self.main_play_button.bind( on_press = self.start )
            self.add_widget( self.main_play_button )
                      
            #refresh bar position and size
            Clock.schedule_interval(self.refresh_player,0.005)    

            self.add_widget(self.video)
Exemple #2
0
    def add_button(self, place):
        pos = self.geometry_squares[str(place)].pos
        buttons = GridLayout(cols=2, row_force_default=True, row_default_height=self.element_size[1]*0.5, size = self.element_size, pos = pos, spacing = 3 )
        but1 = SuperButton(background_normal = 'style/bar/slider-picto-type-off.png',background_down = 'style/bar/slider-picto-type-on.png')
        but1.bind(on_press = self.sort_by_app_type)
        but2 = Button(background_normal = 'style/bar/slider-picto-ABC-off.png',background_down = 'style/bar/slider-picto-ABC-on.png')
        but2.bind(on_press = self.sort_by_title)
        but3 = Button(background_normal = 'style/bar/slider-picto-90-off.png',background_down = 'style/bar/slider-picto-90-on.png')
        but3.bind(on_press = self.rotate_images)        
        but4 = Button(background_normal = 'style/bar/slider-picto-preSet-off.png',background_down = 'style/bar/slider-picto-preSet-on.png')

        buttons.add_widget(but1)
        buttons.add_widget(but2)
        buttons.add_widget(but3)  
        buttons.add_widget(but4)     
        self.layout.add_widget(buttons)
Exemple #3
0
 def __init__(self,**kwargs):
     super(Bar,self).__init__(**kwargs)
     self.apps = self.app.field.init_apps()
     self.size_hint = (None,1)
     #self.width = 135
     self.padding_left = int((self.width - self.element_size[0])/2) 
     self.geometry_squares = {}
     self.images = {}
     self.sorting = []  
     #self.scroll = ScrollView( size_hint = (None, None), width = 130, height = 1000 )
     #self.add_widget(self.scroll) 
     self.layout = Widget(size_hint = (None, None), width = 130, height = 2000 ) #size_hint=(None, None), width = 130, height = 1500) # size_hint = (1,1) )#self.add_widget(self.layout)
     self.add_widget(self.layout)
     self.draw_empty_squares()
     self.sort()
     self.fill()
     #self.resort('title')
     self.leave_app_button = SuperButton(background_normal = 'style/bar/slider-picto-type-off.png',background_down = 'style/bar/slider-picto-type-on.png', size = (30,30), pos_hint = (None,0.95), x = 0 )
     self.leave_app_button.bind(on_press = self.app.appview.leave_current_app)
Exemple #4
0
class Bar(FloatLayout):
    objects = DictProperty( {} )
    app = ObjectProperty(None)
    apps = DictProperty( {} )
    element_size = ObjectProperty( (70,70) )
    spacing = NumericProperty(10)
    sorting_condition = StringProperty( 'app_type' )
    
    def __init__(self,**kwargs):
        super(Bar,self).__init__(**kwargs)
        self.apps = self.app.field.init_apps()
        self.size_hint = (None,1)
        #self.width = 135
        self.padding_left = int((self.width - self.element_size[0])/2) 
        self.geometry_squares = {}
        self.images = {}
        self.sorting = []  
        #self.scroll = ScrollView( size_hint = (None, None), width = 130, height = 1000 )
        #self.add_widget(self.scroll) 
        self.layout = Widget(size_hint = (None, None), width = 130, height = 2000 ) #size_hint=(None, None), width = 130, height = 1500) # size_hint = (1,1) )#self.add_widget(self.layout)
        self.add_widget(self.layout)
        self.draw_empty_squares()
        self.sort()
        self.fill()
        #self.resort('title')
        self.leave_app_button = SuperButton(background_normal = 'style/bar/slider-picto-type-off.png',background_down = 'style/bar/slider-picto-type-on.png', size = (30,30), pos_hint = (None,0.95), x = 0 )
        self.leave_app_button.bind(on_press = self.app.appview.leave_current_app)
        

    def clear(self):
        for i in self.children :
            self.remove_widget(i)

    def sort(self):

        #list of app keys in order
        condition = self.sorting_condition
        self.sorting = self.apps.keys()
        
        if condition == 'title':
            l = []
            for i,val in self.apps.iteritems():
                t = val['title']
                l.append( [t,i] )    
        elif condition == 'app_type':
            l = []
            for i,val in self.apps.iteritems():
                t = val['app_type']
                l.append( [t,i] )
        else : 
            return
        l.sort()
        #print l
        sorting = []
        counter =0
        for i in l:
            if counter in [7,14,21,28]:
                #button
                sorting.append( 'b' )
            sorting.append( i[1] )
            counter +=1
        self.sorting = sorting

    def resort(self,condition):
        self.sorting_condition = condition
        self.sort()
        #self.clear()
        #animate icons now
        gs = self.geometry_squares
        
        for key,val in gs.iteritems() :
            im_key = self.sorting[int(key)]
            if not im_key == 'b': #exception for buttons
                    #get destination gs
                    center = val.center
                    a = Animation(center = center)
                    im = self.images[ str(im_key) ]
                    im.initial_center = center
                    a.start( im )
                    #im.pos = center                  

    def fill(self):
        #print 'apps'
        #print self.apps
        gs = self.geometry_squares 
        s = self.sorting
        counter = 0
        for key,val in self.apps.iteritems() :
            #get destination gs
            g = gs[ str( s.index(key) ) ]
            center = g.center
            pos = g.pos
            self.add_app(key,val,center,pos)    
            counter +=1
        #add sorting buttons
        counter = 0
        for key in s :
            if key == "b":
                self.add_button(counter)
            counter +=1    
             

    def add_button(self, place):
        pos = self.geometry_squares[str(place)].pos
        buttons = GridLayout(cols=2, row_force_default=True, row_default_height=self.element_size[1]*0.5, size = self.element_size, pos = pos, spacing = 3 )
        but1 = SuperButton(background_normal = 'style/bar/slider-picto-type-off.png',background_down = 'style/bar/slider-picto-type-on.png')
        but1.bind(on_press = self.sort_by_app_type)
        but2 = Button(background_normal = 'style/bar/slider-picto-ABC-off.png',background_down = 'style/bar/slider-picto-ABC-on.png')
        but2.bind(on_press = self.sort_by_title)
        but3 = Button(background_normal = 'style/bar/slider-picto-90-off.png',background_down = 'style/bar/slider-picto-90-on.png')
        but3.bind(on_press = self.rotate_images)        
        but4 = Button(background_normal = 'style/bar/slider-picto-preSet-off.png',background_down = 'style/bar/slider-picto-preSet-on.png')

        buttons.add_widget(but1)
        buttons.add_widget(but2)
        buttons.add_widget(but3)  
        buttons.add_widget(but4)     
        self.layout.add_widget(buttons)

    def sort_by_app_type(self,a):
        self.resort('app_type')

    def sort_by_title(self,a):
        self.resort('title')

    def rotate_images(self,a):
        for i,val in self.images.iteritems():
            val.rotation = val.rotation + 90            

    def add_app(self, key, app, center, pos):
        # Nop.
        self.images[key] = BarImage( source= str(app["image_path"]) , app =self.app, bar=self, key=key, pos =pos, initial_center = center, size = self.element_size )
        if key in self.app.field.squares.keys() : 
            self.images[key].opacify()
        if self.app.field.geometry["vertical"] == "True": 
            self.images[key].rotation += 270 
        self.layout.add_widget(self.images[key])

    def draw_empty_squares(self):
        apps = self.apps
        m = self.spacing#self.app.field.style['geometry_square_margin']
        padding_left = self.padding_left
        max = len(apps)
        #leave space for buttons
        r = max/7
        max +=int(r)
        
        for i in xrange(0,max):
            self.geometry_squares[str(i)] = GeometrySquare(
                           geometry_id = i, 
                           pos = (padding_left,m+(self.element_size[1]+m)*i), 
                           size = self.element_size, 
                           layout_type = "icon", 
                           do_scale = False, 
                           do_rotation = False, 
                           do_translation = False, 
                           auto_bring_to_front = False
                           )
            self.layout.add_widget( self.geometry_squares[str(i)] ) 

    def put_on_field(self, key, touch):
        self.app.field.add_app(key, touch)

    def on_image_touch_down(self, touch, key):
        squares = self.app.field.squares
        if not key in squares.keys() : return
        if self.app.appview.position_left == False:
            if touch.is_double_tap :
                square  = self.app.field.squares[key]
                square.launch(1)
        else : 
            #check if already on field
            self.app.field.shake_square( touch,key,10)

    def show_leave_app_button(self):
        return
        self.layout.add_widget( self.leave_app_button )

    def hide_leave_app_button(self):
        return
        self.layout.remove_widget( self.leave_app_button )

    def opacify(self):
        squares = self.app.field.squares.keys()
        for key,item in self.images.iteritems() :
            if key in squares : 
                item.opacify()

    def unopacify(self):
        for key,item in self.images.iteritems() :
                item.unopacify()
class VideoPlayer(Widget):

    source = StringProperty('')
    hide_buttons_time_out = NumericProperty(7)
    play = BooleanProperty( False )
    options = DictProperty( {'eos':'loop'} )

    def __init__(self,**kwargs) :
            super(VideoPlayer,self).__init__(**kwargs)

            #new events
            self.register_event_type('on_mute')
            self.register_event_type('on_unmute')
            self.register_event_type('on_start')
            self.register_event_type('on_stop')
            self.register_event_type('on_fullscreen')
            self.register_event_type('on_leave_fullscreen')
            
            self.video = Video(source = self.source, play=self.play, options = self.options , size_hint = (1,1))
            #delay to load the video before launching it
            Clock.schedule_once(self.start,0.2)
            Clock.schedule_once(self.stop,2.4)             
            
            #buttons box
            self.buttons = BoxLayout(orientation = 'horizontal', size_hint = (None, None), size = (self.video.width, 30 ) )
            self.buttons.padding = 5 
            self.buttons.spacing = 5

            #play button
            self.play_button = SuperButton2(text ='', background_normal= 'video_player/style/1318898242_media-play.png', background_down= 'video_player/style/1318898242_media-play.png', size_hint = (None, None), size = (20, 20) )
            self.play_button.bind( on_press = self.start_stop_button )
            self.buttons.add_widget( self.play_button )
            #sound button
            self.sound_button = SuperButton2(text ='', background_normal = 'video_player/style/1318898261_media-volume-0.png', background_down = 'video_player/style/1318898261_media-volume-0.png', size_hint = (None, None), size = (20, 20) )
            self.sound_button.bind( on_press = self.mute_unmute_button )
            self.buttons.add_widget( self.sound_button )
            #fullscreen 
            self.fullscreen_button = SuperButton(text ='', background_normal = 'video_player/style/fullscreen-logo.png', background_down = 'video_player/style/fullscreen-logo.png', size_hint = (None, None), size = (20, 20) )
            self.fullscreen_button.bind(on_press = self.fullscreen_button_down )
            self.buttons.add_widget( self.fullscreen_button )
            #duration bar
            self.duration = -1
            self.progress_bar = ProgressBar( size_hint = (1, 1)  )
            self.progress_bar.bind(on_touch_move = self.move_to_position)
            self.buttons.add_widget( self.progress_bar )
            #manage appearance counter
            self.last_touch_down_time = 0
            #fullscreen status
            self.full_screen = False
            
            #main play button
            self.main_play_button = SuperButton(text ='', background_normal= 'video_player/style/A-play-T3.png', size_hint = (None, None), size = (50, 50) )
            self.main_play_button.bind( on_press = self.start )
            self.add_widget( self.main_play_button )
                      
            #refresh bar position and size
            Clock.schedule_interval(self.refresh_player,0.005)    

            self.add_widget(self.video)


    def start_stop_button(self,a) :
            #actually does start and stop (both functions on same button)
            m = self.video 
            if m.play == False :
                self.start(a)
            else :
                self.stop(a) 

    def start(self, a):
        self.video.play = True
        self.play_button.source = 'video_player/style/1318898221_media-stop.png'
        self.remove_widget( self.main_play_button )
        self.dispatch('on_start')

    def stop(self, a):
        self.video.play=False
        self.play_button.source = 'video_player/style/1318898242_media-play.png'
        self.add_widget( self.main_play_button )
        self.dispatch('on_stop')

    def mute_unmute_button(self,a):
        if self.video.volume == 1:
            self.mute(a)        
        else :     
            self.unmute(a)    

    def mute(self, a):
        self.video.volume = 0
        self.sound_button.source = 'video_player/style/1318898286_media-volume-3.png'
        self.dispatch('on_mute')    

    def unmute(self, a):
        self.video.volume = 1
        self.sound_button.source = 'video_player/style/1318898261_media-volume-0.png'
        self.dispatch('on_unmute')

    def fullscreen_button_down(self, a):
        if self.full_screen == False:
            self.fullscreen(1)
        else :
            self.leave_fullscreen(1)

    def fullscreen(self, a):
        self.full_screen = True
        self.dispatch('on_fullscreen')
    
    def leave_fullscreen(self,a):
        self.full_screen = False
        self.dispatch('on_leave_fullscreen')  

    def refresh_player(self, a):
        #progress bar
        if self.duration in [-1,1,0] :
            self.duration = self.video.duration
            self.progress_bar.max = int(self.duration)
        self.buttons.pos = self.pos
        self.buttons.width = self.width
        self.progress_bar.width = self.width
        self.video.pos = self.pos
        self.video.size = self.size
        self.progress_bar.value = self.video.position
        self.main_play_button.center = self.video.center 
        

    def move_to_position(self, a, touch):
        return
        x = touch.x
        x_hint = x / self.progress_bar.width
        self.video.play = False
        self.video.position = x_hint * self.duration
        self.video.play = True

    def on_touch_down(self, touch):
        super(VideoPlayer,self).on_touch_down(touch)
        self.last_touch_down_time = Clock.get_time()
        #display bar and buttons
        self.show_buttons()

    def hide_buttons(self,a):
        delta = Clock.get_time() - self.last_touch_down_time
        if delta >= (self.hide_buttons_time_out - 0.02) : 
            self.remove_widget(self.buttons)

    def show_buttons(self):
        self.remove_widget(self.buttons)
        self.add_widget(self.buttons)
        Clock.schedule_once(self.hide_buttons, self.hide_buttons_time_out)
    
    def on_mute(self):
        pass

    def on_unmute(self):
        pass

    def on_start(self):
        pass

    def on_stop(self):
        pass

    def on_fullscreen(self):
        pass

    def on_leave_fullscreen(self):
        pass  
Exemple #6
0
    def init_layouts(self):

        def layers2texture(layers, berkelium):
            #convert either an image or an html webpage to texture
            #to be used as a background by the square
            converted_layers = {}
            bk = {}
            for key,path in layers.iteritems():
                #fileName, fileExtension = os.path.splitext(path)
                #if fileName[4] in ['http','file']: #fileExtension in ['.org','.com','.fr','.html','.htm'] :
                if path[:4] in ['http','file']:
                    if self.berkelium_is_installed == False : return None
                    size = (600,600)
                    bk[key] = berkelium.Webbrowser(url=path, size=size)
                    texture = bk[key]._bk.texture
                    converted_layers[key] = texture
                    #finally delete the berkelium instance
                    del bk[key]   
                else :
                    from kivy.uix.image import Image
                    img = Image(source=path)
                    texture = img.texture
                    converted_layers[key] = texture
            #print path, texture
            return converted_layers   
        
        #load berkelium
        berkelium = None
        if self.berkelium_is_installed == True : 
            from kivy.ext import load
            berkelium = load('berkelium', (1, 1))            

        #extract textures from layouts
        self.layers = layers2texture(self.layers, berkelium)

        #get current layout
        layout_type = self.layout_type
        param = self.square_parameters[layout_type] #load parameters specific to that size (small, medium, large)
        
        #color
        a,b,c,d = self.color_up
        
        ######################### LAYOUT ##########################################################
        
        self.texture_path = texture_path = str(param['texture_path']) #self.style['square_texture_path']
        #text layer
        self.layer_texture_path = self.layers[layout_type]
        """
        from kivy.uix.image import Image
        self.layer = Image(source = "apps/layers/xyz/large.png", size_hint = (1,1))
        self.layout.add_widget(self.layer)
        """         
        #top part : Title, app_type, authors
        self.box_top = BoxLayout(size_hint = param['box_top_size_hint'] )#orientation = 'horizontal', 
        font_size = self.process_font_size( self.title, int( param['title_label_font_size']) )
        text_size = (len(self.title)*font_size +100,None )
        self.title_label = Label( text=self.title, font_size = font_size, color = self.color_text, halign = 'left', valign = 'top',text_size = text_size, padding = (5,0) ) #font_name = 'DEJAVU SANS CONDENSED', bold = False
        self.box2 = BoxLayout(orientation = 'horizontal',  size_hint = (None,1) , width = self.title_label.text_size[0], pos_hint={'top': 1,'left':1} )
        #self.app_type_pic = Image(source = str(self.app_type), pos_hint={'top': 1,'right':1}, size_hint = (1,3) )
        #self.box3 = AnchorLayout( anchor_x = 'right', anchor_y = 'bottom')
        #self.authors_label = Label(text = self.authors, font_size = int( param['authors_label_font_size'] ), pos_hint ={'right':1},  color = self.color_text, halign = 'right') #, pos_hint={'bottom': 1,'right':1} )        
        self.box2.add_widget(self.title_label)
        self.box_top.add_widget(self.box2)
        #self.box3.add_widget(self.authors_label)
        #self.box_top.add_widget(self.box3)
        self.layout.add_widget( self.box_top )
        
        #middle part : Image or Video
        self.box_middle = BoxLayout(orientation = 'horizontal', size_hint = param['box_middle_size_hint'] )
        self.box_middle1 = BoxLayout(orientation = 'horizontal', size_hint = param['box_middle1_size_hint'], padding = 0, spacing = 0 )
        self.box_middle2 = BoxLayout(orientation = 'horizontal', size_hint = param['box_middle2_size_hint'], padding = 0, spacing = 0 )
        self.box_middle.add_widget( self.box_middle1 ) 
        self.box_middle.add_widget( self.box_middle2 )
 
        if self.main_media_type == 'webpage' :
            #berkelium installed was already checked by field
            try : 
                self.webpage = berkelium.Webbrowser(url=self.webpage_path, size=(50,50) )
                self.box_middle1.add_widget( self.webpage ) 
            except :
                print 'Cannot load url: '+str(self.webpage_path)
                self.main_media_type = 'image'
            
        if self.main_media_type == 'image' : 
            from kivy.uix.image import Image
            image = Image(source = self.image_path, allow_stretch = True, keep_ratio = False, size_hint = (1,1), pos_hint={'left': 1, 'top' : 1} )
            self.box_middle1.add_widget( image ) 

        elif self.main_media_type == 'video' :
            #if self.main_media_type == 'video' :
            self.video = VideoPlayer(source = self.video_path)
            self.video.bind(on_unmute =self.on_unmute)
            self.video.bind(on_start=self.on_start)
            self.video.bind(on_fullscreen = self.on_fullscreen)
            self.video.bind(on_leave_fullscreen = self.on_leave_fullscreen)
            self.box_middle1.add_widget( self.video ) 
        
        self.layout.add_widget( self.box_middle ) 

        #Bottom part : buttons
        self.box_bottom = BoxLayout(orientation = 'horizontal', size_hint = param['box_bottom_size_hint'] )
        self.subbox = BoxLayout(orientation = 'horizontal' )
        self.box_bottom.padding = int( param['box_bottom_padding'] ) #box.height*0.15 
        self.vote_button = SuperButton(background_normal = 'style/square/bouton-vote-T2-off.png', background_down = 'style/square/bouton-vote-T2-on.png', size_hint = (None,None), size=param["vote_button_size"] )
        self.vote_button.bind( on_press = self.vote ) 
        self.subbox.add_widget( self.vote_button )
        #vote feedback
        from kivy.uix.image import Image
        self.fb = Image(source = 'style/square/like'+self.convert_vote_feedback()+'.png', size_hint=(None,None), size=param["vote_feedback_size"])
        self.subbox.add_widget( self.fb )
        self.box_bottom.add_widget(self.subbox)
        self.launch_button = SuperButton(background_normal = 'style/square/bouton-lancer-T2-off.png',background_down = 'style/square/bouton-lancer-T2-on.png', size_hint = (None,None), size=param["launch_button_size"] ) 
        self.launch_button.bind( on_press = self.launch ) 
        self.box_bottom.add_widget( self.launch_button )
        self.box_bottom.spacing = (self.layout.width - self.vote_button.width - self.launch_button.width)*0.97
        self.layout.add_widget( self.box_bottom )

        self.add_widget(self.layout)
Exemple #7
0
class Square(Scatter):
    app = ObjectProperty( None )
    geometry_id = NumericProperty(None)#location on the field where the Square sits
    #content
    id = StringProperty('')
    title = StringProperty(None)
    app_type = StringProperty(None) #'info', 'service', 'jeu'
    color = ObjectProperty( (.82,.82,.82,1) )
    color_text = ObjectProperty( (.82,.82,.82,1) )
    color_down = ObjectProperty( (1,1,0,1) )
    color_up = ObjectProperty( (.1,.1,.1,1) )
    authors = StringProperty(None)
    main_media_type = StringProperty(None) #'image' or 'video' or 'webpage'
    image_path = StringProperty(None)
    video_path = StringProperty(None)
    webpage_path = StringProperty("http://www.google.com")
    vote_feedback = NumericProperty(0) #value between 0 and 1
    #shape
    rotation_90d = NumericProperty(0)
    layout_type = StringProperty(None) #'icon'/'small'/'medium' or 'large'
    icon_size = ObjectProperty( None )
    small_size = ObjectProperty( None )
    medium_size = ObjectProperty( None )
    large_size = ObjectProperty( None )
    #internal variables
    touches = DictProperty( {} ) #current active touches on the widget
    #buttons = DictProperty( {} ) #store buttons widgets
    square_parameters = DictProperty( {} ) #initial parameters of the square
    texture_path = StringProperty("")
    layout = ObjectProperty( None )#base layout for all the widgets
    layers = DictProperty( {} )#stores background text layers of each size
    layer_texture_path = ObjectProperty( None )
    process_touch_up_forbidden = BooleanProperty(False)
    padding = NumericProperty(10) #square layout padding
    berkelium_is_installed = BooleanProperty(False)

    def __init__(self,**kwargs) :

        super(Square,self).__init__(**kwargs)

        l,h = self.size
        pad = self.padding
        self.layout = BoxLayout(orientation = 'vertical', size = (l -2*pad,h -2*pad), pos = (pad,pad) )           
        self.init_layouts() 

          
    
    def on_start(self, a):
        try :
            self.parent.mute(self.uid) #mute other parents' video players
        except:
            pass
        self.video.unmute(1) #unmute the player

    def on_unmute(self,a):
        try :
            self.parent.mute(self.uid)                
        except : 
            pass

    def mute(self):
        if self.main_media_type == 'video':
            self.video.mute(1)
 
    def on_fullscreen(self, a):
        self.video.stop(1)
        vid = self.video
        x,y = vid.pos
        self.parent.play_video_fullscreen(self.video_path, self.to_parent(x,y) , self.video.size, self.video.video.position)
        
    def on_leave_fullscreen(self, a):
        pass 

    def process_font_size(self, text, font_size):
        #in case the text is multiline, reduce the font size
        multiline = False
        for i in text : 
            if i == '\n' : multiline = True
        if not multiline : return font_size
        else : return font_size - 6            

    def init_layouts(self):

        def layers2texture(layers, berkelium):
            #convert either an image or an html webpage to texture
            #to be used as a background by the square
            converted_layers = {}
            bk = {}
            for key,path in layers.iteritems():
                #fileName, fileExtension = os.path.splitext(path)
                #if fileName[4] in ['http','file']: #fileExtension in ['.org','.com','.fr','.html','.htm'] :
                if path[:4] in ['http','file']:
                    if self.berkelium_is_installed == False : return None
                    size = (600,600)
                    bk[key] = berkelium.Webbrowser(url=path, size=size)
                    texture = bk[key]._bk.texture
                    converted_layers[key] = texture
                    #finally delete the berkelium instance
                    del bk[key]   
                else :
                    from kivy.uix.image import Image
                    img = Image(source=path)
                    texture = img.texture
                    converted_layers[key] = texture
            #print path, texture
            return converted_layers   
        
        #load berkelium
        berkelium = None
        if self.berkelium_is_installed == True : 
            from kivy.ext import load
            berkelium = load('berkelium', (1, 1))            

        #extract textures from layouts
        self.layers = layers2texture(self.layers, berkelium)

        #get current layout
        layout_type = self.layout_type
        param = self.square_parameters[layout_type] #load parameters specific to that size (small, medium, large)
        
        #color
        a,b,c,d = self.color_up
        
        ######################### LAYOUT ##########################################################
        
        self.texture_path = texture_path = str(param['texture_path']) #self.style['square_texture_path']
        #text layer
        self.layer_texture_path = self.layers[layout_type]
        """
        from kivy.uix.image import Image
        self.layer = Image(source = "apps/layers/xyz/large.png", size_hint = (1,1))
        self.layout.add_widget(self.layer)
        """         
        #top part : Title, app_type, authors
        self.box_top = BoxLayout(size_hint = param['box_top_size_hint'] )#orientation = 'horizontal', 
        font_size = self.process_font_size( self.title, int( param['title_label_font_size']) )
        text_size = (len(self.title)*font_size +100,None )
        self.title_label = Label( text=self.title, font_size = font_size, color = self.color_text, halign = 'left', valign = 'top',text_size = text_size, padding = (5,0) ) #font_name = 'DEJAVU SANS CONDENSED', bold = False
        self.box2 = BoxLayout(orientation = 'horizontal',  size_hint = (None,1) , width = self.title_label.text_size[0], pos_hint={'top': 1,'left':1} )
        #self.app_type_pic = Image(source = str(self.app_type), pos_hint={'top': 1,'right':1}, size_hint = (1,3) )
        #self.box3 = AnchorLayout( anchor_x = 'right', anchor_y = 'bottom')
        #self.authors_label = Label(text = self.authors, font_size = int( param['authors_label_font_size'] ), pos_hint ={'right':1},  color = self.color_text, halign = 'right') #, pos_hint={'bottom': 1,'right':1} )        
        self.box2.add_widget(self.title_label)
        self.box_top.add_widget(self.box2)
        #self.box3.add_widget(self.authors_label)
        #self.box_top.add_widget(self.box3)
        self.layout.add_widget( self.box_top )
        
        #middle part : Image or Video
        self.box_middle = BoxLayout(orientation = 'horizontal', size_hint = param['box_middle_size_hint'] )
        self.box_middle1 = BoxLayout(orientation = 'horizontal', size_hint = param['box_middle1_size_hint'], padding = 0, spacing = 0 )
        self.box_middle2 = BoxLayout(orientation = 'horizontal', size_hint = param['box_middle2_size_hint'], padding = 0, spacing = 0 )
        self.box_middle.add_widget( self.box_middle1 ) 
        self.box_middle.add_widget( self.box_middle2 )
 
        if self.main_media_type == 'webpage' :
            #berkelium installed was already checked by field
            try : 
                self.webpage = berkelium.Webbrowser(url=self.webpage_path, size=(50,50) )
                self.box_middle1.add_widget( self.webpage ) 
            except :
                print 'Cannot load url: '+str(self.webpage_path)
                self.main_media_type = 'image'
            
        if self.main_media_type == 'image' : 
            from kivy.uix.image import Image
            image = Image(source = self.image_path, allow_stretch = True, keep_ratio = False, size_hint = (1,1), pos_hint={'left': 1, 'top' : 1} )
            self.box_middle1.add_widget( image ) 

        elif self.main_media_type == 'video' :
            #if self.main_media_type == 'video' :
            self.video = VideoPlayer(source = self.video_path)
            self.video.bind(on_unmute =self.on_unmute)
            self.video.bind(on_start=self.on_start)
            self.video.bind(on_fullscreen = self.on_fullscreen)
            self.video.bind(on_leave_fullscreen = self.on_leave_fullscreen)
            self.box_middle1.add_widget( self.video ) 
        
        self.layout.add_widget( self.box_middle ) 

        #Bottom part : buttons
        self.box_bottom = BoxLayout(orientation = 'horizontal', size_hint = param['box_bottom_size_hint'] )
        self.subbox = BoxLayout(orientation = 'horizontal' )
        self.box_bottom.padding = int( param['box_bottom_padding'] ) #box.height*0.15 
        self.vote_button = SuperButton(background_normal = 'style/square/bouton-vote-T2-off.png', background_down = 'style/square/bouton-vote-T2-on.png', size_hint = (None,None), size=param["vote_button_size"] )
        self.vote_button.bind( on_press = self.vote ) 
        self.subbox.add_widget( self.vote_button )
        #vote feedback
        from kivy.uix.image import Image
        self.fb = Image(source = 'style/square/like'+self.convert_vote_feedback()+'.png', size_hint=(None,None), size=param["vote_feedback_size"])
        self.subbox.add_widget( self.fb )
        self.box_bottom.add_widget(self.subbox)
        self.launch_button = SuperButton(background_normal = 'style/square/bouton-lancer-T2-off.png',background_down = 'style/square/bouton-lancer-T2-on.png', size_hint = (None,None), size=param["launch_button_size"] ) 
        self.launch_button.bind( on_press = self.launch ) 
        self.box_bottom.add_widget( self.launch_button )
        self.box_bottom.spacing = (self.layout.width - self.vote_button.width - self.launch_button.width)*0.97
        self.layout.add_widget( self.box_bottom )

        self.add_widget(self.layout)
        #Clock.schedule_once(self.update_canvas, 4)

    def convert_vote_feedback(self):
        vf = self.vote_feedback
        if vf > 1 : vf =1
        elif vf < 0 : vf = 0
        vf = int(vf*6)
        return str(vf)    

    def layout_type2size(self,layout_type) :
        #print layout_type
        pad = self.padding
        if layout_type == 'large':
            l,h = self.large_size
            s = (l -2*pad,h -2*pad)
        elif layout_type == 'medium': 
            l,h = self.medium_size
            s = (l -2*pad,h -2*pad)
        elif layout_type == 'small': 
            l,h = self.small_size
            s = (l -2*pad,h -2*pad)
        elif layout_type == 'icon': 
            l,h = self.icon_size
            s = (l -2*pad,h -2*pad)
        return s     
    
    def refresh_layout(self, layout_type) :
        size = self.layout_type2size(layout_type)
        pad = self.padding
        self.layout_type = layout_type
        
        kwargs = {'duration' : 1.1,'t':'in_quart'}
        anim = Animation(pos = (pad,pad), size = size, **kwargs)
        anim.start(self.layout)
        
        #refresh background texture
        Clock.schedule_once(self.refresh_background, 1.1)
    
    def refresh_background(self, a):
        self.texture_path = str( self.square_parameters[self.layout_type]['texture_path'] )
        self.layer_texture_path = self.layers[self.layout_type]
    
    def launch(self,a):
        self.app.appview.launch_app(id, self.title)

    def vote(self,a):
        print 'vote for app ' + self.title
        self.vote_feedback += 0.05
        self.fb.source = 'style/square/like'+ self.convert_vote_feedback() +'.png'        
    
    def on_touch_down(self, touch):
        #analyse and store touches so that we know on_touch_up which
        #square was concerned by the touch_up 
        if self.collide_point(touch.x,touch.y):
            self.touches[touch.id] = touch
            #enlarge a bit
            self.reshape_when_touch_down(touch, 0)     
        super(Square, self).on_touch_down(touch)  
    
    def on_touch_up(self, touch):
        super(Square, self).on_touch_up(touch)
        if not touch.id in self.touches : return
        del self.touches[touch.id]

        if self.collide_point(touch.x,touch.y):
            #print self.rotation
            if not self.process_touch_up_forbidden : 
                self.parent.process_touch_up(self)
            #reduce size a bit
            self.reshape_when_touch_up(touch)  
            return True   
    
    def reshape_when_touch_down(self, touch, intensity):
        self.color = self.color_down
        self.pos = (self.x + intensity, self.y + intensity)
        #self.title_label.color = self.color_up
        self.texture_path = 'style/square/square_'+str(self.layout_type)+'_touch_down.png'
        #self.app_type_label.color = self.color_up
        #self.size = (self.width + 3, self.height + 3)
        #a = Animation(center = self.center, size = self.size)
        #a.start(self)

    def reshape_when_touch_up(self, touch):
        self.color = self.color_up
        #self.title_label.color = self.color_down
        #self.app_type_label.color = self.color_up
        self.texture_path = 'style/square/square_'+str(self.layout_type)+'.png'
        pass

    def update_canvas(self,a):
        self.canvas.ask_update()