summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJames E. Blair <corvus@gnu.org>2014-12-20 15:35:13 (GMT)
committerJames E. Blair <corvus@gnu.org>2015-01-09 18:39:14 (GMT)
commitef9fb76de9ef299fbdc8f87f1dd05bdd1eda649e (patch)
treedc85b1dfb180f427b3686e59d6b7a8254397c1e2
Initial commit
-rw-r--r--.gitignore7
-rw-r--r--COPYING674
-rw-r--r--README.rst63
-rw-r--r--example/ansi.ans45
-rw-r--r--example/demo.rst149
-rw-r--r--example/gg.jpgbin0 -> 78551 bytes
-rw-r--r--presentty/__init__.py0
-rw-r--r--presentty/ansiparser.py185
-rw-r--r--presentty/client.py66
-rw-r--r--presentty/console.py292
-rw-r--r--presentty/image.py168
-rw-r--r--presentty/palette.py78
-rw-r--r--presentty/presentty.py162
-rw-r--r--presentty/rst.py493
-rw-r--r--presentty/server.py112
-rw-r--r--presentty/slide.py178
-rw-r--r--presentty/text.py81
-rw-r--r--presentty/transition.py153
-rw-r--r--requirements.txt7
-rw-r--r--setup.cfg45
-rw-r--r--setup.py20
21 files changed, 2978 insertions, 0 deletions
diff --git a/.gitignore b/.gitignore
new file mode 100644
index 0000000..7d1a781
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1,7 @@
1*.egg
2*.egg-info
3*.pyc
4AUTHORS
5build/*
6ChangeLog
7venv/
diff --git a/COPYING b/COPYING
new file mode 100644
index 0000000..94a9ed0
--- /dev/null
+++ b/COPYING
@@ -0,0 +1,674 @@
1 GNU GENERAL PUBLIC LICENSE
2 Version 3, 29 June 2007
3
4 Copyright (C) 2007 Free Software Foundation, Inc. <http://fsf.org/>
5 Everyone is permitted to copy and distribute verbatim copies
6 of this license document, but changing it is not allowed.
7
8 Preamble
9
10 The GNU General Public License is a free, copyleft license for
11software and other kinds of works.
12
13 The licenses for most software and other practical works are designed
14to take away your freedom to share and change the works. By contrast,
15the GNU General Public License is intended to guarantee your freedom to
16share and change all versions of a program--to make sure it remains free
17software for all its users. We, the Free Software Foundation, use the
18GNU General Public License for most of our software; it applies also to
19any other work released this way by its authors. You can apply it to
20your programs, too.
21
22 When we speak of free software, we are referring to freedom, not
23price. Our General Public Licenses are designed to make sure that you
24have the freedom to distribute copies of free software (and charge for
25them if you wish), that you receive source code or can get it if you
26want it, that you can change the software or use pieces of it in new
27free programs, and that you know you can do these things.
28
29 To protect your rights, we need to prevent others from denying you
30these rights or asking you to surrender the rights. Therefore, you have
31certain responsibilities if you distribute copies of the software, or if
32you modify it: responsibilities to respect the freedom of others.
33
34 For example, if you distribute copies of such a program, whether
35gratis or for a fee, you must pass on to the recipients the same
36freedoms that you received. You must make sure that they, too, receive
37or can get the source code. And you must show them these terms so they
38know their rights.
39
40 Developers that use the GNU GPL protect your rights with two steps:
41(1) assert copyright on the software, and (2) offer you this License
42giving you legal permission to copy, distribute and/or modify it.
43
44 For the developers' and authors' protection, the GPL clearly explains
45that there is no warranty for this free software. For both users' and
46authors' sake, the GPL requires that modified versions be marked as
47changed, so that their problems will not be attributed erroneously to
48authors of previous versions.
49
50 Some devices are designed to deny users access to install or run
51modified versions of the software inside them, although the manufacturer
52can do so. This is fundamentally incompatible with the aim of
53protecting users' freedom to change the software. The systematic
54pattern of such abuse occurs in the area of products for individuals to
55use, which is precisely where it is most unacceptable. Therefore, we
56have designed this version of the GPL to prohibit the practice for those
57products. If such problems arise substantially in other domains, we
58stand ready to extend this provision to those domains in future versions
59of the GPL, as needed to protect the freedom of users.
60
61 Finally, every program is threatened constantly by software patents.
62States should not allow patents to restrict development and use of
63software on general-purpose computers, but in those that do, we wish to
64avoid the special danger that patents applied to a free program could
65make it effectively proprietary. To prevent this, the GPL assures that
66patents cannot be used to render the program non-free.
67
68 The precise terms and conditions for copying, distribution and
69modification follow.
70
71 TERMS AND CONDITIONS
72
73 0. Definitions.
74
75 "This License" refers to version 3 of the GNU General Public License.
76
77 "Copyright" also means copyright-like laws that apply to other kinds of
78works, such as semiconductor masks.
79
80 "The Program" refers to any copyrightable work licensed under this
81License. Each licensee is addressed as "you". "Licensees" and
82"recipients" may be individuals or organizations.
83
84 To "modify" a work means to copy from or adapt all or part of the work
85in a fashion requiring copyright permission, other than the making of an
86exact copy. The resulting work is called a "modified version" of the
87earlier work or a work "based on" the earlier work.
88
89 A "covered work" means either the unmodified Program or a work based
90on the Program.
91
92 To "propagate" a work means to do anything with it that, without
93permission, would make you directly or secondarily liable for
94infringement under applicable copyright law, except executing it on a
95computer or modifying a private copy. Propagation includes copying,
96distribution (with or without modification), making available to the
97public, and in some countries other activities as well.
98
99 To "convey" a work means any kind of propagation that enables other
100parties to make or receive copies. Mere interaction with a user through
101a computer network, with no transfer of a copy, is not conveying.
102
103 An interactive user interface displays "Appropriate Legal Notices"
104to the extent that it includes a convenient and prominently visible
105feature that (1) displays an appropriate copyright notice, and (2)
106tells the user that there is no warranty for the work (except to the
107extent that warranties are provided), that licensees may convey the
108work under this License, and how to view a copy of this License. If
109the interface presents a list of user commands or options, such as a
110menu, a prominent item in the list meets this criterion.
111
112 1. Source Code.
113
114 The "source code" for a work means the preferred form of the work
115for making modifications to it. "Object code" means any non-source
116form of a work.
117
118 A "Standard Interface" means an interface that either is an official
119standard defined by a recognized standards body, or, in the case of
120interfaces specified for a particular programming language, one that
121is widely used among developers working in that language.
122
123 The "System Libraries" of an executable work include anything, other
124than the work as a whole, that (a) is included in the normal form of
125packaging a Major Component, but which is not part of that Major
126Component, and (b) serves only to enable use of the work with that
127Major Component, or to implement a Standard Interface for which an
128implementation is available to the public in source code form. A
129"Major Component", in this context, means a major essential component
130(kernel, window system, and so on) of the specific operating system
131(if any) on which the executable work runs, or a compiler used to
132produce the work, or an object code interpreter used to run it.
133
134 The "Corresponding Source" for a work in object code form means all
135the source code needed to generate, install, and (for an executable
136work) run the object code and to modify the work, including scripts to
137control those activities. However, it does not include the work's
138System Libraries, or general-purpose tools or generally available free
139programs which are used unmodified in performing those activities but
140which are not part of the work. For example, Corresponding Source
141includes interface definition files associated with source files for
142the work, and the source code for shared libraries and dynamically
143linked subprograms that the work is specifically designed to require,
144such as by intimate data communication or control flow between those
145subprograms and other parts of the work.
146
147 The Corresponding Source need not include anything that users
148can regenerate automatically from other parts of the Corresponding
149Source.
150
151 The Corresponding Source for a work in source code form is that
152same work.
153
154 2. Basic Permissions.
155
156 All rights granted under this License are granted for the term of
157copyright on the Program, and are irrevocable provided the stated
158conditions are met. This License explicitly affirms your unlimited
159permission to run the unmodified Program. The output from running a
160covered work is covered by this License only if the output, given its
161content, constitutes a covered work. This License acknowledges your
162rights of fair use or other equivalent, as provided by copyright law.
163
164 You may make, run and propagate covered works that you do not
165convey, without conditions so long as your license otherwise remains
166in force. You may convey covered works to others for the sole purpose
167of having them make modifications exclusively for you, or provide you
168with facilities for running those works, provided that you comply with
169the terms of this License in conveying all material for which you do
170not control copyright. Those thus making or running the covered works
171for you must do so exclusively on your behalf, under your direction
172and control, on terms that prohibit them from making any copies of
173your copyrighted material outside their relationship with you.
174
175 Conveying under any other circumstances is permitted solely under
176the conditions stated below. Sublicensing is not allowed; section 10
177makes it unnecessary.
178
179 3. Protecting Users' Legal Rights From Anti-Circumvention Law.
180
181 No covered work shall be deemed part of an effective technological
182measure under any applicable law fulfilling obligations under article
18311 of the WIPO copyright treaty adopted on 20 December 1996, or
184similar laws prohibiting or restricting circumvention of such
185measures.
186
187 When you convey a covered work, you waive any legal power to forbid
188circumvention of technological measures to the extent such circumvention
189is effected by exercising rights under this License with respect to
190the covered work, and you disclaim any intention to limit operation or
191modification of the work as a means of enforcing, against the work's
192users, your or third parties' legal rights to forbid circumvention of
193technological measures.
194
195 4. Conveying Verbatim Copies.
196
197 You may convey verbatim copies of the Program's source code as you
198receive it, in any medium, provided that you conspicuously and
199appropriately publish on each copy an appropriate copyright notice;
200keep intact all notices stating that this License and any
201non-permissive terms added in accord with section 7 apply to the code;
202keep intact all notices of the absence of any warranty; and give all
203recipients a copy of this License along with the Program.
204
205 You may charge any price or no price for each copy that you convey,
206and you may offer support or warranty protection for a fee.
207
208 5. Conveying Modified Source Versions.
209
210 You may convey a work based on the Program, or the modifications to
211produce it from the Program, in the form of source code under the
212terms of section 4, provided that you also meet all of these conditions:
213
214 a) The work must carry prominent notices stating that you modified
215 it, and giving a relevant date.
216
217 b) The work must carry prominent notices stating that it is
218 released under this License and any conditions added under section
219 7. This requirement modifies the requirement in section 4 to
220 "keep intact all notices".
221
222 c) You must license the entire work, as a whole, under this
223 License to anyone who comes into possession of a copy. This
224 License will therefore apply, along with any applicable section 7
225 additional terms, to the whole of the work, and all its parts,
226 regardless of how they are packaged. This License gives no
227 permission to license the work in any other way, but it does not
228 invalidate such permission if you have separately received it.
229
230 d) If the work has interactive user interfaces, each must display
231 Appropriate Legal Notices; however, if the Program has interactive
232 interfaces that do not display Appropriate Legal Notices, your
233 work need not make them do so.
234
235 A compilation of a covered work with other separate and independent
236works, which are not by their nature extensions of the covered work,
237and which are not combined with it such as to form a larger program,
238in or on a volume of a storage or distribution medium, is called an
239"aggregate" if the compilation and its resulting copyright are not
240used to limit the access or legal rights of the compilation's users
241beyond what the individual works permit. Inclusion of a covered work
242in an aggregate does not cause this License to apply to the other
243parts of the aggregate.
244
245 6. Conveying Non-Source Forms.
246
247 You may convey a covered work in object code form under the terms
248of sections 4 and 5, provided that you also convey the
249machine-readable Corresponding Source under the terms of this License,
250in one of these ways:
251
252 a) Convey the object code in, or embodied in, a physical product
253 (including a physical distribution medium), accompanied by the
254 Corresponding Source fixed on a durable physical medium
255 customarily used for software interchange.
256
257 b) Convey the object code in, or embodied in, a physical product
258 (including a physical distribution medium), accompanied by a
259 written offer, valid for at least three years and valid for as
260 long as you offer spare parts or customer support for that product
261 model, to give anyone who possesses the object code either (1) a
262 copy of the Corresponding Source for all the software in the
263 product that is covered by this License, on a durable physical
264 medium customarily used for software interchange, for a price no
265 more than your reasonable cost of physically performing this
266 conveying of source, or (2) access to copy the
267 Corresponding Source from a network server at no charge.
268
269 c) Convey individual copies of the object code with a copy of the
270 written offer to provide the Corresponding Source. This
271 alternative is allowed only occasionally and noncommercially, and
272 only if you received the object code with such an offer, in accord
273 with subsection 6b.
274
275 d) Convey the object code by offering access from a designated
276 place (gratis or for a charge), and offer equivalent access to the
277 Corresponding Source in the same way through the same place at no
278 further charge. You need not require recipients to copy the
279 Corresponding Source along with the object code. If the place to
280 copy the object code is a network server, the Corresponding Source
281 may be on a different server (operated by you or a third party)
282 that supports equivalent copying facilities, provided you maintain
283 clear directions next to the object code saying where to find the
284 Corresponding Source. Regardless of what server hosts the
285 Corresponding Source, you remain obligated to ensure that it is
286 available for as long as needed to satisfy these requirements.
287
288 e) Convey the object code using peer-to-peer transmission, provided
289 you inform other peers where the object code and Corresponding
290 Source of the work are being offered to the general public at no
291 charge under subsection 6d.
292
293 A separable portion of the object code, whose source code is excluded
294from the Corresponding Source as a System Library, need not be
295included in conveying the object code work.
296
297 A "User Product" is either (1) a "consumer product", which means any
298tangible personal property which is normally used for personal, family,
299or household purposes, or (2) anything designed or sold for incorporation
300into a dwelling. In determining whether a product is a consumer product,
301doubtful cases shall be resolved in favor of coverage. For a particular
302product received by a particular user, "normally used" refers to a
303typical or common use of that class of product, regardless of the status
304of the particular user or of the way in which the particular user
305actually uses, or expects or is expected to use, the product. A product
306is a consumer product regardless of whether the product has substantial
307commercial, industrial or non-consumer uses, unless such uses represent
308the only significant mode of use of the product.
309
310 "Installation Information" for a User Product means any methods,
311procedures, authorization keys, or other information required to install
312and execute modified versions of a covered work in that User Product from
313a modified version of its Corresponding Source. The information must
314suffice to ensure that the continued functioning of the modified object
315code is in no case prevented or interfered with solely because
316modification has been made.
317
318 If you convey an object code work under this section in, or with, or
319specifically for use in, a User Product, and the conveying occurs as
320part of a transaction in which the right of possession and use of the
321User Product is transferred to the recipient in perpetuity or for a
322fixed term (regardless of how the transaction is characterized), the
323Corresponding Source conveyed under this section must be accompanied
324by the Installation Information. But this requirement does not apply
325if neither you nor any third party retains the ability to install
326modified object code on the User Product (for example, the work has
327been installed in ROM).
328
329 The requirement to provide Installation Information does not include a
330requirement to continue to provide support service, warranty, or updates
331for a work that has been modified or installed by the recipient, or for
332the User Product in which it has been modified or installed. Access to a
333network may be denied when the modification itself materially and
334adversely affects the operation of the network or violates the rules and
335protocols for communication across the network.
336
337 Corresponding Source conveyed, and Installation Information provided,
338in accord with this section must be in a format that is publicly
339documented (and with an implementation available to the public in
340source code form), and must require no special password or key for
341unpacking, reading or copying.
342
343 7. Additional Terms.
344
345 "Additional permissions" are terms that supplement the terms of this
346License by making exceptions from one or more of its conditions.
347Additional permissions that are applicable to the entire Program shall
348be treated as though they were included in this License, to the extent
349that they are valid under applicable law. If additional permissions
350apply only to part of the Program, that part may be used separately
351under those permissions, but the entire Program remains governed by
352this License without regard to the additional permissions.
353
354 When you convey a copy of a covered work, you may at your option
355remove any additional permissions from that copy, or from any part of
356it. (Additional permissions may be written to require their own
357removal in certain cases when you modify the work.) You may place
358additional permissions on material, added by you to a covered work,
359for which you have or can give appropriate copyright permission.
360
361 Notwithstanding any other provision of this License, for material you
362add to a covered work, you may (if authorized by the copyright holders of
363that material) supplement the terms of this License with terms:
364
365 a) Disclaiming warranty or limiting liability differently from the
366 terms of sections 15 and 16 of this License; or
367
368 b) Requiring preservation of specified reasonable legal notices or
369 author attributions in that material or in the Appropriate Legal
370 Notices displayed by works containing it; or
371
372 c) Prohibiting misrepresentation of the origin of that material, or
373 requiring that modified versions of such material be marked in
374 reasonable ways as different from the original version; or
375
376 d) Limiting the use for publicity purposes of names of licensors or
377 authors of the material; or
378
379 e) Declining to grant rights under trademark law for use of some
380 trade names, trademarks, or service marks; or
381
382 f) Requiring indemnification of licensors and authors of that
383 material by anyone who conveys the material (or modified versions of
384 it) with contractual assumptions of liability to the recipient, for
385 any liability that these contractual assumptions directly impose on
386 those licensors and authors.
387
388 All other non-permissive additional terms are considered "further
389restrictions" within the meaning of section 10. If the Program as you
390received it, or any part of it, contains a notice stating that it is
391governed by this License along with a term that is a further
392restriction, you may remove that term. If a license document contains
393a further restriction but permits relicensing or conveying under this
394License, you may add to a covered work material governed by the terms
395of that license document, provided that the further restriction does
396not survive such relicensing or conveying.
397
398 If you add terms to a covered work in accord with this section, you
399must place, in the relevant source files, a statement of the
400additional terms that apply to those files, or a notice indicating
401where to find the applicable terms.
402
403 Additional terms, permissive or non-permissive, may be stated in the
404form of a separately written license, or stated as exceptions;
405the above requirements apply either way.
406
407 8. Termination.
408
409 You may not propagate or modify a covered work except as expressly
410provided under this License. Any attempt otherwise to propagate or
411modify it is void, and will automatically terminate your rights under
412this License (including any patent licenses granted under the third
413paragraph of section 11).
414
415 However, if you cease all violation of this License, then your
416license from a particular copyright holder is reinstated (a)
417provisionally, unless and until the copyright holder explicitly and
418finally terminates your license, and (b) permanently, if the copyright
419holder fails to notify you of the violation by some reasonable means
420prior to 60 days after the cessation.
421
422 Moreover, your license from a particular copyright holder is
423reinstated permanently if the copyright holder notifies you of the
424violation by some reasonable means, this is the first time you have
425received notice of violation of this License (for any work) from that
426copyright holder, and you cure the violation prior to 30 days after
427your receipt of the notice.
428
429 Termination of your rights under this section does not terminate the
430licenses of parties who have received copies or rights from you under
431this License. If your rights have been terminated and not permanently
432reinstated, you do not qualify to receive new licenses for the same
433material under section 10.
434
435 9. Acceptance Not Required for Having Copies.
436
437 You are not required to accept this License in order to receive or
438run a copy of the Program. Ancillary propagation of a covered work
439occurring solely as a consequence of using peer-to-peer transmission
440to receive a copy likewise does not require acceptance. However,
441nothing other than this License grants you permission to propagate or
442modify any covered work. These actions infringe copyright if you do
443not accept this License. Therefore, by modifying or propagating a
444covered work, you indicate your acceptance of this License to do so.
445
446 10. Automatic Licensing of Downstream Recipients.
447
448 Each time you convey a covered work, the recipient automatically
449receives a license from the original licensors, to run, modify and
450propagate that work, subject to this License. You are not responsible
451for enforcing compliance by third parties with this License.
452
453 An "entity transaction" is a transaction transferring control of an
454organization, or substantially all assets of one, or subdividing an
455organization, or merging organizations. If propagation of a covered
456work results from an entity transaction, each party to that
457transaction who receives a copy of the work also receives whatever
458licenses to the work the party's predecessor in interest had or could
459give under the previous paragraph, plus a right to possession of the
460Corresponding Source of the work from the predecessor in interest, if
461the predecessor has it or can get it with reasonable efforts.
462
463 You may not impose any further restrictions on the exercise of the
464rights granted or affirmed under this License. For example, you may
465not impose a license fee, royalty, or other charge for exercise of
466rights granted under this License, and you may not initiate litigation
467(including a cross-claim or counterclaim in a lawsuit) alleging that
468any patent claim is infringed by making, using, selling, offering for
469sale, or importing the Program or any portion of it.
470
471 11. Patents.
472
473 A "contributor" is a copyright holder who authorizes use under this
474License of the Program or a work on which the Program is based. The
475work thus licensed is called the contributor's "contributor version".
476
477 A contributor's "essential patent claims" are all patent claims
478owned or controlled by the contributor, whether already acquired or
479hereafter acquired, that would be infringed by some manner, permitted
480by this License, of making, using, or selling its contributor version,
481but do not include claims that would be infringed only as a
482consequence of further modification of the contributor version. For
483purposes of this definition, "control" includes the right to grant
484patent sublicenses in a manner consistent with the requirements of
485this License.
486
487 Each contributor grants you a non-exclusive, worldwide, royalty-free
488patent license under the contributor's essential patent claims, to
489make, use, sell, offer for sale, import and otherwise run, modify and
490propagate the contents of its contributor version.
491
492 In the following three paragraphs, a "patent license" is any express
493agreement or commitment, however denominated, not to enforce a patent
494(such as an express permission to practice a patent or covenant not to
495sue for patent infringement). To "grant" such a patent license to a
496party means to make such an agreement or commitment not to enforce a
497patent against the party.
498
499 If you convey a covered work, knowingly relying on a patent license,
500and the Corresponding Source of the work is not available for anyone
501to copy, free of charge and under the terms of this License, through a
502publicly available network server or other readily accessible means,
503then you must either (1) cause the Corresponding Source to be so
504available, or (2) arrange to deprive yourself of the benefit of the
505patent license for this particular work, or (3) arrange, in a manner
506consistent with the requirements of this License, to extend the patent
507license to downstream recipients. "Knowingly relying" means you have
508actual knowledge that, but for the patent license, your conveying the
509covered work in a country, or your recipient's use of the covered work
510in a country, would infringe one or more identifiable patents in that
511country that you have reason to believe are valid.
512
513 If, pursuant to or in connection with a single transaction or
514arrangement, you convey, or propagate by procuring conveyance of, a
515covered work, and grant a patent license to some of the parties
516receiving the covered work authorizing them to use, propagate, modify
517or convey a specific copy of the covered work, then the patent license
518you grant is automatically extended to all recipients of the covered
519work and works based on it.
520
521 A patent license is "discriminatory" if it does not include within
522the scope of its coverage, prohibits the exercise of, or is
523conditioned on the non-exercise of one or more of the rights that are
524specifically granted under this License. You may not convey a covered
525work if you are a party to an arrangement with a third party that is
526in the business of distributing software, under which you make payment
527to the third party based on the extent of your activity of conveying
528the work, and under which the third party grants, to any of the
529parties who would receive the covered work from you, a discriminatory
530patent license (a) in connection with copies of the covered work
531conveyed by you (or copies made from those copies), or (b) primarily
532for and in connection with specific products or compilations that
533contain the covered work, unless you entered into that arrangement,
534or that patent license was granted, prior to 28 March 2007.
535
536 Nothing in this License shall be construed as excluding or limiting
537any implied license or other defenses to infringement that may
538otherwise be available to you under applicable patent law.
539
540 12. No Surrender of Others' Freedom.
541
542 If conditions are imposed on you (whether by court order, agreement or
543otherwise) that contradict the conditions of this License, they do not
544excuse you from the conditions of this License. If you cannot convey a
545covered work so as to satisfy simultaneously your obligations under this
546License and any other pertinent obligations, then as a consequence you may
547not convey it at all. For example, if you agree to terms that obligate you
548to collect a royalty for further conveying from those to whom you convey
549the Program, the only way you could satisfy both those terms and this
550License would be to refrain entirely from conveying the Program.
551
552 13. Use with the GNU Affero General Public License.
553
554 Notwithstanding any other provision of this License, you have
555permission to link or combine any covered work with a work licensed
556under version 3 of the GNU Affero General Public License into a single
557combined work, and to convey the resulting work. The terms of this
558License will continue to apply to the part which is the covered work,
559but the special requirements of the GNU Affero General Public License,
560section 13, concerning interaction through a network will apply to the
561combination as such.
562
563 14. Revised Versions of this License.
564
565 The Free Software Foundation may publish revised and/or new versions of
566the GNU General Public License from time to time. Such new versions will
567be similar in spirit to the present version, but may differ in detail to
568address new problems or concerns.
569
570 Each version is given a distinguishing version number. If the
571Program specifies that a certain numbered version of the GNU General
572Public License "or any later version" applies to it, you have the
573option of following the terms and conditions either of that numbered
574version or of any later version published by the Free Software
575Foundation. If the Program does not specify a version number of the
576GNU General Public License, you may choose any version ever published
577by the Free Software Foundation.
578
579 If the Program specifies that a proxy can decide which future
580versions of the GNU General Public License can be used, that proxy's
581public statement of acceptance of a version permanently authorizes you
582to choose that version for the Program.
583
584 Later license versions may give you additional or different
585permissions. However, no additional obligations are imposed on any
586author or copyright holder as a result of your choosing to follow a
587later version.
588
589 15. Disclaimer of Warranty.
590
591 THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY
592APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT
593HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY
594OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO,
595THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
596PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM
597IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF
598ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
599
600 16. Limitation of Liability.
601
602 IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
603WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS
604THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY
605GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE
606USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF
607DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD
608PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS),
609EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF
610SUCH DAMAGES.
611
612 17. Interpretation of Sections 15 and 16.
613
614 If the disclaimer of warranty and limitation of liability provided
615above cannot be given local legal effect according to their terms,
616reviewing courts shall apply local law that most closely approximates
617an absolute waiver of all civil liability in connection with the
618Program, unless a warranty or assumption of liability accompanies a
619copy of the Program in return for a fee.
620
621 END OF TERMS AND CONDITIONS
622
623 How to Apply These Terms to Your New Programs
624
625 If you develop a new program, and you want it to be of the greatest
626possible use to the public, the best way to achieve this is to make it
627free software which everyone can redistribute and change under these terms.
628
629 To do so, attach the following notices to the program. It is safest
630to attach them to the start of each source file to most effectively
631state the exclusion of warranty; and each file should have at least
632the "copyright" line and a pointer to where the full notice is found.
633
634 <one line to give the program's name and a brief idea of what it does.>
635 Copyright (C) <year> <name of author>
636
637 This program is free software: you can redistribute it and/or modify
638 it under the terms of the GNU General Public License as published by
639 the Free Software Foundation, either version 3 of the License, or
640 (at your option) any later version.
641
642 This program is distributed in the hope that it will be useful,
643 but WITHOUT ANY WARRANTY; without even the implied warranty of
644 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
645 GNU General Public License for more details.
646
647 You should have received a copy of the GNU General Public License
648 along with this program. If not, see <http://www.gnu.org/licenses/>.
649
650Also add information on how to contact you by electronic and paper mail.
651
652 If the program does terminal interaction, make it output a short
653notice like this when it starts in an interactive mode:
654
655 <program> Copyright (C) <year> <name of author>
656 This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
657 This is free software, and you are welcome to redistribute it
658 under certain conditions; type `show c' for details.
659
660The hypothetical commands `show w' and `show c' should show the appropriate
661parts of the General Public License. Of course, your program's commands
662might be different; for a GUI interface, you would use an "about box".
663
664 You should also get your employer (if you work as a programmer) or school,
665if any, to sign a "copyright disclaimer" for the program, if necessary.
666For more information on this, and how to apply and follow the GNU GPL, see
667<http://www.gnu.org/licenses/>.
668
669 The GNU General Public License does not permit incorporating your program
670into proprietary programs. If your program is a subroutine library, you
671may consider it more useful to permit linking proprietary applications with
672the library. If this is what you want to do, use the GNU Lesser General
673Public License instead of this License. But first, please read
674<http://www.gnu.org/philosophy/why-not-lgpl.html>.
diff --git a/README.rst b/README.rst
new file mode 100644
index 0000000..ddc18d4
--- /dev/null
+++ b/README.rst
@@ -0,0 +1,63 @@
1Presentty
2=========
3
4Presentty is a console-based presentation program based on
5RestructuredText.
6
7Installation
8------------
9
10It is recommended, but not required, to install presentty in to a
11virtualenv. To cset one up::
12
13 virtualenv presentty-env
14 source presentty-env/bin/activate
15
16To install the latest version from the cheeseshop::
17
18 pip install presentty
19
20To install from a git checkout::
21
22 pip install .
23
24In order to use the cross-fade transition, you must run presentty in a
25256-color capable terminal, such as gnome-terminal or xterm.
26
27In order for images to render as ascii art, you must have jp2a
28installed.
29
30In order to use figlet and cowsay directives, their respective
31programs must be installed.
32
33Usage
34-----
35
36Presentty takes the path to the presentation file as an argument.
37
38To run the demonstration included with Presentty, run the following::
39
40 presentty example/demo.rst
41
42Other command line options are available; you can see them with::
43
44 presentty --help
45
46Once presentty is running, you may start an optional presenter's
47console in another window with::
48
49 presentty-console example/demo.rst
50
51Once in the presenter's console, you can use the arrow keys and
52[enter] to change the current slide, 't' to set the countdown timer
53starting value, and [space] to start or stop the timer.
54
55In either the presenter's console or the main presentty window, the
56left and right arrow keys or page-up and page-down navigate between
57slides.
58
59License
60-------
61
62Presentty is licensed under the GPLv3 or later. Please see the
63COPYING file for details.
diff --git a/example/ansi.ans b/example/ansi.ans
new file mode 100644
index 0000000..ea6a694
--- /dev/null
+++ b/example/ansi.ans
@@ -0,0 +1,45 @@
1 ______________ .──. .──. ______________
2
3( (  \ \_____)____(_____/ /  ) )
4
5 \ ) `─────'   `─────' ( /
6
7 )/   \(
8
9 /' `\ 
10
11O  _ _ _ ____ ___ _ _   O
12
13│  / \ | \ | / ___|_ _| / \ _ __| |_  │
14
15│  / _ \ | \| \___ \| | / _ \ | '__| __| │
16
17│  / ___ \| |\ |___) | | / ___ \| | | |_  │
18
19│ /_/ \_\_| \_|____/___| /_/ \_\_| \__| │
20
21│ │
22
23O  May be directly included  O
24
25 \. ./ 
26
27 )\  ,____ ____,  /(
28
29 / ) / ____\ ____ /____ \ ( \
30
31( (_________/_/ ) ( \_\_________) )
32
33 ~-'  `──' `──'  `-~ 
34
35
36
37
38
39
40
41
42
43
44
45 \ No newline at end of file
diff --git a/example/demo.rst b/example/demo.rst
new file mode 100644
index 0000000..bafd9ba
--- /dev/null
+++ b/example/demo.rst
@@ -0,0 +1,149 @@
1.. This is an RST comment.
2 The following directives, when used at the top of the file, set default
3 values for all slides:
4
5 This sets the transition style. Values are: 'dissolve', 'pan', or
6 'cut'. The optional argument of 'duration' sets the duration of
7 the transition in seconds (0.4 seconds by default). The same
8 syntax may be used within a slide to override the transition for
9 that slide alone.
10
11 .. transition:: dissolve
12 :duration: 0.4
13
14 This disables display of the title. Each slide must still have a
15 title, and it will be used by the presenter console, but it will
16 not be displayed on the slide. The same syntax may be used within
17 a slide to hide the title of that individual slide.
18
19 .. hidetitle::
20
21.. Slides are defined one at a time by starting a new top-level
22 section:
23
24Presentty
25=========
26.. container:: handout
27
28 Content that is placed in a container called "handout" will not be
29 displayed with the slides, but will be displayed on the presenter's
30 console.
31
32Presentty is a console presentation system based where slides are
33authored in reStructuredText.
34
35Bullet Lists
36============
37It is able to display lists of items:
38
39* Pork
40
41 * Eastern North Carolina
42 * Lexington
43
44* Ribs
45* Brisket
46
47
48Progressive Display
49===================
50Bullet lists may include a *progressive* display:
51
52.. container:: progressive
53
54 * Red Leicester
55 * Tilsit
56 * Caerphilly
57
58
59Table
60=====
61
62=== ===
63 p !p
64=== ===
65 T F
66 F T
67=== ===
68
69Dissove Transition
70==================
71Transitions may be "dissolve," where one slide cross-fades into the next...
72
73Pan Transition
74==============
75.. transition:: pan
76
77...or "pan," where the slides appear horizontally adjacent and move
78right to left...
79
80Cut Transition
81==============
82.. transition:: cut
83
84...or "cut," where they abruptly change from one to the next.
85
86Syntax Highligting
87==================
88Pygments is used to provide syntax highlighting of code in almost any
89language:
90
91.. code:: python
92
93 class UrwidTranslator(nodes.GenericNodeVisitor):
94 def depart_Text(self, node):
95 if self.stack and isinstance(self.stack[-1], 'string'):
96 # a comment
97 if self.attr:
98 t = (self.attr[-1], node.astext())
99 else:
100 t = node.astext()
101 self.stack[-1].append(t)
102 visit_literal_block = visit_textelement
103
104Cowsay
105======
106.. cowsay:: Presentty is a console-based presentation program where
107 reStructuredText is used to author slides.
108
109| If cowsay is installed, it can easily
110| be used to display text.
111
112Figlet
113======
114.. container:: handout
115
116 Cowsay and figlet are non-standard directives and will not appear
117 if the RST file is rendered with a program other than presentty.
118 If you want to ensure that the content appears in all forms, you
119 may wish to run the respective commands manually and copy the
120 output into a quoted block in the RST file.
121
122.. figlet:: FIGLET
123
124| If figlet is installed, it can be
125| used to provide large text.
126
127ANSI Art
128========
129.. hidetitle::
130.. container:: handout
131
132 Note that the ansi directive is specific to presentty, and so if an
133 RST file that includes it is rendered with another program,
134 included ANSI files will not appear.
135
136.. ansi:: ansi.ans
137
138Images
139======
140.. container:: handout
141
142 The standard sphinx image directive can be used to include bitmap
143 images (such as JPEG or PNG files) which will be automatically
144 converted to ANSI art for display. This feauter requires that PIL
145 or Pillow (Python Image Library) and jp2a be installed.
146
147.. image:: gg.jpg
148
149"Golden Gate Bridge" by Kevin Cole (CC-BY: https://flic.kr/p/7L2Rdu)
diff --git a/example/gg.jpg b/example/gg.jpg
new file mode 100644
index 0000000..77dcb67
--- /dev/null
+++ b/example/gg.jpg
Binary files differ
diff --git a/presentty/__init__.py b/presentty/__init__.py
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/presentty/__init__.py
diff --git a/presentty/ansiparser.py b/presentty/ansiparser.py
new file mode 100644
index 0000000..a780b42
--- /dev/null
+++ b/presentty/ansiparser.py
@@ -0,0 +1,185 @@
1# Copyright (C) 2015 James E. Blair <corvus@gnu.org>
2#
3# This program is free software: you can redistribute it and/or modify
4# it under the terms of the GNU General Public License as published by
5# the Free Software Foundation, either version 3 of the License, or
6# (at your option) any later version.
7#
8# This program is distributed in the hope that it will be useful,
9# but WITHOUT ANY WARRANTY; without even the implied warranty of
10# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11# GNU General Public License for more details.
12#
13# You should have received a copy of the GNU General Public License
14# along with this program. If not, see <http://www.gnu.org/licenses/>.
15
16import re
17
18import urwid
19
20class ANSIParser(object):
21 colors = [
22 urwid.BLACK,
23 urwid.DARK_RED,
24 urwid.DARK_GREEN,
25 urwid.BROWN,
26 urwid.DARK_BLUE,
27 urwid.DARK_MAGENTA,
28 urwid.DARK_CYAN,
29 urwid.LIGHT_GRAY,
30 urwid.DARK_GRAY,
31 urwid.LIGHT_RED,
32 urwid.LIGHT_GREEN,
33 urwid.YELLOW,
34 urwid.LIGHT_BLUE,
35 urwid.LIGHT_MAGENTA,
36 urwid.LIGHT_CYAN,
37 urwid.WHITE,
38 ]
39
40 colors256 = ['0', '6', '8', 'a', 'd', 'f']
41 colorsgray = ['3', '7', '11', '13', '15', '19', '23', '27', '31',
42 '35', '38', '42', '46', '50', '52', '58', '62', '66',
43 '70', '74', '78', '82', '85', '89', '93']
44
45 def __init__(self):
46 self.x = 0
47 self.y = 0
48 self.text_lines = []
49 self.attr_lines = []
50 self.background = urwid.AttrSpec('light gray', 'black')
51 self.attr = self.background
52 self.resetColor()
53 self.moveTo(0,0)
54
55 def resetColor(self):
56 self.bold = False
57 self.blink = False
58 self.fg = 7
59 self.bg = 0
60
61 def moveTo(self, x, y):
62 while x>80:
63 x-=80
64 y+=1
65 while y+1 > len(self.text_lines):
66 self.text_lines.append([u' ' for i in range(80)])
67 self.attr_lines.append([self.attr for i in range(80)])
68 self.x = x
69 self.y = y
70
71 def parseSequence(self, seq):
72 values = []
73 buf = ''
74 for c in seq:
75 if c in ['\x1b', '[']:
76 continue
77 if c == ';':
78 values.append(int(buf))
79 buf = ''
80 continue
81 if ord(c) < 64:
82 buf += c
83 if buf:
84 values.append(int(buf))
85 if c == 'm':
86 if not values:
87 values = [0]
88 fg256 = None
89 for v in values:
90 if fg256 is True:
91 if v <= 0x08:
92 self.fg = v
93 elif v <= 0x0f:
94 self.fg = v - 0x08
95 self.bold = True
96 elif v <= 0xe7:
97 r, x = divmod(v-16, 36)
98 g, x = divmod(x, 6)
99 b = x % 6
100 fg256 = ('#' +
101 self.colors256[r] +
102 self.colors256[g] +
103 self.colors256[b])
104 else:
105 fg256 = 'g' + str(self.colorsgray[v-232])
106 elif v == 0:
107 self.resetColor()
108 elif v == 1:
109 self.bold = True
110 elif v == 5:
111 self.blink = True
112 elif v>29 and v<38:
113 self.fg = v-30
114 elif v>39 and v<48:
115 self.bg = v-40
116 elif v==38:
117 fg256=True
118 fg = self.fg
119 if self.bold:
120 fg += 8
121 fgattrs = []
122 if self.blink:
123 fgattrs.append('blink')
124 if fg256:
125 fgattrs.append(fg256)
126 else:
127 fgattrs.append(self.colors[fg])
128 self.attr = urwid.AttrSpec(', '.join(fgattrs), self.colors[self.bg])
129 if c == 'A':
130 if not values:
131 values = [1]
132 y = max(self.y-values[0], 0)
133 self.moveTo(self.x, y)
134 if c == 'C':
135 if not values:
136 values = [1]
137 x = self.x + values[0]
138 self.moveTo(x, self.y)
139 if c == 'H':
140 self.moveTo(values[1]-1, values[0]-1)
141
142 def parse(self, data):
143 seq = ''
144 for char in data:
145 if seq:
146 seq += char
147 if ord(char) >= 64 and char != '[':
148 self.parseSequence(seq)
149 seq = ''
150 continue
151 if char == '\x1a':
152 continue
153 if char == '\x1b':
154 seq = char
155 continue
156 if char == '\r':
157 self.moveTo(0, self.y)
158 continue
159 if char == '\n':
160 self.moveTo(self.x, self.y+1)
161 continue
162 if not seq:
163 self.text_lines[self.y][self.x] = char
164 self.attr_lines[self.y][self.x] = self.attr
165 x = self.x + 1
166 self.moveTo(x, self.y)
167 text = []
168 current_attr = self.attr_lines[0][0]
169 current_text = u''
170 for y in range(len(self.text_lines)):
171 for x in range(80):
172 char = self.text_lines[y][x]
173 attr = self.attr_lines[y][x]
174 if (attr.foreground_number != current_attr.foreground_number or
175 attr.background_number != current_attr.background_number):
176 text.append((current_attr, current_text))
177 current_attr = attr
178 current_text = u''
179 current_text += char
180 if (current_attr.background_number==0):
181 current_text = current_text.rstrip(' ')
182 current_text += u'\n'
183 current_text = re.sub('\n+$', '\n', current_text)
184 text.append((current_attr, current_text))
185 return text
diff --git a/presentty/client.py b/presentty/client.py
new file mode 100644
index 0000000..a819dfd
--- /dev/null
+++ b/presentty/client.py
@@ -0,0 +1,66 @@
1# Copyright (C) 2015 James E. Blair <corvus@gnu.org>
2#
3# This program is free software: you can redistribute it and/or modify
4# it under the terms of the GNU General Public License as published by
5# the Free Software Foundation, either version 3 of the License, or
6# (at your option) any later version.
7#
8# This program is distributed in the hope that it will be useful,
9# but WITHOUT ANY WARRANTY; without even the implied warranty of
10# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11# GNU General Public License for more details.
12#
13# You should have received a copy of the GNU General Public License
14# along with this program. If not, see <http://www.gnu.org/licenses/>.
15
16import socket
17
18class Client(object):
19 def __init__(self, host='127.0.0.1', port=1292):
20 self.host = host
21 self.port = port
22 self.sock = None
23 self.connect()
24
25 def connect(self):
26 self.sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
27 self.sock.connect((self.host, self.port))
28 self.file = self.sock.makefile('rw', 0)
29
30 def list(self):
31 self.file.write('list\n')
32 program = []
33 while True:
34 ln = self.file.readline().strip()
35 if ln == 'end':
36 break
37 x, index, title = ln.split(' ', 2)
38 program.append(title)
39 return program
40
41 def size(self):
42 self.file.write('size\n')
43 ln = self.file.readline().strip()
44 x, cols, rows = ln.split(' ', 2)
45 return (int(cols), int(rows))
46
47 def parseCurrent(self):
48 ln = self.file.readline().strip()
49 x, index, progressive_state, title = ln.split(' ', 3)
50 return (int(index), int(progressive_state))
51
52 def current(self):
53 self.file.write('current\n')
54 return self.parseCurrent()
55
56 def jump(self, index):
57 self.file.write('jump %i\n' % index)
58 return self.parseCurrent()
59
60 def next(self):
61 self.file.write('next\n')
62 return self.parseCurrent()
63
64 def prev(self):
65 self.file.write('prev\n')
66 return self.parseCurrent()
diff --git a/presentty/console.py b/presentty/console.py
new file mode 100644
index 0000000..d29b864
--- /dev/null
+++ b/presentty/console.py
@@ -0,0 +1,292 @@
1# Copyright (C) 2015 James E. Blair <corvus@gnu.org>
2#
3# This program is free software: you can redistribute it and/or modify
4# it under the terms of the GNU General Public License as published by
5# the Free Software Foundation, either version 3 of the License, or
6# (at your option) any later version.
7#
8# This program is distributed in the hope that it will be useful,
9# but WITHOUT ANY WARRANTY; without even the implied warranty of
10# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11# GNU General Public License for more details.
12#
13# You should have received a copy of the GNU General Public License
14# along with this program. If not, see <http://www.gnu.org/licenses/>.
15
16import argparse
17import sys
18import datetime
19import time
20
21import urwid
22
23import palette
24import client
25import slide
26import rst
27
28PALETTE = [
29 ('reversed', 'standout', ''),
30 ('status', 'light red', ''),
31]
32
33class Row(urwid.Button):
34 def __init__(self, index, title, console):
35 super(Row, self).__init__('', on_press=console.jump, user_data=index)
36 col = urwid.Columns([
37 ('fixed', 3, urwid.Text('%-2i' % (index+1))),
38 urwid.Text(title),
39 ])
40 self._w = urwid.AttrMap(col, None, focus_map='reversed')
41
42 def selectable(self):
43 return True
44
45class Footer(urwid.WidgetWrap):
46 def __init__(self):
47 super(Footer, self).__init__(urwid.Columns([]))
48 self.position = urwid.Text(u'')
49 self.timer = urwid.Text(u'')
50 self._w.contents.append((self.position, ('pack', None, False)))
51 self._w.contents.append((urwid.Text(u''), ('weight', 1, False)))
52 self._w.contents.append((self.timer, ('pack', None, False)))
53
54class Screen(urwid.WidgetWrap):
55 def __init__(self, console):
56 super(Screen, self).__init__(urwid.Pile([]))
57 self.console = console
58 self.program = []
59 self.current = -1
60 self.progressive_state = 0
61 self.blank_slide = slide.UrwidSlide(
62 u'', None, urwid.Text(u''), None)
63 self.timer = 45*60
64 self.size = (80, 25)
65 self.timer_end = None
66 self.listbox = urwid.ListBox(urwid.SimpleFocusListWalker([]))
67 self.footer = Footer()
68 footer = urwid.AttrMap(self.footer, 'status')
69 self.left = urwid.Pile([])
70 self.left.contents.append((self.listbox, ('weight', 1)))
71 self.left.set_focus(0)
72
73 self.right = urwid.Pile([])
74 self.setPreviews()
75
76 self.main = urwid.Columns([])
77 self.main.contents.append((self.left, ('weight', 1, False)))
78 self.main.contents.append((self.right, ('given', self.size[0]+2, False)))
79 self.main.set_focus(0)
80
81 self._w.contents.append((self.main, ('weight', 1)))
82 self._w.contents.append((footer, ('pack', 1)))
83 self._w.set_focus(0)
84
85 def setPreviews(self):
86 current_slide = next_slide = self.blank_slide
87 if 0 <= self.current < len(self.program):
88 current_slide = self.program[self.current]
89 if 0 <= self.current+1 < len(self.program):
90 next_slide = self.program[self.current+1]
91 current_slide.setProgressive(self.progressive_state)
92 current_box = urwid.LineBox(current_slide, "Current")
93 next_box = urwid.LineBox(next_slide, "Next")
94 if current_slide.handout:
95 notes_box = urwid.LineBox(current_slide.handout, "Notes")
96 else:
97 notes_box = None
98 self.right.contents[:] = []
99 self.left.contents[:] = self.left.contents[:1]
100 cols, rows = self.size
101 self.right.contents.append((current_box, ('given', rows+2)))
102 self.right.contents.append((next_box, ('given', rows+2)))
103 self.right.contents.append((urwid.Filler(urwid.Text(u'')), ('weight', 1)))
104 if notes_box:
105 self.left.contents.append((notes_box, ('pack', None)))
106
107 def setProgram(self, program):
108 self.program = program
109 self.listbox.body[:] = []
110 for i, s in enumerate(program):
111 self.listbox.body.append(Row(i, s.title, self.console))
112
113 def setSize(self, size):
114 self.size = size
115 cols, rows = size
116 self.right.contents[0] = (self.right.contents[0][0], ('given', rows+2))
117 self.right.contents[1] = (self.right.contents[1][0], ('given', rows+2))
118 self.main.contents[1] = (self.main.contents[1][0], ('given', cols+2, False))
119
120 # Implement this method from the urwid screen interface for the ScreenHinter
121 def get_cols_rows(self):
122 return self.size
123
124 def setCurrent(self, state):
125 index, progressive_state = state
126 changed = False
127 if index != self.current:
128 self.current = index
129 self.listbox.set_focus(index)
130 self.listbox._invalidate()
131 self.footer.position.set_text('%i / %i' % (index+1, len(self.program)))
132 changed = True
133 if progressive_state != self.progressive_state:
134 self.progressive_state = progressive_state
135 changed = True
136 if changed:
137 self.setPreviews()
138 self.footer.timer.set_text(self.getTime())
139
140 def getTime(self):
141 now = time.time()
142 if self.timer_end:
143 return str(datetime.timedelta(seconds=(int(self.timer_end-now))))
144 else:
145 return str(datetime.timedelta(seconds=int(self.timer)))
146
147 def setTimer(self, secs):
148 self.timer = secs
149 if self.timer_end:
150 now = time.time()
151 self.timer_end = now + self.timer
152
153 def startStopTimer(self):
154 now = time.time()
155 if self.timer_end:
156 remain = max(self.timer_end - int(now), 0)
157 self.timer = remain
158 self.timer_end = None
159 else:
160 self.timer_end = now + self.timer
161
162 def keypress(self, size, key):
163 if key in (' ', 'x'):
164 self.startStopTimer()
165 elif key == 'page up':
166 self.console.prev()
167 elif key == 'page down':
168 self.console.next()
169 elif key == 'right':
170 self.console.next()
171 elif key == 'left':
172 self.console.prev()
173 elif key == 't':
174 self.console.timerDialog()
175 else:
176 return super(Screen, self).keypress(size, key)
177 return None
178
179class FixedButton(urwid.Button):
180 def sizing(self):
181 return frozenset([urwid.FIXED])
182
183 def pack(self, size, focus=False):
184 return (len(self.get_label())+4, 1)
185
186class TimerDialog(urwid.WidgetWrap):
187 signals = ['set', 'cancel']
188 def __init__(self):
189 set_button = FixedButton('Set')
190 cancel_button = FixedButton('Cancel')
191 urwid.connect_signal(set_button, 'click',
192 lambda button:self._emit('set'))
193 urwid.connect_signal(cancel_button, 'click',
194 lambda button:self._emit('cancel'))
195 button_widgets = [('pack', set_button),
196 ('pack', cancel_button)]
197 button_columns = urwid.Columns(button_widgets, dividechars=2)
198 rows = []
199 self.entry = urwid.Edit('Timer: ', edit_text='45:00')
200 rows.append(self.entry)
201 rows.append(urwid.Divider())
202 rows.append(button_columns)
203 pile = urwid.Pile(rows)
204 fill = urwid.Filler(pile, valign='top')
205 super(TimerDialog, self).__init__(urwid.LineBox(fill, 'Timer'))
206
207 def keypress(self, size, key):
208 r = super(TimerDialog, self).keypress(size, key)
209 if r == 'enter':
210 self._emit('set')
211 return None
212 elif r == 'esc':
213 self._emit('cancel')
214 return None
215 return r
216
217class Console(object):
218 poll_interval = 0.5
219
220 def __init__(self, program):
221 self.screen = Screen(self)
222 self.loop = urwid.MainLoop(self.screen, palette=PALETTE)
223 self.client = client.Client()
224 self.screen.setProgram(program)
225 self.update()
226 self.loop.set_alarm_in(self.poll_interval, self.updateCallback)
227
228 def run(self):
229 self.loop.run()
230
231 def jump(self, widget, index):
232 self.screen.setCurrent(self.client.jump(index))
233
234 def next(self):
235 self.screen.setCurrent(self.client.next())
236
237 def prev(self):
238 self.screen.setCurrent(self.client.prev())
239
240 def updateCallback(self, loop=None, data=None):
241 self.update()
242 self.loop.set_alarm_in(self.poll_interval, self.updateCallback)
243
244 def update(self):
245 self.screen.setSize(self.client.size())
246 self.screen.setCurrent(self.client.current())
247
248 def timerDialog(self):
249 dialog = TimerDialog()
250 overlay = urwid.Overlay(dialog, self.loop.widget,
251 'center', 30,
252 'middle', 6)
253 self.loop.widget = overlay
254 urwid.connect_signal(dialog, 'cancel', self.cancelDialog)
255 urwid.connect_signal(dialog, 'set', self.setTimer)
256
257 def cancelDialog(self, widget):
258 self.loop.widget = self.screen
259
260 def setTimer(self, widget):
261 parts = widget.entry.edit_text.split(':')
262 secs = 0
263 if len(parts):
264 secs += int(parts.pop())
265 if len(parts):
266 secs += int(parts.pop())*60
267 if len(parts):
268 secs += int(parts.pop())*60*60
269 self.screen.setTimer(secs)
270 self.loop.widget = self.screen
271
272
273def main():
274 parser = argparse.ArgumentParser(
275 description='Console-based presentation system')
276 parser.add_argument('--light', dest='light',
277 default=False,
278 action='store_true',
279 help='use a black on white palette')
280 parser.add_argument('file',
281 help='presentation file (RST)')
282 args = parser.parse_args()
283 if args.light:
284 plt = palette.LIGHT_PALETTE
285 else:
286 plt = palette.DARK_PALETTE
287 hinter = slide.ScreenHinter()
288 parser = rst.PresentationParser(plt, hinter)
289 program = parser.parse(open(args.file).read())
290 c = Console(program)
291 hinter.setScreen(c.screen)
292 c.run()
diff --git a/presentty/image.py b/presentty/image.py
new file mode 100644
index 0000000..9aabee8
--- /dev/null
+++ b/presentty/image.py
@@ -0,0 +1,168 @@
1# Copyright (C) 2015 James E. Blair <corvus@gnu.org>
2#
3# This program is free software: you can redistribute it and/or modify
4# it under the terms of the GNU General Public License as published by
5# the Free Software Foundation, either version 3 of the License, or
6# (at your option) any later version.
7#
8# This program is distributed in the hope that it will be useful,
9# but WITHOUT ANY WARRANTY; without even the implied warranty of
10# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11# GNU General Public License for more details.
12#
13# You should have received a copy of the GNU General Public License
14# along with this program. If not, see <http://www.gnu.org/licenses/>.
15
16import subprocess
17import HTMLParser
18import re
19
20import PIL
21import PIL.ExifTags
22import urwid
23
24import slide
25
26def nearest_color(x):
27 if x < 0x30: return '0'
28 if x < 0x70: return '6'
29 if x < 0x98: return '8'
30 if x < 0xc0: return 'a'
31 if x < 0xe8: return 'd'
32 return 'f'
33
34class ANSIImage(urwid.Widget):
35 def __init__(self, uri, hinter=None):
36 super(ANSIImage, self).__init__()
37 self.uri = uri
38 image = self._loadImage()
39 self.htmlparser = HTMLParser.HTMLParser()
40 self.ratio = float(image.size[0])/float(image.size[1])
41 self.hinter = hinter
42
43 def _loadImage(self):
44 image = PIL.Image.open(self.uri)
45 image.load()
46 exif = image._getexif()
47 if exif:
48 orientation = exif.get(274, 1)
49 if orientation == 1:
50 pass
51 elif orientation == 3:
52 image = image.rotate(180)
53 elif orientation == 6:
54 image = image.rotate(-90)
55 elif orientation == 8:
56 image = image.rotate(90)
57 else:
58 raise Exception("unknown orientation %s" % orientation)
59 return image
60
61 def pack(self, size, focus=False):
62 cols = size[0]
63 if len(size) > 1:
64 rows = size[1]
65 elif self.hinter:
66 rows = self.hinter.getSize()[1]
67 else:
68 rows = None
69 width = cols
70 height = int(cols*(1.0/self.ratio)/2.0)
71 if rows is not None and height > rows:
72 height = rows
73 width = int(rows*self.ratio*2.0)
74 return (width, height)
75
76 def rows(self, size, focus=False):
77 r = self.pack(size)
78 return r[1]
79
80 SPAN_RE = re.compile(r"<span style='color:#(......); background-color:#(......);'>(.*)")
81 def render(self, size, focus=False):
82 spanre = self.SPAN_RE
83 htmlparser = self.htmlparser
84 width, height = self.pack(size, focus)
85 jp2a = subprocess.Popen(['jp2a', '--colors', '--fill',
86 '--width=%s' % width,
87 '--height=%s' % height,
88 '--html-raw', '-'],
89 stdin=subprocess.PIPE,
90 stdout=subprocess.PIPE,
91 stderr=subprocess.PIPE)
92 image = self._loadImage()
93 image.save(jp2a.stdin, 'JPEG')
94 jp2a.stdin.close()
95 data = jp2a.stdout.read()
96 jp2a.stderr.read()
97 jp2a.wait()
98
99 line_list = []
100 attr_list = []
101 line_text = ''
102 line_attrs = []
103 current_attr = [None, 0]
104 current_fg = None
105 current_bg = None
106 current_props = None
107 for line in data.split('<br/>'):
108 if not line:
109 continue
110 for span in line.split('</span>'):
111 if not span:
112 continue
113 m = spanre.match(span)
114 fg, bg, char = m.groups()
115 if '&' in char:
116 char = htmlparser.unescape(char)
117 char = char.encode('utf8')
118 line_text += char
119 props = []
120 # TODO: if bold is set, append bold to props
121 fg = ('#'+
122 nearest_color(int(fg[0:2], 16)) +
123 nearest_color(int(fg[2:4], 16)) +
124 nearest_color(int(fg[4:6], 16)))
125 bg = ('#'+
126 nearest_color(int(bg[0:2], 16)) +
127 nearest_color(int(bg[2:4], 16)) +
128 nearest_color(int(bg[4:6], 16)))
129 if current_fg == fg and current_bg == bg and current_props == props:
130 current_attr[1] += len(char)
131 else:
132 if current_attr[0]:
133 line_attrs.append(tuple(current_attr))
134 fg = ', '.join(props + [fg])
135 attr = urwid.AttrSpec(fg, bg)
136 current_attr = [attr, len(char)]
137 current_fg = fg
138 current_bg = bg
139 current_props = props
140 line_attrs.append(tuple(current_attr))
141 current_attr = [None, 0]
142 current_fg = None
143 current_bg = None
144 line_list.append(line_text)
145 line_text = ''
146 attr_list.append(line_attrs)
147 line_attrs = []
148 canvas = urwid.TextCanvas(line_list, attr_list)
149 return canvas
150
151def main():
152 import PIL.Image
153 img = PIL.Image.open('/tmp/p/8.jpg')
154 img.load()
155 hinter = slide.ScreenHinter()
156 hinter.set_cols_rows((80, 25))
157 w = ANSIImage(img, hinter)
158 slpile = slide.SlidePile([])
159 slpile.contents.append((w, slpile.options()))
160 pad = slide.SlidePadding(slpile, align='center', width='pack')
161 fill = slide.SlideFiller(pad)
162 #w.render((80,25))
163 fill.render((80,25))
164 screen = urwid.raw_display.Screen()
165 if True:
166 with screen.start():
167 screen.draw_screen((80,25), fill.render((80,25)))
168 raw_input()
diff --git a/presentty/palette.py b/presentty/palette.py
new file mode 100644
index 0000000..6079a95
--- /dev/null
+++ b/presentty/palette.py
@@ -0,0 +1,78 @@
1# Copyright (C) 2015 James E. Blair <corvus@gnu.org>
2#
3# This program is free software: you can redistribute it and/or modify
4# it under the terms of the GNU General Public License as published by
5# the Free Software Foundation, either version 3 of the License, or
6# (at your option) any later version.
7#
8# This program is distributed in the hope that it will be useful,
9# but WITHOUT ANY WARRANTY; without even the implied warranty of
10# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11# GNU General Public License for more details.
12#
13# You should have received a copy of the GNU General Public License
14# along with this program. If not, see <http://www.gnu.org/licenses/>.
15
16import urwid
17
18DARK_PALETTE = {
19 '_default': urwid.AttrSpec('light gray', 'black'),
20
21 'emphasis': urwid.AttrSpec('bold, light gray', 'black'),
22 'title': urwid.AttrSpec('bold, white', 'black'),
23
24 'progressive': urwid.AttrSpec('dark gray', 'black'),
25
26 # Based on pygments default colors
27
28 'whitespace': urwid.AttrSpec('light gray', '#aaa'),
29 'comment': urwid.AttrSpec('#688', 'black'),
30 'comment-preproc': urwid.AttrSpec('#a80', 'black'),
31 'keyword': urwid.AttrSpec('bold, #0f0', 'black'),
32 'keyword-pseudo': urwid.AttrSpec('#080', 'black'),
33 'keyword-type': urwid.AttrSpec('#a06', 'black'),
34 'operator': urwid.AttrSpec('#666', 'black'),
35 'operator-word': urwid.AttrSpec('bold, #a0f', 'black'),
36 'name-builtin': urwid.AttrSpec('#0d0', 'black'),
37 'name-function': urwid.AttrSpec('#00f', 'black'),
38 'name-class': urwid.AttrSpec('bold, #00f', 'black'),
39 'name-namespace': urwid.AttrSpec('bold, #00f', 'black'),
40 'name-exception': urwid.AttrSpec('bold, #d66', 'black'),
41 'name-variable': urwid.AttrSpec('#008', 'black'),
42 'name-constant': urwid.AttrSpec('#800', 'black'),
43 'name-label': urwid.AttrSpec('#aa0', 'black'),
44 'name-entity': urwid.AttrSpec('bold, #888', 'black'),
45 'name-attribute': urwid.AttrSpec('#880', 'black'),
46 'name-tag': urwid.AttrSpec('bold, #080', 'black'),
47 'name-decorator': urwid.AttrSpec('#a0f', 'black'),
48 'string': urwid.AttrSpec('#a00', 'black'),
49 'string-doc': urwid.AttrSpec('light gray', 'black'),
50 'string-interpol': urwid.AttrSpec('bold, #a68', 'black'),
51 'string-escape': urwid.AttrSpec('bold, #a60', 'black'),
52 'string-regex': urwid.AttrSpec('#a68', 'black'),
53 'string-symbol': urwid.AttrSpec('#008', 'black'),
54 'string-other': urwid.AttrSpec('#080', 'black'),
55 'number': urwid.AttrSpec('#666', 'black'),
56 'generic-heading': urwid.AttrSpec('bold, #008', 'black'),
57 'generic-subheading': urwid.AttrSpec('bold, #808', 'black'),
58 'generic-deleted': urwid.AttrSpec('#a00', 'black'),
59 'generic-inserted': urwid.AttrSpec('#0a0', 'black'),
60 'generic-error': urwid.AttrSpec('#f00', 'black'),
61 'generic-emph': urwid.AttrSpec('bold, #fff', 'black'),
62 'generic-strong': urwid.AttrSpec('bold, #ddd', 'black'),
63 'generic-prompt': urwid.AttrSpec('bold, #008', 'black'),
64 'generic-output': urwid.AttrSpec('#888', 'black'),
65 'generic-traceback': urwid.AttrSpec('#06d', 'black'),
66 'error': urwid.AttrSpec('underline, #f00', 'black'),
67}
68
69LIGHT_PALETTE = {}
70for k, v in DARK_PALETTE.items():
71 LIGHT_PALETTE[k] = urwid.AttrSpec(v.foreground, 'h15')
72
73LIGHT_PALETTE.update({
74 '_default': urwid.AttrSpec('black', 'h15'),
75 'emphasis': urwid.AttrSpec('bold, black', 'h15'),
76 'title': urwid.AttrSpec('bold, #000', 'h15'),
77 'progressive': urwid.AttrSpec('light gray', 'h15'),
78})
diff --git a/presentty/presentty.py b/presentty/presentty.py
new file mode 100644
index 0000000..35e19c1
--- /dev/null
+++ b/presentty/presentty.py
@@ -0,0 +1,162 @@
1# Copyright (C) 2015 James E. Blair <corvus@gnu.org>
2#
3# This program is free software: you can redistribute it and/or modify
4# it under the terms of the GNU General Public License as published by
5# the Free Software Foundation, either version 3 of the License, or
6# (at your option) any later version.
7#
8# This program is distributed in the hope that it will be useful,
9# but WITHOUT ANY WARRANTY; without even the implied warranty of
10# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11# GNU General Public License for more details.
12#
13# You should have received a copy of the GNU General Public License
14# along with this program. If not, see <http://www.gnu.org/licenses/>.
15
16import argparse
17import os
18import sys
19import time
20
21import urwid
22
23import slide
24import server
25import rst
26import palette
27
28
29class Presenter(object):
30 def __init__(self, palette):
31 blank = urwid.Text(u'')
32 self.blank = slide.UrwidSlide('Blank', None, blank,
33 palette['_default'])
34 self.current = self.blank
35 self.program = []
36 self.palette = palette
37 self.pos = -1
38 self.loop = urwid.MainLoop(self.blank,
39 unhandled_input=self.unhandledInput)
40 self.loop.screen.set_terminal_properties(colors=256)
41
42 self.server_pipe_in = self.loop.watch_pipe(self.serverData)
43 r,w = os.pipe()
44 self.server_pipe_out_read = os.fdopen(r)
45 self.server_pipe_out_write = w
46 self.server = server.ConsoleServer(self)
47 self.server.start()
48
49 def serverData(self, data):
50 parts = data.split()
51 if parts[0] == 'jump':
52 try:
53 index = int(parts[1])
54 except Exception:
55 os.write(self.server_pipe_out_write, 'err\n')
56 return
57 if index < 0 or index > len(self.program)-1:
58 os.write(self.server_pipe_out_write, 'err\n')
59 return
60 self.transitionTo(index)
61 os.write(self.server_pipe_out_write, 'ok\n')
62 elif parts[0] == 'next':
63 self.nextSlide()
64 os.write(self.server_pipe_out_write, 'ok\n')
65 elif parts[0] == 'prev':
66 self.prevSlide()
67 os.write(self.server_pipe_out_write, 'ok\n')
68
69 def setProgram(self, program):
70 self.program = program
71
72 def run(self):
73 self.loop.set_alarm_in(0, self.nextSlide)
74 self.loop.run()
75
76 def unhandledInput(self, key):
77 if key in ('right', 'page down'):
78 self.nextSlide()
79 elif key in ('left', 'page up'):
80 self.prevSlide()
81
82 def transitionTo(self, index, forward=True):
83 self.pos = index
84 current_slide = self.current
85 new_slide = self.program[index]
86 if forward:
87 transition = new_slide.transition
88 new_slide.resetProgressive()
89 else:
90 transition = current_slide.transition
91 new_slide.resetProgressive(True)
92 current_slide.stopAnimation()
93 if forward:
94 transition.setTargets(current_slide, new_slide)
95 else:
96 transition.setTargets(new_slide, current_slide)
97 self.loop.widget = transition
98 duration = transition.getDuration()
99 start = time.time()
100 now = start
101 end = start + duration
102 while duration:
103 if forward:
104 progress = min(1-((end-now)/duration), 1.0)
105 else:
106 progress = max(((end-now)/duration), 0.0)
107 transition.setProgress(progress)
108 self.loop.draw_screen()
109 now = time.time()
110 if now >= end:
111 break
112 end = time.time()
113 self.loop.widget = new_slide
114 self.current = new_slide
115 self.loop.draw_screen()
116 current_slide.resetAnimation()
117 new_slide.startAnimation(self.loop)
118
119 def nextSlide(self, loop=None, data=None):
120 if self.current.nextProgressive():
121 return
122 if self.pos+1 == len(self.program):
123 return
124 self.transitionTo(self.pos+1)
125
126 def prevSlide(self, loop=None, data=None):
127 if self.current.prevProgressive():
128 return
129 if self.pos == 0:
130 return
131 self.transitionTo(self.pos-1, forward=False)
132
133def main():
134 parser = argparse.ArgumentParser(
135 description='Console-based presentation system')
136 parser.add_argument('--light', dest='light',
137 default=False,
138 action='store_true',
139 help='use a black on white palette')
140 parser.add_argument('--warnings', dest='warnings',
141 default=False,
142 action='store_true',
143 help='print RST parser warnings and exit if any')
144 parser.add_argument('file',
145 help='presentation file (RST)')
146 args = parser.parse_args()
147 if args.light:
148 plt = palette.LIGHT_PALETTE
149 else:
150 plt = palette.DARK_PALETTE
151 hinter = slide.ScreenHinter()
152 parser = rst.PresentationParser(plt, hinter)
153 program = parser.parse(open(args.file).read(), args.file)
154 if args.warnings:
155 w = parser.warnings.getvalue()
156 if w:
157 print w
158 sys.exit(1)
159 p = Presenter(plt)
160 p.setProgram(program)
161 hinter.setScreen(p.loop.screen)
162 p.run()
diff --git a/presentty/rst.py b/presentty/rst.py
new file mode 100644
index 0000000..41b3f97
--- /dev/null
+++ b/presentty/rst.py
@@ -0,0 +1,493 @@
1# Copyright (C) 2015 James E. Blair <corvus@gnu.org>
2#
3# This program is free software: you can redistribute it and/or modify
4# it under the terms of the GNU General Public License as published by
5# the Free Software Foundation, either version 3 of the License, or
6# (at your option) any later version.
7#
8# This program is distributed in the hope that it will be useful,
9# but WITHOUT ANY WARRANTY; without even the implied warranty of
10# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11# GNU General Public License for more details.
12#
13# You should have received a copy of the GNU General Public License
14# along with this program. If not, see <http://www.gnu.org/licenses/>.
15
16import os
17import re
18import docutils
19import docutils.frontend
20import docutils.parsers.rst
21import docutils.nodes
22import cStringIO as StringIO
23
24import urwid
25
26import slide
27import transition as transition_mod
28import image
29import ansiparser
30import text
31
32try:
33 import PIL
34 import PIL.Image
35except ImportError:
36 PIL = None
37
38DEFAULT_TRANSITION = 'dissolve'
39DEFAULT_TRANSITION_DURATION = 0.4
40
41class TextAccumulator(object):
42 def __init__(self):
43 self.text = []
44
45 def append(self, text):
46 self.text.append(text)
47
48 def getFormattedText(self):
49 return self.text
50
51 wsre = re.compile('\s+')
52
53 def getFlowedText(self):
54 ret = []
55 for part in self.text:
56 if isinstance(part, tuple):
57 ret.append((part[0], self.wsre.sub(u' ', part[1])))
58 else:
59 ret.append(self.wsre.sub(u' ', part))
60 if not ret:
61 return u''
62 return ret
63
64class UrwidTranslator(docutils.nodes.GenericNodeVisitor):
65 transition_map = {'dissolve': transition_mod.DissolveTransition,
66 'cut': transition_mod.CutTransition,
67 'pan': transition_mod.PanTransition,
68 }
69
70 def __init__(self, document, palette, hinter=None, basedir='.'):
71 docutils.nodes.GenericNodeVisitor.__init__(self, document)
72 self.program = []
73 self.stack = []
74 self.default_transition = self._make_transition(
75 DEFAULT_TRANSITION,
76 DEFAULT_TRANSITION_DURATION)
77 self.transition = self.default_transition
78 self.attr = []
79 self.table_columns = []
80 self.table_column = []
81 self.progressives = []
82 self.palette = palette
83 self.hinter = hinter
84 self.basedir = basedir
85 self.slide = None
86 self.default_hide_title = False
87 self.hide_title = self.default_hide_title
88
89 def _make_transition(self, name, duration):
90 tr = self.transition_map[name]
91 return tr(duration)
92
93 def default_visit(self, node):
94 """Override for generic, uniform traversals."""
95 pass
96
97 def default_departure(self, node):
98 """Override for generic, uniform traversals."""
99 pass
100
101 def _append(self, node, widget, *args, **kw):
102 if self.stack:
103 if 'handout' in node.get('classes'):
104 if self.handout_pile not in self.stack:
105 container = self.handout_pile
106 else:
107 # If the handout pile is in the stack, then ignore
108 # this class -- it has probably needlessly been
109 # applied to something deeper in the stack. The
110 # thing further up will end up in the handout.
111 container = self.stack[-1]
112 else:
113 container = self.stack[-1]
114 container.contents.append((widget, container.options(*args, **kw)))
115
116 def styled(self, style, text):
117 if style in self.palette:
118 return (self.palette[style], text)
119 return text
120
121 def visit_transition(self, node):
122 name = node['name']
123 duration = node.get('duration', DEFAULT_TRANSITION_DURATION)
124 self.transition = self._make_transition(name, duration)
125
126 def depart_transition(self, node):
127 pass
128
129 def visit_hidetitle(self, node):
130 if self.slide:
131 self.hide_title = True
132 else:
133 self.default_hide_title = True
134
135 def depart_hidetitle(self, node):
136 pass
137
138 def visit_system_message(self, node):
139 #print node.astext()
140 raise docutils.nodes.SkipNode()
141
142 def visit_section(self, node):
143 self.hide_title = self.default_hide_title
144 self.transition = self.default_transition
145 title_pile = slide.SlidePile([])
146 title_pad = slide.SlidePadding(title_pile,
147 align='center', width='pack')
148
149 main_pile = slide.SlidePile([])
150 main_pad = slide.SlidePadding(main_pile, align='center', width='pack')
151 outer_pile = slide.SlidePile([
152 ('pack', title_pad),
153 ('pack', main_pad),
154 ])
155 s = slide.UrwidSlide(u'', self.transition, outer_pile,
156 self.palette['_default'])
157 self.slide = s
158 self.stack.append(main_pile)
159 self.title_pile = title_pile
160
161 pile = slide.SlidePile([])
162 s = slide.Handout(pile, self.palette['_default'])
163 self.handout = s
164 self.handout_pile = pile
165 self.slide.handout = s
166
167 def depart_section(self, node):
168 self.slide.transition = self.transition
169 if self.hide_title:
170 self.title_pile.contents[:] = []
171 self.program.append(self.slide)
172 self.stack.pop()
173
174 def visit_block_quote(self, node):
175 self.stack.append(slide.SlidePile([]))
176
177 def depart_block_quote(self, node):
178 pile = self.stack.pop()
179 pad = slide.SlidePadding(pile, left=2)
180 self._append(node, pad, 'pack')
181
182 def visit_list_item(self, node):
183 self.stack.append(slide.SlidePile([]))
184
185 def depart_list_item(self, node):
186 pile = self.stack.pop()
187 bullet = urwid.Text(u'* ')
188 cols = slide.SlideColumns([])
189 cols.contents.append((bullet, cols.options('pack')))
190 cols.contents.append((pile, cols.options('weight', 1)))
191 if self.progressives:
192 cols = urwid.AttrMap(cols, self.palette['progressive'])
193 self.progressives[-1].append(cols)
194 self._append(node, cols, 'pack')
195
196 def visit_tgroup(self, node):
197 self.table_columns.append([])
198 self.stack.append(slide.SlidePile([]))
199
200 def visit_colspec(self, node):
201 self.table_columns[-1].append(node['colwidth'])
202
203 def visit_row(self, node):
204 self.stack.append(slide.SlideColumns([], dividechars=1))
205 self.table_column.append(0)
206
207 def depart_row(self, node):
208 self.table_column.pop()
209 cols = self.stack.pop()
210 self._append(node, cols, 'pack')
211
212 def visit_thead(self, node):
213 pass
214
215 def depart_thead(self, node):
216 cols = slide.SlideColumns([], dividechars=1)
217 for width in self.table_columns[-1]:
218 cols.contents.append((urwid.Text(u'='*width),
219 cols.options('given', width)))
220 self._append(node, cols, 'pack')
221
222 def visit_entry(self, node):
223 self.stack.append(slide.SlidePile([]))
224
225 def depart_entry(self, node):
226 colindex = self.table_column[-1]
227 self.table_column[-1] = colindex + 1
228 pile = self.stack.pop()
229 self._append(node, pile, 'given', self.table_columns[-1][colindex])
230
231 def depart_tgroup(self, node):
232 self.table_columns.pop()
233 pile = self.stack.pop()
234 self._append(node, pile, 'pack')
235
236 def visit_textelement(self, node):
237 self.stack.append(TextAccumulator())
238
239 visit_paragraph = visit_textelement
240
241 def depart_paragraph(self, node):
242 text = self.stack.pop()
243 self._append(node, urwid.Text(text.getFlowedText()), 'pack')
244
245 visit_literal_block = visit_textelement
246
247 def depart_literal_block(self, node):
248 text = self.stack.pop()
249 text = urwid.Text(text.getFormattedText(), wrap='clip')
250 pad = slide.SlidePadding(text, width='pack')
251 self._append(node, pad, 'pack')
252
253 visit_line = visit_textelement
254
255 def depart_line(self, node):
256 text = self.stack.pop()
257 self._append(node, urwid.Text(text.getFormattedText(), wrap='clip'),
258 'pack')
259
260 visit_title = visit_textelement
261
262 def depart_title(self, node):
263 text = self.stack.pop()
264 self.slide.title = node.astext()
265 widget = urwid.Text(self.styled('title', text.getFlowedText()),
266 align='center')
267 self.title_pile.contents.append(
268 (widget, self.title_pile.options('pack')))
269
270 def visit_Text(self, node):
271 pass
272
273 def depart_Text(self, node):
274 if self.stack and isinstance(self.stack[-1], TextAccumulator):
275 if self.attr:
276 t = (self.attr[-1], node.astext())
277 else:
278 t = node.astext()
279 self.stack[-1].append(t)
280
281 def visit_emphasis(self, node):
282 self.attr.append(self.palette['emphasis'])
283
284 def depart_emphasis(self, node):
285 self.attr.pop()
286
287 def visit_inline(self, node):
288 cls = node.get('classes')
289 if not cls:
290 raise docutils.nodes.SkipDeparture()
291 cls = [x for x in cls if x != 'literal']
292 for length in range(len(cls), 0, -1):
293 clsname = '-'.join(cls[:length])
294 if clsname in self.palette:
295 self.attr.append(self.palette[clsname])
296 return
297 raise docutils.nodes.SkipDeparture()
298
299 def depart_inline(self, node):
300 self.attr.pop()
301
302 def visit_image(self, node):
303 if not PIL:
304 return
305 uri = node['uri']
306 fn = os.path.join(self.basedir, uri)
307 w = image.ANSIImage(fn, self.hinter)
308 self._append(node, w, 'pack')
309
310 def visit_ansi(self, node):
311 interval = node.get('interval', 0.5)
312 oneshot = node.get('oneshot', False)
313 animation = slide.AnimatedText(interval, oneshot)
314 for name in node['names']:
315 p = ansiparser.ANSIParser()
316 fn = os.path.join(self.basedir, name)
317 data = unicode(open(fn).read(), 'utf8')
318 text = p.parse(data)
319 animation.addFrame(text)
320 self.slide.animations.append(animation)
321 self._append(node, animation, 'pack')
322
323 def depart_ansi(self, node):
324 pass
325
326 def visit_figlet(self, node):
327 figlet = text.FigletText(node['text'])
328 self._append(node, figlet, 'pack')
329
330 def depart_figlet(self, node):
331 pass
332
333 def visit_cowsay(self, node):
334 cowsay = text.CowsayText(node['text'])
335 self._append(node, cowsay, 'pack')
336
337 def depart_cowsay(self, node):
338 pass
339
340 def visit_container(self, node):
341 self.stack.append(slide.SlidePile([]))
342 if 'progressive' in node.get('classes'):
343 self.progressives.append(self.slide.progressives)
344 self.slide.progressive_attr = self.palette['progressive']
345
346 def depart_container(self, node):
347 pile = self.stack.pop()
348 self._append(node, pile, 'pack')
349 if 'progressive' in node.get('classes'):
350 self.progressives.pop()
351
352class TransitionDirective(docutils.parsers.rst.Directive):
353 required_arguments = 1
354 option_spec = {'duration': float}
355 has_content = False
356
357 def run(self):
358 args = {'name': self.arguments[0]}
359 duration = self.options.get('duration')
360 if duration:
361 args['duration'] = duration
362 node = transition(**args)
363 return [node]
364
365class ANSIDirective(docutils.parsers.rst.Directive):
366 required_arguments = 1
367 final_argument_whitespace = True
368 option_spec = {'interval': float,
369 'oneshot': bool}
370 has_content = False
371
372 def run(self):
373 args = {'names': self.arguments[0].split()}
374 args.update(self.options)
375 node = ansi(**args)
376 return [node]
377
378class FigletDirective(docutils.parsers.rst.Directive):
379 required_arguments = 1
380 has_content = False
381 final_argument_whitespace = True
382
383 def run(self):
384 args = {'text': self.arguments[0]}
385 node = figlet(**args)
386 return [node]
387
388class CowsayDirective(docutils.parsers.rst.Directive):
389 required_arguments = 1
390 has_content = False
391 final_argument_whitespace = True
392
393 def run(self):
394 args = {'text': self.arguments[0]}
395 node = cowsay(**args)
396 return [node]
397
398class HideTitleDirective(docutils.parsers.rst.Directive):
399 has_content = False
400
401 def run(self):
402 node = hidetitle()
403 return [node]
404
405class transition(docutils.nodes.Special, docutils.nodes.Invisible,
406 docutils.nodes.Element):
407 pass
408
409class ansi(docutils.nodes.General, docutils.nodes.Inline,
410 docutils.nodes.Element):
411 pass
412
413class figlet(docutils.nodes.General, docutils.nodes.Inline,
414 docutils.nodes.Element):
415 pass
416
417class cowsay(docutils.nodes.General, docutils.nodes.Inline,
418 docutils.nodes.Element):
419 pass
420
421class hidetitle(docutils.nodes.Special, docutils.nodes.Invisible,
422 docutils.nodes.Element):
423 pass
424
425class PresentationParser(object):
426 def __init__(self, palette, hinter=None):
427 docutils.parsers.rst.directives.register_directive(
428 'transition', TransitionDirective)
429 docutils.parsers.rst.directives.register_directive(
430 'ansi', ANSIDirective)
431 docutils.parsers.rst.directives.register_directive(
432 'figlet', FigletDirective)
433 docutils.parsers.rst.directives.register_directive(
434 'cowsay', CowsayDirective)
435 docutils.parsers.rst.directives.register_directive(
436 'hidetitle', HideTitleDirective)
437 self.warnings = StringIO.StringIO()
438 self.settings = docutils.frontend.OptionParser(
439 components=(docutils.parsers.rst.Parser,),
440 defaults=dict(warning_stream=self.warnings)).get_default_values()
441 self.parser = docutils.parsers.rst.Parser()
442 self.palette = palette
443 self.hinter = hinter
444
445 def _parse(self, input, filename):
446 document = docutils.utils.new_document(filename, self.settings)
447 self.parser.parse(input, document)
448 visitor = UrwidTranslator(document, self.palette, self.hinter,
449 os.path.dirname(filename))
450 document.walkabout(visitor)
451 return document, visitor
452
453 def parse(self, input, filename='program'):
454 document, visitor = self._parse(input, filename)
455 return visitor.program
456
457def main():
458 import argparse
459 import palette
460
461 argp = argparse.ArgumentParser(description='Test RST parser')
462 argp.add_argument('file', help='presentation file (RST)')
463 argp.add_argument('slides', nargs='?', default=[],
464 help='slides to render')
465 argp.add_argument('--render', action='store_true',
466 help='Fully render a slide')
467 args = argp.parse_args()
468
469 parser = PresentationParser(palette.DARK_PALETTE)
470 document, visitor = parser._parse(open(args.file).read(), args.file)
471
472 slides = args.slides
473 if not slides:
474 slides = range(len(visitor.program))
475 slides = [int(x) for x in slides]
476
477 if not args.render:
478 print document.pformat()
479 for i in slides:
480 print '-'*80
481 s = visitor.program[i]
482 for line in s.render((80,25)).text:
483 print line
484 else:
485 screen = urwid.raw_display.Screen()
486 with screen.start():
487 for i in slides:
488 s = visitor.program[i]
489 screen.draw_screen((80,25), s.render((80,25)))
490 raw_input()
491
492if __name__ == '__main__':
493 main()
diff --git a/presentty/server.py b/presentty/server.py
new file mode 100644
index 0000000..74e64b2
--- /dev/null
+++ b/presentty/server.py
@@ -0,0 +1,112 @@
1# Copyright (C) 2015 James E. Blair <corvus@gnu.org>
2#
3# This program is free software: you can redistribute it and/or modify
4# it under the terms of the GNU General Public License as published by
5# the Free Software Foundation, either version 3 of the License, or
6# (at your option) any later version.
7#
8# This program is distributed in the hope that it will be useful,
9# but WITHOUT ANY WARRANTY; without even the implied warranty of
10# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11# GNU General Public License for more details.
12#
13# You should have received a copy of the GNU General Public License
14# along with this program. If not, see <http://www.gnu.org/licenses/>.
15
16import os
17import threading
18import SocketServer
19
20class ConsoleHandler(SocketServer.StreamRequestHandler):
21 def handle(self):
22 server = self.server.server
23 while True:
24 try:
25 data = self.rfile.readline()
26 except Exception:
27 break
28 if not data:
29 break
30 data = data.strip()
31 if data == 'list':
32 for i, slide in enumerate(server.list()):
33 self.wfile.write('slide %i %s\n' % (i, slide.title))
34 self.wfile.write('end\n')
35 elif data == 'current':
36 i, slide = server.current()
37 self.wfile.write('current %i %i %s\n' % (
38 i, slide.progressive_state, slide.title))
39 elif data == 'next':
40 i, slide = server.next()
41 self.wfile.write('current %i %i %s\n' % (
42 i, slide.progressive_state, slide.title))
43 elif data == 'prev':
44 i, slide = server.prev()
45 self.wfile.write('current %i %i %s\n' % (
46 i, slide.progressive_state, slide.title))
47 elif data.startswith('jump'):
48 parts = data.split()
49 i, slide = server.jump(int(parts[1].strip()))
50 self.wfile.write('current %i %i %s\n' % (
51 i, slide.progressive_state, slide.title))
52 elif data == 'size':
53 size = server.size()
54 self.wfile.write('size %s %s\n' % size)
55
56class ThreadedTCPServer(SocketServer.ThreadingMixIn, SocketServer.TCPServer):
57 allow_reuse_address=True
58
59class ConsoleServer(object):
60 def __init__(self, presenter, host='localhost', port=1292):
61 self.presenter = presenter
62 self.server = ThreadedTCPServer((host, port), ConsoleHandler)
63 self.server.server = self
64 self.lock = threading.Lock()
65
66 def start(self):
67 self.thread=threading.Thread(target=self._run, name="Console Server")
68 self.thread.daemon=True
69 self.thread.start()
70
71 def _run(self):
72 self.server.serve_forever()
73
74 def stop(self):
75 self.server.shutdown()
76
77 def list(self):
78 return self.presenter.program
79
80 def current(self):
81 s = self.presenter.program[self.presenter.pos]
82 return (self.presenter.pos, s)
83
84 def size(self):
85 return self.presenter.loop.screen.get_cols_rows()
86
87 def next(self):
88 self.lock.acquire()
89 try:
90 os.write(self.presenter.server_pipe_in, 'next')
91 self.presenter.server_pipe_out_read.readline()
92 return self.current()
93 finally:
94 self.lock.release()
95
96 def prev(self):
97 self.lock.acquire()
98 try:
99 os.write(self.presenter.server_pipe_in, 'prev')
100 self.presenter.server_pipe_out_read.readline()
101 return self.current()
102 finally:
103 self.lock.release()
104
105 def jump(self, pos):
106 self.lock.acquire()
107 try:
108 os.write(self.presenter.server_pipe_in, 'jump %s' % (pos,))
109 self.presenter.server_pipe_out_read.readline()
110 return self.current()
111 finally:
112 self.lock.release()
diff --git a/presentty/slide.py b/presentty/slide.py
new file mode 100644
index 0000000..4894f45
--- /dev/null
+++ b/presentty/slide.py
@@ -0,0 +1,178 @@
1# Copyright (C) 2015 James E. Blair <corvus@gnu.org>
2#
3# This program is free software: you can redistribute it and/or modify
4# it under the terms of the GNU General Public License as published by
5# the Free Software Foundation, either version 3 of the License, or
6# (at your option) any later version.
7#
8# This program is distributed in the hope that it will be useful,
9# but WITHOUT ANY WARRANTY; without even the implied warranty of
10# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11# GNU General Public License for more details.
12#
13# You should have received a copy of the GNU General Public License
14# along with this program. If not, see <http://www.gnu.org/licenses/>.
15
16import urwid
17
18class SlidePile(urwid.Pile):
19 def pack(self, size, focus=False):
20 cols = 0
21 rows = 0
22 for x in self.contents:
23 c,r = x[0].pack((size[0],))
24 if c>cols:
25 cols = c
26 rows += r
27 return (cols, rows)
28
29class SlidePadding(urwid.Padding):
30 def pack(self, size, focus=False):
31 r = self._original_widget.pack(size, focus)
32 width = max(r[0] + self.left + self.right, self.min_width)
33 width = min(size[0], width)
34 return (width, r[1])
35
36class SlideColumns(urwid.Columns):
37 def pack(self, size, focus=False):
38 cols = self.dividechars * (len(self.contents)-1)
39 rows = 0
40 for widget, packing in self.contents:
41 if packing[0] == 'given':
42 allocated_cols = packing[1]
43 else:
44 allocated_cols = size[0]
45 c,r = widget.pack((allocated_cols,))
46 if packing[0] == 'given':
47 c = allocated_cols
48 if r>rows:
49 rows = r
50 cols += c
51 return (cols, rows)
52
53class SlideFiller(urwid.Filler):
54 pass
55
56class ScreenHinter(object):
57 # A terrible hack to try to provide some needed context to the
58 # image widget.
59 def __init__(self, screen=None):
60 self.screen = screen
61
62 def setScreen(self, screen):
63 self.screen = screen
64
65 def getSize(self):
66 cols, rows = self.screen.get_cols_rows()
67 return (cols, rows-1)
68
69class Handout(urwid.WidgetWrap):
70 def __init__(self, widget, background):
71 self.background = background
72 self.pad = SlidePadding(widget, align='center', width='pack')
73 self.map = urwid.AttrMap(self.pad, self.background)
74 super(Handout, self).__init__(self.map)
75
76class UrwidSlide(urwid.WidgetWrap):
77 def __init__(self, title, transition, widget, background):
78 self.title = title
79 self.transition = transition
80 self.fill = SlideFiller(widget)
81 self.background = background
82 self.map = urwid.AttrMap(self.fill, self.background)
83 self.handout = None
84 self.animations = []
85 self.progressives = []
86 self.progressive_attr = None
87 self.progressive_state = 0
88 super(UrwidSlide, self).__init__(self.map)
89
90 def startAnimation(self, loop):
91 for x in self.animations:
92 x.startAnimation(loop)
93
94 def stopAnimation(self):
95 for x in self.animations:
96 x.stopAnimation()
97
98 def resetAnimation(self):
99 for x in self.animations:
100 x.resetAnimation()
101
102 def resetProgressive(self, on=False):
103 if on:
104 self.progressive_state = len(self.progressives)
105 for x in self.progressives:
106 x.set_attr_map({None: None})
107 else:
108 self.progressive_state = 0
109 for x in self.progressives:
110 x.set_attr_map({None: self.progressive_attr})
111
112 def nextProgressive(self):
113 if self.progressive_state >= len(self.progressives):
114 return False
115 self.progressives[self.progressive_state].set_attr_map(
116 {None: None})
117 self.progressive_state += 1
118 return True
119
120 def prevProgressive(self):
121 if self.progressive_state <= 0:
122 return False
123 self.progressive_state -= 1
124 self.progressives[self.progressive_state].set_attr_map(
125 {None: self.progressive_attr})
126 return True
127
128 def setProgressive(self, state):
129 self.progressive_state = state
130 for i, x in enumerate(self.progressives):
131 if i < self.progressive_state:
132 x.set_attr_map({None: None})
133 else:
134 x.set_attr_map({None: self.progressive_attr})
135
136class AnimatedText(urwid.Text):
137 def __init__(self, interval=0.5, oneshot=False):
138 super(AnimatedText, self).__init__(u'')
139 self.frames = []
140 self.current = 0
141 self.running = False
142 self.interval = interval
143 self.oneshot = oneshot
144
145 def addFrame(self, text):
146 self.frames.append(text)
147 if len(self.frames) == self.current+1:
148 self.set_text(text)
149
150 def startAnimation(self, loop):
151 if self.running:
152 return
153 if len(self.frames) == 1:
154 return
155 self.running = True
156 loop.set_alarm_in(self.interval, self.updateCallback)
157
158 def updateCallback(self, loop=None, data=None):
159 if not self.running:
160 return
161 if self.current+1 >= len(self.frames):
162 if self.oneshot:
163 self.running = False
164 return
165 self.current = 0
166 else:
167 self.current += 1
168 self.set_text(self.frames[self.current])
169 loop.set_alarm_in(self.interval, self.updateCallback)
170
171 def stopAnimation(self):
172 if not self.running:
173 return
174 self.running = False
175
176 def resetAnimation(self):
177 self.current = 0
178 self.set_text(self.frames[self.current])
diff --git a/presentty/text.py b/presentty/text.py
new file mode 100644
index 0000000..e0a88fc
--- /dev/null
+++ b/presentty/text.py
@@ -0,0 +1,81 @@
1# Copyright (C) 2015 James E. Blair <corvus@gnu.org>
2#
3# This program is free software: you can redistribute it and/or modify
4# it under the terms of the GNU General Public License as published by
5# the Free Software Foundation, either version 3 of the License, or
6# (at your option) any later version.
7#
8# This program is distributed in the hope that it will be useful,
9# but WITHOUT ANY WARRANTY; without even the implied warranty of
10# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11# GNU General Public License for more details.
12#
13# You should have received a copy of the GNU General Public License
14# along with this program. If not, see <http://www.gnu.org/licenses/>.
15
16import subprocess
17
18import urwid
19
20class FigletText(urwid.WidgetWrap):
21 def __init__(self, text, attr=None):
22 self.text = text
23 self.attr = attr
24 output = self._run()
25 if attr:
26 widget = urwid.Text((attr, output), wrap='clip')
27 else:
28 widget = urwid.Text(output, wrap='clip')
29 super(FigletText, self).__init__(widget)
30
31 def _run(self):
32 p = subprocess.Popen(['figlet'],
33 stdin=subprocess.PIPE,
34 stdout=subprocess.PIPE,
35 stderr=subprocess.PIPE)
36 p.stdin.write(self.text)
37 p.stdin.close()
38 data = p.stdout.read()
39 p.stderr.read()
40 p.wait()
41 return data
42
43class CowsayText(urwid.WidgetWrap):
44 def __init__(self, text, attr=None):
45 self.text = text
46 self.attr = attr
47 output = self._run()
48 if attr:
49 widget = urwid.Text((attr, output), wrap='clip')
50 else:
51 widget = urwid.Text(output, wrap='clip')
52 super(CowsayText, self).__init__(widget)
53
54 def _run(self):
55 p = subprocess.Popen(['cowsay'],
56 stdin=subprocess.PIPE,
57 stdout=subprocess.PIPE,
58 stderr=subprocess.PIPE)
59 p.stdin.write(self.text)
60 p.stdin.close()
61 data = p.stdout.read()
62 p.stderr.read()
63 p.wait()
64 return data
65
66def main():
67 import slide
68 w = FigletText("Testing")
69 slpile = slide.SlidePile([])
70 slpile.contents.append((w, slpile.options()))
71 pad = slide.SlidePadding(slpile, align='center', width='pack')
72 fill = slide.SlideFiller(pad)
73 #w.render((80,25))
74 fill.render((80,25))
75 screen = urwid.raw_display.Screen()
76 if True:
77 with screen.start():
78 screen.draw_screen((80,25), fill.render((80,25)))
79 raw_input()
80if __name__=='__main__':
81 main()
diff --git a/presentty/transition.py b/presentty/transition.py
new file mode 100644
index 0000000..9133629
--- /dev/null
+++ b/presentty/transition.py
@@ -0,0 +1,153 @@
1# Copyright (C) 2015 James E. Blair <corvus@gnu.org>
2#
3# This program is free software: you can redistribute it and/or modify
4# it under the terms of the GNU General Public License as published by
5# the Free Software Foundation, either version 3 of the License, or
6# (at your option) any later version.
7#
8# This program is distributed in the hope that it will be useful,
9# but WITHOUT ANY WARRANTY; without even the implied warranty of
10# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11# GNU General Public License for more details.
12#
13# You should have received a copy of the GNU General Public License
14# along with this program. If not, see <http://www.gnu.org/licenses/>.
15
16import urwid
17
18class Transition(urwid.Widget):
19 def __init__(self, duration=0.4):
20 super(Transition, self).__init__()
21 self.duration = 0.4
22 self.old = None
23 self.new = None
24 self.progress = 0.0
25
26 def getDuration(self):
27 return self.duration
28
29 def setTargets(self, old, new):
30 self.old = old
31 self.new = new
32 self.setProgress(0.0)
33
34 def setProgress(self, progress):
35 self.progress = progress
36 self._invalidate()
37
38class PanTransition(Transition):
39 def render(self, size, focus=False):
40 old = self.old.render((size[0], size[1]))
41 new = self.new.render((size[0], size[1]))
42 c = urwid.CanvasJoin([(old, None, False, size[0]),
43 (new, None, False, size[0])])
44 #c = urwid.CanvasOverlay(new, old, 6, 0)
45 offset = int(size[0] * self.progress)
46 c.pad_trim_left_right(0-offset, 0-(size[0]-offset))
47 return c
48
49class DissolveTransition(Transition):
50 def __init__(self, *args, **kw):
51 super(DissolveTransition, self).__init__(*args, **kw)
52 self._oldbuf = None
53 self._newbuf = None
54 self._cache_size = None
55
56 def setTargets(self, old, new):
57 if old != self.old:
58 self._oldbuf = None
59 self._cache_size = None
60 if new != self.new:
61 self._newbuf = None
62 self._cache_size = None
63 super(DissolveTransition, self).setTargets(old, new)
64
65 def _to_buf(self, canvas):
66 buf = []
67 for line in canvas.content():
68 for (attr, cs, text) in line:
69 for char in unicode(text, 'utf8'):
70 buf.append((attr, cs, char))
71 return buf
72
73 def render(self, size, focus=False):
74 if self._cache_size != size:
75 old = self.old.render((size[0], size[1]))
76 new = self.new.render((size[0], size[1]))
77 self._oldbuf = self._to_buf(old)
78 self._newbuf = self._to_buf(new)
79 self._cache_size = size
80 line_list = []
81 attr_list = []
82 line_text = ''
83 line_attrs = []
84 current_attr = [None, 0]
85 current_rgb = None
86 current_props = None
87 background = urwid.AttrSpec('light gray', 'black')
88 for i in range(len(self._oldbuf)):
89 oldattr, oldcs, oldchar = self._oldbuf[i]
90 newattr, newcs, newchar = self._newbuf[i]
91 oldrgb = oldattr.get_rgb_values()
92 newrgb = newattr.get_rgb_values()
93 if None in oldrgb:
94 oldrgb = background.get_rgb_values()
95 if None in newrgb:
96 newrgb = background.get_rgb_values()
97 if newchar == ' ':
98 char = oldchar
99 charattr = oldattr
100 newrgb = newrgb[3:]*2
101 elif oldchar == ' ':
102 char = newchar
103 charattr = newattr
104 oldrgb = oldrgb[3:]*2
105 elif self.progress >= 0.5:
106 char = newchar
107 charattr = newattr
108 else:
109 char = oldchar
110 charattr = oldattr
111 char = char.encode('utf8')
112 line_text += char
113 rgb = []
114 props = []
115 if charattr.bold:
116 props.append('bold')
117 if charattr.underline:
118 props.append('underline')
119 if charattr.standout:
120 props.append('standout')
121 if charattr.blink:
122 props.append('blink')
123 for x in range(len(oldrgb)):
124 rgb.append(int(((newrgb[x]-oldrgb[x])*self.progress)+oldrgb[x])>>4)
125 if current_rgb == rgb and current_props == props:
126 current_attr[1] += len(char)
127 else:
128 if current_attr[0]:
129 line_attrs.append(tuple(current_attr))
130 fg = ', '.join(props + ['#%x%x%x' % tuple(rgb[:3])])
131 bg = '#%x%x%x' % tuple(rgb[3:])
132 attr = urwid.AttrSpec(fg, bg)
133 current_attr = [attr, len(char)]
134 current_rgb = rgb
135 current_props = props
136 if (i+1) % size[0] == 0:
137 line_attrs.append(tuple(current_attr))
138 current_attr = [None, 0]
139 current_rgb = None
140 line_list.append(line_text)
141 line_text = ''
142 attr_list.append(line_attrs)
143 line_attrs = []
144 canvas = urwid.TextCanvas(line_list, attr_list)
145 return canvas
146
147class CutTransition(Transition):
148 def __init__(self, *args, **kw):
149 super(CutTransition, self).__init__(*args, **kw)
150 self.duration = 0.0
151
152 def render(self, size, focus=False):
153 return self.new.render(size, focus)
diff --git a/requirements.txt b/requirements.txt
new file mode 100644
index 0000000..7996638
--- /dev/null
+++ b/requirements.txt
@@ -0,0 +1,7 @@
1pbr>=0.5.21,<1.0
2
3urwid
4docutils>=0.12
5pygments
6pillow # or PIL. Optional; only used for images.
7
diff --git a/setup.cfg b/setup.cfg
new file mode 100644
index 0000000..80939da
--- /dev/null
+++ b/setup.cfg
@@ -0,0 +1,45 @@
1# Copyright (C) 2015 James E. Blair <corvus@gnu.org>
2#
3# This program is free software: you can redistribute it and/or modify
4# it under the terms of the GNU General Public License as published by
5# the Free Software Foundation, either version 3 of the License, or
6# (at your option) any later version.
7#
8# This program is distributed in the hope that it will be useful,
9# but WITHOUT ANY WARRANTY; without even the implied warranty of
10# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11# GNU General Public License for more details.
12#
13# You should have received a copy of the GNU General Public License
14# along with this program. If not, see <http://www.gnu.org/licenses/>.
15
16[metadata]
17name = presentty
18summary = Console-based presentation system
19description-file =
20 README.rst
21author = James E. Blair
22author-email = corvus@gnu.org
23classifier =
24 Environment :: Console
25 Intended Audience :: Developers
26 Intended Audience :: Education
27 Intended Audience :: End Users/Desktop
28 Intended Audience :: Information Technology
29 Intended Audience :: System Administrators
30 License :: OSI Approved :: GNU General Public License v3 or later (GPLv3+)
31 Programming Language :: Python
32 Topic :: Multimedia :: Graphics :: Presentation
33
34[pbr]
35warnerrors = True
36
37[entry_points]
38console_scripts =
39 presentty = presentty.presentty:main
40 presentty-console = presentty.console:main
41
42[build_sphinx]
43source-dir = doc/source
44build-dir = doc/build
45all_files = 1
diff --git a/setup.py b/setup.py
new file mode 100644
index 0000000..c56e349
--- /dev/null
+++ b/setup.py
@@ -0,0 +1,20 @@
1# Copyright (C) 2015 James E. Blair <corvus@gnu.org>
2#
3# This program is free software: you can redistribute it and/or modify
4# it under the terms of the GNU General Public License as published by
5# the Free Software Foundation, either version 3 of the License, or
6# (at your option) any later version.
7#
8# This program is distributed in the hope that it will be useful,
9# but WITHOUT ANY WARRANTY; without even the implied warranty of
10# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11# GNU General Public License for more details.
12#
13# You should have received a copy of the GNU General Public License
14# along with this program. If not, see <http://www.gnu.org/licenses/>.
15
16import setuptools
17
18setuptools.setup(
19 setup_requires=['pbr'],
20 pbr=True)