Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -31,7 +31,8 @@ def get_font(size=14):
|
|
31 |
if os.path.exists(font_path):
|
32 |
return font_manager.FontProperties(fname=font_path, size=size)
|
33 |
else:
|
34 |
-
|
|
|
35 |
return font_manager.FontProperties(family='sans-serif', size=size)
|
36 |
|
37 |
def get_pinyin_abbr(text):
|
@@ -55,7 +56,7 @@ def format_seq(n):
|
|
55 |
return circled_chars[n - 1]
|
56 |
return f'({n})'
|
57 |
|
58 |
-
# --- '放映时间核对表' 处理函数 ---
|
59 |
def process_schedule_led(file):
|
60 |
"""处理 '放映时间核对表.xls' 文件"""
|
61 |
try:
|
@@ -103,7 +104,7 @@ def process_schedule_led(file):
|
|
103 |
return None, date_str
|
104 |
|
105 |
def create_print_layout_led(data, date_str):
|
106 |
-
"""为 '放映时间核对表' 生成打印布局"""
|
107 |
if data is None or data.empty:
|
108 |
return None
|
109 |
A4_width_in, A4_height_in = 8.27, 11.69
|
@@ -201,7 +202,7 @@ def create_print_layout_led(data, date_str):
|
|
201 |
plt.close(fig)
|
202 |
return outputs
|
203 |
|
204 |
-
# --- '放映场次核对表' 处理函数 ---
|
205 |
def process_schedule_times(file):
|
206 |
"""处理 '放映场次核对表.xls' 文件"""
|
207 |
try:
|
@@ -209,7 +210,7 @@ def process_schedule_times(file):
|
|
209 |
df = df.iloc[:, [6, 7, 9]]
|
210 |
df.columns = ['Hall', 'StartTime', 'EndTime']
|
211 |
df = df.dropna(subset=['Hall', 'StartTime', 'EndTime'])
|
212 |
-
df['Hall'] = df['Hall'].str.extract(r'(\d
|
213 |
base_date = datetime.today().date()
|
214 |
df['StartTime'] = pd.to_datetime(df['StartTime'])
|
215 |
df['EndTime'] = pd.to_datetime(df['EndTime'])
|
@@ -250,7 +251,7 @@ def process_schedule_times(file):
|
|
250 |
return None, None, None
|
251 |
|
252 |
def create_print_layout_times(data, title, date_str):
|
253 |
-
"""为 '放映场次核对表' 生成打印布局"""
|
254 |
if data.empty:
|
255 |
return None
|
256 |
|
@@ -267,10 +268,13 @@ def create_print_layout_times(data, title, date_str):
|
|
267 |
fontsize_from_width = target_text_width_pt / (8 * 0.6)
|
268 |
fontsize_from_height = cell_height_pt * 0.8
|
269 |
base_fontsize = min(fontsize_from_width, fontsize_from_height)
|
|
|
|
|
|
|
|
|
270 |
fig = plt.figure(figsize=(A5_WIDTH_IN, A5_HEIGHT_IN), dpi=300)
|
271 |
fig.subplots_adjust(left=0, right=1, top=1, bottom=0)
|
272 |
-
|
273 |
-
plt.rcParams['font.sans-serif'] = ['SimHei']
|
274 |
gs = gridspec.GridSpec(
|
275 |
num_rows + 1, NUM_COLS,
|
276 |
hspace=0, wspace=0,
|
@@ -299,8 +303,10 @@ def create_print_layout_times(data, title, date_str):
|
|
299 |
spine.set_color(BORDER_COLOR)
|
300 |
spine.set_linewidth(0.75)
|
301 |
display_text = f"{hall}{end_time}"
|
|
|
|
|
302 |
ax.text(0.5, 0.5, display_text,
|
303 |
-
|
304 |
fontweight='bold',
|
305 |
ha='center', va='center',
|
306 |
transform=ax.transAxes)
|
@@ -308,8 +314,10 @@ def create_print_layout_times(data, title, date_str):
|
|
308 |
ax.set_yticks([])
|
309 |
ax.set_facecolor('none')
|
310 |
ax_date = fig.add_subplot(gs[0, :])
|
|
|
|
|
311 |
ax_date.text(0.01, 0.5, f"{date_str} {title}",
|
312 |
-
|
313 |
color=DATE_COLOR, fontweight='bold',
|
314 |
ha='left', va='center',
|
315 |
transform=ax_date.transAxes)
|
|
|
31 |
if os.path.exists(font_path):
|
32 |
return font_manager.FontProperties(fname=font_path, size=size)
|
33 |
else:
|
34 |
+
# 仅在使用时发出警告
|
35 |
+
st.warning("警告:未找到SimHei字体文件,部分复杂中文(如电影名)可能无法正确显示。请将 simHei.ttc 或 SimHei.ttf 文件放入项目文件夹。")
|
36 |
return font_manager.FontProperties(family='sans-serif', size=size)
|
37 |
|
38 |
def get_pinyin_abbr(text):
|
|
|
56 |
return circled_chars[n - 1]
|
57 |
return f'({n})'
|
58 |
|
59 |
+
# --- '放映时间核对表' 处理函数 (使用SimHei) ---
|
60 |
def process_schedule_led(file):
|
61 |
"""处理 '放映时间核对表.xls' 文件"""
|
62 |
try:
|
|
|
104 |
return None, date_str
|
105 |
|
106 |
def create_print_layout_led(data, date_str):
|
107 |
+
"""为 '放映时间核对表' 生成打印布局 (使用SimHei)"""
|
108 |
if data is None or data.empty:
|
109 |
return None
|
110 |
A4_width_in, A4_height_in = 8.27, 11.69
|
|
|
202 |
plt.close(fig)
|
203 |
return outputs
|
204 |
|
205 |
+
# --- '放映场次核对表' 处理函数 (使用默认字体) ---
|
206 |
def process_schedule_times(file):
|
207 |
"""处理 '放映场次核对表.xls' 文件"""
|
208 |
try:
|
|
|
210 |
df = df.iloc[:, [6, 7, 9]]
|
211 |
df.columns = ['Hall', 'StartTime', 'EndTime']
|
212 |
df = df.dropna(subset=['Hall', 'StartTime', 'EndTime'])
|
213 |
+
df['Hall'] = df['Hall'].str.extract(r'(\d+号)').astype(str) + ' '
|
214 |
base_date = datetime.today().date()
|
215 |
df['StartTime'] = pd.to_datetime(df['StartTime'])
|
216 |
df['EndTime'] = pd.to_datetime(df['EndTime'])
|
|
|
251 |
return None, None, None
|
252 |
|
253 |
def create_print_layout_times(data, title, date_str):
|
254 |
+
"""为 '放映场次核对表' 生成打印布局 (使用默认字体)"""
|
255 |
if data.empty:
|
256 |
return None
|
257 |
|
|
|
268 |
fontsize_from_width = target_text_width_pt / (8 * 0.6)
|
269 |
fontsize_from_height = cell_height_pt * 0.8
|
270 |
base_fontsize = min(fontsize_from_width, fontsize_from_height)
|
271 |
+
|
272 |
+
# **修改点**: 使用Matplotlib的默认字体设置
|
273 |
+
plt.rcParams['font.sans-serif'] = plt.rcParamsDefault['font.sans-serif']
|
274 |
+
|
275 |
fig = plt.figure(figsize=(A5_WIDTH_IN, A5_HEIGHT_IN), dpi=300)
|
276 |
fig.subplots_adjust(left=0, right=1, top=1, bottom=0)
|
277 |
+
|
|
|
278 |
gs = gridspec.GridSpec(
|
279 |
num_rows + 1, NUM_COLS,
|
280 |
hspace=0, wspace=0,
|
|
|
303 |
spine.set_color(BORDER_COLOR)
|
304 |
spine.set_linewidth(0.75)
|
305 |
display_text = f"{hall}{end_time}"
|
306 |
+
|
307 |
+
# **修改点**: 移除 fontproperties,改用 fontsize
|
308 |
ax.text(0.5, 0.5, display_text,
|
309 |
+
fontsize=base_fontsize,
|
310 |
fontweight='bold',
|
311 |
ha='center', va='center',
|
312 |
transform=ax.transAxes)
|
|
|
314 |
ax.set_yticks([])
|
315 |
ax.set_facecolor('none')
|
316 |
ax_date = fig.add_subplot(gs[0, :])
|
317 |
+
|
318 |
+
# **修改点**: 移除 fontproperties,改用 fontsize
|
319 |
ax_date.text(0.01, 0.5, f"{date_str} {title}",
|
320 |
+
fontsize=base_fontsize * 0.5,
|
321 |
color=DATE_COLOR, fontweight='bold',
|
322 |
ha='left', va='center',
|
323 |
transform=ax_date.transAxes)
|