[Pychord-commits] r42 - in trunk: pgui pychord2

danilo at garage.maemo.org danilo at garage.maemo.org
Wed Mar 5 03:29:46 EET 2008


Author: danilo
Date: 2008-03-05 03:29:44 +0200 (Wed, 05 Mar 2008)
New Revision: 42

Added:
   trunk/pgui/combo.py
Modified:
   trunk/pgui/__init__.py
   trunk/pgui/button.py
   trunk/pgui/container.py
   trunk/pgui/input.py
   trunk/pgui/label.py
   trunk/pgui/locale.py
   trunk/pgui/pguiobject.py
   trunk/pychord2/main_window.py
Log:
All widgets are Working!!!

Modified: trunk/pgui/__init__.py
===================================================================
--- trunk/pgui/__init__.py	2008-03-03 05:59:01 UTC (rev 41)
+++ trunk/pgui/__init__.py	2008-03-05 01:29:44 UTC (rev 42)
@@ -5,5 +5,6 @@
 from label import *
 from input import *
 from button import *
+from combo import *
 
 from locale import *
\ No newline at end of file

Modified: trunk/pgui/button.py
===================================================================
--- trunk/pgui/button.py	2008-03-03 05:59:01 UTC (rev 41)
+++ trunk/pgui/button.py	2008-03-05 01:29:44 UTC (rev 42)
@@ -1,15 +1,15 @@
-from widget import *
-from container import *
-from label import *
-
 from pygame.locals import *
 import pygame
 import os
 
-
-from box import *
+from widget import *
+from container import *
 from label import *
+from box import *
+from locale import *
 
+
+
 images_dir = os.path.join( "img" )
 
 
@@ -23,14 +23,15 @@
 
 class Tbutton (container):
     
