Ejemplo n.º 1
0
    def main(self):
        from Kamaelia.UI.Pygame.Display import PygameDisplay
        from Kamaelia.UI.Pygame.MagnaDoodle import MagnaDoodle

        X=PygameDisplay(width=200,height=200).activate()
        PygameDisplay.setDisplayService(X)
        MagnaDoodle().run()
Ejemplo n.º 2
0
    def RateLimitedPlayback(frame):
        fps = frame["frame_rate"]
        x,y = tuple(frame["size"])
        print "Frames per second:",fps
        print "(width,height):",(x,y)
        
        pgd = PygameDisplay(width=x,height=y).activate()
        PygameDisplay.setDisplayService(pgd)

        return Graphline( \
            LIMIT = PromptedTurnstile(),
            RATE  = ByteRate_RequestControl(rate=fps, chunksize=1.0, allowchunkaggregation=False),
            PLAY  = player,
            linkages = {
                ("",      "inbox" ) : ("LIMIT", "inbox"),
                ("LIMIT", "outbox") : ("PLAY",  "inbox"),
                ("PLAY",  "outbox") : ("",      "outbox"),
                
                ("RATE", "outbox" ) : ("LIMIT", "next"),

                ("",      "control") : ("RATE",  "control"),
                ("RATE",  "signal" ) : ("LIMIT", "control"),
                ("LIMIT", "signal" ) : ("PLAY",  "control"),
                ("PLAY",  "signal" ) : ("",      "signal"),
            },
            boxsizes = {
                ("LIMIT","inbox") : 2,
            },
        )
Ejemplo n.º 3
0
    def RateLimitedPlayback(frame):
        fps = frame["frame_rate"]
        x, y = tuple(frame["size"])
        print "Frames per second:", fps
        print "(width,height):", (x, y)

        pgd = PygameDisplay(width=x, height=y).activate()
        PygameDisplay.setDisplayService(pgd)

        return Graphline( \
            LIMIT = PromptedTurnstile(),
            RATE  = ByteRate_RequestControl(rate=fps, chunksize=1.0, allowchunkaggregation=False),
            PLAY  = player,
            linkages = {
                ("",      "inbox" ) : ("LIMIT", "inbox"),
                ("LIMIT", "outbox") : ("PLAY",  "inbox"),
                ("PLAY",  "outbox") : ("",      "outbox"),

                ("RATE", "outbox" ) : ("LIMIT", "next"),

                ("",      "control") : ("RATE",  "control"),
                ("RATE",  "signal" ) : ("LIMIT", "control"),
                ("LIMIT", "signal" ) : ("PLAY",  "control"),
                ("PLAY",  "signal" ) : ("",      "signal"),
            },
            boxsizes = {
                ("LIMIT","inbox") : 2,
            },
        )
Ejemplo n.º 4
0
    def main(self):
        from Kamaelia.UI.Pygame.Display import PygameDisplay
        from Kamaelia.UI.Pygame.MagnaDoodle import MagnaDoodle

        X = PygameDisplay(width=200, height=200).activate()
        PygameDisplay.setDisplayService(X)
        MagnaDoodle().run()
Ejemplo n.º 5
0
 def getDisplay(self):
     displayservice = PygameDisplay.getDisplayService()
     self.link((self, "display_signal"), displayservice)
     self.send(self.disprequest, "display_signal")
     while not self.dataReady("callback"):
         self.pause()
         yield 1
     self.display = self.recv("callback")
Ejemplo n.º 6
0
 def getDisplay(self):
     displayservice = PygameDisplay.getDisplayService()
     self.link((self, "display_signal"), displayservice)
     self.send(self.disprequest, "display_signal")
     while not self.dataReady("callback"):
         self.pause()
         yield 1
     self.display = self.recv("callback")
Ejemplo n.º 7
0
 def __init__(self):
     super(dummy, self).__init__()
     width = 400
     height = 200
     displayservice = PygameDisplay.getDisplayService()
     disprequest = {"DISPLAYREQUEST" : True,
                    "size" : (width,height),               # pixels size for the new surface
                    "callback" : (self, "inbox"),  # to send the new surface object to
                    "events" : (self, "events")
     }
     self.link((self, 'outbox'), displayservice)
     self.send(disprequest, 'outbox')
Ejemplo n.º 8
0
    def main(self):
        """Main loop."""
        displayservice = PygameDisplay.getDisplayService()
        self.link((self,"display_signal"), displayservice)
        self.send( self.dispRequest,
                    "display_signal")
        for _ in self.waitBox("callback"): yield 1
        self.display = self.recv("callback")
        
        # tool buttons
        circleb = ImageButton(caption=(os.path.join('icons', 'EllipseToolIcon.png')),position=(10,10), bgcolour = (235,235,235), msg = (("Tool", "Circle"),)).activate()
        eraseb = ImageButton(caption=(os.path.join('icons', 'EraserToolIcon.png')),position=(100,10), bgcolour = (235,235,235), msg = (("Tool", "Eraser"),)).activate()
        lineb = ImageButton(caption=(os.path.join('icons', 'PaintBrushToolIcon.png')),position=(10,50), bgcolour = (235,235,235), msg = (("Tool", "Line"),)).activate()
        bucketb = ImageButton(caption=(os.path.join('icons', 'PaintBucketIcon.png')),position=(10,90), bgcolour = (235,235,235), msg = (("Tool", "Bucket"),)).activate()
        eyeb = ImageButton(caption=(os.path.join('icons', 'ColorPickerToolIcon.png')),position=(10,130), bgcolour = (235,235,235), msg = (("Tool", "Eyedropper"),)).activate()
        addlayerb = ImageButton(caption=(os.path.join('icons', 'PlusButtonIcon.png')),position=(10,540), bgcolour = (235,235,235), msg = (("Layer", "Add"),)).activate()
        prevlayerb = ImageButton(caption=(os.path.join('icons', 'MenuLayersMoveLayerDownIcon.png')),position=(80,540), bgcolour = (235,235,235), msg = (("Layer", "Prev"),)).activate()
        nextlayerb = ImageButton(caption=(os.path.join('icons', 'MenuLayersMoveLayerUpIcon.png')),position=(110,540), bgcolour = (235,235,235), msg = (("Layer", "Next"),)).activate()
        dellayerb = ImageButton(caption=(os.path.join('icons', 'MinusButtonIcon.png')),position=(35,540), bgcolour = (235,235,235), msg = (("Layer", "Delete"),)).activate()
        saveb = ImageButton(caption=(os.path.join('icons', 'MenuFileSaveIcon.png')),position=(100,130), bgcolour = (235,235,235), msg = (("Save", "Test"),)).activate()
        self.link( (circleb,"outbox"), (self,"outbox"), passthrough = 2 )
        self.link( (eraseb,"outbox"), (self,"outbox"), passthrough = 2 )
        self.link( (lineb,"outbox"), (self,"outbox"), passthrough = 2 )
        self.link( (bucketb,"outbox"), (self,"outbox"), passthrough = 2 )
        self.link( (eyeb,"outbox"), (self,"outbox"), passthrough = 2 )
        self.link( (addlayerb,"outbox"), (self,"outbox"), passthrough = 2 )
        self.link( (prevlayerb,"outbox"), (self,"outbox"), passthrough = 2 )
        self.link( (nextlayerb,"outbox"), (self,"outbox"), passthrough = 2 )
        self.link( (dellayerb,"outbox"), (self,"outbox"), passthrough = 2 )
        self.link( (saveb,"outbox"), (self,"outbox"), passthrough = 2 )
        colSel = ColourSelector(position = (10,170), size = (255,255)).activate()
        self.link( (colSel,"outbox"), (self,"outbox"), passthrough = 2 )
        SizeSlider = Slider(size=(255, 50), messagePrefix = "Size", position = (10, 460), default = 9).activate()
        self.link( (SizeSlider,"outbox"), (self,"outbox"), passthrough = 2 )
        AlphaSlider = Slider(size=(255, 10), messagePrefix = "Alpha", position = (10, 515), default = 255).activate()
        self.link( (AlphaSlider,"outbox"), (self,"outbox"), passthrough = 2 )

        
        
        self.drawBG()
        done = False
        while not done:
            if not self.anyReady():
                self.pause()
            yield 1
Ejemplo n.º 9
0
    def initPygame(self, **argd):
        displayservice = PygameDisplay.getDisplayService()
        self.link((self, "_pygame"), displayservice)
        self.send(argd, "_pygame")
        while not self.dataReady("_surface"):
            yield 1
        self.screen = self.recv("_surface")
        self.screen.fill(self.background_color)
        self.scratch = self.screen.copy()
        self.send({"REDRAW": True, "surface": self.screen}, "_pygame")
        yield 1

        h = self.screen_height
        w = self.screen_width
        th = self.text_height
        self.font = pygame.font.Font(None, th)
        self.linelen = w / self.font.size('a')[0]
        self.keepRect = pygame.Rect((0, th), (w, h - th))
        self.scrollingRect = pygame.Rect((0, 0), (w, h - th))
        self.writeRect = pygame.Rect((0, h - th), (w, th))
Ejemplo n.º 10
0
    def initPygame(self, **argd):
        """requests a display surface from the PygameDisplay service, fills
        the color in, and copies it"""
        displayservice = PygameDisplay.getDisplayService()
        self.link((self, "_pygame"), displayservice)
        if self.transparent:
            argd["transparency"] = self.bgcolour
        self.send(argd, "_pygame")
        while not self.dataReady("_surface"):
            yield 1
        self.screen = self.recv("_surface")
        self.clear()

        self.scratch = self.screen.copy()
        self.send({"REDRAW": True, "surface": self.screen}, "_pygame")
        yield 1

        h = self.screen_height
        w = self.screen_width
        th = self.text_height  # Text height

        self.font = pygame.font.Font(self.font_file, th)
        th = (
            self.text_height
        ) = self.font.get_linesize()  # Adjust the rendering of text inside, such that it renders nicer

        self.linelen = w / self.font.size("a")[0]

        # First pass approach at adding basic padding into the model
        pad = self.padding

        padtop = self.padding
        padbottom = self.padding
        padleft = self.padding
        padright = self.padding

        self.keepRect = pygame.Rect((0 + padleft, th + padtop), (w - padleft - padright, h - th - padtop - padbottom))
        self.scrollingRect = pygame.Rect(
            (0 + padleft, 0 + padtop), (w - padleft - padright, h - th - padtop - padbottom)
        )
        self.writeRect = pygame.Rect((0 + padleft, h - th - padbottom), (w - pad - pad, th))
Ejemplo n.º 11
0
    def initPygame(self, **argd):
        displayservice = PygameDisplay.getDisplayService()
        self.link((self, "_pygame"), displayservice)
        self.send(argd, "_pygame")
        while not self.dataReady("_surface"):
            yield 1
        self.screen = self.recv("_surface")
        self.screen.fill(self.background_color)
        self.scratch = self.screen.copy()
        self.send({"REDRAW" : True,
                   "surface" : self.screen}, "_pygame")
        yield 1

        h = self.screen_height
        w = self.screen_width
        th = self.text_height
        self.font = pygame.font.Font(None, th)
        self.linelen = w/self.font.size('a')[0]
        self.keepRect = pygame.Rect((0, th),(w, h - th))
        self.scrollingRect = pygame.Rect((0, 0), (w, h - th))
        self.writeRect = pygame.Rect((0, h - th), (w, th))
Ejemplo n.º 12
0
    def main(self):
        """Main loop."""
        displayservice = PygameDisplay.getDisplayService()
        self.link((self, "display_signal"), displayservice)
        self.send(self.dispRequest, "display_signal")
        for _ in self.waitBox("callback"):
            yield 1
        self.display = self.recv("callback")

        # tool buttons
        circleb = Button(caption="Circle", position=(10, 10), msg=(("Tool", "Circle"),)).activate()
        eraseb = Button(caption="Eraser", position=(100, 10), msg=(("Tool", "Eraser"),)).activate()
        lineb = Button(caption="Line", position=(10, 50), msg=(("Tool", "Line"),)).activate()
        bucketb = Button(caption="Bucket", position=(10, 90), msg=(("Tool", "Bucket"),)).activate()
        eyeb = Button(caption="Eyedropper", position=(10, 130), msg=(("Tool", "Eyedropper"),)).activate()
        addlayerb = Button(caption="Add Layer", position=(10, 540), msg=(("Layer", "Add"),)).activate()
        prevlayerb = Button(caption="<-", position=(80, 540), msg=(("Layer", "Prev"),)).activate()
        nextlayerb = Button(caption="->", position=(110, 540), msg=(("Layer", "Next"),)).activate()
        dellayerb = Button(caption="Delete", position=(140, 540), msg=(("Layer", "Delete"),)).activate()
        self.link((circleb, "outbox"), (self, "outbox"), passthrough=2)
        self.link((eraseb, "outbox"), (self, "outbox"), passthrough=2)
        self.link((lineb, "outbox"), (self, "outbox"), passthrough=2)
        self.link((bucketb, "outbox"), (self, "outbox"), passthrough=2)
        self.link((eyeb, "outbox"), (self, "outbox"), passthrough=2)
        self.link((addlayerb, "outbox"), (self, "outbox"), passthrough=2)
        self.link((prevlayerb, "outbox"), (self, "outbox"), passthrough=2)
        self.link((nextlayerb, "outbox"), (self, "outbox"), passthrough=2)
        self.link((dellayerb, "outbox"), (self, "outbox"), passthrough=2)
        colSel = ColourSelector(position=(10, 170), size=(255, 255)).activate()
        self.link((colSel, "outbox"), (self, "outbox"), passthrough=2)
        SizeSlider = Slider(size=(255, 50), messagePrefix="Size", position=(10, 460), default=9).activate()
        self.link((SizeSlider, "outbox"), (self, "outbox"), passthrough=2)
        AlphaSlider = Slider(size=(255, 10), messagePrefix="Alpha", position=(10, 515), default=255).activate()
        self.link((AlphaSlider, "outbox"), (self, "outbox"), passthrough=2)
        self.drawBG()
        done = False
        while not done:
            if not self.anyReady():
                self.pause()
            yield 1
