示例#1
0
    def ExitingSnippet(self):

        if g.getxy() == "":
            return None

        xs, ys = g.getxy().split()
        x = int(xs)
        y = int(ys)

        for i, j in XYIterator():
            key = CellKeyFromXY(x + i, y + j)
            if key in self.smarCells:
                return self.snippets[self.smarCells[key]]

        return None
示例#2
0
def UpdateMove(d, w, h, x0, y0, p, t):
   
   under = d[0]
   obj = d[1]
   x = d[2]
   y = d[3]
   
   
   if under != -1:
      ClearRect(x - w, y - h, 2 * w + 1, 2 * h + 1)
      g.putcells(under)
   
   
   val = g.getxy()
   
   if val == "":
      return 
      
   
   x1 = int(val.split()[0])
   y1 = y0 + GetDirection(t) * (x1 - x0)
   
   d[0] = g.getcells([x1 - w, y1 - h, 2 * w + 1, 2 * h + 1])
   
   #ClearRect(x1 - w, y1 - h, 2 * w + 1, 2 * h + 1)
   
   g.putcells(g.evolve(obj, p + GetEvolveDirection(t) * ((4 * (x1 - x0)) % p)), x1, y1)
   
   g.update()
   
   d[2] = x1
   d[3] = y1
示例#3
0
    def ManageMove(self, attachedPat, movementData):

        val = g.getxy()

        if val == "":
            return

        x1 = int(val.split()[0]) + movementData.delta
        self.MoveToX(attachedPat, x1, movementData)
示例#4
0
    def GetClickOnSignal(self, event):

        xs, ys = g.getxy().split()
        x = int(xs)
        y = int(ys)

        sig = sigMan.SignalInArea(x, y)

        if sig != None:

            #sigMan.Remove(sig)

            if "left" in event:
                return (sig, "out")
            if "right" in event:
                return (sig, "out")
示例#5
0
def drawlines():
    global oldline, firstcell
    started = False
    oldmouse = ""
    while True:
        event = g.getevent()
        if event.startswith("click"):
            # event is a string like "click 10 20 left altctrlshift"
            evt, x, y, butt, mods = event.split()
            oldmouse = x + ' ' + y
            if started:
                # draw permanent line from start pos to end pos
                endx = int(x)
                endy = int(y)
                drawline(startx, starty, endx, endy)
                # this is also the start of another line
                startx = endx
                starty = endy
                oldline = []
                firstcell = []
            else:
                # start first line
                startx = int(x)
                starty = int(y)
                firstcell = [startx, starty, g.getcell(startx, starty)]
                g.setcell(startx, starty, drawstate)
                g.update()
                started = True
                g.show(
                    "Click where to end this line (and start another line)...")
        else:
            # event might be "" or "key m none"
            if len(event) > 0: g.doevent(event)
            mousepos = g.getxy()
            if started and len(mousepos) == 0:
                # erase old line if mouse is not over grid
                if len(oldline) > 0:
                    eraseline(oldline)
                    oldline = []
                    g.update()
            elif started and len(mousepos) > 0 and mousepos != oldmouse:
                # mouse has moved, so erase old line (if any) and draw new line
                if len(oldline) > 0: eraseline(oldline)
                x, y = mousepos.split()
                oldline = drawline(startx, starty, int(x), int(y))
                oldmouse = mousepos
示例#6
0
def moveselection():
    global oldcells, selrect, selpatt

    # wait for 1st click in selection
    while True:
        event = g.getevent()
        if event.startswith("click"):
            # event is a string like "click 10 20 left none"
            evt, xstr, ystr, butt, mods = event.split()
            x = int(xstr)
            y = int(ystr)
            if cellinrect(x, y, selrect):
                oldmouse = xstr + ' ' + ystr
                firstx = x
                firsty = y
                xoffset = firstx - selrect[0]
                yoffset = firsty - selrect[1]
                if mods == "alt":
                    # don't delete pattern in selection
                    oldcells = g.getcells(selrect)
                break
        elif event == "key h none":
            showhelp1()
        else:
            g.doevent(event)

    # wait for 2nd click while moving selection
    g.show("Move mouse and click again..." + helpmsg)
    gotclick = False
    while not gotclick:
        event = g.getevent()
        if event.startswith("click"):
            evt, x, y, butt, mods = event.split()
            mousepos = x+' '+y
            gotclick = True
        else:
            if len(event) > 0:
                lookforkeys(event, x - firstx, y - firsty)
                # update xoffset,yoffset in case selection was rotated
                xoffset = x - selrect[0]
                yoffset = y - selrect[1]
            mousepos = g.getxy()
        if len(mousepos) > 0 and mousepos != oldmouse:
            # mouse has moved, so move selection rect and pattern
            g.clear(0)
            if len(oldcells) > 0: g.putcells(oldcells)
            xstr, ystr = mousepos.split()
            x = int(xstr)
            y = int(ystr)
            selrect[0] = x - xoffset
            selrect[1] = y - yoffset

            if g.getwidth() > 0:
                # ensure selrect doesn't move beyond left/right edge of grid
                if selrect[0] < gridl:
                    selrect[0] = gridl
                    x = selrect[0] + xoffset
                elif selrect[0] + selrect[2] - 1 > gridr:
                    selrect[0] = gridr + 1 - selrect[2]
                    x = selrect[0] + xoffset
            if g.getheight() > 0:
                # ensure selrect doesn't move beyond top/bottom edge of grid
                if selrect[1] < gridt:
                    selrect[1] = gridt
                    y = selrect[1] + yoffset
                elif selrect[1] + selrect[3] - 1 > gridb:
                    selrect[1] = gridb + 1 - selrect[3]
                    y = selrect[1] + yoffset

            g.select(selrect)
            oldcells = g.getcells(selrect)
            g.putcells(selpatt, x - firstx, y - firsty)
            oldmouse = mousepos
            g.update()
