The sub() method takes a replacement value, which can be either a string or a function, and the string to be processed.
replacement can also be a function, which gives you even more control. If replacement is a function, the function is called for every non-overlapping occurrence of pattern. On each call, the function is passed a match object argument for the match and can use this information to compute the desired replacement string and return it.
import ctypes
import ctypes.wintypes as w
def ErrorIfZero(result, func, args):
if not result:
raise ctypes.WinError(ctypes.get_last_error())
return result
# используем user32.dll и kernel32.dll
kernel32 = ctypes.windll.kernel32
user32 = ctypes.windll.user32
gdi32 = ctypes.windll.gdi32
# описываем используемые функции, типы и константы
kernel32.GetConsoleWindow.argtypes = []
kernel32.GetConsoleWindow.restype = w.HWND
kernel32.GetConsoleWindow.check = ErrorIfZero
user32.GetWindowRect.argtypes = [w.HWND, w.LPRECT]
user32.GetWindowRect.restype = w.BOOL
user32.GetWindowRect.check = ErrorIfZero
user32.SetWindowRgn.argtypes = [w.HWND, w.HRGN, w.BOOL]
user32.SetWindowRgn.restype = w.INT
user32.SetWindowRgn.check = ErrorIfZero
gdi32.DeleteObject.argtypes = [w.HANDLE]
gdi32.DeleteObject.restype = w.BOOL
gdi32.DeleteObject.check = ErrorIfZero
gdi32.CreateRectRgnIndirect.argtypes = [w.LPRECT]
gdi32.CreateRectRgnIndirect.restype = w.HRGN
gdi32.CreateRectRgnIndirect.check = ErrorIfZero
gdi32.CombineRgn.argtypes = [w.HRGN, w.HRGN, w.HRGN, w.INT]
gdi32.CombineRgn.restype = w.INT
gdi32.CombineRgn.check = ErrorIfZero
RGN_AND = 1
RGN_OR = 2
RGN_XOR = 3
RGN_DIFF = 4
RGN_COPY = 5
hWnd = kernel32.GetConsoleWindow()
r = w.RECT()
user32.GetWindowRect(hWnd, ctypes.byref(r))
r.left, r.right = 0, r.right - r.left
r.top, r.bottom = -50, r.bottom - r.top #почему-то есть косяк с заголовком окна
hole = w.RECT(r.right // 4, r.bottom // 4, 3 * r.right // 4, 3 * r.bottom // 4)
hRgn = gdi32.CreateRectRgnIndirect(ctypes.byref(r))
hHole = gdi32.CreateRectRgnIndirect(ctypes.byref(hole))
gdi32.CombineRgn(hRgn, hRgn, hHole, RGN_DIFF)
gdi32.DeleteObject(hHole)
user32.SetWindowRgn(hWnd, hRgn, True)
input('Press Enter to fix the hole.')
user32.SetWindowRgn(hWnd, 0, True)
gdi32.DeleteObject(hRgn)
if call.data == "yes":
bot.send_message(call.message.chat.id, "Отлично")
game = True
if game == True:
def play(message):
...
else:
bot.send_message(message.from_user.id, "Напиши /reg")
A B
C D
max(A.shape[1]+B.shape[1], C.shape[1]+D.shape[1])
, а высота max(A.shape[0]+C.shape[0], B.shape[0]+D.shape[0])
max(A.shape[1], C.shape[1])
, отступ по Y для C и D будет max(A.shape[0], B.shape[0])
.R[0:A.shape[0], 0:A.shape[1]] = A
R[0:B.shape[0], X:X+B.shape[1]] = B
R[Y:Y+C.shape[0], 0:C.shape[1]] = C
R[Y:Y+D.shape[0], X:X+D.shape[1]] = D