Ejemplo n.º 13
0
    def initPygame(self, **argd):
        """requests a display surface from the PygameDisplay service, fills
        the color in, and copies it"""
        displayservice = PygameDisplay.getDisplayService()
        self.link((self, "_pygame"), displayservice)
        if self.transparent:
            argd["transparency"] = self.bgcolour
        self.send(argd, "_pygame")
        while not self.dataReady("_surface"):
            yield 1
        self.screen = self.recv("_surface")
        self.clear()

        self.scratch = self.screen.copy()
        self.send({"REDRAW" : True,
                   "surface" : self.screen}, "_pygame")
        yield 1

        h = self.screen_height
        w = self.screen_width
        th = self.text_height                                     # Text height

        self.font = pygame.font.Font(self.font_file, th)
        th = self.text_height = self.font.get_linesize() # Adjust the rendering of text inside, such that it renders nicer

        self.linelen = w/self.font.size('a')[0]

        # First pass approach at adding basic padding into the model
        pad = self.padding

        padtop = self.padding
        padbottom = self.padding
        padleft = self.padding
        padright = self.padding
        
        self.keepRect      = pygame.Rect((0+padleft, th+padtop),(w - padleft - padright, h - th - padtop - padbottom))
        self.scrollingRect = pygame.Rect((0+padleft, 0+padtop), (w - padleft - padright, h - th - padtop - padbottom))
        self.writeRect     = pygame.Rect((0+padleft, h - th - padbottom), (w - pad - pad, th))
Ejemplo n.º 14
0
                          ("ANALYSE", "drawing")  : ("self", "drawing"),
                        }
                    )



if __name__ == "__main__":

    from Kamaelia.UI.Pygame.Display import PygameDisplay
    from Kamaelia.Util.Console import ConsoleEchoer

    width = 1024
    height = 384

    pgd = PygameDisplay( width=width, height=height ).activate()
    PygameDisplay.setDisplayService(pgd)
    
    Graphline( CANVAS  = Canvas( position=(0,0),size=(width,height) ),
               PEN     = Pen(),
               STROKER = StrokeRecogniser(),
               OUTPUT  = ConsoleEchoer(),
        
               linkages = {
                   ("CANVAS",  "eventsOut") : ("PEN", "inbox"),
                   ("PEN", "outbox")        : ("CANVAS", "inbox"),
                   ("PEN", "points")        : ("STROKER", "inbox"),
                   ("STROKER", "outbox")    : ("OUTPUT", "inbox"),
                   ("STROKER", "drawing")   : ("CANVAS", "inbox"),
                   },
            ).run()
    
Ejemplo n.º 15
0
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

import pygame
from Kamaelia.UI.Pygame.Display import PygameDisplay
from Kamaelia.Chassis.Graphline import Graphline
from Kamaelia.Util.Console import ConsoleEchoer
from Kamaelia.UI.Pygame.KeyEvent import KeyEvent
from pygame.locals import *

width = 400
height = 200

displayservice = PygameDisplay.getDisplayService()
g = Graphline(displayservice=displayservice,
              linkages={
                  ("self", "outbox"): displayservice,
              })

disprequest = {
    "DISPLAYREQUEST": True,
    "size": (width, height),  # pixels size for the new surface
    "callback": (g, "inbox"),  # to send the new surface object to
    "events": (g, "events")
}
Ejemplo n.º 16
0
    def main(self):
        """Main loop."""
        displayservice = PygameDisplay.getDisplayService()
        self.link((self,"display_signal"), displayservice)

        self.send( self.dispRequest,
                    "display_signal")

        for _ in self.waitBox("callback"): yield 1
        self.display = self.recv("callback")
        
        


        # Initial render so we don't see a blank screen
        self.sliderPos = self.default
        self.drawBG()
        self.render()

        self.send({"ADDLISTENEVENT" : pygame.MOUSEBUTTONDOWN,
                    "surface" : self.display},
                    "display_signal")

        self.send({"ADDLISTENEVENT" : pygame.MOUSEBUTTONUP,
                    "surface" : self.display},
                    "display_signal")

        self.send({"ADDLISTENEVENT" : pygame.MOUSEMOTION,
                    "surface" : self.display},
                    "display_signal")
        done = False
        while not done:
            if not self.anyReady():
                self.pause()
            yield 1
            while self.dataReady("control"):
                cmsg = self.recv("control")
                if (isinstance(cmsg, producerFinished)):
                    self.send(cmsg, "signal")
                    done = True
            while self.dataReady("colours"):
                msg = self.recv("colours")
                if msg[0] == "ColourCombi":
                    self.colourCombi = msg[1]
                else: 
                    if self.colourCombi == 'RG':
                        self.selectedColour = (msg[1][0],msg[1][1],self.sliderPos)
                    elif self.colourCombi == 'RB':
                        self.selectedColour = (msg[1][0],self.sliderPos,msg[1][2])
                    elif self.colourCombi == 'GB':
                        self.selectedColour = (self.sliderPos,msg[1][1],msg[1][2])
                    self.bgcolour = self.selectedColour
            #        self.display.fill( self.selectedColour)
                self.drawBG()
                self.render()
            while self.dataReady("inbox"):
                for event in self.recv("inbox"):
                    if event.type == pygame.MOUSEBUTTONDOWN:
                        if self.display.get_rect().collidepoint(*event.pos):
                            if self.vertical:
                                self.sliderPos = event.pos[1]
                            else:
                                self.sliderPos = event.pos[0]
                            self.drawBG()
                            self.render()
                            self.mouseDown = True

                    if event.type == pygame.MOUSEBUTTONUP:
                        if self.mouseDown:
                            if self.vertical:
                                self.sliderPos = event.pos[1]
                            else:
                                self.sliderPos = event.pos[0]
                            self.drawBG()
                            self.render()
                        self.mouseDown = False
                    
                    if event.type == pygame.MOUSEMOTION and self.mouseDown:
                        if self.display.get_rect().collidepoint(*event.pos):
                            if self.vertical:
                                self.sliderPos = event.pos[1]
                            else:
                                self.sliderPos = event.pos[0]
                            self.drawBG()
                            self.render()
                        else: self.mouseDown = False
Ejemplo n.º 17
0
#!/usr/bin/python

from Kamaelia.UI.Pygame.Display import PygameDisplay
from Kamaelia.Chassis.Pipeline import Pipeline
from Kamaelia.Util.Console import ConsoleEchoer
from Kamaelia.UI.Pygame.Text import Textbox, TextDisplayer

X = PygameDisplay(background_colour=(224, 224, 255), width=1000,
                  height=400).activate()
PygameDisplay.setDisplayService(X)

Pipeline(
    Textbox(size=(800, 150),
            position=(100, 230),
            font_file="/home/michaels/.fonts/MichaelHW.ttf",
            padding=20,
            border_size=10,
            border_colour=(128, 0, 0)),
    TextDisplayer(size=(800, 150),
                  position=(100, 40),
                  font_file="/home/michaels/.fonts/GillSans.ttf",
                  padding=20,
                  border_size=10,
                  border_colour=(0, 0, 128))).run()
Ejemplo n.º 18
0
#!/usr/bin/python

from Kamaelia.UI.Pygame.Display import PygameDisplay
from Kamaelia.Chassis.Pipeline import Pipeline
from Kamaelia.Util.Console import ConsoleEchoer
from Kamaelia.UI.Pygame.Text import Textbox, TextDisplayer

X = PygameDisplay(background_colour=(224,224,255),width=1000,height=400).activate()
PygameDisplay.setDisplayService(X)

Pipeline(
         Textbox(size = (800, 150), position = (100,230),      font_file="/home/michaels/.fonts/MichaelHW.ttf",padding=20, border_size=10, border_colour=(128,0,0)),
         TextDisplayer(size = (800, 150), position = (100,40), font_file="/home/michaels/.fonts/GillSans.ttf", padding=20, border_size=10, border_colour=(0,0,128))
).run()
                 
                  
Ejemplo n.º 19
0
    def main(self):
        """Main loop."""
        displayservice = PygameDisplay.getDisplayService()
        self.link((self, "display_signal"), displayservice)

        self.send(self.dispRequest, "display_signal")

        for _ in self.waitBox("callback"):
            yield 1
        self.display = self.recv("callback")

        # Initial render so we don't see a blank screen
        self.sliderPos = self.default
        self.drawBG()
        self.render()

        self.send(
            {
                "ADDLISTENEVENT": pygame.MOUSEBUTTONDOWN,
                "surface": self.display
            }, "display_signal")

        self.send(
            {
                "ADDLISTENEVENT": pygame.MOUSEBUTTONUP,
                "surface": self.display
            }, "display_signal")

        self.send(
            {
                "ADDLISTENEVENT": pygame.MOUSEMOTION,
                "surface": self.display
            }, "display_signal")
        done = False
        while not done:
            if not self.anyReady():
                self.pause()
            yield 1
            while self.dataReady("control"):
                cmsg = self.recv("control")
                if (isinstance(cmsg, producerFinished)):
                    self.send(cmsg, "signal")
                    done = True
            while self.dataReady("colours"):
                msg = self.recv("colours")
                if msg[0] == "ColourCombi":
                    self.colourCombi = msg[1]
                else:
                    if self.colourCombi == 'RG':
                        self.selectedColour = (msg[1][0], msg[1][1],
                                               self.sliderPos)
                    elif self.colourCombi == 'RB':
                        self.selectedColour = (msg[1][0], self.sliderPos,
                                               msg[1][2])
                    elif self.colourCombi == 'GB':
                        self.selectedColour = (self.sliderPos, msg[1][1],
                                               msg[1][2])
                    self.bgcolour = self.selectedColour
            #        self.display.fill( self.selectedColour)
                self.drawBG()
                self.render()
            while self.dataReady("inbox"):
                for event in self.recv("inbox"):
                    if event.type == pygame.MOUSEBUTTONDOWN:
                        if self.display.get_rect().collidepoint(*event.pos):
                            if self.vertical:
                                self.sliderPos = event.pos[1]
                            else:
                                self.sliderPos = event.pos[0]
                            self.drawBG()
                            self.render()
                            self.mouseDown = True

                    if event.type == pygame.MOUSEBUTTONUP:
                        if self.mouseDown:
                            if self.vertical:
                                self.sliderPos = event.pos[1]
                            else:
                                self.sliderPos = event.pos[0]
                            self.drawBG()
                            self.render()
                        self.mouseDown = False

                    if event.type == pygame.MOUSEMOTION and self.mouseDown:
                        if self.display.get_rect().collidepoint(*event.pos):
                            if self.vertical:
                                self.sliderPos = event.pos[1]
                            else:
                                self.sliderPos = event.pos[0]
                            self.drawBG()
                            self.render()
                        else:
                            self.mouseDown = False
Ejemplo n.º 20
0
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

import pygame
from Kamaelia.UI.Pygame.Display import PygameDisplay
from Kamaelia.Chassis.Graphline import Graphline
from Kamaelia.Util.Console import ConsoleEchoer
from Kamaelia.UI.Pygame.KeyEvent import KeyEvent
from pygame.locals import *

width = 400
height = 200

displayservice = PygameDisplay.getDisplayService()
g = Graphline(displayservice = displayservice,
              linkages = {("self", "outbox") : displayservice,
                          }
              )

disprequest = {"DISPLAYREQUEST" : True,
               "size" : (width,height),               # pixels size for the new surface
               "callback" : (g, "inbox"),  # to send the new surface object to
               "events" : (g, "events")
}

Ejemplo n.º 21
0
 def main(self):
     pgd = PygameDisplay( width=self.width, height=self.height ).activate()
     PygameDisplay.setDisplayService(pgd)
     yield 1
