Skip to content

Commit f6f6580

Browse files
committed
quick & dirty pass at updating to python3
1 parent 58cf508 commit f6f6580

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

47 files changed

+1189
-1753
lines changed

Diff for: ants/examples/ants.pv

+1-7
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,4 @@
1-
import importlib
2-
try:
3-
ants = ximport("ants")
4-
except:
5-
ants = ximport("__init__")
6-
importlib.reload(ants)
7-
1+
import ants
82

93
size(500,500)
104
speed(200)

Diff for: cornu/examples/cornu-1.pv

+1-6
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,4 @@
1-
import importlib
2-
try:
3-
cornu = ximport("cornu")
4-
except:
5-
cornu = ximport("__init__")
6-
importlib.reload(cornu)
1+
import cornu
72

83
size(600,600)
94

Diff for: cornu/examples/cornu-2.pv

+1-6
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,8 @@
1-
import importlib
21
# Interactive Cornu editor.
32
# Click and drag points on the canvas.
43
# Your work will be saved as an SVG-file in this folder.
54

6-
try:
7-
cornu = ximport("cornu")
8-
except:
9-
cornu = ximport("__init__")
10-
importlib.reload(cornu)
5+
import cornu
116

127
points = []
138
drag = None

Diff for: flowerewolf/examples/flowerewolf.pv

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# Note: you'll also need the NodeBox English Linguistics library:
22
# http://nodebox.net/code/index.php/Linguistics
33

4-
flowerewolf = ximport("__init__")
4+
import flowerewolf
55

66
var("topic", TEXT, "kiss")
77
size(600,700)

Diff for: google/google_test.py renamed to google/examples/google.pv

+1-9
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,10 @@
11
from urllib.request import urlopen
22
import re
3-
import importlib
43

54
size(500, 500)
65
background(0.2,0.5,0)
76

8-
# Import the Google library
9-
try:
10-
# This is the statement you normally use.
11-
google = ximport("google")
12-
except:
13-
# From inside the library folder.
14-
google = ximport("__init__")
15-
importlib.reload(google)
7+
import google
168

179
# Set the license key
1810
google.license("<your license key>")

Diff for: graph/examples/graph-1.pv

+1-11
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,4 @@
1-
import importlib
2-
# Import the library
3-
try:
4-
# This is the statement you normally use.
5-
graph = ximport("graph")
6-
except ImportError:
7-
# But since these examples are "inside" the library
8-
# we may need to try something different when
9-
# the library is not located in /Application Support
10-
graph = ximport("__init__")
11-
importlib.reload(graph)
1+
import graph
122

133
size(500, 500)
144

Diff for: graph/examples/graph-2.pv

+1-6
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,4 @@
1-
import importlib
2-
try:
3-
graph = ximport("graph")
4-
except ImportError:
5-
graph = ximport("__init__")
6-
importlib.reload(graph)
1+
import graph
72

83
size(600, 600)
94

Diff for: graph/examples/graph-3.pv

+1-6
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,4 @@
1-
import importlib
2-
try:
3-
graph = ximport("graph")
4-
except ImportError:
5-
graph = ximport("__init__")
6-
importlib.reload(graph)
1+
import graph
72

83
size(500, 500)
94

Diff for: graph/examples/graph-4.pv

+1-6
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,7 @@
55

66
query = "bird"
77

8-
try:
9-
graph = ximport("graph")
10-
except ImportError:
11-
graph = ximport("__init__")
12-
importlib.reload(graph)
13-
8+
import graph
149
import en
1510
from random import shuffle
1611
import importlib

Diff for: grid/examples/grid-1.pv

+1-11
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,4 @@
1-
import importlib
2-
# Import the library
3-
try:
4-
# This is the statement you normally use.
5-
grid = ximport("grid")
6-
except:
7-
# But since this example is "inside" the library
8-
# we may need to try something different when
9-
# the library is not located in /Application Support
10-
grid = ximport("__init__")
11-
importlib.reload(grid)
1+
import grid
122

133
g = grid.create(3, 1, width=400, height=500)
144
g.bottom.split(1, 3)

Diff for: grid/examples/grid-2.pv

+1-6
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,6 @@
1-
import importlib
21
# IMAGE GRID
32

4-
try:
5-
grid = ximport("grid")
6-
except:
7-
grid = ximport("__init__")
8-
importlib.reload(grid)
3+
import grid
94

105
# Play around with the rows, columns, width and height.
116
# With the g.styles.fit = True defined below,

Diff for: grid/examples/grid-3.pv

+1-6
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,4 @@
1-
import importlib
2-
try:
3-
grid = ximport("grid")
4-
except:
5-
grid = ximport("__init__")
6-
importlib.reload(grid)
1+
import grid
72

83
w, h = grid.format.A4
94
size(w+0, h+0)

Diff for: grid/proportion.py

