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
for i in range(len(spisok_csv)):
или for i, s in enumerate(spisok_csv):
<input type="submit" hidden />
#!/usr/bin/env python
add
(без расширения) и сделай его исполняемым командой chmod +x add
.profile
в твоём домашнем каталоге, он как раз этим занимается. Он может быть настроен так, чтобы автоматически добавлять в PATH каталог bin в твоем домашнем каталоге, тогда просто создай этот каталог и закинь файл туда. # -*- coding: utf-8 -*-
import typing as t
import tkinter as tk
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
user32 = ctypes.windll.user32
# описываем используемые функции, типы и константы
WNDENUMPROC = ctypes.WINFUNCTYPE(w.BOOL, w.HWND, w.LPARAM)
user32.EnumWindows.argtypes = [WNDENUMPROC, w.LPARAM]
user32.EnumWindows.restype = w.BOOL
user32.GetClassNameW.argtypes = [w.HWND, w.LPWSTR, w.INT]
user32.GetClassNameW.restype = w.INT
user32.GetClassNameW.errcheck = ErrorIfZero
user32.GetWindowLongW.argtypes = [w.HWND, w.INT]
user32.GetWindowLongW.restype = w.DWORD
user32.SetWindowLongW.argtypes = [w.HWND, w.INT, w.LONG]
user32.SetWindowLongW.restype = w.DWORD
user32.SetWindowPos.argtypes = [w.HWND, w.HWND, w.INT, w.INT, w.INT, w.INT, w.UINT]
user32.SetWindowPos.restype = w.BOOL
user32.SetWindowPos.errcheck = ErrorIfZero
user32.SetParent.argtypes = [w.HWND, w.HWND]
user32.SetParent.restype = w.HWND
user32.GetParent.argtypes = [w.HWND]
user32.GetParent.restype = w.HWND
GWL_STYLE = w.INT(-16)
WS_CHILD = 0x40000000
SWP_NOACTIVATE = 0x0010
SWP_NOZORDER = 0x0004
SWP_SHOWWINDOW = 0x0040
# определяем дескриптор окна панели задач
def get_taskbar_window() -> w.HWND:
class_buf = ctypes.create_unicode_buffer(256)
handle: w.HWND = 0
#callback - функция будет проверять каждое окно
def process_window(hWnd: w.HWND, lParam: w.LPARAM) -> w.BOOL:
length = user32.GetClassNameW(hWnd, class_buf, len(class_buf))
name = ''.join(class_buf[:length])
if 'Shell_TrayWnd' == name: # имя класса окна панели задач всегда "Shell_TrayWnd"
nonlocal handle
handle = hWnd
return 0 # нашли, стоп
return 1 # не нашли, идём дальше
# перебираем окна верхнего уровня
user32.EnumWindows(WNDENUMPROC(process_window), 0)
if handle == 0:
raise ValueError('Taskbar not found')
return handle
def make_attachment() -> tk.Tk: #создаём простое окно
root = tk.Tk()
def button_command():
print('Bye!')
root.destroy()
item = tk.Button(root, text='Hello, World!', command=button_command)
item.pack(expand=True, fill='both')
return root
def attach(root: tk.Tk, hTaskbar: w.HWND):
hTop: w.HWND = user32.GetParent(w.HWND(root.winfo_id())) #дескриптор окна верхнего уровня для нашего приложения
user32.SetParent(hTop, hTaskbar) #задаём родителем панель задач
user32.SetWindowLongW(hTop, GWL_STYLE, WS_CHILD) #говорим, что наше окно на самом деле дочернее, а не верхнего уровня
user32.SetWindowPos(hTop,
0, #z-order - после какого окна должно идти наше. 0 - наверху
500, 0, # положение окна, пикселей
100, 40, # рамер окна, пикселей
SWP_NOACTIVATE | SWP_NOZORDER | SWP_SHOWWINDOW) # позиционируем и показываем окно
hTaskbar = get_taskbar_window()
root = make_attachment()
# откладываем вызов attach(root, hTaskbar)
# так как ткинтер некоторые настройки задаёт не сразу же
root.after(1, attach, root, hTaskbar)
root.mainloop()
def init_bot(bot):
# и прямо тут и описываешь все обработчики. Они получат доступ к параметру bot через замыкание.
@bot.message_handler(commands=['start'])
def start(message):
msg = bot.send_message(message.chat.id, f'_Введи имя:_', parse_mode='markdown')
bot.register_next_step_handler(msg, step1)