Compare commits

...

13 Commits
2.3 ... master

Author SHA1 Message Date
KikooDX 5e5f1bc9ef Fixed fmargin. 2019-11-16 16:18:27 +01:00
KikooDX 80cf133bbf Fancy margin.
Speed and size optimization.
2019-11-16 16:12:56 +01:00
KikooDX d35e62b1d7 The mighty -4 return... 2019-11-06 11:20:08 +01:00
KikooDX b4dc69ced1 Added the mighty -4... 2019-11-06 11:15:12 +01:00
KikooDX 2ab53c8116 The cursor is now always to the bottom right with fancy display. 2019-11-06 10:57:50 +01:00
KikooDX 49fc0f6a4f Redundant operation. 2019-11-06 10:52:45 +01:00
KikooDX febd7dd1ec Pad now works properly. 2019-11-06 10:51:05 +01:00
KikooDX f1f664f716 Deleted artifact debug line. Implemented fancy for Pad. Need testing on the calc. 2019-11-06 10:06:11 +01:00
KikooDX 8ac28a47f4 Made a test version of fancy display for Screen. 2019-11-06 09:53:02 +01:00
KikooDX c6299aaaa0 Deleted crappy verification process. 2019-11-06 09:31:11 +01:00
KikooDX 35d3728feb Merge branch 'master' of https://gitea.planet-casio.com/KikooDX/Locate2.py 2019-07-17 17:06:49 +02:00
KikooDX c287decd4d Indentation set to 2 spaces instead of 4 (Casio Micro Python choice) 2019-07-17 17:05:08 +02:00
KikooDX 2a62b540e7 Ajouter '.gitignore' 2019-07-17 17:00:55 +02:00
2 changed files with 219 additions and 124 deletions

116
.gitignore vendored Normal file
View File

@ -0,0 +1,116 @@
# ---> Python
# Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]
*$py.class
# C extensions
*.so
# Distribution / packaging
.Python
build/
develop-eggs/
dist/
downloads/
eggs/
.eggs/
lib/
lib64/
parts/
sdist/
var/
wheels/
*.egg-info/
.installed.cfg
*.egg
MANIFEST
# PyInstaller
# Usually these files are written by a python script from a template
# before PyInstaller builds the exe, so as to inject date/other infos into it.
*.manifest
*.spec
# Installer logs
pip-log.txt
pip-delete-this-directory.txt
# Unit test / coverage reports
htmlcov/
.tox/
.nox/
.coverage
.coverage.*
.cache
nosetests.xml
coverage.xml
*.cover
.hypothesis/
.pytest_cache/
# Translations
*.mo
*.pot
# Django stuff:
*.log
local_settings.py
db.sqlite3
# Flask stuff:
instance/
.webassets-cache
# Scrapy stuff:
.scrapy
# Sphinx documentation
docs/_build/
# PyBuilder
target/
# Jupyter Notebook
.ipynb_checkpoints
# IPython
profile_default/
ipython_config.py
# pyenv
.python-version
# celery beat schedule file
celerybeat-schedule
# SageMath parsed files
*.sage.py
# Environments
.env
.venv
env/
venv/
ENV/
env.bak/
venv.bak/
# Spyder project settings
.spyderproject
.spyproject
# Rope project settings
.ropeproject
# mkdocs documentation
/site
# mypy
.mypy_cache/
.dmypy.json
dmypy.json
# Pyre type checker
.pyre/

View File

