예제 #1
0
파일: 2048.py 프로젝트: mochar/2048-remake
    def __init__(self):
        pyglet.window.Window.__init__(self, width=275, height=275)

        # show and set the fps
        pyglet.clock.set_fps_limit(60.0)
        self.fps_display = pyglet.clock.ClockDisplay()

        # notification queue
        self.notifications = []

        # the menu with the options in it
        self.menu = Menu(self)
        self.menu_open = False

        # Show info about tiles
        self.debug = False

        # add items to the menu
        self.menu.add_item('Scoreboard', exit)
        self.menu.add_item('Restart', self.restart)

        # notification telling the player how to open the menu
        self.add_notification('Press \'M\'', 'to open the menu', duration=2.5)

        self.background = pyglet.resource.image('background.png')

        # the board object of the game. check the Board class for more info
        self.game_board = Board(self)
예제 #2
0
    def __init__(self, *args, **kwargs):
        super(RootBox, self).__init__(*args, **kwargs)
        self.chat_client = None
        self.receive_queue = Queue()

        # create the confirm box for quitting
        self.quit_confirm = ConfirmPopup(title='Quit?', confirm_text='Quit')
        self.quit_confirm.bind(on_confirm=self.quit_pushed)
        self.quit_confirm.bind(on_cancel=self.cancel_pushed)

        # there is some sort of instantiation order problem where you can't
        # directly refer to custom classes as children in the kv language, so
        # everywhere were we want custom classes there is a BoxLayout which we
        # will now put the custom classes inside
        self.menu = Menu()
        self.menu.hide_item('Chats')
        self.menu.bind(text=self.menu_action)
        self.ids.menu_container.add_widget(self.menu)

        self.chat_box = ChatBox()
        self.ids.chat_box_container.add_widget(self.chat_box)
        
        # don't add server_list just yet, it has the connection status label in
        # it
        # self.server_list = ServerBox(self)

        # store = JsonStore('storage.json')
        # try:
        #     userid = store.get('account')['userid']
        #     password = store.get('account')['password']
        #     host = store.get('server')['host']
        #     port = store.get('server')['port']
        # except KeyError as msg:
        #     print("test {}".format(msg))
        #     self.ids.connection_label.text = 'No Username Set'
        # else:
        #     # create the chat client and start processing on separate thread
        #     self.chat_client = ChatClient(self, userid, password)
        #     self.chat_client.connect((host, port))
        #     self.chat_client.process(block=False)

        self.chat_client = TMPClient(self, tmp, username)
예제 #3
0
def main():
    """Main entry point for the script"""
    parser = argparse.ArgumentParser(
        prog='PyVegan',
        description='The better way to collect some delicious vegan recipes!',
        usage="""
        PyVegan - Get delicious vegan recipes from the web!
        Usage: pyvegan [-s/--search ingredient_to_search]


        Examples:
        - Get recipes with potato
            $ pyvegan -s batata
        - Get recipes that use more than one ingredient
            $ pyvegan -s "batata e tomate"

        How to get basic options and help? Use -h/--help
        """,
    )
    parser.add_argument('-s',
                        '--search',
                        type=str,
                        help='Get recipes using the given ingredients')

    options = parser.parse_args()

    if options.search:
        param = options.search
    else:
        param = ''

    try:
        browser = Browser()
        browser.search(param)
        content = browser.page_content()
    except requests.ConnectionError:
        print('A connection problem occurred.')
    except requests.Timeout:
        print('A timeout problem occurred.')
    except requests.TooManyRedirects:
        msg = ('The request exceeds the configured'
               ' number of maximum redirections.')
        print(msg)
    except Exception as e:
        print(e)

    if not content:
        return

    recipeManager = RecipeManager(content)
    recipes = recipeManager.recipes

    menu = Menu(recipes)
    menu.build()
    menu.show()
예제 #4
0
    def __init__(self, *args, **kwargs):
        super(RootBox, self).__init__(*args, **kwargs)
        self.chat_client = None
        self.receive_queue = Queue()

        # create the confirm box for quitting
        self.quit_confirm = ConfirmPopup(title='Quit?', confirm_text='Quit')
        self.quit_confirm.bind(on_confirm=self.quit_pushed)
        self.quit_confirm.bind(on_cancel=self.cancel_pushed)

        # there is some sort of instantiation order problem where you can't
        # directly refer to custom classes as children in the kv language, so
        # everywhere were we want custom classes there is a BoxLayout which we
        # will now put the custom classes inside
        self.menu = Menu()
        self.menu.hide_item('Chats')
        self.menu.bind(text=self.menu_action)
        self.ids.menu_container.add_widget(self.menu)

        self.chat_box = ChatBox()
        self.ids.chat_box_container.add_widget(self.chat_box)
        
        # don't add friend_box just yet, it has the connection status label in
        # it
        self.friend_box = FriendBox(self)

        store = JsonStore('storage.json')
        try:
            userid = store.get('account')['userid']
            password = store.get('account')['password']
            host = store.get('server')['host']
            port = store.get('server')['port']
        except KeyError:
            self.ids.connection_label.text = 'No Username Set'
        else:
            # create the chat client and start processing on separate thread
            self.chat_client = ChatClient(self, userid, password)
            self.chat_client.connect((host, port))
            self.chat_client.process(block=False)  
