glotlib2 0.9.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.
Files changed (60) hide show
  1. glotlib2/__init__.py +6 -0
  2. glotlib2/colors.py +44 -0
  3. glotlib2/constants.py +106 -0
  4. glotlib2/event_queue.py +28 -0
  5. glotlib2/faces.py +7 -0
  6. glotlib2/font.py +233 -0
  7. glotlib2/font_files/__init__.py +0 -0
  8. glotlib2/font_files/ttf_bitstream_vera_1_10/COPYRIGHT.TXT +124 -0
  9. glotlib2/font_files/ttf_bitstream_vera_1_10/README.TXT +11 -0
  10. glotlib2/font_files/ttf_bitstream_vera_1_10/RELEASENOTES.TXT +162 -0
  11. glotlib2/font_files/ttf_bitstream_vera_1_10/Vera.ttf +0 -0
  12. glotlib2/font_files/ttf_bitstream_vera_1_10/VeraBI.ttf +0 -0
  13. glotlib2/font_files/ttf_bitstream_vera_1_10/VeraBd.ttf +0 -0
  14. glotlib2/font_files/ttf_bitstream_vera_1_10/VeraIt.ttf +0 -0
  15. glotlib2/font_files/ttf_bitstream_vera_1_10/VeraMoBI.ttf +0 -0
  16. glotlib2/font_files/ttf_bitstream_vera_1_10/VeraMoBd.ttf +0 -0
  17. glotlib2/font_files/ttf_bitstream_vera_1_10/VeraMoIt.ttf +0 -0
  18. glotlib2/font_files/ttf_bitstream_vera_1_10/VeraMono.ttf +0 -0
  19. glotlib2/font_files/ttf_bitstream_vera_1_10/VeraSe.ttf +0 -0
  20. glotlib2/font_files/ttf_bitstream_vera_1_10/VeraSeBd.ttf +0 -0
  21. glotlib2/font_files/ttf_bitstream_vera_1_10/local.conf +32 -0
  22. glotlib2/gl_context.py +342 -0
  23. glotlib2/gl_object.py +89 -0
  24. glotlib2/glfw/__init__.py +9 -0
  25. glotlib2/glfw/backend.py +43 -0
  26. glotlib2/glfw/gl_context.py +27 -0
  27. glotlib2/glfw/window.py +281 -0
  28. glotlib2/hline.py +99 -0
  29. glotlib2/label.py +160 -0
  30. glotlib2/matrix.py +72 -0
  31. glotlib2/miter_lines.py +113 -0
  32. glotlib2/periodic.py +27 -0
  33. glotlib2/plot.py +674 -0
  34. glotlib2/program.py +67 -0
  35. glotlib2/programs.py +117 -0
  36. glotlib2/pyside6/__init__.py +13 -0
  37. glotlib2/pyside6/backend.py +25 -0
  38. glotlib2/pyside6/gl_context.py +20 -0
  39. glotlib2/pyside6/gl_widget.py +362 -0
  40. glotlib2/pyside6/window.py +25 -0
  41. glotlib2/series.py +175 -0
  42. glotlib2/shaders/__init__.py +0 -0
  43. glotlib2/shaders/frag.frag +10 -0
  44. glotlib2/shaders/miter_line.vert +49 -0
  45. glotlib2/shaders/mvp_z.vert +10 -0
  46. glotlib2/shaders/points.frag +14 -0
  47. glotlib2/shaders/rect.vert +19 -0
  48. glotlib2/shaders/square_instanced_line.vert +38 -0
  49. glotlib2/shaders/text.frag +14 -0
  50. glotlib2/shaders/text.vert +15 -0
  51. glotlib2/step_series.py +76 -0
  52. glotlib2/ticker.py +78 -0
  53. glotlib2/vbo.py +128 -0
  54. glotlib2/vline.py +99 -0
  55. glotlib2/vstrip.py +86 -0
  56. glotlib2-0.9.0.dist-info/METADATA +73 -0
  57. glotlib2-0.9.0.dist-info/RECORD +60 -0
  58. glotlib2-0.9.0.dist-info/WHEEL +5 -0
  59. glotlib2-0.9.0.dist-info/licenses/LICENSE +373 -0
  60. glotlib2-0.9.0.dist-info/top_level.txt +1 -0
