def __init__(self, file_name, default_data, group_order=None): self.file_name = format_file_path(file_name) self._default_data = default_data self.default_data = {} self.order = list(group_order) if group_order is not None else [] for group, data in get_items(self._default_data): self.default_data[group] = self._default_data[group] self.load()
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 __call__(self, message_id, *args): q0 = self.message_queue[0].append q1 = self.message_queue[1].append q2 = self.message_queue[2].append if message_id == MESSAGE_DEBUG: self.debug.append(args) if message_id == MOUSE_UNDETECTED: q2(self.string['mouse']['undetected']) if message_id == MOUSE_DETECTED: q2(self.string['mouse']['detected']) if message_id == MOUSE_OFFSCREEN: q1(self.string['mouse']['offscreen']) if message_id == MOUSE_ONSCREEN: q1(self.string['mouse']['onscreen']) if message_id == MOUSE_POSITION: q0(self.string['mouse']['position'].format(X=args[0][0], Y=args[0][1])) if message_id == MOUSE_CLICKED: mouse_button = args[0] try: resolution = args[1] except IndexError: q1(self.string['mouse']['clicked']['offscreen'].format( MB=self._mb(mouse_button), C=self.word['mouse']['click']['single'])) else: q1(self.string['mouse']['clicked']['onscreen'].format( MB=self._mb(mouse_button), X=resolution[0], Y=resolution[1], C=self.word['mouse']['click']['single'])) if message_id == MOUSE_CLICKED_DOUBLE: mouse_button = args[0] try: resolution = args[1] except IndexError: q1(self.string['mouse']['clicked']['offscreen'].format( MB=self._mb(mouse_button), C=self.word['mouse']['click']['double'])) else: q1(self.string['mouse']['clicked']['onscreen'].format( MB=self._mb(mouse_button), X=resolution[0], Y=resolution[1], C=self.word['mouse']['click']['double'])) if message_id == MOUSE_CLICKED_HELD: mouse_button = args[0] try: resolution = args[1] except IndexError: q1(self.string['mouse']['held']['offscreen'].format( MB=self._mb(mouse_button))) else: q1(self.string['mouse']['held']['onscreen'].format( MB=self._mb(mouse_button), X=resolution[0], Y=resolution[1])) if message_id == MOUSE_UNCLICKED: q0(self.string['mouse']['unclicked']) if message_id == TRACK_COMPRESS_START: q2(self.string['compress']['start']) if message_id == TRACK_COMPRESS_END: q2(self.string['compress']['end']) if message_id == RESOLUTION_CHANGED: q2(self.string['resolution']['new'].format(X1=args[0][0], Y1=args[0][1], X2=args[1][0], Y2=args[1][1])) if message_id == MONITOR_CHANGED: q1(self.string['resolution']['changed'].format(X1=args[0][0], Y1=args[0][1], X2=args[1][0], Y2=args[1][1])) if message_id == APPLICATION_RESOLUTION: q1(self.string['resolution']['application']['start'].format( X=args[0][0], Y=args[0][1])) if message_id == APPLICATION_MOVE: q1(self.string['resolution']['application']['move'].format( X1=args[0][0], Y1=args[0][1], X2=args[1][0], Y2=args[1][1])) if message_id == APPLICATION_RESIZE: q1(self.string['resolution']['application']['resize'].format( X1=args[0][0], Y1=args[0][1], X2=args[1][0], Y2=args[1][1])) if message_id == KEYBOARD_PRESSES: _press = self.word['keypress'] press = _press['single'] if len(args[0]) == 1 else _press['plural'] q1(self.string['keyboard']['press'].format(K=', '.join(*args), P=press)) if message_id == KEYBOARD_PRESSES_HELD: _press = self.word['keypress'] press = _press['single'] if len(args[0]) == 1 else _press['plural'] q1(self.string['keyboard']['held'].format(K=', '.join(*args), P=press)) if message_id == APPLICATION_STARTED: q2(self.string['application']['start'].format(A=args[0][0])) if message_id == APPLICATION_LOADING: try: if args[0][0] is None: raise TypeError() except (IndexError, TypeError): profile = DEFAULT_NAME else: profile = args[0][0] q2(self.string['application']['load'].format(A=profile)) if message_id == APPLICATION_QUIT: try: if args[0][0] is None: raise TypeError() except (IndexError, TypeError): profile = DEFAULT_NAME else: profile = args[0][0] q2(self.string['application']['quit'].format(A=profile)) if message_id == APPLICATION_RELOAD: q1(self.string['application']['reload']) if message_id == APPLICATION_LISTEN: q1(self.string['application']['listen']) if message_id == APPLICATION_FOCUSED: try: if args[0][0] is None: raise TypeError() except (IndexError, TypeError): profile = DEFAULT_NAME else: profile = args[0][0] q1(self.string['application']['focused'].format(A=profile)) if message_id == APPLICATION_UNFOCUSED: try: if args[0][0] is None: raise TypeError() except (IndexError, TypeError): profile = DEFAULT_NAME else: profile = args[0][0] q1(self.string['application']['unfocused'].format(A=profile)) if message_id == APPLIST_UPDATE_START: q1(self.string['application']['update']['start']) if message_id == APPLIST_UPDATE_SUCCESS: q1(self.string['application']['update']['success']) if message_id == APPLIST_UPDATE_FAIL: q1(self.string['application']['update']['fail']) if message_id == SAVE_START: q2(self.string['save']['start']) if message_id == SAVE_SUCCESS: q2(self.string['save']['success']) if message_id == SAVE_FAIL: q2(self.string['save']['fail']['noretry']) if message_id == SAVE_FAIL_RETRY: _second = self.word['second'] second = _second['single'] if args[0] == 1 else _second['plural'] q2(self.string['save']['fail']['retry'].format(T=args[0], S=second, C=args[1] + 1, M=args[2])) if message_id == SAVE_FAIL_END: q2(self.string['save']['fail']['end']) if message_id == SAVE_SKIP: if args[1] > 2: q2(self.string['save']['skip']['nochange']) else: _second = self.word['second'] second = _second['single'] if args[0] == 1 else _second[ 'plural'] q2(self.string['save']['skip']['inactive'].format(T=args[0], S=second)) if message_id == SAVE_PREPARE: q2(self.string['save']['prepare']) if message_id == START_MAIN: q2(self.string['script']['main']['start']) if message_id == START_THREAD: q2(self.string['script']['thread']['start']) if message_id == DATA_LOADED: q1(self.string['profile']['load']) if message_id == DATA_NOTFOUND: q1(self.string['profile']['new']) if message_id == MT_PATH: q2(self.string['path'].format(P=format_file_path(DEFAULT_PATH))) if message_id == QUEUE_SIZE: _command = self.word['command'] command = _command['single'] if args[0] == 1 else _command['plural'] q1(self.string['queue'].format(N=args[0], C=command)) if message_id == PROCESS_EXIT: q2(self.string['script']['main']['end']) if message_id == THREAD_EXIT: q2(self.string['script']['thread']['end'])
def generate(self, image_type, reload=False): image_type = image_type.lower() if reload: self.reload() lookup = {'clicks': 'GenerateHeatmap', 'tracks': 'GenerateTracks', 'keyboard': 'GenerateKeyboard', 'csv-tracks': 'NameFormatTracks', 'csv-clicks': 'NameFormatClicks', 'csv-keyboard': 'NameFormatKeyboard'} try: name = CONFIG[lookup[image_type]]['NameFormat'] except KeyError: try: name = CONFIG['GenerateCSV'][lookup[image_type]] except KeyError: raise ValueError('incorred image type: {}'.format(image_type)) #Rename alternative variables for k, v in get_items(self.ALTERNATIVES): k = '[{}]'.format(k) for i in v: i = '[{}]'.format(i) name = name.replace(i, k) #General Options name = name.replace('[Name]', self.name) name = name.replace('[FileName]', self.file_name) name = name.replace('[Width]', self.width) name = name.replace('[Height]', self.height) name = name.replace('[UpscaleWidth]', self.uwidth) name = name.replace('[UpscaleHeight]', self.uheight) name = name.replace('[Version]', VERSION) name = name.replace('[HighPrecision]', self.high_precision) if self.data is not None: name = name.replace('[FirstSave]', str(round_int(self.data['Time']['Created']))) name = name.replace('[LatestSave]', str(round_int(self.data['Time']['Modified']))) name = name.replace('[FileVersion]', str(self.data['Version'])) name = name.replace('[TimesLoaded]', str(self.data['TimesLoaded'])) name = name.replace('[Sessions]', str(len(self.data['SessionStarts']))) ticks = self.data['Ticks']['Total'] name = name.replace('[Ticks]', str(int(ticks))) name = name.replace('[RunningTimeSeconds]', str(round_int(ticks / UPDATES_PER_SECOND))) name = name.replace('[RunningTimeMinutes]', str(round(ticks / (UPDATES_PER_SECOND * 60), 2))) name = name.replace('[RunningTimeHours]', str(round(ticks / (UPDATES_PER_SECOND * 60 * 60), 2))) name = name.replace('[RunningTimeDays]', str(round(ticks / (UPDATES_PER_SECOND * 60 * 60 * 24), 2))) #Specific options if image_type == 'clicks': name = name.replace('[Colours]', self.heatmap_colours) name = name.replace('[MouseButton]', self.heatmap_button_group) name = name.replace('[GaussianBlur]', self.heatmap_gaussian) name = name.replace('[GaussianSigma]', self.heatmap_gaussian_actual) elif image_type == 'tracks': name = name.replace('[Colours]', self.track_colour) elif image_type.lower() == 'keyboard': name = name.replace('[Exponential]', self.keyboard_exponential) name = name.replace('[Colours]', self.keyboard_colour) name = name.replace('[DataSet]', self.keyboard_set) name = name.replace('[Size]', self.keyboard_size_mult) name = name.replace('[Extended]', self.keyboard_extended) elif image_type.startswith('csv'): if image_type == 'csv-clicks': #Using the heatmap mouse buttons saves rewriting parts of the function, #but the config will need edited first to only have one button selected. name = name.replace('[MouseButton]', self.heatmap_button_group) else: raise ValueError('incorred image type: {}'.format(image_type)) #Replace invalid characters invalid_chars = ':*?"<>|' for char in invalid_chars: if char in name: name = name.replace(char, '') if image_type.startswith('csv'): ext = 'csv' else: ext = CONFIG['GenerateImages']['FileType'] return '{}.{}'.format(format_file_path(name), ext)
import zipfile from core.config import CONFIG from core.compatibility import PYTHON_VERSION, get_items from core.constants import DEFAULT_NAME, format_file_path from core.os import remove_file, rename_file, create_folder, hide_file, get_modified_time, list_directory from core.versions import VERSION, upgrade_version, IterateMaps import core.numpy as numpy if PYTHON_VERSION < 3: import cPickle else: import pickle as cPickle DATA_FOLDER = format_file_path(CONFIG['Paths']['Data']) DATA_EXTENSION = '.data' DATA_NAME = '[PROGRAM]' + DATA_EXTENSION DATA_BACKUP_FOLDER = '.backup' DATA_TEMP_FOLDER = '.temp' DATA_CORRUPT_FOLDER = '.corrupted' DATA_SAVED_FOLDER = 'Saved' PICKLE_PROTOCOL = min(cPickle.HIGHEST_PROTOCOL, 2)