def _loop(self): logger.info(f"Connecting to {self.name}") try: f = None f = open(f"\\\\.\\pipe\\{self.name}", "r+b", 0) logger.info("Connected event handler!") while self.running: n = struct.unpack("I", f.read(4))[0] data = f.read(n) obj = msgpack.unpackb(data, raw=False) if obj["data"][0] == "call" and obj["data"][1][ "method"] == "emit": args = obj["data"][1]["args"][0] for evt_args in args: logger.debug(f"Event {evt_args['event_name']}") if evt_args["event_name"] in self.event_handlers: for handler in self.event_handlers[ evt_args["event_name"]]: handler.emit(evt_args["args"]) f.close() except: if f is not None: f.close() self.running = False self.event_loop = None self.on_connection_lost.emit()
def close(self): if self.handler is None: return try: h = self.handler self.handler = None h.close() self.call_id = 0 logger.info("Handler closed!") except Exception as e: logger.error(f"Error while closing the handler!: {e}")
def run(self): self.connecting = True while self.connecting: QThread.sleep(1) try: self.core.connect("MaidFiddlerService") if self._connected(): logger.info("Connected!") return except Exception as e: logger.error( f"Failed to connect because {e}! Retrying in a second!") self.connection_reset.emit()
def on_connection_close(self): if not self.core.is_connected(): return logger.info("Connection closed!") self.close() self.maids_list.clear_list() for menu_action in self.findChildren(QAction): if len(menu_action.objectName()) != 0 and menu_action.isCheckable( ): menu_action.blockSignals(True) menu_action.setChecked(False) menu_action.blockSignals(False) self.connect()
def run(self): logger.debug("doing request") try: response = request.urlopen( f"https://api.github.com/repos/{GIT_REPO}/releases/latest", timeout=5) except URLError as e: self.error.emit(str(e.reason)) return data = json.load(response) version = data["tag_name"][1:] logger.info(f"Latest version: {version}, current version: {VERSION}") if version <= VERSION: self.no_update.emit() return self.update_available.emit(data)
def main(): setup_logger() load_config() save_config() app = QApplication(sys.argv) app.setStyle(QStyleFactory.create("Fusion")) window = MainWindow() if CONFIG.getboolean("Options", "check_updates_on_startup", fallback=True): CONFIG["Options"]["check_updates_on_startup"] = "yes" save_config() window.check_updates(True) window.show() window.connect() app.exec_() logger.info("Exited!")
def __init__(self): logger.info("Initializing UI") super(MainWindow, self).__init__() self.setupUi(self) self.error_occurred.connect(self.display_error_box) sys.excepthook = lambda t, v, tr: self.error_occurred.emit( { "t": t, "val": v, "traceback": tr }) icon = QPixmap() icon.loadFromData(APP_ICON) self.setWindowIcon(QIcon(icon)) self.ui_tabs.setEnabled(False) self.menuSelected_maid.setEnabled(False) self.connection_lost.connect(self.on_connection_close) self.core = PipeRpcCaller(self.connection_lost) self.event_poller = PipedEventHandler("MaidFildderEventEmitter", self.connection_lost) self.about_dialog = AboutDialog() self.core_version = "?" self.maid_mgr = MaidManager() self.tabs.append(MaidInfoTab(self)) self.tabs.append(MaidStatsTab(self)) self.tabs.append(FeaturePropensityTab(self)) self.tabs.append(YotogiTab(self)) self.tabs.append(WorkTab(self)) self.player_tab = PlayerTab(self) self.tabs.append(self.player_tab) self.maids_list = MaidsList(self) self.init_events() self.init_translations()
def _connected(self): self.connected.emit() logger.info("Got connection! Trying to get game data!") try: game_data, err = self.core.try_invoke("GetGameInfo") if game_data is None: logger.warning( f"Got empty response! Resetting the connection!") self.core.close() self.connection_reset.emit() return False except Exception as e: logger.error(f"Got error while calling GetGameInfo: {e}") self.connection_reset.emit() return False self.connecting = False self.setup_complete.emit(game_data) return True
def update_ui(self): personalities = self.properties["personal"].index_map() contracts = self.properties["contract"].index_map() relations = self.properties["relation"].index_map() feelings = self.properties["feeling"].index_map() additional_relations = self.properties["additionalRelation"].index_map( ) special_relation = self.properties["specialRelation"].index_map() cur_seikeiken = self.properties["seikeiken"].index_map() init_seikeiken = self.properties["initSeikeiken"].index_map() job_classes = self.properties["current_job_class_id"].index_map() yotogi_classes = self.properties["current_yotogi_class_id"].index_map() personalities.clear() contracts.clear() relations.clear() feelings.clear() additional_relations.clear() special_relation.clear() cur_seikeiken.clear() init_seikeiken.clear() job_classes.clear() yotogi_classes.clear() self.personality_names.clear() self.contracts_names.clear() self.relations_names.clear() self.feeling_names.clear() self.additional_relations_names.clear() self.special_relation_names.clear() self.seikeiken_names.clear() self.job_classes_names.clear() self.yotogi_classes_names.clear() self.ui.personality_combo.blockSignals(True) self.ui.contract_combo.blockSignals(True) self.ui.relation_combo.blockSignals(True) self.ui.feeling_combo.blockSignals(True) self.ui.additional_relation_combo.blockSignals(True) self.ui.special_relation_combo.blockSignals(True) self.ui.current_combo.blockSignals(True) self.ui.initial_combo.blockSignals(True) self.ui.job_class_combo.blockSignals(True) self.ui.yotogi_class_combo.blockSignals(True) self.ui.personality_combo.clear() self.ui.contract_combo.clear() self.ui.relation_combo.clear() self.ui.additional_relation_combo.clear() self.ui.special_relation_combo.clear() self.ui.current_combo.clear() self.ui.initial_combo.clear() self.ui.job_class_combo.clear() self.ui.yotogi_class_combo.clear() for i, personal in enumerate(self._game_data["personal_list"]): self.ui.personality_combo.addItem(personal["name"], personal["id"]) personalities[personal["id"]] = i self.personality_names.append(f"personality.{personal['name']}") for i, contract_name in enumerate(self._game_data["contract"]): contract_id = self._game_data["contract"][contract_name] self.ui.contract_combo.addItem(contract_name, contract_id) contracts[contract_id] = i self.contracts_names.append(f"contracts.{contract_name}") for i, relation_name in enumerate(self._game_data["relation"]): relation_id = self._game_data["relation"][relation_name] self.ui.relation_combo.addItem(relation_name, relation_id) relations[relation_id] = i self.relations_names.append(f"relations.{relation_name}") for i, feeling_name in enumerate(self._game_data["feeling"]): feeling_id = self._game_data["feeling"][feeling_name] self.ui.feeling_combo.addItem(feeling_name, feeling_id) feelings[feeling_id] = i self.feeling_names.append(f"feeling.{feeling_name}") for i, relation_name in enumerate( self._game_data["additional_relation"]): relation_id = self._game_data["additional_relation"][relation_name] self.ui.additional_relation_combo.addItem(relation_name, relation_id) additional_relations[relation_id] = i self.additional_relations_names.append( f"additional_relations.{relation_name}") for i, relation_name in enumerate(self._game_data["special_relation"]): logger.info("relation_name:" + relation_name) relation_id = self._game_data["special_relation"][relation_name] logger.info("relation_id:" + str(relation_id)) self.ui.special_relation_combo.addItem(relation_name, relation_id) special_relation[relation_id] = i self.special_relation_names.append( f"special_relation.{relation_name}") for i, seik_name in enumerate(self._game_data["seikeiken"]): seik_id = self._game_data["seikeiken"][seik_name] self.ui.current_combo.addItem(seik_name, seik_id) self.ui.initial_combo.addItem(seik_name, seik_id) cur_seikeiken[seik_id] = i init_seikeiken[seik_id] = i self.seikeiken_names.append(f"seikeiken.{seik_name}") for i, job_class in enumerate(self._game_data["job_class_list"]): self.ui.job_class_combo.addItem(job_class["name"], job_class["id"]) job_classes[job_class["id"]] = i self.job_classes_names.append(f"job_class.{job_class['name']}") for i, yotogi_class in enumerate(self._game_data["yotogi_class_list"]): self.ui.yotogi_class_combo.addItem(yotogi_class["name"], yotogi_class["id"]) yotogi_classes[yotogi_class["id"]] = i self.yotogi_classes_names.append( f"yotogi_class.{yotogi_class['name']}") self.ui.yotogi_class_combo.view().setVerticalScrollBarPolicy( Qt.ScrollBarAsNeeded) self.ui.personality_combo.blockSignals(False) self.ui.contract_combo.blockSignals(False) self.ui.relation_combo.blockSignals(False) self.ui.feeling_combo.blockSignals(False) self.ui.additional_relation_combo.blockSignals(False) self.ui.special_relation_combo.blockSignals(False) self.ui.current_combo.blockSignals(False) self.ui.initial_combo.blockSignals(False) self.ui.job_class_combo.blockSignals(False) self.ui.yotogi_class_combo.blockSignals(False)