a1e90ab47ca07cbd324453ec627ab0eac1320371
   1from configparser import ConfigParser
   2
   3prefs = None
   4
   5defaults = {
   6        'Main': {
   7            # Logging level
   8            # Options: debug, info, warning, error, critical
   9            # (see https://docs.python.org/3/howto/logging.html#when-to-use-logging)
  10            'logging': 'debug',
  11
  12            # Cache location
  13            # Directory to store slide preview images for each presentation
  14            'cache': r'''C:\Windows\Temp\ppt-cache''',
  15
  16            # Cache format
  17            # Can be set to any image filter set in the registry, but most commonly JPG or PNG
  18            # (see https://docs.microsoft.com/en-us/office/vba/api/powerpoint.slide.export)
  19            'cache_format': 'JPG',
  20
  21            # Cache timeout
  22            # Time after which slides should be exported again to reflect any changes made in the
  23            # PowerPoint editor. Value is in seconds.
  24            'cache_timeout': 5*60,
  25
  26            # Cache initialisation
  27            # Whether to export all slides when a slideshow is started. Can be set to any falsy or
  28            # truthy value.
  29            'cache_init': True,
  30
  31            # Black-white behaviour
  32            # Sets the behaviour when returning from black or white mode. Options: "both", "literal"
  33            # In PowerPoint's presenter view, if the slideshow is in black or white screen mode,
  34            # attempting to switch to the other mode (white/black) will result in the slideshow
  35            # returning to a normal (visible) state, rather than white/black. This behaviour is
  36            # also the default for ppt-control, and is set by setting the value of "blackwhite"
  37            # to "both" (since when the slideshow is in black or white mode, requesting either
  38            # of black or white mode will return the slideshow to normal). The more intuitive
  39            # settings is "literal", whereby when the slideshow is in black or white mode, 
  40            # pressing the button corresponding to the mode that the slideshow is already in will
  41            # return the slideshow to normal mode, and pressing the other button will put the 
  42            # slideshow into that mode.
  43            'blackwhite': 'both',
  44
  45            # Refresh interval
  46            # Describes the number of seconds between backend updates, which consist of:
  47            # - synchronisation of PowerPoint's events with the internal state. 
  48            # - updating the interface (systray icon) status
  49            # - check for PowerPoint files that have been opened in protected view
  50            # You could set a shorter value here, but these updates don't have to be instant so
  51            # the default value of 2 seconds should work fine.
  52            'refresh': 2,
  53
  54            # Disable protecte view
  55            # If set to a truthy value, ppt-control will attempt to disable protected view on files
  56            # which have been opened in protected view. Obviously this introduces some security risk,
  57            # so if you are uncomfortable with this, leave it off and you will have to disable 
  58            # protected view for each file manually to be able to control it will ppt-control.
  59            'disable_protected': True
  60        },
  61        'HTTP': {
  62            # HTTP interface
  63            # The interface to listen for HTTP requests on. Change this if you want to restrict the
  64            # HTTP frontend to a specific network. A blank value means all interfaces.
  65            'interface': '',
  66
  67            # HTTP port
  68            # The port to listen for HTTP requests on. The default value of 80 is the standard 
  69            # port for HTTP, so when set to this value you don't need to include the port number
  70            # in the URL when navigating to the frontend. For all other values you will need to 
  71            # specify the port number in the web browser (except 443, but that's a bad idea).
  72            'port': 80
  73        },
  74        'WebSocket': {
  75            # WebSocket interface
  76            # The interface to listen for WebSocket requests on. Change this if you want to restrict
  77            # the WebSocket interface to a specific network. A value of 0.0.0.0 means all interfaces.
  78            'interface': '0.0.0.0',
  79
  80            # WebSocket port
  81            # The port to listen for WebSocket requests on. This needs to match the port specified in
  82            # whatever frontend you are using (e.g. in the JS code for the HTTP frontend, or in the
  83            # script settings for the OBS frontend).
  84            'port': 5678
  85        }
  86}
  87
  88
  89def loadconf(configpaths):
  90    """
  91    Initial setup for a ConfigParser object. `configpaths` should be a list of
  92    configuration files to load (typically only one). To use the generated
  93    ConfigParser, use `import logparse.config` and then `config.prefs.get(..)`.
  94    The prefs object is returned after creation as a convenience but this method
  95    should only be called once per runtime.
  96    """
  97    prefs = ConfigParser()
  98    prefs.read_dict(defaults)
  99    try:
 100        success = prefs.read(configpaths)
 101        print("Loaded {0} config file(s): {1}".format(
 102                str(len(success)), str(success)))
 103    except Exception as e:
 104        print("Error processing config: " + str(e))
 105    return prefs
 106
 107def export_defaults(file):
 108    """
 109    Write the default settings to a file object, including comments and with spaces around 
 110    delimeters. This function is intended to be used to populate the config file with defaults
 111    after installation.
 112    """
 113    prefs = loadconf([])
 114    prefs.write(file, space_around_delimiters=True)