Ethscriptions commited on
Commit
5422259
·
verified ·
1 Parent(s): 966b698

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +23 -6
app.py CHANGED
@@ -6,7 +6,8 @@ import io
6
  import base64
7
  import matplotlib.gridspec as gridspec
8
  import math
9
- from matplotlib.backends.backend_pdf import PdfPages # 新增导入
 
10
 
11
  SPLIT_TIME = "17:30"
12
  BUSINESS_START = "09:30"
@@ -179,9 +180,25 @@ def create_print_layout(data, title, date_str):
179
  if row_grid < num_rows + 1: # 确保索引在网格内
180
  ax = fig.add_subplot(gs[row_grid, col_grid]) # 使用 fig.add_subplot
181
 
 
 
182
  for spine in ax.spines.values():
183
- spine.set_color(BORDER_COLOR)
184
- spine.set_linewidth(0.5)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
185
 
186
  display_text = f"{hall}{end_time}"
187
  ax.text(0.5, 0.5, display_text,
@@ -220,7 +237,7 @@ def create_print_layout(data, title, date_str):
220
 
221
  # --- 保存 PNG ---
222
  png_buffer = io.BytesIO()
223
- # 可以尝试减小 pad_inches,甚至设为 0
224
  png_fig.savefig(png_buffer, format='png', bbox_inches='tight', pad_inches=0.02)
225
  png_buffer.seek(0)
226
  png_base64 = base64.b64encode(png_buffer.getvalue()).decode()
@@ -229,7 +246,7 @@ def create_print_layout(data, title, date_str):
229
  # --- 保存 PDF ---
230
  pdf_buffer = io.BytesIO()
231
  with PdfPages(pdf_buffer) as pdf:
232
- # 可以尝试减小 pad_inches,甚至设为 0
233
  pdf.savefig(pdf_fig, bbox_inches='tight', pad_inches=0.02)
234
  pdf_buffer.seek(0)
235
  pdf_base64 = base64.b64encode(pdf_buffer.getvalue()).decode()
@@ -250,7 +267,7 @@ def display_pdf(base64_pdf):
250
  st.set_page_config(page_title="散厅时间快捷打印", layout="wide")
251
  st.title("散厅时间快捷打印")
252
 
253
- uploaded_file = st.file_uploader("上传【放映场次核对表.xls】文件", type=["xls", "xlsx"])
254
 
255
  if uploaded_file:
256
  part1, part2, date_str = process_schedule(uploaded_file)
 
6
  import base64
7
  import matplotlib.gridspec as gridspec
8
  import math
9
+ from matplotlib.backends.backend_pdf import PdfPages
10
+ from matplotlib.patches import FancyBboxPatch # 新增导入
11
 
12
  SPLIT_TIME = "17:30"
13
  BUSINESS_START = "09:30"
 
180
  if row_grid < num_rows + 1: # 确保索引在网格内
181
  ax = fig.add_subplot(gs[row_grid, col_grid]) # 使用 fig.add_subplot
182
 
183
+ # --- 修改开始:绘制圆角矩形 ---
184
+ # 隐藏原始边框
185
  for spine in ax.spines.values():
186
+ spine.set_visible(False)
187
+
188
+ # 创建圆角矩形 Patch
189
+ bbox = FancyBboxPatch(
190
+ (0.01, 0.01), # 左下角坐标 (稍微内缩一点避免接触边缘)
191
+ 0.98, 0.98, # 宽度和高度 (占满大部分区域)
192
+ boxstyle="round,pad=0,rounding_size=0.02", # 圆角样式,rounding_size 控制圆角程度
193
+ edgecolor=BORDER_COLOR,
194
+ facecolor='none', # 无填充色
195
+ linewidth=0.5,
196
+ transform=ax.transAxes, # 使用相对坐标
197
+ clip_on=False # 避免被裁剪
198
+ )
199
+ # 添加 Patch 到 Axes
200
+ ax.add_patch(bbox)
201
+ # --- 修改结束 ---
202
 
203
  display_text = f"{hall}{end_time}"
204
  ax.text(0.5, 0.5, display_text,
 
237
 
238
  # --- 保存 PNG ---
239
  png_buffer = io.BytesIO()
240
+ # 可以尝试减小 pad_inches even set to 0
241
  png_fig.savefig(png_buffer, format='png', bbox_inches='tight', pad_inches=0.02)
242
  png_buffer.seek(0)
243
  png_base64 = base64.b64encode(png_buffer.getvalue()).decode()
 
246
  # --- 保存 PDF ---
247
  pdf_buffer = io.BytesIO()
248
  with PdfPages(pdf_buffer) as pdf:
249
+ # 可以尝试减小 pad_inches even set to 0
250
  pdf.savefig(pdf_fig, bbox_inches='tight', pad_inches=0.02)
251
  pdf_buffer.seek(0)
252
  pdf_base64 = base64.b64encode(pdf_buffer.getvalue()).decode()
 
267
  st.set_page_config(page_title="散厅时间快捷打印", layout="wide")
268
  st.title("散厅时间快捷打印")
269
 
270
+ uploaded_file = st.file_uploader("上传【放映场次核对表.xls】文件", type=["xls"])
271
 
272
  if uploaded_file:
273
  part1, part2, date_str = process_schedule(uploaded_file)