加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
change_frame_.py 4.34 KB
一键复制 编辑 原始数据 按行查看 历史
曾振宇 提交于 2021-04-03 17:17 . 修改布局
def change_frame(self,index,direct,O_o,size):
frame = copy.deepcopy(self.frame)
flag = 0
print(frame)
if direct == 1:#上
for i in range(len(frame)):#直接修改
if i != index:
if abs(frame[i][3] - frame[index][3] - frame[index][1]) < 0.01:# or abs(frame[i][0] + frame[i][2] - frame[index][0] - frame[index][2]) < 0.01:
#frame1上边为frame2下边
frame[i][3] += size * O_o
frame[i][3] = round(frame[i][3],2)
frame[i][1] -= size * O_o
frame[i][1] = round(frame[i][1],2)
elif abs(frame[i][1] + frame[i][3] - frame[index][1] - frame[index][3]) < 0.01:
#frame1上边为frame2上边
frame[i][1] += size * O_o
frame[i][1] = round(frame[i][1],2)
frame[index][1] += size * O_o
frame[index][1] = round(frame[index][1],2)
elif direct == 2:#右
# for i in range(len(frame)):#情况1:区块右边刚好为另一块的左边
# if abs(frame[i][2] - frame[index][2] - frame[index][0]) < 0.01 and abs(frame[i][1] - frame[index][1]) < 0.01:
# flag = 1
for i in range(len(frame)):#直接修改
if i != index:
if abs(frame[i][2] - frame[index][2] - frame[index][0]) < 0.01:# or abs(frame[i][0] + frame[i][2] - frame[index][0] - frame[index][2]) < 0.01:
#frame1右边为frame2左边
frame[i][2] += size * O_o
frame[i][2] = round(frame[i][2],2)
frame[i][0] -= size * O_o
frame[i][0] = round(frame[i][0],2)
elif abs(frame[i][0] + frame[i][2] - frame[index][0] - frame[index][2]) < 0.01:
#frame1右边为frame2右边
frame[i][0] += size * O_o
frame[i][0] = round(frame[i][0],2)
frame[index][0] += size * O_o
frame[index][0] = round(frame[index][0],2)
self.frame = list(frame)
print(self.frame)
# print(frame)
# print(self.frame)
def get_frame(self):
frame = []
pattern = r"\\new.*?\[statico.*?\]"
match = re.findall(pattern,self.file_data,re.S)
for match_str in match:
# index = int(re.search(r"(?<=statico)\d(?=\])",match_str).group())
params = re.findall(r"[0-9\.]+",match_str)
# print(list(map(float,params))[1:-1])
frame.append(list(map(float,params))[1:-1])
self.frame = frame
def change_tex_frame(self):
print(self.frame)
# new_frames = []
pattern = r"\\new.*?\[statico.*?\]"
match = re.findall(pattern,self.file_data,re.S)
count = len(match)
for i in range(count):
if i == 1:
insertion = r"\newflowframe[1]{%.2f\textwidth}{%.2f\textheight}{%.2f\textwidth}{%.2f\textheight}[statico%d]" % (self.frame[i][0],self.frame[i][1],self.frame[i][2],self.frame[i][3],i)
else:
insertion = r"\newstaticframe[1]{%.2f\textwidth}{%.2f\textheight}{%.2f\textwidth}{%.2f\textheight}[statico%d]" % (self.frame[i][0],self.frame[i][1],self.frame[i][2],self.frame[i][3],i)
# print(match[i])
# print(insertion)
self.file_data = self.file_data.replace(match[i],insertion)
#修改红框高度[colframe=red!75!white,colback=white,width=\textwidth,height=0.3\textheight,boxrule=2pt]
pattern = r"\[colframe=red.*?pt\]"
match = re.findall(pattern,self.file_data,re.S)
count = len(match)
for i in range(count):
if i == 0:
insertion = r"[colframe=red!75!white,colback=white,height=%.2f\textheight,boxrule=2pt]" % self.frame[1][1]
elif i == 1:
insertion = r"[colframe=red!75!white,colback=white,height=%.2f\textheight,boxrule=2pt]" % self.frame[0][1]
else:
insertion = r"[colframe=red!75!white,colback=white,height=%.2f\textheight,boxrule=2pt]" % self.frame[i][1]
print(match[i])
print(insertion)
self.file_data = self.file_data.replace(match[i],insertion)
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化