class PrintScreen(GridLayout):
    def __init__(self, **kwargs):
        super(PrintScreen,self).__init__(**kwargs)

        self.cols = 1
        image_file_source = Path('slices/out' + str(0).zfill(4) + '.png')
        self.image = Image(allow_stretch= True,source = str(image_file_source), size_hint = (x_size,y_size), pos_hint = {'center_x': x, 'center_y': y})
        self.image.bind()
        self.add_widget(self.image)
        #HOW MUCH DELAY
        Clock.schedule_interval(self.update_pic,.1)

    def update_pic(self,dt):
        global number
        number += 1
        image_file_source = Path('slices/out' + str(number).zfill(4) + '.png')
        if image_file_source.is_file():
            self.image = Image(allow_stretch= True,source = str(image_file_source), size_hint = (x_size,y_size), pos_hint = {'center_x': x, 'center_y': y})
            self.image.bind()
            self.clear_widgets()
            self.add_widget(self.image)
            #DELAY???
            #r = requests.get(ApiCall_pos)
        else:
            Clock.unschedule(self.update_pic)
            PhonePrinter_App.screen_manager.current = 'MainScreen'
예제 #2
0
    def __init__(self, previous, image_set, fragment_list=None, **kwargs):
        super(GameScreen, self).__init__(**kwargs)
        # screen we came from, to pass on to game over/victory screen
        self.previous = previous

        # set image for the map and prepare it for color selection
        self.source = image_set.sources["raw"]
        self.image.imdata = utils.ImageArray.load(self.source)
        self.image.bind(on_touch_down=self.color_drop)

        # loads fragments from fragment directory
        self.f_index = 0
        self.fragments = []
        if os.path.exists(config.fragment_directory):
            for f in os.listdir(config.fragment_directory):
                if fragment_list is None or f in fragment_list:
                    imgpath = os.path.join(config.fragment_directory, f)
                    if os.path.isfile(imgpath):
                        img = Image(source=imgpath)
                        img.bind(on_touch_down=self.im_press)
                        self.fragments.append(img)

        # cursor options
        self.cursor_active = False
        self.cursor_array = self.fragments

        self.picker = None
        self.scatter = None
        self.cutter_event = None

        # starting values
        self.completion = 0
        self.tree_start = self.tree.height
        self.forest_color = None
        self.started = False
class TestImage(GridLayout):
    def __init__(self, **kwargs):
        super(TestImage,self).__init__(**kwargs)

        self.cols = 1
        self.image = Image(allow_stretch= True,source='slices/out0400.png',size_hint=(x_size,y_size),pos_hint={'center_x': x, 'center_y': y})
        self.image.bind()
        self.add_widget(self.image)
예제 #4
0
 def display_help_screen(self):
     # display the help screen on a Popup
     image = Image(source='graphics/help_screen.png')
     
     help_screen = Popup(title='Quick Guide through DEFLECTOUCH',
                         attach_to=self,
                         size_hint=(0.98, 0.98),
                         content=image)
     image.bind(on_touch_down=help_screen.dismiss)
     help_screen.open()
예제 #5
0
    def display_help_screen(self):
        # display the help screen on a Popup
        image = Image(source='graphics/help_screen.png')

        help_screen = Popup(title='Quick Guide through DEFLECTOUCH',
                            attach_to=self,
                            size_hint=(0.98, 0.98),
                            content=image)
        image.bind(on_touch_down=help_screen.dismiss)
        help_screen.open()
예제 #6
0
class B1L3(Screen):  # Building 1 Level 3
    def __init__(self, **kwargs):
        Screen.__init__(self, **kwargs)
        self.layout = FloatLayout()

        # Mapping of the Dustbin
        self.label2 = Label(text='.',
                            color=(0, 0, 1, 1),
                            font_size=100,
                            pos=(-260, 54))
        self.label3 = Label(text='1.3A (1%)',
                            color=(0, 0, 1, 1),
                            font_size=18,
                            pos=(-260, -1))
        self.label4 = Label(text='.',
                            color=(0, 0, 1, 1),
                            font_size=100,
                            pos=(-185, 70))
        self.label5 = Label(text='1.3B (1%)',
                            color=(0, 0, 1, 1),
                            font_size=18,
                            pos=(-185, 15))
        self.label6 = Label(text='.',
                            color=(0, 0, 1, 1),
                            font_size=100,
                            pos=(-45, -100))
        self.label7 = Label(text='1.3C (1%)',
                            color=(0, 0, 1, 1),
                            font_size=18,
                            pos=(-45, -155))

        # Floor Plan and Slide Detection
        self.image1 = Image(source='Building1.png')
        self.image1.bind(on_touch_move=self.detect)

        # Add Widget
        self.layout.add_widget(self.image1)
        self.layout.add_widget(self.label2)
        self.layout.add_widget(self.label3)
        self.layout.add_widget(self.label4)
        self.layout.add_widget(self.label5)
        self.layout.add_widget(self.label6)
        self.layout.add_widget(self.label7)

        self.add_widget(self.layout)

    def detect(self, instance, touch):
        if touch.dy < -20:  # Slide down to Building 2 Level 3
            self.manager.transition.direction = 'down'
            self.manager.current = 'B2L3'

        if touch.dx < -20:  # Slide to left to Building 1 Level 4
            self.manager.transition.direction = 'left'
            self.manager.current = 'B1L4'
예제 #7
0
 def display_help_screen(self):
     # zeigt die how to bilder an
     image = Image(source="images/help4.png")
     help_screen1 = Popup(title="How to",
                          attach_to=self,
                          size_hint=(0.98, 0.98),
                          content=image)
     image.bind(on_touch_down=help_screen1.dismiss)
     help_screen1.open()
     image = Image(source="images/help3.png")
     help_screen2 = Popup(title="How to",
                          attach_to=self,
                          size_hint=(0.98, 0.98),
                          content=image)
     image.bind(on_touch_down=help_screen2.dismiss)
     help_screen2.open()
     image = Image(source="images/help2.png")
     help_screen3 = Popup(title="How to",
                          attach_to=self,
                          size_hint=(0.98, 0.98),
                          content=image)
     image.bind(on_touch_down=help_screen3.dismiss)
     help_screen3.open()
     image = Image(source="images/help1.png")
     help_screen4 = Popup(title="How to",
                          attach_to=self,
                          size_hint=(0.98, 0.98),
                          content=image)
     image.bind(on_touch_down=help_screen4.dismiss)
     help_screen4.open()
예제 #8
0
    def get_row_item(self, index, controller):
        """
        Build and return a formatted DisplayItem for the folder.
        """
        # Initialize
        album = self.albums[index]

        if 'tracks' not in album.keys():
            self._populate_album(album)
        di = DisplayItem()
        add_label = di.ids.labels.add_widget

        # Add header
        add_label(Label(
            text=u"[b][color=#FFFF00]{0} : {1}[/color][/b]".format(
                 album['artist'], album['album']),
            markup=True))

        # Add images + warnings
        if len(album['images']) == 0:
            di.ids.images.add_widget(Image(source="images/album.png"))
        else:
            for source in album['images']:
                image = Image(source=source, allow_stretch=True)
                image.bind(on_touch_down=lambda w, t:
                           w.collide_point(*t.pos) and controller.stop())
                di.ids.images.add_widget(image)

        [add_label(Label(
            text=u"[color=#FF0000]{0}[/color]".format(warn)))
            for warn in album['warnings']]

        # Add tracks
        for k, track in enumerate(album['tracks']):
            playing = bool(
                controller.playing_album == controller.album_index and
                controller.playing_track == k)
            pl_label = PlaylistLabel(
                controller=controller,
                text=track,
                album_index=index,
                track_index=k)
            add_label(pl_label)
            if playing:
                controller.set_selected(pl_label)

        return di
예제 #9
0
class GridHangman(GridLayout):
    """3rd level grid for Hangman graphic."""
    def __init__(self, **kwargs):
        super(GridHangman, self).__init__(**kwargs)
        self.rows = 2
        self.row_force_default = True
        self.row_default_height = 180

        self.imgsource = 'images/hangman-1-11.png'
        self.hangman = Image(source=self.imgsource, size=(500, 500))
        self.add_widget(self.hangman)
        self.hangman.bind(on_press=change_img)

        self.wrongletters = Label(text='')
        self.add_widget(self.wrongletters)

        self.bind(pos=callback_pos)
예제 #10
0
    def get_row_item(self, index, controller):
        """
        Build and return a formatted DisplayItem for the folder.
        """
        # Initialize
        album = self.albums[index]

        if 'tracks' not in album.keys():
            self._populate_album(album)
        di = DisplayItem()
        add_label = di.ids.labels.add_widget

        # Add header
        add_label(
            Label(text=u"[b][color=#FFFF00]{0} : {1}[/color][/b]".format(
                album['artist'], album['album']),
                  markup=True))

        # Add images + warnings
        if len(album['images']) == 0:
            di.ids.images.add_widget(Image(source="images/album.png"))
        else:
            for source in album['images']:
                image = Image(source=source, allow_stretch=True)
                image.bind(on_touch_down=lambda w, t: w.collide_point(*t.pos)
                           and controller.stop())
                di.ids.images.add_widget(image)

        [
            add_label(Label(text=u"[color=#FF0000]{0}[/color]".format(warn)))
            for warn in album['warnings']
        ]

        # Add tracks
        for k, track in enumerate(album['tracks']):
            playing = bool(controller.playing_album == controller.album_index
                           and controller.playing_track == k)
            pl_label = PlaylistLabel(controller=controller,
                                     text=track,
                                     album_index=index,
                                     track_index=k)
            add_label(pl_label)
            if playing:
                controller.set_selected(pl_label)

        return di
예제 #11
0
class GridHangman(GridLayout):
    """3rd level grid for Hangman graphic."""
    def __init__(self, **kwargs):
        super(GridHangman, self).__init__(**kwargs)
        self.rows = 2
        self.row_force_default=True
        self.row_default_height=180

        self.imgsource = 'images/hangman-1-11.png'
        self.hangman = Image(source=self.imgsource, size=(500,500))
        self.add_widget(self.hangman)
        self.hangman.bind(on_press=change_img)

        self.wrongletters = Label(text='')
        self.add_widget(self.wrongletters)

        self.bind(pos=callback_pos)
예제 #12
0
class MyBigImage(FloatLayout):
    def __init__(self, **kwargs):
        super(MyBigImage, self).__init__(**kwargs)
	self.velocity = [8, 6]
	self.addImage("bluerose.png")
	self.sound = self.sound = SoundLoader.load("glass.ogg")
	Clock.schedule_interval(self.moving, 1.0/3)

    def addImage(self, filename):
        self.image = Image(source=filename, mipmap=True)
	self.image.size_hint = None, None
	self.image.width = 140
	self.image.height = 140
	self.image.pos = 300+random.randint(-200,200), 200+random.randint(-150,150)
	self.add_widget(self.image)
	self.image.bind(on_touch_down=self.touchMove)


    def moving(self, dt):
	self.sound.play()
        x, y = self.image.pos
        if x < 0: x = 0
        if y < 0: y = 0
        x = x + self.velocity[0]
        y = y + self.velocity[1]
        self.image.pos = x, y
        ww = app.root.width - 128
        hh = app.root.height - 128
        if x > ww:
                self.velocity[0] = - random.randint(1,10)
	elif x <= 0:
                self.velocity[0] =  random.randint(1,10)
        if y > hh:
                self.velocity[1] = - random.randint(1,10)
	elif y <= 0:
                self.velocity[1] =  random.randint(1,10)
	return

    def touchMove(self, image, touch):
	if image.collide_point( *touch.pos):
		Clock.unschedule(self.moving)
		return True
        return super(MyBigImage, self).on_touch_down(touch)
예제 #13
0
파일: gui.py 프로젝트: yOyOeK1/ykpilot
class ImageFromTexture(BoxLayout):
	
	
	def __init__(self, **kwargs):
		self.myCanvas = self.canvas
		
		super(ImageFromTexture, self).__init__(**kwargs)
		self.imgTexture = Image(source='./icons/ico_find_64_64.png')
		self.canvas.add(Color(1,.5,1))
		self.r = Rectangle(
			size=self.size, 
			pos = self.pos
			)
		self.canvas.add(self.r)
		self.imgTexture.bind(texture=self.update_texture)
		
	
	def update_texture(self, instance, value):
		print("update_texture",instance," value ",value)
		self.r.texture = value
예제 #14
0
파일: y.py 프로젝트: ik486/kivy_examples
class MyBigImage(FloatLayout):
    def __init__(self, **kwargs):
        super(MyBigImage, self).__init__(**kwargs)
	for i in range(20):
		self.addImage("bluerose.png")

    def addImage(self, filename):
        self.image = Image(source=filename, mipmap=True)
	self.image.size_hint = None, None
	self.image.width = 140
	self.image.height = 140
	self.image.pos = 300+random.randint(-200,200), 200+random.randint(-150,150)
	self.add_widget(self.image)
	self.image.bind(on_touch_move=self.touchMove)

    def touchMove(self, image, touch):
	if image.collide_point( *touch.pos):
		image.pos = image.pos[0]+touch.dx, image.pos[1]+touch.dy
		return True
        return super(MyBigImage, self).on_touch_down(touch)
예제 #15
0
    def __init__(self, difficulty, level_list, **kwargs):
        super(TrainingLevelScreen, self).__init__(**kwargs)
        self.difficulty = difficulty

        # checks for the level directory and lists its files
        if os.path.exists(config.level_directory):
            for l in os.listdir(config.level_directory):

                # checks the files with the correct naming conventions (DIFFICULTY_NAME.png)
                split = l.split("_")
                if split[0] == difficulty and (level_list is None or l[1] in level_list):
                    levelpath = os.path.join(config.level_directory, l)

                    # loads files onto the grid
                    if os.path.isfile(levelpath):
                        img = Image(source=levelpath)
                        img.bind(on_touch_down=self.select_level)
                        self.grid.add_widget(img)

        # cursor options
        self.cursor_array = self.layout.children[:-1]
        self.cursor_reverse = True
        self.cursor_wrap = True