@@ -0,0 +1,162 @@
1
+ Bitstream Vera Fonts - April 16, 2003
2
+ =====================================
3
+
4
+ The version number of these fonts is 1.10 to distinguish them from the
5
+ beta test fonts.
6
+
7
+ Note that the Vera copyright is incorporated in the fonts themselves.
8
+ The License field in the fonts contains the copyright license as it
9
+ appears below. The TrueType copyright field is not large enough to
10
+ contain the full license, so the license is incorporated (as you might
11
+ think if you thought about it) into the license field, which
12
+ unfortunately can be obscure to find. (In pfaedit, see: Element->Font
13
+ Info->TTFNames->License).
14
+
15
+ Our apologies for it taking longer to complete the fonts than planned.
16
+ Beta testers requested a tighter line spacing (less leading) and Jim
17
+ Lyles redesigned Vera's accents to bring its line spacing to more
18
+ typical of other fonts. This took additional time and effort. Our
19
+ thanks to Jim for this effort above and beyond the call of duty.
20
+
21
+ There are four monospace and sans faces (normal, oblique, bold, bold
22
+ oblique) and two serif faces (normal and bold). Fontconfig/Xft2 (see
23
+ www.fontconfig.org) can artificially oblique the serif faces for you:
24
+ this loses hinting and distorts the faces slightly, but is visibly
25
+ different than normal and bold, and reasonably pleasing.
26
+
27
+ On systems with fontconfig 2.0 or 2.1 installed, making your sans,
28
+ serif and monospace fonts default to these fonts is very easy. Just
29
+ drop the file local.conf into your /etc/fonts directory. This will
30
+ make the Bitstream fonts your default fonts for all applications using
31
+ fontconfig (if sans, serif, or monospace names are used, as they often
32
+ are as default values in many desktops). The XML in local.conf may
33
+ need modification to enable subpixel decimation, if appropriate,
34
+ however, the commented out phrase does so for XFree86 4.3, in the case
35
+ that the server does not have sufficient information to identify the
36
+ use of a flat panel. Fontconfig 2.2 adds Vera to the list of font
37
+ families and will, by default use it as the default sans, serif and
38
+ monospace fonts.
39
+
40
+ During the testing of the final Vera fonts, we learned that screen
41
+ fonts in general are only typically hinted to work correctly at
42
+ integer pixel sizes. Vera is coded internally for integer sizes only.
43
+ We need to investigate further to see if there are commonly used fonts
44
+ that are hinted to be rounded but are not rounded to integer sizes due
45
+ to oversights in their coding.
46
+
47
+ Most fonts work best at 8 pixels and below if anti-aliased only, as
48
+ the amount of work required to hint well at smaller and smaller sizes
49
+ becomes astronomical. GASP tables are typically used to control
50
+ whether hinting is used or not, but Freetype/Xft does not currently
51
+ support GASP tables (which are present in Vera).
52
+
53
+ To mitigate this problem, both for Vera and other fonts, there will be
54
+ (very shortly) a new fontconfig 2.2 release that will, by default not
55
+ apply hints if the size is below 8 pixels. if you should have a font
56
+ that in fact has been hinted more agressively, you can use fontconfig
57
+ to note this exception. We believe this should improve many hinted
58
+ fonts in addition to Vera, though implemeting GASP support is likely
59
+ the right long term solution.
60
+
61
+ Font rendering in Gnome or KDE is the combination of algorithms in
62
+ Xft2 and Freetype, along with hinting in the fonts themselves. It is
63
+ vital to have sufficient information to disentangle problems that you
64
+ may observe.
65
+
66
+ Note that having your font rendering system set up correctly is vital
67
+ to proper judgement of problems of the fonts:
68
+
69
+ * Freetype may or may not be configured to in ways that may
70
+ implement execution of possibly patented (in some parts of the world)
71
+ TrueType hinting algorithms, particularly at small sizes. Best
72
+ results are obtained while using these algorithms.
73
+
74
+ * The freetype autohinter (used when the possibly patented
75
+ algorithms are not used) continues to improve with each release. If
76
+ you are using the autohinter, please ensure you are using an up to
77
+ date version of freetype before reporting problems.
78
+
79
+ * Please identify what version of freetype you are using in any
80
+ bug reports, and how your freetype is configured.
81
+
82
+ * Make sure you are not using the freetype version included in
83
+ XFree86 4.3, as it has bugs that significantly degrade most fonts,
84
+ including Vera. if you build XFree86 4.3 from source yourself, you may
85
+ have installed this broken version without intending it (as I
86
+ did). Vera was verified with the recently released Freetype 2.1.4. On
87
+ many systems, 'ldd" can be used to see which freetype shared library
88
+ is actually being used.
89
+
90
+ * Xft/X Render does not (yet) implement gamma correction. This
91
+ causes significant problems rendering white text on a black background
92
+ (causing partial pixels to be insufficiently shaded) if the gamma of
93
+ your monitor has not been compensated for, and minor problems with
94
+ black text on a while background. The program "xgamma" can be used to
95
+ set a gamma correction value in the X server's color pallette. Most
96
+ monitors have a gamma near 2.
97
+
98
+ * Note that the Vera family uses minimal delta hinting. Your
99
+ results on other systems when not used anti-aliased may not be
100
+ entirely satisfying. We are primarily interested in reports of
101
+ problems on open source systems implementing Xft2/fontconfig/freetype
102
+ (which implements antialiasing and hinting adjustements, and
103
+ sophisticated subpixel decimation on flatpanels). Also, the
104
+ algorithms used by Xft2 adjust the hints to integer widths and the
105
+ results are crisper on open source systems than on Windows or
106
+ MacIntosh.
107
+
108
+ * Your fontconfig may (probably does) predate the release of
109
+ fontconfig 2.2, and you may see artifacts not present when the font is
110
+ used at very small sizes with hinting enabled. "vc-list -V" can be
111
+ used to see what version you have installed.
112
+
113
+ We believe and hope that these fonts will resolve the problems
114
+ reported during beta test. The largest change is the reduction of
115
+ leading (interline spacing), which had annoyed a number of people, and
116
+ reduced Vera's utility for some applcations. The Vera monospace font
117
+ should also now make '0' and 'O' and '1' and 'l' more clearly
118
+ distinguishable.
119
+
120
+ The version of these fonts is version 1.10. Fontconfig should be
121
+ choosing the new version of the fonts if both the released fonts and
122
+ beta test fonts are installed (though please discard them: they have
123
+ names of form tt20[1-12]gn.ttf). Note that older versions of
124
+ fontconfig sometimes did not rebuild their cache correctly when new
125
+ fonts are installed: please upgrade to fontconfig 2.2. "fc-cache -f"
126
+ can be used to force rebuilding fontconfig's cache files.
127
+
128
+ If you note problems, please send them to fonts at gnome dot org, with
129
+ exactly which face and size and unicode point you observe the problem
130
+ at. The xfd utility from XFree86 CVS may be useful for this (e.g. "xfd
131
+ -fa sans"). A possibly more useful program to examine fonts at a
132
+ variety of sizes is the "waterfall" program found in Keith Packard's
133
+ CVS.
134
+
135
+ $ cvs -d :pserver:anoncvs@keithp.com:/local/src/CVS login
136
+ Logging in to :pserver:anoncvs@keithp.com:2401/local/src/CVS
137
+ CVS password: <hit return>
138
+ $ cvs -d :pserver:anoncvs@keithp.com:/local/src/CVS co waterfall
139
+ $ cd waterfall
140
+ $ xmkmf -a
141
+ $ make
142
+ # make install
143
+ # make install.man
144
+
145
+ Again, please make sure you are running an up-to-date freetype, and
146
+ that you are only examining integer sizes.
147
+
148
+ Reporting Problems
149
+ ==================
150
+
151
+ Please send problem reports to fonts at gnome org, with the following
152
+ information:
153
+
154
+ 1. Version of Freetype, Xft2 and fontconfig
155
+ 2. Whether TT hinting is being used, or the autohinter
156
+ 3. Application being used
157
+ 4. Character/Unicode code point that has problems (if applicable)
158
+ 5. Version of which operating system
159
+ 6. Please include a screenshot, when possible.
160
+
161
+ Please check the fonts list archives before reporting problems to cut
162
+ down on duplication.
@@ -0,0 +1,32 @@
1
+ <?xml version="1.0"?>
2
+ <!DOCTYPE fontconfig SYSTEM "fonts.dtd">
3
+ <!-- /etc/fonts.conf file to configure system font access -->
4
+ <fontconfig>
5
+ <!-- Enable sub-pixel rendering
6
+ <match target="font">
7
+ <test qual="all" name="rgba">
8
+ <const>unknown</const>
9
+ </test>
10
+ <edit name="rgba" mode="assign"><const>rgb</const></edit>
11
+ </match>
12
+ -->
13
+
14
+ <alias>
15
+ <family>serif</family>
16
+ <prefer>
17
+ <family>Bitstream Vera Serif</family>
18
+ </prefer>
19
+ </alias>
20
+ <alias>
21
+ <family>sans-serif</family>
22
+ <prefer>
23
+ <family>Bitstream Vera Sans</family>
24
+ </prefer>
25
+ </alias>
26
+ <alias>
27
+ <family>monospace</family>
28
+ <prefer>
29
+ <family>Bitstream Vera Sans Mono</family>
30
+ </prefer>
31
+ </alias>
32
+ </fontconfig>
glotlib2/gl_context.py ADDED
@@ -0,0 +1,342 @@
1
+ import time
2
+
3
+ from OpenGL import GL
4
+
5
+ from .gl_object import GLObject
6
+ from .event_queue import EventQueue
7
+ from .programs import Programs
8
+ from .faces import Faces
9
+ from .label import FlexLabel
10
+ from .plot import Plot
11
+ from . import matrix
12
+ from . import constants
13
+ from . import periodic
14
+
15
+
16
+ # This is the padding on each side of the flexible window area. Note that
17
+ # this amount of padding exists on the left and right sides and on the top and
18
+ # bottom sides, so the total padding is double these values.
19
+ PAD_H = 0.05
20
+ PAD_V = 0.05
21
+
22
+
23
+ def _bounds_hwp(h, w, p):
24
+ '''
25
+ Given a grid of height h and width w, returns the bounds (l, b, r, t) of
26
+ the grid cell p, with coordinates as percentages of the total grid. The
27
+ value p is specified by numbering the grid cells as follows:
28
+
29
+ 1, 2, 3, 4,
30
+ 5, 6, 7, 8,
31
+ ...
32
+
33
+ Note that the first cell is numbered 1.
34
+ '''
35
+ p -= 1
36
+ y = h - (p // w) - 1
37
+ x = p % w
38
+
39
+ return (x / w, y / h, (x + 1) / w, (y + 1) / h)
40
+
41
+
42
+ def _bounds_hwr(h, w, r):
43
+ '''
44
+ Given a grid of height h and width w, and a tuple r (p0, p1), returns the
45
+ bounds (l, b, r, t) of the smallest rectangle fully enclosing both p0 and
46
+ p1, with coordinates as percentages of the total grid. The values p0 and
47
+ p1 arespecified by numbering the grid cells as follows:
48
+
49
+ 1, 2, 3, 4,
50
+ 5, 6, 7, 8,
51
+ ...
52
+
53
+ Note that the first cell is numbered 1. In the example above, the range
54
+ (2, 7) and (7, 2) would specify the same rectangle, covering all of cells
55
+ 2, 3, 6 and 7.
56
+ '''
57
+ b0 = _bounds_hwp(h, w, r[0])
58
+ b1 = _bounds_hwp(h, w, r[1])
59
+ return (min(b0[0], b1[0]), min(b0[1], b1[1]),
60
+ max(b0[2], b1[2]), max(b0[3], b1[3]))
61
+
62
+
63
+ def _bounds_int(b):
64
+ '''
65
+ Given the value b, in the range 111 to 999, interpret the value as thought
66
+ the first digit were the height of the grid, the second digit were the
67
+ width of the grid and the third digit was the position p in the grid, and
68
+ then use _boudns_hwp() to compute the coordinates.
69
+ '''
70
+ assert 111 <= b <= 999
71
+ h = b // 100
72
+ w = (b % 100) // 10
73
+ p = (b % 10)
74
+ return _bounds_hwp(h, w, p)
75
+
76
+
77
+ def _bounds(b, pad_l=PAD_H, pad_r=PAD_H, pad_b=PAD_V, pad_t=PAD_V):
78
+ if isinstance(b, int):
79
+ c = _bounds_int(b)
80
+ elif isinstance(b, tuple) and len(b) == 3 and isinstance(b[2], int):
81
+ c = _bounds_hwp(*b)
82
+ elif isinstance(b, tuple) and len(b) == 3 and isinstance(b[2], tuple):
83
+ c = _bounds_hwr(*b)
84
+ elif isinstance(b, tuple) and len(b) == 4:
85
+ c = b
86
+ else:
87
+ return None
88
+
89
+ return (pad_l + (1 - (pad_l + pad_r))*c[0],
90
+ pad_b + (1 - (pad_b + pad_t))*c[1],
91
+ pad_l + (1 - (pad_l + pad_r))*c[2],
92
+ pad_b + (1 - (pad_b + pad_t))*c[3])
93
+
94
+
95
+ class MouseButtonState:
96
+ def __init__(self, plot, button, x, y, mods):
97
+ self.plot = plot
98
+ self.button = button
99
+ self.click_x = x
100
+ self.click_y = y
101
+ self.mods = mods
102
+
103
+
104
+ class GLContextDelegate:
105
+ def handle_mouse_moved(self, plot, x, y):
106
+ pass
107
+
108
+ def handle_mouse_down(self, mbs):
109
+ pass
110
+
111
+ def handle_mouse_up(self, mbs, x, y):
112
+ pass
113
+
114
+ def handle_key_press(self, key):
115
+ pass
116
+
117
+ def update_geometry(self):
118
+ pass
119
+
120
+
121
+ class GLContext(GLObject):
122
+ def __init__(self, msaa=None, delegate=None):
123
+ super().__init__(None)
124
+
125
+ self._event_queue = EventQueue()
126
+
127
+ self.opengl_context = None
128
+ self.msaa = msaa
129
+ self.programs = Programs()
130
+ self.faces = Faces()
131
+
132
+ self.ctx_w = None
133
+ self.ctx_h = None
134
+ self.fb_w = None
135
+ self.fb_h = None
136
+ self.mvp = None
137
+ self.r_w = None
138
+ self.r_h = None
139
+
140
+ self.mouse_x = None
141
+ self.mouse_y = None
142
+ self.mouse_button_state = {}
143
+
144
+ self._modifier_mask = 0
145
+
146
+ self.plots = []
147
+ self.frame_time_0 = None
148
+ self.frame_time = 0
149
+ self.fps_ticker = None
150
+
151
+ self.delegate = delegate or GLContextDelegate()
152
+
153
+ def is_active(self):
154
+ '''
155
+ Returns true if we are bound to the current thread's OpenGL context.
156
+ '''
157
+ raise NotImplementedError
158
+
159
+ def set_fps(self, fps):
160
+ '''
161
+ This sets the frame rate for periodic updates (animation). If you want
162
+ your app to do animation based on time rather than simply being
163
+ reactive to input device events, set the fps to a non-zero value.
164
+ '''
165
+ interval = 1. / fps
166
+ if self.fps_ticker is None:
167
+ self.fps_ticker = periodic.Ticker(interval, self.mark_dirty)
168
+ else:
169
+ self.fps_ticker.interval = interval
170
+
171
+ def _defer(self, func, *args, **kwargs):
172
+ self._event_queue.enqueue(func, *args, **kwargs)
173
+ self.mark_dirty()
174
+
175
+ def _init_ctx(self, opengl_context, ctx_w, ctx_h, fb_w, fb_h):
176
+ '''
177
+ Called by the native window manager (or whatever is creating contexts)
178
+ with the context bound to the current thread and handing us some
179
+ parameters that the rest of the tree will need.
180
+ '''
181
+ self.opengl_context = opengl_context
182
+ assert self.is_active()
183
+
184
+ self.ctx_w, self.ctx_h = ctx_w, ctx_h
185
+ self.fb_w, self.fb_h = fb_w, fb_h
186
+ self.mvp = matrix.ortho(0, self.ctx_w, 0, self.ctx_h, -1, 1)
187
+
188
+ self._init_gl()
189
+ self._tree_init_new_gl_children()
190
+
191
+ def _init_gl(self):
192
+ '''
193
+ Called by the native window manager (or whatever is creating contexts)
194
+ with the context bound to the current thread. This is where you should
195
+ initialize OpenGL state.
196
+ '''
197
+ self.programs.load()
198
+
199
+ if self.msaa is not None:
200
+ GL.glEnable(GL.GL_MULTISAMPLE)
201
+
202
+ GL.glClearColor(1, 1, 1, 1)
203
+ GL.glBlendFunc(GL.GL_SRC_ALPHA, GL.GL_ONE_MINUS_SRC_ALPHA)
204
+
205
+ def _paint_gl(self):
206
+ '''
207
+ This is called when the OS has decided that the window needs to be
208
+ redrawn, for instance due to a window resize event. We must always
209
+ repaint the window since everything should be considered invalidated.
210
+ '''
211
+ assert self.is_active()
212
+
213
+ self._event_queue.process()
214
+
215
+ t = time.monotonic()
216
+ if self.frame_time_0 is None:
217
+ self.frame_time_0 = t
218
+ self.frame_time = t - self.frame_time_0
219
+ self.delegate.update_geometry()
220
+
221
+ GL.glClear(GL.GL_COLOR_BUFFER_BIT)
222
+
223
+ def _update_ratios(self):
224
+ self.r_w = self.fb_w / self.ctx_w if self.ctx_w else 0
225
+ self.r_h = self.fb_h / self.ctx_h if self.ctx_h else 0
226
+
227
+ def _resize_gl_ctx(self, w, h):
228
+ '''
229
+ Called by the native window manager when the OpenGL context changes
230
+ size. The values are dimensions in window manager context coordinates.
231
+ '''
232
+ assert self.is_active()
233
+ self.ctx_w, self.ctx_h = w, h
234
+ self.mvp = matrix.ortho(0, self.ctx_w, 0, self.ctx_h, -1, 1)
235
+ self._update_ratios()
236
+
237
+ def _resize_gl_fb(self, w, h):
238
+ '''
239
+ Called by the native window manager when the OpenGL framebuffer changes
240
+ size. The values are the dimensions in framebuffer coordinates and
241
+ take into count things like a Retina display which has twice as many
242
+ pixels in each dimension compares to the window manager coordinates.
243
+ '''
244
+ assert self.is_active()
245
+ self.fb_w, self.fb_h = w, h
246
+ self._update_ratios()
247
+
248
+ def _handle_mouse_moved(self, x, y):
249
+ self.mouse_x, self.mouse_y = x, y
250
+ for p in self.plots:
251
+ p.handle_mouse_moved(x, y)
252
+ self.delegate.handle_mouse_moved(self.find_plot(x, y), x, y)
253
+
254
+ def _handle_mouse_button_callback(self, x, y, button, action, mods):
255
+ plot = self.find_plot(x, y)
256
+ if action == constants.MOUSE_BUTTON_PRESS:
257
+ mbs = MouseButtonState(plot, button, x, y, mods)
258
+ self.mouse_button_state[button] = mbs
259
+ if plot:
260
+ plot.handle_mouse_down(mbs)
261
+ self.delegate.handle_mouse_down(mbs)
262
+ elif action == constants.MOUSE_BUTTON_RELEASE:
263
+ mbs = self.mouse_button_state.get(button)
264
+ if mbs:
265
+ if mbs.plot:
266
+ mbs.plot.handle_mouse_up(mbs)
267
+ self.mouse_button_state[button] = None
268
+ self.delegate.handle_mouse_up(mbs, x, y)
269
+
270
+ def _handle_mouse_scrolled(self, x, y, dx, dy, mods):
271
+ plot = self.find_plot(x, y)
272
+ if plot:
273
+ plot.handle_mouse_scrolled(x, y, dx, dy, mods)
274
+
275
+ def _handle_key_event(self, x, y, key, action):
276
+ key_mod_mask = constants.KEY_TO_MODIFIER_MAP.get(key, 0)
277
+ if action == constants.KEY_PRESS:
278
+ self._modifier_mask |= key_mod_mask
279
+ if key == ' ':
280
+ p = self.find_plot(x, y)
281
+ if p:
282
+ p.snap_bounds()
283
+ else:
284
+ self.delegate.handle_key_press(key)
285
+ else:
286
+ self._modifier_mask &= ~key_mod_mask
287
+
288
+ def add_label(self, *args, font=None, **kwargs):
289
+ font = font or self.faces.vera(12)
290
+ return FlexLabel(self, *args, font=font, **kwargs)
291
+
292
+ def add_plot(self, bounds=111, **kwargs):
293
+ '''
294
+ Adds a rectangular plot to the window. The bounds value selects the
295
+ position of the plot and can have one of the following formats:
296
+
297
+ HWP - a set of 3 integers encoded either as a 3-digit decimal
298
+ number with H, W, P in the hundreds, tens and ones positions,
299
+ respectively, or as a 3-tuple (H, W, P). H and W divide the
300
+ window space into a grid of height H and width W and P
301
+ selects the grid cell numbered from 1 to H*W left-to-right
302
+ and then top-to-bottom.
303
+
304
+ HWR - a 3-tuple (H, W, (r0, r1)) where the H and W values are the
305
+ same as HWP format but the plot rectangle will have the
306
+ bounds of the smallest rectangle that fully encloses both the
307
+ grid cells at positions r0 and r1.
308
+
309
+ (x0, y0, x1, y1) - a 4-tuple specifying the bottom-left and top-
310
+ right positions of the bounding rectangle, expressed as a
311
+ fraction from 0 to 1 which scaled with the dimensions of the
312
+ enclosing window.
313
+
314
+ The limits 4-tuple can be used to specify the (x0, y0, x1, y1) data
315
+ limits that the plot will initially be looking at.
316
+
317
+ The colors parameter can specify a list of (R, G, B, A) colors to cycle
318
+ through for each new curve added to the plot, as floating-point values
319
+ from 0 to 1.
320
+
321
+ The max_h_ticks and max_v_ticks parameters can be used to specify the
322
+ maximum number of ticks to display on the plot, which can be useful to
323
+ limit spam on smaller plots.
324
+
325
+ The aspect parameter can be either Plot.ASPECT_NONE or
326
+ Plot.ASPECT_SQUARE, the latter which enforces the plot's data view
327
+ edges so that squares in the data space are rendered as squares in the
328
+ screen space.
329
+ '''
330
+ p = Plot(self, bounds=_bounds(bounds), **kwargs)
331
+ self.plots.append(p)
332
+ return p
333
+
334
+ def set_plot_bounds(self, plot, bounds, **kwargs):
335
+ plot.bounds = _bounds(bounds, **kwargs)
336
+ plot._handle_resize()
337
+
338
+ def find_plot(self, x, y):
339
+ for p in self.plots:
340
+ if p.visible and p.x <= x < p.x + p.w and p.y <= y < p.y + p.h:
341
+ return p
342
+ return None
glotlib2/gl_object.py ADDED
@@ -0,0 +1,89 @@
1
+ import threading
2
+
3
+
4
+ class GLObjectMeta(type):
5
+ '''
6
+ Metaclass that causes the object to automatically be registered with the
7
+ parent.
8
+ '''
9
+ def __call__(cls, *args, **kwargs):
10
+ obj = super().__call__(*args, **kwargs)
11
+ if obj.gl_parent:
12
+ obj.gl_parent._tree_register_new_gl_child(obj)
13
+ return obj
14
+
15
+
16
+ class GLObject(metaclass=GLObjectMeta):
17
+ def __init__(self, gl_parent, visible=True):
18
+ self.gl_parent = gl_parent
19
+ self.gl_children_lock = threading.Lock()
20
+ self.new_gl_children = []
21
+ self.gl_children = []
22
+ self.visible = visible
23
+
24
+ if gl_parent:
25
+ self.ctx = getattr(gl_parent, 'ctx', gl_parent)
26
+
27
+ def _init_gl(self):
28
+ pass
29
+
30
+ def _resize_gl_ctx(self, w, h):
31
+ pass
32
+
33
+ def _resize_gl_fb(self, w, h):
34
+ pass
35
+
36
+ def _paint_gl(self):
37
+ pass
38
+
39
+ def mark_dirty(self):
40
+ '''
41
+ Marks the context as dirty so that the next time through the event loop
42
+ a redraw will be forced.
43
+ '''
44
+ self.gl_parent.mark_dirty()
45
+
46
+ def show(self):
47
+ self.visible = True
48
+ self.ctx.mark_dirty()
49
+
50
+ def hide(self):
51
+ self.visible = False
52
+ self.ctx.mark_dirty()
53
+
54
+ def _tree_register_new_gl_child(self, child):
55
+ with self.gl_children_lock:
56
+ self.new_gl_children.append(child)
57
+ self.mark_dirty()
58
+
59
+ def _tree_init_new_gl_children(self):
60
+ '''
61
+ Pops all GL objects from the new_gl_children list, inits them and then
62
+ adds them to the regular objects list.
63
+ '''
64
+ if self.new_gl_children:
65
+ with self.gl_children_lock:
66
+ new_gl_children = self.new_gl_children
67
+ self.new_gl_children = []
68
+
69
+ for obj in new_gl_children:
70
+ obj._init_gl()
71
+ self.gl_children.append(obj)
72
+ obj._tree_init_new_gl_children()
73
+
74
+ def _tree_resize_gl_ctx(self, w, h):
75
+ self._resize_gl_ctx(w, h)
76
+ for obj in self.gl_children:
77
+ obj._tree_resize_gl_ctx(w, h)
78
+
79
+ def _tree_resize_gl_fb(self, w, h):
80
+ self._resize_gl_fb(w, h)
81
+ for obj in self.gl_children:
82
+ obj._tree_resize_gl_fb(w, h)
83
+
84
+ def _tree_paint_gl(self):
85
+ self._tree_init_new_gl_children()
86
+ if self.visible:
87
+ self._paint_gl()
88
+ for obj in self.gl_children:
89
+ obj._tree_paint_gl()
@@ -0,0 +1,9 @@
1
+ from .backend import init_backend, interact
2
+ from .window import Window
3
+
4
+
5
+ __all__ = [
6
+ 'init_backend',
7
+ 'interact',
8
+ 'Window',
9
+ ]