graduation-project/main.py

159 lines
4.9 KiB
Python
Raw Normal View History

2022-06-27 14:22:35 +08:00
#!C:\Users\Dinger\anaconda3\envs\graduation_project2\python.exe
2022-02-19 07:10:20 +08:00
import multiprocessing
2022-05-14 14:29:25 +08:00
import sys
2022-01-25 21:31:18 +08:00
import tkinter
from identify import *
from tkinter.filedialog import *
2022-05-14 14:29:25 +08:00
from tkinter import messagebox
2022-01-25 21:31:18 +08:00
from win32com.client import Dispatch
import win32con
import win32api
import time
import os
def control_page_up():
win32api.keybd_event(38, 0, 0, 0) # 代表按下f键
time.sleep(0.02)
win32api.keybd_event(38, 0, win32con.KEYEVENTF_KEYUP, 0) # 释放f键
def control_page_down():
win32api.keybd_event(40, 0, 0, 0) # 代表按下f键
time.sleep(0.02)
win32api.keybd_event(40, 0, win32con.KEYEVENTF_KEYUP, 0) # 释放f键
def control_ppt_begin():
win32api.keybd_event(16, 0, 0, 0) # 代表按下f键
2022-06-27 14:22:35 +08:00
win32api.keybd_event(116, 0, 0, 0) # 代表按下f键
2022-01-25 21:31:18 +08:00
time.sleep(0.02)
win32api.keybd_event(116, 0, win32con.KEYEVENTF_KEYUP, 0) # 释放f键
win32api.keybd_event(16, 0, win32con.KEYEVENTF_KEYUP, 0) # 释放f键
def control_ppt_end():
win32api.keybd_event(27, 0, 0, 0) # 代表按下f键
time.sleep(0.02)
win32api.keybd_event(27, 0, win32con.KEYEVENTF_KEYUP, 0) # 释放f键
def control_open_pencil():
win32api.keybd_event(17, 0, 0, 0) # 代表按下f键
2022-03-21 20:53:29 +08:00
win32api.keybd_event(82, 0, 0, 0) # 代表按下f键
2022-01-25 21:31:18 +08:00
time.sleep(0.02)
win32api.keybd_event(17, 0, win32con.KEYEVENTF_KEYUP, 0) # 释放f键
2022-03-21 20:53:29 +08:00
win32api.keybd_event(82, 0, win32con.KEYEVENTF_KEYUP, 0) # 释放f键
def control_writing(m, position_x, position_y):
m.move(position_x, position_y)
2022-01-25 21:31:18 +08:00
2022-05-14 14:29:25 +08:00
def control_thread(control_number, array, over_flag):
2022-02-19 07:10:20 +08:00
last_time = 0.0
step = 0
2022-03-21 20:53:29 +08:00
mouse = PyMouse()
2022-05-14 14:29:25 +08:00
test_time1 = time.time()
count = 0
2022-01-25 21:31:18 +08:00
while 1:
2022-05-14 14:29:25 +08:00
count += 1
# print("step = " + str(step))
2022-02-19 07:10:20 +08:00
# print("control_thread")
now_time = time.time()
2022-05-14 14:29:25 +08:00
control_flag = control_number.value
# os._exit(0)
if control_flag == 7:
# test_time2 = time.time()
# fps = count / (test_time2 - test_time1)
# print("count2 = " + str(count))
# print("time = " + str(test_time2 - test_time1))
# print("fps_control = " + str(fps))
over_flag.value = 1
sys.exit(0)
2022-03-21 20:53:29 +08:00
if step == 2:
if control_flag == 4:
position_x = int(mouse.screen_size()[0] / array[2] * array[0])
position_y = int(mouse.screen_size()[1] / array[3] * array[1])
control_writing(mouse, position_x, position_y)
elif control_flag == 5:
step = 1
control_ppt_end()
last_time = now_time
continue
2022-02-19 07:10:20 +08:00
if now_time - last_time < 1:
continue
last_time = now_time
2022-05-14 14:29:25 +08:00
# print("control_flag2 = " + str(control_flag))
# # print("main.step = " + str(step))
if step == 0:
if control_flag == 1:
control_ppt_begin()
step = 1
elif step == 1:
if control_flag == 2:
control_page_up()
# print("control_flag == 2")
2022-03-21 20:53:29 +08:00
elif control_flag == 3:
control_page_down()
# print("control_flag == 3")
2022-03-21 20:53:29 +08:00
elif control_flag == 4:
control_open_pencil()
step = 2
2022-05-14 14:29:25 +08:00
elif control_flag == 6:
control_ppt_end()
step = 0
2022-05-14 14:29:25 +08:00
2022-01-25 21:31:18 +08:00
2022-05-14 14:29:25 +08:00
def identify_thread(control_number, array, over_flag):
identify = Identify(control_number, array)
identify.begin(over_flag)
2022-03-21 20:53:29 +08:00
2022-01-25 21:31:18 +08:00
def open_file():
2022-03-21 20:53:29 +08:00
file_path = askopenfilename(title=u'选择文件')
2022-05-14 14:29:25 +08:00
if not open_ppt(file_path):
return False
control_number = multiprocessing.Value('i', 0)
2022-03-21 20:53:29 +08:00
array = multiprocessing.Array('i', 4)
2022-05-14 14:29:25 +08:00
over_flag = multiprocessing.Value('i', 0)
p1 = multiprocessing.Process(target=identify_thread, args=(control_number, array, over_flag))
p2 = multiprocessing.Process(target=control_thread, args=(control_number, array, over_flag))
2022-02-19 07:10:20 +08:00
p1.start()
p2.start()
2022-05-14 14:29:25 +08:00
return True
2022-01-25 21:31:18 +08:00
2022-02-19 07:10:20 +08:00
2022-05-14 14:29:25 +08:00
def judge_ppt(file_path):
string = file_path
string = string.split('.')
if len(string) <= 0:
return False
string = string[len(string) - 1]
if string.find('ppt') != -1:
return True
return False
2022-02-19 07:10:20 +08:00
def open_ppt(file_path):
2022-05-14 14:29:25 +08:00
if not len(file_path):
messagebox.showinfo("选择失败", "您尚未选择ppt文件请重新选择")
return False
if not judge_ppt(file_path):
messagebox.showinfo("选择失败", "该文件非ppt文件请重新选择")
return False
2022-02-19 07:10:20 +08:00
ppt = Dispatch('PowerPoint.Application')
ppt.Visible = 1 # 后台运行
ppt.DisplayAlerts = 0 # 不显示,不警告
2022-03-21 20:53:29 +08:00
ppt.Presentations.Open(file_path)
2022-05-14 14:29:25 +08:00
return True
2022-01-25 21:31:18 +08:00
if __name__ == '__main__':
2022-04-17 15:23:46 +08:00
window = tkinter.Tk()
window.title("会议PPT选择")
window.geometry("200x100")
2022-01-25 21:31:18 +08:00
bt1 = tkinter.Button(window, text='打开文件', width=15, height=15, command=open_file)
bt1.pack()
window.mainloop()