assignmentwriter 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.
- assignmentwriter-0.1.0/LICENSE +21 -0
- assignmentwriter-0.1.0/PKG-INFO +266 -0
- assignmentwriter-0.1.0/PYPI-README.md +247 -0
- assignmentwriter-0.1.0/README.md +303 -0
- assignmentwriter-0.1.0/assignmentwriter/__init__.py +33 -0
- assignmentwriter-0.1.0/assignmentwriter/__main__.py +263 -0
- assignmentwriter-0.1.0/assignmentwriter/layouts.py +119 -0
- assignmentwriter-0.1.0/assignmentwriter/modules.py +447 -0
- assignmentwriter-0.1.0/assignmentwriter/res/fonts/AdineKirnberg.ttf +0 -0
- assignmentwriter-0.1.0/assignmentwriter/res/fonts/AlanisHand.ttf +0 -0
- assignmentwriter-0.1.0/assignmentwriter/res/fonts/Architex.ttf +0 -0
- assignmentwriter-0.1.0/assignmentwriter/res/fonts/GreatVibes-Regular.ttf +0 -0
- assignmentwriter-0.1.0/assignmentwriter/res/fonts/Hand_Note.otf +0 -0
- assignmentwriter-0.1.0/assignmentwriter/res/fonts/HomemadeApple.ttf +0 -0
- assignmentwriter-0.1.0/assignmentwriter/res/fonts/HoneyScript.ttf +0 -0
- assignmentwriter-0.1.0/assignmentwriter/res/fonts/JottFLF.ttf +0 -0
- assignmentwriter-0.1.0/assignmentwriter/res/fonts/NOTICE.md +26 -0
- assignmentwriter-0.1.0/assignmentwriter/res/fonts/Note_this.ttf +0 -0
- assignmentwriter-0.1.0/assignmentwriter/res/fonts/S_Hand.ttf +0 -0
- assignmentwriter-0.1.0/assignmentwriter/res/fonts/caveat.ttf +0 -0
- assignmentwriter-0.1.0/assignmentwriter/res/fonts/pleasewritemeasong.ttf +0 -0
- assignmentwriter-0.1.0/assignmentwriter/res/papers/a4paper.jpg +0 -0
- assignmentwriter-0.1.0/assignmentwriter/res/papers/cream.jpg +0 -0
- assignmentwriter-0.1.0/assignmentwriter/res/papers/cyan.jpg +0 -0
- assignmentwriter-0.1.0/assignmentwriter/res/papers/lightblue.jpg +0 -0
- assignmentwriter-0.1.0/assignmentwriter/res/papers/lightgreen.jpg +0 -0
- assignmentwriter-0.1.0/assignmentwriter/res/papers/lime.jpg +0 -0
- assignmentwriter-0.1.0/assignmentwriter/res/papers/lined.png +0 -0
- assignmentwriter-0.1.0/assignmentwriter/res/papers/orange.jpg +0 -0
- assignmentwriter-0.1.0/assignmentwriter/res/papers/pink.jpg +0 -0
- assignmentwriter-0.1.0/assignmentwriter/res/papers/rough.jpg +0 -0
- assignmentwriter-0.1.0/assignmentwriter/res/papers/spiral.png +0 -0
- assignmentwriter-0.1.0/assignmentwriter/res/papers/wrinkled.jpg +0 -0
- assignmentwriter-0.1.0/assignmentwriter.egg-info/PKG-INFO +266 -0
- assignmentwriter-0.1.0/assignmentwriter.egg-info/SOURCES.txt +40 -0
- assignmentwriter-0.1.0/assignmentwriter.egg-info/dependency_links.txt +1 -0
- assignmentwriter-0.1.0/assignmentwriter.egg-info/entry_points.txt +2 -0
- assignmentwriter-0.1.0/assignmentwriter.egg-info/requires.txt +4 -0
- assignmentwriter-0.1.0/assignmentwriter.egg-info/top_level.txt +1 -0
- assignmentwriter-0.1.0/pyproject.toml +32 -0
- assignmentwriter-0.1.0/setup.cfg +4 -0
- assignmentwriter-0.1.0/tests/test_assignmentwriter.py +782 -0
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 TheHritu
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1,266 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: assignmentwriter
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: A Python package and CLI that writes your text on paper in a handwriting font and ink of your choice
|
|
5
|
+
Author: TheHritu
|
|
6
|
+
License-Expression: MIT
|
|
7
|
+
Project-URL: Homepage, https://github.com/TheHritu/AssignmentWriter
|
|
8
|
+
Keywords: assignment,handwriting,handwritten,text-to-handwriting,image,pillow
|
|
9
|
+
Classifier: Programming Language :: Python :: 3
|
|
10
|
+
Classifier: Operating System :: OS Independent
|
|
11
|
+
Classifier: Topic :: Multimedia :: Graphics
|
|
12
|
+
Requires-Python: >=3.10
|
|
13
|
+
Description-Content-Type: text/markdown
|
|
14
|
+
License-File: LICENSE
|
|
15
|
+
Requires-Dist: Pillow>=9.0
|
|
16
|
+
Provides-Extra: cli
|
|
17
|
+
Requires-Dist: rich; extra == "cli"
|
|
18
|
+
Dynamic: license-file
|
|
19
|
+
|
|
20
|
+
# AssignmentWriter
|
|
21
|
+
|
|
22
|
+
A Python package and command line tool that writes your text on a sheet of paper, in a handwriting font and ink colour of your choice. Pick a paper, a font and an ink, and get back an image of the page(s) (in form of pdf too) - all in a few lines of code.
|
|
23
|
+
|
|
24
|
+
[](https://pypi.org/project/assignmentwriter/) [](https://github.com/TheHritu/AssignmentWriter/blob/main/LICENSE)
|
|
25
|
+
|
|
26
|
+
## Installation
|
|
27
|
+
|
|
28
|
+
```
|
|
29
|
+
pip install assignmentwriter -U
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
## Quick Start
|
|
33
|
+
|
|
34
|
+
```python
|
|
35
|
+
from assignmentwriter import Assignment, AssignmentConfigOptions
|
|
36
|
+
|
|
37
|
+
config = AssignmentConfigOptions(Text="Hello World", Paper="lined", Font="caveat", Ink="blue")
|
|
38
|
+
result = Assignment(config).create()
|
|
39
|
+
|
|
40
|
+
result.save("page.png") # saves the image
|
|
41
|
+
print(result) # prints the saved path (if saved)
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
Or write a whole text file, on as many pages as it needs:
|
|
45
|
+
|
|
46
|
+
```python
|
|
47
|
+
config = AssignmentConfigOptions(File="essay.txt", Paper="spiral", Ink="teal")
|
|
48
|
+
result = Assignment(config).create()
|
|
49
|
+
|
|
50
|
+
result.save("essay.png") # essay_1.png, essay_2.png, ...
|
|
51
|
+
result.save_pdf("essay.pdf") # or all the pages in one PDF
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
## Previews
|
|
55
|
+
|
|
56
|
+
See at https://github.com/TheHritu/AssignmentWriter
|
|
57
|
+
|
|
58
|
+
## Papers, fonts and inks
|
|
59
|
+
|
|
60
|
+
| Option | Values |
|
|
61
|
+
|--------|--------|
|
|
62
|
+
| `Paper` | `a4`, `lined`, `rough`, `spiral`, `wrinkled`, `cream`, `cyan`, `lightblue`, `lightgreen`, `lime`, `orange`, `pink` |
|
|
63
|
+
| `Font` | `adinekirnberg`, `alanishand`, `architex`, `caveat`, `greatvibesregular`, `hand_note`, `homemadeapple`, `honeyscript`, `jottflf`, `note_this`, `pleasewritemeasong`, `s_hand` |
|
|
64
|
+
| `Ink` | `blue`, `black`, `red`, `green`, `pencil`, `brown`, `purple`, `orange`, `teal`, `magenta`, or any hex colour such as `"131394"` |
|
|
65
|
+
|
|
66
|
+
A font can also be chosen by its number, 1 to 12, in the order shown above (`Font=4` is `caveat`).
|
|
67
|
+
Names are not case sensitive and spaces, dashes and underscores are ignored (`"Hand Note"` and `"Light Green"` work).
|
|
68
|
+
|
|
69
|
+
```python
|
|
70
|
+
from assignmentwriter import available_fonts, available_papers, INKS
|
|
71
|
+
|
|
72
|
+
print(available_papers()) # ['a4', 'lined', 'rough', 'spiral', 'wrinkled', 'cream', 'cyan', 'lightblue', 'lightgreen', 'lime', 'orange', 'pink']
|
|
73
|
+
print(available_fonts()) # ['adinekirnberg', 'alanishand', 'architex', 'caveat', 'greatvibesregular', 'hand_note', 'homemadeapple', 'honeyscript', 'jottflf', 'note_this', 'pleasewritemeasong', 's_hand']
|
|
74
|
+
print(list(INKS)) # ['blue', 'black', 'red', 'green', 'pencil', 'brown', 'purple', 'orange', 'teal', 'magenta']
|
|
75
|
+
```
|
|
76
|
+
|
|
77
|
+
> **Note:** `alanishand` draws the digits `2` and `5` very wide, so lines with those numbers can run off the page. Use another font for text with numbers.
|
|
78
|
+
|
|
79
|
+
## Configuration
|
|
80
|
+
|
|
81
|
+
`AssignmentConfigOptions` accepts these fields:
|
|
82
|
+
|
|
83
|
+
| Field | Type | Default | Description |
|
|
84
|
+
|-------|------|---------|-------------|
|
|
85
|
+
| `Text` | `str` | `None` | Text to write (give `Text` or `File`, not both) |
|
|
86
|
+
| `File` | `str` or `Path` | `None` | A UTF-8 text file to write instead of `Text` |
|
|
87
|
+
| `Paper` | `str` | `"a4"` | Paper to write on |
|
|
88
|
+
| `Font` | `str` | `"caveat"` | Handwriting font (name or number) |
|
|
89
|
+
| `Ink` | `str` | `"blue"` | Ink colour (name or hex) |
|
|
90
|
+
| `KeepLineBreaks` | `bool` | `False` | Start a new line wherever your text has one |
|
|
91
|
+
| `FontSize` | `int` | `None` | Override the font size |
|
|
92
|
+
| `MaxLineLength` | `int` | `None` | Override the number of characters per line |
|
|
93
|
+
| `MarginLeft` | `int` | `None` | Override the left margin (pixels) |
|
|
94
|
+
| `MarginTop` | `int` | `None` | Override the top margin (pixels) |
|
|
95
|
+
| `MarginBottom` | `int` | `None` | Override the space kept free at the bottom of each page (pixels) |
|
|
96
|
+
| `LineSpacing` | `float` | `None` | Override the space between lines (pixels) |
|
|
97
|
+
|
|
98
|
+
The last six are `None` by default, which keeps the layout that is tuned for the chosen paper and font.
|
|
99
|
+
An invalid value raises a `ValueError` as soon as the config is created.
|
|
100
|
+
|
|
101
|
+
By default your text is written as one paragraph, line breaks are treated as spaces.
|
|
102
|
+
Use `KeepLineBreaks=True` to keep headings, lists and paragraphs on their own lines.
|
|
103
|
+
|
|
104
|
+
### Text from a file
|
|
105
|
+
|
|
106
|
+
Pass the path of a UTF-8 text file as `File` instead of `Text`:
|
|
107
|
+
|
|
108
|
+
```python
|
|
109
|
+
from assignmentwriter import Assignment, AssignmentConfigOptions
|
|
110
|
+
|
|
111
|
+
config = AssignmentConfigOptions(File="essay.txt", Paper="lined", Ink="black", KeepLineBreaks=True)
|
|
112
|
+
result = Assignment(config).create()
|
|
113
|
+
result.save("essay.png")
|
|
114
|
+
```
|
|
115
|
+
|
|
116
|
+
A `ValueError` is raised if the file cannot be read, is empty, or if you give both `Text` and `File`.
|
|
117
|
+
|
|
118
|
+
### Get the tuned layout for a paper and font:
|
|
119
|
+
|
|
120
|
+
Returns a dictionary with the default layout values.
|
|
121
|
+
|
|
122
|
+
```python
|
|
123
|
+
from assignmentwriter import Assignment, AssignmentConfigOptions
|
|
124
|
+
|
|
125
|
+
config = AssignmentConfigOptions(Text="Hi", Paper="lined", Font="caveat")
|
|
126
|
+
print(Assignment(config).get_defaults())
|
|
127
|
+
# {'Paper': 'lined', 'Font': 'caveat', 'FontFile': 'caveat.ttf', 'FontSize': 85,
|
|
128
|
+
# 'MaxLineLength': 52, 'MarginLeft': 370, 'MarginTop': 333, 'MarginBottom': 130, 'LineSpacing': 22}
|
|
129
|
+
```
|
|
130
|
+
|
|
131
|
+
## Several pages
|
|
132
|
+
|
|
133
|
+
When your text is too long for one page, it continues on as many pages as it needs, so none of it is lost.
|
|
134
|
+
A line is never split between two pages.
|
|
135
|
+
|
|
136
|
+
```python
|
|
137
|
+
config = AssignmentConfigOptions(File="essay.txt", Paper="spiral")
|
|
138
|
+
result = Assignment(config).create()
|
|
139
|
+
|
|
140
|
+
print(len(result)) # the number of pages
|
|
141
|
+
result.save("essay.png") # essay_1.png, essay_2.png, ...
|
|
142
|
+
result.save_pdf("essay.pdf") # or all the pages in one PDF
|
|
143
|
+
```
|
|
144
|
+
|
|
145
|
+
## `AssignmentResult`
|
|
146
|
+
|
|
147
|
+
`Assignment.create()` returns an `AssignmentResult` object:
|
|
148
|
+
|
|
149
|
+
```python
|
|
150
|
+
result = Assignment(config).create()
|
|
151
|
+
|
|
152
|
+
bool(result) # False if the pages could not be created
|
|
153
|
+
len(result) # the number of pages
|
|
154
|
+
result.image # the first page as a Pillow Image
|
|
155
|
+
result[1] # the second page, `for page in result` goes through all of them
|
|
156
|
+
result.save() # assignment.png, or assignment_1.png, assignment_2.png ... for several pages
|
|
157
|
+
result.save("out.png") # save to a specific path (png, jpg, ...), returns the list of paths
|
|
158
|
+
result.save("pages/") # save in a folder
|
|
159
|
+
result.save_pdf("out.pdf") # all the pages in one PDF (as wide as an A4 sheet), returns the path
|
|
160
|
+
str(result) # the paths of the last save, one per line ("" before saving)
|
|
161
|
+
```
|
|
162
|
+
|
|
163
|
+
Each page is drawn when you ask for it, so a very long text does not keep every page in memory at once.
|
|
164
|
+
|
|
165
|
+
If anything fails, `create()` returns a falsy `AssignmentResult` and logs the error. `save()` and `save_pdf()` return `None` and log the error if a file cannot be written.
|
|
166
|
+
A warning is logged if some lines run past the right edge of the page. Use a smaller `FontSize` / `MaxLineLength`.
|
|
167
|
+
|
|
168
|
+
---
|
|
169
|
+
|
|
170
|
+
# CLI
|
|
171
|
+
|
|
172
|
+
First, install the extra dependency for coloured output (optional, the CLI also works without it):
|
|
173
|
+
|
|
174
|
+
```
|
|
175
|
+
pip install "assignmentwriter[cli]"
|
|
176
|
+
```
|
|
177
|
+
|
|
178
|
+
---
|
|
179
|
+
|
|
180
|
+
## Usage
|
|
181
|
+
|
|
182
|
+
**No arguments** — launches an interactive prompt:
|
|
183
|
+
|
|
184
|
+
```
|
|
185
|
+
assignmentwriter
|
|
186
|
+
```
|
|
187
|
+
|
|
188
|
+
**Quick create** — just pass your text directly (saved as `assignment.png`):
|
|
189
|
+
|
|
190
|
+
```
|
|
191
|
+
assignmentwriter "Hello World"
|
|
192
|
+
```
|
|
193
|
+
|
|
194
|
+
**Pick a paper, font and ink:**
|
|
195
|
+
|
|
196
|
+
```
|
|
197
|
+
assignmentwriter "Hello World" --paper lined --font caveat --ink black
|
|
198
|
+
```
|
|
199
|
+
|
|
200
|
+
**Save the image to a file:**
|
|
201
|
+
|
|
202
|
+
```
|
|
203
|
+
assignmentwriter "Hello World" --save output.png
|
|
204
|
+
```
|
|
205
|
+
|
|
206
|
+
**Write the text of a file** (keep its line breaks):
|
|
207
|
+
|
|
208
|
+
```
|
|
209
|
+
assignmentwriter --file notes.txt --keep-line-breaks
|
|
210
|
+
```
|
|
211
|
+
|
|
212
|
+
**Long text** continues on more pages, saved as `essay_1.png`, `essay_2.png`, ... :
|
|
213
|
+
|
|
214
|
+
```
|
|
215
|
+
assignmentwriter --file essay.txt --paper spiral --save essay.png
|
|
216
|
+
```
|
|
217
|
+
|
|
218
|
+
**Save all the pages as one PDF:**
|
|
219
|
+
|
|
220
|
+
```
|
|
221
|
+
assignmentwriter --file essay.txt --paper spiral --pdf
|
|
222
|
+
```
|
|
223
|
+
|
|
224
|
+
**Plain output** (just the saved paths, no colors — useful for scripting):
|
|
225
|
+
|
|
226
|
+
```
|
|
227
|
+
assignmentwriter "Hello World" --as-text
|
|
228
|
+
```
|
|
229
|
+
|
|
230
|
+
---
|
|
231
|
+
|
|
232
|
+
## List
|
|
233
|
+
|
|
234
|
+
See every paper, font and ink:
|
|
235
|
+
|
|
236
|
+
```
|
|
237
|
+
assignmentwriter list
|
|
238
|
+
```
|
|
239
|
+
|
|
240
|
+
> **Add `--as-text` to get plain line-by-line output instead of a table.**
|
|
241
|
+
|
|
242
|
+
## On Some OS
|
|
243
|
+
|
|
244
|
+
On some operating systems, the CLI may not be available as `assignmentwriter` immediately after installation. If you encounter a "command not found" error, try running it with Python:
|
|
245
|
+
|
|
246
|
+
```
|
|
247
|
+
python -m assignmentwriter "Hello World"
|
|
248
|
+
```
|
|
249
|
+
|
|
250
|
+
---
|
|
251
|
+
|
|
252
|
+
## Fonts and papers
|
|
253
|
+
|
|
254
|
+
The code is MIT licensed, but the fonts and paper images have their own terms.
|
|
255
|
+
|
|
256
|
+
## Coffee is love, coffee is life.
|
|
257
|
+
|
|
258
|
+
https://www.buymeacoffee.com/hritu
|
|
259
|
+
|
|
260
|
+
## Contributing
|
|
261
|
+
|
|
262
|
+
Contributions are welcome — open an issue or submit a pull request.
|
|
263
|
+
|
|
264
|
+
## License
|
|
265
|
+
|
|
266
|
+
MIT © TheHritu
|
|
@@ -0,0 +1,247 @@
|
|
|
1
|
+
# AssignmentWriter
|
|
2
|
+
|
|
3
|
+
A Python package and command line tool that writes your text on a sheet of paper, in a handwriting font and ink colour of your choice. Pick a paper, a font and an ink, and get back an image of the page(s) (in form of pdf too) - all in a few lines of code.
|
|
4
|
+
|
|
5
|
+
[](https://pypi.org/project/assignmentwriter/) [](https://github.com/TheHritu/AssignmentWriter/blob/main/LICENSE)
|
|
6
|
+
|
|
7
|
+
## Installation
|
|
8
|
+
|
|
9
|
+
```
|
|
10
|
+
pip install assignmentwriter -U
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
## Quick Start
|
|
14
|
+
|
|
15
|
+
```python
|
|
16
|
+
from assignmentwriter import Assignment, AssignmentConfigOptions
|
|
17
|
+
|
|
18
|
+
config = AssignmentConfigOptions(Text="Hello World", Paper="lined", Font="caveat", Ink="blue")
|
|
19
|
+
result = Assignment(config).create()
|
|
20
|
+
|
|
21
|
+
result.save("page.png") # saves the image
|
|
22
|
+
print(result) # prints the saved path (if saved)
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
Or write a whole text file, on as many pages as it needs:
|
|
26
|
+
|
|
27
|
+
```python
|
|
28
|
+
config = AssignmentConfigOptions(File="essay.txt", Paper="spiral", Ink="teal")
|
|
29
|
+
result = Assignment(config).create()
|
|
30
|
+
|
|
31
|
+
result.save("essay.png") # essay_1.png, essay_2.png, ...
|
|
32
|
+
result.save_pdf("essay.pdf") # or all the pages in one PDF
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
## Previews
|
|
36
|
+
|
|
37
|
+
See at https://github.com/TheHritu/AssignmentWriter
|
|
38
|
+
|
|
39
|
+
## Papers, fonts and inks
|
|
40
|
+
|
|
41
|
+
| Option | Values |
|
|
42
|
+
|--------|--------|
|
|
43
|
+
| `Paper` | `a4`, `lined`, `rough`, `spiral`, `wrinkled`, `cream`, `cyan`, `lightblue`, `lightgreen`, `lime`, `orange`, `pink` |
|
|
44
|
+
| `Font` | `adinekirnberg`, `alanishand`, `architex`, `caveat`, `greatvibesregular`, `hand_note`, `homemadeapple`, `honeyscript`, `jottflf`, `note_this`, `pleasewritemeasong`, `s_hand` |
|
|
45
|
+
| `Ink` | `blue`, `black`, `red`, `green`, `pencil`, `brown`, `purple`, `orange`, `teal`, `magenta`, or any hex colour such as `"131394"` |
|
|
46
|
+
|
|
47
|
+
A font can also be chosen by its number, 1 to 12, in the order shown above (`Font=4` is `caveat`).
|
|
48
|
+
Names are not case sensitive and spaces, dashes and underscores are ignored (`"Hand Note"` and `"Light Green"` work).
|
|
49
|
+
|
|
50
|
+
```python
|
|
51
|
+
from assignmentwriter import available_fonts, available_papers, INKS
|
|
52
|
+
|
|
53
|
+
print(available_papers()) # ['a4', 'lined', 'rough', 'spiral', 'wrinkled', 'cream', 'cyan', 'lightblue', 'lightgreen', 'lime', 'orange', 'pink']
|
|
54
|
+
print(available_fonts()) # ['adinekirnberg', 'alanishand', 'architex', 'caveat', 'greatvibesregular', 'hand_note', 'homemadeapple', 'honeyscript', 'jottflf', 'note_this', 'pleasewritemeasong', 's_hand']
|
|
55
|
+
print(list(INKS)) # ['blue', 'black', 'red', 'green', 'pencil', 'brown', 'purple', 'orange', 'teal', 'magenta']
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
> **Note:** `alanishand` draws the digits `2` and `5` very wide, so lines with those numbers can run off the page. Use another font for text with numbers.
|
|
59
|
+
|
|
60
|
+
## Configuration
|
|
61
|
+
|
|
62
|
+
`AssignmentConfigOptions` accepts these fields:
|
|
63
|
+
|
|
64
|
+
| Field | Type | Default | Description |
|
|
65
|
+
|-------|------|---------|-------------|
|
|
66
|
+
| `Text` | `str` | `None` | Text to write (give `Text` or `File`, not both) |
|
|
67
|
+
| `File` | `str` or `Path` | `None` | A UTF-8 text file to write instead of `Text` |
|
|
68
|
+
| `Paper` | `str` | `"a4"` | Paper to write on |
|
|
69
|
+
| `Font` | `str` | `"caveat"` | Handwriting font (name or number) |
|
|
70
|
+
| `Ink` | `str` | `"blue"` | Ink colour (name or hex) |
|
|
71
|
+
| `KeepLineBreaks` | `bool` | `False` | Start a new line wherever your text has one |
|
|
72
|
+
| `FontSize` | `int` | `None` | Override the font size |
|
|
73
|
+
| `MaxLineLength` | `int` | `None` | Override the number of characters per line |
|
|
74
|
+
| `MarginLeft` | `int` | `None` | Override the left margin (pixels) |
|
|
75
|
+
| `MarginTop` | `int` | `None` | Override the top margin (pixels) |
|
|
76
|
+
| `MarginBottom` | `int` | `None` | Override the space kept free at the bottom of each page (pixels) |
|
|
77
|
+
| `LineSpacing` | `float` | `None` | Override the space between lines (pixels) |
|
|
78
|
+
|
|
79
|
+
The last six are `None` by default, which keeps the layout that is tuned for the chosen paper and font.
|
|
80
|
+
An invalid value raises a `ValueError` as soon as the config is created.
|
|
81
|
+
|
|
82
|
+
By default your text is written as one paragraph, line breaks are treated as spaces.
|
|
83
|
+
Use `KeepLineBreaks=True` to keep headings, lists and paragraphs on their own lines.
|
|
84
|
+
|
|
85
|
+
### Text from a file
|
|
86
|
+
|
|
87
|
+
Pass the path of a UTF-8 text file as `File` instead of `Text`:
|
|
88
|
+
|
|
89
|
+
```python
|
|
90
|
+
from assignmentwriter import Assignment, AssignmentConfigOptions
|
|
91
|
+
|
|
92
|
+
config = AssignmentConfigOptions(File="essay.txt", Paper="lined", Ink="black", KeepLineBreaks=True)
|
|
93
|
+
result = Assignment(config).create()
|
|
94
|
+
result.save("essay.png")
|
|
95
|
+
```
|
|
96
|
+
|
|
97
|
+
A `ValueError` is raised if the file cannot be read, is empty, or if you give both `Text` and `File`.
|
|
98
|
+
|
|
99
|
+
### Get the tuned layout for a paper and font:
|
|
100
|
+
|
|
101
|
+
Returns a dictionary with the default layout values.
|
|
102
|
+
|
|
103
|
+
```python
|
|
104
|
+
from assignmentwriter import Assignment, AssignmentConfigOptions
|
|
105
|
+
|
|
106
|
+
config = AssignmentConfigOptions(Text="Hi", Paper="lined", Font="caveat")
|
|
107
|
+
print(Assignment(config).get_defaults())
|
|
108
|
+
# {'Paper': 'lined', 'Font': 'caveat', 'FontFile': 'caveat.ttf', 'FontSize': 85,
|
|
109
|
+
# 'MaxLineLength': 52, 'MarginLeft': 370, 'MarginTop': 333, 'MarginBottom': 130, 'LineSpacing': 22}
|
|
110
|
+
```
|
|
111
|
+
|
|
112
|
+
## Several pages
|
|
113
|
+
|
|
114
|
+
When your text is too long for one page, it continues on as many pages as it needs, so none of it is lost.
|
|
115
|
+
A line is never split between two pages.
|
|
116
|
+
|
|
117
|
+
```python
|
|
118
|
+
config = AssignmentConfigOptions(File="essay.txt", Paper="spiral")
|
|
119
|
+
result = Assignment(config).create()
|
|
120
|
+
|
|
121
|
+
print(len(result)) # the number of pages
|
|
122
|
+
result.save("essay.png") # essay_1.png, essay_2.png, ...
|
|
123
|
+
result.save_pdf("essay.pdf") # or all the pages in one PDF
|
|
124
|
+
```
|
|
125
|
+
|
|
126
|
+
## `AssignmentResult`
|
|
127
|
+
|
|
128
|
+
`Assignment.create()` returns an `AssignmentResult` object:
|
|
129
|
+
|
|
130
|
+
```python
|
|
131
|
+
result = Assignment(config).create()
|
|
132
|
+
|
|
133
|
+
bool(result) # False if the pages could not be created
|
|
134
|
+
len(result) # the number of pages
|
|
135
|
+
result.image # the first page as a Pillow Image
|
|
136
|
+
result[1] # the second page, `for page in result` goes through all of them
|
|
137
|
+
result.save() # assignment.png, or assignment_1.png, assignment_2.png ... for several pages
|
|
138
|
+
result.save("out.png") # save to a specific path (png, jpg, ...), returns the list of paths
|
|
139
|
+
result.save("pages/") # save in a folder
|
|
140
|
+
result.save_pdf("out.pdf") # all the pages in one PDF (as wide as an A4 sheet), returns the path
|
|
141
|
+
str(result) # the paths of the last save, one per line ("" before saving)
|
|
142
|
+
```
|
|
143
|
+
|
|
144
|
+
Each page is drawn when you ask for it, so a very long text does not keep every page in memory at once.
|
|
145
|
+
|
|
146
|
+
If anything fails, `create()` returns a falsy `AssignmentResult` and logs the error. `save()` and `save_pdf()` return `None` and log the error if a file cannot be written.
|
|
147
|
+
A warning is logged if some lines run past the right edge of the page. Use a smaller `FontSize` / `MaxLineLength`.
|
|
148
|
+
|
|
149
|
+
---
|
|
150
|
+
|
|
151
|
+
# CLI
|
|
152
|
+
|
|
153
|
+
First, install the extra dependency for coloured output (optional, the CLI also works without it):
|
|
154
|
+
|
|
155
|
+
```
|
|
156
|
+
pip install "assignmentwriter[cli]"
|
|
157
|
+
```
|
|
158
|
+
|
|
159
|
+
---
|
|
160
|
+
|
|
161
|
+
## Usage
|
|
162
|
+
|
|
163
|
+
**No arguments** — launches an interactive prompt:
|
|
164
|
+
|
|
165
|
+
```
|
|
166
|
+
assignmentwriter
|
|
167
|
+
```
|
|
168
|
+
|
|
169
|
+
**Quick create** — just pass your text directly (saved as `assignment.png`):
|
|
170
|
+
|
|
171
|
+
```
|
|
172
|
+
assignmentwriter "Hello World"
|
|
173
|
+
```
|
|
174
|
+
|
|
175
|
+
**Pick a paper, font and ink:**
|
|
176
|
+
|
|
177
|
+
```
|
|
178
|
+
assignmentwriter "Hello World" --paper lined --font caveat --ink black
|
|
179
|
+
```
|
|
180
|
+
|
|
181
|
+
**Save the image to a file:**
|
|
182
|
+
|
|
183
|
+
```
|
|
184
|
+
assignmentwriter "Hello World" --save output.png
|
|
185
|
+
```
|
|
186
|
+
|
|
187
|
+
**Write the text of a file** (keep its line breaks):
|
|
188
|
+
|
|
189
|
+
```
|
|
190
|
+
assignmentwriter --file notes.txt --keep-line-breaks
|
|
191
|
+
```
|
|
192
|
+
|
|
193
|
+
**Long text** continues on more pages, saved as `essay_1.png`, `essay_2.png`, ... :
|
|
194
|
+
|
|
195
|
+
```
|
|
196
|
+
assignmentwriter --file essay.txt --paper spiral --save essay.png
|
|
197
|
+
```
|
|
198
|
+
|
|
199
|
+
**Save all the pages as one PDF:**
|
|
200
|
+
|
|
201
|
+
```
|
|
202
|
+
assignmentwriter --file essay.txt --paper spiral --pdf
|
|
203
|
+
```
|
|
204
|
+
|
|
205
|
+
**Plain output** (just the saved paths, no colors — useful for scripting):
|
|
206
|
+
|
|
207
|
+
```
|
|
208
|
+
assignmentwriter "Hello World" --as-text
|
|
209
|
+
```
|
|
210
|
+
|
|
211
|
+
---
|
|
212
|
+
|
|
213
|
+
## List
|
|
214
|
+
|
|
215
|
+
See every paper, font and ink:
|
|
216
|
+
|
|
217
|
+
```
|
|
218
|
+
assignmentwriter list
|
|
219
|
+
```
|
|
220
|
+
|
|
221
|
+
> **Add `--as-text` to get plain line-by-line output instead of a table.**
|
|
222
|
+
|
|
223
|
+
## On Some OS
|
|
224
|
+
|
|
225
|
+
On some operating systems, the CLI may not be available as `assignmentwriter` immediately after installation. If you encounter a "command not found" error, try running it with Python:
|
|
226
|
+
|
|
227
|
+
```
|
|
228
|
+
python -m assignmentwriter "Hello World"
|
|
229
|
+
```
|
|
230
|
+
|
|
231
|
+
---
|
|
232
|
+
|
|
233
|
+
## Fonts and papers
|
|
234
|
+
|
|
235
|
+
The code is MIT licensed, but the fonts and paper images have their own terms.
|
|
236
|
+
|
|
237
|
+
## Coffee is love, coffee is life.
|
|
238
|
+
|
|
239
|
+
https://www.buymeacoffee.com/hritu
|
|
240
|
+
|
|
241
|
+
## Contributing
|
|
242
|
+
|
|
243
|
+
Contributions are welcome — open an issue or submit a pull request.
|
|
244
|
+
|
|
245
|
+
## License
|
|
246
|
+
|
|
247
|
+
MIT © TheHritu
|