蓝色天空.知识 · 实践 · 创造
我的收藏
在线代码实验室

离线解析 .idea/workspace.xml 工具窗口布局、encodings.xml 与视图模式配置

PYTHONWindows x64、CPython 3.12.14 离线 PyCharm 工程语义与配置验证器(未启动桌面端 PyCharm IDE)。explore-start-intro.py
explore-start-intro.py131 行
"""Offline Python verification lab for PyCharm Chapter 06 (start-intro)."""
import json
import xml.etree.ElementTree as ET

VERSION = "CPython 3.12.14 offline PyCharm workflow verifier (desktop IDE not launched)"


def case_ide_layout_and_tool_windows():
    workspace_xml = """<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
  <component name="ToolWindowManager">
    <layout>
      <window_info id="Project" anchor="left" />
      <window_info id="Structure" anchor="left" />
      <window_info id="Python Console" anchor="left" />
      <window_info id="Terminal" anchor="left" />
      <window_info id="AI Assistant" anchor="right" />
      <window_info id="Database" anchor="right" />
      <window_info id="Run" anchor="bottom" />
      <window_info id="Problems" anchor="bottom" />
      <window_info id="TODO" anchor="bottom" />
      <window_info id="Version Control" anchor="bottom" />
    </layout>
  </component>
</project>"""
    root = ET.fromstring(workspace_xml)
    by_anchor = {"left": [], "right": [], "bottom": []}
    for wi in root.findall(".//window_info"):
        by_anchor[wi.attrib["anchor"]].append(wi.attrib["id"])

    top_menus = [
        "File", "Edit", "View", "Navigate", "Code",
        "Refactor", "Run", "Tools", "VCS", "Window", "Help",
    ]
    status_bar_items = ["Interpreter", "Encoding", "LineSeparator", "CaretPosition", "MemoryIndicator"]
    expected = {
        "top_menu_count": 11,
        "left_windows": ["Project", "Structure", "Python Console", "Terminal"],
        "right_windows": ["AI Assistant", "Database"],
        "bottom_windows": ["Run", "Problems", "TODO", "Version Control"],
        "status_bar_count": 5,
    }
    actual = {
        "top_menu_count": len(top_menus),
        "left_windows": by_anchor["left"],
        "right_windows": by_anchor["right"],
        "bottom_windows": by_anchor["bottom"],
        "status_bar_count": len(status_bar_items),
    }
    return {
        "name": "ide_layout_and_tool_windows",
        "summary": "解析 .idea/workspace.xml 工具窗口停靠布局并核对顶部 11 项菜单与底部 5 项状态栏指示器",
        "expected": expected,
        "actual": actual,
        "passed": actual == expected,
    }


def case_chinese_ui_and_encoding_settings():
    encodings_xml = """<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
  <component name="Encoding" defaultCharsetForPropertiesFiles="UTF-8" native2AsciiForPropertiesFiles="true">
    <file url="PROJECT" charset="UTF-8" />
  </component>
</project>"""
    root = ET.fromstring(encodings_xml)
    enc = root.find("./component[@name='Encoding']")
    proj_file = enc.find("./file[@url='PROJECT']") if enc is not None else None
    terms = {
        "Refactor": "重构",
        "Inspect Code": "检查代码",
        "Run Configuration": "运行配置",
    }
    expected = {
        "project_charset": "UTF-8",
        "transparent_conversion": True,
        "term_mapping": {"Refactor": "重构", "Inspect Code": "检查代码", "Run Configuration": "运行配置"},
    }
    actual = {
        "project_charset": proj_file.attrib.get("charset") if proj_file is not None else "",
        "transparent_conversion": enc.attrib.get("native2AsciiForPropertiesFiles") == "true" if enc is not None else False,
        "term_mapping": terms,
    }
    return {
        "name": "chinese_ui_and_encoding_settings",
        "summary": "解析 .idea/encodings.xml UTF-8 与透明转换设置并核对中英文界面高频术语对照",
        "expected": expected,
        "actual": actual,
        "passed": actual == expected,
    }


def case_view_modes_and_editor_split():
    view_modes = {
        "full_screen": {"menu": "View -> Enter Full Screen", "shortcut": "Ctrl+Shift+F12"},
        "distraction_free": {"menu": "View -> Distraction Free Mode", "hides_tool_windows": True},
        "presentation": {"menu": "View -> Presentation Mode", "enlarges_font": True},
        "project_view": {"search_everywhere": "Shift+Shift", "query": "Project View"},
    }
    split_orientations = ("vertical", "horizontal")
    expected = {
        "mode_count": 4,
        "full_screen_shortcut": "Ctrl+Shift+F12",
        "split_modes": ["vertical", "horizontal"],
    }
    actual = {
        "mode_count": len(view_modes),
        "full_screen_shortcut": view_modes["full_screen"]["shortcut"],
        "split_modes": list(split_orientations),
    }
    return {
        "name": "view_modes_and_editor_split",
        "summary": "验证全屏、专注、演示、全项目视图模式与垂直/水平分屏配置规范",
        "expected": expected,
        "actual": actual,
        "passed": actual == expected,
    }


def main():
    cases = [
        case_ide_layout_and_tool_windows(),
        case_chinese_ui_and_encoding_settings(),
        case_view_modes_and_editor_split(),
    ]
    print(json.dumps({"version": VERSION, "cases": cases}, ensure_ascii=False, indent=2))


if __name__ == "__main__":
    main()
本例需在 Windows x64、CPython 3.12.14 离线 PyCharm 工程语义与配置验证器(未启动桌面端 PyCharm IDE)。 中运行,请复制源码、保存文件或下载工程包后在本地执行验证。
运行说明与环境独立工程

运行环境:Windows x64、CPython 3.12.14 离线 PyCharm 工程语义与配置验证器(未启动桌面端 PyCharm IDE)。

入口文件:projects/pycharm-start-intro-lab/explore-start-intro.py

本地运行步骤快速上手
  1. 点击上方“保存源码”保存为 explore-start-intro.py,或下载右侧课程工程包。
  2. 确认本地已准备 Windows x64、CPython 3.12.14 离线 PyCharm 工程语义与配置验证器(未启动桌面端 PyCharm IDE)。。
  3. 按对应章节命令执行,结合正文核对实际输出。
附件与关联工程包下载

下载课程关联工程包:PyCharm

课程关联工程包(登记关联17章) · 含当前章节或实例 · mbskycom202612a2240.zip

下载课程关联工程包:PyCharm

课程关联工程包(登记关联1章) · 含当前章节或实例 · mbskycom202612a2254.zip
SITE SEARCH

搜索教程、工具与资讯

热门搜索

JavaScriptJSON格式化正则表达式AI 编程AI 翻译AI导航专题标签
Esc 关闭

欢迎登录蓝色天空网

使用会员账号,继续你的学习