def create_object():
    """
    Creates the original DVD Logo. Code from here will be moved into
    the new class that you are creating.
    """

    width = 200
    height = 200

    obj = GCompound()

    cube = GRect(0, 0, width, height)
    cube.set_filled(True)
    cube.set_color(random_color())
    obj.add(cube)

    dvdtext = GLabel("DVD")
    dvdtext.set_font("bold 60px 'serif'")
    obj.add(dvdtext, width / 2 - dvdtext.get_width() / 2, height / 2 - 10)

    vidtext = GLabel("video")
    vidtext.set_font("bold 50px 'serif'")
    vidtext.set_color("white")
    obj.add(vidtext, width / 2 - vidtext.get_width() / 2,
            height / 2 + vidtext.get_ascent())

    return obj
示例#2
0
 def __init__(self, text, fn=None):
     GCompound.__init__(self)
     label = GLabel(text)
     label.set_font(self.BUTTON_FONT)
     width = max(self.BUTTON_MIN_WIDTH,
                 2 * self.BUTTON_MARGIN + label.get_width())
     frame = GRect(width, self.BUTTON_DEFAULT_HEIGHT)
     frame.set_filled(True)
     frame.set_fill_color("White")
     self.add(frame)
     self.add(label)
     self.text = text
     self.label = label
     self.frame = frame
     self.fn = fn
     self._recenter()
示例#3
0
def image_shop():
    def add_button(label, action):
        """
        Adds a button to the region on the left side of the window
        label is the text that will be displayed on the button and
        action is the callback function that will be run when the
        button is clicked.
        """
        x = BUTTON_MARGIN
        y = gs.next_button_y
        button = GButton(label, action)
        button.set_size(BUTTON_WIDTH, BUTTON_HEIGHT)
        gw.add(button, x, y)
        gs.next_button_y += BUTTON_HEIGHT + BUTTON_MARGIN

    def set_image(image):
        """
        Sets image as the current image after removing the old one.
        """
        if gs.current_image is not None:
            gw.remove(gs.current_image)
        gs.current_image = image
        x = BUTTON_AREA_WIDTH + (IMAGE_AREA_WIDTH - image.get_width()) / 2
        y = (gw.get_height() - image.get_height()) / 2
        gw.add(image, x, y)

    def load_button_action():
        """Callback function for the Load button"""
        filename = choose_input_file()
        if filename != "":
            set_image(GImage(filename))

    def flip_vertical_action():
        """Callback function for the Flip Vertical button"""
        if gs.current_image is not None:
            set_image(flip_vertical(gs.current_image))

    gw = GWindow(GWINDOW_WIDTH, GWINDOW_HEIGHT)
    gs = GState()
    button_area = GRect(0, 0, BUTTON_AREA_WIDTH, GWINDOW_HEIGHT)
    button_area.set_filled(True)
    button_area.set_color(BUTTON_BACKGROUND)
    gw.add(button_area)
    gs.next_button_y = BUTTON_MARGIN
    gs.current_image = None
    add_button("Load", load_button_action)
    add_button("Flip Vertical", flip_vertical_action)
示例#4
0
def create_filled_rect(x, y, w, h, color):
    """ Creates a filled rectangle of the desired color. """
    r = GRect(x, y, w, h)
    r.set_filled(True)
    r.set_color(color)
    return r
示例#5
0
def create_filled_rect(x, y, w, h):
    """Creates a rectangle filled with a random color."""
    r = GRect(x, y, w, h)
    r.set_filled(True)
    r.set_color(rand_color())
    return r
    obj = GCompound()

    cube = GRect(0, 0, width, height)
    cube.set_filled(True)
    cube.set_color(random_color())
    obj.add(cube)

    dvdtext = GLabel("DVD")
    dvdtext.set_font("bold 60px 'serif'")
    obj.add(dvdtext, width / 2 - dvdtext.get_width() / 2, height / 2 - 10)

    vidtext = GLabel("video")
    vidtext.set_font("bold 50px 'serif'")
    vidtext.set_color("white")
    obj.add(vidtext, width / 2 - vidtext.get_width() / 2,
            height / 2 + vidtext.get_ascent())

    return obj


gw = GWindow(800, 600)
# Setting a black background so it looks like the tv
bg = GRect(0, 0, gw.get_width(), gw.get_height())
bg.set_filled(True)
bg.set_color('black')
gw.add(bg)
# Create and add the logo
logo = create_object()
gw.add(logo, 300, 200)