Advertisement
gregwa

Transposer 0.1.1

Sep 7th, 2012
736
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 4.65 KB | None | 0 0
  1. import kivy
  2. kivy.require('1.0.8')
  3. from sys import exit
  4. from kivy.app import App
  5. from kivy.core.window import Window
  6. from kivy.uix.button import Button
  7. from kivy.uix.label import Label
  8. from kivy.uix.anchorlayout import AnchorLayout
  9. from kivy.uix.scrollview import ScrollView
  10. from kivy.uix.gridlayout import GridLayout
  11. from kivy.uix.popup import Popup
  12.  
  13. class BoundedLabel(Label):
  14.     pass
  15.    
  16. class Transpose(App):
  17.     def exit(instance):
  18.         sys.exit()
  19.        
  20.     def build(self):
  21.         def LoadLabels(w):
  22.             if w == 0:
  23.                 tex0 = self.text1
  24.                 tex1 = self.text2
  25.             else:
  26.                 tex0 = self.text3
  27.                 tex1 = self.text4
  28.             for i in range(0,22):
  29.                 if i <= 12:
  30.                     if i < 10:
  31.                         t1 = " " + str(i) + "| "
  32.                     else:
  33.                         t1 = str(i) + "| "
  34.                     t = tex1
  35.                 else:
  36.                     t1 = ''
  37.                     t = ''
  38.                 l = BoundedLabel(text=t1+t[(i*6):(i*6)+78], size=(780, 35),
  39.                              size_hint=(None, None),halign='left',font_name='data/fonts/DroidSansMono.ttf')
  40.                 s.add_widget(l)                
  41.                
  42.         def Swap(instance):                  
  43.             if self.whichway == 0:
  44.                 self.whichway = 1
  45.                 btnWhich.text = "Guitar --> Piano"
  46.                 btn1.text = "    " + self.text3
  47.                 s.clear_widgets()
  48.                 LoadLabels(1)                        
  49.             else:
  50.                 self.whichway = 0
  51.                 btnWhich.text = "Piano --> Guitar"
  52.                 btn1.text = "    " + self.text1
  53.                 s.clear_widgets()                        
  54.                 LoadLabels(0)        
  55.        
  56.         def ShowAbout(instance):
  57.             print "About to Popup"
  58.             popup.open()
  59.                    
  60.         self.whichway=0    
  61.         self.text1 = "  C  |  B  |A#/Bb|  A  |G#/Ab|  G  |F#/Gb|  F  |  E  |D#/Eb|  D  |C#/Db|  C  |"
  62.         self.text2 = "  C  |  B  |A#/Bb|  A  |G#/Ab|  G  |F#/Gb|  F  |  E  |D#/Eb|  D  |C#/Db|  C  |  B  |A#/Bb|  A  |G#/Ab|  G  |F#/Gb|  F  |  E  |D#/Ab|  D  |C#/Db|  C  |"
  63.         self.text3 = "  C  |C#/Db|  D  |D#/Eb|  E  |  F  |F#/Gb|  G  |G#/Ab|  A  |A#/Bb|  B  |  C  |"
  64.         self.text4 = "  C  |C#/Db|  D  |D#/Eb|  E  |  F  |F#/Gb|  G  |G#/Ab|  A  |A#/Bb|  B  |  C  |C#/Db|  D  |D#/Eb|  E  |  F  |F#/Gb|  G  |G#/Ab|  A  |A#/Bb|  B  |  C  |C#/Db|"        
  65.        
  66.         root = GridLayout(orientation='vertical', spacing=6, cols=1,rows=4,row_default_height=40)
  67.         lbl = Label(text='Transposer Ver 0.8.0',font_size=20,size_hint=(None,None),size=(480,20),padding=(10,10))        
  68.         btn1 = Button(text = "    " + self.text1,size=(780,20),
  69.                 size_hint=(None, None),
  70.                 halign='left',
  71.                 font_name='data/fonts/DroidSansMono.ttf',
  72.                 padding=(20,2),
  73.                 background_color=[0.39,0.07,.92,1])
  74.         al0 = AnchorLayout()
  75.         al1 = AnchorLayout()
  76.         al2 = AnchorLayout()
  77.         popup = Popup(title='About Transposer',
  78.                     content=Label(text='Written by G.D. Walters'),
  79.                     size_hint=(None,None),size=(400,400))
  80.         btnWhich = Button(text = "Piano --> Guitar",size=(180,40),size_hint=(None,None))
  81.         btnWhich.bind(on_release=Swap)
  82.         btnAbout=Button(text="About",size=(180,40),size_hint=(None,None))
  83.         btnAbout.bind(on_release=ShowAbout)
  84.         btnExit =Button(text="Exit", size=(180,40),size_hint=(None,None))
  85.         btnExit.bind(on_release=exit)                              
  86.         #--------------------------------------------------------------
  87.         root.add_widget(lbl)
  88.         root.add_widget(btn1)
  89.         #--------------------------------------------------------------
  90.         s = GridLayout(cols=1, spacing = 4, size_hint_y = None)
  91.         s.bind(minimum_height=s.setter('height'))
  92.         LoadLabels(0)
  93.         #--------------------------------------------------------------
  94.         sv = ScrollView(size_hint=(None, None), size=(600,400))
  95.  
  96.         sv.center = Window.center
  97.         root.add_widget(sv)
  98.         sv.add_widget(s)
  99.         al0.add_widget(btnWhich)
  100.         al1.add_widget(btnExit)
  101.         al2.add_widget(btnAbout)
  102.         bgl = GridLayout(orientation='vertical', spacing=6, cols=3,rows=1,row_default_height=40)
  103.         bgl.add_widget(al0)
  104.         bgl.add_widget(al1)
  105.         bgl.add_widget(al2)
  106.         root.add_widget(bgl)
  107.         return root
  108.        
  109. if __name__ in ('__main__','__android__'):
  110.     Transpose().run()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement