User Tools

Site Tools


Writing /var/lib/dokuwiki/data/meta/teaching/ie0117/actividad_7new/kivy.meta failed
teaching:ie0117:actividad_7new:kivy

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
teaching:ie0117:actividad_7new:kivy [2016/05/16 16:40] adminteaching:ie0117:actividad_7new:kivy [2022/09/20 00:08] (current) – external edit 127.0.0.1
Line 1: Line 1:
-====== Actividad 7: Kivy ======+====== Actividad: Kivy ======
  
 ===== Preguntas ===== ===== Preguntas =====
Line 11: Line 11:
  
 ===== Instrucciones ===== ===== Instrucciones =====
 +
 +==== En la PC (Linux) ====
 +
 +  * En la PC instale python-kivy
 +  * Clone el repositorio de git de plyer:
 +
 +  cd ~/local/src
 +  git clone https://github.com/kivy/plyer
 +
 +  * Construya un paquete de debian para plyer e instálelo
 +
 +  sudo apt-get install python-stdeb
 +  cd ~/local/src/plyer
 +  python setup.py --command-packages=stdeb.command bdist_deb
 +  cd deb_dist
 +  sudo dpkg -i python-plyer_1.2.5dev-1_all.deb
 +
 +==== En Android ====
 +
 +  * Configure un servidor ssh. Instale la aplicación sshdroid (Play) o primitive ftpd (de f-droid), configure una clave para el servidor ssh
 +  * Instale kivy-launcher con Play.
 +
 +==== En la PC ====
 +
 +  * Monte el directorio remoto del celular en la computadora (si utiliza primitive ftpd):
 +
 +  mkdir -p ~/mnt/cel
 +  sshfs -p 1234 user@192.168.43.1:/ mnt/cel
 +
 +  * Ahora su celular está disponible en ~/mnt/cel
 +  * Cambien al directorio de kivy en el celular desde su PC:
 +
 +  cd ~/mnt/cel/storage/emulated/0/kivy
 +  mkdir test
 +  cd test
 +
 +  * Dentro de este directorio cree un archivo llamado main.py con el siguiente contenido:
 +
 +  import kivy
 +  kivy.require('1.0.6') # replace with your current kivy version !
 +  
 +  from kivy.app import App
 +  from kivy.uix.label import Label
 +  
 +  
 +  class MyApp(App):
 +  
 +      def build(self):
 +          return Label(text='Hello world')
 +  
 +  
 +  if __name__ == '__main__':
 +      MyApp().run()
 +
 +
 +  * Ejecútelo en Linux:
 +
 +  python main.py
 +
 +  * Ahora para poder correr este programa se debe crear un archivo llamado android.txt con el siguiente contenido:
 +
 +  title=Test
 +  author=test
 +  orientation=portrait
 +
 +==== En Android ====
 +
 +  * Utilice el kivy launcher para correr "Test"
 +  * Copie un archivo con una canción de la siguiente forma:
 +
 +  mkdir -p ~/mnt/cel/storage/emulated/0/kivy/test/musica/
 +  cp directorio_cancion/cancion.mp3 ~/mnt/cel/storage/emulated/0/kivy/test/musica/
 +
 +  * Cambien el contenido completo de main.py por lo siguiente:
 +
 +  from kivy.app import App
 +  from kivy.uix.button import Button
 +  from kivy.core.audio import SoundLoader
 +  from plyer import accelerometer as acc
 +  from kivy.logger import Logger
 +  from time import sleep
 +  from plyer import gps
 +  from kivy.properties import StringProperty
 +  from kivy.clock import Clock, mainthread
 +  from kivy.lang import Builder
 +  
 +  
 +  kv = '''
 +  BoxLayout:
 +      orientation: 'vertical'
 +      Label:
 +          text: app.gps_location
 +      Label:
 +          text: app.gps_status
 +      BoxLayout:
 +          size_hint_y: None
 +          height: '48dp'
 +          padding: '4dp'
 +          ToggleButton:
 +              text: 'Start' if self.state == 'normal' else 'Stop'
 +              on_state:
 +                  app.gps.start() if self.state == 'down' else app.gps.stop()
 +  '''
 +  
 +  class TestApp(App):
 +  
 +      gps_location = StringProperty()
 +      gps_status = StringProperty('Click Start to get GPS location updates')
 +  
 +  
 +      def build(self):
 +          self.gps = gps
 +          try:
 +              self.gps.configure(on_location=self.on_location,
 +                                 on_status=self.on_status)
 +          except NotImplementedError:
 +              import traceback
 +              traceback.print_exc()
 +              self.gps_status = 'GPS is not implemented for your platform'
 +  
 +          return Builder.load_string(kv)
 +  
 +  
 +      @mainthread
 +      def on_location(self, **kwargs):
 +          self.gps_location = '\n'.join([
 +              '{}={}'.format(k, v) for k, v in kwargs.items()])
 +  
 +      @mainthread
 +      def on_status(self, stype, status):
 +          self.gps_status = 'type={}\n{}'.format(stype, status)
 +  
 +  
 +  if __name__=="__main__":
 +      sound = SoundLoader.load('musica/cancion.mp3')
 +      if sound:
 +          print("Sound found at %s" % sound.source)
 +          print("Sound is %.3f seconds" % sound.length)
 +          sound.play()
 +      acc.enable()
 +      x=acc.get_acceleration()
 +      sleep(1)
 +      x=acc.get_acceleration()
 +      x=acc.get_acceleration()
 +      x=acc.get_acceleration()
 +      x=acc.get_acceleration()
 +      x=acc.get_acceleration()
 +      Logger.info('title: This is a info message.'+str(x))
 +  
 +      TestApp().run()
 +
 +  * Ejecútelo en Linux y Android y comente las diferencias.
 +
 +
  
 ===== Evaluación ===== ===== Evaluación =====
 +
 +Cuestionario:
 +
 +  * Comente que sucedió cuando corrió el primer programa main.py. Cuáles fueron las diferencias entre Linux y Android?
 +  * Comente que sucedió cuando corrió el segundo programa main.py. Cuáles fueron las diferencias entre Linux y Android?
 +  * Cómo puede generar mensajes de consola en el programa de Android y cómo puede leerlos?
  
  
teaching/ie0117/actividad_7new/kivy.1463416844.txt.gz · Last modified: 2022/09/20 00:08 (external edit)