Beispiel #1
0
def setup(sk):
    # Create a Canvas as a GUI dialog
    cv = Canvas((384, 256)).config(bg="#f0f0ff", weight=1)

    # Vertical positioning 16 pixels below last item added
    down = lambda cv: 16 + cv[-1].height

    text = dict(color=BLUE, font=FONT, fontStyle=BOLD, padding=4)
    if TextInputCanvas:  # v2.2.dev
        ti = TextInputCanvas(336, "", "Type Some Text...", **text)
    else:  # v2.0-2.1
        ti = TextInput("", "Type Some Text...").config(**text)
    x, y = cv.center[0] - 8, 16
    cv["Input"] = ti.bind(onaction, onchange=onaction).config(anchor=TOP,
                                                              pos=(x, y),
                                                              bg="white",
                                                              weight=1)

    # Add a Radio box
    y += down(cv)
    cfg = {"font": FONT, "fontSize": 14}
    text = "Option A", "Option B", "Option C"
    box = Radio(text, txtConfig=cfg).bind(onchange=radioChange)
    cv["ABC"] = box.config(pos=(x, y), anchor=TOP, selected=1)

    # Add an Options box
    y += down(cv)
    text = "Option X", "Option Y", "Option Z"
    box = Options(text, txtConfig=cfg).config(pos=(x, y), anchor=TOP)
    cv["XYZ"] = box.bind(onaction=optionsChange)

    # Add Buttons
    y += down(cv)
    cv["Button Box"] = buttons(cfg).config(anchor=TOP, pos=(x, y))

    # Modify canvas and sketch size based on content
    cv.resize((cv.width, y + down(cv)), False)
    w, h = cv.size
    sk.size = w + 48, h + 48

    # Add a Slider
    slider = Slider((16, cv.height), [BLUE], 100, 0, 100)
    slider.config(pos=(cv.width, 0), anchor=TOPRIGHT, bg=GREY, weight=1)
    cv["Slider"] = slider.bind(onchange=sliderChange)

    # Create a popup menu
    img = Image.fromBytes(sc8prData("alien"))
    items = [("Action", img, None), ("Back", None, R_TRIANGLE)]
    cv.menu = Menu(items, txtConfig=cfg).config(pos=cv.center)
    cv.menu.bind(onaction=menuAction)

    # Add the dialog to the sketch
    sk["Dialog"] = cv.bind(resize=nothing).config(pos=sk.center)
Beispiel #2
0
 def __init__(self, colors=None):
     img = Image.fromBytes(sc8prData("robot"))
     if colors:  # Replace body and nose colors
         px = pygame.PixelArray(img.image)
         body0, nose0, body, nose = rgba("red", "blue", *colors)
         orig = body0, nose0
         if body in orig or nose in orig:
             colors = body0, nose0, body, nose
             body0 = _tempColor(px, body0, *colors)
             nose0 = _tempColor(px, nose0, *colors)
         if nose != nose0: px.replace(nose0, nose)
         if body != body0: px.replace(body0, body)
     img = img.tiles(2)
     super().__init__(img)
Beispiel #3
0
 def __init__(self, colors=None):
     img = Image.fromBytes(sc8prData("robot"))
     if colors:  # Replace body and nose colors
         px = pygame.PixelArray(img.image)
         body0, nose0, body, nose = rgba("red", "blue", *colors)
         orig = body0, nose0
         if body in orig or nose in orig:
             colors = body0, nose0, body, nose
             body0 = _tempColor(px, body0, *colors)
             nose0 = _tempColor(px, nose0, *colors)
         if nose != nose0: px.replace(nose0, nose)
         if body != body0: px.replace(body0, body)
     img = img.tiles(2)
     super().__init__(img)