Ejemplo n.º 22
0
    def main(self):
        """Main event loop, also handles input from other components"""
        displayservice = PygameDisplay.getDisplayService()
        self.link((self, "display_signal"), displayservice)

        self.send(self.disprequest, "display_signal")

        for _ in self.waitBox("callback"):
            yield 1
        self.display = self.recv("callback")
        self.layers.append(self.display)

        #    f = os.path.join('', "pennyarcade.gif")
        #    x = pygame.image.load(f)
        #    colorkey = x.get_at((0, 0))
        #    if colorkey is True:
        #        x.set_colorkey(colorkey, pygame.RLEACCEL)
        #    self.layers.append(x)
        #    self.display = x
        #    self.activeLayIn = len(self.layers)-1
        #    self.activeLayer = self.layers[self.activeLayIn]
        #    self.display.blit( x, (0,0) )

        layerDisp = TextDisplayer(size=(20, 20), position=(520, 10)).activate()
        self.link((self, "laynum"), (layerDisp, "inbox"))
        self.send(
            {
                "ADDLISTENEVENT": pygame.MOUSEBUTTONDOWN,
                "surface": self.display
            }, "display_signal")

        self.send(
            {
                "ADDLISTENEVENT": pygame.MOUSEBUTTONUP,
                "surface": self.display
            }, "display_signal")

        self.send(
            {
                "ADDLISTENEVENT": pygame.MOUSEMOTION,
                "surface": self.display
            }, "display_signal")

        self.send({
            "ADDLISTENEVENT": pygame.KEYDOWN,
            "surface": self.display
        }, "display_signal")
        self.activeLayer = self.layers[self.activeLayIn]
        self.send(self.activeLayIn, "laynum")
        image = pygame.Surface((20, 20))
        pygame.draw.circle(image, (1, 1, 1), (10, 10), self.toolSize, 0)
        # pygame.draw.circle(image, self.selectedColour, (10, 10), 8, 2)
        image.set_at((9, 9), (255, 255, 255))
        image.set_colorkey(0, pygame.RLEACCEL)
        cursor = GfxCursor(self.display, image, (10, 10))

        self.drawBG(True)
        self.blitToSurface()
        FPS = 1
        clock = Clock(float(1) / FPS).activate()
        clock.link((clock, "outbox"), (self, "newframe"))

        done = False
        while not done:
            dirtyrects = []
            dirtyrects.extend([cursor.hide()])
            if not self.anyReady():
                self.pause()
            yield 1
            while self.dataReady("control"):
                cmsg = self.recv("control")
                if isinstance(cmsg, producerFinished) or isinstance(
                        cmsg, shutdownMicroprocess):
                    self.send(cmsg, "signal")
                    done = True
            while self.dataReady("newframe") and self.playing:
                self.recv("newframe")
                if self.currentFrame != 0:
                    self.layers[self.currentFrame].set_alpha(0)
                self.currentFrame = self.currentFrame + 1
                if self.currentFrame == len(self.layers) - 1:
                    self.playing = False
                self.layers[self.currentFrame].set_alpha(255)
                self.blitToSurface()

            while self.dataReady("inbox"):
                for event in self.recv("inbox"):
                    if isinstance(event, tuple):
                        self.send((event, ), "outbox")
                        if event[0] == "Layer":
                            if event[1] == "Add":
                                yield WaitComplete(self.addLayer())
                                self.activeLayIn = len(self.layers) - 1
                                self.activeLayer = self.layers[
                                    self.activeLayIn]
                                self.drawBG()
                                if self.animator and len(self.layers) - 2 >= 1:
                                    for x in self.layers:
                                        s.set_alpha = 0
                                    self.activeLayer.blit(
                                        self.layers[len(self.layers) - 2],
                                        (0, 0))
                                self.blitToSurface()
                            elif event[1] == "Delete":
                                self.send(
                                    producerFinished(message=self.activeLayer),
                                    "display_signal")
                                self.layers.remove(self.activeLayer)
                                self.activeLayIn = 0
                                self.activeLayer = self.layers[
                                    self.activeLayIn]
                            #  print (self.layers)
                            if event[1] == "Next":
                                if self.animator and self.activeLayIn != 0:
                                    self.activeLayer.set_alpha(0)
                                if self.activeLayIn == len(self.layers) - 1:
                                    self.activeLayIn = 0
                                    self.activeLayer = self.layers[
                                        self.activeLayIn]
                                else:
                                    self.activeLayIn += 1
                                    self.activeLayer = self.layers[
                                        self.activeLayIn]
                                if self.animator:
                                    self.activeLayer.set_alpha(255)
                            elif event[1] == "Prev":
                                if self.animator and self.activeLayIn != 0:
                                    self.activeLayer.set_alpha(0)
                                if self.activeLayIn == 0:
                                    self.activeLayIn = len(self.layers) - 1
                                    self.activeLayer = self.layers[
                                        self.activeLayIn]
                                else:
                                    self.activeLayIn -= 1
                                    self.activeLayer = self.layers[
                                        self.activeLayIn]
                                if self.animator:
                                    self.activeLayer.set_alpha(255)
                            self.send(self.activeLayIn, "laynum")
                        elif event[0] == "Tool":
                            self.tool = event[1]
                        elif event[0] == "Size":
                            self.toolSize = event[1] / 3
                            pygame.draw.circle(image, self.selectedColour,
                                               (10, 10), self.toolSize / 3, 0)
                            image.set_at((9, 9), (255, 255, 255))
                            image.set_colorkey(0, pygame.RLEACCEL)
                            cursor = GfxCursor(self.display, image, (10, 10))
                        elif event[0] == "Alpha":
                            self.layers[self.activeLayIn].set_alpha(event[1])
                            self.blitToSurface()
                        #  print (self.activeLayer.get_alpha())
                        elif event[0] == 'Colour':
                            self.selectedColour = event[1]
                            pygame.draw.circle(image, self.selectedColour,
                                               (10, 10), self.toolSize / 3, 0)
                            image.set_at((9, 9), (255, 255, 255))
                            image.set_colorkey(0, pygame.RLEACCEL)
                            cursor = GfxCursor(self.display, image, (10, 10))
                        elif event[0] == 'Save':
                            self.save(event[1])
                        break
                    if event.type == pygame.MOUSEBUTTONDOWN:
                        cursor.disable()
                        if self.tool == "Circle":
                            if event.button == 1:
                                self.oldpos = event.pos
                                self.drawing = True
                        if self.tool == "Eraser":
                            self.selectedColour = self.backgroundColour
                            self.tool = "Line"
                        if self.tool == "Line":
                            if event.button == 1:
                                self.drawing = True
                        if self.tool == "Bucket":
                            self.floodFill(event.pos[0], event.pos[1],
                                           self.selectedColour,
                                           self.activeLayer.get_at(event.pos))
                        if self.tool == "Eyedropper":
                            self.selectedColour = self.activeLayer.get_at(
                                event.pos)
                        if event.button == 3:
                            self.addLayer()
                            #self.oldpos = None
                            #self.drawBG()
                            #self.blitToSurface()
                            #self.send(("clear",), "outbox")
                    elif event.type == (pygame.KEYDOWN):
                        if event.key == pygame.K_c:
                            image = pygame.image.load(
                                os.path.join('', 'pennyarcade.gif'))
                            yield WaitComplete(self.addLayer())
                            self.activeLayIn = len(self.layers) - 1
                            self.activeLayer = self.layers[self.activeLayIn]
                            self.drawBG()
                            self.activeLayer.blit(image, (10, 10))
                            self.blitToSurface()
                            self.send(self.activeLayIn, "laynum")
                        elif event.key == pygame.K_s:
                            """Testing a different brushing technique, bliting a brush"""
                            print(self.size, self.toolSize)
                            yield WaitComplete(self.addBrush())
                            self.activeBrush = self.brushes[len(self.brushes) -
                                                            1]
                            self.activeBrush.fill(self.backgroundColour)
                            pygame.draw.circle(
                                self.activeBrush, self.selectedColour,
                                (self.toolSize / 2, self.toolSize / 2),
                                self.toolSize, 0)
                        elif event.key == pygame.K_a:
                            self.animator = True
                        elif event.key == pygame.K_l:
                            self.layers[1].blit(self.layers[1], (100, 100))
                #         temp = self.layers[1]
                #         self.layers[1].fill(self.backgroundColour)
                #         self.layers[1].blit( temp, (100,100) )
                        elif event.key == pygame.K_o:
                            for x in self.layers:
                                x.set_alpha(0)
                            self.layers[0].set_alpha(255)
                            self.currentFrame = 0
                            while self.dataReady(
                                    "newframe"
                            ):  # empty if there's anything there
                                self.recv("newframe")
                            self.playing = True
                            self.blitToSurface()

                    elif event.type == pygame.MOUSEBUTTONUP and event.button == 1:
                        cursor.enable()
                        if self.tool == "Circle":
                            rad = int(
                                math.sqrt((
                                    (event.pos[0] - self.oldpos[0])**2) + (
                                        (event.pos[1] - self.oldpos[1])**2)))
                            pygame.draw.circle(self.activeLayer,
                                               self.selectedColour,
                                               self.oldpos, rad, 0)
                            circle = ("circle", self.oldpos, rad)
                            #   self.send((circle,), "outbox")
                            self.blitToSurface()
                        self.drawing = False
                        self.oldpos = None
                    elif event.type == pygame.MOUSEMOTION:
                        cursor.update(event)
                        if self.tool == "Line":
                            if self.drawing and self.innerRect.collidepoint(
                                    *event.pos):
                                if self.oldpos == None:
                                    self.oldpos = event.pos
                                else:
                                    # pygame.draw.circle(self.activeLayer, self.selectedColour, self.oldpos, self.toolSize, 0)
                                    r = pygame.draw.line(
                                        self.activeLayer, self.selectedColour,
                                        self.oldpos, event.pos, self.toolSize)
                                    dirtyrects.append(r)
                                    #  self.activeLayer.blit(self.activeBrush, event.pos) FAILED TECHNIQUE
                                    line = ("line", self.oldpos, event.pos)
                                    self.send((line, ), "outbox")
                                    self.oldpos = event.pos
                        self.blitToSurface()
            self.pause()
            pygame.time.delay(5)
            dirtyrects.extend([cursor.show()])
            pygame.display.update(dirtyrects)
            yield 1
Ejemplo n.º 23
0
                         ("ANALYSE", "outbox"): ("GRAMMAR", "inbox"),
                         ("GRAMMAR", "outbox"): ("self", "outbox"),
                         ("QUANTISE", "drawing"): ("self", "drawing"),
                         ("ANALYSE", "drawing"): ("self", "drawing"),
                     })


if __name__ == "__main__":

    from Kamaelia.UI.Pygame.Display import PygameDisplay
    from Kamaelia.Util.Console import ConsoleEchoer

    width = 1024
    height = 384

    pgd = PygameDisplay(width=width, height=height).activate()
    PygameDisplay.setDisplayService(pgd)

    Graphline(
        CANVAS=Canvas(position=(0, 0), size=(width, height)),
        PEN=Pen(),
        STROKER=StrokeRecogniser(),
        OUTPUT=ConsoleEchoer(),
        linkages={
            ("CANVAS", "eventsOut"): ("PEN", "inbox"),
            ("PEN", "outbox"): ("CANVAS", "inbox"),
            ("PEN", "points"): ("STROKER", "inbox"),
            ("STROKER", "outbox"): ("OUTPUT", "inbox"),
            ("STROKER", "drawing"): ("CANVAS", "inbox"),
        },
    ).run()
Ejemplo n.º 24
0
    def main(self):
        """Main loop."""
        displayservice = PygameDisplay.getDisplayService()
        self.link((self, "display_signal"), displayservice)
        self.send(self.dispRequest, "display_signal")
        for _ in self.waitBox("callback"):
            yield 1
        self.display = self.recv("callback")

        # tool buttons
        circleb = ImageButton(
            caption=(os.path.join("icons", "EllipseToolIcon.png")),
            position=(10, 10),
            bgcolour=(235, 235, 235),
            msg=(("Tool", "Circle"),),
        ).activate()
        eraseb = ImageButton(
            caption=(os.path.join("icons", "EraserToolIcon.png")),
            position=(100, 10),
            bgcolour=(235, 235, 235),
            msg=(("Tool", "Eraser"),),
        ).activate()
        lineb = ImageButton(
            caption=(os.path.join("icons", "PaintBrushToolIcon.png")),
            position=(10, 50),
            bgcolour=(235, 235, 235),
            msg=(("Tool", "Line"),),
        ).activate()
        bucketb = ImageButton(
            caption=(os.path.join("icons", "PaintBucketIcon.png")),
            position=(10, 90),
            bgcolour=(235, 235, 235),
            msg=(("Tool", "Bucket"),),
        ).activate()
        eyeb = ImageButton(
            caption=(os.path.join("icons", "ColorPickerToolIcon.png")),
            position=(10, 130),
            bgcolour=(235, 235, 235),
            msg=(("Tool", "Eyedropper"),),
        ).activate()
        addlayerb = ImageButton(
            caption=(os.path.join("icons", "PlusButtonIcon.png")),
            position=(10, 540),
            bgcolour=(235, 235, 235),
            msg=(("Layer", "Add"),),
        ).activate()
        prevlayerb = ImageButton(
            caption=(os.path.join("icons", "MenuLayersMoveLayerDownIcon.png")),
            position=(80, 540),
            bgcolour=(235, 235, 235),
            msg=(("Layer", "Prev"),),
        ).activate()
        nextlayerb = ImageButton(
            caption=(os.path.join("icons", "MenuLayersMoveLayerUpIcon.png")),
            position=(110, 540),
            bgcolour=(235, 235, 235),
            msg=(("Layer", "Next"),),
        ).activate()
        dellayerb = ImageButton(
            caption=(os.path.join("icons", "MinusButtonIcon.png")),
            position=(35, 540),
            bgcolour=(235, 235, 235),
            msg=(("Layer", "Delete"),),
        ).activate()
        saveb = ImageButton(
            caption=(os.path.join("icons", "MenuFileSaveIcon.png")),
            position=(100, 130),
            bgcolour=(235, 235, 235),
            msg=(("Save", "Test"),),
        ).activate()
        self.link((circleb, "outbox"), (self, "outbox"), passthrough=2)
        self.link((eraseb, "outbox"), (self, "outbox"), passthrough=2)
        self.link((lineb, "outbox"), (self, "outbox"), passthrough=2)
        self.link((bucketb, "outbox"), (self, "outbox"), passthrough=2)
        self.link((eyeb, "outbox"), (self, "outbox"), passthrough=2)
        self.link((addlayerb, "outbox"), (self, "outbox"), passthrough=2)
        self.link((prevlayerb, "outbox"), (self, "outbox"), passthrough=2)
        self.link((nextlayerb, "outbox"), (self, "outbox"), passthrough=2)
        self.link((dellayerb, "outbox"), (self, "outbox"), passthrough=2)
        self.link((saveb, "outbox"), (self, "outbox"), passthrough=2)
        colSel = ColourSelector(position=(10, 170), size=(255, 255)).activate()
        self.link((colSel, "outbox"), (self, "outbox"), passthrough=2)
        SizeSlider = Slider(size=(255, 50), messagePrefix="Size", position=(10, 460), default=9).activate()
        self.link((SizeSlider, "outbox"), (self, "outbox"), passthrough=2)
        AlphaSlider = Slider(size=(255, 10), messagePrefix="Alpha", position=(10, 515), default=255).activate()
        self.link((AlphaSlider, "outbox"), (self, "outbox"), passthrough=2)

        self.drawBG()
        done = False
        while not done:
            if not self.anyReady():
                self.pause()
            yield 1
