[Pychord-commits] r41 - tags/0.0.5/pyw trunk/pgui trunk/pychord2

danilo at garage.maemo.org danilo at garage.maemo.org
Mon Mar 3 07:59:04 EET 2008


Author: danilo
Date: 2008-03-03 07:59:01 +0200 (Mon, 03 Mar 2008)
New Revision: 41

Added:
   trunk/pgui/button.py
Modified:
   tags/0.0.5/pyw/pyw_button.py
   trunk/pgui/__init__.py
   trunk/pgui/box.py
   trunk/pgui/container.py
   trunk/pgui/input.py
   trunk/pgui/pguiobject.py
   trunk/pgui/widget.py
   trunk/pgui/window.py
   trunk/pychord2/main_window.py
Log:
Background fixes, button adds

Modified: tags/0.0.5/pyw/pyw_button.py
===================================================================
--- tags/0.0.5/pyw/pyw_button.py	2008-03-03 01:09:02 UTC (rev 40)
+++ tags/0.0.5/pyw/pyw_button.py	2008-03-03 05:59:01 UTC (rev 41)
@@ -12,9 +12,9 @@
 
 class pyw_button (pyw_widget):
 
-    def __init__(self, father, relative_position, size, img):
+    def __init__(self, father, position, size, img):
         # Widget creating
-        pyw_widget.__init__(self, father, relative_position, size, img)
+        pyw_widget.__init__(self, father, position, size, img)
         
 
 

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

Modified: trunk/pgui/box.py
===================================================================
--- trunk/pgui/box.py	2008-03-03 01:09:02 UTC (rev 40)
+++ trunk/pgui/box.py	2008-03-03 05:59:01 UTC (rev 41)
@@ -11,32 +11,15 @@
     # All widgets needs to know: father, position and size.
     # background needs to know too the color, the bordersize and
     # the background color
-    def __init__(self, father, position, size, color, bsize = 0, bcolor = (255,255,255)):
+    def __init__(self, father, position, size, color, bsize = 0, bgcolor = (255,255,255)):
         
         # Creating a new widget
         widget.__init__(self, father, position, size)
         self.color = color
         self.size = size
-        self.bcolor = bcolor 
+        self.bgcolor = bgcolor 
 
         if bsize > 0:
-            self.setBackground(bcolor)
+            self.setBackground(bgcolor)
             
-        pygame.draw.rect(self.img, color, Rect(bsize, bsize, size[0]-2*bsize, size[1]-2*bsize))
-        
-        
-        
-#    def update(self):
-#        pass
-#        
-#        if self.clicked:   
-#            pos = pygame.mouse.get_rel()
-#            self.move(pos)
-#            
-#    def onClick(self):
-#        self.setBackground((0,255,0))
-#        widget.onClick(self)
-#        
-#    def onClickRelease(self):
-#        self.setBackground(self.bcolor)
-#        widget.onClickRelease(self)
\ No newline at end of file
+        pygame.draw.rect(self.img, color, Rect(bsize, bsize, size[0]-2*bsize, size[1]-2*bsize))
\ No newline at end of file

Added: trunk/pgui/button.py
===================================================================
--- trunk/pgui/button.py	                        (rev 0)
+++ trunk/pgui/button.py	2008-03-03 05:59:01 UTC (rev 41)
@@ -0,0 +1,81 @@
+from widget import *
+from container import *
+from label import *
+
+from pygame.locals import *
+import pygame
+import os
+
+
+from box import *
+from label import *
+
+images_dir = os.path.join( "img" )
+
+
+class button (widget):
+
+    def __init__(self, father, position, size, img):
+        # Widget creating
+        widget.__init__(self, father, position, size, img)
+        
+
+
+class Tbutton (container):
+    
+    def __init__(self, father, position, text = '', ptsize = 30, 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.color = color
+        self.bgcolor = bgcolor
+        
+        # creating the label
+        lbl = label(self, [2,5], text, color, ptsize = ptsize)
+        self.label = lbl
+        
+        # Y_size
+        if height == None:
+            height = self.label.size[1] + bsize*2 + padding*2
+            
+        # X_size
+        if width == None:
+            width = self.label.size[0] + bsize*2 + padding*2
+        
+        # creating the box
+        self.box = box(self,[0,0],(width,height),bgcolor,bsize,(150,150,150))
+        
+        #puting the label into the box image
+        container.__init__(self, father,[self.box,self.label],position,self.box.size)
+        
+    def onMouseOn(self):
+        container.onMouseOn(self)
+        self.box.setBackground((255,100,100))
+        
+    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):
+        """
+
+        @param string img_local : Endereco da imagem
+        @return  :
+        @author
+        """        
+        
+        path  = os.path.join( images_dir, image_file )
+        img   = pygame.image.load( path )
+        size  = img.get_size()
+        
+        button.__init__(self, father, position, size, img)
+