예제 #16
0
파일: RndArt.py 프로젝트: niko886/RndArt
    def AddImageAndCategories(self, imageDict, clb=None):

        self.clear_widgets()

        l = len(imageDict.keys())
        if l % 2:
            self.rows = l / 2 + 1
        else:
            self.rows = l / 2

        categories = imageDict.keys()

        if len(categories) > 1:
            random.shuffle(categories)

        for category in categories:

            img = Image(source=imageDict[category]['image'])
            img.name = category

            if clb:
                img.bind(on_touch_down=clb)

            img = self.add_widget(img)
예제 #17
0
파일: bubble.py 프로젝트: emanuele/kivy
class Bubble(GridLayout):
    '''Bubble class, see module documentation for more information.
    '''

    background_color = ListProperty([1, 1, 1, 1])
    '''Background color, in the format (r, g, b, a).

    :data:`background_color` is a :class:`~kivy.properties.ListProperty`,
    default to [1, 1, 1, 1].
    '''

    border = ListProperty([16, 16, 16, 16])
    '''Border used for :class:`~kivy.graphics.vertex_instructions.BorderImage`
    graphics instruction, used itself for :data:`background_image`.
    Can be used when using custom background.

    It must be a list of 4 value: (top, right, bottom, left). Read the
    BorderImage instruction for more information about how to play with it.

    :data:`border` is a :class:`~kivy.properties.ListProperty`, default to (16,
    16, 16, 16)
    '''

    background_image = StringProperty('data/images/bubble.png')
    '''Background image of the bubble

    :data:`background_image` is a :class:`~kivy.properties.StringProperty`,
    default to 'data/images/bubble.png'.
    '''

    arrow_image = StringProperty('data/images/bubble_arrow.png')
    ''' Image of the arrow pointing to the bubble

    :data:`arrow_image` is a :class:`~kivy.properties.StringProperty`,
    default to 'data/images/bubble_arrow.png'.
    '''

    arrow_pos = OptionProperty('bottom_mid',
            options=('left_top', 'left_mid', 'left_bottom', 'top_left',
                'top_mid', 'top_right', 'right_top', 'right_mid',
                'right_bottom', 'bottom_left', 'bottom_mid', 'bottom_right'))
    '''Specifies the position of the arrow relative to the bubble.
    Can be one of: left_top, left_mid, left_bottom top_left, top_mid, top_right
    right_top, right_mid, right_bottom bottom_left, bottom_mid, bottom_right.

    :data:`arrow_pos` is a :class:`~kivy.properties.OptionProperty`,
    default to 'bottom_mid'.
    '''

    background_texture = ObjectProperty(None)
    '''Specifies the background texture of the bubble

    :data:`background_texture` is a :class:`~kivy.properties.ObjectProperty`,
    default to 'None'.
    '''

    content = ObjectProperty(None)
    '''This is the object where the main content of the bubble is held

    :data:`content` is a :class:`~kivy.properties.ObjectProperty`,
    default to 'None'.
    '''

    orientation = OptionProperty('horizontal',
            options=('horizontal', 'vertical'))
    '''This specifies the manner in which the children inside bubble
    are arranged. can be one of 'vertical', 'horizontal'

    :data:`orientation` is a :class:`~kivy.properties.OptionProperty`,
    default to 'horizontal'.
    '''

    def __init__(self, **kwargs):
        self._arrow_layout = GridLayout(rows=1)
        self._bk_img = Image(
            source=self.background_image, allow_stretch=True,
            keep_ratio=False, color=self.background_color)
        self.background_texture = self._bk_img.texture
        self._arrow_img = Image(source=self.arrow_image,
            color=self.background_color)
        self.content = content = BubbleContent()
        super(Bubble, self).__init__(**kwargs)
        self.add_widget(content)
        self._bk_img.bind(on_texture=self._on_texture)
        self.on_arrow_pos()

    def _on_texture(self, *l):
        self.background_texture = self._bk_img.texture

    def add_widget(self, *l):
        content = self.content
        if content is None:
            return
        if l[0] == content or l[0] == self._arrow_img\
            or l[0] == self._arrow_layout:
            super(Bubble, self).add_widget(*l)
        else:
            content.add_widget(l[0])

    def remove_widget(self, *l):
        content = self.content
        if content is None:
            return
        if l[0] == content or l[0] == self._arrow_img\
            or l[0] == self._arrow_layout:
            super(Bubble, self).remove_widget(*l)
        else:
            content.remove_widget(l[0])

    def clear_widgets(self, **kwargs):
        content = self.content
        if content is None:
            return
        if kwargs.get('do_super', False):
            super(Bubble, self).clear_widgets()
        else:
            content.clear_widgets()

    def on_background_image(self, *l):
        self._bk_img.source = self.background_image

    def on_background_color(self, *l):
        if self.content is None:
            return
        self._arrow_img.color = self._bk_img.color = self.background_color

    def on_orientation(self, *l):
        content = self.content
        if not content:
            return
        if self.orientation[0] == 'v':
            content.cols = 1
            content.rows = 99
        else:
            content.cols = 99
            content.rows = 1

    def on_arrow_image(self, *l):
        self._arrow_img.source = self.arrow_image

    def on_arrow_pos(self, *l):
        self_content = self.content
        if not self_content:
            return
        self_arrow_pos = self.arrow_pos
        self_arrow_layout = self._arrow_layout
        self_arrow_layout.clear_widgets()
        self_arrow_img = self._arrow_img
        self_arrow_img.pos = (0, 0)

        self.clear_widgets(do_super=True)
        self_arrow_img.size_hint = (1, None)
        self_arrow_img.height = self_arrow_img.texture_size[1]
        widget_list = []
        arrow_list = []
        if self_arrow_pos[0] == 'b' or self_arrow_pos[0] == 't':
            self.cols = 1
            self.rows = 2
            self_arrow_layout.rows = 1
            self_arrow_layout.cols = 3
            self_arrow_img.width = self.width/3
            self_arrow_layout.size_hint = (1, None)
            self_arrow_layout.height = self_arrow_img.height
            if self_arrow_pos[0] == 'b':
                if self_arrow_pos == 'bottom_mid':
                    widget_list = (self_content, self_arrow_img)
                else:
                    if self_arrow_pos == 'bottom_left':
                        arrow_list = (self_arrow_img, Widget(), Widget())
                    elif self_arrow_pos == 'bottom_right':
                        #add two dummy widgets
                        arrow_list = (Widget(), Widget(), self_arrow_img)
                    widget_list = (self_content, self_arrow_layout)
            else:
                sctr = Scatter(do_translation = False,
                               rotation = 180,
                               do_rotation = False,
                               do_scale = False,
                               size_hint = (None, None),
                               size = self_arrow_img.size)
                sctr.add_widget(self_arrow_img)
                if self_arrow_pos == 'top_mid':
                    #add two dummy widgets
                    arrow_list = (Widget(), sctr, Widget())
                elif self_arrow_pos == 'top_left':
                    arrow_list = (sctr, Widget(), Widget())
                elif self_arrow_pos == 'top_right':
                    arrow_list = (Widget(), Widget(), sctr)
                widget_list = (self_arrow_layout, self_content)
        elif self_arrow_pos[0] == 'l' or self_arrow_pos[0] == 'r':
            self.cols = 2
            self.rows = 1
            self_arrow_img.width = self.height/3
            self_arrow_layout.rows = 3
            self_arrow_layout.cols = 1
            self_arrow_layout.size_hint = (None, 1)
            self_arrow_layout.width = self_arrow_img.height

            rotation = -90 if self_arrow_pos[0] == 'l' else 90
            sctr = Scatter(do_translation = False,
                               rotation = rotation,
                               do_rotation = False,
                               do_scale = False,
                               size_hint = (None, None),
                               size = self_arrow_img.size)
            sctr.add_widget(self_arrow_img)

            lenarrow_pos = len(self_arrow_pos)
            if self_arrow_pos[lenarrow_pos-4:] == '_top':
                arrow_list = (Widget(size_hint = (1, .07)),
                              sctr, Widget(size_hint = (1, .3)))
            elif self_arrow_pos[lenarrow_pos-4:] == '_mid':
                arrow_list = (Widget(), sctr, Widget())
            elif self_arrow_pos[lenarrow_pos-7:] == '_bottom':
                arrow_list = (Widget(), Widget(), sctr)

            if self_arrow_pos[0] =='l':
                widget_list = (self_arrow_layout, self_content)
            else:
                widget_list = (self_content, self_arrow_layout)

        # add widgets to arrow_layout
        add = self_arrow_layout.add_widget
        for widg in arrow_list:
            add(widg)

        # add widgets to self
        add = self.add_widget
        for widg in widget_list:
            add(widg)
예제 #18
0
class Bubble(GridLayout):
    '''Bubble class, see module documentation for more information.
    '''

    background_color = ListProperty([1, 1, 1, 1])
    '''Background color, in the format (r, g, b, a).

    :data:`background_color` is a :class:`~kivy.properties.ListProperty`,
    default to [1, 1, 1, 1].
    '''

    border = ListProperty([16, 16, 16, 16])
    '''Border used for :class:`~kivy.graphics.vertex_instructions.BorderImage`
    graphics instruction, used itself for :data:`background_image`.
    Can be used when using custom background.

    It must be a list of 4 value: (top, right, bottom, left). Read the
    BorderImage instruction for more information about how to play with it.

    :data:`border` is a :class:`~kivy.properties.ListProperty`, default to (16,
    16, 16, 16)
    '''

    background_image = StringProperty('data/images/bubble.png')
    '''Background image of the bubble

    :data:`background_image` is a :class:`~kivy.properties.StringProperty`,
    default to 'data/images/bubble.png'.
    '''

    arrow_image = StringProperty('data/images/bubble_arrow.png')
    ''' Image of the arrow pointing to the bubble

    :data:`arrow_image` is a :class:`~kivy.properties.StringProperty`,
    default to 'data/images/bubble_arrow.png'.
    '''

    arrow_pos = OptionProperty(
        'bottom_mid',
        options=('left_top', 'left_mid', 'left_bottom', 'top_left', 'top_mid',
                 'top_right', 'right_top', 'right_mid', 'right_bottom',
                 'bottom_left', 'bottom_mid', 'bottom_right'))
    '''Specifies the position of the arrow relative to the bubble.
    Can be one of: left_top, left_mid, left_bottom top_left, top_mid, top_right
    right_top, right_mid, right_bottom bottom_left, bottom_mid, bottom_right.

    :data:`arrow_pos` is a :class:`~kivy.properties.OptionProperty`,
    default to 'bottom_mid'.
    '''

    background_texture = ObjectProperty(None)
    '''Specifies the background texture of the bubble

    :data:`background_texture` is a :class:`~kivy.properties.ObjectProperty`,
    default to 'None'.
    '''

    content = ObjectProperty(None)
    '''This is the object where the main content of the bubble is held

    :data:`content` is a :class:`~kivy.properties.ObjectProperty`,
    default to 'None'.
    '''

    orientation = OptionProperty('horizontal',
                                 options=('horizontal', 'vertical'))
    '''This specifies the manner in which the children inside bubble
    are arranged. can be one of 'vertical', 'horizontal'

    :data:`orientation` is a :class:`~kivy.properties.OptionProperty`,
    default to 'horizontal'.
    '''
    def __init__(self, **kwargs):
        self._arrow_layout = GridLayout(rows=1)
        self._bk_img = Image(source=self.background_image,
                             allow_stretch=True,
                             keep_ratio=False,
                             color=self.background_color)
        self.background_texture = self._bk_img.texture
        self._arrow_img = Image(source=self.arrow_image,
                                color=self.background_color)
        self.content = content = BubbleContent()
        super(Bubble, self).__init__(**kwargs)
        self.add_widget(content)
        self._bk_img.bind(on_texture=self._on_texture)
        self.on_arrow_pos()

    def _on_texture(self, *l):
        self.background_texture = self._bk_img.texture

    def add_widget(self, *l):
        content = self.content
        if content is None:
            return
        if l[0] == content or l[0] == self._arrow_img\
            or l[0] == self._arrow_layout:
            super(Bubble, self).add_widget(*l)
        else:
            content.add_widget(l[0])

    def remove_widget(self, *l):
        content = self.content
        if content is None:
            return
        if l[0] == content or l[0] == self._arrow_img\
            or l[0] == self._arrow_layout:
            super(Bubble, self).remove_widget(*l)
        else:
            content.remove_widget(l[0])

    def clear_widgets(self, **kwargs):
        content = self.content
        if content is None:
            return
        if kwargs.get('do_super', False):
            super(Bubble, self).clear_widgets()
        else:
            content.clear_widgets()

    def on_background_image(self, *l):
        self._bk_img.source = self.background_image

    def on_background_color(self, *l):
        if self.content is None:
            return
        self._arrow_img.color = self._bk_img.color = self.background_color

    def on_orientation(self, *l):
        content = self.content
        if not content:
            return
        if self.orientation[0] == 'v':
            content.cols = 1
            content.rows = 99
        else:
            content.cols = 99
            content.rows = 1

    def on_arrow_image(self, *l):
        self._arrow_img.source = self.arrow_image

    def on_arrow_pos(self, *l):
        self_content = self.content
        if not self_content:
            return
        self_arrow_pos = self.arrow_pos
        self_arrow_layout = self._arrow_layout
        self_arrow_layout.clear_widgets()
        self_arrow_img = self._arrow_img
        self_arrow_img.pos = (0, 0)

        self.clear_widgets(do_super=True)
        self_arrow_img.size_hint = (1, None)
        self_arrow_img.height = self_arrow_img.texture_size[1]
        widget_list = []
        arrow_list = []
        if self_arrow_pos[0] == 'b' or self_arrow_pos[0] == 't':
            self.cols = 1
            self.rows = 2
            self_arrow_layout.rows = 1
            self_arrow_layout.cols = 3
            self_arrow_img.width = self.width / 3
            self_arrow_layout.size_hint = (1, None)
            self_arrow_layout.height = self_arrow_img.height
            if self_arrow_pos[0] == 'b':
                if self_arrow_pos == 'bottom_mid':
                    widget_list = (self_content, self_arrow_img)
                else:
                    if self_arrow_pos == 'bottom_left':
                        arrow_list = (self_arrow_img, Widget(), Widget())
                    elif self_arrow_pos == 'bottom_right':
                        #add two dummy widgets
                        arrow_list = (Widget(), Widget(), self_arrow_img)
                    widget_list = (self_content, self_arrow_layout)
            else:
                sctr = Scatter(do_translation=False,
                               rotation=180,
                               do_rotation=False,
                               do_scale=False,
                               size_hint=(None, None),
                               size=self_arrow_img.size)
                sctr.add_widget(self_arrow_img)
                if self_arrow_pos == 'top_mid':
                    #add two dummy widgets
                    arrow_list = (Widget(), sctr, Widget())
                elif self_arrow_pos == 'top_left':
                    arrow_list = (sctr, Widget(), Widget())
                elif self_arrow_pos == 'top_right':
                    arrow_list = (Widget(), Widget(), sctr)
                widget_list = (self_arrow_layout, self_content)
        elif self_arrow_pos[0] == 'l' or self_arrow_pos[0] == 'r':
            self.cols = 2
            self.rows = 1
            self_arrow_img.width = self.height / 3
            self_arrow_layout.rows = 3
            self_arrow_layout.cols = 1
            self_arrow_layout.size_hint = (None, 1)
            self_arrow_layout.width = self_arrow_img.height

            rotation = -90 if self_arrow_pos[0] == 'l' else 90
            sctr = Scatter(do_translation=False,
                           rotation=rotation,
                           do_rotation=False,
                           do_scale=False,
                           size_hint=(None, None),
                           size=self_arrow_img.size)
            sctr.add_widget(self_arrow_img)

            lenarrow_pos = len(self_arrow_pos)
            if self_arrow_pos[lenarrow_pos - 4:] == '_top':
                arrow_list = (Widget(size_hint=(1, .07)), sctr,
                              Widget(size_hint=(1, .3)))
            elif self_arrow_pos[lenarrow_pos - 4:] == '_mid':
                arrow_list = (Widget(), sctr, Widget())
            elif self_arrow_pos[lenarrow_pos - 7:] == '_bottom':
                arrow_list = (Widget(), Widget(), sctr)

            if self_arrow_pos[0] == 'l':
                widget_list = (self_arrow_layout, self_content)
            else:
                widget_list = (self_content, self_arrow_layout)

        # add widgets to arrow_layout
        add = self_arrow_layout.add_widget
        for widg in arrow_list:
            add(widg)

        # add widgets to self
        add = self.add_widget
        for widg in widget_list:
            add(widg)
