Exemple #1
0
def makeBasicSketcher(left=0, top=0, width=1024, height=768):
    return Graphline(
        CANVAS=Canvas(position=(left, top + 32), size=(width, height - 32)),
        PAINTER=Painter(),
        PALETTE=buildPalette(cols=colours,
                             order=colours_order,
                             topleft=(left + 64, top),
                             size=32),
        ERASER=Button(caption="Eraser", size=(64, 32), position=(left, top)),
        LOAD=Button(caption="LOAD",
                    size=(63, 32),
                    position=(left + 64 + 32 * len(colours), top),
                    msg=[["LOAD", "default.png"]]),
        SAVE=Button(caption="SAVE",
                    size=(63, 32),
                    position=(left + (64 * 2) + 32 * len(colours), top),
                    msg=[["SAVE", "default.png"]]),
        SPLIT=TwoWaySplitter(),
        linkages={
            ("CANVAS", "eventsOut"): ("PAINTER", "inbox"),
            ("PALETTE", "outbox"): ("PAINTER", "colour"),
            ("ERASER", "outbox"): ("PAINTER", "erase"),
            ("LOAD", "outbox"): ("CANVAS", "inbox"),
            ("SAVE", "outbox"): ("CANVAS", "inbox"),
            ("PAINTER", "outbox"): ("SPLIT", "inbox"),
            ("SPLIT", "outbox"): ("CANVAS", "inbox"),
            ("self", "inbox"): ("CANVAS", "inbox"),
            ("SPLIT", "outbox2"): ("self", "outbox"),
            ("CANVAS", "outbox"): ("self", "outbox"),
        },
    )
Exemple #2
0
def LocalPagingControls(left, top):
    return Graphline(REMOTEPREV=Button(caption="~~<<~~",
                                       size=(63, 32),
                                       position=(left, top),
                                       msg=[['prev']]),
                     REMOTENEXT=Button(caption="~~>>~~",
                                       size=(63, 32),
                                       position=(left + 64, top),
                                       msg=[['next']]),
                     linkages={
                         ("REMOTEPREV", "outbox"): ("self", "outbox"),
                         ("REMOTENEXT", "outbox"): ("self", "outbox"),
                     })
Exemple #3
0
def buildPalette(cols, order, topleft=(0,0), size=32):
    buttons = {}
    links = {}
    pos = topleft
    i=0
    # Interesting/neat trick MPS
    for col in order:
        buttons[col] = Button(caption="", position=pos, size=(size,size), bgcolour=cols[col], msg=cols[col])
        links[ (col,"outbox") ] = ("self","outbox")
        pos = (pos[0] + size, pos[1])
        i=i+1
    return Graphline( linkages = links,  **buttons )
Exemple #4
0
def PagingControls(left, top):
    return Graphline(PREV=Button(caption="<<",
                                 size=(63, 32),
                                 position=(left, top),
                                 msg='prev'),
                     NEXT=Button(caption=">>",
                                 size=(63, 32),
                                 position=(left + 64, top),
                                 msg='next'),
                     CHECKPOINT=Button(caption="Checkpoint",
                                       size=(63, 32),
                                       position=(left + 128, top),
                                       msg="checkpoint"),
                     NEWPAGE=Button(caption="New Page",
                                    size=(63, 32),
                                    position=(left + 192, top),
                                    msg="new"),
                     linkages={
                         ("PREV", "outbox"): ("self", "outbox"),
                         ("NEXT", "outbox"): ("self", "outbox"),
                         ("CHECKPOINT", "outbox"): ("self", "outbox"),
                         ("NEWPAGE", "outbox"): ("self", "outbox"),
                     })
Exemple #5
0
       """Pre-render the image to go on the button label."""
       #TODO: render an image to the button instead of the caption
       self.image = pygame.image.load(text)
      
       (w,h) = self.image.get_size()
       if not self.size:
           self.size = (w + 2*self.margin, h + 2*self.margin)
           self.imagePosition = (self.margin, self.margin)
       else:
           self.imagePosition = ( (self.size[0]-w)/2, (self.size[1]-h)/2 )

__kamaelia_components__  = ( ImageButton, )