Ejemplo n.º 25
0
    def main(self):
        """Main loop."""
        displayservice = PygameDisplay.getDisplayService()
        self.link((self, "display_signal"), displayservice)
        self.send(self.dispRequest, "display_signal")
        for _ in self.waitBox("callback"):
            yield 1
        self.display = self.recv("callback")

        # tool buttons
        circleb = Button(caption="Circle",
                         position=(10, 10),
                         msg=(("Tool", "Circle"), )).activate()
        eraseb = Button(caption="Eraser",
                        position=(100, 10),
                        msg=(("Tool", "Eraser"), )).activate()
        lineb = Button(caption="Line",
                       position=(10, 50),
                       msg=(("Tool", "Line"), )).activate()
        bucketb = Button(caption="Bucket",
                         position=(10, 90),
                         msg=(("Tool", "Bucket"), )).activate()
        eyeb = Button(caption="Eyedropper",
                      position=(10, 130),
                      msg=(("Tool", "Eyedropper"), )).activate()
        addlayerb = Button(caption="Add Layer",
                           position=(10, 540),
                           msg=(("Layer", "Add"), )).activate()
        prevlayerb = Button(caption="<-",
                            position=(80, 540),
                            msg=(("Layer", "Prev"), )).activate()
        nextlayerb = Button(caption="->",
                            position=(110, 540),
                            msg=(("Layer", "Next"), )).activate()
        dellayerb = Button(caption="Delete",
                           position=(140, 540),
                           msg=(("Layer", "Delete"), )).activate()
        self.link((circleb, "outbox"), (self, "outbox"), passthrough=2)
        self.link((eraseb, "outbox"), (self, "outbox"), passthrough=2)
        self.link((lineb, "outbox"), (self, "outbox"), passthrough=2)
        self.link((bucketb, "outbox"), (self, "outbox"), passthrough=2)
        self.link((eyeb, "outbox"), (self, "outbox"), passthrough=2)
        self.link((addlayerb, "outbox"), (self, "outbox"), passthrough=2)
        self.link((prevlayerb, "outbox"), (self, "outbox"), passthrough=2)
        self.link((nextlayerb, "outbox"), (self, "outbox"), passthrough=2)
        self.link((dellayerb, "outbox"), (self, "outbox"), passthrough=2)
        colSel = ColourSelector(position=(10, 170), size=(255, 255)).activate()
        self.link((colSel, "outbox"), (self, "outbox"), passthrough=2)
        SizeSlider = Slider(size=(255, 50),
                            messagePrefix="Size",
                            position=(10, 460),
                            default=9).activate()
        self.link((SizeSlider, "outbox"), (self, "outbox"), passthrough=2)
        AlphaSlider = Slider(size=(255, 10),
                             messagePrefix="Alpha",
                             position=(10, 515),
                             default=255).activate()
        self.link((AlphaSlider, "outbox"), (self, "outbox"), passthrough=2)
        self.drawBG()
        done = False
        while not done:
            if not self.anyReady():
                self.pause()
            yield 1
Ejemplo n.º 26
0
                self.send(' '.join(data), "outbox")
            if not self.anyReady():
                pass
            yield 1
            

from Kamaelia.Apps.Whiteboard.Routers import TwoWaySplitter
from Kamaelia.Chassis.Pipeline import Pipeline
from Kamaelia.File.UnixProcess import UnixProcess

from Kamaelia.UI.Pygame.Image import Image

from Kamaelia.UI.Pygame.Display import PygameDisplay
from Kamaelia.Util.Console import ConsoleEchoer

pgd = PygameDisplay( width=800, height=480 ).activate()
PygameDisplay.setDisplayService(pgd)



Backplane("SPEECH").activate()    

Pipeline(
    SubscribeTo("SPEECH"),
    Repeater(),
    Reorderer(),
    ConsoleEchoer(1),
    UnixProcess("while read word; do echo $word | espeak -w foo.wav --stdin ; aplay foo.wav ; done"),
).activate()

bgcolour = (255,255,180)
Ejemplo n.º 27
0
    def main(self):
        """Main loop."""
        displayservice = PygameDisplay.getDisplayService()
        self.link((self, "display_signal"), displayservice)

        self.send(self.disprequest, "display_signal")

        for _ in self.waitBox("callback"):
            yield 1
        self.display = self.recv("callback")
        self.layers.append(self.display)

        #    f = os.path.join('', "pennyarcade.gif")
        #    x = pygame.image.load(f)
        #    colorkey = x.get_at((0, 0))
        #    if colorkey is True:
        #        x.set_colorkey(colorkey, pygame.RLEACCEL)
        #    self.layers.append(x)
        #    self.display = x
        #    self.activeLayIn = len(self.layers)-1
        #    self.activeLayer = self.layers[self.activeLayIn]
        #    self.display.blit( x, (0,0) )

        layerDisp = TextDisplayer(size=(20, 20), position=(520, 10)).activate()
        self.link((self, "laynum"), (layerDisp, "inbox"))
        self.send(
            {
                "ADDLISTENEVENT": pygame.MOUSEBUTTONDOWN,
                "surface": self.display
            }, "display_signal")

        self.send(
            {
                "ADDLISTENEVENT": pygame.MOUSEBUTTONUP,
                "surface": self.display
            }, "display_signal")

        self.send(
            {
                "ADDLISTENEVENT": pygame.MOUSEMOTION,
                "surface": self.display
            }, "display_signal")

        self.send({
            "ADDLISTENEVENT": pygame.KEYDOWN,
            "surface": self.display
        }, "display_signal")
        self.activeLayer = self.layers[self.activeLayIn]
        self.send(self.activeLayIn, "laynum")

        self.drawBG(True)
        self.blitToSurface()

        done = False
        while not done:
            if not self.anyReady():
                self.pause()
            yield 1
            while self.dataReady("control"):
                cmsg = self.recv("control")
                if isinstance(cmsg, producerFinished) or isinstance(
                        cmsg, shutdownMicroprocess):
                    self.send(cmsg, "signal")
                    done = True

            while self.dataReady("inbox"):
                for event in self.recv("inbox"):
                    if isinstance(event, tuple):
                        if event[0] == "Layer":
                            if event[1] == "Add":
                                yield WaitComplete(self.addLayer())
                                self.activeLayIn = len(self.layers) - 1
                                self.activeLayer = self.layers[
                                    self.activeLayIn]
                                #   self.send( self.activeLayIn, "laynum" )
                                self.drawBG()
                                self.blitToSurface()
                            elif event[1] == "Delete":
                                self.send(
                                    producerFinished(message=self.activeLayer),
                                    "display_signal")
                                self.layers.remove(self.activeLayer)
                                self.activeLayIn = 0
                                self.activeLayer = self.layers[
                                    self.activeLayIn]
                            #  print self.layers
                            if event[1] == "Next":
                                if self.activeLayIn == len(self.layers) - 1:
                                    self.activeLayIn = 0
                                    self.activeLayer = self.layers[
                                        self.activeLayIn]
                                else:
                                    self.activeLayIn += 1
                                    self.activeLayer = self.layers[
                                        self.activeLayIn]
                            elif event[1] == "Prev":
                                if self.activeLayIn == 0:
                                    self.activeLayIn = len(self.layers) - 1
                                    self.activeLayer = self.layers[
                                        self.activeLayIn]
                                else:
                                    self.activeLayIn -= 1
                                    self.activeLayer = self.layers[
                                        self.activeLayIn]
                            self.send(self.activeLayIn, "laynum")
                        elif event[0] == "Tool":
                            self.tool = event[1]
                        elif event[0] == "Size":
                            self.toolSize = event[1] / 3
                        elif event[0] == "Alpha":
                            self.layers[self.activeLayIn].set_alpha(event[1])
                            self.blitToSurface()
                        #  print self.activeLayer.get_alpha()
                        elif event[0] == 'Colour':
                            self.selectedColour = event[1]
                        break
                    if event.type == pygame.MOUSEBUTTONDOWN:
                        if self.tool == "Circle":
                            if event.button == 1:
                                self.oldpos = event.pos
                                self.drawing = True
                        if self.tool == "Eraser":
                            self.selectedColour = self.backgroundColour
                            self.tool = "Line"
                        if self.tool == "Line":
                            if event.button == 1:
                                self.drawing = True
                        if self.tool == "Bucket":
                            self.floodFill(event.pos[0], event.pos[1],
                                           self.selectedColour,
                                           self.activeLayer.get_at(event.pos))
                        if self.tool == "Eyedropper":
                            self.selectedColour = self.activeLayer.get_at(
                                event.pos)
                        if event.button == 3:
                            self.addLayer()
                            #self.oldpos = None
                            #self.drawBG()
                            #self.blitToSurface()
                            #self.send(("clear",), "outbox")
                    elif event.type == (pygame.KEYDOWN):
                        if event.key == pygame.K_c:
                            image = pygame.image.load(
                                os.path.join('', 'pennyarcade.gif'))
                            yield WaitComplete(self.addLayer())
                            self.activeLayIn = len(self.layers) - 1
                            self.activeLayer = self.layers[self.activeLayIn]
                            self.drawBG()
                            self.activeLayer.blit(image, (10, 10))
                            self.blitToSurface()
                            self.send(self.activeLayIn, "laynum")
                        elif event.key == pygame.K_s:
                            #  temp = self.layers[0]
                            self.save("tgfdg")
                        #  self.layers.insert(0,temp)
                        #  self.drawBG()
                        elif event.key == pygame.K_l:
                            self.layers[1].blit(self.layers[1], (100, 100))
                #         temp = self.layers[1]
                #         self.layers[1].fill(self.backgroundColour)
                #         self.layers[1].blit( temp, (100,100) )
                        elif event.key == pygame.K_o:
                            move = {
                                "CHANGEDISPLAYGEO": True,
                                "surface": self.layers[1],
                                "position": (100, 100)
                            }
                            self.send(move, "display_signal")

                    elif event.type == pygame.MOUSEBUTTONUP and event.button == 1:
                        if self.tool == "Circle":
                            rad = math.sqrt((
                                (event.pos[0] - self.oldpos[0])**2) + (
                                    (event.pos[1] - self.oldpos[1])**2))
                            pygame.draw.circle(self.activeLayer,
                                               self.selectedColour,
                                               self.oldpos, rad, 0)
                            circle = ("circle", self.oldpos, rad)
                            self.send((circle, ), "outbox")
                            self.blitToSurface()
                        self.drawing = False
                        self.oldpos = None
                    elif event.type == pygame.MOUSEMOTION:
                        if self.tool == "Line":
                            if self.drawing and self.innerRect.collidepoint(
                                    *event.pos):
                                if self.oldpos == None:
                                    self.oldpos = event.pos
                                else:
                                    # pygame.draw.circle(self.activeLayer, self.selectedColour, self.oldpos, self.toolSize, 0)
                                    pygame.draw.line(self.activeLayer,
                                                     self.selectedColour,
                                                     self.oldpos, event.pos,
                                                     self.toolSize)
                                    line = ("line", self.oldpos, event.pos)
                                    self.send((line, ), "outbox")
                                    self.oldpos = event.pos
                                self.blitToSurface()
            self.pause()
            yield 1
