forked from OSGeo/grass
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Helper scripts: Port to Python, fix perlcritic errors (OSGeo#1431)
* Convert 'd.text/test.pl' to Python script * Fix perlcritic warnings for 'utils/copywrite.pl' and 'vector/v.clean/test/v.rand.poly'
- Loading branch information
Owen Smith
authored
Apr 1, 2021
1 parent
f190e2d
commit 27aa771
Showing
4 changed files
with
113 additions
and
92 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
#!/usr/bin/env python3 | ||
# Author: Owen Smith - Rewritten from test.pl by Huidae Cho | ||
# Run: d.mon start=wx0 && ./test.py | d.text at=0,100 | ||
import math | ||
import re | ||
|
||
# Quiet black syntax checking for fonts and colors to keep the code printed to | ||
# the display vertically short. | ||
# fmt: off | ||
fonts = ("cyrilc", "gothgbt", "gothgrt", "gothitt", "greekc", "greekcs", | ||
"greekp", "greeks", "italicc", "italiccs", "italict", "romanc", | ||
"romancs", "romand", "romans", "romant", "scriptc", "scripts", | ||
"cyrilc", "gothgbtlu") | ||
colors = ("red", "orange", "yellow", "green", "blue", "indigo", "violet", | ||
"black", "gray", "brown", "magenta", "aqua", "grey", "cyan", | ||
"purple") | ||
# fmt: on | ||
|
||
|
||
def rc(r, c): | ||
print(f".X {r}\n.Y {c}") | ||
|
||
|
||
def xy(x, y): | ||
print(f".X {x}%\n.Y {y}%") | ||
|
||
|
||
def font(f): | ||
print(f".F {f}") | ||
|
||
|
||
def size(s): | ||
print(f".S {s}") | ||
|
||
|
||
def color(c): | ||
print(f".C {c}") | ||
|
||
|
||
def rotate(r): | ||
print(f".R {r}") | ||
|
||
|
||
def align(a): | ||
print(f".A {a}") | ||
|
||
|
||
def text(in_text): | ||
print(f"{in_text}") | ||
|
||
|
||
for i in range(36): | ||
font(fonts[int(i % len(fonts))]) | ||
size(((36 - i if (i >= 9 and i <= 18 or i > 27) else i) % 9)) | ||
rotate(i * 10) | ||
color(colors[i % len(colors)]) | ||
xy( | ||
(80 + 10 * math.cos(i * 10 / 180 * 3.141593)), | ||
(50 + 10 * 640 / 480 * math.sin(i * 10 / 180 * 3.141593)), | ||
) | ||
text(fonts[int(i % len(fonts))]) | ||
|
||
size(2) | ||
rotate(0) | ||
font("romans") | ||
color("gray") | ||
rc(1, 1) | ||
|
||
with open(__file__) as f: | ||
src = f.read() | ||
|
||
print( | ||
".L 0\n" | ||
+ re.sub( | ||
'(".*?")', | ||
"\n.C red\n,\\g<0>\n.C gray\n", | ||
re.sub("\n", "\n.L 1\n.L 0\n", re.sub("(?m)^#.*\n?", "", src)), | ||
) | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters