Skip to content

Commit

Permalink
V1.9.5 (#203)
Browse files Browse the repository at this point in the history
* update: updated version to 1.9.4

* chore: add Rotation utils

* fix: fixed imports

* fixes: Point fix.

* utils: add funcs

* chore: add BMP read

* chore: add win32 api

* improve: improve window capture

* improve: improve Mouse

* improve: improve Window

* The standard behavior is that pprint will break strings into chunks of 80 characters per line. This update lets the user control the width of strings for pprinting samples of iterables, using 200 as a default value. (#204)

* cereja: fixes bug in visualize_sample

* utils: adds parameter to control the width of strings in function `visualize_sample`

* cereja: updates version

---------

Co-authored-by: Denny <dennyceccon@handtalk.com>

* fixes: fix error on python 3.7

* improves: improve Keyboard and Mouse

---------

Co-authored-by: Denny <ceccon.dm@gmail.com>
Co-authored-by: Denny <dennyceccon@handtalk.com>
  • Loading branch information
3 people authored Dec 15, 2023
1 parent 2762286 commit 2f57565
Show file tree
Hide file tree
Showing 5 changed files with 774 additions and 5 deletions.
2 changes: 1 addition & 1 deletion cereja/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@
from . import experimental
from ._requests import request

VERSION = "1.9.4.final.0"
VERSION = "1.9.5.final.0"
__version__ = get_version_pep440_compliant(VERSION)


Expand Down
85 changes: 83 additions & 2 deletions cereja/file/_io.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,13 @@
from ..system import memory_of_this
from ..utils import string_to_literal, sample, fill

try:
import numpy as np

has_np = True
except ImportError:
has_np = False

logger = logging.Logger(__name__)

__all__ = ["FileIO"]
Expand Down Expand Up @@ -400,8 +407,8 @@ def size(self, unit: str = "KB"):
), f"{repr(unit)} is'nt valid. Choose anyone in {tuple(self._size_map)}"
# subtracts the size of the python object
return (
memory_of_this(self._data) - self._data.__class__().__sizeof__()
) / self._size_map[unit]
memory_of_this(self._data) - self._data.__class__().__sizeof__()
) / self._size_map[unit]

def _load(self, mode=None, **kwargs) -> Any:
if self._path.suffix in self._dont_read:
Expand Down Expand Up @@ -650,6 +657,79 @@ def __iter__(self):
yield i


class _BmpIO(_FileIO, ABC):
_is_byte: bool = True
_only_read = True
_ext_allowed = (".bmp",)

def __init__(
self,
*args,
creation_mode=True,
width=None,
height=None,
**kwargs,
):
if creation_mode and (width is None or height is None):
raise Exception("send width and height kwarg.")
self._header = None
self._width = width
self._height = height
super().__init__(*args, **kwargs)

@property
def header(self):
return self._header

@property
def width(self):
return self._width

@property
def height(self):
return self._height

def _parse_fp(self, fp: Union[TextIO, BytesIO]) -> Any:
self._header = fp.read(54) # Os primeiros 54 bytes são o cabeçalho BMP
self._width = abs(int.from_bytes(self.header[18:22], byteorder='little', signed=True))
self._height = abs(int.from_bytes(self.header[22:26], byteorder='little', signed=True))
return fp.read() # Ler os dados da imagem

def _save_fp(self, fp: Union[TextIO, BytesIO]) -> None:
if self.header is None:
file_header_size = 14
info_header_size = 40
header_size = file_header_size + info_header_size
image_size = self.width * self.height * 4
file_size = header_size + image_size
fp.write(b'BM') # Tipo de arquivo
fp.write(file_size.to_bytes(4, byteorder='little')) # Tamanho do arquivo
fp.write(b'\x00\x00') # Reservado
fp.write(b'\x00\x00') # Reservado
fp.write(header_size.to_bytes(4, byteorder='little')) # Offset para início dos dados da imagem

# Escrevendo o cabeçalho de informações do BMP
fp.write(info_header_size.to_bytes(4, byteorder='little')) # Tamanho do cabeçalho de informações
fp.write(self.width.to_bytes(4, byteorder='little')) # Largura
fp.write(
(-self.height).to_bytes(4,
byteorder='little')) # Altura (negativo para indicar origem superior esquerda)
fp.write((1).to_bytes(2, byteorder='little')) # Planos (deve ser 1)
fp.write((32).to_bytes(2, byteorder='little')) # Bits por pixel
fp.write((0).to_bytes(4, byteorder='little')) # Compressão (nenhuma)
fp.write(image_size.to_bytes(4, byteorder='little')) # Tamanho da imagem
fp.write((0).to_bytes(4, byteorder='little')) # Resolução horizontal (não especificada)
fp.write((0).to_bytes(4, byteorder='little')) # Resolução vertical (não especificada)
fp.write((0).to_bytes(4, byteorder='little')) # Cores na paleta (nenhuma)
fp.write((0).to_bytes(4, byteorder='little')) # Cores importantes (todas)
else:
fp.write(self.header)
fp.write(self.data)

def parse(self, data):
return data


class _Mp4IO(_FileIO, ABC):
_is_byte: bool = True
_only_read = True
Expand Down Expand Up @@ -1006,6 +1086,7 @@ class FileIO:
pkl = _PyObj
zip = _ZipFileIO
srt = _SrtFile
bmp = _BmpIO
_generic = _Generic

def __new__(cls, path_, data=None, **kwargs):
Expand Down
5 changes: 5 additions & 0 deletions cereja/system/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,8 @@

from ._path import *
from ..system.commons import *

try:
from ._win32 import Window, Keyboard, Mouse
except (ImportError, ValueError) as err:
pass
Loading

0 comments on commit 2f57565

Please sign in to comment.