+def connect_ppt():\r
+ """\r
+ Connect to the PowerPoint COM interface and perform initial enumeration of open files \r
+ ("presentations"). Files that are subsequently opened are dealt with using COM events (see the\r
+ ApplicationEvents class above). Therefore, once we are finished setting things up, we just \r
+ call refresh() as a daemon in order to keep clients up to date.\r
+ """\r
+ logger.debug("Searching for a PowerPoint slideshow...")\r
+ global ppt_application\r
+ global ppt_presentations\r
+\r
+ # Initialise PowerPoint application\r
+ ppt_application = get_application()\r
+ if ppt_application is None:\r
+ # Couldn't find PowerPoint application\r
+ icon.notify("Couldn't find PowerPoint application", "Error starting {}".format(PKG_NAME))\r
+ logger.error("Couldn't find PowerPoint application - check that PowerPoint is installed and COM is working")\r
+ sys.exit()\r
+\r
+ # Continue because we can connect to PowerPoint\r
+ logger.debug("Found PowerPoint application")\r
+\r
+ # Dispatch events\r
+ win32com.client.WithEvents(ppt_application, ApplicationEvents)\r
+ logger.debug("Dispatched events")\r
+\r
+ # Deal with windows in protected view\r
+ manage_protected_view(ppt_application)\r
+\r
+ # Initial enumeration of open presentations\r
+ logger.debug("Enumerating {} presentation(s)".format(len(ppt_application.Presentations)))\r
+ for n in range(1, len(ppt_application.Presentations)+1): # PowerPoint's slide indexing starts at 1.. why!?!?!?\r
+ pres = Presentation(ppt_application, n)\r
+ icon.notify("Connected to {}".format(pres.presentation.Name), PKG_NAME)\r
+ logger.debug("Found presentation {} with index {}".format(pres.presentation.Name, n))\r
+ ppt_presentations[pres.presentation.Name] = pres\r
+ refresh_daemon = threading.Thread(name="refresh_daemon", target=refresh)\r
+ refresh_daemon.setDaemon(True)\r
+ logger.debug("Handing over to refresh daemon - goodbye...")\r
+ if len(ppt_presentations) == 0:\r
+ # Provide some confirmation that the program has started if we haven't sent any \r
+ # connection notifications yet\r
+ icon.notify("Started server", PKG_NAME)\r
+ refresh_daemon.start()\r
+\r
+\r
+def start_server(_=None):\r
+ """\r
+ Start HTTP and WS servers, then connect to PPT instance with connect_ppt() which will then \r
+ set off the refresh daemon.\r
+ """\r
+ setup_http()\r
+ setup_ws()\r
+ connect_ppt()\r