示例#7
0
def moveobject():
    global oldcells, object, object1

    # wait for click in or near a live cell
    while True:
        event = g.getevent()
        if event.startswith("click"):
            # event is a string like "click 10 20 left none"
            evt, xstr, ystr, butt, mods = event.split()
            result = findlivecell(int(xstr), int(ystr))
            if len(result) > 0:
                prevx = int(xstr)
                prevy = int(ystr)
                oldmouse = xstr + ' ' + ystr
                g.show("Extracting object...")
                x, y = result
                object = getobject(x, y)
                object1 = list(object)     # save in case user aborts script
                if mods == "alt":
                    # don't delete object
                    oldcells = list(object)
                break
            else:
                g.warn("Click on or near a live cell belonging to the desired object.")
        elif event == "key h none":
            showhelp()
        else:
            g.doevent(event)

    # wait for mouse-up while moving object
    g.show("Move mouse and release button...")
    mousedown = True
    while mousedown:
        event = g.getevent()
        if event.startswith("mup"):
            mousedown = False
        elif len(event) > 0:
            lookforkeys(event)
        mousepos = g.getxy()
        if len(mousepos) > 0 and mousepos != oldmouse:
            # mouse has moved, so move object
            g.putcells(object, 0, 0, 1, 0, 0, 1, "xor")  # erase object
            if len(oldcells) > 0: g.putcells(oldcells)
            xstr, ystr = mousepos.split()
            x = int(xstr)
            y = int(ystr)

            if g.getwidth() > 0:
                # ensure object doesn't move beyond left/right edge of grid
                obox = getminbox( g.transform(object, x - prevx, y - prevy) )
                if obox.left < gridl:
                    x += gridl - obox.left
                elif obox.right > gridr:
                    x -= obox.right - gridr
            if g.getheight() > 0:
                # ensure object doesn't move beyond top/bottom edge of grid
                obox = getminbox( g.transform(object, x - prevx, y - prevy) )
                if obox.top < gridt:
                    y += gridt - obox.top
                elif obox.bottom > gridb:
                    y -= obox.bottom - gridb

            object = g.transform(object, x - prevx, y - prevy)
            oldcells = underneath(object)
            g.putcells(object)
            prevx = x
            prevy = y
            oldmouse = mousepos
            g.update()
示例#8
0
    def Main(self):

        g.show("left click on a pattern to change, 'h' for help")
        gollyMode = False

        while True:

            event = g.getevent()

            if ("key" in event and "return" in event) or (gollyMode
                                                          and " a " in event):
                gollyMode = not gollyMode

                if gollyMode:
                    g.show("In golly mode")
                    g.update()

                else:
                    g.show("left click on a pattern, right click to finish")
                    g.setrule("B3/S23")
                    g.setalgo("HashLife")
                    g.reset()

                    g.update()

                continue

            if gollyMode:

                if " delete " in event:
                    g.clear(0)

                if "click" in event and "ctrl" in event and g.getxy() != "":

                    x, y = g.getxy().split()

                    cell = g.getcell(int(x), int(y))

                    if cell >= 0 and cell <= 1:
                        g.setcell(int(x), int(y), 1 - cell)

                    g.update()

                if " c " in event and "ctrl" in event and g.getselrect() != []:
                    g.copy()

                if " v " in event and "ctrl" in event and g.getxy() != "":

                    x, y = g.getxy().split()

                    g.paste(int(x), int(y), "or")

                if " space " in event:
                    if "ctrl" in event:
                        g.run(10)
                    else:
                        g.run(1)

                g.doevent(event)
                continue

            if "click" in event:

                if "left" in event:

                    if self.ExistinCircuitHandler() == None:
                        if self.SignalClickHandler(event) == None:
                            g.show("left click on a pattern, h for help")

            elif "key" in event:
                if " space " in event:
                    for i in xrange(0, 30):
                        g.run(60)
                        g.update()

                    g.reset()
                    g.update()

                if " a " in event:

                    if g.getrule() == "Perrier":
                        g.setrule("B3/S23")
                        g.setalgo("HashLife")
                        g.update()

                    else:
                        g.setrule("Perrier")

                        for key in self.smarCells:
                            x, y = key.split(":")
                            g.setcell(int(x), int(y), self.smarCells[key] + 2)

                        gollyMode = True
                        g.show("In golly mode")
                        g.update()

                if " s " in event:
                    fname = os.path.join(g.getdir("data"),
                                         "MetadataManager.json")
                    #self.Save(fname)

                if " h " in event:
                    noteMessage = "Viewing and Selecting\n\n"
                    noteMessage += "'left click' to chose gun or glider\n"
                    noteMessage += "'a' to see in colors, a to go back \n"
                    noteMessage += "'space' see ahead 1800 generations \n"
                    noteMessage += "'enter' gollyMode, stays in the script \n"

                    noteMessage += "\n Editing Gun \n\n"
                    noteMessage += "'left click' to place\n"
                    noteMessage += "'right click' to switch gun/orientation \n"
                    noteMessage += "'delete' to delete the gun \n"
                    noteMessage += "'left-right arrow' - one step adjustment\n"

                    noteMessage += "\n In Golly Mode \n\n"
                    noteMessage += "'delete' to clear selection\n"
                    noteMessage += "'ctrl' + 'click' to draw \n"
                    noteMessage += "'ctrl' + 'c' to copy selection \n"
                    noteMessage += "'ctrl' + 'v' to paste in mouse location \n"
                    noteMessage += "'space' + to run 1 generation \n"
                    noteMessage += "'ctrl' +'space' to run 10 generations \n"

                    g.note(noteMessage)