summaryrefslogtreecommitdiffstats
path: root/presentty/transition.py
diff options
context:
space:
mode:
authorToshio Kuratomi <a.badger@gmail.com>2017-09-21 17:02:11 -0700
committerToshio Kuratomi <a.badger@gmail.com>2017-09-21 18:58:39 -0700
commit319a8283c7d9c14911cd26c5710a395942d86c32 (patch)
tree1b1ad35c7a1a477b44840a3c115134947e66996d /presentty/transition.py
parent308a06134d7749638c7ba3afcc4031f31ba09930 (diff)
downloadpresentty-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/transition.py')
-rw-r--r--presentty/transition.py30
1 files changed, 18 insertions, 12 deletions
diff --git a/presentty/transition.py b/presentty/transition.py
index 5592cd9..1e9fbad 100644
--- a/presentty/transition.py
+++ b/presentty/transition.py
@@ -13,7 +13,11 @@
# 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 six
import urwid
+from six.moves import range
class Transition(urwid.Widget):
def __init__(self, duration=0.4):
@@ -76,7 +80,9 @@ class DissolveTransition(Transition):
buf = []
for line in canvas.content():
for (attr, cs, text) in line:
- for char in unicode(text, 'utf8'):
+ if not isinstance(text, six.text_type):
+ text = six.text_type(text, 'utf-8')
+ for char in text:
buf.append((attr, cs, char))
return buf
@@ -87,9 +93,9 @@ class DissolveTransition(Transition):
self._oldbuf = self._to_buf(old)
self._newbuf = self._to_buf(new)
self._cache_size = size
- line_list = []
+ b_line_list = []
attr_list = []
- line_text = ''
+ b_line_text = b''
line_attrs = []
current_attr = [None, 0]
current_rgb = None
@@ -104,11 +110,11 @@ class DissolveTransition(Transition):
oldrgb = background.get_rgb_values()
if None in newrgb:
newrgb = background.get_rgb_values()
- if newchar == ' ':
+ if newchar == b' ':
char = oldchar
charattr = oldattr
newrgb = newrgb[3:]*2
- elif oldchar == ' ':
+ elif oldchar == b' ':
char = newchar
charattr = newattr
oldrgb = oldrgb[3:]*2
@@ -118,8 +124,8 @@ class DissolveTransition(Transition):
else:
char = oldchar
charattr = oldattr
- char = char.encode('utf8')
- line_text += char
+ b_char = char.encode('utf8')
+ b_line_text += b_char
rgb = []
props = []
if charattr.bold:
@@ -133,25 +139,25 @@ class DissolveTransition(Transition):
for x in range(len(oldrgb)):
rgb.append(int(((newrgb[x]-oldrgb[x])*self.progress)+oldrgb[x])>>4)
if current_rgb == rgb and current_props == props:
- current_attr[1] += len(char)
+ current_attr[1] += len(b_char)
else:
if current_attr[0]:
line_attrs.append(tuple(current_attr))
fg = ', '.join(props + ['#%x%x%x' % tuple(rgb[:3])])
bg = '#%x%x%x' % tuple(rgb[3:])
attr = urwid.AttrSpec(fg, bg)
- current_attr = [attr, len(char)]
+ current_attr = [attr, len(b_char)]
current_rgb = rgb
current_props = props
if (i+1) % size[0] == 0:
line_attrs.append(tuple(current_attr))
current_attr = [None, 0]
current_rgb = None
- line_list.append(line_text)
- line_text = ''
+ b_line_list.append(b_line_text)
+ b_line_text = b''
attr_list.append(line_attrs)
line_attrs = []
- canvas = urwid.TextCanvas(line_list, attr_list)
+ canvas = urwid.TextCanvas(b_line_list, attr_list)
return canvas
class CutTransition(Transition):