-    def __init__(self, father, position, text = '', ptsize = 30, width = None,
+    def __init__(self, father, position, text = '', ptsize = pguiDefFontSize, width = None,
                  height = None, color=(0,0,0), bgcolor=(200,200,200),
                  bsize = 1, padding = 2):
         
         self.text = text
         self.bsize = bsize
         self.padding = padding
-        self.position = position
+        self.father = father
+        self.setPositionByRelative(position)
         self.color = color
         self.bgcolor = bgcolor
         
@@ -49,7 +50,7 @@
         # creating the box
         self.box = box(self,[0,0],(width,height),bgcolor,bsize,(150,150,150))
         
-        #puting the label into the box image
+        #putting the label into the box image
         container.__init__(self, father,[self.box,self.label],position,self.box.size)
         
     def onMouseOn(self):
@@ -59,10 +60,8 @@
     def onMouseOff(self):
         container.onMouseOff(self)
         self.box.setBackground(self.box.bgcolor)
-        
-    def click(self):
-        print "Click"
 
+
 class Ibutton (button):
 
     def __init__(self, father, position, image_file):

Added: trunk/pgui/combo.py
===================================================================
--- trunk/pgui/combo.py	                        (rev 0)
+++ trunk/pgui/combo.py	2008-03-05 01:29:44 UTC (rev 42)
@@ -0,0 +1,81 @@
+from input import *
+from window import *
+from button import *
+from locale import *
+
+class combo (input):
+
+
+    def __init__(self, father, position, options = {}, ptsize = pguiDefFontSize, width = 300, height = None, bsize = 1):
+        """
+
+        @param string text : default text
+        @param List pos : Posicao inicial onde o widget vai
+aparecer, relativo a janela
+        @return  :
+        @author
+        """
+        
+        input.__init__(self,father,position,"", ptsize,width,height,bsize)
+        
+        self.options = {}
+        self.selected = None
+        
+        for key in options:
+            self.addOption(key,options[key]) 
+
+        self.comboWindow = comboWindow(None, self.screen, self.options, self.selected, self.position, self.size[1], self.size[0] )
+    
+        
+    def click(self):
+        self.showOptions()
+    
+    def showOptions(self):
+            self.comboWindow.show()
+            self.select(self.comboWindow.selected)
+            self.father.repaint()
+            
+    def addOption(self, key, value):
+        self.options[key] = value
+        pass
+    
+    def select(self, key):
+        self.selected = key
+        self.comboWindow.select(key)
+        if key == None:
+            self.modify("")
+        else:
+            self.modify(self.options[key])
+        
+        
+class comboWindow(window):
+    
+    def __init__(self, father, screen, options, selected, position, hOffset, width):
+        
+        size = [width, len(options)*30+20]
+        position = [position[0],position[1]+hOffset]
+
+        window.__init__(self, father, screen, [], position, size)
+        
+        self.select(selected)
+        
+        bgcolor = (255,255,255)
+        self.setBackground(bgcolor)
+        
+        p = 0
+        for key in options.keys():
+            btn = Tbutton(self,[10,p*30 + 10],options[key], width = width - 20, bgcolor = bgcolor)
+            btn.registerClickSlot(self.select,key)
+            self.addElement(btn)
+            p += 1
+        
+    def setIsPress(self):
+        if not self.rect.collidepoint(pygame.mouse.get_pos()):
+            self.close()
+        window.setIsPress(self)
+
+    def select(self, key):
+        self.selected = key
+        self.close()
+        
+        
\ No newline at end of file

Modified: trunk/pgui/container.py
===================================================================
--- trunk/pgui/container.py	2008-03-03 05:59:01 UTC (rev 41)
+++ trunk/pgui/container.py	2008-03-05 01:29:44 UTC (rev 42)
@@ -11,6 +11,7 @@
     
     def __init__(self, father, elementList = [], position = [0,0], size = [800,420] ):
         
+        # Get the screen when screen is needed
         if father != None:
             self.screen = father.screen
 

Modified: trunk/pgui/input.py
===================================================================
--- trunk/pgui/input.py	2008-03-03 05:59:01 UTC (rev 41)
+++ trunk/pgui/input.py	2008-03-05 01:29:44 UTC (rev 42)
@@ -18,7 +18,6 @@
         self.text = text
         self.bsize = bsize
         self.position = position
-        self.screen = father.screen
 
         # label
         lbl = label(self, [2,5], text, (50,50,50), ptsize = ptsize)

Modified: trunk/pgui/label.py
===================================================================
--- trunk/pgui/label.py	2008-03-03 05:59:01 UTC (rev 41)
+++ trunk/pgui/label.py	2008-03-05 01:29:44 UTC (rev 42)
@@ -1,6 +1,7 @@
 # -*- coding: utf-8 -*-
 
 from pgui import widget
+from locale import *
 
 from pygame import Surface
 from pygame.locals import *
@@ -17,7 +18,7 @@
     """
         
     def __init__(self, father, position , text, color = (255,255,255),
-              bgcolor = None, fontfile = None, ptsize = 30):
+              bgcolor = None, fontfile = None, ptsize = pguiDefFontSize):
     
         self.text = text
         self.color = color

Modified: trunk/pgui/locale.py
===================================================================
--- trunk/pgui/locale.py	2008-03-03 05:59:01 UTC (rev 41)
+++ trunk/pgui/locale.py	2008-03-05 01:29:44 UTC (rev 42)
@@ -6,3 +6,6 @@
 pguiImageString = 2
 pguiImage = 3
 
+
+#THEME OPTIONS
+pguiDefFontSize = 30 # Default FontSize

Modified: trunk/pgui/pguiobject.py
===================================================================
--- trunk/pgui/pguiobject.py	2008-03-03 05:59:01 UTC (rev 41)
+++ trunk/pgui/pguiobject.py	2008-03-05 01:29:44 UTC (rev 42)
@@ -20,9 +20,11 @@
         self.clicked = False
         
         
+        
+        
         self.father  = father     # father widget in hiearquy
+        self.size = size          # Defining widget size
         self.rel_pos = position   # Defining relative position
-        self.size = size          # Defining widget size
 
                    
         # Calculating absolute position on screen
@@ -31,8 +33,10 @@
                              self.father.position[1] + position[1]  ) 
         else:
             self.position = position
+       
+        
+        self.onClickSlots = []
             
-            
         
     def setBackground(self, bg, flag = pguiColor):
         
@@ -102,4 +106,19 @@
         pass
     
     def click(self):
-        pass
\ No newline at end of file
+        for functionName,vars in self.onClickSlots:
+            functionName(vars)
+    
+    def registerClickSlot(self, functionName, vars = []):
+        self.onClickSlots.append([functionName,vars])
+    
+    def setPositionByRelative(self, position = [0,0]):
+        self.rel_pos = position   # Defining relative position
+
+                   
+        # Calculating absolute position on screen
+        if self.father != None:                   
+            self.position = (self.father.position[0] + position[0],
+                             self.father.position[1] + position[1]  ) 
+        else:
+            self.position = position
\ No newline at end of file

Modified: trunk/pychord2/main_window.py
===================================================================
--- trunk/pychord2/main_window.py	2008-03-03 05:59:01 UTC (rev 41)
+++ trunk/pychord2/main_window.py	2008-03-05 01:29:44 UTC (rev 42)
@@ -6,6 +6,7 @@
 from pgui import locale
 from pgui import Tbutton
 from pgui import Ibutton
+from pgui import combo
 
 
 import pygame
@@ -56,3 +57,6 @@
         
         lbl = label(self, [10,200],"Search on:")
         self.addElement(lbl)
+        
+        cmb = combo(self, [10, 240], {'tab':'By Word','artist':'By Artist','song':'By Music'} ,width=700)
+        self.addElement(cmb)



More information about the Pychord-commits mailing list