+10-6
Original file line numberDiff line numberDiff line change
@@ -72,21 +72,25 @@ def generate(self, n):
7272
7373
"""
7474

75+
print('N', n)
7576
r = max(1, self.repetition)
76-
77+
print('R',r)
78+
n = float(n)
79+
r = float(r)
80+
7781
if isinstance(n, list):
7882
list.__init__(self, n)
7983
elif n <= 0:
8084
list.__init__(self, [])
8185
elif n == 1:
8286
list.__init__(self, [1.0])
8387
elif self.distribution == PROPORTION_RANDOM:
84-
list.__init__(self, [random() for i in range(n/r)])
88+
list.__init__(self, [random() for i in range(int(n//r))])
8589
elif self.distribution in (PROPORTION_EVEN):
86-
list.__init__(self, [1.0/n for i in range(n/r)])
90+
list.__init__(self, [1.0/float(n) for i in range(int(n//r))])
8791
elif self.distribution in (PROPORTION_FIBONACCI, PROPORTION_FIB):
8892
# Values distributed according to the golden ratio.
89-
list.__init__(self, [self.fib(i) for i in range(2,(n/r)+2)])
93+
list.__init__(self, [self.fib(i) for i in range(2,(int(n//r))+2)])
9094
elif self.distribution == PROPORTION_CONTRAST:
9195
# Split the range: 80% are 0.05-0.15 value and 20% are 0.85-1.0 values.
9296
i = max(1, int(round((n/r) * 0.2)))
@@ -97,8 +101,8 @@ def generate(self, n):
97101
self.append(random()*0.1+0.05)
98102

99103
# Repeat the range and assert that the list has n elements.
100-
self *= r
101-
for i in range(n-len(self)):
104+
self *= int(r)
105+
for i in range(int(n)-len(self)):
102106
self.append(self[i])
103107

104108
self.relativize()

Diff for: grid/style.py

+3-2
Original file line numberDiff line numberDiff line change
@@ -415,7 +415,7 @@ def draw_background(style, grob, path, x, y, width, height):
415415
# If a background gradient is defined, attempt to import the Colors library.
416416
if style.background.gradient:
417417
try:
418-
colors = style._ctx.ximport("colors")
418+
import colors
419419
g = style.background.gradient
420420
clr1 = g[0]
421421
clr2 = g[1]
@@ -446,7 +446,8 @@ def draw_content(style, grob, x, y, width, height):
446446

447447
# hack the local redefs of alignment args back to plotdevice's values
448448
from plotdevice.gfx import LEFT, RIGHT, CENTER, JUSTIFY
449-
style._ctx.align([LEFT, RIGHT, CENTER, JUSTIFY][style.horizontal])
449+
print("TO", style.horizontal, alignment(style.horizontal))
450+
style._ctx.align([LEFT, RIGHT, CENTER, JUSTIFY][alignment(style.horizontal)])
450451
# style._ctx.align(alignment(style.horizontal))
451452

452453
# Content rotation.

Diff for: grid/text.py

+12-12
Original file line numberDiff line numberDiff line change
@@ -170,13 +170,13 @@ def split(txt, width, height, widows=1, orphans=1, forward=True):
170170

171171
# Splitter parameters.
172172
d = 1.6
173-
if _ctx.fontsize > 20: d = 1.15
173+
if _ctx.font().size > 20: d = 1.15
174174

175175
# Approximate by cutting in large chunks a few times.
176176
# When it gets down to chunks increasing or decreasing by 10 characters,
177177
# proceed from word to word.
178178
h = _ctx.textheight(txt[:i], width)
179-
while abs(h - height) > _ctx.fontsize():
179+
while abs(h - height) > _ctx.font().size:
180180
if abs(i/m) < 10: break # Increase or decrease becomes too small.
181181
if h > height: i -= i/m; m *= d
182182
if h <= height: i += i/m
@@ -230,8 +230,8 @@ def legible_width(txt, chars=70):
230230
Assumes an optimal of 70 characters per line at fontsize 10pt.
231231
Smaller lineheight furthermore decreases the width.
232232
"""
233-
fs = _ctx.fontsize()
234-
_ctx.fontsize(10)
233+
fs = _ctx.font().size
234+
_ctx.font(size=10)
235235
str = ""
236236
for i in range(chars):
237237
str += choice("abcdefghijklmnopqrstuvwxyz ")
@@ -240,7 +240,7 @@ def legible_width(txt, chars=70):
240240
w *= _ctx.lineheight() / 1.2
241241
if txt == txt.upper():
242242
w *= 1.5
243-
_ctx.fontsize(fs)
243+
_ctx.font(size=fs)
244244
return w
245245

246246
#### FIT FONTSIZE ####################################################################################
@@ -252,19 +252,19 @@ def fit_fontsize(str, width, height):
252252
# E.g. if a word contains no descenders (Goo vs. goo) there is more room at the bottom to scale.
253253
def increase(str, width, height, factor):
254254
while _ctx.textheight(str, width) < height:
255-
_ctx.fontsize(_ctx.fontsize()+factor)
255+
_ctx.font(size=_ctx.font().size + factor)
256256
def decrease(str, width, height, factor):
257-
while _ctx.textheight(str, width) > height and _ctx.fontsize() > 0:
258-
_ctx.fontsize(_ctx.fontsize()-factor)
257+
while _ctx.textheight(str, width) > height and _ctx.font().size > 0:
258+
_ctx.font(size = _ctx.fontsize() - factor)
259259
if str == "" or width < 1 or height < 1:
260260
return 0.0001
261-
fs = _ctx.fontsize()
261+
fs = _ctx.font().size
262262
increase(str, width, height, 10)
263263
decrease(str, width, height, 3)
264264
increase(str, width, height, 1)
265265
decrease(str, width, height, 1)
266-
x = _ctx.fontsize()
267-
_ctx.fontsize(fs)
266+
x = _ctx.font().size
267+
_ctx.font(size=fs)
268268
return max(x, 0.0001)
269269

270270
def fit_lineheight(str, width, height):
@@ -278,7 +278,7 @@ def decrease(str, width, height, factor):
278278
_ctx.lineheight(_ctx.lineheight()-factor)
279279
if _ctx.textheight(str, width) <= _ctx.textheight(" ") \
280280
or _ctx.textheight(str, width) <= 1 \
281-
or _ctx.fontsize() < 1:
281+
or _ctx.font().size < 1:
282282
return _ctx.lineheight()
283283
if str == "" or width < 1 or height < 1:
284284
return 0.0001

0 commit comments

Comments
 (0)