@ -1,124 +1,103 @@
class Screen:
def _check(self, x, o, name):
if not isinstance(x, int):
raise TypeError("{} is not an int object".format(name))
elif x < 1:
raise ValueError("{} is lower than 1".format(name))
if o is None:
o = 0
elif x > o and o:
raise ValueError("{} is greater than the height of this object: {} > {}".
format(name, x, o))
def __init__(self, width=21, height=6, patern=" ", copy=None):
if isinstance(copy, Screen):
self._width = copy._width
self._height = copy._height
self._mat = copy._mat
else:
self._check(width, None, "width")
self._check(height, None, "height")
if not isinstance(patern, str):
raise TypeError("patern is not a string")
elif len(patern) > 1:
raise ValueError("patern is too long (length = {})".format(len(patern)))
self._width = width
self._height = height
self.fill(patern)
def locate(self, x, y, string):
self._check(x, self._width, "x")
self._check(y, self._height, "y")
string = str(string)
i = -1
for char in string:
if i + x < self._width:
self._mat[y - 1][x + i] = char
i += 1
def locate_v(self, x, y, string):
self._check(x, self._width, "x")
self._check(y, self._height, "y")
string = str(string)
i = -1
for char in string:
if i + y < self._height:
self._mat[y + i][x - 1] = char
i += 1
def fill(self, patern=" "):
self._mat = [[patern[0] for i in range(self._width)] for i in range(self._height)]
def refresh(self, ask_for_input=True, endl="\n"):
to_print = str()
for line in self._mat:
for cell in line:
to_print += cell
to_print += "\n"
to_print = to_print[:-1]
print(to_print)
if ask_for_input:
return input("> ")
else:
print("", end=endl)
return None
def get_cell(self, x, y):
self._check(x, self._width, "x")
self._check(y, self._width, "y")
return self._mat[y - 1][x - 1]
def get_dim(self):
return self._width, self._height
def export(self):
result = str()
for line in self._mat:
for cell in line:
result += cell
return result
def load(self, string):
if type(string) is not str:
raise TypeError("string is not a string type")
if len(string) != self._width * self._height:
raise ValueError("string lenght isn't equal to {}".format(self._width * self._height))
i = 0
s = 0
while i != self._height:
self._mat[i] = list(string[s:s + self._width])
i += 1
s += self._width
get_cell_content = get_cell # For retro-compability
class Pad(Screen):
def refresh(self, x=1, y=1, width=21, height=6, ask_for_input=True, endl="\n"):
if width > self._width:
width = self._width
if height > self._height:
height = self._height
if x < 1:
x = 1
if y < 1:
y = 1
x -= 1
y -= 1
if x + width > self._width:
x = self._width - width
if y + height > self._height:
y = self._height - height
to_print = str()
for dy in range(y, height+y):
dy = dy
for dx in range(x, width+x):
print(dx, dy)
to_print += self._mat[dy][dx]
to_print += "\n"
to_print = to_print[:-1]
print(to_print)
if ask_for_input:
return input("> ")
else:
print("", end=endl)
return None
class Screen:
def __init__(self, width=21, height=6, patern=" ", copy=None):
if isinstance(copy, Screen):
self._width = copy._width
self._height = copy._height
self._mat = copy._mat
else:
self._width = width
self._height = height
self.fill(patern)
def locate(self, x, y, string):
string = str(string)
i = -1
for char in string:
if i + x < self._width:
self._mat[y - 1][x + i] = char
i += 1
def locate_v(self, x, y, string):
string = str(string)
i = -1
for char in string:
if i + y < self._height:
self._mat[y + i][x - 1] = char
i += 1
def fill(self, patern=" "):
self._mat = [[patern[0] for i in range(self._width)] for i in range(self._height)]
def refresh(self, ask_for_input=True, endl="\n", fancy=False, fmargin=4):
to_print = str()
for line in self._mat[:-1] if fancy else self._mat:
for cell in line:
to_print += cell
to_print += "\n"
to_print = to_print[:-1]
print(to_print)
if ask_for_input or fancy:
line = ""
if fancy:
for cell in self._mat[-1][:-fmargin]:
line += cell
return input(line)
return input("> ")
else:
print("", end=endl)
return None
def get_cell(self, x, y):
return self._mat[y - 1][x - 1]
def get_dim(self):
return self._width, self._height
def export(self):
result = str()
for line in self._mat:
for cell in line:
result += cell
return result
def load(self, string):
i = 0
s = 0
while i != self._height:
self._mat[i] = list(string[s:s + self._width])
i += 1
s += self._width
get_cell_content = get_cell # For retro-compability
class Pad(Screen):
def refresh(self, x=1, y=1, width=21, height=7, ask_for_input=True,\
endl="\n", fancy=True, fmargin=4):
ogwidth = width
if width > self._width:
width = self._width
if height > self._height:
height = self._height
if x < 1:
x = 1
if y < 1:
y = 1
x -= 1
y -= 1
if x + width > self._width:
x = self._width - width
if y + height > self._height:
y = self._height - height
to_print = str()
for dy in range(y, height+y):
dy = dy
for dx in range(x, width+x):
to_print += self._mat[dy][dx]
to_print += "\n"
to_print = to_print[:-1]
print(to_print[:-width], end="")
if ask_for_input or fancy:
return input(to_print[-width:-1]+ " " * (ogwidth - width - fmargin) if fancy else "> ")
else:
print(to_print[-width:], end=endl)
return None