if __name__ == "__main__":
    from pygame.locals import *
    from Kamaelia.Chassis.PAR import PAR
    from Kamaelia.Chassis.Pipeline import Pipeline
    from Kamaelia.Util.Console import ConsoleEchoer
   
    import os
    Pipeline(
        PAR(
            ImageButton(caption='../../../Examples/SupportingMediaFiles/cat-logo.png',key=K_SPACE,msg="cat"),
            Button(caption="Press SPACE or click",key=K_SPACE, msg="space"),
            Button(caption="Reverse colours",fgcolour=(255,255,255),bgcolour=(0,0,0), msg="reverse"),
            Button(caption="Mary...",msg="Mary had a little lamb", position=(200,100)),
        ),
        ConsoleEchoer(),
    ).run()
Exemple #6
0
                    if command[0] == "DEL":
                        if selected:
                            nodeId = nodeId + 1
                            self.send(["del", "node", selected], "outbox")
                    if command[0] == "RELABEL":
                        if selected:
                            randomword = l[random.randint(0,
                                                          len(l) - 1)].strip()
                            self.send(["relabel", selected, randomword],
                                      "outbox")
                            self.send(["select", selected], "outbox")
                yield 1

    Graphline(SOURCE=Source(iterable=relabel_commands, delay=0.3),
              CLEAR=Button(caption="Clear",
                           msg=["del", "all"],
                           position=(0, 690),
                           size=(64, 32)),
              ADD=Button(caption="Add Child Node",
                         msg=["ADD"],
                         position=(70, 690),
                         size=(94, 32)),
              DEL=Button(caption="Del Node",
                         msg=["DEL"],
                         position=(170, 690),
                         size=(64, 32)),
              RELABEL=Button(caption="Relabel Node",
                             msg=["RELABEL"],
                             position=(240, 690),
                             size=(94, 32)),
              CORELOGIC=CoreLogic(),
              TOPOLOGY=MyFoo(),
Exemple #7
0
def calibButton(left, top):
    return Button(caption="Calibrate", size=(63, 32), position=(left, top))
Exemple #8
0
    ).activate()

    #
    # Debugging console
    #
    from Kamaelia.Util.Console import ConsoleReader
    from Kamaelia.Visualisation.Axon.AxonVisualiserServer import text_to_token_lists
    Pipeline(ConsoleReader(), text_to_token_lists(),
             PublishTo("VisualiserControl")).activate()

    Graphline(SEMANTIC_EVENTS=SubscribeTo("Panel_Events"),
              SELECTION_EVENTS=SubscribeTo("VisualiserEvents"),
              TOPOLOGY_VISUALISER=PublishTo("VisualiserControl"),
              CODE_DISPLAY=PublishTo("Display"),
              MAKELINK=Button(caption="make link",
                              size=(63, 32),
                              position=(800, 0),
                              msg="LINK"),
              CENTRAL_CONTROL=Magic(),
              CODE_GENERATOR=CodeGen(),
              linkages={
                  ("SEMANTIC_EVENTS", "outbox"):
                  ("CENTRAL_CONTROL", "from_panel"),
                  ("SELECTION_EVENTS", "outbox"):
                  ("CENTRAL_CONTROL", "from_topology"),
                  ("MAKELINK", "outbox"): ("CENTRAL_CONTROL", "makelink"),
                  ("CENTRAL_CONTROL", "to_topology"):
                  ("TOPOLOGY_VISUALISER", "inbox"),
                  ("CENTRAL_CONTROL", "to_serialiser"):
                  ("CODE_GENERATOR", "inbox"),
                  ("CODE_GENERATOR", "outbox"): ("CODE_DISPLAY", "inbox"),
              }).run()
Exemple #9
0
).activate()

R_ = PygameWrapper(wrap=READER, position=(-2, -2, -10),
                   rotation=(20, 10, 0)).activate()

W_ = PygameWrapper(wrap=WRITER, position=(2, 2, -10),
                   rotation=(20, 10, 0)).activate()

S_ = PygameWrapper(wrap=SCREEN, position=(-2, 2, -10),
                   rotation=(20, 10, 0)).activate()

i1 = MatchedTranslationInteractor(target=R_).activate()
i2 = MatchedTranslationInteractor(target=W_).activate()
i3 = MatchedTranslationInteractor(target=S_).activate()

