import win32print
import tkinter
from tkinter.messagebox import *
from tkinter import *
import tkinter.font as font
import re
from datetime import datetime
from win32con import WM_INPUTLANGCHANGEREQUEST
import ttkbootstrap
from ttkbootstrap import Style
from ttkbootstrap.constants import *
import win32ui
#from tkinter import ttk
from bs4 import BeautifulSoup
from ttkbootstrap.constants import *
from win32com.client.gencache import EnsureDispatch as Dispatch # 读取邮件模块
import tkinter as tk
from tkinter import ttk, scrolledtext, messagebox
from ttkbootstrap import Style
import pandas as pd
#实现了邮件中的table属性对齐
def main():
def search_email():
try:
start_true_time=start_time_text.get("1.0","end-1c")
start_datetime=datetime.strptime(start_true_time,"%Y/%m/%d")
end_true_time=end_time_text.get("1.0","end-1c")
end_datetime=datetime.strptime(end_true_time,"%Y/%m/%d")
print(f"start_time={start_datetime}--type={type(start_datetime)}")
except:
showerror(title="warning",message="日期格式错误")
return 0
account = Dispatch('Outlook.Application').GetNamespace('MAPI')
# 获取收件箱所在位置
inbox = account.GetDefaultFolder(6) # 数字6代表收件箱
# 获取收件箱下的所有邮件
mails = inbox.Items
mails.Sort('[ReceivedTime]', True) # 邮件按时间排序
compare_rule=re.compile(r'PPA_LATENT lots collection')
index=0
with open("output.txt", "w+", encoding="utf-8") as f:
f.write('\n')
# 读取收件箱内前5封邮件的所有信息(下标从1开始)
for mail in mails:
try:
mail_time = str(mail.ReceivedTime)[:19]
mail_true_time = datetime.strptime(mail_time, '%Y-%m-%d %H:%M:%S')
except:
continue
if(compare_rule.findall(mail.Subject) and mail_true_time>start_datetime and mail_true_time<end_datetime):
temp_item="主题:"+mail.Subject+" 日期:"+mail_time
email_list.append(temp_item)
combo1["value"]=email_list
index+=1
# 将邮件信息写入到文件中
f.write('正在读取第[{}]封邮件...'.format(index))
f.write('\n')
f.write('接收时间:{}'.format(str(mail.ReceivedTime)[:-6]))
f.write('\n')
f.write('发件人:{}'.format(mail.SenderName))
f.write('\n')
f.write('\n')
f.write('主题:{}'.format(mail.Subject))
f.write('\n')
soup=BeautifulSoup(mail.HTMLBody,"lxml")
temp_data=[]
tables=soup.find_all('table')
for table in tables:
rows=table.find_all('tr')
design_id=""
fab_facility_code=""
tray_design=""
product_id=""
for row in rows:
cols=row.find_all('td')
temp_lot_list=[]
for item in cols:
temp_str=item.get_text()
temp_lot_list.append(temp_str)
#print(f"---{temp_str}")
if(len(temp_lot_list)==9):
design_id=temp_lot_list[0]
fab_facility_code=temp_lot_list[1]
tray_design=temp_lot_list[2]
product_id=temp_lot_list[3]
#print("**************")
#print(f"999---{temp_lot_list}")
#print("**************")
else:
#print(f"--before={temp_lot_list}")
temp_lot_list.insert(0,design_id)
temp_lot_list.insert(1,fab_facility_code)
temp_lot_list.insert(2,tray_design)
temp_lot_list.insert(3,product_id)
#print(f"--after={temp_lot_list}")
temp_data.append(temp_lot_list)
mycols=[col.get_text(strip=True) for col in cols]
#print(f"---{mycols}")
# print(mycols)
f.write("\t".join(mycols))
f.write("\n")
total_data.append(temp_data)
totoal_number=1
for row in total_data:
for one_row in row:
#print(f"{totoal_number}-----{one_row}")
totoal_number+=1
def temp_func():
def change_row(event):
temp_content=text_scan_lot.get("1.0","end")
temp_list=[]
for item in temp_content:
temp_list.append(item)
#print(f"before change row temp list={temp_list}")
if("\t" in temp_content):
temp_content=temp_content.replace("\t","")
#print("*******")
text_scan_lot.delete(0.0,END)
text_scan_lot.insert(INSERT,temp_content)
temp_list=[]
for item in temp_content:
temp_list.append(item)
global select_list
def submit_func():
temp_content=text_scan_lot.get("1.0","end")
temp_lot_id=temp_content.split("\n")
true_scan_lot_list=[]
for item in temp_lot_id:
if(item!=None and item!="" and item!="\n"):
true_scan_lot_list.append(item)
print(f"---true scan lot={true_scan_lot_list}")
make_sure_scan_list=[]
error_scan_list=[]
for item in email_lot_id_list:
if(item in true_scan_lot_list):
make_sure_scan_list.append(1)
else:
make_sure_scan_list.append(0)
for item in true_scan_lot_list:
if(item not in email_lot_id_list):
error_scan_list.append(item)
print(f"---make sure scan list={make_sure_scan_list}")
print("--------------")
#print()
text_scan_lot.delete(0.0,END)
index_of_make_sure_scan_list=0
for item in email_lot_id_list:
if(make_sure_scan_list[index_of_make_sure_scan_list]==1):
text_scan_lot.insert(INSERT,item+"\n")
else:
text_scan_lot.insert(INSERT,"\n")
index_of_make_sure_scan_list+=1
text_scan_lot.tag_config("my_red", foreground="red")
for item in error_scan_list:
text_scan_lot.insert(1.0,item+"\n","my_red")
text_number.bind("<MouseWheel>",lambda event: Wheel(text_number,[text_scan_lot]))
text_scan_lot.bind("<MouseWheel>",lambda event: Wheel(text_scan_lot,[text_number]))
def Wheel(text,other:list):
print(f"wheel==={text.vbar.get()}")
#text是作为可视范围依据的文本框
#other是需要绑定同步滚动的文本框名称列表
first,end=text.vbar.get()
#get会返回滚动条距离顶端和低端相对位置,一般使用距离顶端的相对位置
for i in other:
i.yview('moveto',first)#调整纵向可视范围
combo2_select=combo2.get()
selected_condition_df=select_list.query("ON_HOLD_FOR==@combo2_select")
#print(f"*******select ={selected_condition_df}")
design_id_set=set()
for index,rows in selected_condition_df.iterrows():
if(rows.to_dict()['DESIGN_ID'] not in design_id_set):
design_id_set.add(rows.to_dict()['DESIGN_ID'])
#print(f"---design_id={design_id_set}")
email_lot_id_list=[]
for index,rows in selected_condition_df.iterrows():
email_lot_id_list.append(rows.to_dict()['LOT_ID'])
#print(f"*****{rows.to_dict()['LOT_ID']}")
#print(f"---email_lot_id={email_lot_id_list}")
root2=Toplevel(root)
#root2=tk.Tk()
root2.geometry('1000x800+410+180')
font_2 = font.Font(family='微软雅黑', size=12, weight='bold')
number_label=Label(root2,text="序号",font=font_1)
number_label.place(relx=0.01, rely=0, relwidth=0.09, relheight=0.05)
location_label=Label(root2,text="Location",font=font_1)
location_label.place(relx=0.15, rely=0, relwidth=0.15, relheight=0.05)
qty_label=Label(root2,text="Qty",font=font_1)
qty_label.place(relx=0.34, rely=0, relwidth=0.09, relheight=0.05)
need_lot_label=Label(root2,text="LOT_ID",font=font_1)
need_lot_label.place(relx=0.5, rely=0, relwidth=0.09, relheight=0.05)
scan_lot_label=Label(root2,text="Scan List",font=font_1)
scan_lot_label.place(relx=0.78, rely=0, relwidth=0.15, relheight=0.05)
text_number =scrolledtext.ScrolledText(root2, height=100, width=30,font=font_2)
text_number.place(relx=0.01, rely=0.05, relwidth=0.69, relheight=0.86)
text_scan_lot =scrolledtext.ScrolledText(root2, height=100, width=30,font=font_2)
text_scan_lot.place(relx=0.71, rely=0.05, relwidth=0.28, relheight=0.86)
# text_number =Text(root2, height=100, width=30,font=font_2)
# text_number.place(relx=0.01, rely=0.05, relwidth=0.69, relheight=0.86)
# text_scan_lot =Text(root2, height=100, width=30,font=font_2)
# text_scan_lot.place(relx=0.71, rely=0.05, relwidth=0.28, relheight=0.86)
index_number=1
for index,rows in selected_condition_df.iterrows():
# text_number.insert(INSERT,str(index_number)+"\n")
# index_number+=1
# text_location.insert(INSERT,rows.to_dict()['LOT LOCATION']+"\n")
# text_qty.insert(INSERT,rows.to_dict()['CURRENT_QTY']+"\n")
# text_need_lot.insert(INSERT,rows.to_dict()['LOT_ID']+"\n")
text_number.insert(INSERT,str(index_number)+"\t")
index_number+=1
text_number.insert(INSERT,rows.to_dict()['LOT LOCATION']+"\t\t\t ")
text_number.insert(INSERT,rows.to_dict()['CURRENT_QTY']+"\t\t")
text_number.insert(INSERT,rows.to_dict()['LOT_ID']+"\n")
text_number.config(state=DISABLED)
text_scan_lot.bind("<KeyRelease>", change_row)
submit_btn=Button(root2,text="提交",command=submit_func,font=font_1)
submit_btn.place(relx=0.4,rely=0.92,relwidth=0.2,relheight=0.078)
root2.mainloop()
def select_owner(event):
global select_list
select_list=pd.DataFrame(total_data[combo1.current()][1:],columns=total_data[combo1.current()][0])
for index,rows in select_list.iterrows():
if(rows.to_dict()['ON_HOLD_FOR'] not in owner_set):
print(f"---{rows.to_dict()['ON_HOLD_FOR']}")
owner_set.add(rows.to_dict()['ON_HOLD_FOR'])
print("88888888")
#print(select_list)
print(f"---set={owner_set}")
combo2["value"]=list(owner_set)
print("1111")
root = tk.Tk()
root.title('Compare Lots')
root.geometry('800x400')
style = Style()
style = Style(theme='cerculean')
TOP6 = style.master
font_1 = font.Font(family='微软雅黑', size=18, weight='bold')
my_lot_list=[]
start_time_label=Label(root,text="Start Time(年/月/日):",font=font_1)
start_time_label.place(relx=0, rely=0.06, relwidth=0.4, relheight=0.08)
start_time_text=Text(root, height=100, width=10,font=font_1)
start_time_text.place(relx=0.43, rely=0.05, relwidth=0.5, relheight=0.12)
end_time_label=Label(root,text="End Time(年/月/日):",font=font_1)
end_time_label.place(relx=0, rely=0.25, relwidth=0.4, relheight=0.08)
end_time_text=Text(root, height=100, width=10,font=font_1)
end_time_text.place(relx=0.43, rely=0.24, relwidth=0.5, relheight=0.12)
email_list=[]
total_data=[]
start_time_text.insert(INSERT,"2024/4/1")
end_time_text.insert(INSERT,"2024/5/1")
combo_text = StringVar()
combo1=ttk.Combobox(root,value=email_list,width=30,textvariable=combo_text,font=font_1)
combo1.place(relx=0.3, rely=0.49)
owner_list=[]
#global select_list
select_list=[]
owner_set=set()
generate_list=[]
combo_text1 = StringVar()
combo2=ttk.Combobox(root,value=owner_list,width=30,textvariable=combo_text1,font=font_1)
combo2.place(relx=0.3, rely=0.69)
search_email_btn=Button(root,text="搜索邮件",command=search_email,font=font_1)
search_email_btn.place(relx=0.4, rely=0.38, relwidth=0.2, relheight=0.1)
find_email_label=Label(root,text="符合的邮件信息:",font=font_1)
find_email_label.place(relx=0, rely=0.49, relwidth=0.3, relheight=0.1)
confirm_email_btn=Button(root,text="确认邮件",command=temp_func,font=font_1)
confirm_email_btn.place(relx=0.4, rely=0.9, relwidth=0.2, relheight=0.1)
combo1.bind("<<ComboboxSelected>>",select_owner)
#text_lot.bind("<KeyRelease>", change_row)
root.mainloop()
if __name__ == '__main__':
main()
text代码
最新推荐文章于 2024-10-13 18:33:13 发布