[Pychord-commits] r49 - in trunk: . font pgui pychord2

danilo at garage.maemo.org danilo at garage.maemo.org
Sun Mar 9 17:36:55 EET 2008


Author: danilo
Date: 2008-03-09 17:36:49 +0200 (Sun, 09 Mar 2008)
New Revision: 49

Added:
   trunk/font/
   trunk/font/VeraMono.ttf
   trunk/pychord2/chordlist.py
Modified:
   trunk/pgui/container.py
   trunk/pgui/label.py
   trunk/pgui/list.py
   trunk/pgui/locale.py
   trunk/pgui/pguiobject.py
   trunk/pgui/window.py
   trunk/pychord2/main_window.py
Log:
- MonoSpace Font added
- chordlist widget fixed
  FontSizeUP and FontSizeDown implemented

Added: trunk/font/VeraMono.ttf
===================================================================
(Binary files differ)


Property changes on: trunk/font/VeraMono.ttf
___________________________________________________________________
Name: svn:mime-type
   + application/octet-stream

Modified: trunk/pgui/container.py
===================================================================
--- trunk/pgui/container.py	2008-03-09 13:38:18 UTC (rev 48)
+++ trunk/pgui/container.py	2008-03-09 15:36:49 UTC (rev 49)
@@ -33,9 +33,13 @@
         self.objects.append(obj)
         self.objectsReverted.insert(0,obj)
         
+    def clearElements(self):
+        self.objects = []
+        self.objectsReverted = []
+    
         
     def delElement(self, obj):
-        self.elements.remove(obj)
+        self.objects.remove(obj)
         self.objectsReverted.remove(obj)
         
         

Modified: trunk/pgui/label.py
===================================================================
--- trunk/pgui/label.py	2008-03-09 13:38:18 UTC (rev 48)
+++ trunk/pgui/label.py	2008-03-09 15:36:49 UTC (rev 49)
@@ -18,14 +18,14 @@
     """
         
     def __init__(self, father, position , text, color = (255,255,255),
-              bgcolor = None, fontfile = None, ptsize = pguiDefFontSize):
+              bgcolor = None, fontFile = None, ptsize = pguiDefFontSize):
     
         self.text = text
         self.color = color
         self.bgcolor = bgcolor
-        self.fontfile = fontfile
+        self.fontFile = fontFile
         self.ptsize = ptsize
-        self.font = pygame.font.Font( fontfile, ptsize )
+        self.font = pygame.font.Font( fontFile, ptsize )
         
         img  = self.font.render( self.text, True, self.color)
         size = img.get_size()

Modified: trunk/pgui/list.py
===================================================================
--- trunk/pgui/list.py	2008-03-09 13:38:18 UTC (rev 48)
+++ trunk/pgui/list.py	2008-03-09 15:36:49 UTC (rev 49)
@@ -5,7 +5,9 @@
 class list (container):
 
 
-    def __init__(self, father, position, text = [], ptsize = pguiDefFontSize, width = 700, height = 480, bsize = 1):
+    def __init__(self, father, position, text = [], fontFile = None, 
+                  ptsize = pguiDefFontSize, width = 700, height = 480,
+                  bsize = 1):
         """
 
         @param string text : default text
@@ -19,6 +21,7 @@
         self.bsize = bsize
         self.position = position
         self.ptsize = ptsize
+        self.fontFile = fontFile 
         
         #Autoscroll
         self.autoScroll(0)
@@ -27,11 +30,15 @@
         # label
         pos = 0
         for i in text: 
-            lbl = label(self, [2,pos*ptsize+5], i, (255,255,255), ptsize = ptsize)
+            lbl = label(self, [2,pos*ptsize+5], i, (255,255,255), fontFile = self.fontFile, ptsize = ptsize)
+            lbl.cutImg(width = width-2)
             self.addElement(lbl)
             pos +=1
-
             
+        self.setBackground((0,0,0))
+        
+        self.movedPosition = 0
+       
     def update(self):
         if self.clicked:
             pos = pygame.mouse.get_rel()
@@ -52,6 +59,8 @@
         
     def move(self,pos):
         
+        self.movedPosition +=pos
+        
         for i in self.objects:
             i.move([0,pos])
             

