-# -*- coding: utf-8 -*-\r
-\r
-import obspython as obs\r
-# pip install pywin32\r
-import win32com.client\r
-import pywintypes\r
-import os\r
-import shutil\r
-import http_server_39 as server\r
-#import http.server as server\r
-import socketserver\r
-import threading\r
-import functools\r
-\r
-powerpoint = None\r
-hotkey_id_frst = None\r
-hotkey_id_prev = None\r
-hotkey_id_next = None\r
-hotkey_id_last = None\r
-hotkey_id_black = None\r
-\r
-HOTKEY_NAME_FRST = 'powerpoint_slides.first'\r
-HOTKEY_NAME_PREV = 'powerpoint_slides.previous'\r
-HOTKEY_NAME_NEXT = 'powerpoint_slides.next'\r
-HOTKEY_NAME_LAST = 'powerpoint_slides.last'\r
-HOTKEY_NAME_BLACK = 'powerpoint_slides.black'\r
-HOTKEY_NAME_WHITE = 'powerpoint_slides.white'\r
-\r
-HOTKEY_DESC_FRST = 'First PowerPoint slide'\r
-HOTKEY_DESC_PREV = 'Previous PowerPoint slide'\r
-HOTKEY_DESC_NEXT = 'Next PowerPoint slide'\r
-HOTKEY_DESC_LAST = 'Last PowerPoint slide'\r
-HOTKEY_DESC_BLACK = 'Black PowerPoint slide'\r
-HOTKEY_DESC_WHITE = 'White PowerPoint slide'\r
-\r
-class Handler(server.CGIHTTPRequestHandler):\r
- def __init__(self, *args, **kwargs):\r
- super().__init__(*args, directory=os.path.dirname(os.path.realpath(__file__)))\r
-\r
-def run_http():\r
- httpd = server.HTTPServer(("", 8000), Handler)\r
- httpd.serve_forever()\r
- \r
-\r
-\r
-\r
-# ------------------------------------------------------------\r
-# global functions for script plugins\r
-\r
-def script_load(settings):\r
- global hotkey_id_frst\r
- global hotkey_id_prev\r
- global hotkey_id_next\r
- global hotkey_id_last\r
- global hotkey_id_black\r
- global hotkey_id_white\r
-\r
- hotkey_id_frst = register_and_load_hotkey(settings, HOTKEY_NAME_FRST, HOTKEY_DESC_FRST, slideshow_view_first)\r
- hotkey_id_prev = register_and_load_hotkey(settings, HOTKEY_NAME_PREV, HOTKEY_DESC_PREV, slideshow_view_previous)\r
- hotkey_id_next = register_and_load_hotkey(settings, HOTKEY_NAME_NEXT, HOTKEY_DESC_NEXT, slideshow_view_next)\r
- hotkey_id_last = register_and_load_hotkey(settings, HOTKEY_NAME_LAST, HOTKEY_DESC_LAST, slideshow_view_last)\r
- hotkey_id_black = register_and_load_hotkey(settings, HOTKEY_NAME_BLACK, HOTKEY_DESC_BLACK, slideshow_view_black)\r
- hotkey_id_white = register_and_load_hotkey(settings, HOTKEY_NAME_WHITE, HOTKEY_DESC_WHITE, slideshow_view_white)\r
-\r
- daemon = threading.Thread(name="daemon_server", target=run_http)\r
- daemon.setDaemon(True)\r
- daemon.start()\r
-\r
-def script_unload():\r
- obs.obs_hotkey_unregister(slideshow_view_first)\r
- obs.obs_hotkey_unregister(slideshow_view_previous)\r
- obs.obs_hotkey_unregister(slideshow_view_next)\r
- obs.obs_hotkey_unregister(slideshow_view_last)\r
- obs.obs_hotkey_unregister(slideshow_view_black)\r
- obs.obs_hotkey_unregister(slideshow_view_white)\r
-\r
-def script_save(settings):\r
- save_hotkey(settings, HOTKEY_NAME_FRST, hotkey_id_frst)\r
- save_hotkey(settings, HOTKEY_NAME_PREV, hotkey_id_prev)\r
- save_hotkey(settings, HOTKEY_NAME_NEXT, hotkey_id_next)\r
- save_hotkey(settings, HOTKEY_NAME_LAST, hotkey_id_last)\r
- save_hotkey(settings, HOTKEY_NAME_BLACK, hotkey_id_black)\r
- save_hotkey(settings, HOTKEY_NAME_WHITE, hotkey_id_white)\r
-\r
-def script_description():\r
- return 'Navigate Powerpoint Slides.'\r
-\r
-def script_defaults(settings):\r
- obs.obs_data_set_default_string(settings, 'cache', r'''C:\Windows\Temp''')\r
-\r
-def script_properties():\r
- props = obs.obs_properties_create()\r
-\r
- obs.obs_properties_add_path(props, "cache", "Slide cache: ", obs.OBS_PATH_DIRECTORY, "*.jpg", r'''C:\Windows\Temp''')\r
- return props\r
-\r
-def script_update(settings):\r
- global cache\r
- cache = obs.obs_data_get_string(settings, "cache").replace("/", "\\")\r
-\r
-def register_and_load_hotkey(settings, name, description, callback):\r
- hotkey_id = obs.obs_hotkey_register_frontend(name, description, callback)\r
- hotkey_save_array = obs.obs_data_get_array(settings, name)\r
- obs.obs_hotkey_load(hotkey_id, hotkey_save_array)\r
- obs.obs_data_array_release(hotkey_save_array)\r
-\r
- return hotkey_id\r
-\r
-def save_hotkey(settings, name, hotkey_id):\r
- hotkey_save_array = obs.obs_hotkey_save(hotkey_id)\r
- obs.obs_data_set_array(settings, name, hotkey_save_array)\r
- obs.obs_data_array_release(hotkey_save_array)\r
-\r
-#-------------------------------------\r
-\r
-def get_slideshow_view():\r
- global powerpoint\r
-\r
- if powerpoint is None:\r
- powerpoint = win32com.client.Dispatch('Powerpoint.Application')\r
-\r
- if powerpoint is None:\r
- return\r
-\r
- ssw = powerpoint.SlideShowWindows\r
- if ssw.Count == 0:\r
- return\r
-\r
- # https://docs.microsoft.com/en-us/office/vba/api/powerpoint.slideshowwindow.view\r
- ssv = ssw[0].View\r
-\r
- return ssv\r
-\r
-def get_activepresentation():\r
- global powerpoint\r
-\r
- if powerpoint is None:\r
- powerpoint = win32com.client.Dispatch('Powerpoint.Application')\r
-\r
- if powerpoint is None:\r
- return\r
-\r
- activepres = powerpoint.ActivePresentation\r
- return activepres\r
-\r
-def export_next(slide):\r
- global cache\r
- ssp = get_activepresentation()\r
- if ssp:\r
- if slide < len(ssp.Slides):\r
- ssp.Slides(slide + 1).Export(cache + r'''\slide0.jpg''', "JPG")\r
- attempts = 0\r
- while attempts < 3:\r
- try:\r
- os.replace(cache + r'''\slide0.jpg''', cache + r'''\slide.jpg''')\r
- except:\r
- pass\r
- attempts += 1\r
- else:\r
- shutil.copyfileobj(open(os.path.dirname(os.path.realpath(__file__)) + r'''\blank.jpg''', 'rb'), open(cache + r'''\slide.jpg''', 'wb'))\r
-\r
-def slideshow_view_first(pressed):\r
- if pressed:\r
- ssv = get_slideshow_view()\r
- if ssv:\r
- ssv.First()\r
- ssv.State = 1\r
-\r
-def slideshow_view_previous(pressed):\r
- if pressed:\r
- ssv = get_slideshow_view()\r
- if ssv:\r
- ssv.Previous()\r
- ssv.State = 1\r
- export_next(ssv.CurrentShowPosition)\r
-\r
-def slideshow_view_next(pressed):\r
- if pressed:\r
- ssv = get_slideshow_view()\r
- if ssv:\r
- ssv.Next()\r
- ssv.State = 1\r
- export_next(ssv.CurrentShowPosition)\r
- \r
-\r
-def slideshow_view_last(pressed):\r
- if pressed:\r
- ssv = get_slideshow_view()\r
- if ssv:\r
- ssv.Last()\r
- ssv.State = 1\r
-\r
-def slideshow_view_black(pressed):\r
- if pressed:\r
- ssv = get_slideshow_view()\r
- if ssv:\r
- if ssv.State == 3 or ssv.State == 4:\r
- ssv.State = 1\r
- else:\r
- ssv.State = 3\r
-\r
-def slideshow_view_white(pressed):\r
- if pressed:\r
- ssv = get_slideshow_view()\r
- if ssv:\r
- if ssv.State == 4 or ssv.State == 3:\r
- ssv.State = 1\r
- else:\r
- ssv.State = 4\r