Ejemplo n.º 28
0
    def main(self):
        """Main loop."""
        #    pgd = PygameDisplay( width=300, height=550 ).activate()
        #   PygameDisplay.setDisplayService(pgd)

        displayservice = PygameDisplay.getDisplayService()
        self.link((self, "display_signal"), displayservice)

        self.send(self.dispRequest, "display_signal")

        for _ in self.waitBox("callback"):
            yield 1
        self.display = self.recv("callback")

        # colour buttons
        if self.colourSelector:
            rgbutton = Button(caption="Red/Green", position=(10, 170), msg=("Colour", "RG")).activate()
            rbbutton = Button(caption="Red/Blue", position=(80, 170), msg=("Colour", "RB")).activate()
            gbbutton = Button(caption="Green/Blue", position=(145, 170), msg=("Colour", "GB")).activate()
            self.link((rgbutton, "outbox"), (self, "buttons"))
            self.link((rbbutton, "outbox"), (self, "buttons"))
            self.link((gbbutton, "outbox"), (self, "buttons"))
            # tool buttons
            circleb = Button(caption="Circle", position=(10, 10), msg=(("Tool", "Circle"),)).activate()
            eraseb = Button(caption="Eraser", position=(100, 10), msg=(("Tool", "Eraser"),)).activate()
            lineb = Button(caption="Line", position=(10, 50), msg=(("Tool", "Line"),)).activate()
            bucketb = Button(caption="Bucket", position=(10, 90), msg=(("Tool", "Bucket"),)).activate()
            eyeb = Button(caption="Eyedropper", position=(10, 130), msg=(("Tool", "Eyedropper"),)).activate()
            addlayerb = Button(caption="Add Layer", position=(10, 540), msg=(("Layer", "Add"),)).activate()
            prevlayerb = Button(caption="<-", position=(80, 540), msg=(("Layer", "Prev"),)).activate()
            nextlayerb = Button(caption="->", position=(110, 540), msg=(("Layer", "Next"),)).activate()
            dellayerb = Button(caption="Delete", position=(140, 540), msg=(("Layer", "Delete"),)).activate()
            self.link((circleb, "outbox"), (self, "outbox"), passthrough=2)
            self.link((eraseb, "outbox"), (self, "outbox"), passthrough=2)
            self.link((lineb, "outbox"), (self, "outbox"), passthrough=2)
            self.link((bucketb, "outbox"), (self, "outbox"), passthrough=2)
            self.link((eyeb, "outbox"), (self, "outbox"), passthrough=2)
            self.link((addlayerb, "outbox"), (self, "outbox"), passthrough=2)
            self.link((prevlayerb, "outbox"), (self, "outbox"), passthrough=2)
            self.link((nextlayerb, "outbox"), (self, "outbox"), passthrough=2)
            self.link((dellayerb, "outbox"), (self, "outbox"), passthrough=2)
            SizePicker = XYPad(
                size=(255, 50),
                bouncingPuck=False,
                position=(10, 480),
                bgcolour=(0, 0, 0),
                fgcolour=(255, 255, 255),
                slider=True,
            ).activate()
            self.link((SizePicker, "outbox"), (self, "outbox"), passthrough=2)
            AlphaPicker = XYPad(
                size=(255, 20),
                bouncingPuck=False,
                position=(10, 575),
                bgcolour=(0, 0, 0),
                fgcolour=(255, 255, 255),
                slider=True,
                alpha=True,
            ).activate()
            self.link((AlphaPicker, "outbox"), (self, "outbox"), passthrough=2)

        # clock - don't really need this
        FPS = 60
        clock = Clock(float(1) / FPS).activate()
        self.link((clock, "outbox"), (self, "newframe"))

        # Initial render so we don't see a blank screen
        self.drawBG()
        #  self.render()
        if self.editable:
            self.send({"ADDLISTENEVENT": pygame.MOUSEBUTTONDOWN, "surface": self.display}, "display_signal")

            self.send({"ADDLISTENEVENT": pygame.MOUSEBUTTONUP, "surface": self.display}, "display_signal")

            self.send({"ADDLISTENEVENT": pygame.MOUSEMOTION, "surface": self.display}, "display_signal")

        done = False
        while not done:
            if not self.anyReady():
                self.pause()
            yield 1
            while self.dataReady("buttons"):
                bmsg = self.recv("buttons")
                if bmsg[0] == "Colour":
                    self.colours = bmsg[1]
                    self.drawBG()

            while self.dataReady("control"):
                cmsg = self.recv("control")
                if isinstance(cmsg, producerFinished):
                    self.send(cmsg, "signal")
                    done = True

            while self.dataReady("inbox"):
                for event in self.recv("inbox"):

                    if event.type == pygame.MOUSEBUTTONDOWN:
                        self.clickTime = time.time()
                        if self.slider:
                            self.sliderPos = event.pos[0]
                            self.drawBG()
                        if self.display.get_rect().collidepoint(*event.pos):
                            self.mouseDown = True
                            self.isBouncing = False
                            self.mousePositions = []
                            self.puckVel = [0, 0]
                            self.puckPos = list(event.pos)
                            self.lastMousePos = event.pos
                            self.send(
                                (
                                    self.messagePrefix + self.positionMsg,
                                    (float(self.puckPos[0]) / self.size[0], float(self.puckPos[1]) / self.size[1]),
                                ),
                                "localChanges",
                            )

                            self.send((self.messagePrefix + "Velocity", self.puckVel), "localChanges")

                    if event.type == pygame.MOUSEBUTTONUP:
                        if self.mouseDown:
                            if self.slider:
                                self.sliderPos = event.pos[0]
                                self.drawBG()
                            if self.bouncingPuck and time.time() - self.clickTime > 0.1:
                                # Click and drag
                                self.isBouncing = True
                                if len(self.mousePositions):
                                    for i in xrange(2):
                                        # Use the average of the last 50
                                        # relative mouse positions
                                        positions = [x[i] for x in self.mousePositions]
                                        self.puckVel[i] = sum(positions)
                                        self.puckVel[i] /= float(len(positions))
                            else:
                                # Just a click
                                self.puckVel = [0, 0]
                                self.render()
                            self.send((self.messagePrefix + "Velocity", self.puckVel), "localChanges")
                        self.mouseDown = False

                    if event.type == pygame.MOUSEMOTION and self.mouseDown:
                        if self.slider:
                            self.sliderPos = event.pos[0]
                            self.drawBG()
                        if self.display.get_rect().collidepoint(*event.pos):
                            # We are dragging inside the display
                            # Keep a buffer of 50 mouse positions
                            if len(self.mousePositions) > 50:
                                del self.mousePositions[0]
                            relPos = []
                            for i in xrange(2):
                                relPos.append(event.pos[i] - self.lastMousePos[i])
                            self.mousePositions.append(relPos)
                            # Move the puck to where the mouse is and remember
                            # where it is
                            self.puckPos = list(event.pos)
                            self.lastMousePos = event.pos
                            self.send(
                                (
                                    self.messagePrefix + self.positionMsg,
                                    (float(self.puckPos[0]) / self.size[0], float(self.puckPos[1]) / self.size[1]),
                                ),
                                "localChanges",
                            )
                            self.render()

            if self.dataReady("remoteChanges"):
                bundle = self.recv("remoteChanges")
                # The action to take is given by the last section of the
                # OSC address - this should maybe be done by a component and
                # we just listen for ("Velocity", (xVel, yVel)) tuples
                action = bundle[0].split("/")[-1]
                if action == "Velocity":
                    if self.bouncingPuck:
                        self.puckVel = bundle[1]
                        self.isBouncing = 1
                elif action == "Position":
                    for i in xrange(2):
                        self.puckPos[i] = self.size[i] * bundle[1][i]
                self.render()

            if self.dataReady("newframe"):
                # Time to render a new frame
                # Clear any backlog of render messages
                while self.dataReady("newframe"):
                    self.recv("newframe")

                # Change the direction of the puck if it hits a wall
                if self.isBouncing:
                    self.processCollisions()

                if self.isBouncing:
                    # Update the position
                    for i in xrange(2):
                        self.puckPos[i] += self.puckVel[i]
                    self.render()
Ejemplo n.º 29
0
   def main(self):
      """Main event loop, also handles input from other components"""
      displayservice = PygameDisplay.getDisplayService()
      self.link((self,"display_signal"), displayservice)

      self.send( self.disprequest,"display_signal")

      for _ in self.waitBox("callback"): yield 1
      self.display = self.recv("callback")
      self.layers.append(self.display)

  #    f = os.path.join('', "pennyarcade.gif")
  #    x = pygame.image.load(f)
  #    colorkey = x.get_at((0, 0))
  #    if colorkey is True:
  #        x.set_colorkey(colorkey, pygame.RLEACCEL)
  #    self.layers.append(x)
  #    self.display = x
  #    self.activeLayIn = len(self.layers)-1
  #    self.activeLayer = self.layers[self.activeLayIn]
  #    self.display.blit( x, (0,0) )
      

      layerDisp = TextDisplayer(size = (20, 20),position = (520,10)).activate()
      self.link( (self,"laynum"), (layerDisp,"inbox") )
      self.send({ "ADDLISTENEVENT" : pygame.MOUSEBUTTONDOWN,
                  "surface" : self.display},
                  "display_signal")

      self.send({ "ADDLISTENEVENT" : pygame.MOUSEBUTTONUP,
                  "surface" : self.display},
                  "display_signal")

      self.send({ "ADDLISTENEVENT" : pygame.MOUSEMOTION,
                  "surface" : self.display},
                  "display_signal")

      self.send({ "ADDLISTENEVENT" : pygame.KEYDOWN,
		  "surface" : self.display},
		  "display_signal")
      self.activeLayer = self.layers[self.activeLayIn]
      self.send( self.activeLayIn, "laynum" )
      image = pygame.Surface((20, 20))
      pygame.draw.circle(image, (1, 1, 1), (10, 10), self.toolSize, 0)
     # pygame.draw.circle(image, self.selectedColour, (10, 10), 8, 2)
      image.set_at((9, 9), (255,255,255))
      image.set_colorkey(0, pygame.RLEACCEL)
      cursor = GfxCursor(self.display, image, (10, 10))

      self.drawBG(True)
      self.blitToSurface()
      FPS = 1
      clock = Clock(float(1)/FPS).activate()
      clock.link((clock, "outbox"), (self, "newframe"))


      done = False
      while not done:
         dirtyrects = []
         dirtyrects.extend([cursor.hide()])
         if not self.anyReady():
             self.pause()
         yield 1
         while self.dataReady("control"):
            cmsg = self.recv("control")
            if isinstance(cmsg, producerFinished) or isinstance(cmsg, shutdownMicroprocess):
               self.send(cmsg, "signal")
               done = True
         while self.dataReady("newframe") and self.playing:
             self.recv("newframe")
             if self.currentFrame != 0:
                self.layers[self.currentFrame].set_alpha(0)
             self.currentFrame = self.currentFrame + 1
             if self.currentFrame == len(self.layers)-1:
                 self.playing = False
             self.layers[self.currentFrame].set_alpha(255)
             self.blitToSurface()

         while self.dataReady("inbox"):
            for event in self.recv("inbox"):
                if isinstance(event, tuple):
                    self.send((event,),"outbox")
                    if event[0] == "Layer":
                        if event[1] == "Add":
                            yield WaitComplete( self.addLayer() )
                            self.activeLayIn = len(self.layers)-1
                            self.activeLayer = self.layers[self.activeLayIn]
                            self.drawBG()
                            if self.animator and len(self.layers)-2 >= 1:
                                for x in self.layers:
                                    s.set_alpha = 0
                                self.activeLayer.blit(self.layers[len(self.layers)-2],(0,0))
                            self.blitToSurface()
                        elif event[1] == "Delete":
                            self.send( producerFinished(message=self.activeLayer),"display_signal")
                            self.layers.remove(self.activeLayer)
                            self.activeLayIn = 0
                            self.activeLayer = self.layers[self.activeLayIn]
                          #  print (self.layers)
                        if event[1] == "Next":
                            if self.animator and self.activeLayIn != 0:
                            	self.activeLayer.set_alpha(0)
                            if self.activeLayIn == len(self.layers)-1:
                                self.activeLayIn = 0
                                self.activeLayer = self.layers[self.activeLayIn]
                            else:
                                self.activeLayIn += 1
                                self.activeLayer = self.layers[self.activeLayIn]
                            if self.animator:
                            	self.activeLayer.set_alpha(255)
                        elif event[1] == "Prev":
                            if self.animator and self.activeLayIn != 0:
                            	self.activeLayer.set_alpha(0)
                            if self.activeLayIn == 0:
                                self.activeLayIn = len(self.layers)-1
                                self.activeLayer = self.layers[self.activeLayIn]
                            else:
                                self.activeLayIn -= 1
                                self.activeLayer = self.layers[self.activeLayIn]
                            if self.animator:
                            	self.activeLayer.set_alpha(255)
                        self.send( self.activeLayIn, "laynum" )
                    elif event[0] == "Tool":
                        self.tool = event[1]
                    elif event[0] == "Size":
                        self.toolSize = event[1]/3
                        pygame.draw.circle(image, self.selectedColour, (10, 10), self.toolSize/3, 0)
                        image.set_at((9, 9), (255,255,255))
                        image.set_colorkey(0, pygame.RLEACCEL)
                        cursor = GfxCursor(self.display, image, (10, 10))
                    elif event[0] == "Alpha":
                        self.layers[self.activeLayIn].set_alpha(event[1])
                        self.blitToSurface()
                      #  print (self.activeLayer.get_alpha())
                    elif event[0] == 'Colour':
                        self.selectedColour = event[1]
                        pygame.draw.circle(image, self.selectedColour, (10, 10), self.toolSize/3, 0)
                        image.set_at((9, 9), (255,255,255))
                        image.set_colorkey(0, pygame.RLEACCEL)
                        cursor = GfxCursor(self.display, image, (10, 10))
                    elif event[0] == 'Save':
                        self.save(event[1])
                    break
                if event.type == pygame.MOUSEBUTTONDOWN:
                    cursor.disable()
                    if self.tool == "Circle":
                        if event.button == 1:
                            self.oldpos = event.pos
                            self.drawing = True
                    if self.tool == "Eraser":
                        self.selectedColour = self.backgroundColour
                        self.tool = "Line"
                    if self.tool == "Line":
                        if event.button == 1:
                            self.drawing = True
                    if self.tool == "Bucket":
                        self.floodFill(event.pos[0],event.pos[1],self.selectedColour,self.activeLayer.get_at(event.pos))
                    if self.tool == "Eyedropper":
                        self.selectedColour = self.activeLayer.get_at(event.pos)
                    if event.button == 3:
                        self.addLayer()
                        #self.oldpos = None
                        #self.drawBG()
                        #self.blitToSurface()
                        #self.send(("clear",), "outbox")
                elif event.type == (pygame.KEYDOWN):
                    if event.key == pygame.K_c:
                        image = pygame.image.load(os.path.join('', 'pennyarcade.gif'))
                        yield WaitComplete( self.addLayer() )
                        self.activeLayIn = len(self.layers)-1
                        self.activeLayer = self.layers[self.activeLayIn]
                        self.drawBG()
                        self.activeLayer.blit( image, (10,10) )
                        self.blitToSurface()
                        self.send( self.activeLayIn, "laynum" )
                    elif event.key == pygame.K_s:
                        """Testing a different brushing technique, bliting a brush"""
                        print (self.size, self.toolSize)
                        yield WaitComplete( self.addBrush() )
                        self.activeBrush = self.brushes[len(self.brushes)-1]
                        self.activeBrush.fill( self.backgroundColour )
                        pygame.draw.circle(self.activeBrush, self.selectedColour, (self.toolSize/2,self.toolSize/2), self.toolSize, 0)
                    elif event.key == pygame.K_a:
                        self.animator = True
                    elif event.key == pygame.K_l:
                        self.layers[1].blit( self.layers[1], (100,100) )
               #         temp = self.layers[1]
               #         self.layers[1].fill(self.backgroundColour)
               #         self.layers[1].blit( temp, (100,100) )
                    elif event.key == pygame.K_o:
                        for x in self.layers:
                            x.set_alpha(0)
                        self.layers[0].set_alpha(255)
                        self.currentFrame = 0
                        while self.dataReady("newframe"): # empty if there's anything there
                            self.recv("newframe")
                        self.playing = True
                        self.blitToSurface()



                elif event.type == pygame.MOUSEBUTTONUP and event.button == 1:
                    cursor.enable()
                    if self.tool == "Circle":
                        rad = int(math.sqrt(((event.pos[0]-self.oldpos[0])**2)+((event.pos[1]-self.oldpos[1])**2)))
                        pygame.draw.circle(self.activeLayer, self.selectedColour, self.oldpos, rad, 0)
                        circle = ("circle", self.oldpos, rad)
                     #   self.send((circle,), "outbox")
                        self.blitToSurface()
                    self.drawing = False
                    self.oldpos = None
                elif event.type == pygame.MOUSEMOTION:
                    cursor.update(event)
                    if self.tool == "Line":
                        if self.drawing and self.innerRect.collidepoint(*event.pos):
                              if self.oldpos == None:
                                 self.oldpos = event.pos
                              else:
                                # pygame.draw.circle(self.activeLayer, self.selectedColour, self.oldpos, self.toolSize, 0)
                                 r = pygame.draw.line(self.activeLayer, self.selectedColour, self.oldpos, event.pos, self.toolSize)
                                 dirtyrects.append(r)
                               #  self.activeLayer.blit(self.activeBrush, event.pos) FAILED TECHNIQUE
                                 line = ("line", self.oldpos, event.pos)
                                 self.send((line,), "outbox")
                                 self.oldpos = event.pos
                    self.blitToSurface()
         self.pause()
         pygame.time.delay(5)
         dirtyrects.extend([cursor.show()])
         pygame.display.update(dirtyrects)
         yield 1
