add action manager
This commit is contained in:
parent
2bd94b9680
commit
b7f91e4820
3
action_handler/__init__.py
Normal file
3
action_handler/__init__.py
Normal file
@ -0,0 +1,3 @@
|
||||
#encoding = utf8
|
||||
|
||||
from .action_manager import ActionManager
|
10
action_handler/action_manager.py
Normal file
10
action_handler/action_manager.py
Normal file
@ -0,0 +1,10 @@
|
||||
#encoding = utf8
|
||||
from action_handler.ppt import PPTAction
|
||||
|
||||
|
||||
class ActionManager:
|
||||
def __init__(self):
|
||||
self.ppt_action = PPTAction()
|
||||
|
||||
def __del__(self):
|
||||
pass
|
4
action_handler/ppt/__init__.py
Normal file
4
action_handler/ppt/__init__.py
Normal file
@ -0,0 +1,4 @@
|
||||
#encoding = utf8
|
||||
|
||||
from .ppt_controller import PPTController
|
||||
from .ppt_action import PPTAction
|
54
action_handler/ppt/ppt_action.py
Normal file
54
action_handler/ppt/ppt_action.py
Normal file
@ -0,0 +1,54 @@
|
||||
#encoding = utf8
|
||||
import logging
|
||||
|
||||
from action_handler.ppt import PPTController
|
||||
from eventbus import EventBus
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
class PPTAction:
|
||||
def __init__(self):
|
||||
self.ppt_controller = None
|
||||
EventBus().register("ppt_open", self.open)
|
||||
EventBus().register("ppt_goto", self.goto)
|
||||
EventBus().register("ppt_next", self.goto)
|
||||
EventBus().register("ppt_pre", self.goto)
|
||||
|
||||
def __del__(self):
|
||||
EventBus().unregister("ppt_open", self.open)
|
||||
EventBus().unregister("ppt_goto", self.goto)
|
||||
EventBus().unregister("ppt_next", self.goto)
|
||||
EventBus().unregister("ppt_pre", self.goto)
|
||||
del self.ppt_controller
|
||||
|
||||
def open(self, *args, **kwargs):
|
||||
path = args[0]
|
||||
if path is None or len(path) == 0:
|
||||
logger.warning('path is empty')
|
||||
return
|
||||
if self.ppt_controller is not None:
|
||||
del self.ppt_controller
|
||||
|
||||
self.ppt_controller = PPTController()
|
||||
self.ppt_controller.open(path)
|
||||
|
||||
def goto(self, *args, **kwargs):
|
||||
page = args[0]
|
||||
if page is None or self.ppt_controller is None:
|
||||
logger.warning('page is none or ppt controller is none')
|
||||
return
|
||||
|
||||
self.ppt_controller.goto_slide(page)
|
||||
|
||||
def next(self, *args, **kwargs):
|
||||
if self.ppt_controller is None:
|
||||
logger.warning('page is none or ppt controller is none')
|
||||
return
|
||||
self.ppt_controller.next_page()
|
||||
|
||||
def pre(self, *args, **kwargs):
|
||||
if self.ppt_controller is None:
|
||||
logger.warning('page is none or ppt controller is none')
|
||||
return
|
||||
self.ppt_controller.pre_page()
|
92
action_handler/ppt/ppt_controller.py
Normal file
92
action_handler/ppt/ppt_controller.py
Normal file
@ -0,0 +1,92 @@
|
||||
#encoding = utf8
|
||||
import time
|
||||
import logging
|
||||
|
||||
import win32com.client
|
||||
import win32api
|
||||
import win32con
|
||||
import pythoncom
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
VK_CODE = {
|
||||
'spacebar': 0x20,
|
||||
'down_arrow': 0x28,
|
||||
}
|
||||
|
||||
|
||||
class PPTController:
|
||||
def __init__(self):
|
||||
pythoncom.CoInitialize()
|
||||
self.app = win32com.client.Dispatch("PowerPoint.Application")
|
||||
self.app.Visible = True
|
||||
|
||||
def __del__(self):
|
||||
self.app.Quit()
|
||||
pythoncom.CoUninitialize()
|
||||
|
||||
def open(self, path):
|
||||
self.app.Presentations.Open(path)
|
||||
|
||||
def full_screen(self):
|
||||
if self.has_active_presentation():
|
||||
self.app.ActivePresentation.SlideShowSettings.Run()
|
||||
return self.get_active_presentation_slide_index()
|
||||
|
||||
def click(self):
|
||||
win32api.keybd_event(VK_CODE['spacebar'], 0, 0, 0)
|
||||
win32api.keybd_event(VK_CODE['spacebar'], 0 , win32con.KEYEVENTF_KEYUP, 0)
|
||||
return self.get_active_presentation_slide_index()
|
||||
|
||||
def goto_slide(self, index):
|
||||
if self.has_active_presentation():
|
||||
try:
|
||||
self.app.ActiveWindow.View.GotoSlide(index)
|
||||
return self.app.ActiveWindow.View.Slide.SlideIndex
|
||||
except Exception as e:
|
||||
self.app.SlideShowWindows(1).View.GotoSlide(index)
|
||||
return self.app.SlideShowWindows(1).View.CurrentShowPosition
|
||||
|
||||
def next_page(self):
|
||||
if self.has_active_presentation():
|
||||
count = self.get_active_presentation_slide_count()
|
||||
index = self.get_active_presentation_slide_index()
|
||||
return index if index >= count else self.goto_slide(index+1)
|
||||
|
||||
def pre_page(self):
|
||||
if self.has_active_presentation():
|
||||
index = self.get_active_presentation_slide_index()
|
||||
return index if index <= 1 else self.goto_slide(index-1)
|
||||
|
||||
def get_active_presentation_slide_index(self):
|
||||
if self.has_active_presentation():
|
||||
try:
|
||||
index = self.app.ActiveWindow.View.Slide.SlideIndex
|
||||
return index
|
||||
except Exception as e:
|
||||
print(e)
|
||||
index = self.app.SlideShowWindows(1).View.CurrentShowPosition
|
||||
return index
|
||||
|
||||
def get_active_presentation_slide_count(self):
|
||||
return self.app.ActivePresentation.Slides.Count
|
||||
|
||||
def get_presentation_count(self):
|
||||
return self.app.Presentations.Count
|
||||
|
||||
def has_active_presentation(self):
|
||||
return True if self.get_presentation_count() > 0 else False
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
ppt = PPTControler()
|
||||
ppt.open(r'D:\Project\LLV\pptAgnet\ppt_test.pptx')
|
||||
time.sleep(2)
|
||||
ppt.full_screen()
|
||||
time.sleep(2)
|
||||
ppt.goto_slide(6)
|
||||
time.sleep(2)
|
||||
ppt.next_page()
|
||||
time.sleep(2)
|
||||
ppt.pre_page()
|
||||
time.sleep(2)
|
2
main.py
2
main.py
@ -3,6 +3,7 @@
|
||||
import logging
|
||||
import os
|
||||
|
||||
from action_handler import ActionManager
|
||||
from human import HumanContext
|
||||
from ui import IpcRender
|
||||
from utils import config_logging
|
||||
@ -17,6 +18,7 @@ if __name__ == '__main__':
|
||||
context = HumanContext()
|
||||
render = IpcRender(context)
|
||||
context.build(render)
|
||||
action_manger = ActionManager()
|
||||
render.run()
|
||||
render.stop()
|
||||
logger.info('------------finish------------')
|
Loading…
Reference in New Issue
Block a user