예제 #5
0
class RootBox(BoxLayout):
    def __init__(self, *args, **kwargs):
        super(RootBox, self).__init__(*args, **kwargs)
        self.chat_client = None
        self.receive_queue = Queue()

        # create the confirm box for quitting
        self.quit_confirm = ConfirmPopup(title='Quit?', confirm_text='Quit')
        self.quit_confirm.bind(on_confirm=self.quit_pushed)
        self.quit_confirm.bind(on_cancel=self.cancel_pushed)

        # there is some sort of instantiation order problem where you can't
        # directly refer to custom classes as children in the kv language, so
        # everywhere were we want custom classes there is a BoxLayout which we
        # will now put the custom classes inside
        self.menu = Menu()
        self.menu.hide_item('Chats')
        self.menu.bind(text=self.menu_action)
        self.ids.menu_container.add_widget(self.menu)

        self.chat_box = ChatBox()
        self.ids.chat_box_container.add_widget(self.chat_box)

        # don't add friend_box just yet, it has the connection status label in
        # it
        self.friend_box = FriendBox(self)

        store = JsonStore('storage.json')
        try:
            userid = store.get('account')['userid']
            password = store.get('account')['password']
            host = store.get('server')['host']
            port = store.get('server')['port']
        except KeyError:
            self.ids.connection_label.text = 'No Username Set'
        else:
            # create the chat client and start processing on separate thread
            self.chat_client = ChatClient(self, userid, password)
            self.chat_client.connect((host, port))
            self.chat_client.process(block=False)

    def quit_pushed(self, *args):
        print 'Disconnecting...'
        if self.chat_client:
            self.chat_client.disconnect(wait=True)
        quit()

    def cancel_pushed(self, *args):
        # changed their mind about quitting, as our menu is not a real menu
        # but a spinner, we need to reset the display value to be our current
        # screen
        self.menu.text = self.ids.screen_manager.current

    def menu_action(self, spinner, text):
        if text == 'Quit':
            self.quit_confirm.open()
        elif text == 'Settings':
            app = App.get_running_app()
            app.open_settings()

            # settings uses a pop-up, need to set our spinner menu back to
            # wherever we were
            self.menu.text = self.ids.screen_manager.current
        elif text == 'Chats':
            # go to chat screen and clear the current tab's friend's message
            # count
            self.ids.screen_manager.current = text
            current_tab = self.chat_box.ids.tab_content.current
            try:
                self.chat_box.chats[current_tab]['friend'].message_count = 0
            except KeyError:
                # there is no current tab, do nothing
                pass
        else:
            # switch to the screen chosen by the spinner
            self.ids.screen_manager.current = text

    def menu_add_chat(self):
        self.menu.show_item('Chats')

    def menu_remove_chat(self):
        self.menu.hide_item('Chats', select='Contacts')
        self.ids.screen_manager.current = 'Contacts'
예제 #6
0
class RootBox(BoxLayout):
    def __init__(self, *args, **kwargs):
        super(RootBox, self).__init__(*args, **kwargs)
        self.chat_client = None
        self.receive_queue = Queue()

        # create the confirm box for quitting
        self.quit_confirm = ConfirmPopup(title='Quit?', confirm_text='Quit')
        self.quit_confirm.bind(on_confirm=self.quit_pushed)
        self.quit_confirm.bind(on_cancel=self.cancel_pushed)

        # there is some sort of instantiation order problem where you can't
        # directly refer to custom classes as children in the kv language, so
        # everywhere were we want custom classes there is a BoxLayout which we
        # will now put the custom classes inside
        self.menu = Menu()
        self.menu.hide_item('Chats')
        self.menu.bind(text=self.menu_action)
        self.ids.menu_container.add_widget(self.menu)

        self.chat_box = ChatBox()
        self.ids.chat_box_container.add_widget(self.chat_box)
        
        # don't add friend_box just yet, it has the connection status label in
        # it
        self.friend_box = FriendBox(self)

        store = JsonStore('storage.json')
        try:
            userid = store.get('account')['userid']
            password = store.get('account')['password']
            host = store.get('server')['host']
            port = store.get('server')['port']
        except KeyError:
            self.ids.connection_label.text = 'No Username Set'
        else:
            # create the chat client and start processing on separate thread
            self.chat_client = ChatClient(self, userid, password)
            self.chat_client.connect((host, port))
            self.chat_client.process(block=False)  

    def quit_pushed(self, *args):
        print ('Disconnecting...')
        if self.chat_client:
            self.chat_client.disconnect(wait=True)
        quit()

    def cancel_pushed(self, *args):
        # changed their mind about quitting, as our menu is not a real menu
        # but a spinner, we need to reset the display value to be our current
        # screen
        self.menu.text = self.ids.screen_manager.current

    def menu_action(self, spinner, text):
        if text == 'Quit':
            self.quit_confirm.open()
        elif text == 'Settings':
            app = App.get_running_app()
            app.open_settings()

            # settings uses a pop-up, need to set our spinner menu back to
            # wherever we were
            self.menu.text = self.ids.screen_manager.current
        elif text == 'Chats':
            # go to chat screen and clear the current tab's friend's message
            # count
            self.ids.screen_manager.current = text
            current_tab = self.chat_box.ids.tab_content.current
            try:
                self.chat_box.chats[current_tab]['friend'].message_count = 0
            except KeyError:
                # there is no current tab, do nothing
                pass
        else:
            # switch to the screen chosen by the spinner
            self.ids.screen_manager.current = text

    def menu_add_chat(self):
        self.menu.show_item('Chats')

    def menu_remove_chat(self):
        self.menu.hide_item('Chats', select='Contacts')
        self.ids.screen_manager.current = 'Contacts'
