def build(app): # Here, you must return a root widget that will be used for app # You also have app instance in parameter. # ------------------------------------------------------------------------- # Our root widget root = FloatLayout() # ------------------------------------------------------------------------- # Add a date slider to our root widget. app.date_slider = slider = CircularSlider(size_hint=(None, None), orientation='horizontal', size=(250, 500)) scatter = date_slider_scatter = Scatter( size=app.date_slider.size, auto_bring_to_front=False, pos=(600, 200), #pos_hint={'y': 0.01, 'center_x': .5}, size_hint=(None, None), rotation=-90, scale=0.9, do_translate=False, do_rotate=False, do_scale=False) scatter.add_widget(app.date_slider) root.add_widget(scatter) # ------------------------------------------------------------------------- # Create an image map widget # search image for map (exclude _active) files sources = glob(join(app.expo_data_dir, 'widgets', 'map', '*.png')) sources = [x for x in sources if '_active' not in x] app.imagemap = imagemap = ImageMap(size_hint=(None, None), size=(700, 893), sources=sources, suffix='_active') #root.add_widget(imagemap) scatter = scatter_imagemap = Scatter( auto_bring_to_front=False, size_hint=(None, None), size=imagemap.size, #pos_hint={'x': 0.61, 'center_y': .55}, #pos_hint={'y': 0.61}, pos=(50, 40), rotation=0, scale=0.4, do_translation=False, do_rotation=False, do_scale=False) scatter.add_widget(app.imagemap) root.add_widget(scatter) # ------------------------------------------------------------------------- # Create a widget for keywords # Here we are using a scatter between to be able to rotate the widget app.keywords = Keywords(size=(325, 650), size_hint=(None, None), orientation='vertical', title_template='KeywordItemTitle') scatter = scatter_keywords = Scatter( size=app.keywords.size, auto_bring_to_front=False, #pos_hint={'x': 0.01, 'center_y': 0.5}, size_hint=(None, None), pos=(1325, -230), rotation=0, scale=0.9, do_translation=False, do_rotation=False, do_scale=False) scatter.add_widget(app.keywords) root.add_widget(scatter) # ------------------------------------------------------------------------- # Create a layout for buttons toolbar_layout = BoxLayout(size_hint=(None, None), pos=(32, 32), spacing=32) kwargs = {'size_hint': (None, None), 'size': (64, 64)} root.add_widget(toolbar_layout) # ------------------------------------------------------------------------- # Create a button to replace randomly elements on screen # This button is on the bottom/left part of the screen '''kwargs = {'size_hint': (None, None), 'size': (64, 64), 'border': (0, 0, 0, 0)} ordering_random = Button( background_normal='widgets/corner_bottomleft.png', background_down='widgets/corner_bottomleft_down.png', **kwargs) ordering_random.bind(on_release=app.do_reset_item_position) root.add_widget(ordering_random)''' # ------------------------------------------------------------------------- # Create a button to order by map kwargs = { 'size_hint': (None, None), 'size': (44, 44), 'border': (0, 0, 0, 0) } ordering_origin = o = Button(background_normal='widgets/classer.png', background_down='widgets/classer_down.png', pos=(50, 10), **kwargs) ordering_origin.bind(on_release=app.do_ordering_origin) root.add_widget(ordering_origin) #Function disabled since ordering button pos is fixed def set_ordering_origin_pos(instance, value): #ordering_origin.right = instance.right + 100 ordering_origin.x = instance.x - 20 ordering_origin.y = instance.top - 500 #scatter_imagemap.bind(pos=set_ordering_origin_pos) #Place the title next to it title_map = Label(text='Departement', font_name=title_font, font_size=title_font_size, color=title_normal, bold=title_bold, size_hint=(None, None), size=(350, 40), pos=(o.x - 14, o.y + 4)) root.add_widget(title_map) # ------------------------------------------------------------------------- # Create a button to order by keyword group kwargs = { 'size_hint': (None, None), 'size': (44, 44), 'border': (0, 0, 0, 0) } ordering_keywords = o = Button(pos=(1325, 10), background_normal='widgets/classer.png', background_down='widgets/classer_down.png', **kwargs) ordering_keywords.bind(on_release=app.do_ordering_keywords) root.add_widget(ordering_keywords) #Function disabled since ordering button pos is fixed def set_ordering_keywords_pos(instance, value): ordering_keywords.x = instance.x ordering_keywords.y = instance.y - 50 #scatter_keywords.bind(pos=set_ordering_keywords_pos) #Place the title next to it title_map = Label(text='Types de cartes', font_name=title_font, font_size=title_font_size, color=title_normal, bold=title_bold, size_hint=(None, None), size=(300, 40), pos=(o.x + 25, o.y + 4)) root.add_widget(title_map) # ------------------------------------------------------------------------- # Create a button to order by datation kwargs = { 'size_hint': (None, None), 'size': (44, 44), 'border': (0, 0, 0, 0) } ordering_datation = o = Button(pos=(627, 10), background_normal='widgets/classer.png', background_down='widgets/classer_down.png', **kwargs) ordering_datation.bind(on_release=app.do_ordering_datation) root.add_widget(ordering_datation) def set_ordering_datation_pos(instance, value): ordering_datation.y = instance.x - 20 ordering_datation.x = instance.y #app.date_slider.bind(pos=set_ordering_datation_pos) #Place the title next to it title_map = Label(text='Date', font_name=title_font, font_size=title_font_size, color=title_normal, bold=title_bold, size_hint=(None, None), size=(220, 40), pos=(o.x - 14, o.y + 4)) root.add_widget(title_map) # ------------------------------------------------------------------------- # Create a basket widget # This button is on the bottom/left part of the screen kwargs = { 'pos_hint': { 'right': 1, 'top': 1 }, 'size_hint': (None, None), 'size': (130, 55), 'border': (0, 0, 0, 0), 'color': (0, 0, 0, 1), 'bold': True } #active to False disables the basket #email_send to True activates sending the url of the basket by email #url_send to True activates sending the url of the basket to a specific url app.basket = basket = Basket( active=True, background_normal='widgets/corner_topright.png', background_down='widgets/corner_topright_down.png', email_send=True, url_send=False, url_send_url='http://urltest.lapin.be?url=', app=app, **kwargs) if basket.active: #do not offer a basket on tablets, only on tables if platform() not in ('android'): root.add_widget(basket) # ------------------------------------------------------------------------- return root
def build(app): # Here, you must return a root widget that will be used for app # You also have app instance in parameter. # ------------------------------------------------------------------------- # Our root widget root = FloatLayout() # ------------------------------------------------------------------------- # BACKGROUND # ------------------------------------------ background = Image(source='widgets/background.png', pos_hint={ 'center_x': .5, 'center_y': .5 }) root.add_widget(background) # ------------------------------------------------------------------------- # SERVER CONNECTION # ------------------------------------------------------------------------- factory = EchoFactory(app) server = reactor.listenTCP(8001, factory) # label = Label(text="server started\n", pos=(100,100)) # root.add_widget(label) # button = Button(text='broadcast msg', width = 100, height = 30, size_hint= (None,None), pos = (300, 100)) # button.bind(on_release=send_message) # root.add_widget(button) # ------------------------------------------------------------------------- # Create a button to display help help_img = Button(background_normal="widgets/help_screen.png", background_down="widgets/help_screen.png", size=(1920, 1080), size_hint=(1, 1)) app.help = BooleanProperty(False) def show_help(self, *largs): # print 'show help' if app.help == False: app.root_images.parent.add_widget(help_img) app.help = True else: app.root_images.parent.remove_widget(help_img) app.help = False helpButton = Button( background_normal='widgets/btn_help.png', background_down='widgets/btn_help.png', size_hint=(None, None), size=(50, 50), #(99,101), border=(0, 0, 0, 0), #pos_hint={'x':25, 'y':25} x=25, y=15) helpButton.bind(on_release=show_help) root.add_widget(helpButton) help_img.bind(on_release=show_help) futur_img = Button(background_normal="widgets/background_temps.png", background_down="widgets/background_temps.png", size=(1920, 1080), size_hint=(1, 1)) app.futur = BooleanProperty(False) def show_futur(self, *largs): if app.futur == False: app.root_images.parent.add_widget(futur_img) app.futur = True else: app.root_images.parent.remove_widget(futur_img) app.futur = False futurButton = Button( background_normal='widgets/btn_idee.png', background_down='widgets/btn_idee.png', size_hint=(None, None), size=(50, 50), #(99,101), border=(0, 0, 0, 0), #pos_hint={'x':25, 'y':25} x=1920 - 25 - 50, y=15) futurButton.bind(on_release=show_futur) root.add_widget(futurButton) futur_img.bind(on_release=show_futur) # ------------------------------------------------------------------------- # Create an image map widget # Widget Mobile sources = glob(join(app.expo_data_dir, 'widgets', 'map', '*.png')) sources = [x for x in sources if '_active' not in x] app.imageButtons = imageButtons = ImageButtons(size_hint=(None, None), size=(420, 420), sources=sources, suffix='_active', show_one_cat_only=True) scatter = scatter_imageButtons = Scatter( auto_bring_to_front=True, size=imageButtons.size, size_hint=(None, None), rotation=0, scale=1, do_scale=False, # pos_hint = {'center_x': .5, 'center_y':.5} x=Window.width / 2 - imageButtons.width / 2, y=Window.height / 2 - imageButtons.height / 2) img = Image(source='widgets/background_menu.png', size=(420, 420)) scatter.add_widget(img) scatter.add_widget(app.imageButtons) root.add_widget(scatter) def on_menu_change(self, active_ids): if len(active_ids) > 0: send_message('clear') app.imageButtons.bind(active_ids=on_menu_change) # ------------------------------------------------------------------------- # Create a basket widget # This button is on the bottom/left part of the screen kwargs = { 'pos_hint': { 'right': 1, 'top': 1 }, 'size_hint': (None, None), 'size': (64, 64), 'border': (0, 0, 0, 0), 'color': (0, 0, 0, 1), 'bold': True } #active to False disables the basket #email_send to True activates sending the url of the basket by email #url_send to True activates sending the url of the basket to a specific url app.basket = basket = Basket( active=False, background_normal='widgets/corner_topright.png', background_down='widgets/corner_topright_down.png', email_send=True, url_send=False, url_send_url='http://urltest.lapin.be?url=', app=app, **kwargs) # if basket.active : #do not offer a basket on tablets, only on tables # if platform() not in ('android'): # root.add_widget(basket) # ------------------------------------------------------------------------- return root
def build(app): # Here, you must return a root widget that will be used for app # You also have app instance in parameter. # ------------------------------------------------------------------------- # Our root widget root = FloatLayout() # ------------------------------------------------------------------------- # Create an image map widget # search image for map (exclude _active) files sources = glob(join(app.expo_data_dir, 'widgets', 'map', '*.png')) sources = [x for x in sources if '_active' not in x] app.imagemap = imagemap = ImageMap(size_hint=(None, None), size=(385, 1000), sources=sources, suffix='_active') scatter = scatter_imagemap = Scatter(auto_bring_to_front=False, size=imagemap.size, size_hint=(None, None), rotation=0, scale=1, pos_hint={ 'right': 1, 'center_y': .55 }, do_translation=False, do_rotation=False, do_scale=False) scatter.add_widget(app.imagemap) root.add_widget(scatter) # ------------------------------------------------------------------------- # Create a widget for keywords # Here we are using a scatter between to be able to rotate the widget app.keywords = Keywords(size=(550, 650), size_hint=(None, None), orientation='vertical', title_template='KeywordItemTitle') scatter = scatter_keywords = Scatter(size=app.keywords.size, auto_bring_to_front=False, pos_hint={ 'x': 0.01, 'center_y': 0.5 }, size_hint=(None, None), rotation=0, do_translation=False, do_rotation=False, do_scale=False) scatter.add_widget(app.keywords) root.add_widget(scatter) # ------------------------------------------------------------------------- # Create a layout for buttons toolbar_layout = BoxLayout(size_hint=(None, None), pos=(32, 32), spacing=32) kwargs = {'size_hint': (None, None), 'size': (64, 64)} root.add_widget(toolbar_layout) # ------------------------------------------------------------------------- # Create a button to replace randomly elements on screen # This button is on the bottom/left part of the screen '''kwargs = {'size_hint': (None, None), 'size': (64, 64), 'border': (0, 0, 0, 0)} ordering_random = Button( background_normal='widgets/corner_bottomleft.png', background_down='widgets/corner_bottomleft_down.png', **kwargs) ordering_random.bind(on_release=app.do_reset_item_position) root.add_widget(ordering_random)''' # ------------------------------------------------------------------------- # Create a button to order by body part kwargs = { 'size_hint': (None, None), 'size': (64, 64), 'border': (0, 0, 0, 0) } ordering_origin = Button(background_normal='widgets/circle_filter.png', background_down='widgets/circle_filter_down.png', **kwargs) ordering_origin.bind(on_release=app.do_ordering_origin) root.add_widget(ordering_origin) def set_ordering_origin_pos(instance, value): ordering_origin.right = instance.right - 20 ordering_origin.y = instance.top - 1050 scatter_imagemap.bind(pos=set_ordering_origin_pos) # ------------------------------------------------------------------------- # Create a button to order by keyword group kwargs = { 'size_hint': (None, None), 'size': (64, 64), 'border': (0, 0, 0, 0) } ordering_keywords = Button( background_normal='widgets/circle_filter.png', background_down='widgets/circle_filter_down.png', **kwargs) ordering_keywords.bind(on_release=app.do_ordering_keywords) root.add_widget(ordering_keywords) def set_ordering_keywords_pos(instance, value): ordering_keywords.x = instance.x ordering_keywords.y = instance.top - 810 scatter_keywords.bind(pos=set_ordering_keywords_pos) # ------------------------------------------------------------------------- # Create a basket widget # This button is on the bottom/left part of the screen kwargs = { 'pos_hint': { 'right': 1, 'top': 1 }, 'size_hint': (None, None), 'size': (100, 100), 'border': (0, 0, 0, 0), 'color': (0, 0, 0, 1), 'bold': True } #active to False disables the basket #email_send to True activates sending the url of the basket by email #url_send to True activates sending the url of the basket to a specific url app.basket = basket = Basket( active=True, background_normal='widgets/corner_topright.png', background_down='widgets/corner_topright_down.png', email_send=True, url_send=False, url_send_url='http://urltest.lapin.be?url=', app=app, **kwargs) if basket.active: #do not offer a basket on tablets, only on tables if platform() not in ('android'): root.add_widget(basket) # ------------------------------------------------------------------------- return root
def build(app): # Here, you must return a root widget that will be used for app # You also have app instance in parameter. # ------------------------------------------------------------------------- # Our root widget root = FloatLayout() app.should_display_images_by_default = True root.scroller = scroller = ScrollView(size_hint=(None, None), size=(1920, 1080), pos_hint={ 'center_x': .5, 'center_y': .5 }, do_scroll_x=False) root.add_widget(scroller) def rotate_window(but): but.background_color = bluergb but.children[0].color = (1, 1, 1, 1) if Window.rotation == 180: Window.rotation = 0 else: Window.rotation = 180 def on_press_button(but): but.background_color = (1, 1, 1, 1) but.children[0].color = bluergb but = Button(size=(72, 71), size_hint=(None, None), pos=(Window.width - 72 + 10, Window.height / 2 - 71 / 2), background_color=bluergb, background_normal='widgets/picto-background.png', background_down='widgets/picto-background.png') img = Image(source='widgets/picto-reverse.png', size=(40, 40), pos=(but.x + (but.width - 40) / 2, but.y + (but.height - 40) / 2), color=(1, 1, 1, 1)) but.add_widget(img) but.bind(on_press=on_press_button) but.bind(on_release=rotate_window) but2 = Button(size=(72, 71), size_hint=(None, None), pos=(0 - 10, Window.height / 2 - 71 / 2), background_color=bluergb, background_normal='widgets/picto-background.png', background_down='widgets/picto-background.png') img = Image(source='widgets/picto-reset.png', size=(40, 40), pos=(but2.x + (but2.width - 40) / 2, but2.y + (but2.height - 40) / 2), color=(1, 1, 1, 1)) but2.add_widget(img) def add_buttons(dt): root.add_widget(but) root.add_widget(but2) Clock.schedule_once(add_buttons, .5) scroller.layout = layout = GridLayout(cols=8, col_force_default=True, row_force_default=True, col_default_width=223, row_default_height=252, padding=15, spacing=15, size_hint=(None, None), width=1920) layout.bind(minimum_height=layout.setter('height')) scroller.add_widget(layout) panel = WidgetsPanel(app=app) app.panel = panel root.add_widget(panel) def clear_panel(but): but.background_color = bluergb but.children[0].color = (1, 1, 1, 1) panel.clear_panel() app.root_images.clear_widgets() panel.close_panel() but2.bind(on_press=on_press_button) but2.bind(on_release=clear_panel) def feed_scroll(defs): source = defs['source'] if source not in app.images_displayed: return current_images = [x.source for x in app.root.scroller.layout.children] if source in current_images: return item = ScrollItem(**defs) app.root.scroller.layout.add_widget(item) def my_show_objects(objects): self = app root = self.root selected_authors = self.author_widget.selected_keywords selected_titles = self.title_widget.selected_keywords # selected_titles = [x.upper() for x in selected_titles] for item in objects[:]: # Filtering authors and titles if item.nom not in selected_titles and len(selected_titles) > 0: objects.remove(item) continue if item.freefield not in selected_authors and len( selected_authors) > 0: objects.remove(item) continue panel.result_sentence.text = "J'ai trouvé [font=fonts/proximanova-bold-webfont.ttf][size=28]" + str( len(objects)) + " [/size][/font]livres!" if isinstance(self.root_images.x, (int, long)): if root.type_expo == 'normal': images = [x.source for x in self.root.scroller.layout.children] images_to_add = [] images_displayed = [] for item in objects: # is the current filename is already showed ? filename = item.filename if filename in images: images.remove(filename) continue image = dict(source=filename, size_hint=(1, 1), item=item, app=self) images_to_add.append(image) images_displayed.append(filename) self.images_displayed = images_displayed self.delayed_work(feed_scroll, images_to_add) # remove all the previous images for child in self.root.scroller.layout.children[:]: for filename in images: if filename == child.source: self.root.scroller.layout.remove_widget(child) app.show_objects = my_show_objects app.trigger_objects_filtering() def on_touch_window(touch): return True # Window.on_touch_down = on_touch_window # def on_value(widget, value): # print 'relou' , value # app.bind(items_to_add=on_value) #### LAISSER CETTE PARTIE SINON CRASH -> variable app.basket appellée dans imageitem # ------------------------------------------------------------------------- # Create a basket widget # This button is on the bottom/left part of the screen kwargs = { 'pos_hint': { 'right': 1, 'top': 1 }, 'size_hint': (None, None), 'size': (64, 64), 'border': (0, 0, 0, 0), 'color': (0, 0, 0, 1), 'bold': True } #active to False disables the basket #email_send to True activates sending the url of the basket by email #url_send to True activates sending the url of the basket to a specific url app.basket = basket = Basket( active=False, background_normal='widgets/corner_topright.png', background_down='widgets/corner_topright_down.png', email_send=True, url_send=False, url_send_url='http://urltest.lapin.be?url=', app=app, **kwargs) if basket.active: #do not offer a basket on tablets, only on tables if platform() not in ('android'): root.add_widget(basket) # ------------------------------------------------------------------------- return root
def build(app): # Here, you must return a root widget that will be used for app # You also have app instance in parameter. # ------------------------------------------------------------------------- # Our root widget root = FloatLayout() # ------------------------------------------------------------------------- # Add a date slider to our root widget. app.date_slider = slider = CircularSlider(size_hint=(None, None), orientation='horizontal', size=(250, 500)) scatter = date_slider_scatter = Scatter(size=app.date_slider.size, auto_bring_to_front=False, pos_hint={ 'y': 0.01, 'center_x': .5 }, size_hint=(None, None), rotation=-90, scale=0.9, do_translate=False, do_rotate=False, do_scale=False) scatter.add_widget(app.date_slider) root.add_widget(scatter) # app.date_slider = slider = CalendarSlider( # size_hint=(None,None), # size = (3000, 100), # ) # scatter = date_slider_scatter = Scatter(size= app.date_slider.size, # auto_bring_to_front = False, # pos_hint = {'y':0, 'center_x':0.5}, # size_hint = (None,None), # do_translate=False, # do_rotate=False, # do_scale=False) # scatter.add_widget(app.date_slider) # root.add_widget(slider) # Create an image map widget # search image for map (exclude _active) files sources = glob(join(app.expo_data_dir, 'widgets', 'europ_map', '*.png')) sources = [x for x in sources if '_active' not in x] app.imagemap = imagemap = ImageMap(size_hint=(None, None), size=(600, 600), sources=sources, suffix='_active') scatter = scatter_imagemap = Scatter(auto_bring_to_front=False, size=imagemap.size, size_hint=(None, None), rotation=0, scale=1, pos_hint={ 'right': 1.12, 'center_y': .5 }, do_translation=False, do_rotation=False, do_scale=False) scatter.add_widget(app.imagemap) root.add_widget(scatter) # sources = glob(join(app.expo_data_dir, 'widgets', 'europ_map', '*.png')) # sources = [x for x in sources if '_active' not in x] # ------------------------------------------------------------------------- # Create a widget for keywords # Here we are using a scatter between to be able to rotate the widget app.keywords = Keywords(size=(550, 650), size_hint=(None, None), orientation='vertical', title_template='KeywordItemTitle') scatter = scatter_keywords = Scatter(size=app.keywords.size, auto_bring_to_front=False, pos_hint={ 'x': 0.01, 'center_y': 0.5 }, size_hint=(None, None), rotation=0, do_translation=False, do_rotation=False, do_scale=False) scatter.add_widget(app.keywords) root.add_widget(scatter) #Create an image map widget # Mouvements artistiques, boutons du haut sources = glob(join(app.expo_data_dir, 'widgets', 'map', '*.png')) sources = [x for x in sources if '_active' not in x] app.imageButtons = imageButtons = ImageButtons(size_hint=(None, None), size=(1128, 150), sources=sources, suffix='_active') scatter = scatter_imageButtons = Scatter(auto_bring_to_front=False, size=imageButtons.size, size_hint=(None, None), rotation=0, scale=1, pos_hint={ 'center_x': .5, 'y': .85 }, do_translation=False, do_rotation=False, do_scale=False) scatter.add_widget(app.imageButtons) root.add_widget(scatter) # ------------------------------------------------------------------------- # Create a layout for buttons toolbar_layout = BoxLayout(size_hint=(None, None), pos=(32, 32), spacing=32) kwargs = {'size_hint': (None, None), 'size': (64, 64)} root.add_widget(toolbar_layout) # ------------------------------------------------------------------------- # Create a button to replace randomly elements on screen # This button is on the bottom/left part of the screen '''kwargs = {'size_hint': (None, None), 'size': (64, 64), 'border': (0, 0, 0, 0)} ordering_random = Button( background_normal='widgets/corner_bottomleft.png', background_down='widgets/corner_bottomleft_down.png', **kwargs) ordering_random.bind(on_release=app.do_reset_item_position) root.add_widget(ordering_random)''' # ------------------------------------------------------------------------- # Create a button to order by body part kwargs = { 'size_hint': (None, None), 'size': (97, 120), 'border': (0, 0, 0, 0) } ordering_origin = Button(background_normal='widgets/circle_filter.png', background_down='widgets/circle_filter_down.png', **kwargs) ordering_origin.bind(on_release=app.do_ordering_origin) root.add_widget(ordering_origin) def set_ordering_origin_pos(instance, value): ordering_origin.right = instance.right - 20 ordering_origin.y = instance.top - 1050 scatter_imagemap.bind(pos=set_ordering_origin_pos) # scatter_imagemap2.bind(pos=set_ordering_origin_pos) # ------------------------------------------------------------------------- # Create a button to order by keyword group kwargs = { 'size_hint': (None, None), 'size': (97, 120), 'border': (0, 0, 0, 0) } ordering_keywords = Button( background_normal='widgets/circle_filter.png', background_down='widgets/circle_filter_down.png', **kwargs) ordering_keywords.bind(on_release=app.do_ordering_keywords) root.add_widget(ordering_keywords) def set_ordering_keywords_pos(instance, value): ordering_keywords.x = instance.x ordering_keywords.y = instance.top - 810 scatter_keywords.bind(pos=set_ordering_keywords_pos) # ------------------------------------------------------------------------- # Create a basket widget # This button is on the bottom/left part of the screen kwargs = { 'pos_hint': { 'right': 1.34, 'top': 1 }, 'size_hint': (None, None), 'size': (700, 1080), 'border': (0, 0, 0, 0), 'color': (0, 0, 0, 1), 'bold': True } #active to False disables the basket #email_send to True activates sending the url of the basket by email #url_send to True activates sending the url of the basket to a specific url app.basket = basket = Basket(active=False, background_normal='widgets/partage.png', background_down='widgets/partage_active.png', email_send=True, url_send=False, url_send_url='http://urltest.lapin.be?url=', app=app, **kwargs) if basket.active: #do not offer a basket on tablets, only on tables if platform() not in ('android'): root.add_widget(basket, index=0) root.add_widget(basket.itemsLayout, index=0) basket.itemsLayout.pos_hint = {'right': 1.1, 'top': 0.85} basket.open = False def translateObject(object, xParam): anim = Animation(x=object.x + xParam, duration=0.2) anim.start(object) def translateAllItems(xParam): translateObject(app.root_images, xParam) for i, item in enumerate(reversed(app.root_images.children)): # anim = Animation(x=item.x + xParam, duration = 0.2) # anim.start(item) translateObject(item, xParam) def moveAllItems(xParam): app.root_images.x = xParam for i, item, in enumerate(reversed(app.root_images.children)): item.x = xParam def translateBasket(instance): if basket.open == True: anim = Animation(x=0, duration=0.2) anim.start(root) translateAllItems(640) basket.open = False else: anim = Animation(x=-640, duration=0.2) anim.start(root) translateAllItems(-640) # root.remove_widget(basket) # root.add_widget(basket) basket.open = True def grabBasket(self, touch): if not self.collide_point(*touch.pos): return touch.grab(self) return True def moveBasket(self, touch): if touch.grab_current is self: root.x = touch.x - self.x # app.root_images.x = touch.x - app.root_images.x # for i, item in enumerate(reversed(app.root_images.children)): # item.x = touch.x - self.x return True def ungrabBasket(self, touch): if touch.grab_current is self: touch.ungrab(self) print root.x if basket.open == False: if root.x < -200: anim = Animation(x=-640, duration=0.2) anim.start(root) root.remove_widget(basket) root.add_widget(basket) basket.open = True else: anim = Animation(x=0, duration=0.3) anim.start(root) basket.open = False else: if root.x < -640: anim = Animation(x=-640, duration=0.2) anim.start(root) basket.open = True else: anim = Animation(x=0, duration=0.2) anim.start(root) basket.open = False return True basket.bind(on_release=translateBasket) # basket.bind(on_touch_move=moveBasket) # basket.bind(on_touch_down=grabBasket) # basket.bind(on_touch_up=ungrabBasket) # ------------------------------------------------------------------------- return root
def build(app): # Here, you must return a root widget that will be used for app # You also have app instance in parameter. # ------------------------------------------------------------------------- # Our root widget root = FloatLayout() # ------------------------------------------------------------------------- # Add a date slider to our root widget. app.date_slider = slider = CircularSlider(pos_hint={ 'right': 1, 'center_y': 0.5 }, size_hint=(None, None), size=(250, 500)) root.add_widget(slider) # ------------------------------------------------------------------------- # Size slider app.size_slider = slider = SizeSlider(size=(420, 30), size_hint=(None, None)) scatter = size_slider_scatter = Scatter(size=app.size_slider.size, auto_bring_to_front=False, pos_hint={ 'top': 0.98, 'center_x': .5 }, size_hint=(None, None), rotation=-180, do_translate=False, do_rotate=False, do_scale=False) scatter.add_widget(app.size_slider) root.add_widget(scatter) # ------------------------------------------------------------------------- # Create an image map widget # search image for map (exclude _active) files sources = glob(join(app.expo_data_dir, 'widgets', 'map', '*.png')) sources = [x for x in sources if '_active' not in x] app.imagemap = imagemap = ImageMap(pos_hint={ 'center_x': 0.5, 'y': 0 }, size_hint=(None, None), size=(500, 268), sources=sources, suffix='_active') root.add_widget(imagemap) # ------------------------------------------------------------------------- # Create a widget for keywords # Here we are using a scatter between to be able to rotate the widget app.keywords = Keywords(size=(500, 250), size_hint=(None, None)) scatter = keywords_scatter = Scatter(size=app.keywords.size, auto_bring_to_front=False, pos_hint={ 'x': 0, 'center_y': 0.5 }, size_hint=(None, None), rotation=-90, do_translate=False, do_rotate=False, do_scale=False) scatter.add_widget(app.keywords) root.add_widget(scatter) # ------------------------------------------------------------------------- # Create a button to replace randomly elements on screen # This button is on the bottom/left part of the screen kwargs = { 'size_hint': (None, None), 'size': (64, 64), 'border': (0, 0, 0, 0) } ordering_origin = Button( background_normal='widgets/corner_bottomleft.png', background_down='widgets/corner_bottomleft_down.png', **kwargs) ordering_origin.bind(on_release=app.do_reset_item_position) root.add_widget(ordering_origin) # ------------------------------------------------------------------------- # Create a button to order by continent # This button must be placed to the right of continent kwargs = { 'size_hint': (None, None), 'size': (40, 40), 'border': (0, 0, 0, 0) } ordering_origin = Button(background_normal='widgets/circle_filter.png', background_down='widgets/circle_filter_down.png', **kwargs) ordering_origin.bind(on_release=app.do_ordering_origin) root.add_widget(ordering_origin) def set_ordering_origin_pos(instance, value): ordering_origin.y = instance.y + 20 ordering_origin.x = instance.right + 20 imagemap.bind(pos=set_ordering_origin_pos) # ------------------------------------------------------------------------- # Create a button to order by datation ordering_datation = Button( background_normal='widgets/circle_filter.png', background_down='widgets/circle_filter_down.png', **kwargs) ordering_datation.bind(on_release=app.do_ordering_datation) root.add_widget(ordering_datation) def set_ordering_datation_pos(instance, value): ordering_datation.y = instance.top + 20 ordering_datation.right = instance.right - 20 app.date_slider.bind(pos=set_ordering_datation_pos) # ------------------------------------------------------------------------- # Create a button to order by size ordering_size = Button(background_normal='widgets/circle_filter.png', background_down='widgets/circle_filter_down.png', **kwargs) ordering_size.bind(on_release=app.do_ordering_size) root.add_widget(ordering_size) def set_ordering_size_pos(instance, value): ordering_size.y = instance.top - 35 ordering_size.right = instance.x - 70 size_slider_scatter.bind(pos=set_ordering_size_pos) # ------------------------------------------------------------------------- # Create a button to order by keywords ordering_keywords = Button( background_normal='widgets/circle_filter.png', background_down='widgets/circle_filter_down.png', **kwargs) #ordering_keywords.bind(on_release=app.do_ordering_keywords) root.add_widget(ordering_keywords) def set_ordering_keywords_pos(instance, value): ordering_keywords.x = 20 ordering_keywords.top = instance.y - 40 keywords_scatter.bind(pos=set_ordering_keywords_pos) # ------------------------------------------------------------------------- # Create a basket widget # This button is on the bottom/left part of the screen kwargs = { 'pos_hint': { 'right': 1, 'top': 1 }, 'size_hint': (None, None), 'size': (64, 64), 'border': (0, 0, 0, 0), 'color': (0, 0, 0, 1), 'bold': True } #active to False disables the basket #email_send to True activates sending the url of the basket by email #url_send to True activates sending the url of the basket to a specific url app.basket = basket = Basket( active=True, background_normal='widgets/corner_topright.png', background_down='widgets/corner_topright_down.png', email_send=True, url_send=False, url_send_url='http://urltest.lapin.be?url=', app=app, **kwargs) if basket.active: #do not offer a basket on tablets, only on tables if platform() not in ('android'): root.add_widget(basket) # ------------------------------------------------------------------------- return root
def build(app): # Here, you must return a root widget that will be used for app # You also have app instance in parameter. # ------------------------------------------------------------------------- # Our root widget root = FloatLayout() # ------------------------------------------------------------------------- # BACKGROUND # ------------------------------------------ background = Image(source='widgets/background.jpg', pos_hint={ 'center_x': .5, 'center_y': .5 }) root.add_widget(background) # ------------------------------------------------------------------------- # ------------------------------------------------------------------------- # PHYSICS # ------------------------------------------------------------------------- # ------------------------------------------------------------------------- constraints_layout = FloatLayout() root.add_widget(constraints_layout) app.bodies_created = [] def update_objects(): constraints_layout.canvas.clear() if hasattr(app, 'root_images'): for child in app.root_images.children: if hasattr(child, 'body'): p = child.body.position child.center = p.x, p.y if hasattr(child, 'content_container' ) and child.content_container != None: with constraints_layout.canvas: opacity = min(child.opacity, child.content_container.opacity) Color(child.color[0], child.color[1], child.color[2], opacity) # Color(0.2,0.5,0.85,1) Line(points=[ child.center_x, child.center_y, child.content_container.center_x, child.content_container.center_y ], width=3, dash_offset=5) for c in app.space.constraints: if c.a != None and c.b != None: if hasattr(c, 'draw') and c.draw == True: p1x, p1y = c.a.position.x, c.a.position.y p2x, p2y = c.b.position.x, c.b.position.y opacity = 1 if hasattr(c.a, 'sprite') and hasattr(c.b, 'sprite'): if c.a.sprite() != None and c.b.sprite() != None: opacity = min(c.a.sprite().opacity, c.b.sprite().opacity) else: app.space.remove(c) with constraints_layout.canvas: Color(1, 1, 1, opacity) # Color(0.2,0.5,0.85,1) Line(points=[p1x, p1y, p2x, p2y], width=1, dash_offset=5) else: app.space.remove(c) def step(dt): app.space.step(1 / 6.) update_objects() def link_parent_and_children(): for item in app.root_images.children: # looking on all items displayed if item.isParent == True: # is parent children = item.item.children #list of children ids item.children_refs = [] # list for children refs for child in app.root_images.children: # looking for child in displayed items if str(child.item.id) in children: child.parent_node = weakref.ref( item) #adding a ref of parent in child item.children_refs.append(weakref.ref( child)) # adding a ref of child in parent def init_items_bodies(dt, *args): link_parent_and_children() items = [] for child in app.root_images.children: if child.isParent: items.append(child) for child in app.root_images.children: if not child.isParent and hasattr(child, 'radius'): items.append(child) set_up_item_bodies(items, app.space) def update_bounds(*largs): assert (len(app.bounds) == 4) a, b, c, d = app.bounds x0, y0 = -100, -100 x1 = Window.width + 100 y1 = Window.height + 100 app.space.remove(a) app.space.remove(b) app.space.remove(c) app.space.remove(d) a.a = (x0, y0) a.b = (x1, y0) b.a = (x1, y0) b.b = (x1, y1) c.a = (x1, y1) c.b = (x0, y1) d.a = (x0, y1) d.b = (x0, y0) app.space.add(a) app.space.add(b) app.space.add(c) app.space.add(d) def init_physics(): print 'init_physics' app.bounds = [] app.space = space = pm.Space() space.iterations = 30 space.damping = .2 space.gravity = (0, 0) space.sleep_time_threshold = 0.5 space.collision_stop = 0.5 for x in xrange(4): seg = pm.Segment(space.static_body, Vec2d(0, 0), Vec2d(0, 0), 100) seg.elasticity = 0.9 app.bounds.append(seg) space.add(seg) Clock.schedule_interval(step, 1. / 60) update_bounds() # Window.bind(size=update_bounds) # Clock.schedule_once(init_items_bodies, 1.) init_physics() # ------------------------------------------------------------------------- # ------------------------------------------------------------------------- # BUTTONS AND WIDGETS # ------------------------------------------------------------------------- # ------------------------------------------------------------------------- # Create an image Button sources = glob(join(app.expo_data_dir, 'widgets', 'map', '*.png')) sources = [x for x in sources if '-active' not in x] app.imageButtons = imageButtons = ImageButtons( size_hint=(None, None), size=(350, 350), sources=sources, suffix='-active', show_objects_when_empty=False, show_one_cat_only=True, is_circular=True) scatter = scatter_imageButtons = Scatter(auto_bring_to_front=True, size=imageButtons.size, size_hint=(None, None), rotation=0, scale=1, center=Window.center, do_scale=False, scale_min=.8, scale_max=1.2) img = Image(source='widgets/background_menu.png', size=(350, 350)) # halo = Image(source = 'widgets/halo.png', size=(3600,3600), pos=(-1800,-1800)) # scatter.add_widget(halo) scatter.add_widget(img) scatter.add_widget(imageButtons) # halo.center = img.center root.add_widget(scatter, 25) def on_imgButton_center(self, value): parent = self.parent if not parent: return x, y = value x = max(parent.x, x) y = max(parent.y, y) x = min(parent.right, x) y = min(parent.top, y) self.center = x, y scatter_imageButtons.bind(center=on_imgButton_center) def default_value_for_imageButton(dt): for child in app.imageButtons.children: if child.source == 'expos/39/data/widgets/map/Reliures.png': child.set_active() Clock.schedule_once(default_value_for_imageButton, 1) img = Image(source='widgets/glossaire.png', size=(900, 698)) close_button = Button(background_normal='widgets/btn-close.png', background_down='widgets/btn-close-active.png', size_hint=(None, None), size=(60, 60), border=(0, 0, 0, 0)) scatter_button = Scatter(size_hint=(None, None), size=close_button.size, scale=.8, pos=(img.width - close_button.width + 8, img.height - close_button.height + 8)) scatter = scatter_glossaire = Scatter(size_hint=(None, None), size=img.size, scale=.5, scale_min=0.5, scale_max=1.5, x=10, center_y=340) scatter_button.add_widget(close_button) scatter.add_widget(img) scatter.add_widget(scatter_button) with scatter.canvas: Color(0.827, 0.286, 0.023, 0) Line(points=(0, 0, 0, scatter.height, scatter.width, scatter.height, scatter.width, 0), close=True, width=2) def on_close_glossaire(but=None): if scatter_glossaire in root.children: root.remove_widget(scatter_glossaire) close_button.bind(on_release=on_close_glossaire) glossaireButton = Button( background_normal='widgets/caption-glossaire.png', background_down='widgets/caption-glossaire-active.png', size_hint=(None, None), size=(100, 100), border=(0, 0, 0, 0), x=0, y=Window.height - 100) def show_glossaire(but): if scatter_glossaire not in root.children: root.add_widget(scatter_glossaire) scatter_glossaire.scale = .5 scatter_glossaire.rotation = 0 scatter_glossaire.x = 10 scatter_glossaire.center_y = 340 else: on_close_glossaire() root.add_widget(glossaireButton) glossaireButton.bind(on_release=show_glossaire) # media : 286, objet : 285, usage : 287 # if str(match['media']) in self.item.keywords: # self.color = (0.015,0.658,0.698,1) # elif str(match['objet']) in self.item.keywords: # self.color = (0.015,0.529,0.702,1) # elif str(match['usage']) in self.item.keywords: # self.color = (0.055,0.447,0.537,1) # match = {'media': 286, 'objet': 285, 'usage': 287} def magnify_items(button): if hasattr(button, 'cat'): id_keyword = match[button.cat] for child in app.root_images.children: if isinstance(child, ImageItem): previous_opacity = child.opacity previous_color = child.color child.opacity = 0 child.color = (0.055, 0.447, 0.537, 1) if str(id_keyword) in child.item.keywords: child.img_square.color = child.color Animation.stop_all(child) anim = Animation(opacity=1, d=1) + Animation( opacity=previous_opacity, d=5) anim.start(child) else: opacity_min = .1 Animation.stop_all(child) anim = Animation(opacity=opacity_min, d=1) + Animation( opacity=previous_opacity, d=5) anim.start(child) if hasattr(child, 'content_container' ) and child.content_container != None: anim2 = Animation( opacity=opacity_min, d=.5) + Animation( opacity=opacity_min, d=2) + Animation( opacity=1, d=1) anim2.start(child.content_container) anim1 = Animation(color=(1, 1, 1, 1), d=10) anim1.start(child.img_square) anim2 = Animation(color=previous_color, d=10) anim2.start(child) mediaButton = Button(background_normal='widgets/caption-media.png', background_down='widgets/caption-media-active.png', size_hint=(None, None), size=(100, 100), border=(0, 0, 0, 0), x=Window.width - 100, y=0) mediaButton.cat = 'media' mediaButton.bind(on_release=magnify_items) root.add_widget(mediaButton) objetButton = Button(background_normal='widgets/caption-objet.png', background_down='widgets/caption-objet-active.png', size_hint=(None, None), size=(100, 100), border=(0, 0, 0, 0), x=0, y=0) objetButton.cat = 'objet' objetButton.bind(on_release=magnify_items) root.add_widget(objetButton) usageButton = Button(background_normal='widgets/caption-usage.png', background_down='widgets/caption-usage-active.png', size_hint=(None, None), size=(100, 100), border=(0, 0, 0, 0), x=Window.width - 100, y=Window.height - 100) usageButton.cat = 'usage' usageButton.bind(on_release=magnify_items) root.add_widget(usageButton) # ------------------------------------------------------------------------- # ------------------------------------------------------------------------- # APP MODIFICATIONS # ------------------------------------------------------------------------- # ------------------------------------------------------------------------- # remove all children from filtered items list app.all_items = app.db.items tmp = [] for item in app.all_items: if len(item['children']) != 0: # item is parent tmp.append(item) app.db.items = tmp local_pos = [] i = 5 j = 3 while j > 0: while i > 0: i -= 1 local_pos.append((344 * i + 300, 293 * j)) i = 5 j -= 1 def show_objects(objects): self = app root = self.root positions = local_pos[:] shuffle(positions) app.images_pos.clear() if isinstance(self.root_images.x, (int, long)): if root.type_expo == 'normal': # images = [x.source for x in self.root_images.children] images = [] # for x in self.root_images.children[:]: # if isinstance(x, ImageItem): # images.append(x.source) images_to_add = [] images_displayed = [] for item in objects[:]: # is the current filename is already showed ? filename = item.filename # if filename in images: # images.remove(filename) # continue x = randint(self.root_images.x + 200, self.root_images.right - 200) y = randint(root.y + 300, root.top - 100) if len(item.children) > 0: if len(positions) > 0: x, y = choice(positions) positions.remove((x, y)) angle = randint(0, 360) image = dict(source=filename, rotation=angle + 90, center=(x, y), item=item, app=self) images_to_add.append(image) images_displayed.append(filename) objects.remove(item) # remove all the previous images for child in self.root_images.children[:]: if isinstance(child, ImageItem): # for filename in images: # if filename == child.source: # self.images_pos[filename] = { # 'center': child.center, # 'rotation': child.rotation } if hasattr(child, 'on_remove'): child.on_remove( ) # close everything and remove all physics attributes from child self.root_images.remove_widget(child) self.images_displayed = images_displayed self.delayed_work(self.show_object, images_to_add) def add_physics_bodies(*largs): if app.items_to_add == 0: init_items_bodies(.5) Clock.unschedule(add_physics_bodies) Clock.schedule_interval(add_physics_bodies, 0.1) # add physics attribute to new items app.show_objects = show_objects def bring_content_to_front(dt): if app.items_to_add == 0: parent = app.root if hasattr(app, 'root_content_layout'): parent.remove_widget(app.root_content_layout) parent.add_widget(app.root_content_layout) Clock.unschedule(bring_content_to_front) def trigger_content_layout_to_front(): Clock.schedule_interval(bring_content_to_front, .1) def my_update_objects_from_filter(dt, *largs): '''Update the objects displayed from filters (date range, origin...) ''' self = app items = self.db.items # filter from keywords but with image buttons, only if there is group of keyword with 'filtre' in the group's name if app.imageButtons: keywords_names = app.imageButtons.active_ids app.keywords_ids = keywords_ids = [] groups = self.db.keywords items_result = [] keywords_all = [] time_keyword = ['297', '298', '299', '300', '301', '302'] for group in groups: if group['group'].find('filtre') != -1: keywords_all = group['children'] if (keywords_all): for name in keywords_names: for keyword in keywords_all: if name == keyword['name']: keywords_ids.append(keyword['id']) for item in items: for key in keywords_ids: if key in item.keywords: items_result.append(item) if app.imageButtons.show_objects_when_empty == True: if not keywords_names and not items_result: #si aucune image activee et aucun resultat items_result = items # on affiche tout # Adding parents which have children selected by keyword tmp = [] for parent in items: if parent not in items_result: for child_id in parent.children: for child in self.all_items: if child.id == int(child_id): for key in keywords_ids: if key in child.keywords and parent not in tmp: tmp.append(parent) items_result = items_result + tmp # Limit at 15 parents # del items_result[len(local_pos):] del items_result[15:] shuffle(items_result) #adding children of parents for item in items_result: if len(item.children) > 0: for child in self.all_items: if str(child.id) in item.children: items_result.append(child) items = items_result self.show_objects(items) trigger_content_layout_to_front() # create trigger for updating objects my_trigger_objects_filtering = Clock.create_trigger( my_update_objects_from_filter, 0) app.trigger_objects_filtering = my_trigger_objects_filtering # ------------------------------------------------------------------------- # ------------------------------------------------------------------------- # SCREENSAVER # ------------------------------------------------------------------------- # ------------------------------------------------------------------------- def screensaver(dt=None, stop=False): Animation.stop_all(scatter_imageButtons) if not stop: anim = Animation(opacity=.5, d=5) anim.start(scatter_imageButtons) else: scatter_imageButtons.opacity = 1 for child in app.root_images.children: if child.isParent and child.__class__.__name__ == 'ImageItem': if hasattr(child, 'body') and child.body != None: if stop == False: forces = [-5, 5, 0] rx = choice(forces) ry = choice(forces) child.body.reset_forces() child.body.apply_force((rx, ry), r=(0, 0)) else: child.body.reset_forces() def launch_screensaver(dt): delay = time.time() - app.last_touch_time if delay > 5: Clock.schedule_interval(screensaver, 5) Clock.unschedule(launch_screensaver) # Clock.schedule_interval(launch_screensaver, 1) def stop_screensaver(): Clock.unschedule(screensaver) Clock.schedule_interval(launch_screensaver, 1) scatter_imageButtons.opacity = 1 screensaver(stop=True) app.last_touch_time = 0 def on_touch_app(touch): app.last_touch_time = touch.time_start for child in root.children[:]: if child.dispatch('on_touch_down', touch): stop_screensaver() return True # root.on_touch_down = on_touch_app # ------------------------------------------------------------------------- # ------------------------------------------------------------------------- # NETWORK PART # ------------------------------------------------------------------------- # ------------------------------------------------------------------------- # factory = WebSocketServerFactory("ws://localhost:9000") # factory.protocol = EchoServerProtocol # listenWS(factory) # ------------------------------------------------------------------------- # ------------------------------------------------------------------------- # BASKET # ------------------------------------------------------------------------- # ------------------------------------------------------------------------- # ------------------------------------------------------------------------- # Create a basket widget # This button is on the bottom/left part of the screen kwargs = { 'pos_hint': { 'right': 1, 'top': 1 }, 'size_hint': (None, None), 'size': (64, 64), 'border': (0, 0, 0, 0), 'color': (0, 0, 0, 1), 'bold': True } #active to False disables the basket #email_send to True activates sending the url of the basket by email #url_send to True activates sending the url of the basket to a specific url app.basket = basket = Basket( active=False, background_normal='widgets/corner_topright.png', background_down='widgets/corner_topright_down.png', email_send=True, url_send=False, url_send_url='http://urltest.lapin.be?url=', app=app, **kwargs) # ------------------------------------------------------------------------- return root