class ViewerScreen(Screen):
    src = StringProperty("")
    label_text = StringProperty("")
    slider_value = NumericProperty(1)
    
    def __init__(self, firebase, **kwargs):
        super(ViewerScreen, self).__init__(**kwargs)
        with self.canvas:
            self.bg = Rectangle(source='app_data/background.jpg', pos=self.pos, size=self.size)
        self.bind(pos=self.update_bg)
        self.bind(size=self.update_bg)
        
        self.firebase = firebase
        self.event = None
        self._popup = None
        self.user_data = None
        self.page = 0
        self.default_zoom = [1, 2.79]
        self.num_pages = 0
        self.timeout = 30

        box_layout = BoxLayout(
            orientation='vertical'
        )
        bar_panel = BarPanel(
            orientation='horizontal',
            size_hint=(1, None),
            height=80,
            padding=7
        )
        image = Image(
            size_hint=(None, 1),
            width=150,
            source='app_data/master_fitness_logo_w_noaddr.png'
        )
        self.label = Label(
            size_hint=(1, 1),
            font_size=20,
            italic=True,
            text=self.label_text
        )
        self.labelPage = Label(
            size_hint=(None, 1),
            width=50,
            font_size=30,
            italic=True
        )
        self.qr_button_anchor = AnchorLayout(
            size_hint=(None, 1),
            width=100,
            anchor_x='center',
            anchor_y='center'
        )
        self.qr_button = Button(
            size_hint=(None, None),
            width=70,
            height=70,
            valign='center',
            halign='center',
            background_normal='app_data/qr_normal.png',
            background_down='app_data/qr_down.png',
            border=(0,0,0,0),
            on_release=self.on_release_qr_button
        )
        self.close_button = Button(
            size_hint=(None, None),
            width=70,
            height=70,
            valign='center',
            halign='center',
            background_normal='app_data/close_normal.png',
            background_down='app_data/close_down.png',
            border=(0,0,0,0),
            on_release=self.on_release_close_button
        )
        self.left_button = Button(
            size_hint=(None, None),
            width=70,
            height=70,
            valign='center',
            halign='center',
            background_normal='app_data/left_normal.png',
            background_down='app_data/left_down.png',
            border=(0,0,0,0),
            on_release=self.on_release_left_button
        )
        self.right_button = Button(
            size_hint=(None, None),
            width=70,
            height=70,
            valign='center',
            halign='center',
            background_normal='app_data/right_normal.png',
            background_down='app_data/right_down.png',
            border=(0,0,0,0),
            on_release=self.on_release_right_button
        )
        self.zoomOut_button = Button(
            size_hint=(None, None),
            width=70,
            height=70,
            valign='center',
            halign='center',
            background_normal='app_data/zoomOut_normal.png',
            background_down='app_data/zoomOut_down.png',
            border=(0,0,0,0),
            on_release=self.on_release_zoomOut_button
        )
        self.zoomIn_button = Button(
            size_hint=(None, None),
            width=70,
            height=70,
            valign='center',
            halign='center',
            background_normal='app_data/zoomIn_normal.png',
            background_down='app_data/zoomIn_down.png',
            border=(0,0,0,0),
            on_release=self.on_release_zoomIn_button
        )
        anchor_layout = AnchorLayout(
            size_hint=(1, 0.8),
            anchor_x='right'
        )
        self.scrollview = ScrollView(
            size_hint=(1, 1),
            bar_color=[0,0,0,0],
            bar_inactive_color=[0,0,0,0],
            effect_cls=ScrollEffect
        )
        self.slider = Slider(
            orientation='vertical',
            size_hint=(None, 1),
            width=50,
            min=0, max=1, step=0.01, value=self.slider_value,
            cursor_image='app_data/kettlebell.png',
            cursor_size=('45sp', '45sp'),
            background_vertical='app_data/slider.png',
            background_width='3sp',
            padding='30sp'
        )
        self.scrollview.bind(scroll_y=self.slider_change)
        self.slider.bind(value=self.scroll_change)
        self.img_view = None #Image(size_hint=(1, None), height=1450, nocache=True, source=self.src)

        bar_panel.add_widget(image)
        bar_panel.add_widget(self.qr_button_anchor)
        self.qr_button_anchor.add_widget(self.qr_button)
        bar_panel.add_widget(self.label)
        bar_panel.add_widget(self.zoomOut_button)
        bar_panel.add_widget(self.zoomIn_button)
        bar_panel.add_widget(self.left_button)
        bar_panel.add_widget(self.labelPage)
        bar_panel.add_widget(self.right_button)
        bar_panel.add_widget(self.close_button)
        #self.scrollview.add_widget(self.img_view)
        anchor_layout.add_widget(self.scrollview)
        anchor_layout.add_widget(self.slider)
        box_layout.add_widget(bar_panel)
        box_layout.add_widget(anchor_layout)
        self.add_widget(box_layout)

    def reschedule(self):
        Clock.unschedule(self.event)
        self.event = Clock.schedule_once(self.go_to_home, self.timeout)

    def on_pre_enter(self):
        self.scrollview.remove_widget(self.img_view)
        self.img_view = None

        self.num_pages = self.user_data['num_pages']
        self.page = self.user_data['page']
        if self.page + 1 > self.num_pages:
            self.page = self.num_pages - 1
        self.labelPage.text=str(self.page+1)+"/"+str(self.num_pages)
        self.label_text = "Scheda di "+self.user_data['name']+" "+self.user_data['surname']
        self.setSourcePath("storage_data/"+str(self.user_data['rfid'])+"/scheda_"+str(self.page)+".jpg")
        self.img_view = Image(
            size_hint=(self.default_zoom[0], self.default_zoom[1]),
            allow_stretch = True,
            nocache=True,
            source=self.src
        )
        self.img_view.bind(size_hint=self.on_img_hint_update)
        self.scrollview.add_widget(self.img_view)

        try:
            self.slider_value = self.user_data['slider_y']
            self.scrollview.scroll_x = self.user_data['slider_x']
            zoom = self.user_data['zoom']
            if zoom[0] == 0 and zoom[1] == 0:
                zoom = self.default_zoom
            self.img_view.size_hint = (zoom[0], zoom[1])
        except:
            self.slider_value = 1
            self.scrollview.scroll_x = 0.5
            self.img_view.size_hint = (self.default_zoom[0], self.default_zoom[1])
        self.reschedule()

    def on_pre_leave(self):
        Clock.unschedule(self.event)
        if self._popup :
            self._popup.dismiss()
            self._popup = None
    
    def on_leave(self):
        if self.user_data :
            data = {
                "page": self.page,
                "zoom": self.img_view.size_hint,
                "slider_x": self.scrollview.scroll_x,
                "slider_y": self.slider_value
            }
            self.saveUserData(self.user_data['rfid'], data)

        self.scrollview.remove_widget(self.img_view)
        self.img_view = None

    def go_to_home(self, *largs):
        self.manager.current = 'home'

    def scroll_change(self, instance, value):
        self.slider_value = value
        self.scrollview.scroll_y = value
        self.reschedule()

    def slider_change(self, instance, value):
        if value >= 0:
        #this to avoid 'maximum recursion depth exceeded' error
            self.slider_value = value
            self.reschedule()

    def on_release_close_button(self, instance):
        self.go_to_home()

    def on_release_qr_button(self, instance):
        self.reschedule()
        content = QrDialog(rfid=str(self.user_data['rfid']))
        self._popup = Popup(title="Scansiona il QR Code", content=content, size_hint=(None, None), width=250, height=300)
        self._popup.open()

    def changePage(self, new_page):
        self.reschedule()
        if path.isfile("storage_data/"+str(self.user_data['rfid'])+"/scheda_"+str(new_page)+".jpg"):
            self.page=new_page
            self.labelPage.text=str(self.page+1)+"/"+str(self.num_pages)
            self.setSourcePath("storage_data/"+str(self.user_data['rfid'])+"/scheda_"+str(self.page)+".jpg")
            self.slider_value = 1

    def on_release_left_button(self, instance):
        self.changePage(new_page=self.page-1)

    def on_release_right_button(self, instance):
        self.changePage(new_page=self.page+1)

    def on_img_hint_update(self, instance, value):
        scroll_x = self.scrollview.scroll_x
        self.scrollview.scroll_x = scroll_x
        self.reschedule()

    def on_release_zoomOut_button(self, instance):
        if self.img_view.size_hint_x / 1.2 >= 1:
            if self.img_view:
                self.img_view.size_hint = (self.img_view.size_hint_x / 1.2, self.img_view.size_hint_y / 1.2)
                self.img_view.width = 0
        else:
            self.scrollview.scroll_x = 0.5

    def on_release_zoomIn_button(self, instance):
        if self.img_view.size_hint_x * 1.2 <= 3:
            if self.img_view:
                self.img_view.size_hint = (self.img_view.size_hint_x * 1.2, self.img_view.size_hint_y * 1.2)
                self.img_view.width = 0

    def on_src(self, instance, value):
        if self.img_view:
            self.img_view.source = value

    def on_label_text(self, instance, value):
        self.label.text = value

    def on_slider_value(self, isinstance, value):
        self.slider.value = value

    def update_bg(self, *args):
        self.bg.pos = self.pos
        self.bg.size = self.size

    def setSourcePath(self, path, *largs):
        self.src = path

    def saveUserData(self, rfid, data):
        if self.firebase:
            self.firebase.update("users/"+rfid, data)

    def setUserData(self, user_data, *largs):
        self.user_data = user_data
예제 #20
0
    def build(self):
        self.from_move = None
        self.to_move = None
        self.chessboard = ChessBoard()
        self.analysis_board = ChessBoard()
        self.squares = []
        self.use_engine = False
        self.last_touch_down_move = None
        self.last_touch_up_move = None

        parent = BoxLayout(size_hint=(1,1))
        grid = GridLayout(cols = 8, rows = 8, spacing = 0, size_hint=(1, 1))

        for i, name in enumerate(SQUARES):
            bt = Image(allow_stretch=True)
            bt.sq = i
            bt.name = name
            # bt.border = [0,0,0,0]
            if i in light_squares:
                bt.sq_color = "l"
                bt.background_down = "img/empty-l.png"

            #                bt.background_color=[1,1,1,1]
            else:
                bt.sq_color = "d"
                bt.background_down = "img/empty-d.png"

            #                bt.background_color=[0,0,0,0]
            #                print i
            # bt.bind(on_press=self.callback)
            bt.bind(on_touch_down=self.touch_down_move)
            bt.bind(on_touch_up=self.touch_up_move)
            # bt.bind(on_touch_up=self.touch_move)


            grid.add_widget(bt)
            self.squares.append(bt)


        b = BoxLayout(size_hint=(0.15,0.15))
        ## Spacers
#        b.add_widget(Button(spacing=1))
#        b.add_widget(Button(spacing=1))
#        b.add_widget(Button(spacing=1))

        # Move control buttons
