def init_menu(self): self.model = Menu('Main') self.m1 = self.model.add(Menu('Menu 1')) self.b1 = self.model.add(Button('Exit')) self.m1.caption = 'Menu One' self.b2 = self.m1.add(Button('Back'))
class Application: @property def screenWidth(self): return self.__screenWidth @property def screenHeight(self): return self.__screenHeight @property def resolution(self): return (self.screenWidth, self.screenHeight) @property def display(self): return self.__display @property def caption(self): return self.__caption def __init__(self): self.__screenWidth = config["game"]["width"] self.__screenHeight = config["game"]["height"] self.__caption = config["game"]["caption"] display = pygame.display.set_mode(self.resolution) pygame.display.set_caption(self.caption) self.__display = display def run(self): self.game = Game(self) self.menu = Menu(self) self.menu.run()
def main(): """работаем с текстойвым документом""" text = open('../words.txt', encoding='utf-8') dictionary = text.readlines() lines = [f.strip() for f in dictionary] text.close() menu = Menu(lines) menu.mainloop()
def restart_game(self): self.menu = Menu() self.board = Board() self.players = [] self.number_players = 0 self.board.restart_board() self.previous_before_playing() self.start_play()
def main(): menu = Menu() menu.run() if not menu.config.start_game: exit(0) game = Game(config=menu.config) new_game = game.run() if new_game: main()
def test_add_bun(): m = Menu() m.add_bun("bun-1", 10, inv_item, 1) assert len(m.buns) == 1 assert m.buns[0].name == 'bun-1' assert m.buns[0].price == 10 assert m.buns[0].component is inv_item assert m.buns[0].component_qty == 1 assert len(m) == 3
def test_add_other(): m = Menu() m.add_other("other-1", 10, inv_item, 1) assert m.other_ingredients[0].name == 'other-1' assert m.other_ingredients[0].price == 10 assert m.other_ingredients[0].component is inv_item assert m.other_ingredients[0].component_qty == 1 assert len(m.other_ingredients) == 1 assert len(m) == 3
def test_add_patty(): m = Menu() m.add_patty("patty-1", 10, inv_item, 1) assert m.patties[0].name == "patty-1" assert m.patties[0].price == 10 assert m.patties[0].component is inv_item assert m.patties[0].component_qty == 1 assert len(m.patties) == 1 assert len(m) == 3
def test_add_drink(): m = Menu() m.add_drink("drink-1", 10, inv_item, 1) assert len(m.drinks) == 1 assert m.drinks[0].name == 'drink-1' assert m.drinks[0].price == 10 assert m.drinks[0].component is inv_item assert m.drinks[0].component_qty == 1 assert len(m) == 3
def test_add_side(): m = Menu() m.add_side("side-1", 10, inv_item, 1) assert len(m.sides) == 1 assert m.sides[0].name == 'side-1' assert m.sides[0].price == 10 assert m.sides[0].component is inv_item assert m.sides[0].component_qty == 1 assert len(m) == 3
def __init__(self, game, rect): self.game = game self.rect = rect self.x, self.y = self.rect.center self.follow_target = None self.font = pygame.font.Font('src//font//font.otf', 30) self.menu = Menu(self.game) self._no_charge_error_counter = 0
def test_invalid_item(): m = Menu() with pytest.raises(InvalidFieldError) as e: """ failure cases should be covere by test_menu_item """ m.add_patty(None, -10, None, 1) assert len(e._messages) == 3 assert e.__str__() == ("Please specify a valid item name\n" "Please specify a valid price\n" "Please specigy a valid quantity\n") assert len(m) == 2
def show_start_screen(self): """ Initializes the menus, music, and starts menu loop. """ self.font = "franklingothic" pg.mixer.music.load( path.join(self.data.music_folder, self.settings["music"]["voidwalk"])) if self.settings["gen"]["music"] == "on": pg.mixer.music.play(-1, 0.0) self.menu = Menu(self.clock, self.screen, self.settings, self.data, self.font, self.character) self.character = self.menu.run(self.menu.menu_main)
def play_maze(self): os.system('cls' if os.name == 'nt' else 'clear') if self.field == None: print("There is no maze currently loaded.") input("Press Enter to continue...") return self.player = Player() self.field.enter(self.player) self.is_in_maze = True while self.is_in_maze: os.system('cls' if os.name == 'nt' else 'clear') print(self.field.render()) print() start = self.field.start_block blocks = [block for row in self.field.blocks for block in row] ends = [block for block in blocks if isinstance(block, Portal)] print("Location of start (A) = {0}".format( f"(row {start.y + 1}, col {start.x + 1})")) print("Location of End (B) = {0}".format(', '.join([ f"(row {block.y + 1}, col {block.x + 1})" for block in ends ]))) def move(player, direction): if not self.field.move(player, direction): print("Invalid movement entered in game. Please try again") time.sleep(1) menu = Menu([ Option("w", "Move up", lambda: move(self.player, Direction.up)), Option("a", "Move left", lambda: move(self.player, Direction.left)), Option("s", "Move down", lambda: move(self.player, Direction.down)), Option("d", "Move right", lambda: move(self.player, Direction.right)), Option("m", "Return to menu", lambda: self.end_play_maze()), ]) selection = input( "Use the WASD to move or M key to return to menu: ") menu.select(selection) if self.player.is_finished: print() print("You have completed the maze, congratulations!") input("Press Enter to continue...") self.end_play_maze()
def test_let_guest_know_they_still_have_cash(self): guest_1 = Guest("Robin Scherbatsky", 50.00, "Heart of glass", "Disco Room") fee = Room("Disco Room", 15.00) order_1 = Menu("Beer", 3.00) order_2 = Menu("Beer", 3.00) order_3 = Menu("Scotch", 5.00) order_4 = Menu("Cocktail", 6.00) guest_1.pay_entry_fee(fee) guest_1.buy_from_menu(order_1) guest_1.buy_from_menu(order_2) guest_1.buy_from_menu(order_3) guest_1.buy_from_menu(order_4) self.assertEqual("Still loaded!", self.guest.is_guest_skint(guest_1))
def test_add_multiple_same_cataory(): m = Menu() m.add_patty("patty-1", 10, inv_item, 1) m.add_patty("patty-2", 10, inv_item, 1) assert m.patties[0].name == "patty-1" assert m.patties[0].price == 10 assert m.patties[0].component is inv_item assert m.patties[0].component_qty == 1 assert m.patties[1].name == "patty-2" assert m.patties[1].price == 10 assert m.patties[1].component is inv_item assert m.patties[1].component_qty == 1 assert len(m.patties) == 2 assert len(m) == 4
def test_let_guest_know_they_are_skint(self): guest_1 = Guest("Marshall Eriksson", 30.00, "Night fever", "Disco Room") fee = Room("Disco Room", 15.00) self.guest.pay_entry_fee(fee) order_1 = Menu("Beer", 3.00) order_2 = Menu("Beer", 3.00) order_3 = Menu("Beer", 3.00) order_4 = Menu("Cocktail", 6.00) guest_1.pay_entry_fee(fee) guest_1.buy_from_menu(order_1) guest_1.buy_from_menu(order_2) guest_1.buy_from_menu(order_3) guest_1.buy_from_menu(order_4) self.assertEqual("Skint!", self.guest.is_guest_skint(guest_1))
def __init__(self): super(Application, self).__init__([]) self.setQuitOnLastWindowClosed(False) # Create ouath object to handle cached token data self.sp_oauth = SpotifyOAuth(spotify_config.client_id, spotify_config.client_secret, spotify_config.redirect_uri, scope='user-read-currently-playing', cache_path=join(FOLDER_PATH, 'spotifycache')) # Create the menu, connect class functions to the app's buttons self.menu = Menu() self.menu.login_info_action.triggered.connect(self._on_login_button) self.menu.toggle_wallpaper_action.triggered.connect( self._on_toggle_wallpaper_button) self.menu.quit_action.triggered.connect(self._on_quit_button) # Create the tray and make it visible self.tray = QSystemTrayIcon() self.tray.setIcon(QIcon(resource_path(join('assets', 'icon.png')))) self.tray.setVisible(True) self.tray.setContextMenu(self.menu) # Create confirm account frame self.confirm_account_window = ConfirmAccountWindow() self.confirm_account_window.form_widget.button.clicked.connect( self._on_confirm_account_button) # Attempt login with cache self._attempt_login()
def run(): pygame.init() pygame.display.set_caption('Tetris') switch_status = 'menu' while True: if switch_status == 'menu': menu = Menu() switch_status = menu.run() elif switch_status == 'single player': single_player = SinglePlayer() switch_status = single_player.run() elif switch_status == 'multi player': multi_player = MultiPlayer() switch_status = multi_player.run()
def test_guest_can_add_to_tab(self): guest_1 = Guest("Ted Mosby", 35.00, "Saturday night", "Disco Room") fee = Room("Disco Room", 15.00) order = Menu("Beer", 3.50) guest_1.pay_entry_fee(fee) guest_1.buy_from_menu(order) self.assertEqual(18.50, guest_1.tab)
def __init__(self): self._orders = [] self._inventory = inventory() self._menu = Menu() self._current_order = Order() self._base_burger = None self._base_wrap = None
def start(self): menu = Menu([ Option("1", "Read and load maze from file", self.load_maze), Option("2", "View maze", self.view_maze), Option("3", "Play maze game", self.play_maze), Option("4", "Configure current maze", self.edit_maze), Option("0", "Exit maze", self.end), ]) while not self.ended: os.system('cls' if os.name == 'nt' else 'clear') print("Main menu") print("=========") print(menu.render()) if not menu.select(input("Enter your option: ")): print("Invalid menu option, try again!") input("Press Enter to continue...") print()
def start(self): while not self.ended: os.system('cls' if os.name == 'nt' else 'clear') self.field.enter(Player()) print(self.field.render()) print() print("Configuration Menu") print("==================") menu = Menu([ Option("1", "Create wall", self.create_wall), Option("2", "Create passageway", self.create_passageway), Option("3", "Create start point", self.create_start_point), Option("4", "Create end point", self.create_end_point), Option("0", "Exit to Main Menu", lambda: self.end()), ]) print(menu.render()) selection = input("Enter your option: ") menu.select(selection)
def main(): # Screen init os.environ['SDL_VIDEO_WINDOW_POS'] = "%d,%d" % (200, 40) pygame.init() pygame.display.set_caption('Teeko-AI') icon = pygame.image.load('resources/Teeko_logo.png') pygame.display.set_icon(icon) clock = pygame.time.Clock() # Screens display = pygame.display.set_mode(SCREEN_SIZE) game = Teeko(pygame.Surface(SCREEN_SIZE)) menu = Menu(pygame.Surface(SCREEN_SIZE)) rules = Rules(pygame.Surface(SCREEN_SIZE)) # Page manager page_manager = PageManager() page_manager.setPage(menu) while True: # Game loop # Collect events for event in pygame.event.get(): if event.type == pygame.QUIT or (event.type == pygame.KEYDOWN and event.key == pygame.K_q): pygame.quit() game.killMinMax() quit() code = page_manager.current.parseEvent(event) if code == CODE_TO_GAME: game.reset(players=(menu.playerone, menu.playertwo), index_difficulty=(menu.index_difficulty_one, menu.index_difficulty_two)) page_manager.transitionTo(game) elif code == CODE_TO_MENU: game.killMinMax() page_manager.transitionTo(menu, reverse=True) elif code == CODE_TO_RULES: page_manager.transitionTo(rules) if page_manager.current == game and page_manager.ready(): game.update() # ingame update # screen update page_manager.current.render() # print screen page_manager.blit(display) pygame.display.update() clock.tick(FPS)
class Game: menu = Menu() board = Board() grid_size_px = 20 menu_height_px = 30 def __init__(self, zygote): self.zygote = zygote self.board.load(self.zygote) self.__recompute_screens() def process_menu_action(self, pos): action = self.menu.handle_click(pos) if action == MenuAction.NEXT: self.board.next_gen() elif action == MenuAction.PLUS: self.board.increase_size() self.__recompute_screens() elif action == MenuAction.MINUS: self.board.decrease_size() self.__recompute_screens() elif action == MenuAction.CLEAR: self.board.clear() def run(self): done = False while not done: self.menu.draw(self.full_screen, pg.mouse.get_pos()) self.board.draw(self.board_screen, self.grid_size_px) pg.display.update() e = pg.event.wait() if e.type == pg.QUIT: done = True if e.type == pg.KEYDOWN and e.key == pg.K_SPACE: self.board.next_gen() if e.type == pg.MOUSEBUTTONUP: if e.pos[1] < self.menu_height_px: # handle menu click self.process_menu_action(e.pos) else: # handle board click self.board.handle_click((e.pos[0], e.pos[1] - self.menu_height_px), self.grid_size_px) def __recompute_screens(self): rows_px = self.board.rows * self.grid_size_px cols_px = self.board.cols * self.grid_size_px self.full_screen = pg.display.set_mode((cols_px, rows_px + self.menu_height_px)) self.full_screen.fill((220, 220, 220)) self.board_screen = self.full_screen.subsurface(pg.Rect(0, self.menu_height_px, cols_px, rows_px))
def test_add_multiple_different_cataory(): m = Menu() m.add_patty("patty-1", 10, inv_item, 1) m.add_drink("drink-1", 10, inv_item, 1) assert m.patties[0].name == "patty-1" assert m.patties[0].price == 10 assert m.patties[0].component is inv_item assert m.patties[0].component_qty == 1 assert m.drinks[0].name == 'drink-1' assert m.drinks[0].price == 10 assert m.drinks[0].component is inv_item assert m.drinks[0].component_qty == 1 assert len(m.patties) == 1 assert len(m.drinks) == 1 assert len(m) == 4
def oepn_menu(self): Menu(self._socket).open()
def generate_menu(): ''' init menu ''' menu = Menu() ''' mains ''' fish_patties = Patties("fish_patties",2,40,"mains") chicken_patties = Patties("chicken_patties",1.5,50,"mains") tomato = Ingredient("tomato",0.5,300,"mains") buns = Buns("buns",0.5,400,"buns") lettuce = Ingredient("lettuce",0.5,100,"mains") ''' drinks ''' can_coca = Can_drink("can_coca",2.5,100,"drinks") bottle_coca = Bottle_drink("bottle_coca",3.5,100,"drinks") small_coca = SmallDrink("small_coca",0,"drinks",2) medium_coca = MediumDrink("medium_coca",0,"drinks",2.75) large_coca = LargeDrink("large_coca",0,"drinks",3.75) ''' sides ''' small_fries = SmallSides("small_fries",0,"sides",1.5) large_fries = LargeSides("large_fries",0,"sides",2.5) medium_fries = MediumSides("medium_fries",0,"sides",3.5) small_salad = SmallSides("small_salad",0,"sides",1,75) medium_salad = MediumSides("medium_salad",0,"sides",2) large_salad = LargeSides("large_salad",0,"sides",4) ''' sundae ''' small_chocolate = SmallSundae("small_chocolate",0,"sundaes",2.5) medium_chocolate = MediumSundae("medium_chocolate",0,"sundaes",3.5) large_chocolate = LargeSundae("large_chocolate",0,"sundaes",4.5) medium_strawberry = MediumSundae("medium_strawberry",0,"sundaes",2.5) small_strawberry = SmallSundae("small_strawberry",0,"sundaes",3.5) large_strawberry = LargeSundae("large_strawberry",0,"sundaes",4.5) ''' add food to menu ''' menu.add_food(small_chocolate) menu.add_food(medium_chocolate) menu.add_food(large_chocolate) menu.add_food(medium_strawberry) menu.add_food(small_strawberry) menu.add_food(large_strawberry) menu.add_food(small_coca) menu.add_food(large_coca) menu.add_food(medium_coca) menu.add_food(fish_patties) menu.add_food(chicken_patties) menu.add_food(tomato) menu.add_food(buns) menu.add_food(lettuce) menu.add_food(can_coca) menu.add_food(bottle_coca) menu.add_food(small_fries) menu.add_food(large_salad) menu.add_food(large_fries) menu.add_food(medium_fries) menu.add_food(small_salad) menu.add_food(medium_salad) menu.add_food(large_salad) return menu
def switchScene(self): preData = self.window.scene.data if(self.window.scene.NAME == 'LAUNCHER'): if(self.window.scene.MODE == 'MENU'): w, h = getResol('./cnf/config.ini') self.window.scene = None self.changeResolution(w, h) self.window.setScene(Menu(preData)) else: if(self.window.scene.MODE == 'AJUSTES'): self.window.setScene(Ajustes(preData)) if(self.window.scene.MODE == 'PRINCIPAL'): self.window.setScene(Principal(preData)) if(self.window.scene.MODE == 'AYUDA'): self.window.setScene(Ayuda(preData)) if(self.window.scene.MODE == 'MENU'): self.window.setScene(Menu(preData)) if(self.window.scene.MODE == 'REGISTRO'): preData['dbcon'] = self.db self.window.setScene(Registro(preData)) if(self.window.scene.MODE == 'LOGIN'): preData['dbcon'] = self.db self.window.setScene(Login(preData)) if(self.window.scene.MODE == 'NIVELES'): preData['dbcon'] = self.db self.window.setScene(Niveles(preData)) if(self.window.scene.MODE == 'NIVEL1'): self.window.setScene(Nivel1(preData)) if(self.window.scene.MODE == 'EJERCICIO2_N1'): self.window.setScene(Ejercicio2_n1(preData)) if(self.window.scene.MODE == 'EJERCICIO3_N1'): self.window.setScene(Ejercicio3_n1(preData)) if(self.window.scene.MODE == 'EJERCICIO1_N2'): self.window.setScene(Ejercicio1_n2(preData)) if(self.window.scene.MODE == 'EJERCICIO2_N2'): self.window.setScene(Ejercicio2_n2(preData)) if(self.window.scene.MODE == 'EJERCICIO3_N2'): self.window.setScene(Ejercicio3_n2(preData)) if(self.window.scene.MODE == 'EJERCICIO1_N3'): self.window.setScene(Ejercicio1_n3(preData)) if(self.window.scene.MODE == 'EJERCICIO2_N3'): self.window.setScene(Ejercicio2_n3(preData)) if(self.window.scene.MODE == 'EJERCICIO3_N3'): self.window.setScene(Ejercicio3_n3(preData))
from src.database import Database __author__ = 'ibininja' Database.initialize() #post = Post(blog_id="125", # title="Healthy Banana", # content="This is the content of Healthy Banana name published articles....", # author="Mohamed") #post.save_to_mongo() #posts = Post.from_blog('125') #for post in posts: # print(post) #posts = Post.from_mongo('3782101c9d3d4e5eae511d8f3180f8d5') #print(posts) #This below is to test Blog # blog = Blog(author="Ibrahim", # title="Sample Title", # description="Sample Description") # blog.new_post() # blog.save_to_mongo() # from_database= Blog.from_mongo(blog.id) # print(blog.get_posts()) #This below is the normal fully fledged running blog: menu = Menu() menu.run_menu()
import arcade from arcade.gui.ui_style import UIStyle from src.menu import Menu from src.globals import * if __name__ == "__main__": # Sets a basic UIStyle for a label UIStyle.default_style().set_class_attrs( 'label', font_color=arcade.color.WHITE, font_color_hover=arcade.color.WHITE, font_color_press=arcade.color.WHITE, ) window = arcade.Window(title='Democracy defender', height=HEIGHT, width=WIDTH) window.show_view(Menu()) arcade.run()