diff options
author | Toshio Kuratomi <a.badger@gmail.com> | 2017-09-21 17:02:11 -0700 |
---|---|---|
committer | Toshio Kuratomi <a.badger@gmail.com> | 2017-09-21 18:58:39 -0700 |
commit | 319a8283c7d9c14911cd26c5710a395942d86c32 (patch) | |
tree | 1b1ad35c7a1a477b44840a3c115134947e66996d /presentty/rst.py | |
parent | 308a06134d7749638c7ba3afcc4031f31ba09930 (diff) | |
download | presentty-python3-port-try2.tar.gz presentty-python3-port-try2.tar.xz presentty-python3-port-try2.zip |
Initial python3 workpython3-port-try2
This is enough to get presentty to display the demo presentation all the
way through. The Python3 version appears to have some slight
performance problems (or perhaps it's a difference in behaviour) during
transitions. On displaying a new slide, the text pulses once (gets
brighter than it should be in its final state).
Diffstat (limited to 'presentty/rst.py')
-rw-r--r-- | presentty/rst.py | 36 |
1 files changed, 22 insertions, 14 deletions
diff --git a/presentty/rst.py b/presentty/rst.py index 5867ca1..e84b6df 100644 --- a/presentty/rst.py +++ b/presentty/rst.py @@ -13,21 +13,26 @@ # You should have received a copy of the GNU General Public License # along with this program. If not, see <http://www.gnu.org/licenses/>. +from __future__ import absolute_import, division, print_function + import os import re import docutils import docutils.frontend import docutils.parsers.rst import docutils.nodes -import cStringIO as StringIO +from io import StringIO +import six +from six.moves import range +from six.moves import input import urwid -import slide -import transition as transition_mod -import image -import ansiparser -import text +from . import slide +from . import transition as transition_mod +from . import image +from . import ansiparser +from . import text try: import PIL @@ -327,7 +332,8 @@ class UrwidTranslator(docutils.nodes.GenericNodeVisitor): for name in node['names']: p = ansiparser.ANSIParser() fn = os.path.join(self.basedir, name) - data = unicode(open(fn).read(), 'utf8') + data = open(fn, 'rb').read() + data = six.text_type(data, 'utf-8') text = p.parse(data) animation.addFrame(text) self.slide.animations.append(animation) @@ -447,7 +453,7 @@ class PresentationParser(object): 'cowsay', CowsayDirective) docutils.parsers.rst.directives.register_directive( 'hidetitle', HideTitleDirective) - self.warnings = StringIO.StringIO() + self.warnings = StringIO() self.settings = docutils.frontend.OptionParser( components=(docutils.parsers.rst.Parser,), defaults=dict(warning_stream=self.warnings)).get_default_values() @@ -469,7 +475,7 @@ class PresentationParser(object): def main(): import argparse - import palette + from . import palette argp = argparse.ArgumentParser(description='Test RST parser') argp.add_argument('file', help='presentation file (RST)') @@ -480,7 +486,9 @@ def main(): args = argp.parse_args() parser = PresentationParser(palette.DARK_PALETTE) - document, visitor = parser._parse(unicode(open(args.file).read(), 'utf-8'), args.file) + args_data = open(args.file, 'rb').read() + args_data = six.text_type(args_data, 'utf-8') + document, visitor = parser._parse(args_data, args.file) slides = args.slides if not slides: @@ -488,19 +496,19 @@ def main(): slides = [int(x) for x in slides] if not args.render: - print document.pformat() + print(document.pformat()) for i in slides: - print '-'*80 + print('-'*80) s = visitor.program[i] for line in s.render((80,25)).text: - print line + print(line) else: screen = urwid.raw_display.Screen() with screen.start(): for i in slides: s = visitor.program[i] screen.draw_screen((80,25), s.render((80,25))) - raw_input() + input() if __name__ == '__main__': main() |