#        back_bt = Button(markup=True)
#       # back_bt.background_normal="img/empty-l.png"
#        back_bt.text="[color=ff3333]Back[/color]"
#        back_bt.bind(on_press=self.back)
#        b.add_widget(back_bt)
#
        save_bt = Button(markup=True)
        #fwd_bt.background_normal="img/empty-d.png"
        save_bt.text="[color=3333ff]Save[/color]"
        # save_bt.text="Save"

        save_bt.bind(on_press=self.save)
        b.add_widget(save_bt)

#        b.add_widget(Button(spacing=10))
#        b.add_widget(Button(spacing=10))
#        b.add_widget(Button(spacing=10))

#        grid.add_widget(b)

#        board_box.add_widget(grid)
#        board_box.add_widget(b)

#        fen_input = TextInput(text="FEN", focus=True, multiline=False)
#        def on_fen_input(instance):
#            self.chessboard.setFEN(instance.text)
#            self.refresh_board()
##            print 'The widget', instance.text
#
#        fen_input.bind(on_text_validate=on_fen_input)
##        self._keyboard.bind(on_key_down=self._on_keyboard_down)
#
#
#        b.add_widget(fen_input)

        settings_bt = Button(markup=True, text='Setup')
        settings_bt.bind(on_press=self.go_to_settings)
        b.add_widget(settings_bt)


#        self.root.current='settings'


        parent.add_widget(grid)

        info_grid = GridLayout(cols = 1, rows = 4, spacing = 1, size_hint=(0.3, 1), orientation='vertical')
        info_grid.add_widget(b)


        self.game_score = ScrollableLabel('New Game', ref_callback=self.go_to_move)

        info_grid.add_widget(self.game_score)

        self.engine_score = ScrollableLabel('[ref=engine_toggle]Analysis[/ref]', ref_callback=self.add_eng_moves)
        info_grid.add_widget(self.engine_score)

        info_grid.add_widget(Button(text="Text"))

        parent.add_widget(info_grid)
        self.refresh_board()

        platform = kivy.utils.platform()
        self.uci_engine = None
        if self.is_desktop():
            self._keyboard = Window.request_keyboard(
                self._keyboard_closed, self)
            self._keyboard.bind(on_key_down=self._on_keyboard_down)

            self.start_engine_thread()
        sm = ScreenManager(transition=SlideTransition())
        board_screen = Screen(name='main')
        board_screen.add_widget(parent)
        sm.add_widget(board_screen)

        settings_screen = SettingsScreen(name='settings')
        settings_screen.add_widget(self.generate_settings())

        sm.add_widget(settings_screen)

        return sm
예제 #21
0
class Missile:
    """
    Class for the missile game object. It handles its movement, collisions and effects.
    """
    def __init__(self):
        self.sound = SoundLoader.load('assets/explosion.wav')
        self.gravity = (0, -0.1)
        self.drag = 0.9
        self.color = Color(0, 1, 0, 0)  # set it to be invisible for now
        self.speed = (0, 0)
        self.radius = 10
        self.size = (self.radius * 2, self.radius * 2)
        self.body = Ellipse(pos=(Window.width / 5, Window.height - 600),
                            size=self.size)
        self.instruction = InstructionGroup()
        self.instruction.add(self.color)
        self.instruction.add(self.body)
        self.active = False
        self.animation = Image(source='assets/explosion.gif',
                               anim_delay=-1,
                               anim_loop=1,
                               allow_stretch=True,
                               keep_ratio=False)
        self.trajectory = Line(points=[], width=1)
        self.instruction.add(Color(1, 1, 1, .3))
        self.instruction.add(self.trajectory)
        self.animation_color = Color(1, 1, 1, 0)
        self.instruction.add(self.animation_color)
        self.animation.bind(texture=self.update_texture)
        self.animation_rectangle = Rectangle(texture=self.animation.texture,
                                             pos=self.body.pos,
                                             size=(150, 150))
        self.instruction.add(self.animation_rectangle)
        game.bind(on_step=lambda x, y: self.on_step(x, y))

    def update_texture(self, instance, value):
        self.animation_rectangle.texture = value

    def activate(self):
        self.trajectory.points.clear()
        self.active = True
        self.color.a = 1

    def deactivate(self):
        self.active = False
        self.color.a = 0

    def on_step(self, sender, diff):
        if not self.active:
            return
        self.trajectory.points = self.trajectory.points + [
            self.body.pos[0] + self.radius, self.body.pos[1] + self.radius
        ]
        pos = tuple(map(lambda x, y: (x + y), self.body.pos, self.speed))
        self.body.pos = pos
        # apply gravity on speed
        self.speed = tuple(map(lambda x, y: (x + y), self.gravity, self.speed))
        # apply drag
        self.speed = tuple(map(lambda x: x * 0.999, self.speed))

        if self.collides:
            self.deactivate()
            game.next_player()
            self.detonate()

    def detonate(self):
        self.sound.play()
        # self.animation_color.a = 1
        # self.animation._coreimage.anim_reset(True)
        # self.animation.anim_delay = 0.08
        # self.animation_rectangle.pos = tuple(map(lambda x: x - 75, self.body.pos))

    @property
    def collides(self) -> bool:
        # check collision with walls
        pos = self.body.pos
        if pos[0] < 0 or pos[0] + self.size[0] > Window.width:
            self.speed = (self.speed[0] * -1, self.speed[1])
            return False
        elif pos[1] + self.size[1] > Window.height:
            self.speed = (self.speed[0], self.speed[1] * -1)
            return False

        # check collision with terrain
        tm = game.terrain_map
        missile_centre = np.array((pos[0] + self.radius, pos[1] + self.radius))
        for x in range(int(pos[0]), int(pos[0]) + self.radius, 2):
            if np.linalg.norm(np.array((x, tm.get(x, 0))) -
                              missile_centre) < self.radius:
                return True

        # check collision with players
        missile_start = (pos[0], pos[1] + self.radius * 2)
        missile_end = (pos[0] + self.radius * 2, pos[1])
        for p in game.players:
            p_pos = p.body.pos
            p_start = (p_pos[0], p_pos[1] + p.size[1])
            p_end = (p_pos[0] + p.size[0], p_pos[1])
            if self.rectangles_collide(missile_start, missile_end, p_start,
                                       p_end):
                p.missile_hit()
                return True
        return False

    @staticmethod
    def rectangles_collide(a1, a2, b1, b2) -> bool:
        # if one rectangle is on left side of other
        if a1[0] > b2[0] or b1[0] > a2[0]:
            return False
        # if one rectangle is above other
        if a1[1] < b2[1] or b1[1] < a2[1]:
            return False
        return True
예제 #22
0
class PickerScreen(Screen):
    def on_pre_enter(self):

        self.layout = search(self, 'layout')
        self.background = search(self, 'background')
        self.scrollview = search(self, 'scrollview')

        self.focus = None

        # set the background to the correct position
        self.on_picker_scroll(None, None)

        self.scrollview.bind(scroll_x=self.on_picker_scroll)
        self.scrollview.bind(pos=self.on_picker_move)

        images = get_images()
        width = math.ceil((len(images) / 2.0 * 312) / 1280.0)
        self.max_width = width * 1280

        # set the width to be much great than the screen
        # somewhat proportionally to the number of images
        rellayout = search(self, 'rellayout')
        rellayout.size_hint = (width, 1)

        grid = search(self, 'grid')

        Loader.loading_image = CoreImage('images/loading.gif')
        Loader.num_workers = 4
        Loader.max_upload_per_frame = 4

        for image in get_images():
            widget = Factory.AsyncImage(source=image, allow_stretch=True)
            widget.bind(on_touch_down=self.on_image_touch)
            grid.add_widget(widget)

        self.scrollview_hidden = False
        self._scrollview_pos_hint = self.scrollview.pos_hint
        self._scrollview_pos = self.scrollview.pos

        self._sv_hide_ani = None
        self._sv_show_ani = None

        self._focus_hide_ani = None
        self._focus_show_ani = None

        self._focus_widget = Image(source='images/loading.gif')
        self._focus_widget.allow_stretch = True
        self._focus_widget.pos_hint = {'center_x': .5}
        self._focus_widget.y = 1024
        self._focus_widget.size_hint = None, None
        self._focus_widget.size = (600, 600)
        self._focus_widget.bind(on_touch_down=self.on_image_touch)
        self.layout.add_widget(self._focus_widget)

    def on_image_touch(self, widget, mouse_point):
        if widget.collide_point(mouse_point.x, mouse_point.y):

            # show the focus widget
            if self.scrollview_hidden:
                self.scrollview_hidden = False

                # cancel scrollview hiding animation
                try:
                    self._sv_hide_ani.cancel(self.scrollview)
                except AttributeError:
                    pass

                # show the scrollview
                x, y = self._scrollview_pos
                self._sv_show_ani = Animation(x=x,
                                              y=y,
                                              t='in_out_quad',
                                              duration=.5)
                self._sv_show_ani.start(self.scrollview)

                # cancel the focus widget show animation
                try:
                    self._focus_show_ani.cancel(self._focus_widget)
                except AttributeError:
                    pass

                # hide the focus widget
                self._focus_hide_ani = Animation(y=1024,
                                                 size=(600, 600),
                                                 t='in_out_quad',
                                                 duration=.5)

                self._focus_hide_ani.start(self._focus_widget)

            # hide the focus widget
            elif self._focus_widget is not widget:
                self.scrollview_hidden = True

                # cancel the scrollview show animation
                try:
                    self._sv_show_ani.cancel(self.scrollview)
                except AttributeError:
                    pass

                # hide the scrollview
                self.sv_hide_ani = Animation(x=0,
                                             y=-450,
                                             t='in_out_quad',
                                             duration=.5)
                self.sv_hide_ani.start(self.scrollview)

                # make sure the focus animation is finished
                try:
                    self._focus_hide_ani.cancel(self._focus_widget)
                except AttributeError:
                    pass

                # set the focus widget to have the same image as the one picked
                # do a bit of mangling to get a more detailed image
                filename = os.path.join(detail,
                                        os.path.basename(widget.source))
                self._focus_widget.source = filename

                # show the focus widget
                self._focus_show_ani = Animation(y=200,
                                                 size=(800, 800),
                                                 t='in_out_quad',
                                                 duration=.5)

                self._focus_show_ani.start(self._focus_widget)

    def on_picker_move(self, widget, arg):
        if widget is self.scrollview:
            x, y = self.background.pos
            self.background.pos = (x, -arg[1] / 50)

    def on_picker_scroll(self, value1, value2):
        self.background.pos = (self.scrollview.scroll_x * -600 - 100,
                               self.background.pos[1])
        return False
예제 #23
0
 def howitworksbutton(self, *latgs):
     page = Widget()
     self.clear_widgets()
     self.add_widget(page)
     button1 = Button(text='Home',
                      background_normal='bottone3.png',
                      size_hint=(0.11, 0.10),
                      pos_hint={
                          'center_x': .1,
                          'center_y': .1
                      })
     button1.bind(on_press=self.start)
     self.add_widget(button1)
     label1 = Label(
         text=
         '1) Assemble the smartphone adaptor \n\n2) Add sample to T1-T2 wells \n\n3) Incubate 30 min \n\n4) Add BL substrate \n\n5) Insert cartridge into the adaptor \n\n6) Acquire BL image & Read result',
         color=(1, 1, 1, .9),
         font_size='15sp',
         pos_hint={
             'center_x': .24,
             'center_y': .56
         })
     self.add_widget(label1)
     button2 = Image(source='./app1-2.png',
                     size_hint=(0.15, 0.21),
                     pos_hint={
                         'center_x': .7,
                         'center_y': .75
                     })
     self.add_widget(button2)
     button3 = Image(source='./app2-1.png',
                     size_hint=(0.20, 0.26),
                     pos_hint={
                         'center_x': .85,
                         'center_y': .77
                     })
     self.add_widget(button3)
     button4 = Image(source='./app3-2.png',
                     size_hint=(0.15, 0.21),
                     pos_hint={
                         'center_x': .7,
                         'center_y': .52
                     })
     self.add_widget(button4)
     button5 = Image(source='./app4-2.png',
                     size_hint=(0.20, 0.26),
                     pos_hint={
                         'center_x': .85,
                         'center_y': .50
                     })
     self.add_widget(button5)
     button6 = Image(source='./app8-2.png',
                     size_hint=(0.25, 0.31),
                     pos_hint={
                         'center_x': .78,
                         'center_y': .2
                     })
     self.add_widget(button6)
     button4 = Button(text='Begin',
                      background_normal='bottone3.png',
                      size_hint=(0.21, 0.11),
                      bold=True,
                      font_size='20sp',
                      pos_hint={
                          'center_x': .5,
                          'center_y': .1
                      })
     button4.bind(on_press=self.analysis)
     self.add_widget(button4)
     label = Button(text='Procedure',
                    background_normal='bottone3.png',
                    size_hint=(0.31, 0.12),
                    bold=True,
                    font_size='20sp',
                    color=(1, 1, 1, .9),
                    valign='top',
                    pos_hint={
                        'center_x': .5,
                        'center_y': .92
                    })
     pict = Image(source='./logo.png',
                  size_hint=(1, .16),
                  pos_hint={
                      'center_x': .68,
                      'center_y': .92
                  })
     self.add_widget(label)
     self.add_widget(pict)