Modified: trunk/pgui/container.py
===================================================================
--- trunk/pgui/container.py	2008-03-03 01:09:02 UTC (rev 40)
+++ trunk/pgui/container.py	2008-03-03 05:59:01 UTC (rev 41)
@@ -10,6 +10,9 @@
 class container (pguiobject):
     
     def __init__(self, father, elementList = [], position = [0,0], size = [800,420] ):
+        
+        if father != None:
+            self.screen = father.screen
 
         pguiobject.__init__(self, father, position, size)
             
@@ -35,20 +38,20 @@
         self.objectsReverted.remove(obj)
         
         
-    def draw(self, screen):
+    def draw(self, screen, force = False):
         """
             Simple draw of the screen
             and draw the elements
         """
 
-        if self.dirty:
+        if self.dirty or force:
             # if we paint the window
             # we need to pain all the widgets of this window too 
             #self.draw(self.screen)
 
             pguiobject.drawBackground(self, screen)
             for obj in self.objects:
-                    obj.draw(self.screen)
+                    obj.draw(self.screen, True)
             self.dirty = False        
 
         else:

Modified: trunk/pgui/input.py
===================================================================
--- trunk/pgui/input.py	2008-03-03 01:09:02 UTC (rev 40)
+++ trunk/pgui/input.py	2008-03-03 05:59:01 UTC (rev 41)
@@ -5,7 +5,7 @@
 class input (container):
 
 
-    def __init__(self, father, position, text = '', ptsize = 30, width = 300, height = None, bsize = 1):
+    def __init__(self, father, position, text = '', ptsize = 40, width = 300, height = None, bsize = 1):
         """
 
         @param string text : default text
@@ -21,25 +21,26 @@
         self.screen = father.screen
 
         # label
-        lbl = label(self, [2,2], text, (50,50,50))
+        lbl = label(self, [2,5], text, (50,50,50), ptsize = ptsize)
         self.label = lbl
+        self.label.cutImg(width - 4)
         
         if height == None:
             height = lbl.size[1]+10
         
-        self.input = box(self,[0,0],(width,height),(255,255,255),1,(100,100,100))
+        self.input = box(self,[0,0],(width,height),(255,255,255),bsize,(150,150,150))
         
         container.__init__(self, father,[self.input,self.label],position,self.input.size)
         
-        pass
+       
     
     def click(self):
-        
-        import virtkeyboard
-        mykb = virtkeyboard.VirtualKeyboard()
-        text = mykb.run(self.father.screen, self.text)
-        
-        self.modify(text) 
+        if self.mouseOn:
+            import virtkeyboard
+            mykb = virtkeyboard.VirtualKeyboard()
+            text = mykb.run(self.father.screen, self.text)
+            
+            self.modify(text)
 
     
     def modify(self, text):
@@ -47,10 +48,19 @@
             This function modifies the text of a input
         """
         self.text = text
+        self.label.position = self.label.rel_pos
         self.label.modify(text)
+        
+        
+        # Cuting the image
+        self.label.cutImg(self.size[0] - 4)
         self.dirty = True
         pass
+    
+    def onMouseOn(self):
+        self.input.setBackground((200,100,100))
+        container.onMouseOn(self)
         
