# -*- coding: utf-8 -*-
"""图 4-7　Project 软件界面（教材第 76 页）
按教材图内标注重画「图意」：功能区（界面顶部）/ 视图区（界面左侧）/ 工作区（界面右侧，
工作区再分左侧「表格」与右侧「甘特图」）。不贴课本照片。
"""
import sys, os
sys.path.insert(0, os.path.dirname(os.path.abspath(__file__)))
from matplotlib.patches import Rectangle
from _draw import setup, canvas, box, line, save, NAV, LINE, ACC

setup()
fig, ax = canvas(w=11.4, h=7.2, xlim=(0, 114), ylim=(0, 72))

# ── 窗口外框
ax.add_patch(Rectangle((1, 2), 112, 66, facecolor='white', edgecolor=NAV, linewidth=1.8, zorder=0))

# 标题栏
box(ax, 1.4, 67.6, 111.2, 3.0, '', fc='#e2e8f0', ec=NAV, fs=8, radius=0.4, lw=1.2)
ax.text(3.2, 66.1, '教务管理系统-范围管理实验  ×.mpp  —  Project Professional',
        ha='left', va='center', fontsize=8, color=NAV)

# ── 功能区（界面顶部）：标签行 + 按钮行，各自独立成带
box(ax, 2.0, 64.4, 110.0, 2.4, '', fc='#f7fafc', ec=LINE, radius=0.3, lw=1.0)
ax.text(57.0, 63.2, '文件   任务   资源   报表   项目   视图   帮助   甘特图格式        操作说明搜索',
        ha='center', va='center', fontsize=9.5, color=NAV)
box(ax, 2.0, 61.6, 110.0, 2.6, '', fc='#ebf8ff', ec=LINE, radius=0.3, lw=1.0)
ribbon = ['子项目', '获取加载项', '项目信息', '自定义字段', '在项目间链接', 'WBS',
          '更改工作时间', '计算项目', '设置', '移动项目', '更新项目']
bw = 8.6
gapx = (110.0 - len(ribbon) * bw) / (len(ribbon) + 1)
for i, t in enumerate(ribbon):
    box(ax, 2.0 + gapx * (i + 1) + i * bw, 61.4, bw, 2.2, t, fc='white', ec=LINE,
        fs=6.4, radius=0.3, lw=0.9)

# ── 标题带：功能区 / 视图区 / 工作区
box(ax, 2.0, 57.4, 110.0, 2.6, '功能区', fc='#ebf8ff', ec=LINE, fs=11.5, bold=True,
    tc=NAV, radius=0.4, lw=1.1)
box(ax, 2.0, 54.4, 8.4, 2.6, '视图区', fc='#ebf8ff', ec=LINE, fs=10.5, bold=True,
    tc=NAV, radius=0.4, lw=1.1)
box(ax, 11.4, 54.4, 67.0, 2.6, '', fc='white', ec=LINE, radius=0.4, lw=1.1)
box(ax, 79.0, 54.4, 33.0, 2.6, '工作区', fc='#ebf8ff', ec=LINE, fs=11.5, bold=True,
    tc=NAV, radius=0.4, lw=1.1)

# ── 视图区：视图切换列表
views = ['甘特图', '跟踪甘特图', '任务分配状况', '任务工作表', '日历', '网络图', '工作组规划器']
vy = 51.4
for v in views:
    box(ax, 2.3, vy, 7.8, 4.0, v, fc="white", ec=LINE, fs=6.4, radius=0.3, lw=0.9)
    vy -= 4.6

# ── 工作区：左「表格」+ 右「甘特图」
box(ax, 11.4, 51.4, 67.0, 36.0, '', fc='white', ec=LINE, radius=0.3, lw=1.0)
# 表格区
box(ax, 12.0, 47.4, 32.4, 2.6, '', fc='white', ec=LINE, radius=0.3, lw=1.0)
hdr = ['①', '任务名称', '工期', '开始时间']
colx = [12.0, 17.0, 32.0, 38.0]
for i, h in enumerate(hdr):
    x0 = colx[i]
    x1 = colx[i + 1] if i + 1 < len(colx) else 44.4
    box(ax, x0, 51.4, x1 - x0, 2.6, h, fc='#f7fafc', ec=LINE, fs=7.0, radius=0.2, lw=0.9)
for x in colx:
    line(ax, (x, 47.4), (x, 15.0))
yy = 44.8
while yy > 15.0:
    line(ax, (12.0, yy), (44.4, yy))
    yy -= 2.4
ax.text(28.2, 17.5, '表格', ha='center', va='bottom', fontsize=13, color=NAV, fontweight='bold')

# 甘特图区
box(ax, 44.4, 51.4, 34.0, 36.0, '', fc='white', ec=LINE, radius=0.3, lw=1.0)
box(ax, 44.9, 51.4, 33.0, 2.0, '2024年11月', fc='#f7fafc', ec=LINE, fs=7.4, radius=0.2, lw=0.9)
box(ax, 44.9, 49.4, 33.0, 2.0, '二  三  四  五  六  日  一  二  三  四  五  六  日  一',
    fc='white', ec=LINE, fs=6.6, radius=0.2, lw=0.9)
for i in range(1, 14):
    x = 44.9 + i * (33.0 / 14.0)
    line(ax, (x, 47.4), (x, 15.0))
yy = 44.8
while yy > 15.0:
    line(ax, (44.9, yy), (77.9, yy))
    yy -= 2.4
ax.text(61.4, 17.5, '甘特图', ha='center', va='bottom', fontsize=13, color=NAV, fontweight='bold')

# ── 说明框
box(ax, 12.0, 13.6, 65.0, 10.4,
    '标注：功能区＝界面顶部（文件/任务/资源/项目/视图/甘特图格式 等选项卡）\n'
    '视图区＝界面左侧，用于切换不同的项目视图（如甘特图、资源工作表等）\n'
    '工作区＝界面右侧主要显示区域：左侧为表格区（展示任务详情：名称、起止日期、资源等），\n'
    '右侧为甘特图区（展示项目时间轴和任务进展情况）',
    fc='#f7fafc', ec=ACC, fs=7.6, radius=0.4, lw=1.1)

ax.text(57, 0.1, '图 4-7　Project 软件界面（功能区 / 视图区 / 工作区＝表格＋甘特图）',
        ha='center', va='bottom', fontsize=10, color='#4a5568')

save(fig, os.path.join(os.path.dirname(os.path.abspath(__file__)), '..', 'assets', '图4-7-Project软件界面.png'))