예제 #24
0
class KivySprite:
    def __init__(self, parent_widget):
        self._parent_widget = parent_widget
        self._scatter_widget = Scatter(#self._tapped,  # callbacks on all areas
                                               do_rotation=False,
                                               do_scale=False,
                                               do_translation=True)
        self._image_widget = Image(source='a.png')
        self._scatter_widget.add_widget(self._image_widget)
        self._parent_widget.add_widget(self._scatter_widget)

        with self._scatter_widget.canvas.before:
            Color(1,0,0)
            Rectangle(pos=self._scatter_widget.pos, size=self._scatter_widget.size)

        self.layer = None
        self.visible = True
        self.rotation_style = 'all around'

        self._scatter_widget.bind(pos=lambda w, p: self._moved())
        self._image_widget.bind(on_touch_down=lambda w, t: self._tapped())

    # to be overriden by Sprite
    def _tapped(self): pass
    def _moved(self): pass
    def _rotated(self): pass
    def _sized(self): pass

    @property
    def image(self):
        return self._image_widget.source

    @image.setter
    def image(self, value):
        self._image_widget.source = value

    @property
    def position(self):
        return self._scatter_widget.pos

    @position.setter
    def position(self, value):
        self._scatter_widget.pos = value

    @property
    def x(self):
        return self.position[0]

    @x.setter
    def x(self, value):
        self._scatter_widget.pos = value - (self._image_widget.size[0]/2), self.y

    @property
    def y(self):
        return self.position[1]

    @y.setter
    def y(self, value):
        self._scatter_widget.pos = self.x, value - (self._image_widget.size[1]/2)

    @property
    def size(self):
        return self._scatter_widget.scale * 100

    @size.setter
    def size(self, value):
        self._scatter_widget.scale = value * 0.01

    @property
    def direction(self):
        return (((self._scatter_widget.rotation + 90) + 179) % 360) - 179

    @direction.setter
    def direction(self, value):
        self._scatter_widget.rotation = value - 90

    @property
    def draggable(self):
        return self._scatter_widget.do_translation

    @draggable.setter
    def draggable(self, value):
        self._scatter_widget.do_translation = value

    def glide(self, x, y, time=None):  # either x, y, time or sprite, time
        if time is None:
            time = y
            y = x.y
            x = x.x
        anim = Animation(x=x, y=y, duration=time)
        anim.start(self._scatter_widget)

    def move(self, steps):
        self.x += steps * math.sin(math.radians(self.direction))
        self.y += steps * math.cos(math.radians(self.direction))
        self._moved()

    def point_towards(self, x, y=None):  # test
        if y is None:  # x is a sprite
            y = x.y
            x = x.x
        dy = y - self.y
        dx = x - self.x
        angle = (-90 if dx < 0 else 90) if dy == 0 else math.degrees(math.atan(dx / dy))
        if dy < 0:
            angle += 180
        self.direction = angle

    def touching(self, other_sprite):
        return self._image_widget.collide_widget(other_sprite._image_widget)
예제 #25
0
class SpecialImage(AnchorLayout, ButtonBehavior, MouseOver):
    background_color = ListProperty([1, 1, 1, 1]) # so I can set this if I want to when instantiating SpecialImage
    file_path = StringProperty("No path")
    file_name = StringProperty("No name")

    def __init__(self, direntry, **kwargs):
        super().__init__(**kwargs)
        self.anchor_x = "center"
        self.anchor_y = "center"

        if direntry != None: # should change to isinstance(direntry)
            self.file_path = direntry.path
            self.file_name = direntry.name
            
        self.file_description = "Extra wide Laminate plank"
        self.hover = False
        self.selected = False
        self.size_hint_x = None
        self.width = 82
        self.size_hint_y = None
        self.a_texture = get_texture()

        self.text_color = almost_black

        self.boxlayout = BoxLayout(orientation = "vertical", size_hint = (None, 1))
        self.add_widget(self.boxlayout)
        self.bind(size = self.update_boxlayout)

        ### inside boxlayout start ###
        self.space_0 = Widget(size_hint = (1, None), height = '0dp')
        self.boxlayout.add_widget(self.space_0)

        self.a_image = Image(size_hint = (1, None), source = self.file_path, allow_stretch = True) # do I need a function here that sets height
        self.boxlayout.add_widget(self.a_image)
        self.hover_widget = Widget()
        self.a_image.add_widget(self.hover_widget)
        self.a_image.bind(size = self.update_image_height)

        self.space_1 = Widget(size_hint = (1, None), height = '2dp')
        self.boxlayout.add_widget(self.space_1)
        
        self.title = Label(size_hint = (1, None), height = '27dp', text = self.file_name, halign = "center", valign = "top", color = self.text_color, font_size = '14dp', bold = True) # this could be one pixel lower (i.e. adjust height of this and above). Waiting to see what their text font is like i.e. the d's and l's stick out by one, but (all?) capitals are fine
        self.boxlayout.add_widget(self.title)

        self.space_2 = Widget(size_hint = (1, None), height = '1dp')
        self.boxlayout.add_widget(self.space_2)

        self.description = Label(size_hint = (1, None), height = 0, text = self.file_description, halign = "left", valign = "top", color = self.text_color, font_size = '13dp') # keeping this one pixels, otherwise it doesn't work 
        #self.boxlayout.add_widget(self.description)  

        # IMPORTANT. TO ADD DESCRIPTION BACK, UNCOMMENT THE ABOVE LINE, AND SET HEIGHT OF SELF.DESRCRIPTION TO SOMETHING (I THINK IT WAS 40PIXELS BEFORE)


        #self.space_3 = Widget(size_hint = (1, 1)) # takes up remaining space
        #self.boxlayout.add_widget(self.space_3)

        self.bind(size = self.update_text_textboxes)
        ### inside boxlayout end ##
        
        self.bind(size = self.update_height)

        self.draw_main(self, (1, 1, 1, 1)) # I need to kno how to access background color property and put it here
        self.draw_hover()
        self.bind(pos = self.update_rectangles, size = self.update_rectangles, height = self.update_rectangles)
        
        self.bind(background_color = self.draw_main)

        ### animations start ###
        self.animation_on_hover_image = Animation(opacity = 1, duration = 0.1, transition = "in_out_expo")
        self.animation_on_hover_text = Animation(color = rich_blue, duration = 0.1, transition = "in_out_expo")
        self.animation_on_hover_background = Animation(background_color = (1, 1, 1, 1), duration = 0.1, transition = "in_out_expo")

        self.animation_on_exit_image = Animation(opacity = 0, duration = 0.1, transition = "in_out_expo")
        self.animation_on_exit_text = Animation(color = self.text_color, duration = 0.1, transition = "in_out_expo")
        self.animation_on_exit_background = Animation(background_color = self.background_color, duration = 0.1, transition = "in_out_expo")

        self.animation_selected_image = Animation(background_color = rich_blue, duration = 0.1, transition = "in_out_expo")
        self.animation_deselected_image = Animation(background_color = self.background_color, duration = 0.1, transition = "in_out_expo") # I need to know how to access background color property and put it here
        
        self.animation_test_1 = Animation(color = (1, 1, 1, 1), duration = 0.1, transition = "in_out_expo")
        self.animation_test_2 = Animation(color = (1, 1, 1, 1), duration = 0.1, transition = "in_out_expo")
        self.animation_test_3 = Animation(color = almost_black, duration = 0.1, transition = "in_out_expo")
        ### animations end ###


    def draw_main(self, self_again, background_color): # no idea how to get around this self_again nonsense
        #Logger.critical("triggered")
        self.canvas.before.clear()
        with self.canvas.before:
            Color(*background_color)
            self.rectangle = Rectangle(pos = self.pos, size  = self.size)

    def draw_hover(self):
        with self.hover_widget.canvas.after:
            self.hover_widget.canvas.opacity = 0
            self.hover_rectangle = Rectangle(texture=self.a_texture) # (not setting size and pos, because I can leave that to update_rectangles, which won't have the correct answer til the first hover anyway)

    def update_rectangles(self, *args): # I could merge all these "update" things
        self.rectangle.pos = self.pos
        self.rectangle.size = self.size
        
        self.hover_rectangle.pos = self.a_image.pos
        self.hover_rectangle.size = self.a_image.size
        

    def update_text_textboxes(self, *args):
        self.title.text_size = [self.boxlayout.width, self.title.height] # If this doesn't work, do self.title.parent.width
        self.description.text_size = [self.boxlayout.width, self.description.height]

    def update_image_height(self, *args):
        self.a_image.height = (self.a_image.width / self.a_image.texture_size[0]) * self.a_image.texture_size[1] # whatever the aspect ratio needs to be, alternatively, I could do a image manager thing

    def update_height(self, *args):
        self.height = self.space_0.height + ((self.boxlayout.width / self.a_image.texture_size[0]) * self.a_image.texture_size[1]) + self.space_1.height + self.title.height + self.space_2.height + self.description.height+ 5 # I need to replace self.boxlayout.width with the image height, if we can know it...

    def update_boxlayout(self, *args):
        self.boxlayout.width = 64

    def on_hover(self):
        #Window.set_system_cursor("hand") #this may need to be handled in filebrowser since on_exit and on_hover will always be simultaneously called. EDIT 21-02-2020, this could be done so that filebrowser sets to arrow IF NOT in specialimage
        if self.selected == False:
            self.hover = True
            #self.parent.parent.parent.hover_count += 1  not fool proof
            self.update_rectangles()
            self.animation_on_hover_image.start(self.hover_widget.canvas)
            self.animation_on_hover_text.start(self.title)
            self.animation_on_hover_background.start(self)  


    def on_exit(self):
        self.hover = False
        #self.parent.parent.parent.hover_count -= 1 not foo lproof
        #Window.set_system_cursor("arrow")
        if self.selected == False:
            self.animation_on_exit_image.start(self.hover_widget.canvas)
            self.animation_on_exit_text.start(self.title)
            self.animation_on_exit_background.start(self)  

    def on_press(self): # must have file browser as parent to work, I could always make a clause if I wanted to make specialimage work fine outside of filebrowser
        self.parent.parent.parent.set_selected(self) # let this decide if set_selected should be called
        #self.set_selected()

    def set_selected(self):
        self.selected = True
        self.animation_selected_image.start(self)
        self.animation_test_1.start(self.title)
        self.animation_test_2.start(self.description) 
        self.animation_on_exit_image.start(self.hover_widget.canvas) ### NEW 
        Window.set_system_cursor("arrow") # a quick thing

    def set_deselected(self):
        """
        foolproof is that on_exit can include self.animation_test_3, and this just play on_exit(). and call the onexit animations "text_default" "description_default", "description hover", "description pressed" etc.
        """
        self.selected = False
        self.animation_on_exit_image.start(self.hover_widget.canvas)
        self.animation_on_exit_text.start(self.title)
        self.animation_on_exit_background.start(self) # deselected (background) animation is now redundant?
        self.animation_test_3.start(self.description)
예제 #26
0
    def updatePrompt(self, hint, input_data, correct_answer, type, promptType, tl, **kwargs):
        global box1
        global box3
        global box3data
        global promptE
        global ib
        global timerbar
        global timerholder
        global timerO

        ib.clear_widgets(children=None)

        # if input_data is of mc format
        # newSource = args[0]
        # potentialAnswers = args[1]
        # correctAnswer = args[2]
        box1.remove_widget(promptE)
        timerholder.remove_widget(timerbar)
        box3 = []
        box3data = []
        timerbar = None
        for pa in input_data:
            box3.append(Button(text=str(pa),
                               size_hint_x=0.5,
                               size_hint_y=0.5,
                               font_size=20))
            box3data.append(pa)
        for i in range(0, len(input_data)):
            if box3data[i]==correct_answer:
                box3[i].bind(on_release=InGame.takeCorrect)
            else:
                box3[i].bind(on_release=InGame.takeWrong)
            ib.add_widget(box3[i])

        # if the hint provided is an image
        if type == "mc":
            if promptType == "texture":
                promptE = Image(source=hint, size_hint_x=0.5)
            else:
                promptE = Button(text="(sound)", size_hint_x=0.3, font_size=64, color=[1,1,1, 1])
                promptE.bind(on_release=InGame.playCurrentPrompt)
                InGame.playCurrentPrompt()
        else:
            promptE = Button(text=hint,
                             size_hint_x=0.5,
                             size_hint_y=0.5,
                             font_size=64,
                             color=[1,1,1, 1],
                             pos_hint={'center_y': 0.5},
                             disabled=True,
                             opacity=1.0)
        box1.add_widget(promptE)
        timerbar = ProgressBar(max=100,
                               value=100,
                               size_hint_y=1.0,
                               size_hint_x=1.0
                               )
        timerholder.add_widget(timerbar)
        timerO = Animation(value=0, duration=tl)
        timerO.start(timerbar)
        timerO.bind(on_complete=InGame.takeTime)
