class Integrador(): def __init__(self): self.__dispositivo = None self.__elisa = None self.__recebedorPacote = None self.__view = View() self.start(self.__view.start()) def start(self, opcao): if opcao == 1: self.__dispositivo = Dispositivo() self.__elisa = ExperimentoElisa(self.__dispositivo) self.__recebedorPacote = RecebedorPacote(self.__dispositivo) self.__recebedorPacote.iniciarThread() self.receber() self.ler() elif opcao == 2: return self.__view.finalizar() else: self.__view.opcaoInvalida() return self.start(self.__view.start()) def receber(self): t = Thread(target=self.ler) t.start() def ler(self): while True: sleep(1) self.__elisa.transformador(self.__recebedorPacote.getLista())
def __init__(self): """ Initialize a controller entering into a game main loop. """ # ----- setting self atributtes. ----- self.y_rect, self.n_rect = "", "" time = 300 # ----- setting the options of the game by the first window loop ---- type_of_game = self.first_window_loop() self.client = None self.em = None # ----- entering into the game. ----- if type_of_game == 3: # networking things. self.game = None self.em = None players = 2 self.is_local = False self.client = Client() else: players = type_of_game self.is_local = True self.em = Event_manager(daemon=True) self.game = Game(players, time, self.em, True) self.view = View(self.game, self.em, daemon=True, is_local=self.is_local, client=self.client) self.square_size = self.view.get_square_size() self.game_ended = False self.view.start() # ----- subscribing to important methods. ----- dispatcher.send(signal="subscribe", event_name="game_ended", listener=self) dispatcher.send(signal="subscribe", event_name="new_game", listener=self) # ----- entering to the main loop ----- self.main_loop()
class Integrador(): def __init__(self): self.__dispositivo = None self.__elisa = None self.__recebedorPacote = None self.__view = View() self.start(self.__view.start()) def start(self, opcao): if opcao == 1: self.__dispositivo = Dispositivo() self.__elisa = ExperimentoElisa(self.__dispositivo) self.__recebedorPacote = RecebedorPacote(self.__dispositivo) self.__recebedorPacote.iniciarThread() self.receber() self.ler() elif opcao == 2: return self.__view.finalizar() else: self.__view.opcaoInvalida() return self.start(self.__view.start()) def receber(self): t = Thread(target=self.ler) t.start() def ler(self): while True: sleep(1) self.__elisa.transformador(self.__recebedorPacote.getLista())
def __init__(self): self.player = Player() self.view = View(1300, 800) self.view.change_view_state(View.STARTVIEW) self.game_state = None self.event_list_start_view = { 'start_button': self.start_button_pressed, 'quit_game': self.quit_button_pressed } self.event_list_game_view = { 'build_scout': self.create_ant, 'quit_game': self.quit_button_pressed } self.game_loop()
def __init__(self): # self.player = Player() self.view = View(1300, 800) self.view.change_view_state(View.STARTVIEW) self.game_state = None self.event_list_start_view = { 'start_button': self.start_button_pressed, 'quit_game': self.exit_game } self.event_list_game_view = { 'build_scout': self.create_scout, 'build_worker': self.create_worker, 'show_build_ants': self.show_build_ants_dialog, 'quit_game': self.exit_game } self.event_list = { 'start_view': self.event_list_start_view, 'game_view': self.event_list_game_view }
def run(self): conn = sqlite3.connect('db.db') with open(DB_SCHEMA_PATH) as schema: conn.executescript(schema.read()) acc_repo = AccountRepo(conn) cat_repo = CategoryRepo(conn) trans_repo = TransactionRepo(conn) ex_rate_repo = ExchangeRateRepo(conn) data_manager = DataManager(acc_repo, cat_repo, trans_repo) data_manager.load_data() ex_rates_store = ExchangeRatesStore(ex_rate_repo, self.api_key) View(data_manager, ex_rates_store).show() conn.commit() conn.close()
def test_view_state(): view = View(1300, 800) view.state = 'start-view' assert view.state == 'start-view'
def test_view_initialization(): view = View(1300, 800) assert not view.state
#!/usr/bin/python #################################################################### # Name: curse.py # Parameter: useremail password # This program is called from the command line to initiate the # CLI client. The user email address and password should be # passed on the command line. # example: python curse.py [email protected] 1234 #################################################################### import sys from src.view.view import View # get username (email) and password from command line: args = len(sys.argv) if args < 3: sys.exit("Invalid Input: include user-email and password in command line") userName = sys.argv[1] userPass = sys.argv[2] # start the curses CLI program from src/view/view.py newView = View(userName, userPass) newView.validateUser() newView.initWrapper()
class Controller: def __init__(self): # self.player = Player() self.view = View(1300, 800) self.view.change_view_state(View.STARTVIEW) self.game_state = None self.event_list_start_view = { 'start_button': self.start_button_pressed, 'quit_game': self.exit_game } self.event_list_game_view = { 'build_scout': self.create_ant, 'quit_game': self.exit_game } self.event_list = { 'start_view': self.event_list_start_view, 'game_view': self.event_list_game_view } def start_button_pressed(self, color, player_name): """ Event-handler for the start button to change Viewstate from Startview to Gameview :param color: Color chosen by player :param player_name: Name chosen by player :return: returns a game_state object for initialization of the game """ if player_name: self.view.change_view_state(View.GAMEVIEW) player = Player(player_name, color) player_list = [player] game_state = GameState(player_list) return game_state else: # TODO Get view to show pop up with message print('Player name not entered') @staticmethod def exit_game(): """ Quit game method :return: nothing """ sys.exit() def create_ant(self, button): """ Event-handler for creating ants using the create ants button :param button: Create Ants button :return: nothing """ if button.state != 'loading': button.state = 'loading' def _create_ant(): time.sleep(all_params.controller_params.create_ant_time) nest = self.game_state.get_nests()[0] self.game_state.create_ants(nest, amount=1) self.view.increment_ant_count() create_thread(func=_create_ant) def get_events(self, view_state): """ Function to get events from view and call the corresponding functions according to view_state :param view_state: String specifying state of view :return: nothing """ # Get the list of events from view event_argument_list = self.view.events() # Getting events and arguments as two lists event = list(event_argument_list.keys()) args = list(event_argument_list.values()) for i in range(len(event)): if event[i] in self.event_list[view_state].keys(): if args[i] is not None: if view_state == 'start_view': self.game_state = self.event_list[view_state][ event[i]](*args[i]) else: self.event_list[view_state][event[i]](*args[i]) def game_state_init(self): """ Function to initialize game state when game state is none :return: nothing """ self.get_events('start_view') def game_state_update(self): """ Function to update game state when game state is not none :return: nothing """ self.view.update( self.game_state.get_objects_in_region(self.view.pos[0], self.view.pos[1])) self.get_events('game_view') self.game_state.update() def game_loop(self): """ Main game loop :return: nothing """ frame_rate = all_params.controller_params.framerate while True: current_time = time.time() if self.game_state is None: self.view.draw() self.game_state_init() else: self.view.draw() self.game_state_update() # For frame rate adjustment exit_time = time.time() time_elapsed = exit_time - current_time frames_per_sec = 1. / frame_rate time.sleep(max(frames_per_sec - time_elapsed, 0))
def __init__(self): self.__view = View()
def test_view_size(): view = View(1300, 800) assert view.size == (1300, 800)
class Controller: def __init__(self): # self.player = Player() self.view = View(1300, 800) self.view.change_view_state(View.STARTVIEW) self.game_state = None self.event_list_start_view = { 'start_button': self.start_button_pressed, 'quit_game': self.exit_game } self.event_list_game_view = { 'build_scout': self.create_scout, 'build_worker': self.create_worker, 'show_build_ants': self.show_build_ants_dialog, 'quit_game': self.exit_game } self.event_list = { 'start_view': self.event_list_start_view, 'game_view': self.event_list_game_view } def start_button_pressed(self, color, player_name): """ Event-handler for the start button to change Viewstate from Startview to Gameview :param color: Color chosen by player :param player_name: Name chosen by player :return: returns a game_state object for initialization of the game """ if player_name: self.view.change_view_state(View.GAMEVIEW, color) player = Player(player_name, color) player_list = [player] game_state = GameState(player_list) return game_state else: # TODO Get view to show pop up with message print('Player name not entered') @staticmethod def exit_game(): """ Quit game method :return: nothing """ sys.exit() def _create_ant(self, button, ant_type: str): """ :param button: create ant button associated with ant type :param ant_type: ant type to be created (scout, worker, soldier) :return: """ time.sleep(all_params.controller_params.create_ant_time) nest = self.game_state.get_nests()[0] self.game_state.create_ants(nest, amount=1, ant_type=ant_type) self.view.increment_ant_count(type=button.ant_type) def create_worker(self, identifier): """ Event-handler for creating worker using the create worker button :param identifier: identifier for create worker button :return: nothing """ button = self.view.get_element_by_id(identifier) button.state = 'loading' create_thread(func=self._create_ant, args=(button, 'worker')) def create_scout(self, identifier): """ Event-handler for creating scouts using the create scouts button :param identifier: identifier for create scout button :return: nothing """ button = self.view.get_element_by_id(identifier) button.state = 'loading' create_thread(func=self._create_ant, args=(button, 'scout')) def show_build_ants_dialog(self, button): """ Event-handler for displaying create ants dialog :param button: Show Build Ants Dialog :return: nothing """ view = button.view dialog = view.get_element_by_id('view_box_id_add_ants_box') dialog.toggle() def get_events(self, view_state): """ Function to get events from view and call the corresponding functions according to view_state :param view_state: String specifying state of view :return: nothing """ # Get the list of events from view event_argument_list = self.view.events() # Getting events and arguments as two lists event = list(event_argument_list.keys()) args = list(event_argument_list.values()) for i in range(len(event)): if event[i] in self.event_list[view_state].keys(): if args[i] is not None: if view_state == 'start_view': self.game_state = self.event_list[view_state][ event[i]](*args[i]) else: self.event_list[view_state][event[i]](*args[i]) def game_state_init(self): """ Function to initialize game state when game state is none :return: nothing """ self.get_events('start_view') def game_state_update(self): """ Function to update game state when game state is not none :return: nothing """ self.view.update( self.game_state.get_objects_in_region(self.view.pos[0], self.view.pos[1])) self.get_events('game_view') self.game_state.update() def game_loop(self): """ Main game loop :return: nothing """ frame_rate = all_params.controller_params.framerate while True: current_time = time.time() if self.game_state is None: self.view.draw(self.view.width, self.view.height) self.game_state_init() else: self.view.draw(self.view.width, self.view.height) self.game_state_update() # For frame rate adjustment exit_time = time.time() time_elapsed = exit_time - current_time frames_per_sec = 1. / frame_rate time.sleep(max(frames_per_sec - time_elapsed, 0))
class Controller: def __init__(self): """ Initialize a controller entering into a game main loop. """ # ----- setting self atributtes. ----- self.y_rect, self.n_rect = "", "" time = 300 # ----- setting the options of the game by the first window loop ---- type_of_game = self.first_window_loop() self.client = None self.em = None # ----- entering into the game. ----- if type_of_game == 3: # networking things. self.game = None self.em = None players = 2 self.is_local = False self.client = Client() else: players = type_of_game self.is_local = True self.em = Event_manager(daemon=True) self.game = Game(players, time, self.em, True) self.view = View(self.game, self.em, daemon=True, is_local=self.is_local, client=self.client) self.square_size = self.view.get_square_size() self.game_ended = False self.view.start() # ----- subscribing to important methods. ----- dispatcher.send(signal="subscribe", event_name="game_ended", listener=self) dispatcher.send(signal="subscribe", event_name="new_game", listener=self) # ----- entering to the main loop ----- self.main_loop() def first_window_loop(self): players = 0 local = True menu = Menu() menu_view = Menu_view(menu) first, second, third = menu_view.get_rects() while True: mouse = pygame.mouse.get_pos() menu.first_hovered = first.collidepoint(mouse) menu.second_hovered = second.collidepoint(mouse) menu.third_hovered = third.collidepoint(mouse) for event in pygame.event.get(): if event.type == pygame.QUIT: pygame.quit() break if event.type == pygame.MOUSEBUTTONDOWN: if menu.first_hovered: return 1 if menu.second_hovered: return 2 if menu.third_hovered: return 3 menu_view.refresh_menu() def main_loop(self): """ Main loop of the game. """ self.game_ended = False while not self.game_ended: for event in pygame.event.get(): keys = pygame.key.get_pressed() if keys[pygame.K_r]: self.view.rotate = not self.view.rotate if event.type == pygame.QUIT: pygame.quit() self.game_ended = True if event.type == pygame.MOUSEBUTTONDOWN: mouse = pygame.mouse.get_pos() column = mouse[0] // self.square_size + 1 row = mouse[1] // self.square_size + 1 if not self.view.rotate: rotate = { 1: 8, 2: 7, 3: 6, 4: 5, 5: 4, 6: 3, 7: 2, 8: 1 } row = rotate[row] if not (column < 0 or column > 8 or row < 0 or row > 8): if self.is_local: dispatcher.send(signal="post", event=Square_clicked(row, column)) else: num_to_letter = { 1: "a", 2: "b", 3: "c", 4: "d", 5: "e", 6: "f", 7: "g", 8: "h" } self.client.send_move(num_to_letter[column] + str(row)) self.decission_loop() def decission_loop(self): decided = False self.y_rect, self.n_rect = self.view.set_decission_screen() while not decided: mouse = pygame.mouse.get_pos() y = self.y_rect.collidepoint(mouse) n = self.n_rect.collidepoint(mouse) n = True if n == 1 else False y = True if y == 1 else False for event in pygame.event.get(): if event.type == pygame.QUIT: decided = True if event.type == pygame.MOUSEBUTTONDOWN: if y: decided = True dispatcher.send(signal='post', event=New_game()) if n: decided = True break self.view.refresh_decission_screen(y, n) pygame.quit() # ----------- em method -------------- def notify(self, event): if event.name == "game_ended": self.game_ended = True if event.name == "new_game": self.main_loop()
def __init__(self): self._model = Model() self._view = View() self._controller = Controller()
class ProgramMode(ABC): """klasa bazowa trybów programu takich jak Menu, Edytor poziomów, Gra""" runMode = True def __init__(self): self._model = Model() self._view = View() self._controller = Controller() def run(self): #główne pętla aktualnego trybu programu while self._model.get_run_mode(): if (self._model.get_change_mode()): self.change_mode() #przetwarzanie danych wejściowych self.process_input() #aktualizacja stanu modelu self.update() #renderowanie self.render() #ograniczenie fps - a jednak clock = py.time.Clock() clock.tick(120) #metoda tworząca odpowiedni nowy tryb i uruchamiająca go @abstractmethod def change_mode(self): pass #metoda, która zajmuje się wszelkimi rzeczami związanymi z danymi wejściowymi od użytkownika #@abstractmethod def process_input(self): self._controller.get_controls(self._view) self._controller.process_input() #metoda, która zajmuje się wszelkimi rzeczami związanymi z aktualizowaniem stanu wewnętrzego modelu #@abstractmethods def update(self): self._controller.give_command(self._model) self._model.update() #metoda, która zajmuje się wszelkimi rzeczami związanymi z renderowaniem obiektów na ekran #@abstractmethod def render(self): if self._model.get_error() == 0: return self._controller.communicateMV(self._model, self._view) self._view.render() def set_volume_from_file(self): file = open(define.get_options_file_path(), 'r') volume = 0 # odczyt kolejnych linii for line in file: splitted_line = line.strip().split() int_optionKey = int(splitted_line[0]) # dodanie informacji do tablicy opcji if int_optionKey == OptionKey.VOLUME: volume = int(splitted_line[1]) py.mixer_music.set_volume(volume / 100) file.close()
class Controller: def __init__(self): self.player = Player() self.view = View(1300, 800) self.view.change_view_state(View.STARTVIEW) self.game_state = None self.event_list_start_view = { 'start_button': self.start_button_pressed, 'quit_game': self.quit_button_pressed } self.event_list_game_view = { 'build_scout': self.create_ant, 'quit_game': self.quit_button_pressed } self.game_loop() def start_button_pressed(self, color, player_name): """ Event-handler for the start button to change Viewstate from Startview to Gameview :param color: Color chosen by player :param player_name: Name chosen by player :return: returns a game_state object for initialization of the game """ if player_name: self.view.change_view_state(View.GAMEVIEW) player = Player(color, player_name) player_list = [player] game_state = GameState(player_list) return game_state else: # TODO Get view to show pop up with message print('Player name not entered') def quit_button_pressed(self): """ :return: empty """ sys.exit() def create_ant(self): """ Event-handler for creating ants using the create ants button :param nest_position: Position of nest that should create ants :param ant_amount: Amount of ants created with one event :return: empty """ print(self.game_state.get_nests()) nest = self.game_state.get_nests()[0] self.game_state.create_ants(nest, amount=1) def game_loop(self): """ Main game loop :return: empty """ while True: if self.game_state is None: self.view.draw() # Get the list of events from view # event_argument_list = self.view.get_event() event_argument_list = self.view.events() if event_argument_list: print(event_argument_list) # Getting events and arguments as two lists event = list(event_argument_list.keys()) args = list(event_argument_list.values()) # Initializing player and game_state class for i in range(len(event)): if event[i] in self.event_list_start_view.keys(): if args[i] is not None: self.game_state = self.event_list_start_view[ event[i]](*args[i]) else: self.view.draw() self.view.update( self.game_state.get_objects_in_region( self.view.pos[0], self.view.pos[1])) # Get the list of events from view # event_argument_list = self.view.get_event() event_argument_list = self.view.events() if event_argument_list: print(event_argument_list) # Getting events and arguments as two lists event = list(event_argument_list.keys()) args = list(event_argument_list.values()) for i in range(len(event)): print(event[i]) if event[i] in self.event_list_game_view.keys(): self.event_list_game_view[event[i]](*args[i]) self.game_state.update()
def __init__(self): self.__dispositivo = None self.__elisa = None self.__recebedorPacote = None self.__view = View() self.start(self.__view.start())
def main(): """ Initial Models """ virtual_assistant = VirtualAssistant() chat = Chat(virtual_assistant) item_list = ItemList() """ Controllers """ chat_controller = ChatController(chat) virtual_assistant_controller = VirtualAssistantController( virtual_assistant) item_list_controller = ItemListController(item_list) """ View """ view = View() """ BestBuy API """ bb_api = BestbuyClient("D2MdM7zQG5OJdzY61jyC0Fjm") """ Runtime """ def msgAction(event): input = view.input_field.get() view.pushChat(input + "\n") view.input_user.set("") virtual_assistant_controller.updateSearchQuery(input) r = bb_api.newSearch(virtual_assistant_controller.getSearchQuery()) if (len(r) >= 3): view.changeLabel1("##" + r[0]['name'] + "##") view.changeLabel2( "##" + ("Price: " + str(r[0]['salePrice']) + "##")) view.changeLabel3("##" + "Rating: " + str(r[0]["customerRating"]) + "##") view.changeLabel4("##" + r[1]['name'] + "##") view.changeLabel5("##" + "Price: " + str(r[1]['salePrice']) + "##") view.changeLabel6("##" + "Rating: " + str(r[1]["customerRating"]) + "##") view.changeLabel7("##" + r[2]['name'] + "##") view.changeLabel8("##" + "Price: " + str(r[2]['salePrice']) + "##") view.changeLabel9("##" + "Rating: " + str(r[2]["customerRating"]) + "##") view.pushChat(virtual_assistant_controller.getNextLine() + "\n") view.assign(msgAction) view.pushChat("Hello, I'm AKASIA. What would you like to buy today?\n") view.mainLoop()
def __init__(self): self.__dispositivo = None self.__elisa = None self.__recebedorPacote = None self.__view = View() self.start(self.__view.start())
def test_view_size(): view = View(1300, 800) assert view.width == 1300 and view.height == 800
from src.models.messages import Messages from src.builders.messageBuilder import MessageBuilder from src.view.view import View import getpass if __name__ == '__main__': args = len(sys.argv) if args < 3: currentUsername = raw_input("Username: ") currentPassword = getpass.getpass() else: # get username and password from command line currentUsername = sys.argv[1] currentPassword = sys.argv[2] view = View(currentUsername, currentPassword) view.validateUser() view.initWrapper() m = MessageBuilder() m.buildMessageFromEmail('email.txt')
#!/usr/bin/python #################################################################### # Name: curse.py # Parameter: useremail password # This program is called from the command line to initiate the # CLI client. The user email address and password should be # passed on the command line. # example: python curse.py [email protected] 1234 #################################################################### import sys from src.view.view import View # get username (email) and password from command line: args = len(sys.argv) if args < 3: sys.exit("Invalid Input: include user-email and password in command line") userName = sys.argv[1] userPass = sys.argv[2] # start the curses CLI program from src/view/view.py newView = View(userName, userPass) newView.validateUser() newView.initWrapper()