core-gui start error:AttributeError: ‘NoneType‘ object has no attribute ‘scale‘

有一次将Ubuntu关机后再重新打开,在终端下运行core-gui命令出现如下错误:

Traceback (most recent call last):
File “/opt/core/venv/bin/core-gui”, line 8, in
sys.exit(main())
File “/opt/core/venv/lib/python3.10/site-packages/core/scripts/gui.py”, line 45, in main
app = Application(args.proxy, args.session)
File “/opt/core/venv/lib/python3.10/site-packages/core/gui/app.py”, line 54, in init
self.app_scale: float = self.guiconfig.scale
AttributeError: ‘NoneType’ object has no attribute ‘scale’

从出错堆栈上分析,应该是self.giconfig为空,导致无法获取其中的scale属性。于是打开文件/opt/core/venv/lib/python3.10/site-packages/core/gui/app.py,从其中第line 54开始查找原因,其中第54行的代码如下:

52 # setup
53 self.guiconfig: GuiConfig = appconfig.read()
54 self.app_scale: float = self.guiconfig.scale

从上面的代码看,应该是guiconfig对象为空。而此对象又是从上一行appconfig.read()读取而来。所以,找到appconfig中的read方法查找原因。appconfig所在的文件是/opt/core/venv/lib/python3.10/site-packages/core/gui/appconfig.py,打开此文件,找到其中的read方法:

def read() -> GuiConfig:
with CONFIG_PATH.open(“r”) as f:
return yaml.safe_load(f)

从上面的代码可以看出,应该是要打开CONFIG_PATH文件并加载其中的内容。于是在此文件中再找到CONFIG_PATH的定义,其在文件的开头,如下所示:

10 HOME_PATH: Path = Path.home().joinpath(“.coregui”)
11 BACKGROUNDS_PATH: Path = HOME_PATH.joinpath(“backgrounds”)
12 CUSTOM_EMANE_PATH: Path = HOME_PATH.joinpath(“custom_emane”)
13 CUSTOM_SERVICE_PATH: Path = HOME_PATH.joinpath(“custom_services”)
14 ICONS_PATH: Path = HOME_PATH.joinpath(“icons”)
15 MOBILITY_PATH: Path = HOME_PATH.joinpath(“mobility”)
16 XMLS_PATH: Path = HOME_PATH.joinpath(“xmls”)
17 CONFIG_PATH: Path = HOME_PATH.joinpath(“config.yaml”)

所以从第17行可以看到, CONFIG_PATH文件指的是一个用户home目录下的.coregui/config.yaml文件。而.coregui目录正在core-gui使用的配置文件目录。于是进入此目录,打开config.yaml查看,此文件内容空空如也。大概率的原因是,某一次关机过程中,core-gui对此配置文件的写操作导致此文件损坏,内容被清空。于是找到另一台电脑,查看其中的config.yaml文件,果然内容非空。于是重新复制一份配置文件config.yaml过来,成功解决问题。

相关推荐

  1. js | <span style='color:red;'>Core</span>

    js | Core

    2024-07-18 08:48:04      20 阅读
  2. .NET CORE架构分层

    2024-07-18 08:48:04       43 阅读
  3. Core Web Vitals

    2024-07-18 08:48:04       50 阅读

最近更新

  1. docker php8.1+nginx base 镜像 dockerfile 配置

    2024-07-18 08:48:04       66 阅读
  2. Could not load dynamic library ‘cudart64_100.dll‘

    2024-07-18 08:48:04       70 阅读
  3. 在Django里面运行非项目文件

    2024-07-18 08:48:04       57 阅读
  4. Python语言-面向对象

    2024-07-18 08:48:04       68 阅读

热门阅读

  1. python + Pytest + requests 的接口自动化步骤

    2024-07-18 08:48:04       19 阅读
  2. vue3中的watch函数

    2024-07-18 08:48:04       22 阅读
  3. 力扣题解(目标和)

    2024-07-18 08:48:04       22 阅读
  4. oracle数据字典详解

    2024-07-18 08:48:04       17 阅读