예제 #27
0
파일: kiosk.py 프로젝트: ikol/PURIKURA
class PickerScreen(Screen):
    def on_pre_enter(self):

        self.layout = search(self, 'layout')
        self.background = search(self, 'background')
        self.scrollview = search(self, 'scrollview')

        self.focus = None

        # set the background to the correct position
        self.on_picker_scroll(None, None)

        self.scrollview.bind(scroll_x=self.on_picker_scroll)
        self.scrollview.bind(pos=self.on_picker_move)

        images = get_images()
        width = math.ceil((len(images) / 2.0 * 312) / 1280.0) 
        self.max_width = width * 1280

        # set the width to be much great than the screen
        # somewhat proportionally to the number of images
        rellayout = search(self, 'rellayout')
        rellayout.size_hint = (width,1)

        grid = search(self, 'grid')

        Loader.loading_image = CoreImage('images/loading.gif')
        Loader.num_workers = 4
        Loader.max_upload_per_frame = 4

        for image in get_images():
            widget = Factory.AsyncImage(source=image, allow_stretch=True)
            widget.bind(on_touch_down=self.on_image_touch)
            grid.add_widget(widget)

        self.scrollview_hidden = False
        self._scrollview_pos_hint = self.scrollview.pos_hint
        self._scrollview_pos = self.scrollview.pos

        self._sv_hide_ani = None
        self._sv_show_ani = None

        self._focus_hide_ani = None
        self._focus_show_ani = None

        self._focus_widget = Image(source='images/loading.gif')
        self._focus_widget.allow_stretch = True
        self._focus_widget.pos_hint = {'center_x': .5}
        self._focus_widget.y = 1024
        self._focus_widget.size_hint = None, None
        self._focus_widget.size = (600, 600)
        self._focus_widget.bind(on_touch_down=self.on_image_touch)
        self.layout.add_widget(self._focus_widget)


    def on_image_touch(self, widget, mouse_point):
        if widget.collide_point(mouse_point.x, mouse_point.y):
        
            # show the focus widget
            if self.scrollview_hidden:
                self.scrollview_hidden = False
               
                # cancel scrollview hiding animation
                try:
                    self._sv_hide_ani.cancel(self.scrollview)
                except AttributeError:
                    pass

                # show the scrollview
                x, y = self._scrollview_pos
                self._sv_show_ani = Animation(x=x, y=y, t='in_out_quad', duration=.5)
                self._sv_show_ani.start(self.scrollview)

                # cancel the focus widget show animation
                try:
                    self._focus_show_ani.cancel(self._focus_widget)
                except AttributeError:
                    pass

                # hide the focus widget
                self._focus_hide_ani = Animation(y=1024,
                                                 size=(600,600),
                                                 t='in_out_quad',
                                                 duration=.5)

                self._focus_hide_ani.start(self._focus_widget)

            # hide the focus widget
            elif self._focus_widget is not widget:
                self.scrollview_hidden = True
              
                # cancel the scrollview show animation
                try:
                    self._sv_show_ani.cancel(self.scrollview)
                except AttributeError:
                    pass

                # hide the scrollview
                self.sv_hide_ani = Animation(x=0, y=-450, t='in_out_quad', duration=.5)
                self.sv_hide_ani.start(self.scrollview)

                # make sure the focus animation is finished
                try:
                    self._focus_hide_ani.cancel(self._focus_widget)
                except AttributeError:
                    pass

                # set the focus widget to have the same image as the one picked
                # do a bit of mangling to get a more detailed image
                filename = os.path.join(detail, os.path.basename(widget.source))
                self._focus_widget.source = filename

                # show the focus widget
                self._focus_show_ani = Animation(y=200,
                                                 size=(800, 800),
                                                 t='in_out_quad',
                                                 duration=.5)

                self._focus_show_ani.start(self._focus_widget)

    def on_picker_move(self, widget, arg):
        if widget is self.scrollview:
            x, y = self.background.pos
            self.background.pos = (x, -arg[1] / 50)

    def on_picker_scroll(self, value1, value2):
        self.background.pos = (self.scrollview.scroll_x*-600 - 100,
                               self.background.pos[1])
        return False
예제 #28
0
파일: picker.py 프로젝트: bitcraft/PURIKURA
class PickerScreen(Screen):
    """ A nice looking touch-enabled file browser
    """
    large_preview_size = ListProperty()
    small_preview_size = ListProperty()
    grid_rows = NumericProperty()
    images = ListProperty()

    def __init__(self, *args, **kwargs):
        super(PickerScreen, self).__init__(*args, **kwargs)

        # these declarations are mainly to keep pycharm from annoying me with
        # notifications that these attributes are not declared in __init__
        self.arduino_handler = None
        self.preview_handler = None
        self.preview_widget = None
        self.preview_label = None
        self.preview_exit = None
        self.preview_button = None
        self.focus_widget = None
        self.background = None
        self.scrollview = None
        self.layout = None
        self.grid = None
        self.locked = None
        self.loaded = None
        self.controls = None
        self.state = 'normal'
        self.tilt = 90

    def on_pre_enter(self):
        # set up the 'normal' state
        screen_width = Config.getint('graphics', 'width')

        # these are pulled from the .kv format file
        self.slider = search(self, 'slider')
        self.layout = search(self, 'layout')
        self.background = search(self, 'background')
        self.scrollview = search(self, 'scrollview')
        self.grid = search(self, 'grid')

        self.background.source = image_path('galaxy.jpg')

        # the grid will expand horizontally as items are added
        self.grid.bind(minimum_width=self.grid.setter('width'))

        # TODO: eventually make this related to the screen width, maybe
        self.grid.spacing = (64, 64)

        # slider / scrollview binding
        def f(widget, value):
            self.scrollview.effect_x.value = value
            self.scrollview.update_from_scroll()
        self.slider.bind(value_normalized=f)

        # tweak the loading so it is quick
        Loader.loading_image = CoreImage(image_path('loading.gif'))
        Loader.num_workers = pkConfig.getint('kiosk', 'loaders')
        Loader.max_upload_per_frame = pkConfig.getint('kiosk',
                                                      'max-upload-per-frame')

        self.scrollview_hidden = False
        self._scrollview_pos_hint = self.scrollview.pos_hint
        self._scrollview_pos = self.scrollview.pos

        # the center of the preview image
        center_x = screen_width - (self.large_preview_size[0] / 2) - 16

        # stuff for the arduino/tilt
        self.arduino_handler = ArduinoHandler()

        # queueing them and updaing the widget's texture
        self.preview_handler = PreviewHandler()
        self.preview_handler.start()

        # F O C U S   W I D G E T
        # the focus widget is the large preview image
        self.focus_widget = Factory.FocusWidget(
            source=image_path('loading.gif'))
        self.focus_widget.allow_stretch = True
        self.focus_widget.x = center_x - OFFSET
        self.focus_widget.y = -1000
        self.focus_widget.size_hint = None, None
        self.focus_widget.size = self.small_preview_size
        #self.focus_widget.bind(on_touch_down=self.on_image_touch)
        self.layout.add_widget(self.focus_widget)

        #   E X I T   B U T T O N
        # this button is used to exit the large camera preview window
        def exit_preview(widget, touch):
            if widget.collide_point(touch.x, touch.y):
                self.change_state('normal')

        self.preview_exit = Factory.ExitButton(
            source=image_path('chevron-right.gif'))
        #self.preview_exit.bind(on_touch_down=exit_preview)
        self.preview_exit.size_hint = None, None
        self.preview_exit.width = 64
        self.preview_exit.height = 175
        self.preview_exit.x = 1280
        self.preview_exit.y = (1024 / 2) - (self.preview_exit.height / 2)
        self.layout.add_widget(self.preview_exit)

        #   P R E V I E W   L A B E L
        # the preview label is used with the focus widget is open
        self.preview_label = Factory.PreviewLabel(pos=(-1000, -1000))
        self.layout.add_widget(self.preview_label)

        # the scrollview is amimated to move in and out
        self.scrollview.original_y = 100
        self.scrollview.y = self.scrollview.original_y
        self.scrollview.effect_cls = MyScrollEffect
        self.scrollview.bind(scroll_x=self.on_picker_scroll)

        # the background has a parallax effect, so position is manual now
        self.background.y = -400
        self.background.pos = self._calc_bg_pos()

        # locked and loaded  :D
        self.locked = False
        self.loaded = set()

        # schedule a callback to check for new images
        Clock.schedule_interval(self.scan, 1)

    def scan(self, dt):
        """ Scan for new images and scroll to edge if found
        """
        new = False
        for filename in self.get_images():
            if filename not in self.loaded:
                new = True
                self.loaded.add(filename)
                widget = self._create_preview_widget(filename)
                self.grid.add_widget(widget)

        # move and animate the scrollview to the far edge
        if new:
            ani = Animation(
                scroll_x=.99,
                t='in_out_quad',
                duration=1)

            ani.start(self.scrollview)

    def _create_preview_widget(self, source):
        # preview widget is a image on the picker screen
        widget = Factory.AsyncImage(
            source=source,
            allow_stretch=True,
            pos_hint={'top': 1})
        # widget.bind(on_touch_down=self.on_image_touch)
        return widget

    def _remove_widget_after_ani(self, ani, widget):
        self.remove_widget(widget)

    def show_controls(self, widget, arg):
        widget.pos_hint = {'x', 0}
        return False

    def unlock(self, dt=None):
        self.locked = False

    def change_state(self, state, **kwargs):
        if self.locked:
            return

        # replace with a state machine in the future?  ...yes.
        if state == 'preview' and self.preview_widget is None:
            self.update_preview()
            return

        screen_width = Config.getint('graphics', 'width')
        screen_height = Config.getint('graphics', 'height')

        new_state = state
        old_state = self.state
        self.state = new_state
        transition = (old_state, self.state)

        logger.debug('transitioning state %s', transition)

        # ====================================================================
        #  F O C U S  =>  N O R M A L
        if transition == ('focus', 'normal'):
            self.scrollview_hidden = False

            # cancel all running animations
            Animation.cancel_all(self.controls)
            Animation.cancel_all(self.scrollview)
            Animation.cancel_all(self.background)
            Animation.cancel_all(self.focus_widget)

            # close the keyboard
            from kivy.core.window import Window

            Window.release_all_keyboards()

            # disable the controls (workaround until 1.8.0)
            self.controls.disable()

            # hide the controls
            ani = Animation(
                opacity=0.0,
                duration=.3)
            ani.bind(on_complete=self._remove_widget_after_ani)
            ani.start(self.preview_label)
            if self.controls:
                ani.start(self.controls)

            # set the background to normal
            x, y = self._calc_bg_pos()
            ani = Animation(
                y=y + 100,
                x=x,
                t='in_out_quad',
                duration=.5)
            ani.start(self.background)

            # show the scrollview
            x, y = self._scrollview_pos[0], self.scrollview.original_y
            ani = Animation(
                x=x,
                y=y,
                t='in_out_quad',
                opacity=1.0,
                duration=.5)
            ani.start(self.scrollview)

            # show the camera button
            ani = Animation(
                y=0,
                t='in_out_quad',
                opacity=1.0,
                duration=.5)
            ani.start(self.preview_button)

            # hide the focus widget
            ani = Animation(
                y=-1000,
                x=self.focus_widget.x + OFFSET,
                size=self.small_preview_size,
                t='in_out_quad',
                duration=.5)

            ani &= Animation(
                opacity=0.0,
                duration=.5)

            ani.start(self.focus_widget)

            # schedule a unlock
            self.locked = True
            Clock.schedule_once(self.unlock, .5)

        #=====================================================================
        #  N O R M A L  =>  F O C U S
        elif transition == ('normal', 'focus'):
            widget = kwargs['widget']
            self.scrollview_hidden = True

            # cancel all running animations
            Animation.cancel_all(self.scrollview)
            Animation.cancel_all(self.background)
            Animation.cancel_all(self.focus_widget)
            Animation.cancel_all(self.preview_button)

            # set the focus widget to have the same image as the one picked
            # do a bit of mangling to get a more detailed image
            thumb, detail, original, comp = self.get_paths()
            filename = jpath(detail, os.path.basename(widget.source))
            original = jpath(original, os.path.basename(widget.source))

            # get a medium resolution image for the preview
            self.focus_widget.source = filename

            # show the controls
            self.controls = SharingControls()
            self.controls.filename = original
            self.controls.size_hint = .40, 1
            self.controls.opacity = 0

            ani = Animation(
                opacity=1.0,
                duration=.3)
            ani.start(self.preview_label)
            ani.start(self.controls)

            self.preview_label.pos_hint = {'x': .25, 'y': .47}

            # set the z to something high to ensure it is on top
            self.add_widget(self.controls)

            # hide the scrollview and camera button
            ani = Animation(
                x=0,
                y=-1000,
                t='in_out_quad',
                opacity=0.0,
                duration=.7)
            ani.start(self.scrollview)
            ani.start(self.preview_button)

            # start a simple animation on the background
            ani = Animation(
                y=self.background.y - 100,
                x=-self.background.width / 2.5,
                t='in_out_quad',
                duration=.5)
            ani += Animation(
                x=0,
                duration=480)
            ani.start(self.background)

            hh = (screen_height - self.large_preview_size[1]) / 2

            # show the focus widget
            ani = Animation(
                opacity=1.0,
                y=screen_height - self.large_preview_size[1] - hh,
                x=(1280 / 2) - 250,
                size=self.large_preview_size,
                t='in_out_quad',
                duration=.5)
            ani &= Animation(
                opacity=1.0,
                duration=.5)
            ani.start(self.focus_widget)

            # schedule a unlock
            self.locked = True
            Clock.schedule_once(self.unlock, .5)

        #=====================================================================
        #  N O R M A L  =>  P R E V I E W
        elif transition == ('normal', 'preview'):
            self.scrollview_hidden = True

            # cancel all running animations
            Animation.cancel_all(self.scrollview)
            Animation.cancel_all(self.background)
            Animation.cancel_all(self.focus_widget)
            Animation.cancel_all(self.preview_exit)
            Animation.cancel_all(self.preview_button)
            Animation.cancel_all(self.preview_widget)

            # show the preview exit button
            ani = Animation(
                x=1280 - self.preview_exit.width,
                t='in_out_quad',
                duration=.5)
            ani &= Animation(
                opacity=1.0,
                duration=.5)
            ani.start(self.preview_exit)

            # show the camera preview
            ani = Animation(
                y=0,
                t='in_out_quad',
                duration=.5)
            ani &= Animation(
                opacity=1.0,
                duration=.5)
            ani.start(self.preview_widget)

            # hide the scrollview and camera button
            ani = Animation(
                x=0,
                y=-1000,
                t='in_out_quad',
                opacity=0.0,
                duration=.7)
            ani.start(self.scrollview)
            ani.start(self.preview_button)

            # schedule a unlock
            self.locked = True
            Clock.schedule_once(self.unlock, .5)

            # schedule an interval to update the preview widget
            interval = pkConfig.getfloat('camera', 'preview-interval')
            Clock.schedule_interval(self.update_preview, interval)

        #=====================================================================
        #  P R E V I E W  =>  N O R M A L
        elif transition == ('preview', 'normal'):
            self.scrollview_hidden = False

            # cancel all running animations
            Animation.cancel_all(self.scrollview)
            Animation.cancel_all(self.background)
            Animation.cancel_all(self.focus_widget)
            Animation.cancel_all(self.preview_exit)
            Animation.cancel_all(self.preview_widget)
            Animation.cancel_all(self.preview_button)

            # hide the preview exit button
            ani = Animation(
                x=1280,
                t='in_out_quad',
                duration=.5)
            ani &= Animation(
                opacity=0.0,
                duration=.5)
            ani.start(self.preview_exit)

            # hide the camera preview
            ani = Animation(
                y=-self.preview_widget.height,
                t='in_out_quad',
                duration=.5)
            ani &= Animation(
                opacity=0.0,
                duration=.5)
            ani.start(self.preview_widget)

            # set the background to normal
            x, y = self._calc_bg_pos()
            ani = Animation(
                y=y + 100,
                x=x,
                t='in_out_quad',
                duration=.5)
            ani.start(self.background)

            # show the scrollview
            x, y = self._scrollview_pos[0], self.scrollview.original_y
            ani = Animation(
                x=x,
                y=y,
                t='in_out_quad',
                opacity=1.0,
                duration=.5)
            ani.start(self.scrollview)

            # show the camera button
            ani = Animation(
                y=0,
                t='in_out_quad',
                opacity=1.0,
                duration=.5)
            ani.start(self.preview_button)

            # schedule a unlock
            self.locked = True
            Clock.schedule_once(self.unlock, .5)

            # unschedule the preview updater
            Clock.unschedule(self.update_preview)

    # P R E V I E W   W I D G E T
    def update_preview(self, *args, **kwargs):
        try:
            imdata = self.preview_handler.queue.get(False)
        except queue.Empty:
            return

        # textures must be created in the main thread;
        # this is a limitation in pygame
        texture = Texture.create_from_data(imdata)

        if self.preview_widget is None:
            tilt_max = pkConfig.getint('arduino', 'max-tilt')
            tilt_min = pkConfig.getint('arduino', 'min-tilt')

            def on_touch_move(widget, touch):
                if widget.collide_point(touch.x, touch.y):
                    self.tilt += touch.dpos[1] / 5
                    if self.tilt < tilt_min:
                        self.tilt = tilt_min
                    if self.tilt > tilt_max:
                        self.tilt = tilt_max
                    value = int(round(self.tilt, 0))
                    self.arduino_handler.set_camera_tilt(value)

            self.preview_widget = Image(texture=texture, nocache=True)
            self.preview_widget.bind(on_touch_move=on_touch_move)
            self.preview_widget.allow_stretch = True
            self.preview_widget.size_hint = None, None
            self.preview_widget.size = (1280, 1024)
            self.preview_widget.x = (1280 / 2) - (self.preview_widget.width / 2)
            self.preview_widget.y = -self.preview_widget.height
            self.layout.add_widget(self.preview_widget)
        else:
            self.preview_widget.texture = texture

    def on_image_touch(self, widget, touch):
        """ called when any image is touched
        """
        if widget.collide_point(touch.x, touch.y):
            # hide the focus widget
            if self.scrollview_hidden:
                self.change_state('normal', widget=widget)

            # show the focus widget
            elif self.focus_widget is not widget:
                if widget is self.preview_widget:
                    return False

                self.change_state('focus', widget=widget)

    def on_picker_scroll(self, widget, value):
        self.slider.value = value
        self.scrollview.update_from_scroll()
        # this is the left/right parallax animation
        if not self.locked:
            self.background.pos = self._calc_bg_pos()
        return True

    def _calc_bg_pos(self):
        bkg_w = self.background.width * .3
        return (-self.scrollview.scroll_x * bkg_w - self.width / 2,
                self.background.pos[1])