예제 #7
0
                break


USER_PROFILE = Menu(
    'User profile Menu',
    [
        [
            'Create blank profile', None,
            create_blank_profile
        ],
        [
            'Show current profile', None,
            get_current_profile
        ],
        [
            'Rate a restaurant', None,
            rate_restaurant
        ],
        [
            'Load user profile', None,
            load_user_profile
        ],
        [
            'Save current user profile', None,
            save_user_profile
        ]
    ]
)


CUISINE_MENU = Menu(
예제 #8
0
파일: 2048.py 프로젝트: mochar/2048-remake
class GameWindow(pyglet.window.Window):
    def __init__(self):
        pyglet.window.Window.__init__(self, width=275, height=275)

        # show and set the fps
        pyglet.clock.set_fps_limit(60.0)
        self.fps_display = pyglet.clock.ClockDisplay()

        # notification queue
        self.notifications = []

        # the menu with the options in it
        self.menu = Menu(self)
        self.menu_open = False

        # Show info about tiles
        self.debug = False

        # add items to the menu
        self.menu.add_item('Scoreboard', exit)
        self.menu.add_item('Restart', self.restart)

        # notification telling the player how to open the menu
        self.add_notification('Press \'M\'', 'to open the menu', duration=2.5)

        self.background = pyglet.resource.image('background.png')

        # the board object of the game. check the Board class for more info
        self.game_board = Board(self)

    def game_tick(self):
        """
        Runs only when a move has been made. Less resource intensive! :D
        """
        self.game_board.update()

    def show_notifications(self):
        for n in self.notifications:
            n.draw()

    def add_notification(self, title, text, duration=5):
        notification = Notification(self, title, text, group=GAME_LAYER)
        self.notifications.append(notification)
        pyglet.clock.schedule_once(lambda x: self.notifications.remove(notification), duration)

    def on_key_press(self, symbol, modifiers):
        if self.menu_open: # we're in the menu
            if symbol == key.F:
                print('Pressed \'F\' while in menu.')
        else:
            if symbol == key.DOWN:
                self.game_board.move_tiles(DIRECTIONS['DOWN'])
                self.game_tick()
            elif symbol == key.UP:
                self.game_board.move_tiles(DIRECTIONS['UP'])
                self.game_tick()
            elif symbol == key.LEFT:
                self.game_board.move_tiles(DIRECTIONS['LEFT'])
                self.game_tick()
            elif symbol == key.RIGHT:
                self.game_board.move_tiles(DIRECTIONS['RIGHT'])
                self.game_tick()
            elif symbol == key.R: # cheating, just to test
                pos = self.game_board.board[0][3]['pos']
                self.game_board.new_tile(choice([2, 4]), pos[0], pos[1])
            elif symbol == key.N:
                self.add_notification('WARNING', 'Watch out, storm ahead!')

        if symbol == key.M:
            self.menu_open = not self.menu_open
        if symbol == key.K:
            self.debug = not self.debug
    def on_mouse_press(self, x, y, button, modifiers):
        if self.menu_open:
            self.menu.on_mouse_press(x, y, button, modifiers)

    def on_draw(self):
        self.clear()
        self.background.blit(0, 0)
        BATCH.draw()
        self.show_notifications()

        if self.debug:
            self.game_board.show_tile_info()
            self.fps_display.draw()

        if self.menu_open:
            self.menu.show()

    def start(self):
        """
        Starts the game.
        """
        pass

    def end(self):
        """
        Ends the game.
        """
        self.add_notification('You lost!', 'Too bad, haha!')

    def restart(self):
        self.game_board = Board(self)
        self.menu_open = False