def init_view(self): _translate = QtCore.QCoreApplication.translate self.service_url_1.setText(_translate("Form", "")) self.service_url_2.setText( _translate( "Form", "https://lockscreenencrypt.oss-us-west-1.aliyuncs.com/")) self.service_url_3.setText( _translate( "Form", "https://lockscreentabencrypt.oss-us-west-1.aliyuncs.com/")) self.reset_button.clicked.connect(self.reset_work) self.run_button.clicked.connect(self.run) self.log_button.clicked.connect( lambda: os.system(path.get_cache_path() + path.RUN_LOG_NAME)) self.log_button_2.clicked.connect(lambda: os.system( path.get_cache_path() + path.ANALYSIS_RECOMMEND_LOG_NAME)) self.analysis_recommend_button.clicked.connect( self.analysis_recommend_image) data = databases.get_normal_json_data() if data: if "service_dir_path" in data: self.service_image_path.setText(data["service_dir_path"]) if "work_dir_path" in data: self.work_image_path.setText(data["work_dir_path"]) if "recommend_image_path" in data: self.recommend_image_path.setText(data["recommend_image_path"])
def run(self): if self.tip_input(): return reply = QMessageBox.question(self, '执行', '确认执行吗?', QMessageBox.No | QMessageBox.Yes, QMessageBox.No) if reply == QMessageBox.Yes: service_image_path = utils.analysis_input_path( self.service_image_path) work_image_path = utils.analysis_input_path(self.work_image_path) # 保存数据 databases.set_normal_json_data({ "service_dir_path": service_image_path, "work_dir_path": work_image_path }) log_file = open(path.get_cache_path() + path.RUN_LOG_NAME, mode='w', encoding='utf-8') self.init_progress_dialog() try: modify_success = True core.select_service_url = self.select_service_url core.run(service_image_path, work_image_path, log_file=log_file, callback=self.progress_callback) except Exception as e: modify_success = False utils.print_log(log_file, str(e)) self.progress_callback(100, 100) log_file.close() QMessageBox.information( self, '提示', '壁纸配置修改成功!' if modify_success else "壁纸配置修改失败")
def get_normal_json_data(): file_path = path.get_cache_path() + NORMAL_JSON_DATABASE_NAME if os.path.exists(file_path): read_data = open(file_path, mode='r', encoding='utf-8') try: return json.loads(read_data.read()) finally: read_data.close() return None
def set_normal_json_data(data): temp_data = get_normal_json_data() if not temp_data: temp_data = {} for key in data: temp_data[key] = data[key] json_file = open(path.get_cache_path() + NORMAL_JSON_DATABASE_NAME, mode='w', encoding='utf-8') json.dump(temp_data, json_file, indent=4, ensure_ascii=False) json_file.close()
def analysis_recommend_image(self): if self.tip_input(): return if not self.recommend_image_path.toPlainText(): QMessageBox.information(self, '提示', '推荐壁纸路径为空!') return service_image_path = utils.analysis_input_path(self.service_image_path) work_image_path = utils.analysis_input_path(self.work_image_path) recommend_image_path = utils.analysis_input_path( self.recommend_image_path) databases.set_normal_json_data({ "service_dir_path": service_image_path, "work_dir_path": work_image_path, "recommend_image_path": recommend_image_path }) reply = QMessageBox.question(self, '推荐壁纸', '确认处理推荐壁纸吗?', QMessageBox.No | QMessageBox.Yes, QMessageBox.No) if reply == QMessageBox.Yes: log_file = open(path.get_cache_path() + path.ANALYSIS_RECOMMEND_LOG_NAME, mode='w', encoding='utf-8') self.init_progress_dialog() core.select_service_url = self.select_service_url analysis_recommend.run(service_image_path, work_image_path, recommend_image_path, log_file=log_file, callback=self.progress_callback) log_file.close() QMessageBox.information(self, '提示', '推荐壁纸处理成功!')