Modified: trunk/pgui/locale.py
===================================================================
--- trunk/pgui/locale.py	2008-03-09 13:38:18 UTC (rev 48)
+++ trunk/pgui/locale.py	2008-03-09 15:36:49 UTC (rev 49)
@@ -10,9 +10,10 @@
 pguiAlignCenter = 1 # Default Align position
 pguiAlignLeft   = 2 # AlignLeft position
 
-#SlotsTypeFlags
+#SlotsType Flags
 pguiOnClickSlot = 1
 pguiWhilePressedSlot = 2
+pguiOnKeyPress = 3
 
 #List Widget
 pguiListMaximumSpeed = 20

Modified: trunk/pgui/pguiobject.py
===================================================================
--- trunk/pgui/pguiobject.py	2008-03-09 13:38:18 UTC (rev 48)
+++ trunk/pgui/pguiobject.py	2008-03-09 15:36:49 UTC (rev 49)
@@ -40,12 +40,15 @@
         
     def setBackground(self, bg, flag = pguiColor):
         
+        self.backgroundType = pguiColor
+        self.background = bg
+        
         if bg == None:
             self.background = None
             
         elif flag == pguiColor:
-            self.background = Surface(self.size)
-            self.background.fill(bg)
+            self.backgroundImg = Surface(self.size)
+            self.backgroundImg.fill(bg)
         
         if self.father != None:    
             self.father.dirty = True
@@ -70,7 +73,7 @@
     def drawBackground(self, screen):
   
         if self.background != None:
-            screen.blit(self.background, self.position)
+            screen.blit(self.backgroundImg , self.position)
             self.dirty = True
     
     def mouseState(self, pos):
@@ -89,15 +92,6 @@
     def onMouseOff(self):
         pass
     
-    def whilePressed(self):
-        
-        for type,functionName,vars in self.Slots:
-            if type == pguiWhilePressedSlot:
-                if vars != None:
-                    functionName(vars)
-                else:
-                    functionName()
-    
     def onClick(self):
 
         print "onClick",self
@@ -122,9 +116,16 @@
         pass
     
     def click(self):
+        self.executeSlotsByType(pguiOnClickSlot)
 
+    def whilePressed(self):
+        self.executeSlotsByType(pguiWhilePressedSlot)
+
+                    
+    def executeSlotsByType(self, slotType):
+        
         for type,functionName,vars in self.Slots:
-            if type == pguiOnClickSlot:
+            if type == slotType:
                 if vars != None:
                     functionName(vars)
                 else:

Modified: trunk/pgui/window.py
===================================================================
--- trunk/pgui/window.py	2008-03-09 13:38:18 UTC (rev 48)
+++ trunk/pgui/window.py	2008-03-09 15:36:49 UTC (rev 49)
@@ -49,14 +49,17 @@
                 pygame.mouse.get_rel()
                 self.setIsPress()
                 
-            if (e.type == MOUSEBUTTONUP):
+            elif (e.type == MOUSEBUTTONUP):
                 self.mousePressed = False
                 self.sendClick()
                 
-            if (e.type == MOUSEMOTION and self.mousePressed):
+            elif (e.type == MOUSEMOTION and self.mousePressed):
                 self.sendMouseEvents(pygame.mouse.get_pos())
+            
+            elif( e.type == KEYDOWN):
+                self.onKeyPress(e.key)
                 
-            if (e.type == QUIT):
+            elif (e.type == QUIT):
                 self.close()
         
     def show(self):
@@ -87,8 +90,9 @@
         if self.objPressed != None:
             self.objPressed.onClickRelease()
             self.objPressed = None