Ejemplo n.º 30
0
    def main(self):
        """Main loop."""
        displayservice = PygameDisplay.getDisplayService()
        self.link((self,"display_signal"), displayservice)

        self.send( self.dispRequest,
                    "display_signal")

        for _ in self.waitBox("callback"): yield 1
        self.display = self.recv("callback")

        # colour buttons

        


        # Initial render so we don't see a blank screen
        self.sliderPos = self.default
        self.drawBG()
        self.render()

        self.send({"ADDLISTENEVENT" : pygame.MOUSEBUTTONDOWN,
                    "surface" : self.display},
                    "display_signal")

        self.send({"ADDLISTENEVENT" : pygame.MOUSEBUTTONUP,
                    "surface" : self.display},
                    "display_signal")

        self.send({"ADDLISTENEVENT" : pygame.MOUSEMOTION,
                    "surface" : self.display},
                    "display_signal")
        done = False
        while not done:
            if not self.anyReady():
                self.pause()
            yield 1
            while self.dataReady("control"):
                cmsg = self.recv("control")
                if (isinstance(cmsg, producerFinished)):
                    self.send(cmsg, "signal")
                    done = True

            while self.dataReady("inbox"):
                for event in self.recv("inbox"):
                    if event.type == pygame.MOUSEBUTTONDOWN:
                        if self.display.get_rect().collidepoint(*event.pos):
                            self.sliderPos = event.pos[0]
                            self.drawBG()
                            self.render()
                            self.mouseDown = True

                    if event.type == pygame.MOUSEBUTTONUP:
                        if self.mouseDown:
                            self.sliderPos = event.pos[0]
                            self.drawBG()
                            self.render()
                        self.mouseDown = False
                    
                    if event.type == pygame.MOUSEMOTION and self.mouseDown:
                        if self.display.get_rect().collidepoint(*event.pos):
                            if event.pos[0] > self.size[0] or event.pos[0] < 0:
                                self.mouseDown = False
                                break
                            self.sliderPos = event.pos[0]
                            self.drawBG()
                            self.render()
Ejemplo n.º 31
0
    def main(self):
        """Main loop."""
        #    pgd = PygameDisplay( width=300, height=550 ).activate()
        #   PygameDisplay.setDisplayService(pgd)

        displayservice = PygameDisplay.getDisplayService()
        self.link((self, "display_signal"), displayservice)

        self.send(self.dispRequest, "display_signal")

        for _ in self.waitBox("callback"):
            yield 1
        self.display = self.recv("callback")

        # colour buttons
        rgbutton = Button(caption="Red/Green",
                          position=(self.position[0],
                                    self.position[1] + self.size[1] + 5),
                          msg=("Colour", "RG")).activate()
        rbbutton = Button(caption="Red/Blue",
                          position=(self.position[0] + 70,
                                    self.position[1] + self.size[1] + 5),
                          msg=("Colour", "RB")).activate()
        gbbutton = Button(caption="Green/Blue",
                          position=(self.position[0] + 140,
                                    self.position[1] + self.size[1] + 5),
                          msg=("Colour", "GB")).activate()
        self.link((rgbutton, "outbox"), (self, "buttons"))
        self.link((rbbutton, "outbox"), (self, "buttons"))
        self.link((gbbutton, "outbox"), (self, "buttons"))

        # Initial render so we don't see a blank screen
        self.drawBG()
        #  self.render()
        if self.editable:
            self.send(
                {
                    "ADDLISTENEVENT": pygame.MOUSEBUTTONDOWN,
                    "surface": self.display
                }, "display_signal")

            self.send(
                {
                    "ADDLISTENEVENT": pygame.MOUSEBUTTONUP,
                    "surface": self.display
                }, "display_signal")

            self.send(
                {
                    "ADDLISTENEVENT": pygame.MOUSEMOTION,
                    "surface": self.display
                }, "display_signal")

        done = False
        while not done:
            if not self.anyReady():
                self.pause()
            yield 1
            while self.dataReady("buttons"):
                bmsg = self.recv("buttons")
                if bmsg[0] == "Colour":
                    self.colours = bmsg[1]
                    self.drawBG()

            while self.dataReady("control"):
                cmsg = self.recv("control")
                if (isinstance(cmsg, producerFinished)):
                    self.send(cmsg, "signal")
                    done = True

            while self.dataReady("inbox"):
                for event in self.recv("inbox"):

                    if event.type == pygame.MOUSEBUTTONDOWN:
                        if self.display.get_rect().collidepoint(*event.pos):
                            self.mouseDown = True
                            self.puckPos = event.pos
                            self.render()

                    if event.type == pygame.MOUSEBUTTONUP:
                        if self.mouseDown:
                            self.puckPos = event.pos
                            self.render()
                        self.mouseDown = False

                    if event.type == pygame.MOUSEMOTION and self.mouseDown:
                        if self.display.get_rect().collidepoint(*event.pos):
                            self.puckPos = event.pos
                            self.render()
Ejemplo n.º 32
0
   def main(self):
      """Main loop."""
      displayservice = PygameDisplay.getDisplayService()
      self.link((self,"display_signal"), displayservice)

      self.send( self.disprequest,"display_signal")

      for _ in self.waitBox("callback"): yield 1
      self.display = self.recv("callback")
      self.layers.append(self.display)
      
  #    f = os.path.join('', "pennyarcade.gif")
  #    x = pygame.image.load(f)
  #    colorkey = x.get_at((0, 0))
  #    if colorkey is True:
  #        x.set_colorkey(colorkey, pygame.RLEACCEL)
  #    self.layers.append(x)
  #    self.display = x
  #    self.activeLayIn = len(self.layers)-1
  #    self.activeLayer = self.layers[self.activeLayIn]
  #    self.display.blit( x, (0,0) )

      
      layerDisp = TextDisplayer(size = (20, 20),position = (520,10)).activate()
      self.link( (self,"laynum"), (layerDisp,"inbox") )
      self.send({ "ADDLISTENEVENT" : pygame.MOUSEBUTTONDOWN,
                  "surface" : self.display},
                  "display_signal")

      self.send({ "ADDLISTENEVENT" : pygame.MOUSEBUTTONUP,
                  "surface" : self.display},
                  "display_signal")

      self.send({ "ADDLISTENEVENT" : pygame.MOUSEMOTION,
                  "surface" : self.display},
                  "display_signal")

      self.send({ "ADDLISTENEVENT" : pygame.KEYDOWN,
		  "surface" : self.display},
		  "display_signal")
      self.activeLayer = self.layers[self.activeLayIn]
      self.send( self.activeLayIn, "laynum" )


      self.drawBG(True)
      self.blitToSurface()
      

      done = False
      while not done:
         if not self.anyReady():
             self.pause()
         yield 1
         while self.dataReady("control"):
            cmsg = self.recv("control")
            if isinstance(cmsg, producerFinished) or isinstance(cmsg, shutdownMicroprocess):
               self.send(cmsg, "signal")
               done = True

         while self.dataReady("inbox"):
            for event in self.recv("inbox"):
                if isinstance(event, tuple):
                    if event[0] == "Layer":
                        if event[1] == "Add":
                            yield WaitComplete( self.addLayer() )
                            self.activeLayIn = len(self.layers)-1
                            self.activeLayer = self.layers[self.activeLayIn]
                         #   self.send( self.activeLayIn, "laynum" )
                            self.drawBG()
                            self.blitToSurface()
                        elif event[1] == "Delete":
                            self.send( producerFinished(message=self.activeLayer),"display_signal")
                            self.layers.remove(self.activeLayer)
                            self.activeLayIn = 0
                            self.activeLayer = self.layers[self.activeLayIn]
                          #  print self.layers
                        if event[1] == "Next":
                            if self.activeLayIn == len(self.layers)-1:
                                self.activeLayIn = 0
                                self.activeLayer = self.layers[self.activeLayIn]
                            else:
                                self.activeLayIn += 1
                                self.activeLayer = self.layers[self.activeLayIn]
                        elif event[1] == "Prev":
                            if self.activeLayIn == 0:
                                self.activeLayIn = len(self.layers)-1
                                self.activeLayer = self.layers[self.activeLayIn]
                            else:
                                self.activeLayIn -= 1
                                self.activeLayer = self.layers[self.activeLayIn]
                        self.send( self.activeLayIn, "laynum" )
                    elif event[0] == "Tool":
                        self.tool = event[1]
                    elif event[0] == "Size":
                        self.toolSize = event[1]/3
                    elif event[0] == "Alpha":
                        self.layers[self.activeLayIn].set_alpha(event[1])
                        self.blitToSurface()
                      #  print self.activeLayer.get_alpha()
                    elif event[0] == 'Colour':
                        self.selectedColour = event[1]
                    break
                if event.type == pygame.MOUSEBUTTONDOWN:
                    if self.tool == "Circle":
                        if event.button == 1:
                            self.oldpos = event.pos
                            self.drawing = True
                    if self.tool == "Eraser":
                        self.selectedColour = self.backgroundColour
                        self.tool = "Line"
                    if self.tool == "Line":
                        if event.button == 1:
                            self.drawing = True
                    if self.tool == "Bucket":
                        self.floodFill(event.pos[0],event.pos[1],self.selectedColour,self.activeLayer.get_at(event.pos))
                    if self.tool == "Eyedropper":
                        self.selectedColour = self.activeLayer.get_at(event.pos)
                    if event.button == 3:
                        self.addLayer()
                        #self.oldpos = None
                        #self.drawBG()
                        #self.blitToSurface()
                        #self.send(("clear",), "outbox")
                elif event.type == (pygame.KEYDOWN):
                    if event.key == pygame.K_c:
                        image = pygame.image.load(os.path.join('', 'pennyarcade.gif'))
                        yield WaitComplete( self.addLayer() )
                        self.activeLayIn = len(self.layers)-1
                        self.activeLayer = self.layers[self.activeLayIn]
                        self.drawBG()
                        self.activeLayer.blit( image, (10,10) )
                        self.blitToSurface()
                        self.send( self.activeLayIn, "laynum" )
                    elif event.key == pygame.K_s:
                      #  temp = self.layers[0]
                        self.save("tgfdg")
                      #  self.layers.insert(0,temp)
                      #  self.drawBG()
                    elif event.key == pygame.K_l:
                        self.layers[1].blit( self.layers[1], (100,100) )
               #         temp = self.layers[1]
               #         self.layers[1].fill(self.backgroundColour)
               #         self.layers[1].blit( temp, (100,100) )
                    elif event.key == pygame.K_o:
                        move = {
                                    "CHANGEDISPLAYGEO" : True,
                                    "surface" : self.layers[1],
                                    "position" : (100,100)
                               }
                        self.send(move, "display_signal")
                                  
                       

                elif event.type == pygame.MOUSEBUTTONUP and event.button == 1:
                    if self.tool == "Circle":
                        rad = math.sqrt(((event.pos[0]-self.oldpos[0])**2)+((event.pos[1]-self.oldpos[1])**2))
                        pygame.draw.circle(self.activeLayer, self.selectedColour, self.oldpos, rad, 0)
                        circle = ("circle", self.oldpos, rad)
                        self.send((circle,), "outbox")
                        self.blitToSurface()
                    self.drawing = False
                    self.oldpos = None
                elif event.type == pygame.MOUSEMOTION:
                    if self.tool == "Line":
                        if self.drawing and self.innerRect.collidepoint(*event.pos):
                              if self.oldpos == None:
                                 self.oldpos = event.pos
                              else:
                                # pygame.draw.circle(self.activeLayer, self.selectedColour, self.oldpos, self.toolSize, 0)
                                 pygame.draw.line(self.activeLayer, self.selectedColour, self.oldpos, event.pos, self.toolSize)
                                 line = ("line", self.oldpos, event.pos)
                                 self.send((line,), "outbox")
                                 self.oldpos = event.pos
                              self.blitToSurface()
         self.pause()
         yield 1