-        
-        
-    
\ No newline at end of file
+    def onMouseOff(self):
+        self.input.setBackground(self.input.bgcolor)
+        container.onMouseOff(self)
\ No newline at end of file

Modified: trunk/pgui/pguiobject.py
===================================================================
--- trunk/pgui/pguiobject.py	2008-03-03 01:09:02 UTC (rev 40)
+++ trunk/pgui/pguiobject.py	2008-03-03 05:59:01 UTC (rev 41)
@@ -49,7 +49,7 @@
             self.dirty = True
     
     
-    def draw(self, screen):
+    def draw(self, screen, force):
         """
          Desenha o objeto na tela
 
@@ -91,6 +91,9 @@
         self.onMouseOn()
  
     def onClickRelease(self):
+        if self.mouseOn:
+            self.click()
+            
         self.mouseOn = False
         self.clicked = False
         self.onMouseOff()

Modified: trunk/pgui/widget.py
===================================================================
--- trunk/pgui/widget.py	2008-03-03 01:09:02 UTC (rev 40)
+++ trunk/pgui/widget.py	2008-03-03 05:59:01 UTC (rev 41)
@@ -33,11 +33,11 @@
         del(self.size)
         del(self.img)
         
-    def draw(self, screen):
+    def draw(self, screen, force = False):
         
         # Verifing if the image really needs to be painted
         if self.rect.colliderect(Rect(0,0,800,480)):
-            pguiobject.draw(self, screen)
+            pguiobject.draw(self, screen, force)
         
     def move(self, pos):
         if pos[0] != pos[1] or pos[1] != 0:
@@ -45,7 +45,15 @@
             self.rect  =  Rect(self.position,self.img.get_size())
             self.father.dirty = True
             
-    def buildImg(self):
-        if self.background != None:
-            pass
-        
\ No newline at end of file
+    def cutImg(self, width = -1, height = -1):
+        
+        if width < 0:
+            width = self.size[0]
+        if height < 0:
+            height = self.size[1]
+        
+        img = Surface((width,height), pygame.SRCALPHA,32)
+        img.blit(self.img,[0,0])
+        self.img = img
+        self.size = self.img.get_size()
+        self.rect  =  Rect(self.position,self.size)
\ No newline at end of file

Modified: trunk/pgui/window.py
===================================================================
--- trunk/pgui/window.py	2008-03-03 01:09:02 UTC (rev 40)
+++ trunk/pgui/window.py	2008-03-03 05:59:01 UTC (rev 41)
@@ -85,7 +85,6 @@
     def sendClick(self):
         
         if self.objPressed != None:
-            self.objPressed.click()
             self.objPressed.onClickRelease()
             self.objPressed = None
             

Modified: trunk/pychord2/main_window.py
===================================================================
--- trunk/pychord2/main_window.py	2008-03-03 01:09:02 UTC (rev 40)
+++ trunk/pychord2/main_window.py	2008-03-03 05:59:01 UTC (rev 41)
@@ -4,6 +4,8 @@
 from pgui import label
 from pgui import input
 from pgui import locale
+from pgui import Tbutton
+from pgui import Ibutton
 
 
 import pygame
@@ -39,16 +41,18 @@
 
         """
         window.__init__(self, None, screen )
-        self.setBackground((200,200,200))
+        self.setBackground((0,0,0))
         
-        bx = box(self,[8,8],(100,90),(100,100,100),10)
-        self.addElement(bx)
+        btX = Ibutton(self,[730,10],"x.png")
+        btX.click = self.close
+        self.addElement(btX)
         
-        lbl = label(self, [20,20],"Danilo Cesar",(255,0,0))
+        lbl = label(self, [10,70],"Search By:")
         self.addElement(lbl)
         
-        inp = input(self, [50,50],"Primeiro INPUT")
+        inp = input(self, [10, 110],"",width=700)
         self.addElement(inp)
         
-        bx = box(self,[200,8],(150,40),(100,100,100),10)
-        self.addElement(bx)
+        
+        lbl = label(self, [10,200],"Search on:")
+        self.addElement(lbl)



More information about the Pychord-commits mailing list