From 8fb8392527317538449368719a4508e15b1ac813 Mon Sep 17 00:00:00 2001 From: Andrew Lorimer Date: Sat, 8 May 2021 14:12:30 +1000 Subject: [PATCH] implement remaining config options --- README.md | 10 +++++++++- ppt_control/ppt_control.py | 30 ++++++++++++++++++------------ setup.py | 1 + 3 files changed, 28 insertions(+), 13 deletions(-) diff --git a/README.md b/README.md index 0fa4b27..2c3eb4f 100644 --- a/README.md +++ b/README.md @@ -5,6 +5,7 @@ An interface for controlling PowerPoint slideshows over the network using WebSoc This was originally designed for controlling a PowerPoint slideshow from an instance of OBS (Open Broadcaster Software) running on the same computer (removing the need for an extra monitor to show presenter view). This package includes three main components: + 1. The daemon, which runs in the background, independently of PowerPoint, and listens for WebSocket commands and hosts an HTTP server for the frontend 2. The HTTP frontend, written in JavaScript, which displays status information and sends commands to the daemon through WebSocket (this can be docked in one of OBS's "custom browser docks") 3. The OBS script, which allows a mapping of keyboard shortcuts to commands within OBS in order to control the slideshow from anywhere in OBS (keyboard shortcuts are implemented in the HTTP interface but only work when this is focused in OBS) @@ -14,14 +15,19 @@ Due to the implementation's use of `pywin32` for COM communication, this daemon ## Installation `pip install ppt-control` + will install all three components. You can then start the daemon by running + `py -m ppt_control` + from a command prompt (note the underscore). There are a few steps to set the package up fully: ### Starting the daemon at bootup To start the daemon automatically at login, run + `pip show ppt-control` + and get the location of the package. Create a shortcut to `ppt_control.py` in Explorer and put it in `%AppData%\Microsoft\Windows\Start Menu\Programs\Startup`. ### Using the HTTP interface in OBS @@ -31,9 +37,11 @@ To view the HTTP interface from within OBS, you can add a "custom browser dock" ### Global keyboard shortcuts in OBS Keyboard shortcuts in OBS browser docks only work when the browser dock is focused by clicking in it (there is actually no indication of focus in the interface, but if you click away from the browser dock the shortcuts will not work). To resolve this, there is another Python script called `ppt_control_obs.py` which can be added as a custom script in OBS. This script will listen for specific keys (configured in OBS's Hotkeys settings) and send commands to the daemon directly over WebSocket (no HTTP involved). To add the custom script, go to Tools -> Scripts, then click the + and choose the script. This will be located in the package directory which can be found with + `pip show ppt-control` + as above. It is a good idea to turn off the keyboard shortcuts in the HTTP interface after loading the OBS hotkey script, otherwise commands will be sent to the daemon twice when the browser dock is focused. ## Configuration -Various settings can be changed in `%AppData%\ppt-control\ppt-control.ini`. This file is populated with the defaults for all possible settings at installation. +Various settings can be changed in `%AppData%\ppt-control\ppt-control.ini`. This file is populated with the defaults for all possible settings at installation. A settings GUI accessible from the system tray icon is also available (work in progress). diff --git a/ppt_control/ppt_control.py b/ppt_control/ppt_control.py index f942b32..5ff80ef 100755 --- a/ppt_control/ppt_control.py +++ b/ppt_control/ppt_control.py @@ -40,7 +40,6 @@ global ws_label global http_server scheduler = None current_slideshow = None -CACHEDIR = r'''C:\Windows\Temp\ppt-cache''' interface_root = None CONFIG_FILE = r'''..\ppt-control.ini''' LOGFILE = r'''..\ppt-control.log''' @@ -81,7 +80,7 @@ class Handler(server.SimpleHTTPRequestHandler): black = 0 if current_slideshow: try: - path = CACHEDIR + "\\" + current_slideshow.name() + path = config.prefs["Main"]["cache"] + "\\" + current_slideshow.name() except Exception as e: path = os.path.join(os.path.dirname(os.path.realpath(__file__)), r'''\static\black.jpg''') + '/' logger.warning("Failed to get current slideshow name: ", e) @@ -103,7 +102,7 @@ class Handler(server.SimpleHTTPRequestHandler): def run_http(): global http_server - http_server = server.HTTPServer(("", 80), Handler) + http_server = server.HTTPServer((config.prefs["HTTP"]["interface"], config.prefs.getint("HTTP", "port")), Handler) http_server.serve_forever() STATE_DEFAULT = {"connected": 0, "current": 0, "total": 0, "visible": 0, "name": ""} @@ -190,7 +189,6 @@ async def ws_receive(websocket, path): notify_state() else: logger.error("Received unnsupported event: {}", data) - message = "" finally: USERS.remove(websocket) @@ -209,7 +207,7 @@ def run_ws(): ws_queue = asyncio.Queue() global loop loop = asyncio.get_event_loop() - start_server = websockets.serve(ws_handler, "0.0.0.0", 5678, ping_interval=None) + start_server = websockets.serve(ws_handler, config.prefs["WebSocket"]["interface"], config.prefs.getint("WebSocket", "port"), ping_interval=None) asyncio.get_event_loop().run_until_complete(start_server) asyncio.get_event_loop().run_forever() @@ -236,7 +234,7 @@ def start_ws(): logger.info("Started websocket server") class Slideshow: - def __init__(self, instance): + def __init__(self, instance, blackwhite): self.instance = instance if self.instance is None: raise ValueError("PPT instance cannot be None") @@ -249,6 +247,8 @@ class Slideshow: raise ValueError("PPT instance has no active presentation") self.presentation = self.instance.ActivePresentation + self.blackwhite = blackwhite + self.export_current_next() def unload(self): @@ -336,7 +336,10 @@ class Slideshow: def black(self): try: self.refresh() - self.view.State = 3 + if self.blackwhite == "both" and self.view.State == 4: + self.view.state = 1 + else: + self.view.State = 3 self.export_current_next() except (ValueError, pywintypes.com_error): self.unload() @@ -344,7 +347,10 @@ class Slideshow: def white(self): try: self.refresh() - self.view.State = 4 + if self.blackwhite == "both" and self.view.State == 3: + self.view.state = 1 + else: + self.view.State = 4 self.export_current_next() except (ValueError, pywintypes.com_error): self.unload() @@ -371,14 +377,14 @@ class Slideshow: self.export(self.current_slide() + 2) def export(self, slide): - destination = CACHEDIR + "\\" + self.name() + "\\" + str(slide) + ".jpg" + destination = config.prefs["Main"]["cache"] + "\\" + self.name() + "\\" + str(slide) + ".jpg" os.makedirs(os.path.dirname(destination), exist_ok=True) if not os.path.exists(destination) or time.time() - os.path.getmtime(destination) > config.prefs.getint("Main", "cache_timeout"): if slide <= self.total_slides(): attempts = 0 while attempts < 3: try: - self.presentation.Slides(slide).Export(destination, "JPG") + self.presentation.Slides(slide).Export(destination, config.prefs["Main"]["cache_format"]) break except: pass @@ -430,7 +436,7 @@ def connect_ppt(): try: instance = get_ppt_instance() global current_slideshow - current_slideshow = Slideshow(instance) + current_slideshow = Slideshow(instance, config.prefs["Main"]["blackwhite"]) STATE["connected"] = 1 STATE["current"] = current_slideshow.current_slide() STATE["total"] = current_slideshow.total_slides() @@ -565,7 +571,7 @@ def start_interface(): #logging.getLogger("asyncio").setLevel(logging.ERROR) #logging.getLogger("asyncio.coroutines").setLevel(logging.ERROR) - #logging.getLogger("websockets.server").setLevel(logging.ERROR) + logging.getLogger("websockets.server").setLevel(logging.ERROR) #logging.getLogger("websockets.protocol").setLevel(logging.ERROR) diff --git a/setup.py b/setup.py index dd4b9bd..8a032b7 100644 --- a/setup.py +++ b/setup.py @@ -11,6 +11,7 @@ setuptools.setup( name='ppt-control', version=ppt_control.__version__, description='Interface for controlling PowerPoint slideshows over WebSocket/HTTP', + long_description=long_description, long_description_content_type='text/markdown', url='https://git.lorimer.id.au/ppt-control.git', author='Andrew Lorimer', -- 2.43.2