-            
-       
+                 
+    def onKeyPress(self, key):
+        pass
 
     def close(self):
         """

Added: trunk/pychord2/chordlist.py
===================================================================
--- trunk/pychord2/chordlist.py	                        (rev 0)
+++ trunk/pychord2/chordlist.py	2008-03-09 15:36:49 UTC (rev 49)
@@ -0,0 +1,52 @@
+from pgui import list
+from pgui.locale import *
+
+
+class chordlist (list):
+    
+    def __init__(self, father, position, text = [], 
+                  ptsize = 25, width = 700, height = 480,
+                  bsize = 1):
+       
+        list.__init__(self, father, position, text, 'font/VeraMono.ttf',
+                  ptsize, width, height,
+                  bsize)
+
+    def fontUp(self):
+        
+        
+        self.clearElements()
+        background = self.background
+        pos =  self.movedPosition
+        speed = self.autoScrollSpeed
+        
+        self.__init__(self.father, 
+                      self.rel_pos, 
+                      self.text, 
+                      self.ptsize+2, 
+                      self.size[0], 
+                      self.size[1],
+                      self.bsize)
+        self.setBackground(background)
+        
+        self.move(pos)
+        self.autoScroll(speed)
+    
+    def fontDown(self):
+        
+        self.clearElements()
+        background = self.background
+        pos =  self.movedPosition
+        speed = self.autoScrollSpeed
+        
+        self.__init__(self.father, 
+                      self.rel_pos, 
+                      self.text, 
+                      self.ptsize-2, 
+                      self.size[0], 
+                      self.size[1],
+                      self.bsize)
+        self.setBackground(background)
+        
+        self.move(pos)
+        self.autoScroll(speed)
\ No newline at end of file

Modified: trunk/pychord2/main_window.py
===================================================================
--- trunk/pychord2/main_window.py	2008-03-09 13:38:18 UTC (rev 48)
+++ trunk/pychord2/main_window.py	2008-03-09 15:36:49 UTC (rev 49)
@@ -1,20 +1,18 @@
 # -*- coding: utf-8 -*-
 from pgui import window
-from pgui import box
-from pgui import label
-from pgui import input
-from pgui import locale
-from pgui import Tbutton
+#from pgui import box
+#from pgui import label
+#from pgui import input
+#from pgui import locale
+#from pgui import Tbutton
 from pgui import Ibutton
-from pgui import combo
-from pgui import list
+#from pgui import combo
+from chordlist import chordlist 
 
-
-import pygame
-from pygame.time   import Clock
 from pygame.locals import *
 
 
+
 class main_window( window ):
     
     
@@ -44,19 +42,20 @@
 #        btSearch = Tbutton(self, [410,300], "Search", width = 300, bsize = 3, padding = 6)
 #        self.addElement(btSearch)
 
-        lst = list(self, [0,0],["Ola mundo, bla bla bla", "Ola mundo, bla bla bla",
+        lst = chordlist(self, [0,0],["Ola mundo, aaaaaaaaaaaaaaaaaaa bla bla aaaaaaaa bla", "Ola mundo, bla bla bla",
+                    "Ola mundo, aaaaaaaaaaaaaaaaaaabla bla bla","Ola mundo, bla bla bla","Ola mundo, bla bla bla",
+                    "Ola mundo, aaaaaaaaaaaaaaaaaaabla bla bla","Ola mundo, bla bla bla","Ola mundo, bla bla bla",
+                    "Ola mundo, aaaaaaaaaaaaaaaaaaabla bla bla","Ola mundo, bla bla bla","Ola mundo, bla bla bla",
                     "Ola mundo, bla bla bla","Ola mundo, bla bla bla","Ola mundo, bla bla bla",
-                    "Ola mundo, bla bla bla","Ola mundo, bla bla bla","Ola mundo, bla bla bla",
                     "Ola mundo, bla bla bla", "Ola mundo, bla bla bla",
                     "Ola mundo, bla bla bla","Ola mundo, bla bla bla","Ola mundo, bla bla bla",
-                    "Ola mundo, bla bla bla","Ola mundo, bla bla bla","Ola mundo, bla bla bla",
-                    "Ola mundo, bla bla bla", "Ola mundo, bla bla bla",
-                    "Ola mundo, bla bla bla","Ola mundo, bla bla bla","Ola mundo, bla bla bla",
                     "Ola mundo, bla bla bla","Ola mundo, bla bla bla","Ola mundo, bla bla bla"])
         lst.setBackground((10,10,10))
         lst.autoScroll(2)
         self.addElement(lst)
         
+        self.chordList = lst
+        
         btFF = Ibutton(self,[730,400],"ff.png")
         btFF.registerPressedSlot(lst.increaseSpeed)
         self.addElement(btFF)
@@ -68,4 +67,11 @@
         btRR = Ibutton(self,[730,280],"rr.png")
         btRR.registerPressedSlot(lst.decreaseSpeed)
         self.addElement(btRR)
-   
\ No newline at end of file
+        
+        
+    def onKeyPress(self, key):
+        
+        if key == K_F8:
+            self.chordList.fontUp()
+        if key == K_F7:
+            self.chordList.fontDown()
\ No newline at end of file



More information about the Pychord-commits mailing list