# Imports ----------------------------- import sys import time # Globals ----------------------------- application_name = 'bdo.grindr' prompt = '>> ' delimiter = '-' delimiter_length = 80 menu_new_grind_loop = {'name': '(N)ew loop', 'hotkey': 'n', 'action': 'action_new_loop'} menu_pause_grind_loop = {'name': '(P)ause loop', 'hotkey': 'p', 'action': 'action_pause_loop'} menu_unpause_grind_loop = {'name': 'un(P)ause loop', 'hotkey': 'p', 'action': 'action_unpause_loop'} menu_end_grind_loop = {'name': '(E)nd loop', 'hotkey': 'e', 'action': 'action_end_loop'} menu_stats = {'name': 'display (S)tats', 'hotkey': 's', 'action': 'action_stats'} menu_reset = {'name': '(R)eset stats', 'hotkey': 'r', 'action': 'action_reset'} menu_help = {'name': '(H)elp', 'hotkey': 'h', 'action': 'action_help'} menu_exit = {'name': 'e(X)it', 'hotkey': 'x', 'action': 'action_exit'} state_not_started = 1 state_in_progress = 2 state_paused = 3 state_map = { state_not_started: 'Not started', state_in_progress: 'In Progress', state_paused: 'Paused' } loop_not_started_options = { 'name': 'loop not started', 'valid_states': [state_not_started], 'options': [menu_new_grind_loop, menu_stats, menu_reset, menu_help, menu_exit] } loop_in_progress_options = { 'name': 'loop in progress', 'valid_states': [state_in_progress], 'options': [menu_pause_grind_loop, menu_end_grind_loop, menu_stats, menu_reset, menu_help, menu_exit] } loop_paused_options = { 'name': 'loop in progress', 'valid_states': [state_paused], 'options': [menu_unpause_grind_loop, menu_stats, menu_reset, menu_help, menu_exit] } stats = { 'status': state_not_started, 'session_start_time': None, 'session_end_time': None, 'loop_start_time': None, 'loop_end_time': None, 'pause_start_time': None, 'pause_time': 0, 'start_exp': None, 'end_exp': None } # ------------------------------------- def menu_handler(options): # ------------------------------------- global stats while stats['status'] in options['valid_states']: # print '_____', application_name, '|', options['name'], '_____' print stats print delimiter * delimiter_length print 'Status:', state_map[stats['status']] print 'TODO: Other session stats' print delimiter * delimiter_length """ for counter, option in enumerate(options['options'], 1): print '%d. %s' % (counter, option['name']) """ menu_string = '' for counter, option in enumerate(options['options'], 1): if len(menu_string) > 0: menu_string += ' | ' menu_string += '%s' % (option['name']) print 'Commands: [' + menu_string + ']' print delimiter * delimiter_length input_validated = False while not input_validated: user_input = raw_input(prompt) for option in options['options']: if user_input.strip().lower() == option['hotkey'].strip().lower(): input_validated = True eval(option['action'] + '()') if not input_validated: print 'Invalid input:', user_input # ------------------------------------- def main_menu(): # ------------------------------------- print 'main_menu' global stats menu_handler(loop_not_started_options) # ------------------------------------- def action_exit(): # ------------------------------------- print 'action_exit' global stats sys.exit(0) # ------------------------------------- def action_help(): # ------------------------------------- print 'action_help' global stats # ------------------------------------- def action_reset(): # ------------------------------------- print 'action_reset' global stats # ------------------------------------- def action_stats(): # ------------------------------------- print 'action_stats' global stats # ------------------------------------- def action_new_loop(): # ------------------------------------- print 'action_new_loop' global stats stats['status'] = state_in_progress menu_handler(loop_in_progress_options) # ------------------------------------- def action_end_loop(): # ------------------------------------- print 'action_end_loop' global stats stats['status'] = state_not_started # ------------------------------------- def action_pause_loop(): # ------------------------------------- print 'action_pause_loop' global stats stats['pause_start_time'] = time.time() stats['status'] = state_paused menu_handler(loop_paused_options) # ------------------------------------- def action_unpause_loop(): # ------------------------------------- print 'action_unpause_loop' global stats stats['pause_time'] = time.time() - stats['pause_start_time'] stats['pause_start_time'] = None stats['status'] = state_in_progress # ------------------------------------- if __name__ == "__main__": # ------------------------------------- main_menu()
Run
Reset
Share
Import
Link
Embed
Language▼
English
中文
Python Fiddle
Python Cloud IDE
Follow @python_fiddle
Browser Version Not Supported
Due to Python Fiddle's reliance on advanced JavaScript techniques, older browsers might have problems running it correctly. Please download the latest version of your favourite browser.
Chrome 10+
Firefox 4+
Safari 5+
IE 10+
Let me try anyway!
url:
Go
Python Snippet
Stackoverflow Question