Ejemplo n.º 33
0
from Kamaelia.Chassis.Graphline import Graphline

from Kamaelia.File.UnixProcess import UnixProcess

from Kamaelia.UI.Pygame.Display import PygameDisplay
from Kamaelia.UI.Pygame.Image import Image
from Kamaelia.UI.Pygame.Text import TextDisplayer, Textbox
from Kamaelia.Util.Console import ConsoleEchoer, ConsoleReader

from Kamaelia.Apps.Whiteboard.Canvas import Canvas
from Kamaelia.Apps.SpeakNWrite.Gestures.StrokeRecogniser import StrokeRecogniser
from Kamaelia.Apps.SpeakNWrite.Gestures.Pen import Pen

from Kamaelia.Visualisation.Axon.AxonVisualiserServer import AxonVisualiser, text_to_token_lists

pgd = PygameDisplay(width=1024, height=500).activate()
PygameDisplay.setDisplayService(pgd)

Backplane("STROKES").activate()
Backplane("CONSOLE").activate()
Backplane("AXONVIS").activate()
Backplane("AXONEVENTS").activate()
bgcolour = (255, 255, 180)

node_add_template = \
"""ADD NODE %(nodeid)s non_config randompos component
ADD NODE %(nodeid)s.o.outbox "outbox" randompos outbox
ADD NODE %(nodeid)s.o.signal "signal" randompos outbox
ADD NODE %(nodeid)s.i.inbox "inbox" randompos inbox
ADD NODE %(nodeid)s.i.control "control" randompos inbox
ADD LINK %(nodeid)s %(nodeid)s.o.outbox
Ejemplo n.º 34
0
             1, TagWithSequenceNumber(),
             1, DetectShotChanges(threshold),
             FormatOutput(),
             ConsoleEchoer(),
             StopSelector(waitForTrigger=True),
             ).run()
         
 else:
     # cut detector plus playback at the same time
     
     from Kamaelia.UI.Pygame.Display import PygameDisplay
     from Kamaelia.UI.Pygame.VideoOverlay import VideoOverlay
     from Kamaelia.Util.Backplane import Backplane,PublishTo,SubscribeTo
     from Kamaelia.Util.RateFilter import MessageRateLimit
     
     PygameDisplay.setDisplayService(PygameDisplay(width=1024,height=500).activate())
     
     Pipeline(
         UnixProcess2("ffmpeg -i "+infile +" -f yuv4mpegpipe -y /dev/stdout"),
         2, YUV4MPEGToFrame(),
         50, MessageRateLimit(25,25),
         PublishTo("VIDEO"),
         Backplane("VIDEO"),
         StopSelector(waitForTrigger=True),
         ).activate()
         
     Pipeline(
         SubscribeTo("VIDEO"),
         TagWithSequenceNumber(),
         DetectShotChanges(threshold),
         FormatOutput(),
Ejemplo n.º 35
0
#from BlankCanvas import BlankCanvas


if __name__=="__main__":
    width = 1024
    height = 768
    top = 0
    left = 0
    colours_order = [ "black", "red", "orange", "yellow", "green", "turquoise", "blue", "purple", "darkgrey", "lightgrey" ]
    ogl_display = OpenGLDisplay(title="Kamaelia Whiteboard",width=width,height=height,background_colour=(255,255,255))
    ogl_display.activate()
    OpenGLDisplay.setDisplayService(ogl_display)
    
    ogl_display = OpenGLDisplay.getDisplayService()
    PygameDisplay.setDisplayService(ogl_display[0])
    
    if (0):
        #PygameDisplay.setDisplayService(ogl_display)
        CANVAS = Canvas( position=(left,top+32),size=(1200,(900-(32+15))),notepad="Test" ).activate() #(replace width with 'width' and height with 'height-(32+15)'
        PAINTER = Painter().activate()
        CANVAS_WRAPPER = PygameWrapper(wrap=CANVAS, position=(0,0,-10), rotation=(0,0,0)).activate() 
        ERASER  = Eraser(left,top).activate()
        PALETTE = buildPalette( cols=colours, order=colours_order, topleft=(left+64,top), size=32 ).activate()
        CLEAR = ClearPage(left+(64*5)+32*len(colours),top).activate()
        #PALETTE_WRAPPER = PygameWrapper(wrap=PALETTE, position=(4,1,-10), rotation=(-20,15,3)).activate()
    
        #PAINTER_WRAPPER = PygameWrapper(wrap=PAINTER, position=(4,1,-10), rotation=(-20,15,3)).activate()
        CANVAS.link( (PAINTER,"outbox"), (CANVAS, "inbox") )
        PAINTER.link( (CANVAS,"eventsOut"), (PAINTER, "inbox") )
        PAINTER.link( (PALETTE,"outbox"), (PAINTER, "colour") )
Ejemplo n.º 36
0
    def main(self):
        """Main loop."""
        #    pgd = PygameDisplay( width=300, height=550 ).activate()
        #   PygameDisplay.setDisplayService(pgd)

        displayservice = PygameDisplay.getDisplayService()
        self.link((self, "display_signal"), displayservice)

        self.send(self.dispRequest, "display_signal")

        for _ in self.waitBox("callback"):
            yield 1
        self.display = self.recv("callback")

        # colour buttons
        if self.colourSelector:
            rgbutton = Button(caption="Red/Green",
                              position=(10, 170),
                              msg=("Colour", "RG")).activate()
            rbbutton = Button(caption="Red/Blue",
                              position=(80, 170),
                              msg=("Colour", "RB")).activate()
            gbbutton = Button(caption="Green/Blue",
                              position=(145, 170),
                              msg=("Colour", "GB")).activate()
            self.link((rgbutton, "outbox"), (self, "buttons"))
            self.link((rbbutton, "outbox"), (self, "buttons"))
            self.link((gbbutton, "outbox"), (self, "buttons"))
            # tool buttons
            circleb = Button(caption="Circle",
                             position=(10, 10),
                             msg=(("Tool", "Circle"), )).activate()
            eraseb = Button(caption="Eraser",
                            position=(100, 10),
                            msg=(("Tool", "Eraser"), )).activate()
            lineb = Button(caption="Line",
                           position=(10, 50),
                           msg=(("Tool", "Line"), )).activate()
            bucketb = Button(caption="Bucket",
                             position=(10, 90),
                             msg=(("Tool", "Bucket"), )).activate()
            eyeb = Button(caption="Eyedropper",
                          position=(10, 130),
                          msg=(("Tool", "Eyedropper"), )).activate()
            addlayerb = Button(caption="Add Layer",
                               position=(10, 540),
                               msg=(("Layer", "Add"), )).activate()
            prevlayerb = Button(caption="<-",
                                position=(80, 540),
                                msg=(("Layer", "Prev"), )).activate()
            nextlayerb = Button(caption="->",
                                position=(110, 540),
                                msg=(("Layer", "Next"), )).activate()
            dellayerb = Button(caption="Delete",
                               position=(140, 540),
                               msg=(("Layer", "Delete"), )).activate()
            self.link((circleb, "outbox"), (self, "outbox"), passthrough=2)
            self.link((eraseb, "outbox"), (self, "outbox"), passthrough=2)
            self.link((lineb, "outbox"), (self, "outbox"), passthrough=2)
            self.link((bucketb, "outbox"), (self, "outbox"), passthrough=2)
            self.link((eyeb, "outbox"), (self, "outbox"), passthrough=2)
            self.link((addlayerb, "outbox"), (self, "outbox"), passthrough=2)
            self.link((prevlayerb, "outbox"), (self, "outbox"), passthrough=2)
            self.link((nextlayerb, "outbox"), (self, "outbox"), passthrough=2)
            self.link((dellayerb, "outbox"), (self, "outbox"), passthrough=2)
            SizePicker = XYPad(size=(255, 50),
                               bouncingPuck=False,
                               position=(10, 480),
                               bgcolour=(0, 0, 0),
                               fgcolour=(255, 255, 255),
                               slider=True).activate()
            self.link((SizePicker, "outbox"), (self, "outbox"), passthrough=2)
            AlphaPicker = XYPad(size=(255, 20),
                                bouncingPuck=False,
                                position=(10, 575),
                                bgcolour=(0, 0, 0),
                                fgcolour=(255, 255, 255),
                                slider=True,
                                alpha=True).activate()
            self.link((AlphaPicker, "outbox"), (self, "outbox"), passthrough=2)

        #clock - don't really need this
        FPS = 60
        clock = Clock(float(1) / FPS).activate()
        self.link((clock, "outbox"), (self, "newframe"))

        # Initial render so we don't see a blank screen
        self.drawBG()
        #  self.render()
        if self.editable:
            self.send(
                {
                    "ADDLISTENEVENT": pygame.MOUSEBUTTONDOWN,
                    "surface": self.display
                }, "display_signal")

            self.send(
                {
                    "ADDLISTENEVENT": pygame.MOUSEBUTTONUP,
                    "surface": self.display
                }, "display_signal")

            self.send(
                {
                    "ADDLISTENEVENT": pygame.MOUSEMOTION,
                    "surface": self.display
                }, "display_signal")

        done = False
        while not done:
            if not self.anyReady():
                self.pause()
            yield 1
            while self.dataReady("buttons"):
                bmsg = self.recv("buttons")
                if bmsg[0] == "Colour":
                    self.colours = bmsg[1]
                    self.drawBG()

            while self.dataReady("control"):
                cmsg = self.recv("control")
                if (isinstance(cmsg, producerFinished)):
                    self.send(cmsg, "signal")
                    done = True

            while self.dataReady("inbox"):
                for event in self.recv("inbox"):

                    if event.type == pygame.MOUSEBUTTONDOWN:
                        self.clickTime = time.time()
                        if self.slider:
                            self.sliderPos = event.pos[0]
                            self.drawBG()
                        if self.display.get_rect().collidepoint(*event.pos):
                            self.mouseDown = True
                            self.isBouncing = False
                            self.mousePositions = []
                            self.puckVel = [0, 0]
                            self.puckPos = list(event.pos)
                            self.lastMousePos = event.pos
                            self.send(
                                (self.messagePrefix + self.positionMsg,
                                 (float(self.puckPos[0]) / self.size[0],
                                  float(self.puckPos[1]) / self.size[1])),
                                "localChanges")

                            self.send((self.messagePrefix + "Velocity",
                                       self.puckVel), "localChanges")

                    if event.type == pygame.MOUSEBUTTONUP:
                        if self.mouseDown:
                            if self.slider:
                                self.sliderPos = event.pos[0]
                                self.drawBG()
                            if (self.bouncingPuck
                                    and time.time() - self.clickTime > 0.1):
                                # Click and drag
                                self.isBouncing = True
                                if len(self.mousePositions):
                                    for i in xrange(2):
                                        # Use the average of the last 50
                                        # relative mouse positions
                                        positions = [
                                            x[i] for x in self.mousePositions
                                        ]
                                        self.puckVel[i] = sum(positions)
                                        self.puckVel[i] /= float(
                                            len(positions))
                            else:
                                # Just a click
                                self.puckVel = [0, 0]
                                self.render()
                            self.send((self.messagePrefix + "Velocity",
                                       self.puckVel), "localChanges")
                        self.mouseDown = False

                    if event.type == pygame.MOUSEMOTION and self.mouseDown:
                        if self.slider:
                            self.sliderPos = event.pos[0]
                            self.drawBG()
                        if self.display.get_rect().collidepoint(*event.pos):
                            # We are dragging inside the display
                            # Keep a buffer of 50 mouse positions
                            if len(self.mousePositions) > 50:
                                del self.mousePositions[0]
                            relPos = []
                            for i in xrange(2):
                                relPos.append(event.pos[i] -
                                              self.lastMousePos[i])
                            self.mousePositions.append(relPos)
                            # Move the puck to where the mouse is and remember
                            # where it is
                            self.puckPos = list(event.pos)
                            self.lastMousePos = event.pos
                            self.send(
                                (self.messagePrefix + self.positionMsg,
                                 (float(self.puckPos[0]) / self.size[0],
                                  float(self.puckPos[1]) / self.size[1])),
                                "localChanges")
                            self.render()

            if self.dataReady("remoteChanges"):
                bundle = self.recv("remoteChanges")
                # The action to take is given by the last section of the
                # OSC address - this should maybe be done by a component and
                # we just listen for ("Velocity", (xVel, yVel)) tuples
                action = bundle[0].split("/")[-1]
                if action == "Velocity":
                    if self.bouncingPuck:
                        self.puckVel = bundle[1]
                        self.isBouncing = 1
                elif action == "Position":
                    for i in xrange(2):
                        self.puckPos[i] = self.size[i] * bundle[1][i]
                self.render()

            if self.dataReady("newframe"):
                # Time to render a new frame
                # Clear any backlog of render messages
                while self.dataReady("newframe"):
                    self.recv("newframe")

                # Change the direction of the puck if it hits a wall
                if self.isBouncing:
                    self.processCollisions()

                if self.isBouncing:
                    # Update the position
                    for i in xrange(2):
                        self.puckPos[i] += self.puckVel[i]
                    self.render()
Ejemplo n.º 37
0
 def main(self):
     pgd = PygameDisplay(width=self.width, height=self.height).activate()
     PygameDisplay.setDisplayService(pgd)
     yield 1
Ejemplo n.º 38
0
    def main(self):
        """Main loop."""
    #    pgd = PygameDisplay( width=300, height=550 ).activate()
     #   PygameDisplay.setDisplayService(pgd)

        displayservice = PygameDisplay.getDisplayService()
        self.link((self,"display_signal"), displayservice)

        self.send( self.dispRequest,
                    "display_signal")

        for _ in self.waitBox("callback"): yield 1
        self.display = self.recv("callback")

        # colour buttons
        rgbutton = Button(caption="Red/Green",position=(self.position[0],self.position[1]+self.size[1]+5), msg = ("Colour", "RG")).activate()
        rbbutton = Button(caption="Red/Blue",position=(self.position[0]+70,self.position[1]+self.size[1]+5), msg = ("Colour", "RB")).activate()
        gbbutton = Button(caption="Green/Blue",position=(self.position[0]+140,self.position[1]+self.size[1]+5), msg = ("Colour", "GB")).activate()
        self.link( (rgbutton,"outbox"), (self,"buttons") )
        self.link( (rbbutton,"outbox"), (self,"buttons") )
        self.link( (gbbutton,"outbox"), (self,"buttons") )

        


      


        # Initial render so we don't see a blank screen
        self.drawBG()
      #  self.render()
        if self.editable:
            self.send({"ADDLISTENEVENT" : pygame.MOUSEBUTTONDOWN,
                       "surface" : self.display},
                      "display_signal")

            self.send({"ADDLISTENEVENT" : pygame.MOUSEBUTTONUP,
                       "surface" : self.display},
                      "display_signal")

            self.send({"ADDLISTENEVENT" : pygame.MOUSEMOTION,
                       "surface" : self.display},
                      "display_signal")

        done = False
        while not done:
            if not self.anyReady():
                self.pause()
            yield 1
            while self.dataReady("buttons"):
                bmsg = self.recv("buttons")
                if bmsg[0]=="Colour":
                    self.colours = bmsg[1]
                    self.drawBG()
                    
            while self.dataReady("control"):
                cmsg = self.recv("control")
                if (isinstance(cmsg, producerFinished)):
                    self.send(cmsg, "signal")
                    done = True

            while self.dataReady("inbox"):
                for event in self.recv("inbox"):

                    if event.type == pygame.MOUSEBUTTONDOWN:
                        if self.display.get_rect().collidepoint(*event.pos):
                            self.mouseDown = True
                            self.puckPos = event.pos
                            self.render()
                                    

                    if event.type == pygame.MOUSEBUTTONUP:
                        if self.mouseDown:
                            self.puckPos = event.pos
                            self.render()
                        self.mouseDown = False
                    
                    if event.type == pygame.MOUSEMOTION and self.mouseDown:
                        if self.display.get_rect().collidepoint(*event.pos):
                            self.puckPos = event.pos
                            self.render()
Ejemplo n.º 39
0
    def main(self):
        """Main loop."""
    #    pgd = PygameDisplay( width=300, height=550 ).activate()
     #   PygameDisplay.setDisplayService(pgd)

        displayservice = PygameDisplay.getDisplayService()
        self.link((self,"display_signal"), displayservice)

        self.send( self.dispRequest,
                    "display_signal")

        for _ in self.waitBox("callback"): yield 1
        self.display = self.recv("callback")

        # colour buttons
        rgbutton = ImageButton(caption=(os.path.join('icons', 'RedGreenIcon.png')),position=(self.position[0],self.position[1]+self.size[1]+5), msg = ("ColourCombi", "RG"), size = (20,20)).activate()
        rbbutton = ImageButton(caption=(os.path.join('icons', 'RedBlueIcon.png')),position=(self.position[0]+35,self.position[1]+self.size[1]+5), msg = ("ColourCombi", "RB"), size = (20,20)).activate()
        gbbutton = ImageButton(caption=(os.path.join('icons', 'GreenBlueIcon.png')),position=(self.position[0]+70,self.position[1]+self.size[1]+5), msg = ("ColourCombi", "GB"), size = (20,20)).activate()
        self.link( (rgbutton,"outbox"), (self,"buttons") )
        self.link( (rbbutton,"outbox"), (self,"buttons") )
        self.link( (gbbutton,"outbox"), (self,"buttons") )
        # saturator
        saturator = Slider(vertical = True, saturator = True, messagePrefix= "Colour", size=(10,255), position=(self.position[0]+self.size[0]+5,self.position[1] )).activate()
        self.link( (self,"saturator"), (saturator,"colours") )
        self.link( (saturator,"outbox"), (self,"outbox"), passthrough = 2 )


      


        # Initial render so we don't see a blank screen
        self.drawBG()
      #  self.render()
        if self.editable:
            self.send({"ADDLISTENEVENT" : pygame.MOUSEBUTTONDOWN,
                       "surface" : self.display},
                      "display_signal")

            self.send({"ADDLISTENEVENT" : pygame.MOUSEBUTTONUP,
                       "surface" : self.display},
                      "display_signal")

            self.send({"ADDLISTENEVENT" : pygame.MOUSEMOTION,
                       "surface" : self.display},
                      "display_signal")

        done = False
        while not done:
            if not self.anyReady():
                self.pause()
            yield 1
            while self.dataReady("buttons"):
                bmsg = self.recv("buttons")
                if bmsg[0]=="ColourCombi":
                    self.colours = bmsg[1]
                    self.send(bmsg, "saturator")
                    self.drawBG()
                    
            while self.dataReady("control"):
                cmsg = self.recv("control")
                if (isinstance(cmsg, producerFinished)):
                    self.send(cmsg, "signal")
                    done = True

            while self.dataReady("inbox"):
                for event in self.recv("inbox"):

                    if event.type == pygame.MOUSEBUTTONDOWN:
                        if self.display.get_rect().collidepoint(*event.pos):
                            self.mouseDown = True
                            self.puckPos = event.pos
                            self.render()
                                    

                    if event.type == pygame.MOUSEBUTTONUP and self.mouseDown:
                        if self.mouseDown:
                            self.puckPos = event.pos
                            self.render()
                        self.mouseDown = False
                    
                    if event.type == pygame.MOUSEMOTION and self.mouseDown:
                        if self.display.get_rect().collidepoint(*event.pos):
                            self.puckPos = event.pos
                            self.render()
                        else: self.mouseDown = False
Ejemplo n.º 40
0
    def main(self):
        """Main loop."""
        #    pgd = PygameDisplay( width=300, height=550 ).activate()
        #   PygameDisplay.setDisplayService(pgd)

        displayservice = PygameDisplay.getDisplayService()
        self.link((self, "display_signal"), displayservice)

        self.send(self.dispRequest, "display_signal")

        for _ in self.waitBox("callback"):
            yield 1
        self.display = self.recv("callback")

        # colour buttons
        rgbutton = ImageButton(caption=(os.path.join('icons',
                                                     'RedGreenIcon.png')),
                               position=(self.position[0],
                                         self.position[1] + self.size[1] + 5),
                               msg=("ColourCombi", "RG"),
                               size=(20, 20)).activate()
        rbbutton = ImageButton(caption=(os.path.join('icons',
                                                     'RedBlueIcon.png')),
                               position=(self.position[0] + 35,
                                         self.position[1] + self.size[1] + 5),
                               msg=("ColourCombi", "RB"),
                               size=(20, 20)).activate()
        gbbutton = ImageButton(caption=(os.path.join('icons',
                                                     'GreenBlueIcon.png')),
                               position=(self.position[0] + 70,
                                         self.position[1] + self.size[1] + 5),
                               msg=("ColourCombi", "GB"),
                               size=(20, 20)).activate()
        self.link((rgbutton, "outbox"), (self, "buttons"))
        self.link((rbbutton, "outbox"), (self, "buttons"))
        self.link((gbbutton, "outbox"), (self, "buttons"))
        # saturator
        saturator = Slider(vertical=True,
                           saturator=True,
                           messagePrefix="Colour",
                           size=(10, 255),
                           position=(self.position[0] + self.size[0] + 5,
                                     self.position[1])).activate()
        self.link((self, "saturator"), (saturator, "colours"))
        self.link((saturator, "outbox"), (self, "outbox"), passthrough=2)

        # Initial render so we don't see a blank screen
        self.drawBG()
        #  self.render()
        if self.editable:
            self.send(
                {
                    "ADDLISTENEVENT": pygame.MOUSEBUTTONDOWN,
                    "surface": self.display
                }, "display_signal")

            self.send(
                {
                    "ADDLISTENEVENT": pygame.MOUSEBUTTONUP,
                    "surface": self.display
                }, "display_signal")

            self.send(
                {
                    "ADDLISTENEVENT": pygame.MOUSEMOTION,
                    "surface": self.display
                }, "display_signal")

        done = False
        while not done:
            if not self.anyReady():
                self.pause()
            yield 1
            while self.dataReady("buttons"):
                bmsg = self.recv("buttons")
                if bmsg[0] == "ColourCombi":
                    self.colours = bmsg[1]
                    self.send(bmsg, "saturator")
                    self.drawBG()

            while self.dataReady("control"):
                cmsg = self.recv("control")
                if (isinstance(cmsg, producerFinished)):
                    self.send(cmsg, "signal")
                    done = True

            while self.dataReady("inbox"):
                for event in self.recv("inbox"):

                    if event.type == pygame.MOUSEBUTTONDOWN:
                        if self.display.get_rect().collidepoint(*event.pos):
                            self.mouseDown = True
                            self.puckPos = event.pos
                            self.render()

                    if event.type == pygame.MOUSEBUTTONUP and self.mouseDown:
                        if self.mouseDown:
                            self.puckPos = event.pos
                            self.render()
                        self.mouseDown = False

                    if event.type == pygame.MOUSEMOTION and self.mouseDown:
                        if self.display.get_rect().collidepoint(*event.pos):
                            self.puckPos = event.pos
                            self.render()
                        else:
                            self.mouseDown = False