def setup(sk):
    # Create a Canvas as a GUI dialog
    cv = Canvas((384,256)).config(bg="#f0f0ff", weight=1)

    # Vertical positioning 12 pixels below last item added
    down = lambda cv: 16 + cv[-1].height

    # Add a TextInput
    x, y = cv.center[0], 16
    cv["Input"] = TextInput("", "Type Some Text...").config(anchor=TOP,
        font=FONT, fontStyle=BOLD, pos=(x,y), color=BLUE,
        bg="white", padding=4).bind(onaction)

    # Add a Radio box
    y += down(cv)
    cfg = {"font":FONT, "fontSize":14}
    text = "Option A", "Option B", "Option C"
    radio = Radio(text, txtConfig=cfg).bind(onchange=radioChange)
    cv["ABC"] = radio.config(pos=(x,y), anchor=TOP, selected=1)

    # Add an Options box
    y += down(cv)
    text = "Option X", "Option Y", "Option Z"
    radio = Options(text, txtConfig=cfg).config(pos=(x,y), anchor=TOP)
    cv["XYZ"] = radio.bind(onaction=optionsChange)

    # Add Buttons
    y += down(cv)
    cv["Button Box"] = buttons(cfg).config(anchor=TOP, pos=(x,y))

    # Modify canvas and sketch size based on content
    cv.resize((cv.width, y + down(cv)), False)
    w, h = cv.size
    sk.size = w + 48, h + 48

    # Add a Slider
    slider = Slider((16, cv.height), BLUE, 100, 0, 100)
    slider.config(pos=(cv.width, 0), anchor=TOPRIGHT, bg=GREY, weight=1)
    cv += slider.bind(onchange=sliderChange)

    # Create a popup menu
    img = Image.fromBytes(sc8prData("alien"))
    items = [("Action", img, None), ("Back", None, R_TRIANGLE)]
    cv.menu = Menu(items, txtConfig=cfg).config(pos=cv.center)
    cv.menu.bind(resize=nothing, onaction=menuAction)

    # Add the dialog to the sketch
    cv.cover = sk.cover()
    sk["Dialog"] = cv.bind(resize=nothing).config(pos=sk.center)
Beispiel #5
0
def setup(game):
    "Create Tic-Tac-Toe board with 100 pixel squares and 20 pixel margins"

    # Load costumes for X and O sprites, and logo
    img = Image(resolvePath("img/xo.png", __file__)).tiles(3)
    game.alien = Image.fromBytes(sc8prData("alien")).config(height=36)

    # Create and position sprites, one per square
    for s in range(9):
        pos = 70 + 100 * (s % 3), 70 + 100 * (s // 3)
        game += Sprite(img).bind(contains=Graphic.contains,
            onclick=clickSquare).config(pos=pos, width=100)

    # Draw the board and start game
    for pts in [((20,120), (320,120)), ((20,220), (320,220)),
        ((120,20), (120,320)), ((220,20), (220,320))]: game += Line(*pts)
    startGame(game)
Beispiel #6
0
def setup(game):
    "Create Tic-Tac-Toe board with 100 pixel squares and 20 pixel margins"

    # Load costumes for X and O sprites, and logo
    img = Image(resolvePath("img/xo.png", __file__)).tiles(3)
    game.alien = Image.fromBytes(sc8prData("alien")).config(height=36)

    # Create and position sprites, one per square
    for s in range(9):
        pos = 70 + 100 * (s % 3), 70 + 100 * (s // 3)
        game += Sprite(img).bind(contains=Graphic.contains,
            onclick=clickSquare).config(pos=pos, width=100)

    # Draw the board and start game
    for pts in [((20,120), (320,120)), ((20,220), (320,220)),
        ((120,20), (120,320)), ((220,20), (220,320))]: game += Line(*pts)
    startGame(game)
Beispiel #7
0
 def _radioTiles():
     "Images for creating radio check boxes"
     if Button._radio is None:
         Button._radio = Image.fromBytes(sc8prData("radio"))
     return Button._radio.tiles(5)
Beispiel #8
0
 def _checkTiles():
     "Images for creating check boxes"
     if Button._check is None:
         Button._check = Image.fromBytes(sc8prData("checkbox"))
     return Button._check.tiles(5)
Beispiel #9
0
 def _yesNoImg(n):
     if Button._yesNo is None:
         Button._yesNo = Image.fromBytes(sc8prData("yesNo")).tiles(2)
     return Button._yesNo[0 if n else 1]