button1 = Button(caption="QUIT", msg="QUIT").activate()


class Quitter(Axon.Component.component):
    def main(self):
        self.pause()
        yield 1
        self.scheduler.stop()


Pipeline(
    READER,
    WRITER,
).activate()

Pipeline(
Exemple #10
0
                  render_right=350,
                  render_top=0,
                  render_bottom=250).activate()
 TICKER1WRAPPER = PygameWrapperPlane(wrap=TICKER1,
                                     pos=Vector(-2, 1, -10),
                                     name="1st Wrapper Plane").activate()
 TICKER2 = Ticker(position=(400, 300),
                  render_left=0,
                  render_right=350,
                  render_top=0,
                  render_bottom=250).activate()
 TICKER2WRAPPER = PygameWrapperPlane(wrap=TICKER2,
                                     pos=Vector(2, 1, -10),
                                     name="2nd Wrapper Plane").activate()
 BUTTON = Button(caption="This button...",
                 msg="...can be moved AND activated!",
                 key=pygame.K_SPACE).activate()
 BUTTONWRAPPER = PygameWrapperPlane(wrap=BUTTON,
                                    pos=Vector(0, 1.5, -5),
                                    name="2nd Wrapper Plane").activate()
 MAGNADOODLE = MagnaDoodle(size=(255, 255)).activate()
 MAGNADOODLEWRAPPER = PygameWrapperPlane(
     wrap=MAGNADOODLE,
     pos=Vector(-2, -2, -10),
     name="Magna Doodle Wrapper Plane").activate()
 ECHO = consoleEchoer().activate()
 CUBE = SimpleCube(pos=Vector(2, -2, -10)).activate()
 CUBEROTATOR = CubeRotator().activate()
 TICKER1WRAPPER.link((TICKER1WRAPPER, "outbox"), (TICKER2, "inbox"))
 TICKER2WRAPPER.link((TICKER2WRAPPER, "outbox"), (TICKER2, "inbox"))
 BUTTON.link((BUTTON, "outbox"), (TICKER2, "inbox"))
Exemple #11
0
def SaveDeck(left, top):
    return Button(caption="Save Deck",
                  size=(63, 32),
                  position=(left, top),
                  msg="savedeck")
Exemple #12
0
def ClearPage(left, top):
    return Button(caption="Clear",
                  size=(63, 32),
                  position=(left, top),
                  msg=[["clear"]])
Exemple #13
0
def Eraser(left, top):
    return Button(caption="Eraser", size=(64, 32), position=(left, top))
Exemple #14
0
def Quit(left, top):
    return Button(caption="Quit",
                  size=(63, 32),
                  position=(left, top),
                  msg="quit")
Exemple #15
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()
Exemple #16
0
                n = n + 1

            if self.dataReady("delnode"):
                self.recv("delnode")
                if node is not None:
                    self.send(("DEL", "NODE", node), "nodeevents")

            if self.dataReady("linknode"):
                self.recv("linknode")
                if node is not None:
                    linkstart = node
                    linkmode = True


