[Pychord-commits] r39 - in trunk: pgui pychord2
danilo at garage.maemo.org
danilo at garage.maemo.org
Sun Mar 2 20:05:26 EET 2008
Author: danilo
Date: 2008-03-02 20:05:24 +0200 (Sun, 02 Mar 2008)
New Revision: 39
Modified:
trunk/pgui/box.py
trunk/pgui/container.py
trunk/pgui/pguiobject.py
trunk/pgui/widget.py
trunk/pgui/window.py
trunk/pychord2/main_window.py
Log:
Background working
Modified: trunk/pgui/box.py
===================================================================
--- trunk/pgui/box.py 2008-03-02 16:31:03 UTC (rev 38)
+++ trunk/pgui/box.py 2008-03-02 18:05:24 UTC (rev 39)
@@ -11,20 +11,31 @@
# 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 = (200,200,200)):
+ def __init__(self, father, position, size, color, bsize = 0, bcolor = (255,255,255)):
- img = pygame.Surface(size)
+ # Creating a new widget
+ widget.__init__(self, father, position, size)
+ self.color = color
+ self.size = size
+ self.bcolor = bcolor
+
if bsize > 0:
- img.fill(bcolor)
+ self.setBackground(bcolor)
+
+ pygame.draw.rect(self.img, color, Rect(bsize, bsize, size[0]-2*bsize, size[1]-2*bsize))
- pygame.draw.rect(img, color, Rect(bsize, bsize, size[0]-2*bsize, size[1]-2*bsize))
- # Creating a new widget
- widget.__init__(self, father, position, size, img)
def update(self):
- if self.clicked:
-
+ if self.clicked:
pos = pygame.mouse.get_rel()
self.move(pos)
+
+ def onClick(self):
+ self.setBackground((0,0,0))
+ widget.onClick(self)
+
+ def onClickRelease(self):
+ self.setBackground(self.bcolor)
+ widget.onClickRelease(self)
\ No newline at end of file
Modified: trunk/pgui/container.py
===================================================================
--- trunk/pgui/container.py 2008-03-02 16:31:03 UTC (rev 38)
+++ trunk/pgui/container.py 2008-03-02 18:05:24 UTC (rev 39)
@@ -73,7 +73,6 @@
for obj in self.objects:
# For widgets
if obj.rect.collidepoint(pygame.mouse.get_pos()):
- obj.mouseOn = True
- obj.clicked = True
+ obj.onClick()
self.objPressed = obj
return
\ No newline at end of file
Modified: trunk/pgui/pguiobject.py
===================================================================
--- trunk/pgui/pguiobject.py 2008-03-02 16:31:03 UTC (rev 38)
+++ trunk/pgui/pguiobject.py 2008-03-02 18:05:24 UTC (rev 39)
@@ -38,15 +38,28 @@
if flag == pguiColor:
self.background = Surface(self.size)
- pygame.draw.rect(self.background, bg, self.rect)
+ self.background.fill(bg)
self.dirty = True
+
+
+ def draw(self, screen):
+ """
+ Desenha o objeto na tela
+
+ @return :
+ @author
+ """
+
+ self.drawBackground(screen)
+ screen.blit(self.img, self.position)
+ self.dirty = False
+
+
def drawBackground(self, screen):
-
-
+
if self.background != None:
- print "Imprimindo background"
screen.blit(self.background, self.position)
self.dirty = True
@@ -61,14 +74,21 @@
self.onMouseOff()
def onMouseOn(self):
- print self,"pnMouseON"
pass
def onMouseOff(self):
- print self,"onMouseOFF"
pass
-
+ def onClick(self):
+ self.mouseOn = True
+ self.clicked = True
+ self.onMouseOn()
+
+ def onClickRelease(self):
+ self.mouseOn = False
+ self.clicked = False
+ self.onMouseOff()
+
def update(self):
pass
Modified: trunk/pgui/widget.py
===================================================================
--- trunk/pgui/widget.py 2008-03-02 16:31:03 UTC (rev 38)
+++ trunk/pgui/widget.py 2008-03-02 18:05:24 UTC (rev 39)
@@ -22,7 +22,7 @@
# We need to do this verification, because a father widget can
# create a image before call widget.__init__
if img == None:
- img = Surface(size)
+ img = Surface(size,pygame.SRCALPHA)
self.img = img
# Image's rectangle
@@ -32,28 +32,20 @@
del(self.rel_pos)
del(self.size)
del(self.img)
-
-
+
def draw(self, screen):
- """
- Desenha o objeto na tela
-
- @return :
- @author
- """
- # Verifing if the image realy need to be painted
- if self.position[1] < 420 and self.position[1] > 0:
-
- screen.blit(self.img, self.position)
+ # Verifing if the image really needs to be painted
+ if self.rect.colliderect(Rect(0,0,800,480)):
+ pguiobject.draw(self, screen)
- self.dirty = False
-
def move(self, pos):
if pos[0] != pos[1] or pos[1] != 0:
- print "position.old",self.position,"Rect.old",self.rect
self.position = (self.position[0] + pos[0], self.position[1] + pos[1])
self.rect = Rect(self.position,self.img.get_size())
- print "position.new",self.position,"Rect.new",self.rect
self.father.dirty = True
+
+ def buildImg(self):
+ if self.background != None:
+ pass
\ No newline at end of file
Modified: trunk/pgui/window.py
===================================================================
--- trunk/pgui/window.py 2008-03-02 16:31:03 UTC (rev 38)
+++ trunk/pgui/window.py 2008-03-02 18:05:24 UTC (rev 39)
@@ -14,7 +14,7 @@
:author:
"""
- def __init__(self, father, screen, elementList = [], position = [0,0], size = [800,420] ):
+ def __init__(self, father, screen, elementList = [], position = [0,0], size = [800,480] ):
# SuperClass initialization
container.__init__(self, father, elementList, position, size)
@@ -86,8 +86,7 @@
if self.objPressed != None:
self.objPressed.click()
- self.objPressed.mouseOn = False
- self.objPressed.clicked = False
+ self.objPressed.onClickRelease()
self.objPressed = None
Modified: trunk/pychord2/main_window.py
===================================================================
--- trunk/pychord2/main_window.py 2008-03-02 16:31:03 UTC (rev 38)
+++ trunk/pychord2/main_window.py 2008-03-02 18:05:24 UTC (rev 39)
@@ -1,5 +1,7 @@
# -*- coding: utf-8 -*-
-from pgui import *
+from pgui import window
+from pgui import box
+from pgui import locale
import pygame
@@ -7,7 +9,7 @@
from pygame.locals import *
-class main_window( pyw_window ):
+class main_window( window ):
# Another stuff
clicking = False
@@ -34,19 +36,11 @@
btS = pywibuttonI([537,160],"search.png")
"""
- pyw_window.__init__(self, screen )
- box = pyw_label(self, [10,10], 'Name:')
+ window.__init__(self, None, screen )
+ self.setBackground((200,200,200))
- box2 = pyw_input(self, [10,30], text = 'Danilo Cesar Lemes de Paula')
+ bx = box(self,[8,8],(50,50),(100,100,100),10)
+ self.addElement(bx)
- box3 = pyw_Tbutton(self, [10,60], 'Search', width = 200)
- box3.click = self.box3_onclick
-
- self.addobj(box)
- self.addobj(box2)
- self.addobj(box3)
-
- def box3_onclick(self):
- w = pyw_window_dialog(self.screen, u"Are you shure about your name?")
- w.show()
- self.repaint()
\ No newline at end of file
+ #bx = box(self,[50,20],(50,50),(100,100,100),10)
+ #self.addElement(bx)
\ No newline at end of file
More information about the Pychord-commits
mailing list