def handle_error(trace=None): """Any errors are sent to here.""" if trace is not None: output = [ 'Mouse Tracks v{} | Python {} | {}'.format(VERSION, PYTHON_VERSION, OPERATING_SYSTEM) ] output.append('') output.append(trace) output = '\n'.join(output) file_name = format_file_path('{}\\error.txt'.format(DEFAULT_PATH)) with open(file_name, 'w') as f: f.write(output) _print(trace) string = Language().get_strings() input(string['string']['exit']) sys.exit()
def fix_poe_mine_build(profile_name, numpad_key): try: _num = 'NUM{}'.format(int(numpad_key)) except ValueError: return False data = LoadData(profile_name, _reset_sessions=False) #Make sure record exists, quick delete if issue is obvious (0 press >0 held) try: if not data['Keys']['All']['Pressed'][_num]: raise KeyError except KeyError: try: del data['Keys']['All']['Held'][_num] except KeyError: pass else: #Count the other numpad items total = {'pressed': 0, 'held': 0, 'count': 0} for i in range(1, 10): if i == numpad_key: continue num = 'NUM{}'.format(i) try: total['pressed'] += data['Keys']['All']['Pressed'][num] total['held'] += data['Keys']['All']['Held'][num] except KeyError: pass else: total['count'] += 1 #Get the average time the numpad is pressed for try: average_press_time = total['held'] / total['pressed'] except ZeroDivisionError: average_press_time = 0 Message('Unable to get an average as no other keypad data exists.') result = input( 'Do you want to delete the numpad key instead (y/n)? ') if not is_yes(result): return False #Assign to numpad key new_held_time = round_int(data['Keys']['All']['Pressed'][_num] * average_press_time) data['Keys']['All']['Held'][_num] = new_held_time return save_data(profile_name, data)
def user_generate(): """Ask for options and generate an image. This seriously needs rewriting. Idea: List of profiles (choose page/type id/type name), shows the file size and last modified date of each profile. (Load profile) Say some stats about the profile Ask for mouse tracks, clicks and key presses For each of those, ask for colour profile and say the file location Ask to open folder (will require image path rewrite for a base path) Loop back to start if required """ all_strings = Language().get_strings() _string = all_strings['string'] string = all_strings['string']['image'] word = all_strings['word'] Message(string['profile']['list'].format(L=word['list'])) profile = input() if profile.lower() == word['list'].lower(): #Read the data folder and format names all_files = list_data_files() if not all_files: Message(string['profile']['empty']) Message(all_strings['exit']) input() sys.exit() programs = {format_name(DEFAULT_NAME): DEFAULT_NAME} app_list = AppList() for program_name in app_list.names: programs[format_name(program_name)] = program_name page = 1 limit = 15 maximum = len(all_files) total_pages = round_up(maximum / limit) sort_date = string['page']['sort']['date'] sort_name = string['page']['sort']['name'] change_sort = [sort_name, 2] #Ask for user input while True: offset = (page - 1) * limit results = all_files[offset:offset + limit] for i, r in enumerate(results): try: program_name = programs[r] except KeyError: program_name = r Message('{}: {}'.format(i + offset + 1, program_name)) Message(string['page']['current'].format(C=page, T=total_pages, P=word['page'])) Message(change_sort[0].format( S='{} {}'.format(word['sort'], change_sort[1]))) Message(string['profile']['number']['input']) profile = input() last_page = page #Change page if profile.lower().startswith('{P} '.format(P=word['page'])): try: page = int(profile.split()[1]) if not 0 < page <= total_pages: raise ValueError except IndexError: Message(string['page']['invalid']) except ValueError: if page > total_pages: page = total_pages else: page = 1 #Shortcut to change page elif profile.endswith('>'): if page < total_pages: page += 1 elif profile.startswith('<'): if page > 1: page -= 1 #Change sorting of profile list elif (profile.lower().startswith('{} '.format(word['sort'])) or profile.lower() == word['sort']): try: sort_level = int(profile.split()[1]) except ValueError: sort_level = 0 except IndexError: sort_level = 1 try: sort_reverse = int(profile.split()[2]) except (ValueError, IndexError): sort_reverse = 0 if sort_level == 1: all_files = list_data_files() change_sort = [sort_name, 2] elif sort_level == 2: all_files = sorted(list_data_files()) change_sort = [sort_date, 1] if sort_reverse: all_files = all_files[::-1] #Select profile else: try: num = int(profile) - 1 if not 0 <= num <= maximum: raise IndexError profile_name = all_files[num] try: profile = programs[all_files[num]] except KeyError: profile = all_files[num] break except ValueError: break except IndexError: Message(string['profile']['number']['nomatch']) try: profile = programs[profile] except KeyError: pass #Load functions Message(_string['import']) from core.image import RenderImage Message(_string['profile']['load'].format(P=profile)) try: r = RenderImage(profile) except ValueError: Message('Error: Selected profile is empty or doesn\'t exist.') return #Check if profile is running try: current_profile = format_name(RunningApplications().check()[0]) except TypeError: pass else: selected_profile = format_name(profile) if current_profile == selected_profile: Message(string['profile']['running']['warning']) save_time = ticks_to_seconds(CONFIG['Save']['Frequency'], 1) metadata = load_data(profile, _metadata_only=True) if metadata['Modified'] is None: Message(string['save']['wait']) Message(string['save']['frequency'].format(T=save_time)) Message(_string['exit']) input() sys.exit() else: last_save_time = time.time() - metadata['Modified'] next_save_time = CONFIG['Save']['Frequency'] - last_save_time last_save = ticks_to_seconds(last_save_time, 1, allow_decimals=False) next_save = ticks_to_seconds(next_save_time, 1, allow_decimals=False) Message(string['save']['next'].format(T1=last_save, T2=next_save)) generate_tracks = False generate_speed = False generate_heatmap = False generate_keyboard = False generate_csv = False default_options = [True, False, True, True, False] kb_string = string['name']['keyboard'] kph = r.keys_per_hour() if kph < 10: default_options[2] = False kb_string = '{} ({})'.format( kb_string, string['name']['low']['keyboard']).format(C=round(kph, 2)) Message(string['option']['generate']) default_option_text = ' '.join( str(i + 1) for i, v in enumerate(default_options) if v) Message(string['option']['select'].format(V=default_option_text)) Message('1: {}'.format(string['name']['track'])) Message('2: {}'.format(string['name']['speed'])) Message('3: {}'.format(string['name']['click'])) Message('4: {}'.format(kb_string)) Message('5: {}'.format(string['name']['csv'])) selection = list(map(int, input().split())) result = value_select(selection, default_options, start=1) if result[0]: generate_tracks = True if result[1]: generate_speed = True if result[2]: generate_heatmap = True Message('Which mouse buttons should be included in the heatmap?.') default_options = [ CONFIG['GenerateHeatmap']['_MouseButtonLeft'], CONFIG['GenerateHeatmap']['_MouseButtonMiddle'], CONFIG['GenerateHeatmap']['_MouseButtonRight'] ] default_option_text = ' '.join( str(i + 1) for i, v in enumerate(default_options) if v) Message(string['option']['select'].format(V=default_option_text)) Message('1: {}'.format(word['mousebutton']['left'])) Message('2: {}'.format(word['mousebutton']['middle'])) Message('3: {}'.format(word['mousebutton']['right'])) selection = list(map(int, input().split())) heatmap_buttons = value_select(selection, default_options, start=1) CONFIG['GenerateHeatmap']['_MouseButtonLeft'] = heatmap_buttons[0] CONFIG['GenerateHeatmap']['_MouseButtonMiddle'] = heatmap_buttons[1] CONFIG['GenerateHeatmap']['_MouseButtonRight'] = heatmap_buttons[2] if not any(heatmap_buttons): generate_heatmap = False if result[3]: generate_keyboard = True if result[4]: generate_csv = True if any((generate_tracks, generate_speed, generate_heatmap, generate_keyboard, generate_csv)): last_session_start = r.data['Ticks']['Session']['Total'] last_session_end = r.data['Ticks']['Total'] all_time = ticks_to_seconds(last_session_end, UPDATES_PER_SECOND) last_session_time = ticks_to_seconds( last_session_end - last_session_start, UPDATES_PER_SECOND) csv_only = generate_csv and not any( (generate_tracks, generate_heatmap, generate_keyboard)) if not last_session_time or last_session_time == all_time or csv_only: last_session = False else: while True: Message(string['option']['session']['select']) Message('1: {} [{}]'.format( string['option']['session']['all'].format(T=all_time), word['default'])) Message('2: {}'.format( string['option']['session']['last'].format( T=last_session_time))) selection = list(map(int, input().split())) result = value_select(selection, [True, False], start=1) if result[0] and result[1]: Message(string['option']['error']['single']) elif result[1]: last_session = True break else: last_session = False break #Generate if generate_tracks: r.tracks(last_session) if generate_speed: r.speed(last_session) if generate_heatmap: r.clicks(last_session) if generate_keyboard: r.keyboard(last_session) if generate_csv: r.csv() if CONFIG['GenerateImages']['OpenOnFinish']: Message(string['option']['open']) open_folder(r.name.generate()) else: Message(string['option']['error']['nothing'])
Message('Unable to get an average as no other keypad data exists.') result = input( 'Do you want to delete the numpad key instead (y/n)? ') if not is_yes(result): return False #Assign to numpad key new_held_time = round_int(data['Keys']['All']['Pressed'][_num] * average_press_time) data['Keys']['All']['Held'][_num] = new_held_time return save_data(profile_name, data) Message('This is a fix for the numlock mine trick in Path of Exile.') Message( 'The trick fools the computer into thinking the key is held down, but it doesn\'t release when the game is quit.' ) Message( 'This fix replaces the \'held down\' time of the key with an average from the other numpad keys.' ) Message( 'The issue is now fixed for other profiles, as the held down keys will be ignored after a profile switch.' ) profile_name = input('Type the name of the profile to fix: ') numpad_key = input('Type which numpad key is being used for mines: ') Message('Please wait while the fix is completed...') if fix_poe_mine_build(profile_name, numpad_key): Message('Finished updating profile.') else: Message('Failed to update profile.')
This is part of the Mouse Tracks Python application. Source: https://github.com/Peter92/MouseTracks """ from __future__ import absolute_import import socket from core.api import AUTOMATIC_PORT, SERVER_PORT from core.compatibility import input from core.sockets import * sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) try: port = int( input('Type a port to connect to, or leave blank to use {}:'.format( SERVER_PORT))) except (TypeError, ValueError): port = SERVER_PORT sock.connect(('localhost', SERVER_PORT)) try: #Print every received message while True: message = recv_msg(sock) if message is None: sock.close() break print(message) except KeyboardInterrupt: sock.close()
""" This is part of the Mouse Tracks Python application. Source: https://github.com/Peter92/MouseTracks """ from __future__ import absolute_import from core.applications import AppList from core.compatibility import input from core.config import CONFIG from core.constants import APP_LIST_FILE if __name__ == '__main__': if not CONFIG['Internet']['Enable']: choice = input( 'Internet access is disabled. Would you like to update from the online {}? (y/n) ' .format(APP_LIST_FILE)) if choice.lower().startswith('y'): CONFIG['Internet']['Enable'] = True CONFIG['SavedSettings']['AppListUpdate'] = 0 AppList().save() input('Finished, press enter to quit.')