slidedesk 0.1.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- slidedesk-0.1.0/LICENSE +28 -0
- slidedesk-0.1.0/PKG-INFO +111 -0
- slidedesk-0.1.0/README.md +90 -0
- slidedesk-0.1.0/pyproject.toml +34 -0
- slidedesk-0.1.0/setup.cfg +4 -0
- slidedesk-0.1.0/src/slidedesk/__init__.py +6 -0
- slidedesk-0.1.0/src/slidedesk/cli.py +46 -0
- slidedesk-0.1.0/src/slidedesk/convert.py +181 -0
- slidedesk-0.1.0/src/slidedesk/db.py +102 -0
- slidedesk-0.1.0/src/slidedesk/embeddings.py +112 -0
- slidedesk-0.1.0/src/slidedesk/image_embeddings.py +49 -0
- slidedesk-0.1.0/src/slidedesk/images.py +61 -0
- slidedesk-0.1.0/src/slidedesk/layout_strip.py +210 -0
- slidedesk-0.1.0/src/slidedesk/models.py +64 -0
- slidedesk-0.1.0/src/slidedesk/pptx_tools.py +159 -0
- slidedesk-0.1.0/src/slidedesk/project.py +548 -0
- slidedesk-0.1.0/src/slidedesk/scanner.py +275 -0
- slidedesk-0.1.0/src/slidedesk/server/__init__.py +0 -0
- slidedesk-0.1.0/src/slidedesk/server/app.py +363 -0
- slidedesk-0.1.0/src/slidedesk/server/static/css/style.css +384 -0
- slidedesk-0.1.0/src/slidedesk/server/static/js/app.js +1502 -0
- slidedesk-0.1.0/src/slidedesk/server/templates/index.html +102 -0
- slidedesk-0.1.0/src/slidedesk/text_generation.py +199 -0
- slidedesk-0.1.0/src/slidedesk.egg-info/PKG-INFO +111 -0
- slidedesk-0.1.0/src/slidedesk.egg-info/SOURCES.txt +40 -0
- slidedesk-0.1.0/src/slidedesk.egg-info/dependency_links.txt +1 -0
- slidedesk-0.1.0/src/slidedesk.egg-info/entry_points.txt +2 -0
- slidedesk-0.1.0/src/slidedesk.egg-info/requires.txt +13 -0
- slidedesk-0.1.0/src/slidedesk.egg-info/top_level.txt +1 -0
- slidedesk-0.1.0/tests/test_basic.py +40 -0
- slidedesk-0.1.0/tests/test_cli.py +45 -0
- slidedesk-0.1.0/tests/test_convert.py +72 -0
- slidedesk-0.1.0/tests/test_embeddings.py +42 -0
- slidedesk-0.1.0/tests/test_export.py +66 -0
- slidedesk-0.1.0/tests/test_image_embeddings.py +231 -0
- slidedesk-0.1.0/tests/test_images.py +48 -0
- slidedesk-0.1.0/tests/test_local_embeddings.py +102 -0
- slidedesk-0.1.0/tests/test_pdf_cache.py +75 -0
- slidedesk-0.1.0/tests/test_scan_progress.py +45 -0
- slidedesk-0.1.0/tests/test_server.py +164 -0
- slidedesk-0.1.0/tests/test_text_generation.py +37 -0
- slidedesk-0.1.0/tests/test_visibility.py +73 -0
slidedesk-0.1.0/LICENSE
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
Copyright 2026 Robert Haase, ScaDS.AI, Uni Leipzig
|
|
2
|
+
All rights reserved.
|
|
3
|
+
|
|
4
|
+
Redistribution and use in source and binary forms, with or without
|
|
5
|
+
modification, are permitted provided that the following conditions are met:
|
|
6
|
+
|
|
7
|
+
1. Redistributions of source code must retain the above copyright notice,
|
|
8
|
+
this list of conditions and the following disclaimer.
|
|
9
|
+
|
|
10
|
+
2. Redistributions in binary form must reproduce the above copyright notice,
|
|
11
|
+
this list of conditions and the following disclaimer in the documentation
|
|
12
|
+
and/or other materials provided with the distribution.
|
|
13
|
+
|
|
14
|
+
3. Neither the name of the copyright holder nor the names of its contributors
|
|
15
|
+
may be used to endorse or promote products derived from this software without
|
|
16
|
+
specific prior written permission.
|
|
17
|
+
|
|
18
|
+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
|
19
|
+
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
20
|
+
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
|
21
|
+
ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
|
|
22
|
+
LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
|
23
|
+
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
|
24
|
+
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
|
25
|
+
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
|
26
|
+
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
|
27
|
+
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
|
28
|
+
POSSIBILITY OF SUCH DAMAGE.
|
slidedesk-0.1.0/PKG-INFO
ADDED
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: slidedesk
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: AI-assisted browsing and re-combination of PowerPoint slide decks
|
|
5
|
+
Author-email: Robert Haase <robert.haase@uni-leipzig.de>
|
|
6
|
+
License: MIT
|
|
7
|
+
Requires-Python: >=3.9
|
|
8
|
+
Description-Content-Type: text/markdown
|
|
9
|
+
License-File: LICENSE
|
|
10
|
+
Requires-Dist: flask>=3.0
|
|
11
|
+
Requires-Dist: python-pptx>=0.6.23
|
|
12
|
+
Requires-Dist: pdf2image>=1.17.0
|
|
13
|
+
Requires-Dist: pillow>=10.0.0
|
|
14
|
+
Requires-Dist: click>=8.1
|
|
15
|
+
Requires-Dist: torch>=2.2
|
|
16
|
+
Requires-Dist: transformers<6,>=4.40
|
|
17
|
+
Requires-Dist: pywin32>=306; sys_platform == "win32"
|
|
18
|
+
Provides-Extra: dev
|
|
19
|
+
Requires-Dist: pytest>=7.4; extra == "dev"
|
|
20
|
+
Dynamic: license-file
|
|
21
|
+
|
|
22
|
+
# SlideDesk
|
|
23
|
+
|
|
24
|
+
SlideDesk indexes a folder full of `.pptx` files (and sub-folders),
|
|
25
|
+
allowing you to browse everything in a touch-friendly browser GUI.
|
|
26
|
+
It also has a similarity search, allowing you to rediscover slides
|
|
27
|
+
and build slide decks efficiently.
|
|
28
|
+
|
|
29
|
+