예제 #29
0
class B2L3(Screen):  #Building 2 Level 3
    def __init__(self, **kwargs):
        Screen.__init__(self, **kwargs)
        self.layout = FloatLayout()

        # Mapping of the Dustbin
        self.label2 = Label(text='.',
                            color=(0, 0, 1, 1),
                            font_size=100,
                            pos=(-220, 30))
        self.label3 = Label(text='2.3A (1%)',
                            color=(0, 0, 1, 1),
                            font_size=18,
                            pos=(-220, -25))
        self.label4 = Label(text='.',
                            color=(0, 0, 1, 1),
                            font_size=100,
                            pos=(-60, 55))
        self.label5 = Label(text='2.3B (1%)',
                            color=(0, 0, 1, 1),
                            font_size=18,
                            pos=(-60, 0))
        self.label6 = Label(text='.',
                            color=(0, 0, 1, 1),
                            font_size=100,
                            pos=(180, 95))
        self.label7 = Label(text='2.3C (1%)',
                            color=(0, 0, 1, 1),
                            font_size=18,
                            pos=(180, 40))
        self.label8 = Label(text='.',
                            color=(0, 0, 1, 1),
                            font_size=100,
                            pos=(-180, -80))
        self.label9 = Label(text='2.3D (1%)',
                            color=(0, 0, 1, 1),
                            font_size=18,
                            pos=(-180, -135))
        self.label10 = Label(text='.',
                             color=(0, 0, 1, 1),
                             font_size=100,
                             pos=(-55, -75))
        self.label11 = Label(text='2.3E (1%)',
                             color=(0, 0, 1, 1),
                             font_size=18,
                             pos=(-55, -130))
        self.label12 = Label(text='.',
                             color=(0, 0, 1, 1),
                             font_size=100,
                             pos=(55, -125))
        self.label13 = Label(text='2.3F (1%)',
                             color=(0, 0, 1, 1),
                             font_size=18,
                             pos=(55, -180))
        self.label14 = Label(text='.',
                             color=(0, 0, 1, 1),
                             font_size=100,
                             pos=(250, -80))
        self.label15 = Label(text='2.3G (1%)',
                             color=(0, 0, 1, 1),
                             font_size=18,
                             pos=(250, -135))

        # Floor Plan and Slide Detection
        self.image1 = Image(source='Building2.png')
        self.image1.bind(on_touch_move=self.detect)

        # Add Widget
        self.layout.add_widget(self.image1)
        self.layout.add_widget(self.label2)
        self.layout.add_widget(self.label3)
        self.layout.add_widget(self.label4)
        self.layout.add_widget(self.label5)
        self.layout.add_widget(self.label6)
        self.layout.add_widget(self.label7)
        self.layout.add_widget(self.label8)
        self.layout.add_widget(self.label9)
        self.layout.add_widget(self.label10)
        self.layout.add_widget(self.label11)
        self.layout.add_widget(self.label12)
        self.layout.add_widget(self.label13)
        self.layout.add_widget(self.label14)
        self.layout.add_widget(self.label15)

        self.add_widget(self.layout)

    def detect(self, instance, touch):
        if touch.dy > 20:  # Slide up to Building 1 Level 3
            self.manager.transition.direction = 'up'
            self.manager.current = 'B1L3'
예제 #30
0
class AnimatedButton(Label):

    state = OptionProperty('normal', options=('normal', 'down'))

    allow_stretch = BooleanProperty(True)

    keep_ratio = BooleanProperty(False)

    border = ObjectProperty(None)

    anim_delay = ObjectProperty(None)

    background_normal = StringProperty(
            'atlas://data/images/defaulttheme/button')

    texture_background = ObjectProperty(None)

    background_down = StringProperty(
            'atlas://data/images/defaulttheme/button_pressed')

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

        self.register_event_type('on_press')
        self.register_event_type('on_release')
        #borderImage.border by default is ...
        self.border = (16, 16, 16, 16)
        #Image to display depending on state
        self.img = Image(source = self.background_normal,
                        allow_stretch = self.allow_stretch,
                        keep_ratio = self.keep_ratio, mipmap = True)
        #reset animation if anim_delay is changed
        def anim_reset(*l):
            self.img.anim_delay = self.anim_delay
        self.bind(anim_delay = anim_reset)
        self.anim_delay = .1
        #update self.texture when image.texture changes
        self.img.bind(texture = self.on_tex_changed)
        self.on_tex_changed()
        #update image source when background image is changed
        def background_changed(*l):
            self.img.source = self.background_normal
            self.anim_delay = .1
        self.bind(background_normal = background_changed)

    def on_tex_changed(self, *largs):
        self.texture_background = self.img.texture

    def _do_press(self):
        self.state = 'down'

    def _do_release(self):
        self.state = 'normal'

    def on_touch_down(self, touch):
        if not self.collide_point(touch.x, touch.y):
            return False
        if self in touch.ud:
            return False
        touch.grab(self)
        touch.ud[self] = True
        _animdelay = self.img.anim_delay
        self.img.source = self.background_down
        self.img.anim_delay = _animdelay
        self._do_press()
        self.dispatch('on_press')
        return True

    def on_touch_move(self, touch):
        return self in touch.ud

    def on_touch_up(self, touch):
        if touch.grab_current is not self:
            return
        assert(self in touch.ud)
        touch.ungrab(self)
        _animdelay = self.img._coreimage.anim_delay
        self.img.source = self.background_normal
        self.anim_delay = _animdelay
        self._do_release()
        self.dispatch('on_release')
        return True

    def on_press(self):
        pass

    def on_release(self):
        pass
예제 #31
0
    def build(self):
        self.from_move = None
        self.to_move = None
        self.chessboard = ChessBoard()
        self.analysis_board = ChessBoard()
        self.squares = []
        self.use_engine = False
        self.last_touch_down_move = None
        self.last_touch_up_move = None

        parent = BoxLayout(size_hint=(1, 1))
        grid = GridLayout(cols=8, rows=8, spacing=0, size_hint=(1, 1))

        for i, name in enumerate(SQUARES):
            bt = Image(allow_stretch=True)
            bt.sq = i
            bt.name = name
            # bt.border = [0,0,0,0]
            if i in light_squares:
                bt.sq_color = "l"
                bt.background_down = "img/empty-l.png"

            #                bt.background_color=[1,1,1,1]
            else:
                bt.sq_color = "d"
                bt.background_down = "img/empty-d.png"

            #                bt.background_color=[0,0,0,0]
            #                print i
            # bt.bind(on_press=self.callback)
            bt.bind(on_touch_down=self.touch_down_move)
            bt.bind(on_touch_up=self.touch_up_move)
            # bt.bind(on_touch_up=self.touch_move)

            grid.add_widget(bt)
            self.squares.append(bt)

        b = BoxLayout(size_hint=(0.15, 0.15))
        ## Spacers
        #        b.add_widget(Button(spacing=1))
        #        b.add_widget(Button(spacing=1))
        #        b.add_widget(Button(spacing=1))

        # Move control buttons
        #        back_bt = Button(markup=True)
        #       # back_bt.background_normal="img/empty-l.png"
        #        back_bt.text="[color=ff3333]Back[/color]"
        #        back_bt.bind(on_press=self.back)
        #        b.add_widget(back_bt)
        #
        save_bt = Button(markup=True)
        #fwd_bt.background_normal="img/empty-d.png"
        save_bt.text = "[color=3333ff]Save[/color]"
        # save_bt.text="Save"

        save_bt.bind(on_press=self.save)
        b.add_widget(save_bt)

        #        b.add_widget(Button(spacing=10))
        #        b.add_widget(Button(spacing=10))
        #        b.add_widget(Button(spacing=10))

        #        grid.add_widget(b)

        #        board_box.add_widget(grid)
        #        board_box.add_widget(b)

        #        fen_input = TextInput(text="FEN", focus=True, multiline=False)
        #        def on_fen_input(instance):
        #            self.chessboard.setFEN(instance.text)
        #            self.refresh_board()
        ##            print 'The widget', instance.text
        #
        #        fen_input.bind(on_text_validate=on_fen_input)
        ##        self._keyboard.bind(on_key_down=self._on_keyboard_down)
        #
        #
        #        b.add_widget(fen_input)

        settings_bt = Button(markup=True, text='Setup')
        settings_bt.bind(on_press=self.go_to_settings)
        b.add_widget(settings_bt)

        #        self.root.current='settings'

        parent.add_widget(grid)

        info_grid = GridLayout(cols=1,
                               rows=4,
                               spacing=1,
                               size_hint=(0.3, 1),
                               orientation='vertical')
        info_grid.add_widget(b)

        self.game_score = ScrollableLabel('New Game',
                                          ref_callback=self.go_to_move)

        info_grid.add_widget(self.game_score)

        self.engine_score = ScrollableLabel(
            '[ref=engine_toggle]Analysis[/ref]',
            ref_callback=self.add_eng_moves)
        info_grid.add_widget(self.engine_score)

        info_grid.add_widget(Button(text="Text"))

        parent.add_widget(info_grid)
        self.refresh_board()

        platform = kivy.utils.platform()
        self.uci_engine = None
        if self.is_desktop():
            self._keyboard = Window.request_keyboard(self._keyboard_closed,
                                                     self)
            self._keyboard.bind(on_key_down=self._on_keyboard_down)

            self.start_engine_thread()
        sm = ScreenManager(transition=SlideTransition())
        board_screen = Screen(name='main')
        board_screen.add_widget(parent)
        sm.add_widget(board_screen)

        settings_screen = SettingsScreen(name='settings')
        settings_screen.add_widget(self.generate_settings())

        sm.add_widget(settings_screen)

        return sm