TVC = TopologyViewerComponent(position=(0, 0)).activate()
Graphline(NEW=Button(caption="New Component", msg="NEXT", position=(72, 8)),
          EDIT=Button(caption="Edit Component", msg="NEXT", position=(182, 8)),
          DEL=Button(caption="Delete Component", msg="NEXT",
                     position=(292, 8)),
          LINK=Button(caption="Make Link", msg="NEXT", position=(402, 8)),
          CONSOLEINPUT=pipeline(
              ConsoleReader(">>> "),
              chunks_to_lines(),
              lines_to_tokenlists(),
          ),
          EDITOR_LOGIC=EditorLogic(),
          DEBUG=ConsoleEchoer(),
          TVC=TVC,
          linkages={
              ("CONSOLEINPUT", "outbox"): ("TVC", "inbox"),
              ("NEW", "outbox"): ("EDITOR_LOGIC", "newnode"),
Exemple #17
0
def LoadDeck(left, top):
    return Button(caption="Load Deck",
                  size=(63, 32),
                  position=(left, top),
                  msg="loaddeck")
Exemple #18
0
Backplane("VIS").activate()
Backplane("UI_Events").activate()

X = Pipeline(
    SubscribeTo("VIS"),
    chunks_to_lines(),
    lines_to_tokenlists(),
    AxonVisualiser(position=(0,0)),
    ConsoleEchoer(forwarder=True),
    PublishTo("UI_Events"),
).activate()


Graphline(
    EXAMPLE = example,
    ADDASSET =  Button(caption="ADD ASSET", position=(800, 20), msg='add'),
    LINKER = Button(caption="LINK", position=(800, 53), msg=("MAKELINKTO",) ),
    
    EVENTS = SubscribeTo("UI_Events"),
    MAGIC = Magic(),
    ASSETS = AssetManager(),
    CONTROL = PublishTo("VIS"),
    linkages = {
        ("EVENTS","outbox") : ("MAGIC","nodeselect"),
        ("LINKER","outbox") : ("MAGIC","makelink"),
        ("ADDASSET","outbox") : ("ASSETS","inbox"),
        ("MAGIC","outbox")   : ("CONTROL","inbox"),
        ("ASSETS","outbox")  : ("CONTROL","inbox"),
        ("EXAMPLE","outbox") : ("CONTROL","inbox"), # This can be removed at a later date
    }
).activate()
Exemple #19
0
def ClearScribbles(left, top):
    return Button(caption="Close Deck",
                  size=(63, 32),
                  position=(left, top),
                  msg="clearscribbles")
Exemple #20
0
    from Kamaelia.Util.ConsoleEcho import consoleEchoer
    from Kamaelia.Util.Graphline import Graphline
    from Kamaelia.UI.Pygame.Button import Button
    from Kamaelia.UI.Pygame.Ticker import Ticker
    from SimpleCube import SimpleCube
    from TexPlane import TexPlane
    from pygame.locals import *

    Display3D.getDisplayService()[0].overridePygameDisplay()

    Graphline(CUBE=SimpleCube(pos=Vector(3, 3, -15)),
              PLANE=TexPlane(pos=Vector(-3, 0, -10),
                             tex="Kamaelia.png",
                             name="1st Tex Plane"),
              BUTTON1=Button(caption="Press SPACE or click", key=K_SPACE),
              BUTTON2=Button(caption="Reverse colours",
                             fgcolour=(255, 255, 255),
                             bgcolour=(0, 0, 0)),
              BUTTON3=Button(caption="Mary...",
                             msg="Mary had a little lamb",
                             position=(200, 100)),
              ROTATOR=CubeRotator(),
              MOVER=CubeMover(),
              BUZZER=CubeBuzzer(),
              ECHO=consoleEchoer(),
              TICKER=Ticker(position=(400, 300),
                            render_left=0,
                            render_right=350,
                            render_top=0,
                            render_bottom=257),
Exemple #21
0
def Delete(left, top):
    return Button(caption="Delete Slide",
                  size=(63, 32),
                  position=(left, top),
                  msg="delete")
Exemple #22
0
                        self.send(["select", selected], "outbox")
            yield 1


import Shard
import LoopShard
import ComponentShard

items = [
    Shard.shard, Shard.docShard, LoopShard.forShard, LoopShard.whileShard,
    ComponentShard.componentShard
]

Graphline(
    CLEAR=Button(caption="Clear",
                 msg=["del", "all"],
                 position=(0, 690),
                 size=(64, 32)),
    GEN=Button(caption="Generate",
               msg=["GEN"],
               position=(70, 690),
               size=(64, 32)),
    DEL=Button(caption="Del Node",
               msg=["DEL"],
               position=(140, 690),
               size=(64, 32)),
    RELABEL=Button(caption="Relabel Node",
                   msg=["RELABEL"],
                   position=(210, 690),
                   size=(94, 32)),
    CORELOGIC=CoreLogic(),
    TOPOLOGY=MyBoxes(),
Exemple #23
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()
Exemple #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 = 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
Exemple #25
0
# -------------------------------------------------------------------------
#

from Kamaelia.UI.Pygame.Button import Button
from Kamaelia.Util.Chooser import Chooser
from Kamaelia.Visualisation.PhysicsGraph.lines_to_tokenlists import lines_to_tokenlists
from Kamaelia.Visualisation.PhysicsGraph.TopologyViewer import TopologyViewer
from Kamaelia.Chassis.Pipeline import Pipeline

graph = """\

ADD NODE TCPClient TCPClient auto -
ADD NODE VorbisDecode VorbisDecode auto -
ADD NODE AOPlayer AOPlayer auto -
ADD LINK TCPClient VorbisDecode
ADD LINK VorbisDecode AOPlayer
ADD NODE Multicast_Transceiver Multicast_Transceiver auto -
ADD NODE detuple detuple auto -
ADD LINK Multicast_Transceiver detuple
DEL NODE TCPClient
ADD LINK detuple VorbisDecode
DEL ALL
""".split("\n")

Pipeline(
     Button(caption="Next", msg="NEXT", position=(72,8)),
     Chooser(items = graph),
     lines_to_tokenlists(),
     TopologyViewer(transparency = (255,255,255), showGrid = False),
).run()
Exemple #26
0
#files = os.listdir(path)
#files = [ os.path.join(path,fname) for fname in files if fname[-len(extn):]==extn ]
#files.sort()

allfiles = os.listdir(path)
files = list()
for fname in allfiles:
    if fname[-len(extn):] == extn:
        files.append(os.path.join(path, fname))

files.sort()

Graphline(CHOOSER=Chooser(items=files),
          IMAGE=Image(size=(800, 600), position=(0, 0)),
          NEXT=Button(caption="Next",
                      msg="NEXT",
                      position=(64, 0),
                      transparent=True),
          PREVIOUS=Button(caption="Previous",
                          msg="PREV",
                          position=(0, 0),
                          transparent=True),
          FIRST=Button(caption="First",
                       msg="FIRST",
                       position=(256, 0),
                       transparent=True),
          LAST=Button(caption="Last",
                      msg="LAST",
                      position=(320, 0),
                      transparent=True),
          linkages={
              ("NEXT", "outbox"): ("CHOOSER", "inbox"),
Exemple #27
0
                              laws=AxonLaws(),
                              particleTypes=particleTypes)

SANDBOX = Sandbox()

Graphline(CONSOLEINPUT=pipeline(
    ConsoleReader(">>> "),
    chunks_to_lines(),
    lines_to_tokenlists(),
),
          DEBUG=ConsoleEchoer(forwarder=True),
          TVC=TVC,
          INTROSPECTOR=pipeline(Introspector(SANDBOX), chunks_to_lines(),
                                lines_to_tokenlists()),
          SANDBOX=SANDBOX,
          NEW=Button(caption="New Component", msg="NEXT", position=(8, 8)),
          CHANGE=Button(caption="Change Component",
                        msg="NEXT",
                        position=(128, 8)),
          DEL=Button(caption="Delete Component", msg="NEXT",
                     position=(256, 8)),
          LINK=Button(caption="Make Link", msg="NEXT", position=(402, 8)),
          UNLINK=Button(caption="Break Link", msg="NEXT", position=(480, 8)),
          GO=Button(caption="Activate!", msg="NEXT", position=(590, 8)),
          EDITOR_LOGIC=EditorLogic(),
          CED=ComponentEditor(classes),
          linkages={
              ("CONSOLEINPUT", "outbox"): ("SANDBOX", "inbox"),
              ("LINK", "outbox"): ("EDITOR_LOGIC", "linknode"),
              ("UNLINK", "outbox"): ("EDITOR_LOGIC", "unlinknode"),
              ("CHANGE", "outbox"): ("EDITOR_LOGIC", "changenode"),
Exemple #28
0
path = "Slides"
extn = ".gif"
allfiles = os.listdir(path)
files = list()
K_esc = 27
for fname in allfiles:
    if fname[-len(extn):] == extn:
        files.append(os.path.join(path, fname))

files.sort()

g = Graphline(
    CHOOSER=Chooser(items=files),
    IMAGE=Image(size=(800, 600), position=(8, 48)),
    NEXT=Button(caption="Next", msg="NEXT", position=(72, 8)),
    PREVIOUS=Button(caption="Previous", msg="PREV", position=(8, 8)),
    FIRST=Button(caption="First", msg="FIRST", position=(256, 8)),
    LAST=Button(caption="Last", msg="LAST", position=(320, 8)),
    RANDOM=Button(caption="Random", msg="RANDOM", position=(500, 8)),
    #KeyEvent stuff
    keys=KeyEvent(key_events={K_esc: (shutdownMicroprocess(), "outbox")}),
    output=ConsoleEchoer(),
    linkages={
        ("NEXT", "outbox"): ("CHOOSER", "inbox"),
        ("PREVIOUS", "outbox"): ("CHOOSER", "inbox"),
        ("FIRST", "outbox"): ("CHOOSER", "inbox"),
        ("LAST", "outbox"): ("CHOOSER", "inbox"),
        ("RANDOM", "outbox"): ("CHOOSER", "inbox"),
        ("CHOOSER", "outbox"): ("IMAGE", "inbox"),
        #	("keys", "outbox") : ("output", "inbox")
Exemple #29
0
def makeBasicSketcher(left=0,top=0,width=1024,height=768):
    return Graphline( CANVAS  = Canvas( position=(left,top+32),
                                        size=(width,height-32),
                                        displayExtra={ "transparency" : (255,255,255) },
                                      ),
                      PAINTER = Painter(),
                      PALETTE = buildPalette( cols=colours, order=colours_order, topleft=(left+64,top), size=32 ),
                      ERASER  = Button(caption="Eraser", size=(64,32), position=(left,top)),

                      PREV  = Button(caption="<<",
                                     size=(63,32), 
                                     position=(left+64+32*len(colours), top),
                                     msg='prev'),
                      NEXT  = Button(caption=">>",
                                     size=(63,32), 
                                     position=(left+(64*2)+32*len(colours), top),
                                     msg='next'),
                      CHECKPOINT  = Button(caption="checkpoint",
                                     size=(63,32),
                                     position=(left+(64*3)+32*len(colours), top),
                                     msg="checkpoint"),
                      CLEAR  = Button(caption="clear",
                                     size=(63,32),
                                     position=(left+(64*4)+32*len(colours), top),
                                     msg=[["clear"]]),
                      NEWPAGE  = Button(caption="new page",
                                     size=(63,32),
                                     position=(left+(64*5)+32*len(colours), top),
                                     msg="new"),

                      REMOTEPREV  = Button(caption="~~<<~~",
                                     size=(63,32), 
                                     position=(left+(64*6)+32*len(colours), top),
                                     msg=[['prev']]),
                      REMOTENEXT  = Button(caption="~~>>~~",
                                     size=(63,32), 
                                     position=(left+(64*7)+32*len(colours), top),
                                     msg=[['next']]),

                      PREFILTER = PreFilter(),

                      HISTORY = CheckpointSequencer(lambda X: [["LOAD", "Scribbles/slide.%d.png" % (X,)]],
                                                    lambda X: [["SAVE", "Scribbles//slide.%d.png" % (X,)]],
                                                    lambda X: [["CLEAR"]],
                                                    initial = 1,
                                                    highest = num_pages,
                                ),

                      SPLIT   = TwoWaySplitter(),
                      SPLIT2  = TwoWaySplitter(),
                      DEBUG   = ConsoleEchoer(),

                      linkages = {
                          ("CANVAS",  "eventsOut") : ("PAINTER", "inbox"),
                          ("PALETTE", "outbox")    : ("PAINTER", "colour"),
                          ("ERASER", "outbox")     : ("PAINTER", "erase"),

                          ("CLEAR","outbox")       : ("CANVAS", "inbox"),
                          ("NEWPAGE","outbox")     : ("HISTORY", "inbox"),

#                          ("REMOTEPREV","outbox")  : ("self", "outbox"),
#                          ("REMOTENEXT","outbox")  : ("self", "outbox"),
                          ("REMOTEPREV","outbox")  : ("SPLIT2", "inbox"),
                          ("REMOTENEXT","outbox")  : ("SPLIT2", "inbox"),

                          ("SPLIT2", "outbox")      : ("PREFILTER", "inbox"),
                          ("SPLIT2", "outbox2")     : ("self", "outbox"), # send to network


                          ("PREV","outbox")        : ("HISTORY", "inbox"),
                          ("NEXT","outbox")        : ("HISTORY", "inbox"),
                          ("CHECKPOINT","outbox")  : ("HISTORY", "inbox"),
                          ("HISTORY","outbox")     : ("CANVAS", "inbox"),

                          ("PAINTER", "outbox")    : ("SPLIT", "inbox"),
                          ("SPLIT", "outbox")      : ("CANVAS", "inbox"),
                          ("SPLIT", "outbox2")     : ("self", "outbox"), # send to network

                          ("self", "inbox")        : ("PREFILTER", "inbox"),
                          ("PREFILTER", "outbox")  : ("CANVAS", "inbox"),
                          ("PREFILTER", "history_event")  : ("HISTORY", "inbox"),
                          ("CANVAS", "outbox")     : ("self", "outbox"),

                          ("CANVAS","surfacechanged") : ("HISTORY", "inbox"),
                          },
                    )
Exemple #30
0
import pypm
import Axon
from Kamaelia.Chassis.Graphline import Graphline
from Kamaelia.UI.Pygame.Button import Button


class MidiTest(Axon.Component.component):
    def __init__(self, port_number):
        super(MidiTest, self).__init__()
        pypm.Initialize()
        self.output = pypm.Output(port_number, 0)

    def main(self):
        while 1:
            if self.dataReady("inbox"):
                #Note on (with note num from inbox) if we get data
                self.output.WriteShort(0x90, self.recv("inbox"), 127)
            yield 1


if __name__ == "__main__":
    Graphline(bd=Button(caption="BD", msg=36, position=(0, 0)),
              sd=Button(caption="SD", msg=38, position=(50, 0)),
              hh=Button(caption="HH", msg=46, position=(100, 0)),
              midi_out=MidiTest(0),
              linkages={
                  ("bd", "outbox"): ("midi_out", "inbox"),
                  ("hh", "outbox"): ("midi_out", "inbox"),
                  ("sd", "outbox"): ("midi_out", "inbox"),
              }).run()
    from Kamaelia.UI.Pygame.Ticker import Ticker
    from Kamaelia.UI.Pygame.Button import Button
    from SimpleCube import *
    import sys;
    sys.path.append("../pygame/")
    from MagnaDoodle import *
    sys.path.append("../../MPS/Systems/Paint/")
    from Paint import *

    Display3D.getDisplayService()[0].overridePygameDisplay()
   
    TEXT = datasource().activate()
    TICKER1 = Ticker(position = (400, 300), render_left = 0, render_right=350, render_top=0, render_bottom=250).activate()
    TICKER1WRAPPER = PygameWrapperPlane(wrap=TICKER1, pos=Vector(-2, 1,-10), name="1st Wrapper Plane").activate()
    TICKER2 = Ticker(position = (400, 300), render_left = 0, render_right=350, render_top=0, render_bottom=250).activate()
    TICKER2WRAPPER = PygameWrapperPlane(wrap=TICKER2, pos=Vector(2, 1,-10),  name="2nd Wrapper Plane").activate()
    BUTTON = Button(caption="This button...",msg="...can be moved AND activated!", key=pygame.K_SPACE).activate()
    BUTTONWRAPPER = PygameWrapperPlane(wrap=BUTTON, pos=Vector(0, 1.5,-5),  name="2nd Wrapper Plane").activate()
    MAGNADOODLE = MagnaDoodle(size=(255,255)).activate()
    MAGNADOODLEWRAPPER = PygameWrapperPlane(wrap=MAGNADOODLE, pos=Vector(-2, -2,-10),  name="Magna Doodle Wrapper Plane").activate() 
    ECHO = consoleEchoer().activate()
    CUBE = SimpleCube(pos = Vector(2,-2,-10)).activate()
    CUBEROTATOR = CubeRotator().activate()
    TICKER1WRAPPER.link((TICKER1WRAPPER, "outbox"), (TICKER2, "inbox"))
    TICKER2WRAPPER.link((TICKER2WRAPPER, "outbox"), (TICKER2, "inbox"))
    BUTTON.link((BUTTON, "outbox"), (TICKER2, "inbox"))
    TEXT.link((TEXT, "outbox"), (TICKER1, "inbox"))
    CUBEROTATOR.link((CUBEROTATOR,"outbox"), (CUBE, "control3d"))
        
    Axon.Scheduler.scheduler.run.runThreads()