Exemple #1
0
    def add_clip(self, filename=None, length=None):
        role = self.app.config.get('ChatSettings', 'role')
        if role == 'ARTIST':

            # Generate the index number of the clip for referencing in filenames
            SessionScreen.clip_no += 1

            # add play button and filename index # for later playback
            btn = ToggleButton(background_normal='../img/play.png',
                               size_hint=(.18, 1), group='play', allow_stretch=False)
            btn.apply_property(clip_no=NumericProperty(SessionScreen.clip_no))
            btn.bind(on_press=self.play_clip)

            # add filename label
            audio_files = self.app.get_own_state()['audio_files']
            label = Label(text=os.path.basename(audio_files[-1])[0:9], halign='left', size_hint=(.5, 0.2))

            # add request button
            btn2 = Label(text="", size=(100, 50),
                          size_hint=(0.32, None))
            # Same clip number as play button

            self.ids.audioSidebar.add_widget(btn)
            self.ids.audioSidebar.add_widget(label)
            self.ids.audioSidebar.add_widget(btn2)

        elif role == 'PRODUCER':
            self.app.phone.stop_start_recording(datetime.now().strftime(constants.DATETIME_LQ))
            btn = ToggleButton(background_normal='../img/play.png',
                               size_hint=(.18, 1), group='play', allow_stretch=False)
            btn.apply_property(filename=StringProperty(filename))
            btn.apply_property(length=StringProperty(length))
            btn.bind(on_press=self.play_clip)

            # add filename label
            label = Label(text=filename, halign='left', size_hint=(.5, 0.2))

            # add request button
            btn2 = Button(text="Request", size=(100, 50),
                          size_hint=(0.32, None))
            # Same clip number as play button
            btn2.apply_property(filename=StringProperty(filename))
            btn2.bind(on_press=self.request_file)

            self.ids.audioSidebar.add_widget(btn)
            self.ids.audioSidebar.add_widget(label)
            self.ids.audioSidebar.add_widget(btn2)

        else:  # You are a listener
            self.app.phone.stop_start_recording(datetime.now().strftime(constants.DATETIME_LQ))
            btn = ToggleButton(background_normal='../img/play.png',
                               size_hint=(.18, 1), group='play', allow_stretch=False)
            btn.apply_property(filename=StringProperty(filename))
            btn.apply_property(length=StringProperty(length))
            btn.bind(on_press=self.play_clip)

            # add filename label
            label = Label(text=filename, halign='left', size_hint=(.5, 0.2))

            # add request button
            btn2 = Label(text="", size=(100, 50),
                         size_hint=(0.32, None))

            self.ids.audioSidebar.add_widget(btn)
            self.ids.audioSidebar.add_widget(label)
            self.ids.audioSidebar.add_widget(btn2)