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
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)
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
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)