def _save_open_route(self, file_path): prev_route = config.get("route", "path") config.set_key("route", "path", file_path) config.save_config() success = self.open_route() if success: return else: config.set_key("route", "path", prev_route) config.save_config() self.open_route()
def apply_clicked(self): # Update and save preferences self.general_menu.update_preferences() self.connection_menu.update_preferences() self.thresholds_menu.update_preferences() self.colour_thresholds_menu.update_preferences() self.error_menu.update_preferences() self.adv_menu.update_preferences() config.save_config() self.hide() self.applied.emit()
def load_route(self, route_path=None): """ Loads route from path specified in preferences :return: """ if not route_path: _route_path = config.get("route", "path") else: _route_path = route_path try: route = route_loader.load(_route_path) if route: route_error = route_loader.validate_route(route) else: self.new() return if route_error: self.display_error_message(route_error, "Route Error") except FileNotFoundError: route = None self.display_error_message( "Route file not found.", "Invalid route: {}".format(path.basename(_route_path))) except KeyError: route = None self.display_error_message( "Invalid or missing Key", "Invalid route: {}".format(path.basename(_route_path))) except JSONDecodeError: route = None self.display_error_message( "Invalid JSON formatting", "Invalid route: {}".format(path.basename(_route_path))) except PermissionError: route = None if route: self.route = route self.route_path = self.route.file_path config.set_key("route", "path", resource_utils.abs_to_rel(_route_path)) config.save_config() self.display_route()
def open_route(self): self._stop() if config.get("route", "path") == "": return try: route = route_loader.load(config.get("route", "path")) except KeyError: self.display_error_message("Key Error", "Route Error") return False if not route: self.display_error_message("Could not load route", "Route Error") self._load_route_dir() config.set_key("route", "path", "") config.save_config() return False error = route_loader.validate_route(route) if error: self.display_error_message(error, "Route Error") return False self.route = route self.split_list.clear() self.star_count.star_count = route.initial_star self.star_count.split_star = route.splits[0].star_count for split in route.splits: split_icon_path = split.icon_path if split_icon_path: split_icon_path = rel_to_abs(split_icon_path) icon = QtGui.QPixmap(split_icon_path) else: icon = None self.split_list.add_split(split.title, icon) self.split_list.repaint() return True
def apply_clicked(self): try: os.remove("resources/images/generated_reset_one.jpg") except FileNotFoundError: pass try: os.remove("resources/images/generated_reset_two.jpg") except FileNotFoundError: pass try: os.rename( "resources/images/generated_temp_" + str(self.gen_1_sb.value()) + ".jpg", "resources/images/generated_reset_one.jpg") except FileNotFoundError: pass try: os.rename( "resources/images/generated_temp_" + str(self.gen_2_sb.value()) + ".jpg", "resources/images/generated_reset_two.jpg") except FileNotFoundError: pass for i in range(ResetGenerator.CAPTURE_COUNT): try: os.remove("resources/images/generated_temp_" + str(i) + ".jpg") except FileNotFoundError: pass config.set_key("advanced", "reset_frame_one", "resources/images/generated_reset_one.jpg") config.set_key("advanced", "reset_frame_two", "resources/images/generated_reset_two.jpg") config.save_config() self._reset_generator.stop() self.hide()
def contextMenuEvent(self, event): context_menu = QtWidgets.QMenu(self) route_menu = QtWidgets.QMenu("Open Route") route_actions = {} category_menus = {} # SRL MODE Action srl_action = QtWidgets.QAction("SRL Mode", self, checkable=True) context_menu.addAction(srl_action) srl_action.setChecked(config.get("general", "srl_mode")) context_menu.addSeparator() for category in sorted(self._routes, key=lambda text:[int(c) if c.isdigit() else c for c in re.split(r'(\d+)', text)]): if len(self._routes[category]) == 1 or category == "": for route in self._routes[category]: route_menu.addAction(route[0]) route_actions[route[0]] = partial(self._save_open_route, route[1]) else: category_menus[category] = QtWidgets.QMenu(str(category)) route_menu.addMenu(category_menus[category]) for route in self._routes[category]: category_menus[category].addAction(route[0]) route_actions[route[0]] = partial(self._save_open_route, route[1]) route_menu.addSeparator() file_action = route_menu.addAction("From File") # Actions edit_route = context_menu.addAction("Edit Route") context_menu.addMenu(route_menu) context_menu.addSeparator() cords_action = context_menu.addAction("Edit Coordinates") context_menu.addSeparator() advanced_action = context_menu.addAction("Settings") context_menu.addSeparator() reset_gen_action = context_menu.addAction("Generate Reset Templates") context_menu.addSeparator() about_action = context_menu.addAction("About") exit_action = context_menu.addAction("Exit") action = context_menu.exec_(self.mapToGlobal(event.pos())) # Connections if action == srl_action: checked = srl_action.isChecked() config.set_key("general", "srl_mode", checked) config.save_config() elif action == edit_route: self.dialogs["route_editor"].show() elif action == file_action: self.open_route_browser() elif action == cords_action: self.dialogs["capture_editor"].show() elif action == advanced_action: self.dialogs["settings_dialog"].show() elif action == reset_gen_action: self.dialogs["reset_dialog"].show() elif action == about_action: self.dialogs["about_dialog"].show() elif action == exit_action: self.close() else: try: route_actions[action.text()]() except (KeyError, AttributeError): pass
def apply_clicked(self): config.set_key("game", "game_region", self.game_region_panel.get_data()) config.set_key("game", "process_name", self.process_combo.currentText()) config.save_config() self.close()
def save(self): self.apply_btn.setFocus() splits = [] if self.split_table.rowCount() < 1: self.display_error_message("No Splits", "Route Error") return -1 for row in range(self.split_table.rowCount()): title = self.split_table.item(row, 1).text() if len(title) <= 0: self.display_error_message( "Invalid Title - Row: " + str(row + 1), "Route Error") self.split_table.setCurrentCell(row, 1) return -1 try: star_count = int(self.split_table.item(row, 2).text()) except (ValueError, AttributeError): self.display_error_message( "Invalid Star Count - Row: " + str(row + 1), "Route Error") self.split_table.setCurrentCell(row, 2) return -1 try: fadeouts = int(self.split_table.item(row, 3).text()) except (ValueError, AttributeError): if self.split_table.cellWidget(row, 5).currentText == SPLIT_NORMAL: self.display_error_message( "Invalid Fadeout - Row: " + str(row + 1), "Route Error") self.split_table.setCurrentCell(row, 3) return -1 else: fadeouts = -1 try: fadeins = int(self.split_table.item(row, 4).text()) except (ValueError, AttributeError): if self.split_table.cellWidget(row, 5).currentText == SPLIT_NORMAL: self.display_error_message( "Invalid Fadein - Row: " + str(row + 1), "Route Error") self.split_table.setCurrentCell(row, 4) return -1 else: fadeins = -1 try: icon_path = self.split_table.item(row, 0).toolTip() except (ValueError, AttributeError): icon_path = "" split_type = self.split_table.cellWidget(row, 5).currentText() splits.append( Split(title, star_count, fadeouts, fadeins, split_type, icon_path)) title = self.title_le.text() if len(title) <= 0: self.display_error_message("Invalid Route Title", "Route Error") return -1 try: initial_star = int(self.init_star_le.text()) except (ValueError, AttributeError): self.display_error_message("Invalid Initial Star", "Route Error") return -1 category = self.category_combo.lineEdit().text() route = Route( self.route_path, title, splits, initial_star, self.version_combo.itemText(self.version_combo.currentIndex()), category) route_error = route_loader.validate_route(route) if route_error: self.display_error_message(route_error, "Route Error") return -1 if not self.route_path: file_name, _ = QtWidgets.QFileDialog.getSaveFileName( self, "Save Route", resource_utils.base_path() + "/routes", "AS64 Route Files (*.as64)") if file_name != '': self.route_path = file_name else: return -1 route_loader.save(route, self.route_path) config.set_key("route", "path", self.route_path) config.save_config() self.route_updated.emit()