|
|
30
|
+
|
|
31
|
+
## Install
|
|
32
|
+
|
|
33
|
+
It is recommended to install SlideDesk in a [conda-forge](https://conda-forge.org/download/) environment.
|
|
34
|
+
|
|
35
|
+
```bash
|
|
36
|
+
pip install slidedesk
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
### Additional requirements
|
|
40
|
+
|
|
41
|
+
* Works on Windows only
|
|
42
|
+
* Requires Microsoft PowerPoint installed
|
|
43
|
+
* Requires [Poppler](https://poppler.freedesktop.org/). You can install poppler like this
|
|
44
|
+
|
|
45
|
+
```
|
|
46
|
+
conda install poppler
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
## Usage
|
|
50
|
+
|
|
51
|
+
```bash
|
|
52
|
+
slidedesk /path/to/folder
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
**Note:** If you run this for the first time on a folder that contains many slide decks,
|
|
56
|
+
the initial scan may take hours depending on your computer. You will slide decks once they are scanned and a progress bar in the top right corner shows how far scanning and embedding are done.
|
|
57
|
+
|
|
58
|
+
Alternatively, navigate to the folder and run SlideDesk from there:
|
|
59
|
+
```bash
|
|
60
|
+
cd /path/to/folder
|
|
61
|
+
slidedesk .
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
This creates (or opens) a `.slidedesk/slidedesk.db` SQLite project file inside the folder,
|
|
65
|
+
starts scanning it for `.pptx` files in the background, and opens a browser GUI at
|
|
66
|
+
`http://127.0.0.1:5000`. You can also make it use a different port using the
|
|
67
|
+
`--port 8989` option.
|
|
68
|
+
|
|
69
|
+
To browse decks already stored in `slidedesk.db` without scanning folders for
|
|
70
|
+
changes or new decks:
|
|
71
|
+
|
|
72
|
+
```bash
|
|
73
|
+
slidedesk /path/to/folder --no-scan
|
|
74
|
+
```
|
|
75
|
+
|
|
76
|
+
This disables startup and recurring folder scans.
|
|
77
|
+
The background embedding worker is also stopped in this mode. You can still
|
|
78
|
+
explicitly refresh an individual indexed deck from the GUI.
|
|
79
|
+
|
|
80
|
+
## How it works under the hood
|
|
81
|
+
|
|
82
|
+
SlideDesk downloads models from Hugging Face on first use, to run them locally
|
|
83
|
+
Hence, it does not need an API key or an OpenAI-compatible server.
|
|
84
|
+
|
|
85
|
+
* Slide texts are embedded using the [intfloat/multilingual-e5-large-instruct](https://huggingface.co/intfloat/multilingual-e5-large-instruct) model. Thanks to this, you can search for terms
|
|
86
|
+
such as "image filtering" and it may find slides about "image processsing", too.
|
|
87
|
+
|
|
88
|
+
* Slide images are embedded locally with [openai/clip-vit-base-patch32](https://huggingface.co/openai/clip-vit-base-patch32).
|
|
89
|
+
|
|
90
|
+
* Advanced Search generates editable slide outlines locally with the text-generation small language model [Qwen/Qwen3.5-0.8B](https://huggingface.co/Qwen/Qwen3.5-0.8B). The model is downloaded on first use.
|
|
91
|
+
|
|
92
|
+
The background worker stores vectors in `slidedesk.db`.
|
|
93
|
+
|
|
94
|
+
“Show similar slides” presents one list: visual matches first, followed by
|
|
95
|
+
additional text matches, excluding duplicates. Either cache
|
|
96
|
+
can supply results while the other is still being built or unavailable.
|
|
97
|
+
|
|
98
|
+
## Similar and related projects
|
|
99
|
+
|
|
100
|
+
* [SlideFlow](https://github.com/michaelseliger/slideflow)
|
|
101
|
+
* [SlideInsight](https://github.com/NFDI4BIOIMAGE/SlideInsight)
|
|
102
|
+
* [pptx-automizer](https://github.com/singerla/pptx-automizer)
|
|
103
|
+
|
|
104
|
+
## Contributing
|
|
105
|
+
|
|
106
|
+
Contributions are welcome! Please feel free to submit a Pull Request. Note: Large parts of the code in this repository were vibe-coded using GitHub Copilot integration in Visual Studio Code. When modifying code here, consider using a similar tool.
|
|
107
|
+
|
|
108
|
+
## Acknowledgements
|
|
109
|
+
|
|
110
|
+
We acknowledge the financial support by the Federal Ministry of Research, Technology and Space of Germany and by Sächsische Staatsministerium für Wissenschaft, Kultur und Tourismus in the programme Center of Excellence for AI-research „Center for Scalable Data Analytics and Artificial Intelligence Dresden/Leipzig“, project identification number: ScaDS.AI
|
|
111
|
+
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
# SlideDesk
|
|
2
|
+
|
|
3
|
+
SlideDesk indexes a folder full of `.pptx` files (and sub-folders),
|
|
4
|
+
allowing you to browse everything in a touch-friendly browser GUI.
|
|
5
|
+
It also has a similarity search, allowing you to rediscover slides
|
|
6
|
+
and build slide decks efficiently.
|
|
7
|
+
|
|
8
|
+

|
|
9
|
+
|
|
10
|
+
## Install
|
|
11
|
+
|
|
12
|
+
It is recommended to install SlideDesk in a [conda-forge](https://conda-forge.org/download/) environment.
|
|
13
|
+
|
|
14
|
+
```bash
|
|
15
|
+
pip install slidedesk
|
|
16
|
+
```
|
|
17
|
+
|
|
18
|
+
### Additional requirements
|
|
19
|
+
|
|
20
|
+
* Works on Windows only
|
|
21
|
+
* Requires Microsoft PowerPoint installed
|
|
22
|
+
* Requires [Poppler](https://poppler.freedesktop.org/). You can install poppler like this
|
|
23
|
+
|
|
24
|
+
```
|
|
25
|
+
conda install poppler
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
## Usage
|
|
29
|
+
|
|
30
|
+
```bash
|
|
31
|
+
slidedesk /path/to/folder
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
**Note:** If you run this for the first time on a folder that contains many slide decks,
|
|
35
|
+
the initial scan may take hours depending on your computer. You will slide decks once they are scanned and a progress bar in the top right corner shows how far scanning and embedding are done.
|
|
36
|
+
|
|
37
|
+
Alternatively, navigate to the folder and run SlideDesk from there:
|
|
38
|
+
```bash
|
|
39
|
+
cd /path/to/folder
|
|
40
|
+
slidedesk .
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
This creates (or opens) a `.slidedesk/slidedesk.db` SQLite project file inside the folder,
|
|
44
|
+
starts scanning it for `.pptx` files in the background, and opens a browser GUI at
|
|
45
|
+
`http://127.0.0.1:5000`. You can also make it use a different port using the
|
|
46
|
+
`--port 8989` option.
|
|
47
|
+
|
|
48
|
+
To browse decks already stored in `slidedesk.db` without scanning folders for
|
|
49
|
+
changes or new decks:
|
|
50
|
+
|
|
51
|
+
```bash
|
|
52
|
+
slidedesk /path/to/folder --no-scan
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
This disables startup and recurring folder scans.
|
|
56
|
+
The background embedding worker is also stopped in this mode. You can still
|
|
57
|
+
explicitly refresh an individual indexed deck from the GUI.
|
|
58
|
+
|
|
59
|
+
## How it works under the hood
|
|
60
|
+
|
|
61
|
+
SlideDesk downloads models from Hugging Face on first use, to run them locally
|
|
62
|
+
Hence, it does not need an API key or an OpenAI-compatible server.
|
|
63
|
+
|
|
64
|
+
* Slide texts are embedded using the [intfloat/multilingual-e5-large-instruct](https://huggingface.co/intfloat/multilingual-e5-large-instruct) model. Thanks to this, you can search for terms
|
|
65
|
+
such as "image filtering" and it may find slides about "image processsing", too.
|
|
66
|
+
|
|
67
|
+
* Slide images are embedded locally with [openai/clip-vit-base-patch32](https://huggingface.co/openai/clip-vit-base-patch32).
|
|
68
|
+
|
|
69
|
+
* Advanced Search generates editable slide outlines locally with the text-generation small language model [Qwen/Qwen3.5-0.8B](https://huggingface.co/Qwen/Qwen3.5-0.8B). The model is downloaded on first use.
|
|
70
|
+
|
|
71
|
+
The background worker stores vectors in `slidedesk.db`.
|
|
72
|
+
|
|
73
|
+
“Show similar slides” presents one list: visual matches first, followed by
|
|
74
|
+
additional text matches, excluding duplicates. Either cache
|
|
75
|
+
can supply results while the other is still being built or unavailable.
|
|
76
|
+
|
|
77
|
+
## Similar and related projects
|
|
78
|
+
|
|
79
|
+
* [SlideFlow](https://github.com/michaelseliger/slideflow)
|
|
80
|
+
* [SlideInsight](https://github.com/NFDI4BIOIMAGE/SlideInsight)
|
|
81
|
+
* [pptx-automizer](https://github.com/singerla/pptx-automizer)
|
|
82
|
+
|
|
83
|
+
## Contributing
|
|
84
|
+
|
|
85
|
+
Contributions are welcome! Please feel free to submit a Pull Request. Note: Large parts of the code in this repository were vibe-coded using GitHub Copilot integration in Visual Studio Code. When modifying code here, consider using a similar tool.
|
|
86
|
+
|
|
87
|
+
## Acknowledgements
|
|
88
|
+
|
|
89
|
+
We acknowledge the financial support by the Federal Ministry of Research, Technology and Space of Germany and by Sächsische Staatsministerium für Wissenschaft, Kultur und Tourismus in the programme Center of Excellence for AI-research „Center for Scalable Data Analytics and Artificial Intelligence Dresden/Leipzig“, project identification number: ScaDS.AI
|
|
90
|
+
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
requires = ["setuptools>=68", "wheel"]
|
|
3
|
+
build-backend = "setuptools.build_meta"
|
|
4
|
+
|
|
5
|
+
[project]
|
|
6
|
+
name = "slidedesk"
|
|
7
|
+
version = "0.1.0"
|
|
8
|
+
description = "AI-assisted browsing and re-combination of PowerPoint slide decks"
|
|
9
|
+
readme = "README.md"
|
|
10
|
+
requires-python = ">=3.9"
|
|
11
|
+
license = { text = "MIT" }
|
|
12
|
+
authors = [{ name = "Robert Haase", email = "robert.haase@uni-leipzig.de" }]
|
|
13
|
+
dependencies = [
|
|
14
|
+
"flask>=3.0",
|
|
15
|
+
"python-pptx>=0.6.23",
|
|
16
|
+
"pdf2image>=1.17.0",
|
|
17
|
+
"pillow>=10.0.0",
|
|
18
|
+
"click>=8.1",
|
|
19
|
+
"torch>=2.2",
|
|
20
|
+
"transformers>=4.40,<6",
|
|
21
|
+
"pywin32>=306; sys_platform == 'win32'",
|
|
22
|
+
]
|
|
23
|
+
|
|
24
|
+
[project.optional-dependencies]
|
|
25
|
+
dev = ["pytest>=7.4"]
|
|
26
|
+
|
|
27
|
+
[project.scripts]
|
|
28
|
+
slidedesk = "slidedesk.cli:main"
|
|
29
|
+
|
|
30
|
+
[tool.setuptools.packages.find]
|
|
31
|
+
where = ["src"]
|
|
32
|
+
|
|
33
|
+
[tool.setuptools.package-data]
|
|
34
|
+
slidedesk = ["server/static/**/*", "server/templates/**/*"]
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
"""Command-line entry point: `slidedesk <folder>`."""
|
|
2
|
+
from __future__ import annotations
|
|
3
|
+
|
|
4
|
+
import threading
|
|
5
|
+
import webbrowser
|
|
6
|
+
|
|
7
|
+
import click
|
|
8
|
+
|
|
9
|
+
from .project import SlideProject
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
@click.command()
|
|
13
|
+
@click.argument("folder", type=click.Path(file_okay=False, path_type=str))
|
|
14
|
+
@click.option("--host", default="127.0.0.1", show_default=True)
|
|
15
|
+
@click.option("--port", default=5000, show_default=True, type=int)
|
|
16
|
+
@click.option("--no-browser", is_flag=True, help="Don't open a browser window.")
|
|
17
|
+
@click.option("--no-scan", is_flag=True, help="Use indexed decks without scanning folders for changes or new decks.")
|
|
18
|
+
@click.option(
|
|
19
|
+
"--scan-interval",
|
|
20
|
+
default=5.0,
|
|
21
|
+
show_default=True,
|
|
22
|
+
type=float,
|
|
23
|
+
help="Seconds between background folder scans.",
|
|
24
|
+
)
|
|
25
|
+
def main(folder: str, host: str, port: int, no_browser: bool, scan_interval: float, no_scan: bool = False) -> None:
|
|
26
|
+
"""Open (or create) a project in FOLDER and start the GUI server."""
|
|
27
|
+
from .server.app import create_app
|
|
28
|
+
|
|
29
|
+
project = SlideProject(folder)
|
|
30
|
+
if not no_scan:
|
|
31
|
+
project.scan_in_background(interval=scan_interval)
|
|
32
|
+
|
|
33
|
+
app = create_app(project, scan_enabled=not no_scan)
|
|
34
|
+
|
|
35
|
+
if not no_browser:
|
|
36
|
+
url = f"http://{host}:{port}/"
|
|
37
|
+
threading.Timer(1.0, lambda: webbrowser.open(url)).start()
|
|
38
|
+
|
|
39
|
+
try:
|
|
40
|
+
app.run(host=host, port=port, threaded=True, use_reloader=False)
|
|
41
|
+
finally:
|
|
42
|
+
project.close()
|
|
43
|
+
|
|
44
|
+
|
|
45
|
+
if __name__ == "__main__":
|
|
46
|
+
main()
|
|
@@ -0,0 +1,181 @@
|
|
|
1
|
+
"""Convert .pptx files to .pdf using Microsoft PowerPoint via COM automation.
|
|
2
|
+
|
|
3
|
+
Windows-only: requires Microsoft PowerPoint and pywin32 to be installed.
|
|
4
|
+
Rendering slide *images* from the resulting PDFs is done separately via
|
|
5
|
+
pdf2image/poppler (see images.py) and has no PowerPoint dependency.
|
|
6
|
+
"""
|
|
7
|
+
from __future__ import annotations
|
|
8
|
+
|
|
9
|
+
import platform
|
|
10
|
+
import threading
|
|
11
|
+
from pathlib import Path
|
|
12
|
+
|
|
13
|
+
_PP_SAVE_AS_PDF = 32 # PowerPoint's ppSaveAsPDF file-format constant
|
|
14
|
+
|
|
15
|
+
_local = threading.local()
|
|
16
|
+
_apps = []
|
|
17
|
+
_apps_lock = threading.Lock()
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
class ConversionError(RuntimeError):
|
|
21
|
+
pass
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
def _retain_app(app) -> None:
|
|
25
|
+
with _apps_lock:
|
|
26
|
+
_apps.append(app)
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
def repair_pptx(source: Path, repaired: Path) -> None:
|
|
30
|
+
"""Open and resave an export using a dedicated PowerPoint instance."""
|
|
31
|
+
if platform.system() != "Windows":
|
|
32
|
+
raise ConversionError("Repairing PowerPoint exports requires Microsoft PowerPoint on Windows.")
|
|
33
|
+
try:
|
|
34
|
+
import pythoncom
|
|
35
|
+
import win32com.client
|
|
36
|
+
except ImportError as exc:
|
|
37
|
+
raise ConversionError("pywin32 is required to repair PowerPoint exports.") from exc
|
|
38
|
+
|
|
39
|
+
source = source.resolve()
|
|
40
|
+
repaired = repaired.resolve()
|
|
41
|
+
repaired.parent.mkdir(parents=True, exist_ok=True)
|
|
42
|
+
app = None
|
|
43
|
+
presentation = None
|
|
44
|
+
pythoncom.CoInitialize()
|
|
45
|
+
print(f"Repairing PowerPoint export: {source} -> {repaired}")
|
|
46
|
+
try:
|
|
47
|
+
try:
|
|
48
|
+
app = win32com.client.DispatchEx("PowerPoint.Application")
|
|
49
|
+
_retain_app(app)
|
|
50
|
+
app.DisplayAlerts = 2 # ppAlertsNone
|
|
51
|
+
presentation = app.Presentations.Open(
|
|
52
|
+
str(source), ReadOnly=False, Untitled=False, WithWindow=False
|
|
53
|
+
)
|
|
54
|
+
presentation.SaveAs(str(repaired), 24) # ppSaveAsOpenXMLPresentation
|
|
55
|
+
finally:
|
|
56
|
+
if presentation is not None:
|
|
57
|
+
presentation.Close()
|
|
58
|
+
except Exception as exc:
|
|
59
|
+
import warnings
|
|
60
|
+
warnings.warn(f"PowerPoint failed to repair {source.name}: {exc}")
|
|
61
|
+
pythoncom.CoUninitialize()
|
|
62
|
+
|
|
63
|
+
|
|
64
|
+
def _get_powerpoint_app():
|
|
65
|
+
if platform.system() != "Windows":
|
|
66
|
+
raise ConversionError(
|
|
67
|
+
"Converting .pptx to .pdf requires Microsoft PowerPoint via COM "
|
|
68
|
+
"automation, which is only available on Windows."
|
|
69
|
+
)
|
|
70
|
+
try:
|
|
71
|
+
import pythoncom
|
|
72
|
+
import win32com.client
|
|
73
|
+
except ImportError as exc:
|
|
74
|
+
raise ConversionError(
|
|
75
|
+
"pywin32 is required for .pptx -> .pdf conversion. Install it with "
|
|
76
|
+
"'pip install pywin32'."
|
|
77
|
+
) from exc
|
|
78
|
+
|
|
79
|
+
app = getattr(_local, "app", None)
|
|
80
|
+
if app is not None:
|
|
81
|
+
return app
|
|
82
|
+
|
|
83
|
+
pythoncom.CoInitialize()
|
|
84
|
+
try:
|
|
85
|
+
app = win32com.client.DispatchEx("PowerPoint.Application")
|
|
86
|
+
except Exception as exc:
|
|
87
|
+
raise ConversionError(f"Could not start PowerPoint: {exc}") from exc
|
|
88
|
+
_retain_app(app)
|
|
89
|
+
_local.app = app
|
|
90
|
+
return app
|
|
91
|
+
|
|
92
|
+
|
|
93
|
+
def convert_pptx_to_pdf(pptx_path: Path, out_pdf_path: Path, timeout: int = 180) -> None:
|
|
94
|
+
"""Convert `pptx_path` to a PDF at `out_pdf_path` using PowerPoint COM automation."""
|
|
95
|
+
app = _get_powerpoint_app()
|
|
96
|
+
pptx_path = pptx_path.resolve()
|
|
97
|
+
out_pdf_path = out_pdf_path.resolve()
|
|
98
|
+
out_pdf_path.parent.mkdir(parents=True, exist_ok=True)
|
|
99
|
+
|
|
100
|
+
presentation = None
|
|
101
|
+
try:
|
|
102
|
+
presentation = app.Presentations.Open(
|
|
103
|
+
str(pptx_path), ReadOnly=True, WithWindow=False
|
|
104
|
+
)
|
|
105
|
+
presentation.SaveAs(str(out_pdf_path), _PP_SAVE_AS_PDF)
|
|
106
|
+
except Exception as exc:
|
|
107
|
+
raise ConversionError(
|
|
108
|
+
f"PowerPoint failed to convert {pptx_path} to PDF: {exc}"
|
|
109
|
+
) from exc
|
|
110
|
+
finally:
|
|
111
|
+
if presentation is not None:
|
|
112
|
+
presentation.Close()
|
|
113
|
+
|
|
114
|
+
if not out_pdf_path.exists():
|
|
115
|
+
raise ConversionError(f"PowerPoint did not produce {out_pdf_path}")
|
|
116
|
+
|
|
117
|
+
|
|
118
|
+
def _copy_to_clipboard(pptx_path: Path, do_copy) -> None:
|
|
119
|
+
"""Open `pptx_path` in a windowless PowerPoint and run `do_copy(presentation)`,
|
|
120
|
+
which is expected to call `.Copy()` on some slide selection to populate the clipboard.
|
|
121
|
+
"""
|
|
122
|
+
if platform.system() != "Windows":
|
|
123
|
+
raise ConversionError("Copying slides to the clipboard requires Microsoft PowerPoint on Windows.")
|
|
124
|
+
try:
|
|
125
|
+
import pythoncom
|
|
126
|
+
import win32com.client
|
|
127
|
+
except ImportError as exc:
|
|
128
|
+
raise ConversionError("pywin32 is required to copy slides to the clipboard.") from exc
|
|
129
|
+
|
|
130
|
+
pptx_path = pptx_path.resolve()
|
|
131
|
+
presentation = None
|
|
132
|
+
pythoncom.CoInitialize()
|
|
133
|
+
try:
|
|
134
|
+
try:
|
|
135
|
+
app = win32com.client.DispatchEx("PowerPoint.Application")
|
|
136
|
+
_retain_app(app)
|
|
137
|
+
app.DisplayAlerts = 2 # ppAlertsNone
|
|
138
|
+
presentation = app.Presentations.Open(
|
|
139
|
+
str(pptx_path), ReadOnly=True, Untitled=False, WithWindow=False
|
|
140
|
+
)
|
|
141
|
+
do_copy(presentation)
|
|
142
|
+
finally:
|
|
143
|
+
if presentation is not None:
|
|
144
|
+
presentation.Close()
|
|
145
|
+
except ConversionError:
|
|
146
|
+
pythoncom.CoUninitialize()
|
|
147
|
+
raise
|
|
148
|
+
except Exception as exc:
|
|
149
|
+
pythoncom.CoUninitialize()
|
|
150
|
+
raise ConversionError(f"PowerPoint failed to copy slides from {pptx_path.name}: {exc}") from exc
|
|
151
|
+
pythoncom.CoUninitialize()
|
|
152
|
+
|
|
153
|
+
|
|
154
|
+
def copy_slide_to_clipboard(pptx_path: Path, index_in_deck: int) -> None:
|
|
155
|
+
"""Copy one slide from `pptx_path` onto the OS clipboard via PowerPoint's
|
|
156
|
+
native `Slide.Copy()`, so it can be pasted directly into another open
|
|
157
|
+
PowerPoint presentation. Requires PowerPoint on Windows.
|
|
158
|
+
"""
|
|
159
|
+
def do_copy(presentation):
|
|
160
|
+
slide_number = index_in_deck + 1
|
|
161
|
+
if not (1 <= slide_number <= presentation.Slides.Count):
|
|
162
|
+
raise ConversionError(f"Slide index {index_in_deck} out of range for {pptx_path.name}")
|
|
163
|
+
presentation.Slides(slide_number).Copy()
|
|
164
|
+
|
|
165
|
+
_copy_to_clipboard(pptx_path, do_copy)
|
|
166
|
+
|
|
167
|
+
|
|
168
|
+
def copy_slides_to_clipboard(pptx_path: Path) -> None:
|
|
169
|
+
"""Copy every slide in `pptx_path` onto the OS clipboard as a single
|
|
170
|
+
multi-slide `SlideRange.Copy()`, so the whole set can be pasted together.
|
|
171
|
+
"""
|
|
172
|
+
def do_copy(presentation):
|
|
173
|
+
if presentation.Slides.Count == 0:
|
|
174
|
+
raise ConversionError("No slides to copy")
|
|
175
|
+
presentation.Slides.Range().Copy()
|
|
176
|
+
|
|
177
|
+
_copy_to_clipboard(pptx_path, do_copy)
|
|
178
|
+
|
|
179
|
+
|
|
180
|
+
def shutdown() -> None:
|
|
181
|
+
"""Compatibility hook; PowerPoint instances are intentionally left open."""
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
"""Low-level SQLite schema and connection helpers for a slidedesk project."""
|
|
2
|
+
from __future__ import annotations
|
|
3
|
+
|
|
4
|
+
import sqlite3
|
|
5
|
+
from pathlib import Path
|
|
6
|
+
|
|
7
|
+
SCHEMA_VERSION = 2
|
|
8
|
+
|
|
9
|
+
_SCHEMA = """
|
|
10
|
+
CREATE TABLE IF NOT EXISTS meta (
|
|
11
|
+
key TEXT PRIMARY KEY,
|
|
12
|
+
value TEXT
|
|
13
|
+
);
|
|
14
|
+
|
|
15
|
+
CREATE TABLE IF NOT EXISTS decks (
|
|
16
|
+
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
|
17
|
+
pptx_path TEXT UNIQUE NOT NULL,
|
|
18
|
+
pptx_mtime REAL NOT NULL,
|
|
19
|
+
pdf_path TEXT,
|
|
20
|
+
pdf_mtime REAL,
|
|
21
|
+
hidden_pdf_path TEXT,
|
|
22
|
+
hidden_pdf_mtime REAL,
|
|
23
|
+
last_scanned REAL
|
|
24
|
+
);
|
|
25
|
+
|
|
26
|
+
CREATE TABLE IF NOT EXISTS slides (
|
|
27
|
+
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
|
28
|
+
deck_id INTEGER NOT NULL REFERENCES decks(id) ON DELETE CASCADE,
|
|
29
|
+
index_in_deck INTEGER NOT NULL,
|
|
30
|
+
visible_pdf_page INTEGER,
|
|
31
|
+
hidden INTEGER NOT NULL DEFAULT 0,
|
|
32
|
+
text TEXT NOT NULL DEFAULT '',
|
|
33
|
+
UNIQUE(deck_id, index_in_deck)
|
|
34
|
+
);
|
|
35
|
+
|
|
36
|
+
CREATE INDEX IF NOT EXISTS idx_slides_deck ON slides(deck_id);
|
|
37
|
+
|
|
38
|
+
CREATE TABLE IF NOT EXISTS slide_embeddings (
|
|
39
|
+
slide_id INTEGER PRIMARY KEY REFERENCES slides(id) ON DELETE CASCADE,
|
|
40
|
+
model TEXT NOT NULL,
|
|
41
|
+
vector BLOB NOT NULL,
|
|
42
|
+
updated_at REAL NOT NULL
|
|
43
|
+
);
|
|
44
|
+
|
|
45
|
+
CREATE TABLE IF NOT EXISTS slide_image_embeddings (
|
|
46
|
+
slide_id INTEGER PRIMARY KEY REFERENCES slides(id) ON DELETE CASCADE,
|
|
47
|
+
model TEXT NOT NULL,
|
|
48
|
+
source_key TEXT NOT NULL,
|
|
49
|
+
vector BLOB NOT NULL,
|
|
50
|
+
updated_at REAL NOT NULL
|
|
51
|
+
);
|
|
52
|
+
|
|
53
|
+
CREATE TABLE IF NOT EXISTS slide_strip_image_embeddings (
|
|
54
|
+
slide_id INTEGER PRIMARY KEY REFERENCES slides(id) ON DELETE CASCADE,
|
|
55
|
+
model TEXT NOT NULL,
|
|
56
|
+
source_key TEXT NOT NULL,
|
|
57
|
+
vector BLOB NOT NULL,
|
|
58
|
+
updated_at REAL NOT NULL
|
|
59
|
+
);
|
|
60
|
+
|
|
61
|
+
CREATE VIRTUAL TABLE IF NOT EXISTS slides_fts USING fts5(
|
|
62
|
+
text,
|
|
63
|
+
content='slides',
|
|
64
|
+
content_rowid='id'
|
|
65
|
+
);
|
|
66
|
+
|
|
67
|
+
CREATE TRIGGER IF NOT EXISTS slides_ai AFTER INSERT ON slides BEGIN
|
|
68
|
+
INSERT INTO slides_fts(rowid, text) VALUES (new.id, new.text);
|
|
69
|
+
END;
|
|
70
|
+
|
|
71
|
+
CREATE TRIGGER IF NOT EXISTS slides_ad AFTER DELETE ON slides BEGIN
|
|
72
|
+
INSERT INTO slides_fts(slides_fts, rowid, text) VALUES ('delete', old.id, old.text);
|
|
73
|
+
END;
|
|
74
|
+
|
|
75
|
+
CREATE TRIGGER IF NOT EXISTS slides_au AFTER UPDATE ON slides BEGIN
|
|
76
|
+
INSERT INTO slides_fts(slides_fts, rowid, text) VALUES ('delete', old.id, old.text);
|
|
77
|
+
INSERT INTO slides_fts(rowid, text) VALUES (new.id, new.text);
|
|
78
|
+
END;
|
|
79
|
+
"""
|
|
80
|
+
|
|
81
|
+
|
|
82
|
+
def connect(db_path: Path) -> sqlite3.Connection:
|
|
83
|
+
"""Open a connection to the project database, creating the schema if needed."""
|
|
84
|
+
conn = sqlite3.connect(str(db_path), check_same_thread=False)
|
|
85
|
+
conn.row_factory = sqlite3.Row
|
|
86
|
+
conn.execute("PRAGMA foreign_keys = ON")
|
|
87
|
+
conn.executescript(_SCHEMA)
|
|
88
|
+
deck_columns = {row["name"] for row in conn.execute("PRAGMA table_info(decks)")}
|
|
89
|
+
for column, kind in (("strip_pdf_path", "TEXT"), ("strip_pdf_mtime", "REAL")):
|
|
90
|
+
if column not in deck_columns:
|
|
91
|
+
conn.execute(f"ALTER TABLE decks ADD COLUMN {column} {kind}")
|
|
92
|
+
columns = {row["name"] for row in conn.execute("PRAGMA table_info(slides)")}
|
|
93
|
+
if "user_hidden" not in columns:
|
|
94
|
+
conn.execute("ALTER TABLE slides ADD COLUMN user_hidden INTEGER")
|
|
95
|
+
if "source_slide_id" not in columns:
|
|
96
|
+
conn.execute("ALTER TABLE slides ADD COLUMN source_slide_id INTEGER")
|
|
97
|
+
conn.execute(
|
|
98
|
+
"INSERT OR REPLACE INTO meta(key, value) VALUES ('schema_version', ?)",
|
|
99
|
+
(str(SCHEMA_VERSION),),
|
|
100
|
+
)
|
|
101
|
+
conn.commit()
|
|
102
|
+
return conn
|