def set_download_path(self): """设置下载路径""" dl_path = QFileDialog.getExistingDirectory() dl_path = os.path.normpath(dl_path) # windows backslash if dl_path == self.configs["settings"]["dl_path"] or dl_path == ".": return if dl_path == "": dl_path = os.path.dirname(os.path.abspath(__file__)) + os.sep + "downloads" up_info = {"dl_path": dl_path} else: up_info = {"dl_path": dl_path} update_settings(self._config_file, up_info, is_settings=True) self.load_settings() self.line_dl_path.setText(self.configs["settings"]["dl_path"])
def set_download_path(self): """设置下载路径""" dl_path = QFileDialog.getExistingDirectory() if dl_path == self.settings["path"]: return if dl_path == "": dl_path = os.path.dirname( os.path.abspath(__file__)) + os.sep + "downloads" up_info = {"path": dl_path} else: up_info = {"path": dl_path} update_settings(self._config, up_info) self.load_settings() self.line_dl_path.setText(self.settings["path"])
def load_settings(self, ref_ui=False): """加载用户设置""" try: with open(self._config_file, "rb") as _file: self.configs = load(_file) except Exception: self.configs = {"user": "", "pwd": "", "cookie": "", "settings": self._default_settings} with open(self._config_file, "wb") as _file: dump(self.configs, _file) # 兼容以前的平配置文件 if "settings" not in self.configs or not self.configs["settings"]: self.configs.update({"settings": self._default_settings}) update_settings(self._config_file, {"settings": self._default_settings}) self.update_lanzoucloud_settings() if ref_ui and self.tabWidget.currentIndex() == 1: # 更新文件界面的时间 self.show_file_and_folder_lists()
def call_update_cookie(self, cookie): """更新cookie至config文件""" up_info = {"cookie": cookie} update_settings(self._config_file, up_info)