imfeel 0.1.0__py3-none-any.whl
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.
- imfeel/__init__.py +258 -0
- imfeel/assets/fonts/Inconsolata-Bold.ttf +0 -0
- imfeel/assets/fonts/OFL.txt +93 -0
- imfeel/demo/__init__.py +22 -0
- imfeel/demo/__main__.py +7 -0
- imfeel/demo/app.py +212 -0
- imfeel/demo/controls.py +340 -0
- imfeel/demo/docs.py +96 -0
- imfeel/demo/imscribe_docs.py +261 -0
- imfeel/demo/imscribe_features.py +679 -0
- imfeel/demo/pages.py +392 -0
- imfeel/demo/scrolling.py +307 -0
- imfeel/demo/state.py +253 -0
- imfeel/demo/text.py +130 -0
- imfeel/demo/theming.py +316 -0
- imfeel/demo/values_page.py +315 -0
- imfeel/extras.py +401 -0
- imfeel/fonts.py +741 -0
- imfeel/listview.py +399 -0
- imfeel/palette.py +830 -0
- imfeel/py.typed +0 -0
- imfeel/scroll.py +522 -0
- imfeel/shortcuts.py +152 -0
- imfeel/theme.py +382 -0
- imfeel/values.py +415 -0
- imfeel/widgets.py +647 -0
- imfeel-0.1.0.dist-info/METADATA +96 -0
- imfeel-0.1.0.dist-info/RECORD +30 -0
- imfeel-0.1.0.dist-info/WHEEL +4 -0
- imfeel-0.1.0.dist-info/licenses/LICENSE +21 -0
imfeel/__init__.py
ADDED
|
@@ -0,0 +1,258 @@
|
|
|
1
|
+
"""imfeel: a consistent look and feel for Dear ImGui apps.
|
|
2
|
+
|
|
3
|
+
A small library of conventions, not a framework: plain functions and begin/end
|
|
4
|
+
context managers that always call ImGui the same way. The public API is filled
|
|
5
|
+
in by the component modules as they land; exports here are additive.
|
|
6
|
+
|
|
7
|
+
Theme and palette: `Palette`, `THEMES`, `apply_style`, `use_palette`,
|
|
8
|
+
`current_palette`. Fonts and sizes: `em`, `load_fonts`, `DEFAULT_RENDERING`.
|
|
9
|
+
Round two: `scroll_window`, the value controls (`slider_float`, `combo`, `key_step`, ...),
|
|
10
|
+
formulas on by default (`read_markdown`, `FORMULA_SCALE`), and the audited row colours
|
|
11
|
+
(`header_colours`, `combo_contrasts`). Constants that are tuning values of one module
|
|
12
|
+
(a floor, a row's height in ems) stay in it: `imfeel.palette.LINK_FLOOR`.
|
|
13
|
+
"""
|
|
14
|
+
|
|
15
|
+
from __future__ import annotations
|
|
16
|
+
|
|
17
|
+
from .extras import (
|
|
18
|
+
CTRL_ENTER_SUBMITS,
|
|
19
|
+
Help,
|
|
20
|
+
Notice,
|
|
21
|
+
Revert,
|
|
22
|
+
Tone,
|
|
23
|
+
begin_context_menu,
|
|
24
|
+
ellipsis,
|
|
25
|
+
flat_line,
|
|
26
|
+
hint_colour,
|
|
27
|
+
multiline_input,
|
|
28
|
+
notice,
|
|
29
|
+
path_tail,
|
|
30
|
+
wants_send,
|
|
31
|
+
)
|
|
32
|
+
from .fonts import (
|
|
33
|
+
BASE_FONT_PX,
|
|
34
|
+
DEFAULT_RENDERING,
|
|
35
|
+
FORMULA_AIR,
|
|
36
|
+
FORMULA_AIR_PER_SCALE,
|
|
37
|
+
FORMULA_LINES,
|
|
38
|
+
FORMULA_SCALE,
|
|
39
|
+
FORMULA_SCALE_STEPS,
|
|
40
|
+
UI_FONT_PX,
|
|
41
|
+
Fonts,
|
|
42
|
+
RenderingConfig,
|
|
43
|
+
Role,
|
|
44
|
+
RoleStyle,
|
|
45
|
+
Slot,
|
|
46
|
+
em,
|
|
47
|
+
formula_scale,
|
|
48
|
+
imscribe_palette,
|
|
49
|
+
imscribe_theme,
|
|
50
|
+
load_fonts,
|
|
51
|
+
load_typeset_fonts,
|
|
52
|
+
load_ui_fonts,
|
|
53
|
+
math_fences_as_display,
|
|
54
|
+
math_ready,
|
|
55
|
+
read_markdown,
|
|
56
|
+
role_pitch,
|
|
57
|
+
role_px,
|
|
58
|
+
)
|
|
59
|
+
from .listview import Selection, list_view
|
|
60
|
+
from .palette import (
|
|
61
|
+
APART_FLOOR,
|
|
62
|
+
BAR_FLOOR,
|
|
63
|
+
BAR_ON_FILL_FLOOR,
|
|
64
|
+
COLOUR_ROLES,
|
|
65
|
+
DEFAULT_PALETTE,
|
|
66
|
+
DEFAULT_THEME,
|
|
67
|
+
FRAME_FLOOR,
|
|
68
|
+
HOVERED_FLOOR,
|
|
69
|
+
RGBA,
|
|
70
|
+
SELECTED_FLOOR,
|
|
71
|
+
TEXT_FLOOR,
|
|
72
|
+
THEMES,
|
|
73
|
+
ButtonColours,
|
|
74
|
+
HeaderColours,
|
|
75
|
+
LinkInks,
|
|
76
|
+
Palette,
|
|
77
|
+
WellColours,
|
|
78
|
+
button_colours,
|
|
79
|
+
composite,
|
|
80
|
+
contrast_ratio,
|
|
81
|
+
get_theme,
|
|
82
|
+
header_colours,
|
|
83
|
+
header_surfaces,
|
|
84
|
+
link_inks,
|
|
85
|
+
mix,
|
|
86
|
+
rgb,
|
|
87
|
+
rgba8,
|
|
88
|
+
scrollbar_alphas,
|
|
89
|
+
to_imvec4,
|
|
90
|
+
to_u32,
|
|
91
|
+
well_colours,
|
|
92
|
+
with_alpha,
|
|
93
|
+
)
|
|
94
|
+
from .scroll import (
|
|
95
|
+
SCROLL_WINDOW_FLAGS,
|
|
96
|
+
ScrollArea,
|
|
97
|
+
edge_scroll,
|
|
98
|
+
follow_tail,
|
|
99
|
+
scroll_area,
|
|
100
|
+
scroll_window,
|
|
101
|
+
wheels_here,
|
|
102
|
+
)
|
|
103
|
+
from .shortcuts import Scope, copy_shortcut, escape_closes, shortcut
|
|
104
|
+
from .theme import (
|
|
105
|
+
METRICS,
|
|
106
|
+
Contrast,
|
|
107
|
+
StyleMetrics,
|
|
108
|
+
apply_style,
|
|
109
|
+
combo_contrasts,
|
|
110
|
+
current_palette,
|
|
111
|
+
resolve_palette,
|
|
112
|
+
style_colours,
|
|
113
|
+
use_palette,
|
|
114
|
+
)
|
|
115
|
+
from .values import (
|
|
116
|
+
COARSE,
|
|
117
|
+
FINE,
|
|
118
|
+
SLIDER_STEPS,
|
|
119
|
+
Axis,
|
|
120
|
+
combo,
|
|
121
|
+
drag_float,
|
|
122
|
+
drag_int,
|
|
123
|
+
key_step,
|
|
124
|
+
slider_float,
|
|
125
|
+
slider_int,
|
|
126
|
+
vslider_float,
|
|
127
|
+
vslider_int,
|
|
128
|
+
)
|
|
129
|
+
from .widgets import (
|
|
130
|
+
button,
|
|
131
|
+
dialog_style,
|
|
132
|
+
help_mark,
|
|
133
|
+
link,
|
|
134
|
+
safe_button,
|
|
135
|
+
section,
|
|
136
|
+
small_button,
|
|
137
|
+
small_button_line,
|
|
138
|
+
small_button_width,
|
|
139
|
+
)
|
|
140
|
+
|
|
141
|
+
__version__ = "0.1.0"
|
|
142
|
+
|
|
143
|
+
__all__ = [
|
|
144
|
+
"CTRL_ENTER_SUBMITS",
|
|
145
|
+
"Help",
|
|
146
|
+
"Notice",
|
|
147
|
+
"Revert",
|
|
148
|
+
"Tone",
|
|
149
|
+
"begin_context_menu",
|
|
150
|
+
"ellipsis",
|
|
151
|
+
"flat_line",
|
|
152
|
+
"hint_colour",
|
|
153
|
+
"multiline_input",
|
|
154
|
+
"notice",
|
|
155
|
+
"path_tail",
|
|
156
|
+
"wants_send",
|
|
157
|
+
"Selection",
|
|
158
|
+
"list_view",
|
|
159
|
+
"ScrollArea",
|
|
160
|
+
"edge_scroll",
|
|
161
|
+
"follow_tail",
|
|
162
|
+
"SCROLL_WINDOW_FLAGS",
|
|
163
|
+
"scroll_area",
|
|
164
|
+
"scroll_window",
|
|
165
|
+
"wheels_here",
|
|
166
|
+
"COARSE",
|
|
167
|
+
"FINE",
|
|
168
|
+
"SLIDER_STEPS",
|
|
169
|
+
"Axis",
|
|
170
|
+
"combo",
|
|
171
|
+
"drag_float",
|
|
172
|
+
"drag_int",
|
|
173
|
+
"key_step",
|
|
174
|
+
"slider_float",
|
|
175
|
+
"slider_int",
|
|
176
|
+
"vslider_float",
|
|
177
|
+
"vslider_int",
|
|
178
|
+
"Scope",
|
|
179
|
+
"copy_shortcut",
|
|
180
|
+
"escape_closes",
|
|
181
|
+
"shortcut",
|
|
182
|
+
"button",
|
|
183
|
+
"dialog_style",
|
|
184
|
+
"help_mark",
|
|
185
|
+
"link",
|
|
186
|
+
"safe_button",
|
|
187
|
+
"section",
|
|
188
|
+
"small_button",
|
|
189
|
+
"small_button_line",
|
|
190
|
+
"small_button_width",
|
|
191
|
+
"APART_FLOOR",
|
|
192
|
+
"BAR_FLOOR",
|
|
193
|
+
"BAR_ON_FILL_FLOOR",
|
|
194
|
+
"BASE_FONT_PX",
|
|
195
|
+
"COLOUR_ROLES",
|
|
196
|
+
"DEFAULT_PALETTE",
|
|
197
|
+
"DEFAULT_RENDERING",
|
|
198
|
+
"DEFAULT_THEME",
|
|
199
|
+
"FORMULA_AIR",
|
|
200
|
+
"FORMULA_AIR_PER_SCALE",
|
|
201
|
+
"FORMULA_LINES",
|
|
202
|
+
"FORMULA_SCALE",
|
|
203
|
+
"FORMULA_SCALE_STEPS",
|
|
204
|
+
"FRAME_FLOOR",
|
|
205
|
+
"HOVERED_FLOOR",
|
|
206
|
+
"METRICS",
|
|
207
|
+
"RGBA",
|
|
208
|
+
"SELECTED_FLOOR",
|
|
209
|
+
"TEXT_FLOOR",
|
|
210
|
+
"THEMES",
|
|
211
|
+
"UI_FONT_PX",
|
|
212
|
+
"ButtonColours",
|
|
213
|
+
"Contrast",
|
|
214
|
+
"Fonts",
|
|
215
|
+
"HeaderColours",
|
|
216
|
+
"LinkInks",
|
|
217
|
+
"Palette",
|
|
218
|
+
"RenderingConfig",
|
|
219
|
+
"Role",
|
|
220
|
+
"RoleStyle",
|
|
221
|
+
"Slot",
|
|
222
|
+
"StyleMetrics",
|
|
223
|
+
"WellColours",
|
|
224
|
+
"__version__",
|
|
225
|
+
"apply_style",
|
|
226
|
+
"button_colours",
|
|
227
|
+
"combo_contrasts",
|
|
228
|
+
"composite",
|
|
229
|
+
"contrast_ratio",
|
|
230
|
+
"current_palette",
|
|
231
|
+
"em",
|
|
232
|
+
"formula_scale",
|
|
233
|
+
"get_theme",
|
|
234
|
+
"header_colours",
|
|
235
|
+
"header_surfaces",
|
|
236
|
+
"imscribe_palette",
|
|
237
|
+
"imscribe_theme",
|
|
238
|
+
"link_inks",
|
|
239
|
+
"load_fonts",
|
|
240
|
+
"load_typeset_fonts",
|
|
241
|
+
"load_ui_fonts",
|
|
242
|
+
"math_fences_as_display",
|
|
243
|
+
"math_ready",
|
|
244
|
+
"mix",
|
|
245
|
+
"read_markdown",
|
|
246
|
+
"resolve_palette",
|
|
247
|
+
"rgb",
|
|
248
|
+
"rgba8",
|
|
249
|
+
"role_pitch",
|
|
250
|
+
"role_px",
|
|
251
|
+
"scrollbar_alphas",
|
|
252
|
+
"style_colours",
|
|
253
|
+
"to_imvec4",
|
|
254
|
+
"to_u32",
|
|
255
|
+
"use_palette",
|
|
256
|
+
"well_colours",
|
|
257
|
+
"with_alpha",
|
|
258
|
+
]
|
|
Binary file
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
Copyright 2006 The Inconsolata Project Authors (https://github.com/cyrealtype/Inconsolata)
|
|
2
|
+
|
|
3
|
+
This Font Software is licensed under the SIL Open Font License, Version 1.1.
|
|
4
|
+
This license is copied below, and is also available with a FAQ at:
|
|
5
|
+
http://scripts.sil.org/OFL
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
-----------------------------------------------------------
|
|
9
|
+
SIL OPEN FONT LICENSE Version 1.1 - 26 February 2007
|
|
10
|
+
-----------------------------------------------------------
|
|
11
|
+
|
|
12
|
+
PREAMBLE
|
|
13
|
+
The goals of the Open Font License (OFL) are to stimulate worldwide
|
|
14
|
+
development of collaborative font projects, to support the font creation
|
|
15
|
+
efforts of academic and linguistic communities, and to provide a free and
|
|
16
|
+
open framework in which fonts may be shared and improved in partnership
|
|
17
|
+
with others.
|
|
18
|
+
|
|
19
|
+
The OFL allows the licensed fonts to be used, studied, modified and
|
|
20
|
+
redistributed freely as long as they are not sold by themselves. The
|
|
21
|
+
fonts, including any derivative works, can be bundled, embedded,
|
|
22
|
+
redistributed and/or sold with any software provided that any reserved
|
|
23
|
+
names are not used by derivative works. The fonts and derivatives,
|
|
24
|
+
however, cannot be released under any other type of license. The
|
|
25
|
+
requirement for fonts to remain under this license does not apply
|
|
26
|
+
to any document created using the fonts or their derivatives.
|
|
27
|
+
|
|
28
|
+
DEFINITIONS
|
|
29
|
+
"Font Software" refers to the set of files released by the Copyright
|
|
30
|
+
Holder(s) under this license and clearly marked as such. This may
|
|
31
|
+
include source files, build scripts and documentation.
|
|
32
|
+
|
|
33
|
+
"Reserved Font Name" refers to any names specified as such after the
|
|
34
|
+
copyright statement(s).
|
|
35
|
+
|
|
36
|
+
"Original Version" refers to the collection of Font Software components as
|
|
37
|
+
distributed by the Copyright Holder(s).
|
|
38
|
+
|
|
39
|
+
"Modified Version" refers to any derivative made by adding to, deleting,
|
|
40
|
+
or substituting -- in part or in whole -- any of the components of the
|
|
41
|
+
Original Version, by changing formats or by porting the Font Software to a
|
|
42
|
+
new environment.
|
|
43
|
+
|
|
44
|
+
"Author" refers to any designer, engineer, programmer, technical
|
|
45
|
+
writer or other person who contributed to the Font Software.
|
|
46
|
+
|
|
47
|
+
PERMISSION & CONDITIONS
|
|
48
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
|
49
|
+
a copy of the Font Software, to use, study, copy, merge, embed, modify,
|
|
50
|
+
redistribute, and sell modified and unmodified copies of the Font
|
|
51
|
+
Software, subject to the following conditions:
|
|
52
|
+
|
|
53
|
+
1) Neither the Font Software nor any of its individual components,
|
|
54
|
+
in Original or Modified Versions, may be sold by itself.
|
|
55
|
+
|
|
56
|
+
2) Original or Modified Versions of the Font Software may be bundled,
|
|
57
|
+
redistributed and/or sold with any software, provided that each copy
|
|
58
|
+
contains the above copyright notice and this license. These can be
|
|
59
|
+
included either as stand-alone text files, human-readable headers or
|
|
60
|
+
in the appropriate machine-readable metadata fields within text or
|
|
61
|
+
binary files as long as those fields can be easily viewed by the user.
|
|
62
|
+
|
|
63
|
+
3) No Modified Version of the Font Software may use the Reserved Font
|
|
64
|
+
Name(s) unless explicit written permission is granted by the corresponding
|
|
65
|
+
Copyright Holder. This restriction only applies to the primary font name as
|
|
66
|
+
presented to the users.
|
|
67
|
+
|
|
68
|
+
4) The name(s) of the Copyright Holder(s) or the Author(s) of the Font
|
|
69
|
+
Software shall not be used to promote, endorse or advertise any
|
|
70
|
+
Modified Version, except to acknowledge the contribution(s) of the
|
|
71
|
+
Copyright Holder(s) and the Author(s) or with their explicit written
|
|
72
|
+
permission.
|
|
73
|
+
|
|
74
|
+
5) The Font Software, modified or unmodified, in part or in whole,
|
|
75
|
+
must be distributed entirely under this license, and must not be
|
|
76
|
+
distributed under any other license. The requirement for fonts to
|
|
77
|
+
remain under this license does not apply to any document created
|
|
78
|
+
using the Font Software.
|
|
79
|
+
|
|
80
|
+
TERMINATION
|
|
81
|
+
This license becomes null and void if any of the above conditions are
|
|
82
|
+
not met.
|
|
83
|
+
|
|
84
|
+
DISCLAIMER
|
|
85
|
+
THE FONT SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
|
86
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO ANY WARRANTIES OF
|
|
87
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT
|
|
88
|
+
OF COPYRIGHT, PATENT, TRADEMARK, OR OTHER RIGHT. IN NO EVENT SHALL THE
|
|
89
|
+
COPYRIGHT HOLDER BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
|
|
90
|
+
INCLUDING ANY GENERAL, SPECIAL, INDIRECT, INCIDENTAL, OR CONSEQUENTIAL
|
|
91
|
+
DAMAGES, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
|
92
|
+
FROM, OUT OF THE USE OR INABILITY TO USE THE FONT SOFTWARE OR FROM
|
|
93
|
+
OTHER DEALINGS IN THE FONT SOFTWARE.
|
imfeel/demo/__init__.py
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
"""The imfeel demo: one window per component family, every default shown and labelled.
|
|
2
|
+
|
|
3
|
+
Run it with `python -m imfeel.demo` (`make demo`); `--screenshot PATH` renders and exits
|
|
4
|
+
(`make shot`). The pages are in `imfeel.demo.pages`; the demo is the specification.
|
|
5
|
+
"""
|
|
6
|
+
|
|
7
|
+
from __future__ import annotations
|
|
8
|
+
|
|
9
|
+
from .app import build_runner, main
|
|
10
|
+
from .pages import PAGES, PAGES_BY_KEY, Page, all_declared
|
|
11
|
+
from .state import AppState, Demo
|
|
12
|
+
|
|
13
|
+
__all__ = [
|
|
14
|
+
"PAGES",
|
|
15
|
+
"PAGES_BY_KEY",
|
|
16
|
+
"AppState",
|
|
17
|
+
"Demo",
|
|
18
|
+
"Page",
|
|
19
|
+
"all_declared",
|
|
20
|
+
"build_runner",
|
|
21
|
+
"main",
|
|
22
|
+
]
|
imfeel/demo/__main__.py
ADDED
imfeel/demo/app.py
ADDED
|
@@ -0,0 +1,212 @@
|
|
|
1
|
+
"""
|
|
2
|
+
The demo app: hello_imgui windows over `pages.PAGES`, and its screenshot mode.
|
|
3
|
+
|
|
4
|
+
`python -m imfeel.demo` opens one dockable window per component family. `--screenshot PATH`
|
|
5
|
+
runs the same app for N frames, grabs the framebuffer and exits, so it can be looked at without
|
|
6
|
+
a person: `--window NAME` shows one window full-size, `--theme NAME` starts in a palette,
|
|
7
|
+
`--list` prints the window names.
|
|
8
|
+
|
|
9
|
+
**The grab is numpy-free.** `hello_imgui.final_app_window_screenshot` returns a numpy array and
|
|
10
|
+
raises a nanobind `TypeError` without numpy, which this project's venv does not have (nothing
|
|
11
|
+
can be installed offline). The frame is read instead with `glReadPixels` from the back buffer in
|
|
12
|
+
`before_swap`, the one moment its contents are specified (after the swap they are not), through
|
|
13
|
+
PyOpenGL, and written as a PNG by hand with zlib. Both are how pptmstr's own screenshot works.
|
|
14
|
+
"""
|
|
15
|
+
|
|
16
|
+
from __future__ import annotations
|
|
17
|
+
|
|
18
|
+
import argparse
|
|
19
|
+
import struct
|
|
20
|
+
import sys
|
|
21
|
+
import zlib
|
|
22
|
+
from collections.abc import Callable, Sequence
|
|
23
|
+
from pathlib import Path
|
|
24
|
+
|
|
25
|
+
from imgui_bundle import hello_imgui, imgui
|
|
26
|
+
|
|
27
|
+
from .. import fonts
|
|
28
|
+
from ..palette import DEFAULT_THEME, THEMES, to_imvec4
|
|
29
|
+
from ..scroll import SCROLL_WINDOW_FLAGS, scroll_window
|
|
30
|
+
from ..theme import apply_style, use_palette
|
|
31
|
+
from .pages import PAGES, Page
|
|
32
|
+
from .scrolling import remember_window_scroll
|
|
33
|
+
from .state import AppState, Demo
|
|
34
|
+
|
|
35
|
+
DEFAULT_SIZE = (1400, 1000)
|
|
36
|
+
DEFAULT_FRAMES = 90
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
def write_png(path: Path, width: int, height: int, rgb_rows: Sequence[bytes]) -> None:
|
|
40
|
+
"""A minimal truecolour 8-bit PNG, filter type 0 on every row (no Pillow, no numpy)."""
|
|
41
|
+
raw = b"".join(b"\x00" + row for row in rgb_rows)
|
|
42
|
+
|
|
43
|
+
def chunk(tag: bytes, data: bytes) -> bytes:
|
|
44
|
+
crc = zlib.crc32(tag + data) & 0xFFFFFFFF
|
|
45
|
+
return struct.pack(">I", len(data)) + tag + data + struct.pack(">I", crc)
|
|
46
|
+
|
|
47
|
+
header = struct.pack(">IIBBBBB", width, height, 8, 2, 0, 0, 0)
|
|
48
|
+
path.parent.mkdir(parents=True, exist_ok=True)
|
|
49
|
+
path.write_bytes(
|
|
50
|
+
b"\x89PNG\r\n\x1a\n"
|
|
51
|
+
+ chunk(b"IHDR", header)
|
|
52
|
+
+ chunk(b"IDAT", zlib.compress(raw, 6))
|
|
53
|
+
+ chunk(b"IEND", b"")
|
|
54
|
+
)
|
|
55
|
+
|
|
56
|
+
|
|
57
|
+
def grab(path: Path) -> None:
|
|
58
|
+
"""Read the back buffer and write it as `path`. Call from `before_swap` only."""
|
|
59
|
+
from OpenGL import GL # PyOpenGL: not numpy, and already in the venv
|
|
60
|
+
|
|
61
|
+
io = imgui.get_io()
|
|
62
|
+
width = int(io.display_size.x * io.display_framebuffer_scale.x)
|
|
63
|
+
height = int(io.display_size.y * io.display_framebuffer_scale.y)
|
|
64
|
+
GL.glPixelStorei(GL.GL_PACK_ALIGNMENT, 1)
|
|
65
|
+
GL.glReadBuffer(GL.GL_BACK)
|
|
66
|
+
data = GL.glReadPixels(0, 0, width, height, GL.GL_RGB, GL.GL_UNSIGNED_BYTE)
|
|
67
|
+
if not isinstance(data, bytes):
|
|
68
|
+
data = bytes(data)
|
|
69
|
+
stride = width * 3
|
|
70
|
+
# OpenGL's origin is bottom-left and a PNG's top-left: reverse the rows.
|
|
71
|
+
rows = [data[y * stride : (y + 1) * stride] for y in range(height - 1, -1, -1)]
|
|
72
|
+
write_png(path, width, height, rows)
|
|
73
|
+
print(f"wrote {path} ({width}x{height})", flush=True)
|
|
74
|
+
|
|
75
|
+
|
|
76
|
+
def draw_page(app: AppState, page: Page) -> None:
|
|
77
|
+
"""
|
|
78
|
+
One window's content, with the demo's palette set as the one in force, then `scroll_window()`.
|
|
79
|
+
|
|
80
|
+
**The one place every page window gets its keys.** A page is a plain dockable window that Dear
|
|
81
|
+
ImGui does not scroll from the keyboard (keyboard navigation is off on purpose), so Up/Down,
|
|
82
|
+
PageUp/PageDown and Home/End, drag past the edge, all come from `scroll_window()`, called once
|
|
83
|
+
at the end of the body (after a nested `scroll_area`, which keeps its keys while the pointer
|
|
84
|
+
is over it and it can scroll). `build_runner` passes `SCROLL_WINDOW_FLAGS` for the always-
|
|
85
|
+
shown bar. A page does not call it itself: `tests/test_demo.py` fails if a window is drawn
|
|
86
|
+
without it.
|
|
87
|
+
"""
|
|
88
|
+
with use_palette(app.palette):
|
|
89
|
+
page.draw(Demo(app, page.key))
|
|
90
|
+
remember_window_scroll(app, page.key, scroll_window())
|
|
91
|
+
|
|
92
|
+
|
|
93
|
+
def build_runner(
|
|
94
|
+
app: AppState,
|
|
95
|
+
*,
|
|
96
|
+
size: tuple[int, int] = DEFAULT_SIZE,
|
|
97
|
+
window: str | None = None,
|
|
98
|
+
) -> hello_imgui.RunnerParams:
|
|
99
|
+
"""The runner params: fonts, the dockable windows (one per page), and the style hook."""
|
|
100
|
+
runner = hello_imgui.RunnerParams()
|
|
101
|
+
runner.app_window_params.window_title = "imfeel demo"
|
|
102
|
+
runner.app_window_params.window_geometry.size = size
|
|
103
|
+
runner.imgui_window_params.default_imgui_window_type = (
|
|
104
|
+
hello_imgui.DefaultImGuiWindowType.provide_full_screen_dock_space
|
|
105
|
+
)
|
|
106
|
+
runner.imgui_window_params.show_menu_bar = False
|
|
107
|
+
runner.imgui_window_params.show_status_bar = False
|
|
108
|
+
runner.imgui_window_params.show_menu_view = False
|
|
109
|
+
runner.imgui_window_params.show_menu_app = False
|
|
110
|
+
runner.imgui_window_params.show_menu_view_themes = False
|
|
111
|
+
runner.imgui_window_params.remember_theme = False
|
|
112
|
+
runner.ini_disable = True
|
|
113
|
+
runner.fps_idling.enable_idling = False
|
|
114
|
+
|
|
115
|
+
def load_fonts() -> None:
|
|
116
|
+
app.fonts = fonts.load_fonts()
|
|
117
|
+
|
|
118
|
+
def before_frame() -> None:
|
|
119
|
+
if app.dirty:
|
|
120
|
+
apply_style(app.palette)
|
|
121
|
+
hello_imgui.get_runner_params().imgui_window_params.background_color = to_imvec4(
|
|
122
|
+
app.palette.bg
|
|
123
|
+
)
|
|
124
|
+
app.dirty = False
|
|
125
|
+
|
|
126
|
+
runner.callbacks.load_additional_fonts = load_fonts
|
|
127
|
+
runner.callbacks.pre_new_frame = before_frame
|
|
128
|
+
|
|
129
|
+
windows: list[hello_imgui.DockableWindow] = []
|
|
130
|
+
for page in PAGES:
|
|
131
|
+
win = hello_imgui.DockableWindow()
|
|
132
|
+
win.label = page.title
|
|
133
|
+
win.dock_space_name = "MainDockSpace" if window or page.dock == "center" else page.dock
|
|
134
|
+
win.gui_function = _caller(app, page)
|
|
135
|
+
win.can_be_closed = False
|
|
136
|
+
win.include_in_view_menu = False
|
|
137
|
+
win.imgui_window_flags = SCROLL_WINDOW_FLAGS # the vertical bar is always there
|
|
138
|
+
win.is_visible = window is None or page.key == window
|
|
139
|
+
windows.append(win)
|
|
140
|
+
runner.docking_params.dockable_windows = windows
|
|
141
|
+
if window is None:
|
|
142
|
+
runner.docking_params.docking_splits = [
|
|
143
|
+
_split("MainDockSpace", "left", imgui.Dir.left, 0.30),
|
|
144
|
+
_split("MainDockSpace", "right", imgui.Dir.right, 0.26),
|
|
145
|
+
]
|
|
146
|
+
return runner
|
|
147
|
+
|
|
148
|
+
|
|
149
|
+
def _caller(app: AppState, page: Page) -> Callable[[], None]:
|
|
150
|
+
def call() -> None:
|
|
151
|
+
draw_page(app, page)
|
|
152
|
+
|
|
153
|
+
return call
|
|
154
|
+
|
|
155
|
+
|
|
156
|
+
def _split(initial: str, new: str, direction: imgui.Dir, ratio: float) -> hello_imgui.DockingSplit:
|
|
157
|
+
split = hello_imgui.DockingSplit()
|
|
158
|
+
split.initial_dock = initial
|
|
159
|
+
split.new_dock = new
|
|
160
|
+
split.direction = direction
|
|
161
|
+
split.ratio = ratio
|
|
162
|
+
return split
|
|
163
|
+
|
|
164
|
+
|
|
165
|
+
def parse_size(text: str) -> tuple[int, int]:
|
|
166
|
+
width, _, height = text.lower().partition("x")
|
|
167
|
+
return int(width), int(height)
|
|
168
|
+
|
|
169
|
+
|
|
170
|
+
def main(argv: Sequence[str] | None = None) -> int:
|
|
171
|
+
ap = argparse.ArgumentParser(prog="python -m imfeel.demo", description=__doc__.split("\n\n")[0])
|
|
172
|
+
ap.add_argument("--screenshot", type=Path, metavar="PATH", help="render, save a PNG, exit")
|
|
173
|
+
ap.add_argument("--frames", type=int, default=DEFAULT_FRAMES, help="frames before the grab")
|
|
174
|
+
ap.add_argument("--theme", default=DEFAULT_THEME, choices=list(THEMES), help="start palette")
|
|
175
|
+
ap.add_argument("--window", choices=[p.key for p in PAGES], help="show only this window")
|
|
176
|
+
ap.add_argument("--size", type=parse_size, default=DEFAULT_SIZE, metavar="WxH")
|
|
177
|
+
ap.add_argument("--list", action="store_true", help="print the window names and exit")
|
|
178
|
+
args = ap.parse_args(argv)
|
|
179
|
+
if args.list:
|
|
180
|
+
for page in PAGES:
|
|
181
|
+
print(page.key)
|
|
182
|
+
return 0
|
|
183
|
+
if args.frames < 1:
|
|
184
|
+
ap.error("--frames must be at least 1")
|
|
185
|
+
|
|
186
|
+
app = AppState(palette=THEMES[args.theme])
|
|
187
|
+
runner = build_runner(app, size=args.size, window=args.window)
|
|
188
|
+
if args.screenshot is not None:
|
|
189
|
+
_install_screenshot(runner, args.screenshot, args.frames)
|
|
190
|
+
hello_imgui.run(runner)
|
|
191
|
+
if args.screenshot is not None and not args.screenshot.exists():
|
|
192
|
+
print("no screenshot was written", file=sys.stderr)
|
|
193
|
+
return 1
|
|
194
|
+
return 0
|
|
195
|
+
|
|
196
|
+
|
|
197
|
+
def _install_screenshot(runner: hello_imgui.RunnerParams, path: Path, frames: int) -> None:
|
|
198
|
+
"""Grab the `frames`-th frame in `before_swap`, then ask the app to exit."""
|
|
199
|
+
count = {"swapped": 0}
|
|
200
|
+
path.unlink(missing_ok=True)
|
|
201
|
+
|
|
202
|
+
def before_swap() -> None:
|
|
203
|
+
if count["swapped"] == frames - 1:
|
|
204
|
+
grab(path)
|
|
205
|
+
|
|
206
|
+
def after_swap() -> None:
|
|
207
|
+
count["swapped"] += 1
|
|
208
|
+
if count["swapped"] >= frames:
|
|
209
|
+
hello_imgui.get_runner_params().app_shall_exit = True
|
|
210
|
+
|
|
211
|
+
runner.callbacks.before_swap = before_swap
|
|
212
|
+
runner.callbacks.after_swap = after_swap
|