Esempio n. 1
0
def main(stdscr):
    # Settings
    stdscr.nodelay(True)
    curses.curs_set(0)

    SLEEP_TIME = 1. / 120.0
    RENDER_TIME = 1. / 60.0

    # Context for whole application
    global_context = GlobalContext()
    global_context.main_screen = Screen(stdscr)
    global_context.database = HexDatabase()
    global_context.database.db_init()
    global_context.state_machine = StateMachine(global_context)

    # Aliases
    state_machine = global_context.state_machine
    main_screen = global_context.main_screen

    gClose = False
    render_timer = 0.  #
    while (not gClose) and (not state_machine.is_empty()):
        time.sleep(SLEEP_TIME)
        render_timer += SLEEP_TIME

        # Input
        key = stdscr.getch()
        if key != -1:
            state_machine.on_input(key)

        # Update
        state_machine.on_update(SLEEP_TIME)

        # Render
        if render_timer >= RENDER_TIME:
            main_screen.clear()
            state_machine.on_render()
            main_screen.render()

            render_timer = 0.
    def _init_session_params(self, query):
        self._params.user_token = query.get_user_token()
        self._params.sign_id = query.get_required_int64('sign_id')
        self._params.is_private = query.get_optional_bool('is_private')

    def _run_session(self):
        info = self._sign_engine.get_info(self._params.sign_id)

        # Check user credentials
        self._access_rules.check_can_edit_sign(self._params.user_token,
                                               sign_info=info)

        if self._params.is_private != None:
            self._sign_engine.set_sign_privacy(self._params.sign_id,
                                               self._params.is_private)

        return {'success': True}


if __name__ == "__main__":
    from global_context import GlobalContext
    global_context = GlobalContext()
    global_context.initialize()

    s = UpdateSignSession(global_context)
    s.parse_query(
        '{"user_token": "Gn0qsNoPY2BJGhfVYpKaVilLcClAMhbkOUocm6wTCEYfrL2sdzOs3FDVPOKk/paM9rsRALIS5VnnNxPGgcq33gBrcuy5cvHsSddQY8SqGNJ5lBDPZC4nT4imTibF+Uz/", "sign_id": 1152699052946918040}'
    )
    print s.execute()