예제 #32
0
class AnimatedButton(Label):
    state = OptionProperty('normal', options=('normal', 'down'))
    allow_stretch = BooleanProperty(True)
    keep_ratio = BooleanProperty(False)
    border = ObjectProperty(None)
    anim_delay = ObjectProperty(None)
    background_normal = StringProperty(
        'atlas://data/images/defaulttheme/button')
    texture_background = ObjectProperty(None)
    background_down = StringProperty(
        'atlas://data/images/defaulttheme/button_pressed')

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

        self.register_event_type('on_press')
        self.register_event_type('on_release')
        # borderImage.border by default is ...
        self.border = (16, 16, 16, 16)
        # Image to display depending on state
        self.img = Image(
            source=self.background_normal,
            allow_stretch=self.allow_stretch,
            keep_ratio=self.keep_ratio,
            mipmap=True)

        # reset animation if anim_delay is changed
        def anim_reset(*l):
            self.img.anim_delay = self.anim_delay

        self.bind(anim_delay=anim_reset)
        self.anim_delay = .1
        # update self.texture when image.texture changes
        self.img.bind(texture=self.on_tex_changed)
        self.on_tex_changed()

        # update image source when background image is changed
        def background_changed(*l):
            self.img.source = self.background_normal
            self.anim_delay = .1

        self.bind(background_normal=background_changed)

    def on_tex_changed(self, *largs):
        self.texture_background = self.img.texture

    def _do_press(self):
        self.state = 'down'

    def _do_release(self):
        self.state = 'normal'

    def on_touch_down(self, touch):
        if not self.collide_point(touch.x, touch.y):
            return False
        if repr(self) in touch.ud:
            return False
        touch.grab(self)
        touch.ud[repr(self)] = True
        _animdelay = self.img.anim_delay
        self.img.source = self.background_down
        self.img.anim_delay = _animdelay
        self._do_press()
        self.dispatch('on_press')
        return True

    def on_touch_move(self, touch):
        return repr(self) in touch.ud

    def on_touch_up(self, touch):
        if touch.grab_current is not self:
            return
        assert (repr(self) in touch.ud)
        touch.ungrab(self)
        _animdelay = self.img._coreimage.anim_delay
        self.img.source = self.background_normal
        self.anim_delay = _animdelay
        self._do_release()
        self.dispatch('on_release')
        return True

    def on_press(self):
        pass

    def on_release(self):
        pass
예제 #33
0
class PickerScreen(Screen):
    """ A nice looking touch-enabled file browser
    """
    large_preview_size = ListProperty()
    small_preview_size = ListProperty()
    grid_rows = NumericProperty()
    images = ListProperty()

    def __init__(self, *args, **kwargs):
        super(PickerScreen, self).__init__(*args, **kwargs)
        self.preview_widget = None

    def on_pre_enter(self):
        # set up the 'normal' state
        self.state = 'normal'

        # these are pulled from the .kv format file
        self.view = search(self, 'view')
        self.top_parent = search(self, 'top_parent')
        self.slider = search(self, 'slider')
        self.drawer = search(self, 'drawer')
        self.preview_button = search(self, 'preview button')
        self.background = search(self, 'background')
        self.scrollview = search(self, 'scrollview')
        self.grid = search(self, 'grid')

        # the grid will expand horizontally as items are added
        def f(widget, value):
            self.grid.width = value
            #self.slider.max = value

        self.grid.bind(minimum_width=f)

        # TODO: eventually make this related to the screen width, maybe
        self.grid.spacing = (64, 64)

        self.slider.max = 1

        # slider => scrollview binding
        def f(scrollview, widget, value):
            # not sure why value has to be negated here
            scrollview.effect_x.value = -value * self.grid.minimum_width

        self.slider.bind(value=partial(f, self.scrollview))

        # scrollview => slider binding
        def f(slider, widget, value):
            print "slider", slider, widget, value
            # avoid 'maximum recursion depth exceeded' error
            if value >= 0:
                slider.value = value

        self.scrollview.effect_x.bind(value=partial(f, self.slider))

        # background parallax effect
        def f(widget, value):
            if not self.locked:
                self.background.pos_hint = {'x': -value - .3, 'y': -.25}

        self.scrollview.bind(scroll_x=f)

        # kivy's scroll effect doesn't seem to work with a huge scrollview
        # so set the effect to my homebrew scrolling effect
        self.scrollview.effect_cls = MyScrollEffect

        # tweak the loading so it is quick
        Loader.loading_image = CoreImage(image_path('loading.gif'))
        Loader.num_workers = pkConfig.getint('kiosk', 'loaders')
        Loader.max_upload_per_frame = pkConfig.getint('kiosk',
                                                      'max-upload-per-frame')

        self.scrollview_hidden = False

        # stuff for the arduino/tilt
        self.arduino_handler = ArduinoHandler()

        # queueing them and updaing the widget's texture
        self.preview_handler = PreviewHandler()
        self.preview_handler.start()

        # F O C U S   W I D G E T
        # the focus widget is the large preview image
        self.focus_widget = Factory.FocusWidget(
            source=image_path('loading.gif'))
        self.focus_widget.allow_stretch = True
        self.focus_widget.pos_hint = {'top': -1, 'center_x': .75}
        self.focus_widget.height = self.height
        self.focus_widget.bind(on_touch_down=self.on_image_touch)
        self.add_widget(self.focus_widget)

        #   P R E V I E W   B U T T O N
        # this button is used to toggle the large camera preview window
        def f(widget):
            if not self.locked:
                if self.state == 'normal':
                    self.change_state('preview')
                elif self.state == 'preview':
                    self.change_state('normal')

        self.preview_button.bind(on_press=f)

        #   P R E V I E W   L A B E L
        # the preview label is used with the focus widget is open
        self.preview_label = Factory.PreviewLabel(pos=(-1000, -1000))
        self.view.add_widget(self.preview_label)

        # the background has a parallax effect
        self.background.source = image_path('galaxy.jpg')
        self.background.pos_hint = {'x': 0}

        self.locked = False
        self.loaded = set()

        Clock.schedule_interval(self.check_new_photos, 1)

    def on_image_touch(self, widget, touch):
        """ called when any image is touched
        """
        if widget.collide_point(touch.x, touch.y):
            # hide the focus widget
            if self.scrollview_hidden:
                self.change_state('normal', widget=widget)

            # show the focus widget
            elif self.focus_widget is not widget:
                if widget is self.preview_widget:
                    return False

                self.change_state('focus', widget=widget)

    def check_new_photos(self, dt):
        """ Scan for new images and scroll to edge if found
        """

        new = self.get_images() - self.loaded

        for filename in sorted(new):
            self.loaded.add(filename)
            widget = Factory.AsyncImage(source=filename, allow_stretch=True)
            widget.bind(on_touch_down=self.on_image_touch)
            self.grid.add_widget(widget)

        if new and self.scrollview.effect_x is not None:
            self.loaded |= new
            Animation(value_normalized=1, t='in_out_quad',
                      duration=1).start(self.slider)

    def _remove_widget_after_ani(self, ani, widget):
        self.remove_widget(widget)

    def show_controls(self, widget, arg):
        widget.pos_hint = {'x': 0}
        return False

    def unlock(self, dt=None):
        self.locked = False

    def change_state(self, state, **kwargs):
        if self.locked:
            return

        # replace with a state machine in the future?  ...yes.
        if state == 'preview' and self.preview_widget is None:
            self.update_preview()
            return

        screen_width, screen_height = self.view.size

        new_state = state
        old_state = self.state
        self.state = new_state
        transition = (old_state, self.state)

        logger.debug('transitioning state %s', transition)

        # ====================================================================
        #  F O C U S  =>  N O R M A L
        if transition == ('focus', 'normal'):
            self.scrollview_hidden = False

            # cancel all running animations
            Animation.cancel_all(self.controls)
            Animation.cancel_all(self.scrollview)
            Animation.cancel_all(self.background)
            Animation.cancel_all(self.focus_widget)

            # close the keyboard
            from kivy.core.window import Window

            Window.release_all_keyboards()

            # disable the controls (workaround until 1.8.0)
            self.controls.disable()

            # hide the controls
            ani = Animation(opacity=0.0, duration=.3)
            ani.bind(on_complete=self._remove_widget_after_ani)
            ani.start(self.preview_label)
            if self.controls:
                ani.start(self.controls)

            # set the background to normal
            ani = Animation(size_hint=(3, 1.5), t='in_out_quad', duration=.5)
            ani.start(self.background)

            # show the scrollview and drawer
            ani = Animation(y=0, t='in_out_quad', opacity=1.0, duration=.5)
            ani.start(search(self, 'scrollview_area'))
            ani.start(self.drawer)

            # hide the focus widget
            ani = Animation(pos_hint={'top': 0},
                            height=screen_height * .25,
                            t='in_out_quad',
                            duration=.5)

            ani &= Animation(opacity=0.0, duration=.5)

            ani.start(self.focus_widget)

            # schedule a unlock
            self.locked = True
            Clock.schedule_once(self.unlock, .5)

        #=====================================================================
        #  N O R M A L  =>  F O C U S
        elif transition == ('normal', 'focus'):
            widget = kwargs['widget']
            self.scrollview_hidden = True

            # cancel all running animations
            Animation.cancel_all(self.scrollview)
            Animation.cancel_all(self.background)
            Animation.cancel_all(self.focus_widget)
            Animation.cancel_all(self.drawer)

            # set the focus widget to have the same image as the one picked
            # do a bit of mangling to get a more detailed image
            thumb, detail, original, comp = self.get_paths()
            filename = jpath(detail, os.path.basename(widget.source))
            original = jpath(original, os.path.basename(widget.source))

            # get a medium resolution image for the preview
            self.focus_widget.source = filename

            # show the controls
            self.controls = SharingControls()
            self.controls.filename = original
            self.controls.size_hint = .40, 1
            self.controls.opacity = 0

            ani = Animation(opacity=1.0, duration=.3)
            ani.start(self.preview_label)
            ani.start(self.controls)

            self.preview_label.pos_hint = {'x': .25, 'y': .47}
            self.add_widget(self.controls)

            # hide the scrollview and drawer
            ani = Animation(x=0,
                            y=-1000,
                            t='in_out_quad',
                            opacity=0.0,
                            duration=.7)
            ani.start(search(self, 'scrollview_area'))
            ani.start(self.drawer)

            # start a simple animation on the background
            x = self.background.pos_hint['x']
            ani = Animation(t='in_out_quad', size_hint=(4, 2), duration=.5)
            ani += Animation(pos_hint={'x': x + 1.5}, duration=480)
            ani.start(self.background)

            # show the focus widget
            ani = Animation(opacity=1.0,
                            pos_hint={
                                'top': 1,
                                'center_x': .75
                            },
                            size_hint=(1, 1),
                            t='in_out_quad',
                            duration=.5)
            ani &= Animation(opacity=1.0, duration=.5)
            ani.start(self.focus_widget)

            # schedule a unlock
            self.locked = True
            Clock.schedule_once(self.unlock, .5)

        #=====================================================================
        #  N O R M A L  =>  P R E V I E W
        elif transition == ('normal', 'preview'):
            self.scrollview_hidden = True

            # cancel all running animations
            Animation.cancel_all(self.scrollview)
            Animation.cancel_all(self.background)
            Animation.cancel_all(self.focus_widget)
            Animation.cancel_all(self.preview_widget)
            Animation.cancel_all(self.drawer)

            # show the camera preview
            ani = Animation(
                size_hint=(1, 1),
                #pos_hint={'x': 0, 'y': 1},
                x=0,
                y=0,
                t='in_out_quad',
                duration=.5)
            ani &= Animation(opacity=1.0, duration=.5)
            ani.start(self.preview_widget)

            # hide the layout
            ani = Animation(x=0,
                            y=-2000,
                            t='in_out_quad',
                            opacity=0.0,
                            duration=.7)
            ani.start(search(self, 'scrollview_area'))

            # schedule a unlock
            def f(*args):
                self.unlock()
                self.preview_button.text = 'Hide Preview'

            self.locked = True
            Clock.schedule_once(f, .7)

            # schedule an interval to update the preview widget
            interval = pkConfig.getfloat('camera', 'preview-interval')
            Clock.schedule_interval(self.update_preview, interval)

        #=====================================================================
        #  P R E V I E W  =>  N O R M A L
        elif transition == ('preview', 'normal'):
            self.scrollview_hidden = False

            # cancel all running animations
            Animation.cancel_all(self.scrollview)
            Animation.cancel_all(self.background)
            Animation.cancel_all(self.focus_widget)
            Animation.cancel_all(self.preview_widget)
            Animation.cancel_all(self.drawer)

            # hide the camera preview
            ani = Animation(y=-self.preview_widget.height,
                            t='in_out_quad',
                            duration=.5)
            ani &= Animation(opacity=0.0, duration=.5)
            ani.start(self.preview_widget)

            # show the layout
            ani = Animation(y=0, t='in_out_quad', opacity=1.0, duration=.5)
            ani.start(search(self, 'scrollview_area'))

            # schedule a unlock
            def f(*args):
                self.unlock()
                self.preview_button.text = 'Show Preview'

            self.locked = True
            Clock.schedule_once(f, .7)

            # unschedule the preview updater
            Clock.unschedule(self.update_preview)

    # P R E V I E W   W I D G E T
    def update_preview(self, *args, **kwargs):
        try:
            imdata = self.preview_handler.queue.get(False)
        except queue.Empty:
            return

        # textures must be created in the main thread;
        # this is a limitation in pygame
        texture = Texture.create_from_data(imdata)

        if self.preview_widget is None:
            self.tilt = 90
            tilt_max = pkConfig.getint('arduino', 'max-tilt')
            tilt_min = pkConfig.getint('arduino', 'min-tilt')

            def on_touch_move(widget, touch):
                if widget.collide_point(touch.x, touch.y):
                    self.tilt += touch.dpos[1] / 5
                    if self.tilt < tilt_min:
                        self.tilt = tilt_min
                    if self.tilt > tilt_max:
                        self.tilt = tilt_max
                    value = int(round(self.tilt, 0))
                    self.arduino_handler.set_camera_tilt(value)

            self.preview_widget = Image(texture=texture, nocache=True)
            self.preview_widget.bind(on_touch_move=on_touch_move)
            self.preview_widget.allow_stretch = True
            self.preview_widget.x = 0
            self.preview_widget.y = -2000
            self.view.add_widget(self.preview_widget)
        else:
            self.preview_widget.texture = texture