Add files via upload
This commit is contained in:
parent
741ea4081f
commit
c62119243e
60 changed files with 422 additions and 130 deletions
|
@ -1,6 +1,7 @@
|
||||||
from pygwin.surface import surface
|
from pygwin.surface import surface
|
||||||
import pygwin.keyboard as keyboard
|
import pygwin.keyboard as keyboard
|
||||||
from pygwin.console import console
|
from pygwin.console import console
|
||||||
|
from pygwin.color import color
|
||||||
import pygwin.gamepad as _gp
|
import pygwin.gamepad as _gp
|
||||||
import pygwin.mouse as mouse
|
import pygwin.mouse as mouse
|
||||||
from pygwin.rect import rect
|
from pygwin.rect import rect
|
||||||
|
|
|
@ -10,9 +10,12 @@ import win32con as _w32c
|
||||||
import win32gui as _w32g
|
import win32gui as _w32g
|
||||||
import requests as _req
|
import requests as _req
|
||||||
import tempfile as _tf
|
import tempfile as _tf
|
||||||
|
import threading as _t
|
||||||
import pickle as _p
|
import pickle as _p
|
||||||
|
import mouse as _m
|
||||||
|
import time as _ti
|
||||||
|
|
||||||
class win(_surface):
|
class _win(_surface):
|
||||||
def __init__(self, iconpath=None):
|
def __init__(self, iconpath=None):
|
||||||
self._orig = _pg.display.get_surface()
|
self._orig = _pg.display.get_surface()
|
||||||
super().__init__(self._orig.get_size())
|
super().__init__(self._orig.get_size())
|
||||||
|
@ -20,6 +23,8 @@ class win(_surface):
|
||||||
self._clock = _pg.time.Clock()
|
self._clock = _pg.time.Clock()
|
||||||
self._withfps = False
|
self._withfps = False
|
||||||
self._iconpath = iconpath
|
self._iconpath = iconpath
|
||||||
|
self._isallowdrag = False
|
||||||
|
# self._issmartdrag = False
|
||||||
if iconpath != None:
|
if iconpath != None:
|
||||||
self.tray = _tray(self.title,iconpath)
|
self.tray = _tray(self.title,iconpath)
|
||||||
def update(self, fps=-1):
|
def update(self, fps=-1):
|
||||||
|
@ -27,6 +32,11 @@ class win(_surface):
|
||||||
self._clock.tick(fps)
|
self._clock.tick(fps)
|
||||||
self._withfps = True
|
self._withfps = True
|
||||||
_pg.display.update()
|
_pg.display.update()
|
||||||
|
def resize(self, size=None):
|
||||||
|
if size == None:
|
||||||
|
return self.size
|
||||||
|
else:
|
||||||
|
self._orig = _pg.display.set_mode(value)
|
||||||
def title():
|
def title():
|
||||||
def fget(self):
|
def fget(self):
|
||||||
return _pg.display.get_caption()[0]
|
return _pg.display.get_caption()[0]
|
||||||
|
@ -55,27 +65,67 @@ class win(_surface):
|
||||||
def fullscreen(self):
|
def fullscreen(self):
|
||||||
_pg.display.toogle_fullscreen()
|
_pg.display.toogle_fullscreen()
|
||||||
def close(self):
|
def close(self):
|
||||||
|
# _w32g.PostMessage(self.hwnd, _w32c.WM_CLOSE, 0, 0)
|
||||||
_pg.display.quit()
|
_pg.display.quit()
|
||||||
_w32g.PostMessage(self.hwnd, _w32c.WM_CLOSE, 0, 0)
|
try:self.tray.stop()
|
||||||
self.tray.stop()
|
except:pass
|
||||||
def focus(self):
|
def focus(self):
|
||||||
self.hide()
|
self.hide()
|
||||||
self.show()
|
self.show()
|
||||||
_w32g.BringWindowToTop(self.hwnd)
|
_w32g.BringWindowToTop(self.hwnd)
|
||||||
_w32g.ShowWindow(self.hwnd, _w32c.SW_SHOWNORMAL)
|
_w32g.ShowWindow(self.hwnd, _w32c.SW_SHOWNORMAL)
|
||||||
_w32g.SetForegroundWindow(self.hwnd)
|
_w32g.SetForegroundWindow(self.hwnd)
|
||||||
def unfocus(self):
|
|
||||||
pass
|
|
||||||
def hide(self):
|
def hide(self):
|
||||||
_w32g.ShowWindow(self.hwnd, _w32c.SW_HIDE)
|
_w32g.ShowWindow(self.hwnd, _w32c.SW_HIDE)
|
||||||
def show(self):
|
def show(self):
|
||||||
_w32g.ShowWindow(self.hwnd, _w32c.SW_SHOW)
|
_w32g.ShowWindow(self.hwnd, _w32c.SW_SHOW)
|
||||||
def move(self, x, y):
|
def move(self, x, y):
|
||||||
rect = _w32g.GetWindowRect(self.hwnd)
|
rect = _w32g.GetWindowRect(self.hwnd)
|
||||||
_w32g.MoveWindow(self.hwnd, x, y, rect[2]-x, rect[3]-y, 0)
|
_w32g.MoveWindow(self.hwnd, int(x), int(y),
|
||||||
|
rect[2]-x, rect[3]-y, 0)
|
||||||
def screenshot(self, path):
|
def screenshot(self, path):
|
||||||
_s(self._orig, path)
|
_s(self._orig, path)
|
||||||
return path
|
return path
|
||||||
|
def center(self,x=_w32a.GetSystemMetrics(0)/2,
|
||||||
|
y=_w32a.GetSystemMetrics(1)/2):
|
||||||
|
self.move(x-self.size[0]/2,y-self.size[1]/2)
|
||||||
|
def denyDrag(self):
|
||||||
|
self._isallowdrag = True
|
||||||
|
def loop(self):
|
||||||
|
while self._isallowdrag:
|
||||||
|
pos = _m.get_position()
|
||||||
|
pos = [pos[i]-self.position[i] for i in range(2)]
|
||||||
|
if pos[0] < _w32g.GetWindowRect(self.hwnd)[2]-137:
|
||||||
|
if pos[1] < 30:
|
||||||
|
_m.release('left')
|
||||||
|
_t.Thread(target=lambda:loop(self),daemon=1).start()
|
||||||
|
def allowDrag(self):
|
||||||
|
self._isallowdrag = False
|
||||||
|
# def smartDrag(self, x):
|
||||||
|
# self.allowDrag()
|
||||||
|
# self._issmartdrag = x
|
||||||
|
# if x:
|
||||||
|
# self._isallowdrag = True
|
||||||
|
# def loop(self):
|
||||||
|
# wsd = None
|
||||||
|
# while self._issmartdrag:
|
||||||
|
# self.update()
|
||||||
|
# pos = _m.get_position()
|
||||||
|
# pos = [pos[i]-self.position[i] for i in range(2)]
|
||||||
|
# if pos[0] < _w32g.GetWindowRect(self.hwnd)[2]-137:
|
||||||
|
# if pos[1] < 30:
|
||||||
|
# if _m.is_pressed('left'):
|
||||||
|
# _m.release('left')
|
||||||
|
# if wsd == None:
|
||||||
|
# wsd = pos+list(self.position)
|
||||||
|
# else:
|
||||||
|
# if wsd != pos+list(self.position):
|
||||||
|
# self.move(wsd[2]+(pos[0]-wsd[0]),
|
||||||
|
# wsd[3]+(pos[1]-wsd[1]))
|
||||||
|
# else:
|
||||||
|
# wsd = None
|
||||||
|
# _ti.sleep(0.5)
|
||||||
|
# _t.Thread(target=lambda:loop(self),daemon=1).start()
|
||||||
@property
|
@property
|
||||||
def position(self):
|
def position(self):
|
||||||
rect = _w32g.GetWindowRect(self.hwnd)
|
rect = _w32g.GetWindowRect(self.hwnd)
|
||||||
|
@ -109,7 +159,7 @@ def create(title=None, size=(0,0), icon=None, resizable=False, noframe=False):
|
||||||
_pg.display.set_caption(title)
|
_pg.display.set_caption(title)
|
||||||
if icon != None:
|
if icon != None:
|
||||||
_pg.display.set_icon(_pg.image.load(icon))
|
_pg.display.set_icon(_pg.image.load(icon))
|
||||||
return win(icon)
|
return _win(icon)
|
||||||
|
|
||||||
def ramLimit(memory_limit):
|
def ramLimit(memory_limit):
|
||||||
hjob = _w32j.CreateJobObject(None,job_name)
|
hjob = _w32j.CreateJobObject(None,job_name)
|
||||||
|
|
27
build/lib/pygwin/color.py
Normal file
27
build/lib/pygwin/color.py
Normal file
|
@ -0,0 +1,27 @@
|
||||||
|
class color:
|
||||||
|
def __init__(self,r,g=None,b=None,a=255):
|
||||||
|
try:
|
||||||
|
r,g,b = tuple(int(r[i:i+2],16)for i in(0,2,4))
|
||||||
|
except:
|
||||||
|
pass
|
||||||
|
self.r = r
|
||||||
|
self.g = g
|
||||||
|
self.b = b
|
||||||
|
self.a = a
|
||||||
|
def hex(self):
|
||||||
|
return '%02x%02x%02x' % (self.r,self.g,self.b)
|
||||||
|
def rgb(self):
|
||||||
|
return (self.r,self.g,self.b,self.a)
|
||||||
|
def inverse(self):
|
||||||
|
return color(255-self.r,255-self.g,
|
||||||
|
255-self.b,255-self.a)
|
||||||
|
def __getitem__(self,x):
|
||||||
|
return [self.r,self.g,self.b,self.a][x]
|
||||||
|
def __list__(self):
|
||||||
|
return [self.r,self.g,self.b,self.a]
|
||||||
|
def __tuple__(self):
|
||||||
|
return self.rgb()
|
||||||
|
def __repr__(self):
|
||||||
|
return self.__str__()
|
||||||
|
def __str__(self):
|
||||||
|
return f'({",".join(str(i)for i in self.__list__())})'
|
|
@ -1,6 +1,7 @@
|
||||||
import win32console as w32con
|
import win32console as w32con
|
||||||
import win32con as w32c
|
import win32con as w32c
|
||||||
import win32gui as w32g
|
import win32gui as w32g
|
||||||
|
import win32api as w32a
|
||||||
import pyautogui as pag
|
import pyautogui as pag
|
||||||
|
|
||||||
class console:
|
class console:
|
||||||
|
@ -40,6 +41,9 @@ class console:
|
||||||
pass
|
pass
|
||||||
return locals()
|
return locals()
|
||||||
title = property(**title())
|
title = property(**title())
|
||||||
|
def center(self,x=w32a.GetSystemMetrics(0)/2,
|
||||||
|
y=w32a.GetSystemMetrics(1)/2):
|
||||||
|
self.move(x-self.size[0]/2,y-self.size[1]/2)
|
||||||
@property
|
@property
|
||||||
def visible(self):
|
def visible(self):
|
||||||
return w32g.IsWindowVisible(self.hwnd)
|
return w32g.IsWindowVisible(self.hwnd)
|
||||||
|
|
|
@ -1,19 +1,26 @@
|
||||||
from pygwin._pg import pg as _pg
|
from pygwin._pg import pg as _pg
|
||||||
from pygwin.surface import surface as _surface
|
from pygwin.surface import surface as _surface
|
||||||
from PIL import Image as _im
|
from PIL import Image as _im
|
||||||
|
import tempfile as _tf
|
||||||
|
import randstr as _rs
|
||||||
import pickle as _p
|
import pickle as _p
|
||||||
import bz2 as _bz2
|
import bz2 as _bz2
|
||||||
|
import os as _os
|
||||||
|
|
||||||
def load(path):
|
def load(path):
|
||||||
if path.endswith('.gif'):
|
if path.endswith('.gif'):
|
||||||
im = _im.open(path)
|
im = _im.open(path)
|
||||||
surfs = []
|
with _tf.TemporaryDirectory() as td:
|
||||||
for i in range(im.n_frames):
|
surfs = []
|
||||||
im.seek(i)
|
for i in range(im.n_frames):
|
||||||
image = _pg.image.fromstring(im.tobytes(),im.size,im.mode)
|
im.seek(i)
|
||||||
surf = _surface(image.get_size())
|
p = _os.path.join(td,f'{i}.png')
|
||||||
surf._surface_orig = image
|
im.save(p)
|
||||||
surfs.append(surf)
|
s = _pg.image.load(p)
|
||||||
|
_os.remove(p)
|
||||||
|
sg = _surface(s.get_size())
|
||||||
|
sg.blit(s,(0,0))
|
||||||
|
surfs.append(sg)
|
||||||
return surfs
|
return surfs
|
||||||
else:
|
else:
|
||||||
im = _im.open(path.encode('utf8').decode('utf8'))
|
im = _im.open(path.encode('utf8').decode('utf8'))
|
||||||
|
@ -23,18 +30,10 @@ def load(path):
|
||||||
return surf
|
return surf
|
||||||
|
|
||||||
def save(surface, dest):
|
def save(surface, dest):
|
||||||
if type(surface) == _surface:
|
_pg.image.save_extended(surface._grp(), dest)
|
||||||
orig = surface._surface_orig
|
|
||||||
else:
|
|
||||||
orig = surface._orig
|
|
||||||
_pg.image.save_extended(orig, dest)
|
|
||||||
|
|
||||||
def toBytes(surface):
|
def toBytes(surface):
|
||||||
try:
|
return _bz2.compress(_p.dumps([_pg.image.tostring(surface._grp(),"RGBA"),list(surface.size)]))
|
||||||
orig = surface._surface_orig
|
|
||||||
except:
|
|
||||||
orig = surface._orig
|
|
||||||
return _bz2.compress(_p.dumps([_pg.image.tostring(orig,"RGBA"),list(surface.size)]))
|
|
||||||
|
|
||||||
def fromBytes(bytes):
|
def fromBytes(bytes):
|
||||||
string = _p.loads(_bz2.decompress(bytes))
|
string = _p.loads(_bz2.decompress(bytes))
|
||||||
|
|
|
@ -8,3 +8,15 @@ def getPressed():
|
||||||
return fkeys
|
return fkeys
|
||||||
def isPressed(key):
|
def isPressed(key):
|
||||||
return getPressed()[key]
|
return getPressed()[key]
|
||||||
|
|
||||||
|
import inspect as _i
|
||||||
|
|
||||||
|
_aliases = {'getPressed':['gprs','getkeys'],
|
||||||
|
'isPressed':['isprs','keyprs']}
|
||||||
|
|
||||||
|
for i in _aliases.items():
|
||||||
|
exec(f'args = _i.signature({i[0]})')
|
||||||
|
args = [str(i[1]) for i in dict(args.parameters).items()]
|
||||||
|
args = ', '.join(args)
|
||||||
|
for i0 in i[1]:
|
||||||
|
exec(f"def {i0}({args}):return {i[0]}({args})")
|
||||||
|
|
|
@ -4,7 +4,7 @@ def getPressed():
|
||||||
orig = _pg.mouse.get_pressed(3)
|
orig = _pg.mouse.get_pressed(3)
|
||||||
return {'left':orig[0],'middle':orig[1],'right':orig[2]}
|
return {'left':orig[0],'middle':orig[1],'right':orig[2]}
|
||||||
def isPressed(x):
|
def isPressed(x):
|
||||||
return getPressed()[x]
|
return getPressed()[x.lower()]
|
||||||
def setPosition(x):
|
def setPosition(x):
|
||||||
_pg.mouse.set_pos(x)
|
_pg.mouse.set_pos(x)
|
||||||
def getPosition():
|
def getPosition():
|
||||||
|
@ -20,3 +20,17 @@ def setCursor(size, hotspot=None, xormasks=None, andmasks=None):
|
||||||
_pg.mouse.set_system_cursor(size)
|
_pg.mouse.set_system_cursor(size)
|
||||||
else:
|
else:
|
||||||
_pg.mouse.set_cursor(size, hotspot, xormasks, andmasks)
|
_pg.mouse.set_cursor(size, hotspot, xormasks, andmasks)
|
||||||
|
|
||||||
|
import inspect as _i
|
||||||
|
|
||||||
|
_aliases = {'getPressed':['gprs','getbtns'],
|
||||||
|
'isPressed':['isprs','btnprs'],
|
||||||
|
'setPosition':['spos','setpos','move'],
|
||||||
|
'getPosition':['gpos','getpos']}
|
||||||
|
|
||||||
|
for i in _aliases.items():
|
||||||
|
exec(f'args = _i.signature({i[0]})')
|
||||||
|
args = [str(i[1]) for i in dict(args.parameters).items()]
|
||||||
|
args = ', '.join(args)
|
||||||
|
for i0 in i[1]:
|
||||||
|
exec(f"def {i0}({args}):return {i[0]}({args})")
|
||||||
|
|
|
@ -1,34 +1,60 @@
|
||||||
from pygwin._pg import pg
|
from pygwin._pg import pg
|
||||||
|
|
||||||
|
_aliases = {'w':['width'],'h':['height'],
|
||||||
|
'c':['center','middle'],
|
||||||
|
'x':['left'],'y':['up'],
|
||||||
|
'r':['right'],'d':['down']}
|
||||||
|
|
||||||
class rect:
|
class rect:
|
||||||
def __init__(self,x,y,w,h):
|
def __init__(self,x,y,w,h):
|
||||||
self.x = x
|
self.x = x
|
||||||
self.y = y
|
self.y = y
|
||||||
self.w = w
|
self.w = w
|
||||||
self.h = h
|
self.h = h
|
||||||
self._rect = pg.Rect(x,y,w,h)
|
self._reload()
|
||||||
def width():
|
|
||||||
def fget(self):
|
|
||||||
return self.w
|
|
||||||
def fset(self, value):
|
|
||||||
self.w = value
|
|
||||||
def fdel(self):
|
|
||||||
pass
|
|
||||||
return locals()
|
|
||||||
width = property(**width())
|
|
||||||
def height():
|
|
||||||
def fget(self):
|
|
||||||
return self.h
|
|
||||||
def fset(self, value):
|
|
||||||
self.h = value
|
|
||||||
def fdel(self):
|
|
||||||
pass
|
|
||||||
return locals()
|
|
||||||
height = property(**height())
|
|
||||||
def collide(self, x):
|
def collide(self, x):
|
||||||
try:
|
try:return self._rect.colliderect(x._rect_rect)
|
||||||
return self._rect.colliderect(x._rect_rect)
|
except:return self._rect.colliderect(x._rect)
|
||||||
except:
|
|
||||||
return self._rect.colliderect(x._rect)
|
|
||||||
def contains(self, x, y):
|
def contains(self, x, y):
|
||||||
return self._rect.collidepoint(x,y)
|
return self._rect.collidepoint(x,y)
|
||||||
|
def copy(self):
|
||||||
|
return rect(self.x,self.y,self.w,self.h)
|
||||||
|
def _reload(self):
|
||||||
|
self.c = (self.x/2+self.w/2,self.y/2+self.h/2)
|
||||||
|
self.cx, self.cy = self.c
|
||||||
|
self.r,self.d = self.x+self.w,self.y+self.h
|
||||||
|
self._rect = pg.Rect(self.x,self.y,self.w,self.h)
|
||||||
|
def __getitem__(self,x):
|
||||||
|
return [self.x,self.y,self.w,self.h][x]
|
||||||
|
def __list__(self):
|
||||||
|
return [self.x,self.y,self.w,self.h]
|
||||||
|
def __tuple__(self):
|
||||||
|
return (self.x,self.y,self.w,self.h)
|
||||||
|
def __str__(self):
|
||||||
|
return f'<{self.x}x{self.y},{self.w}x{self.h}>'
|
||||||
|
def __setattr__(self,attr,data):
|
||||||
|
if attr in _aliases.values():
|
||||||
|
ma = None
|
||||||
|
for i in _aliases.items():
|
||||||
|
if i[1] in attr:
|
||||||
|
ma = i[0]
|
||||||
|
break
|
||||||
|
attr = ma
|
||||||
|
object.__setattr__(self,attr,data)
|
||||||
|
def __getattr__(self,attr):
|
||||||
|
if attr in _aliases.values():
|
||||||
|
ma = None
|
||||||
|
for i in _aliases.items():
|
||||||
|
if i[1] == attr:
|
||||||
|
ma = i[0]
|
||||||
|
break
|
||||||
|
attr = ma
|
||||||
|
data = self.__dict__[attr]
|
||||||
|
return data
|
||||||
|
|
||||||
|
|
||||||
|
# def fromSurface(surf,x=0,y=0,c=())
|
||||||
|
#
|
||||||
|
# # print(dir(property))
|
||||||
|
# r = rect(123,321,654,987)
|
||||||
|
# print(r.width)
|
||||||
|
|
|
@ -1,5 +1,11 @@
|
||||||
from pygwin.rect import rect as _r
|
from pygwin.rect import rect as _r
|
||||||
|
from pygwin.color import color as _clr
|
||||||
from pygwin._pg import pg as _pg
|
from pygwin._pg import pg as _pg
|
||||||
|
from PIL import Image as _im
|
||||||
|
import tempfile as _tf
|
||||||
|
import randstr as _rs
|
||||||
|
import time as _t
|
||||||
|
import os as _os
|
||||||
|
|
||||||
class surface:
|
class surface:
|
||||||
def __init__(self, size):
|
def __init__(self, size):
|
||||||
|
@ -8,15 +14,16 @@ class surface:
|
||||||
@property
|
@property
|
||||||
def pixels(self):
|
def pixels(self):
|
||||||
pixels = []
|
pixels = []
|
||||||
pxls = _pg.PixelArray(self._orig)
|
|
||||||
for x in range(self.size[0]):
|
for x in range(self.size[0]):
|
||||||
pixels.append([])
|
pixels.append([])
|
||||||
for y in range(self.size[1]):
|
for y in range(self.size[1]):
|
||||||
pixels[x].append(pxls[x, y])
|
pixels[x].append(self.getPixel(x,y))
|
||||||
return pixels
|
return pixels
|
||||||
@property
|
@property
|
||||||
def size(self):
|
def size(self):
|
||||||
return self._size
|
return self._size
|
||||||
|
def _grp(self):
|
||||||
|
return self._orig
|
||||||
def rect(self, x=0, y=0, center=[]):
|
def rect(self, x=0, y=0, center=[]):
|
||||||
if center == []:
|
if center == []:
|
||||||
return _r(x, y, self.size[0], self.size[1])
|
return _r(x, y, self.size[0], self.size[1])
|
||||||
|
@ -30,7 +37,7 @@ class surface:
|
||||||
surf._surface_size = self._size
|
surf._surface_size = self._size
|
||||||
return surf
|
return surf
|
||||||
def getPixel(self, x, y):
|
def getPixel(self, x, y):
|
||||||
return self._orig.get_at((x,y))
|
return _clr(*self._orig.get_at((x,y)))
|
||||||
def setPixel(self, x, y, color):
|
def setPixel(self, x, y, color):
|
||||||
self._orig.set_at((x,y),color)
|
self._orig.set_at((x,y),color)
|
||||||
return self.copy()
|
return self.copy()
|
||||||
|
@ -47,10 +54,10 @@ class surface:
|
||||||
self._orig.blit(surf, xy)
|
self._orig.blit(surf, xy)
|
||||||
return self.copy()
|
return self.copy()
|
||||||
def fill(self, color):
|
def fill(self, color):
|
||||||
self._orig.fill(color)
|
self._orig.fill(list(color))
|
||||||
return self.copy()
|
return self.copy()
|
||||||
def crop(self, rect):
|
def crop(self, rect):
|
||||||
self._orig = self._orig.subsurface((rect.x,rect.y,rect.w,rect.h))
|
self._orig = self._orig.subsurface(rect)
|
||||||
self._size = self._orig.get_size()
|
self._size = self._orig.get_size()
|
||||||
return self.copy()
|
return self.copy()
|
||||||
def scale(self, size, smooth=False):
|
def scale(self, size, smooth=False):
|
||||||
|
@ -75,6 +82,7 @@ class surface:
|
||||||
self._orig = _pg.transform.smoothscale(self._orig,scale)
|
self._orig = _pg.transform.smoothscale(self._orig,scale)
|
||||||
self._orig = _pg.transform.smoothscale(self._orig,size)
|
self._orig = _pg.transform.smoothscale(self._orig,size)
|
||||||
return self.copy()
|
return self.copy()
|
||||||
|
|
||||||
class _draw:
|
class _draw:
|
||||||
def __init__(self,surface):
|
def __init__(self,surface):
|
||||||
self._surf = surface
|
self._surf = surface
|
||||||
|
@ -88,10 +96,9 @@ class surface:
|
||||||
orig = self._surf._surface_orig
|
orig = self._surf._surface_orig
|
||||||
except:
|
except:
|
||||||
orig = self._surf._orig
|
orig = self._surf._orig
|
||||||
_pg.draw.rect(orig,color,_pg.Rect(rect.x,rect.y,rect.w,rect.h),
|
_pg.draw.rect(orig,color,_pg.Rect(rect[0],rect[1],rect[2],rect[3]),
|
||||||
width,borderRadius,borderTopLeftRadius,
|
width,borderRadius,borderTopLeftRadius,borderTopRightRadius,
|
||||||
borderTopRightRadius,borderBottomLeftRadius,
|
borderBottomLeftRadius,borderBottomRightRadius)
|
||||||
borderBottomRightRadius)
|
|
||||||
return self._surf.copy()
|
return self._surf.copy()
|
||||||
def polygon(self, color, points, width=0):
|
def polygon(self, color, points, width=0):
|
||||||
try:
|
try:
|
||||||
|
@ -119,7 +126,8 @@ class surface:
|
||||||
orig = self._surf._surface_orig
|
orig = self._surf._surface_orig
|
||||||
except:
|
except:
|
||||||
orig = self._surf._orig
|
orig = self._surf._orig
|
||||||
_pg.draw.ellipse(orig,color,_pg.Rect(rect.x,rect.y,rect.w,rect.h),width)
|
_pg.draw.ellipse(orig,color,_pg.Rect(rect[0],
|
||||||
|
rect[1],rect[2],rect[3]),width)
|
||||||
return self._surf.copy()
|
return self._surf.copy()
|
||||||
def line(self,color,start,end,width=1):
|
def line(self,color,start,end,width=1):
|
||||||
try:
|
try:
|
||||||
|
@ -133,8 +141,8 @@ class surface:
|
||||||
orig = self._surf._surface_orig
|
orig = self._surf._surface_orig
|
||||||
except:
|
except:
|
||||||
orig = self._surf._orig
|
orig = self._surf._orig
|
||||||
_pg.draw.arc(orig,color,
|
_pg.draw.arc(orig,color,_pg.Rect(rect[0],
|
||||||
_pg.Rect(rect.x,rect.y,rect.w,rect.h),
|
rect[1],rect[2],rect[3]),
|
||||||
startAngle,stopAngle,width)
|
startAngle,stopAngle,width)
|
||||||
return self._surf.copy()
|
return self._surf.copy()
|
||||||
@property
|
@property
|
||||||
|
|
|
@ -703,7 +703,7 @@ class base:
|
||||||
self._widgets[self._page].remove(i)
|
self._widgets[self._page].remove(i)
|
||||||
def put(self, widget, pos, page=0):
|
def put(self, widget, pos, page=0):
|
||||||
if page not in self._widgets:
|
if page not in self._widgets:
|
||||||
self._widgets.update({page:[]})
|
self.blankPage(page)
|
||||||
self._widgets[page].append([widget, pos])
|
self._widgets[page].append([widget, pos])
|
||||||
def selectPage(self, page):
|
def selectPage(self, page):
|
||||||
self._page = page
|
self._page = page
|
||||||
|
@ -713,3 +713,5 @@ class base:
|
||||||
return self._widgets[page]
|
return self._widgets[page]
|
||||||
def setWidgetPos(self,index,pos,page=0):
|
def setWidgetPos(self,index,pos,page=0):
|
||||||
self._widgets[page][index] = [self._widgets[page][index][0], pos]
|
self._widgets[page][index] = [self._widgets[page][index][0], pos]
|
||||||
|
def blankPage(self,page):
|
||||||
|
self._widgets.update({page:[]})
|
||||||
|
|
BIN
dist/pgw-0.0.4-py3-none-any.whl
vendored
Normal file
BIN
dist/pgw-0.0.4-py3-none-any.whl
vendored
Normal file
Binary file not shown.
BIN
dist/pgw-0.0.4.tar.gz
vendored
Normal file
BIN
dist/pgw-0.0.4.tar.gz
vendored
Normal file
Binary file not shown.
BIN
dist/pgw-0.0.5-py3-none-any.whl
vendored
Normal file
BIN
dist/pgw-0.0.5-py3-none-any.whl
vendored
Normal file
Binary file not shown.
BIN
dist/pgw-0.0.5-py3.7.egg
vendored
Normal file
BIN
dist/pgw-0.0.5-py3.7.egg
vendored
Normal file
Binary file not shown.
BIN
dist/pgw-0.0.5.tar.gz
vendored
Normal file
BIN
dist/pgw-0.0.5.tar.gz
vendored
Normal file
Binary file not shown.
BIN
dist/pgw-0.0.6-py3-none-any.whl
vendored
Normal file
BIN
dist/pgw-0.0.6-py3-none-any.whl
vendored
Normal file
Binary file not shown.
BIN
dist/pgw-0.0.6-py3.7.egg
vendored
Normal file
BIN
dist/pgw-0.0.6-py3.7.egg
vendored
Normal file
Binary file not shown.
BIN
dist/pgw-0.0.6.tar.gz
vendored
Normal file
BIN
dist/pgw-0.0.6.tar.gz
vendored
Normal file
Binary file not shown.
BIN
dist/pgw-0.0.7-py3-none-any.whl
vendored
Normal file
BIN
dist/pgw-0.0.7-py3-none-any.whl
vendored
Normal file
Binary file not shown.
BIN
dist/pgw-0.0.7-py3.7.egg
vendored
Normal file
BIN
dist/pgw-0.0.7-py3.7.egg
vendored
Normal file
Binary file not shown.
BIN
dist/pgw-0.0.7.tar.gz
vendored
Normal file
BIN
dist/pgw-0.0.7.tar.gz
vendored
Normal file
Binary file not shown.
BIN
dist/pgw-0.0.8-py3-none-any.whl
vendored
Normal file
BIN
dist/pgw-0.0.8-py3-none-any.whl
vendored
Normal file
Binary file not shown.
BIN
dist/pgw-0.0.8-py3.7.egg
vendored
Normal file
BIN
dist/pgw-0.0.8-py3.7.egg
vendored
Normal file
Binary file not shown.
BIN
dist/pgw-0.0.8.tar.gz
vendored
Normal file
BIN
dist/pgw-0.0.8.tar.gz
vendored
Normal file
Binary file not shown.
BIN
dist/pgw-0.0.9-py3.7.egg
vendored
Normal file
BIN
dist/pgw-0.0.9-py3.7.egg
vendored
Normal file
Binary file not shown.
BIN
dist/pgw-0.1.0-py3-none-any.whl
vendored
Normal file
BIN
dist/pgw-0.1.0-py3-none-any.whl
vendored
Normal file
Binary file not shown.
BIN
dist/pgw-0.1.0-py3.7.egg
vendored
Normal file
BIN
dist/pgw-0.1.0-py3.7.egg
vendored
Normal file
Binary file not shown.
BIN
dist/pgw-0.1.0.tar.gz
vendored
Normal file
BIN
dist/pgw-0.1.0.tar.gz
vendored
Normal file
Binary file not shown.
|
@ -8,6 +8,7 @@ requires = [
|
||||||
"inputs",
|
"inputs",
|
||||||
"pillow",
|
"pillow",
|
||||||
"wxPython",
|
"wxPython",
|
||||||
|
"randstr",
|
||||||
"setuptools >=42"
|
"setuptools >=42"
|
||||||
]
|
]
|
||||||
build-backend = "setuptools.build_meta"
|
build-backend = "setuptools.build_meta"
|
||||||
|
|
|
@ -1,2 +1,4 @@
|
||||||
@echo off
|
@echo off
|
||||||
|
pip uninstall pgw -y
|
||||||
python setup.py install
|
python setup.py install
|
||||||
|
pipwin install pyaudio
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
[metadata]
|
[metadata]
|
||||||
name = pgw
|
name = pgw
|
||||||
version = 0.0.4
|
version = 0.1.0
|
||||||
author = themixray
|
author = themixray
|
||||||
author_email = simindeymo@gmail.com
|
author_email = simindeymo@gmail.com
|
||||||
description = Python Grapchical Window.
|
description = Python Grapchical Window.
|
||||||
|
|
10
setup.py
10
setup.py
|
@ -1,8 +1,6 @@
|
||||||
from setuptools import setup
|
from setuptools import setup
|
||||||
|
|
||||||
setup(name='pgw',packages=['pygwin'],version='0.0.4',author='themixray',
|
setup(name='pgw',packages=['pygwin'],version='0.1.0',
|
||||||
description='A library for creating Python applications.',
|
author='themixray',description='A library for creating Python applications.',
|
||||||
license='MIT',install_requires=
|
license='MIT',install_requires=['cython','pywin32','pygame','inputs','randstr',
|
||||||
['cython','pywin32','pygame','inputs',
|
'pydub','wxPython','pyautogui','moviepy','pipwin','wave','opencv-python'])
|
||||||
'pydub','wxPython','pyautogui','moviepy',
|
|
||||||
'pipwin','wave','opencv-python'])
|
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
Metadata-Version: 2.1
|
Metadata-Version: 2.1
|
||||||
Name: pgw
|
Name: pgw
|
||||||
Version: 0.0.4
|
Version: 0.1.0
|
||||||
Summary: A library for creating Python applications.
|
Summary: A library for creating Python applications.
|
||||||
Home-page: https://github.com/themixray/pygwin
|
Home-page: https://github.com/themixray/pygwin
|
||||||
Author: themixray
|
Author: themixray
|
||||||
|
|
|
@ -11,6 +11,7 @@ src/pgw.egg-info/top_level.txt
|
||||||
src/pygwin/__init__.py
|
src/pygwin/__init__.py
|
||||||
src/pygwin/_pg.py
|
src/pygwin/_pg.py
|
||||||
src/pygwin/_win.py
|
src/pygwin/_win.py
|
||||||
|
src/pygwin/color.py
|
||||||
src/pygwin/console.py
|
src/pygwin/console.py
|
||||||
src/pygwin/font.py
|
src/pygwin/font.py
|
||||||
src/pygwin/gamepad.py
|
src/pygwin/gamepad.py
|
||||||
|
|
|
@ -2,6 +2,7 @@ cython
|
||||||
pywin32
|
pywin32
|
||||||
pygame
|
pygame
|
||||||
inputs
|
inputs
|
||||||
|
randstr
|
||||||
pydub
|
pydub
|
||||||
wxPython
|
wxPython
|
||||||
pyautogui
|
pyautogui
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
from pygwin.surface import surface
|
from pygwin.surface import surface
|
||||||
import pygwin.keyboard as keyboard
|
import pygwin.keyboard as keyboard
|
||||||
from pygwin.console import console
|
from pygwin.console import console
|
||||||
|
from pygwin.color import color
|
||||||
import pygwin.gamepad as _gp
|
import pygwin.gamepad as _gp
|
||||||
import pygwin.mouse as mouse
|
import pygwin.mouse as mouse
|
||||||
from pygwin.rect import rect
|
from pygwin.rect import rect
|
||||||
|
|
BIN
src/pygwin/__pycache__/__init__.cpython-37.pyc
Normal file
BIN
src/pygwin/__pycache__/__init__.cpython-37.pyc
Normal file
Binary file not shown.
BIN
src/pygwin/__pycache__/_pg.cpython-37.pyc
Normal file
BIN
src/pygwin/__pycache__/_pg.cpython-37.pyc
Normal file
Binary file not shown.
BIN
src/pygwin/__pycache__/_win.cpython-37.pyc
Normal file
BIN
src/pygwin/__pycache__/_win.cpython-37.pyc
Normal file
Binary file not shown.
BIN
src/pygwin/__pycache__/console.cpython-37.pyc
Normal file
BIN
src/pygwin/__pycache__/console.cpython-37.pyc
Normal file
Binary file not shown.
BIN
src/pygwin/__pycache__/font.cpython-37.pyc
Normal file
BIN
src/pygwin/__pycache__/font.cpython-37.pyc
Normal file
Binary file not shown.
BIN
src/pygwin/__pycache__/gamepad.cpython-37.pyc
Normal file
BIN
src/pygwin/__pycache__/gamepad.cpython-37.pyc
Normal file
Binary file not shown.
BIN
src/pygwin/__pycache__/image.cpython-37.pyc
Normal file
BIN
src/pygwin/__pycache__/image.cpython-37.pyc
Normal file
Binary file not shown.
BIN
src/pygwin/__pycache__/keyboard.cpython-37.pyc
Normal file
BIN
src/pygwin/__pycache__/keyboard.cpython-37.pyc
Normal file
Binary file not shown.
BIN
src/pygwin/__pycache__/mixer.cpython-37.pyc
Normal file
BIN
src/pygwin/__pycache__/mixer.cpython-37.pyc
Normal file
Binary file not shown.
BIN
src/pygwin/__pycache__/mouse.cpython-37.pyc
Normal file
BIN
src/pygwin/__pycache__/mouse.cpython-37.pyc
Normal file
Binary file not shown.
BIN
src/pygwin/__pycache__/rect.cpython-37.pyc
Normal file
BIN
src/pygwin/__pycache__/rect.cpython-37.pyc
Normal file
Binary file not shown.
BIN
src/pygwin/__pycache__/surface.cpython-37.pyc
Normal file
BIN
src/pygwin/__pycache__/surface.cpython-37.pyc
Normal file
Binary file not shown.
BIN
src/pygwin/__pycache__/tray.cpython-37.pyc
Normal file
BIN
src/pygwin/__pycache__/tray.cpython-37.pyc
Normal file
Binary file not shown.
BIN
src/pygwin/__pycache__/ui.cpython-37.pyc
Normal file
BIN
src/pygwin/__pycache__/ui.cpython-37.pyc
Normal file
Binary file not shown.
|
@ -10,9 +10,12 @@ import win32con as _w32c
|
||||||
import win32gui as _w32g
|
import win32gui as _w32g
|
||||||
import requests as _req
|
import requests as _req
|
||||||
import tempfile as _tf
|
import tempfile as _tf
|
||||||
|
import threading as _t
|
||||||
import pickle as _p
|
import pickle as _p
|
||||||
|
import mouse as _m
|
||||||
|
import time as _ti
|
||||||
|
|
||||||
class win(_surface):
|
class _win(_surface):
|
||||||
def __init__(self, iconpath=None):
|
def __init__(self, iconpath=None):
|
||||||
self._orig = _pg.display.get_surface()
|
self._orig = _pg.display.get_surface()
|
||||||
super().__init__(self._orig.get_size())
|
super().__init__(self._orig.get_size())
|
||||||
|
@ -20,6 +23,8 @@ class win(_surface):
|
||||||
self._clock = _pg.time.Clock()
|
self._clock = _pg.time.Clock()
|
||||||
self._withfps = False
|
self._withfps = False
|
||||||
self._iconpath = iconpath
|
self._iconpath = iconpath
|
||||||
|
self._isallowdrag = False
|
||||||
|
# self._issmartdrag = False
|
||||||
if iconpath != None:
|
if iconpath != None:
|
||||||
self.tray = _tray(self.title,iconpath)
|
self.tray = _tray(self.title,iconpath)
|
||||||
def update(self, fps=-1):
|
def update(self, fps=-1):
|
||||||
|
@ -27,6 +32,11 @@ class win(_surface):
|
||||||
self._clock.tick(fps)
|
self._clock.tick(fps)
|
||||||
self._withfps = True
|
self._withfps = True
|
||||||
_pg.display.update()
|
_pg.display.update()
|
||||||
|
def resize(self, size=None):
|
||||||
|
if size == None:
|
||||||
|
return self.size
|
||||||
|
else:
|
||||||
|
self._orig = _pg.display.set_mode(size)
|
||||||
def title():
|
def title():
|
||||||
def fget(self):
|
def fget(self):
|
||||||
return _pg.display.get_caption()[0]
|
return _pg.display.get_caption()[0]
|
||||||
|
@ -55,27 +65,67 @@ class win(_surface):
|
||||||
def fullscreen(self):
|
def fullscreen(self):
|
||||||
_pg.display.toogle_fullscreen()
|
_pg.display.toogle_fullscreen()
|
||||||
def close(self):
|
def close(self):
|
||||||
|
# _w32g.PostMessage(self.hwnd, _w32c.WM_CLOSE, 0, 0)
|
||||||
_pg.display.quit()
|
_pg.display.quit()
|
||||||
_w32g.PostMessage(self.hwnd, _w32c.WM_CLOSE, 0, 0)
|
try:self.tray.stop()
|
||||||
self.tray.stop()
|
except:pass
|
||||||
def focus(self):
|
def focus(self):
|
||||||
self.hide()
|
self.hide()
|
||||||
self.show()
|
self.show()
|
||||||
_w32g.BringWindowToTop(self.hwnd)
|
_w32g.BringWindowToTop(self.hwnd)
|
||||||
_w32g.ShowWindow(self.hwnd, _w32c.SW_SHOWNORMAL)
|
_w32g.ShowWindow(self.hwnd, _w32c.SW_SHOWNORMAL)
|
||||||
_w32g.SetForegroundWindow(self.hwnd)
|
_w32g.SetForegroundWindow(self.hwnd)
|
||||||
def unfocus(self):
|
|
||||||
pass
|
|
||||||
def hide(self):
|
def hide(self):
|
||||||
_w32g.ShowWindow(self.hwnd, _w32c.SW_HIDE)
|
_w32g.ShowWindow(self.hwnd, _w32c.SW_HIDE)
|
||||||
def show(self):
|
def show(self):
|
||||||
_w32g.ShowWindow(self.hwnd, _w32c.SW_SHOW)
|
_w32g.ShowWindow(self.hwnd, _w32c.SW_SHOW)
|
||||||
def move(self, x, y):
|
def move(self, x, y):
|
||||||
rect = _w32g.GetWindowRect(self.hwnd)
|
rect = _w32g.GetWindowRect(self.hwnd)
|
||||||
_w32g.MoveWindow(self.hwnd, x, y, rect[2]-x, rect[3]-y, 0)
|
_w32g.MoveWindow(self.hwnd, int(x), int(y),
|
||||||
|
rect[2]-x, rect[3]-y, 0)
|
||||||
def screenshot(self, path):
|
def screenshot(self, path):
|
||||||
_s(self._orig, path)
|
_s(self._orig, path)
|
||||||
return path
|
return path
|
||||||
|
def center(self,x=_w32a.GetSystemMetrics(0)/2,
|
||||||
|
y=_w32a.GetSystemMetrics(1)/2):
|
||||||
|
self.move(x-self.size[0]/2,y-self.size[1]/2)
|
||||||
|
def denyDrag(self):
|
||||||
|
self._isallowdrag = True
|
||||||
|
def loop(self):
|
||||||
|
while self._isallowdrag:
|
||||||
|
pos = _m.get_position()
|
||||||
|
pos = [pos[i]-self.position[i] for i in range(2)]
|
||||||
|
if pos[0] < _w32g.GetWindowRect(self.hwnd)[2]-137:
|
||||||
|
if pos[1] < 30:
|
||||||
|
_m.release('left')
|
||||||
|
_t.Thread(target=lambda:loop(self),daemon=1).start()
|
||||||
|
def allowDrag(self):
|
||||||
|
self._isallowdrag = False
|
||||||
|
# def smartDrag(self, x):
|
||||||
|
# self.allowDrag()
|
||||||
|
# self._issmartdrag = x
|
||||||
|
# if x:
|
||||||
|
# self._isallowdrag = True
|
||||||
|
# def loop(self):
|
||||||
|
# wsd = None
|
||||||
|
# while self._issmartdrag:
|
||||||
|
# self.update()
|
||||||
|
# pos = _m.get_position()
|
||||||
|
# pos = [pos[i]-self.position[i] for i in range(2)]
|
||||||
|
# if pos[0] < _w32g.GetWindowRect(self.hwnd)[2]-137:
|
||||||
|
# if pos[1] < 30:
|
||||||
|
# if _m.is_pressed('left'):
|
||||||
|
# _m.release('left')
|
||||||
|
# if wsd == None:
|
||||||
|
# wsd = pos+list(self.position)
|
||||||
|
# else:
|
||||||
|
# if wsd != pos+list(self.position):
|
||||||
|
# self.move(wsd[2]+(pos[0]-wsd[0]),
|
||||||
|
# wsd[3]+(pos[1]-wsd[1]))
|
||||||
|
# else:
|
||||||
|
# wsd = None
|
||||||
|
# _ti.sleep(0.5)
|
||||||
|
# _t.Thread(target=lambda:loop(self),daemon=1).start()
|
||||||
@property
|
@property
|
||||||
def position(self):
|
def position(self):
|
||||||
rect = _w32g.GetWindowRect(self.hwnd)
|
rect = _w32g.GetWindowRect(self.hwnd)
|
||||||
|
@ -109,7 +159,7 @@ def create(title=None, size=(0,0), icon=None, resizable=False, noframe=False):
|
||||||
_pg.display.set_caption(title)
|
_pg.display.set_caption(title)
|
||||||
if icon != None:
|
if icon != None:
|
||||||
_pg.display.set_icon(_pg.image.load(icon))
|
_pg.display.set_icon(_pg.image.load(icon))
|
||||||
return win(icon)
|
return _win(icon)
|
||||||
|
|
||||||
def ramLimit(memory_limit):
|
def ramLimit(memory_limit):
|
||||||
hjob = _w32j.CreateJobObject(None,job_name)
|
hjob = _w32j.CreateJobObject(None,job_name)
|
||||||
|
|
27
src/pygwin/color.py
Normal file
27
src/pygwin/color.py
Normal file
|
@ -0,0 +1,27 @@
|
||||||
|
class color:
|
||||||
|
def __init__(self,r,g=None,b=None,a=255):
|
||||||
|
try:
|
||||||
|
r,g,b = tuple(int(r[i:i+2],16)for i in(0,2,4))
|
||||||
|
except:
|
||||||
|
pass
|
||||||
|
self.r = r
|
||||||
|
self.g = g
|
||||||
|
self.b = b
|
||||||
|
self.a = a
|
||||||
|
def hex(self):
|
||||||
|
return '%02x%02x%02x' % (self.r,self.g,self.b)
|
||||||
|
def rgb(self):
|
||||||
|
return (self.r,self.g,self.b,self.a)
|
||||||
|
def inverse(self):
|
||||||
|
return color(255-self.r,255-self.g,
|
||||||
|
255-self.b,255-self.a)
|
||||||
|
def __getitem__(self,x):
|
||||||
|
return [self.r,self.g,self.b,self.a][x]
|
||||||
|
def __list__(self):
|
||||||
|
return [self.r,self.g,self.b,self.a]
|
||||||
|
def __tuple__(self):
|
||||||
|
return self.rgb()
|
||||||
|
def __repr__(self):
|
||||||
|
return self.__str__()
|
||||||
|
def __str__(self):
|
||||||
|
return f'({",".join(str(i)for i in self.__list__())})'
|
|
@ -1,6 +1,7 @@
|
||||||
import win32console as w32con
|
import win32console as w32con
|
||||||
import win32con as w32c
|
import win32con as w32c
|
||||||
import win32gui as w32g
|
import win32gui as w32g
|
||||||
|
import win32api as w32a
|
||||||
import pyautogui as pag
|
import pyautogui as pag
|
||||||
|
|
||||||
class console:
|
class console:
|
||||||
|
@ -40,6 +41,9 @@ class console:
|
||||||
pass
|
pass
|
||||||
return locals()
|
return locals()
|
||||||
title = property(**title())
|
title = property(**title())
|
||||||
|
def center(self,x=w32a.GetSystemMetrics(0)/2,
|
||||||
|
y=w32a.GetSystemMetrics(1)/2):
|
||||||
|
self.move(x-self.size[0]/2,y-self.size[1]/2)
|
||||||
@property
|
@property
|
||||||
def visible(self):
|
def visible(self):
|
||||||
return w32g.IsWindowVisible(self.hwnd)
|
return w32g.IsWindowVisible(self.hwnd)
|
||||||
|
|
|
@ -1,19 +1,26 @@
|
||||||
from pygwin._pg import pg as _pg
|
from pygwin._pg import pg as _pg
|
||||||
from pygwin.surface import surface as _surface
|
from pygwin.surface import surface as _surface
|
||||||
from PIL import Image as _im
|
from PIL import Image as _im
|
||||||
|
import tempfile as _tf
|
||||||
|
import randstr as _rs
|
||||||
import pickle as _p
|
import pickle as _p
|
||||||
import bz2 as _bz2
|
import bz2 as _bz2
|
||||||
|
import os as _os
|
||||||
|
|
||||||
def load(path):
|
def load(path):
|
||||||
if path.endswith('.gif'):
|
if path.endswith('.gif'):
|
||||||
im = _im.open(path)
|
im = _im.open(path)
|
||||||
surfs = []
|
with _tf.TemporaryDirectory() as td:
|
||||||
for i in range(im.n_frames):
|
surfs = []
|
||||||
im.seek(i)
|
for i in range(im.n_frames):
|
||||||
image = _pg.image.fromstring(im.tobytes(),im.size,im.mode)
|
im.seek(i)
|
||||||
surf = _surface(image.get_size())
|
p = _os.path.join(td,f'{i}.png')
|
||||||
surf._surface_orig = image
|
im.save(p)
|
||||||
surfs.append(surf)
|
s = _pg.image.load(p)
|
||||||
|
_os.remove(p)
|
||||||
|
sg = _surface(s.get_size())
|
||||||
|
sg.blit(s,(0,0))
|
||||||
|
surfs.append(sg)
|
||||||
return surfs
|
return surfs
|
||||||
else:
|
else:
|
||||||
im = _im.open(path.encode('utf8').decode('utf8'))
|
im = _im.open(path.encode('utf8').decode('utf8'))
|
||||||
|
@ -23,18 +30,10 @@ def load(path):
|
||||||
return surf
|
return surf
|
||||||
|
|
||||||
def save(surface, dest):
|
def save(surface, dest):
|
||||||
if type(surface) == _surface:
|
_pg.image.save_extended(surface._grp(), dest)
|
||||||
orig = surface._surface_orig
|
|
||||||
else:
|
|
||||||
orig = surface._orig
|
|
||||||
_pg.image.save_extended(orig, dest)
|
|
||||||
|
|
||||||
def toBytes(surface):
|
def toBytes(surface):
|
||||||
try:
|
return _bz2.compress(_p.dumps([_pg.image.tostring(surface._grp(),"RGBA"),list(surface.size)]))
|
||||||
orig = surface._surface_orig
|
|
||||||
except:
|
|
||||||
orig = surface._orig
|
|
||||||
return _bz2.compress(_p.dumps([_pg.image.tostring(orig,"RGBA"),list(surface.size)]))
|
|
||||||
|
|
||||||
def fromBytes(bytes):
|
def fromBytes(bytes):
|
||||||
string = _p.loads(_bz2.decompress(bytes))
|
string = _p.loads(_bz2.decompress(bytes))
|
||||||
|
|
|
@ -8,3 +8,15 @@ def getPressed():
|
||||||
return fkeys
|
return fkeys
|
||||||
def isPressed(key):
|
def isPressed(key):
|
||||||
return getPressed()[key]
|
return getPressed()[key]
|
||||||
|
|
||||||
|
import inspect as _i
|
||||||
|
|
||||||
|
_aliases = {'getPressed':['gprs','getkeys'],
|
||||||
|
'isPressed':['isprs','keyprs']}
|
||||||
|
|
||||||
|
for i in _aliases.items():
|
||||||
|
exec(f'args = _i.signature({i[0]})')
|
||||||
|
args = [str(i[1]) for i in dict(args.parameters).items()]
|
||||||
|
args = ', '.join(args)
|
||||||
|
for i0 in i[1]:
|
||||||
|
exec(f"def {i0}({args}):return {i[0]}({args})")
|
||||||
|
|
|
@ -4,7 +4,7 @@ def getPressed():
|
||||||
orig = _pg.mouse.get_pressed(3)
|
orig = _pg.mouse.get_pressed(3)
|
||||||
return {'left':orig[0],'middle':orig[1],'right':orig[2]}
|
return {'left':orig[0],'middle':orig[1],'right':orig[2]}
|
||||||
def isPressed(x):
|
def isPressed(x):
|
||||||
return getPressed()[x]
|
return getPressed()[x.lower()]
|
||||||
def setPosition(x):
|
def setPosition(x):
|
||||||
_pg.mouse.set_pos(x)
|
_pg.mouse.set_pos(x)
|
||||||
def getPosition():
|
def getPosition():
|
||||||
|
@ -20,3 +20,17 @@ def setCursor(size, hotspot=None, xormasks=None, andmasks=None):
|
||||||
_pg.mouse.set_system_cursor(size)
|
_pg.mouse.set_system_cursor(size)
|
||||||
else:
|
else:
|
||||||
_pg.mouse.set_cursor(size, hotspot, xormasks, andmasks)
|
_pg.mouse.set_cursor(size, hotspot, xormasks, andmasks)
|
||||||
|
|
||||||
|
import inspect as _i
|
||||||
|
|
||||||
|
_aliases = {'getPressed':['gprs','getbtns'],
|
||||||
|
'isPressed':['isprs','btnprs'],
|
||||||
|
'setPosition':['spos','setpos','move'],
|
||||||
|
'getPosition':['gpos','getpos']}
|
||||||
|
|
||||||
|
for i in _aliases.items():
|
||||||
|
exec(f'args = _i.signature({i[0]})')
|
||||||
|
args = [str(i[1]) for i in dict(args.parameters).items()]
|
||||||
|
args = ', '.join(args)
|
||||||
|
for i0 in i[1]:
|
||||||
|
exec(f"def {i0}({args}):return {i[0]}({args})")
|
||||||
|
|
|
@ -1,34 +1,60 @@
|
||||||
from pygwin._pg import pg
|
from pygwin._pg import pg
|
||||||
|
|
||||||
|
_aliases = {'w':['width'],'h':['height'],
|
||||||
|
'c':['center','middle'],
|
||||||
|
'x':['left'],'y':['up'],
|
||||||
|
'r':['right'],'d':['down']}
|
||||||
|
|
||||||
class rect:
|
class rect:
|
||||||
def __init__(self,x,y,w,h):
|
def __init__(self,x,y,w,h):
|
||||||
self.x = x
|
self.x = x
|
||||||
self.y = y
|
self.y = y
|
||||||
self.w = w
|
self.w = w
|
||||||
self.h = h
|
self.h = h
|
||||||
self._rect = pg.Rect(x,y,w,h)
|
self._reload()
|
||||||
def width():
|
|
||||||
def fget(self):
|
|
||||||
return self.w
|
|
||||||
def fset(self, value):
|
|
||||||
self.w = value
|
|
||||||
def fdel(self):
|
|
||||||
pass
|
|
||||||
return locals()
|
|
||||||
width = property(**width())
|
|
||||||
def height():
|
|
||||||
def fget(self):
|
|
||||||
return self.h
|
|
||||||
def fset(self, value):
|
|
||||||
self.h = value
|
|
||||||
def fdel(self):
|
|
||||||
pass
|
|
||||||
return locals()
|
|
||||||
height = property(**height())
|
|
||||||
def collide(self, x):
|
def collide(self, x):
|
||||||
try:
|
try:return self._rect.colliderect(x._rect_rect)
|
||||||
return self._rect.colliderect(x._rect_rect)
|
except:return self._rect.colliderect(x._rect)
|
||||||
except:
|
|
||||||
return self._rect.colliderect(x._rect)
|
|
||||||
def contains(self, x, y):
|
def contains(self, x, y):
|
||||||
return self._rect.collidepoint(x,y)
|
return self._rect.collidepoint(x,y)
|
||||||
|
def copy(self):
|
||||||
|
return rect(self.x,self.y,self.w,self.h)
|
||||||
|
def _reload(self):
|
||||||
|
self.c = (self.x/2+self.w/2,self.y/2+self.h/2)
|
||||||
|
self.cx, self.cy = self.c
|
||||||
|
self.r,self.d = self.x+self.w,self.y+self.h
|
||||||
|
self._rect = pg.Rect(self.x,self.y,self.w,self.h)
|
||||||
|
def __getitem__(self,x):
|
||||||
|
return [self.x,self.y,self.w,self.h][x]
|
||||||
|
def __list__(self):
|
||||||
|
return [self.x,self.y,self.w,self.h]
|
||||||
|
def __tuple__(self):
|
||||||
|
return (self.x,self.y,self.w,self.h)
|
||||||
|
def __str__(self):
|
||||||
|
return f'<{self.x}x{self.y},{self.w}x{self.h}>'
|
||||||
|
def __setattr__(self,attr,data):
|
||||||
|
if attr in _aliases.values():
|
||||||
|
ma = None
|
||||||
|
for i in _aliases.items():
|
||||||
|
if i[1] in attr:
|
||||||
|
ma = i[0]
|
||||||
|
break
|
||||||
|
attr = ma
|
||||||
|
object.__setattr__(self,attr,data)
|
||||||
|
def __getattr__(self,attr):
|
||||||
|
if attr in _aliases.values():
|
||||||
|
ma = None
|
||||||
|
for i in _aliases.items():
|
||||||
|
if i[1] == attr:
|
||||||
|
ma = i[0]
|
||||||
|
break
|
||||||
|
attr = ma
|
||||||
|
data = self.__dict__[attr]
|
||||||
|
return data
|
||||||
|
|
||||||
|
|
||||||
|
# def fromSurface(surf,x=0,y=0,c=())
|
||||||
|
#
|
||||||
|
# # print(dir(property))
|
||||||
|
# r = rect(123,321,654,987)
|
||||||
|
# print(r.width)
|
||||||
|
|
|
@ -1,5 +1,11 @@
|
||||||
from pygwin.rect import rect as _r
|
from pygwin.rect import rect as _r
|
||||||
|
from pygwin.color import color as _clr
|
||||||
from pygwin._pg import pg as _pg
|
from pygwin._pg import pg as _pg
|
||||||
|
from PIL import Image as _im
|
||||||
|
import tempfile as _tf
|
||||||
|
import randstr as _rs
|
||||||
|
import time as _t
|
||||||
|
import os as _os
|
||||||
|
|
||||||
class surface:
|
class surface:
|
||||||
def __init__(self, size):
|
def __init__(self, size):
|
||||||
|
@ -8,15 +14,16 @@ class surface:
|
||||||
@property
|
@property
|
||||||
def pixels(self):
|
def pixels(self):
|
||||||
pixels = []
|
pixels = []
|
||||||
pxls = _pg.PixelArray(self._orig)
|
|
||||||
for x in range(self.size[0]):
|
for x in range(self.size[0]):
|
||||||
pixels.append([])
|
pixels.append([])
|
||||||
for y in range(self.size[1]):
|
for y in range(self.size[1]):
|
||||||
pixels[x].append(pxls[x, y])
|
pixels[x].append(self.getPixel(x,y))
|
||||||
return pixels
|
return pixels
|
||||||
@property
|
@property
|
||||||
def size(self):
|
def size(self):
|
||||||
return self._size
|
return self._size
|
||||||
|
def _grp(self):
|
||||||
|
return self._orig
|
||||||
def rect(self, x=0, y=0, center=[]):
|
def rect(self, x=0, y=0, center=[]):
|
||||||
if center == []:
|
if center == []:
|
||||||
return _r(x, y, self.size[0], self.size[1])
|
return _r(x, y, self.size[0], self.size[1])
|
||||||
|
@ -30,7 +37,7 @@ class surface:
|
||||||
surf._surface_size = self._size
|
surf._surface_size = self._size
|
||||||
return surf
|
return surf
|
||||||
def getPixel(self, x, y):
|
def getPixel(self, x, y):
|
||||||
return self._orig.get_at((x,y))
|
return _clr(*self._orig.get_at((x,y)))
|
||||||
def setPixel(self, x, y, color):
|
def setPixel(self, x, y, color):
|
||||||
self._orig.set_at((x,y),color)
|
self._orig.set_at((x,y),color)
|
||||||
return self.copy()
|
return self.copy()
|
||||||
|
@ -47,10 +54,10 @@ class surface:
|
||||||
self._orig.blit(surf, xy)
|
self._orig.blit(surf, xy)
|
||||||
return self.copy()
|
return self.copy()
|
||||||
def fill(self, color):
|
def fill(self, color):
|
||||||
self._orig.fill(color)
|
self._orig.fill(list(color))
|
||||||
return self.copy()
|
return self.copy()
|
||||||
def crop(self, rect):
|
def crop(self, rect):
|
||||||
self._orig = self._orig.subsurface((rect.x,rect.y,rect.w,rect.h))
|
self._orig = self._orig.subsurface(rect)
|
||||||
self._size = self._orig.get_size()
|
self._size = self._orig.get_size()
|
||||||
return self.copy()
|
return self.copy()
|
||||||
def scale(self, size, smooth=False):
|
def scale(self, size, smooth=False):
|
||||||
|
@ -75,6 +82,7 @@ class surface:
|
||||||
self._orig = _pg.transform.smoothscale(self._orig,scale)
|
self._orig = _pg.transform.smoothscale(self._orig,scale)
|
||||||
self._orig = _pg.transform.smoothscale(self._orig,size)
|
self._orig = _pg.transform.smoothscale(self._orig,size)
|
||||||
return self.copy()
|
return self.copy()
|
||||||
|
|
||||||
class _draw:
|
class _draw:
|
||||||
def __init__(self,surface):
|
def __init__(self,surface):
|
||||||
self._surf = surface
|
self._surf = surface
|
||||||
|
@ -88,10 +96,9 @@ class surface:
|
||||||
orig = self._surf._surface_orig
|
orig = self._surf._surface_orig
|
||||||
except:
|
except:
|
||||||
orig = self._surf._orig
|
orig = self._surf._orig
|
||||||
_pg.draw.rect(orig,color,_pg.Rect(rect.x,rect.y,rect.w,rect.h),
|
_pg.draw.rect(orig,color,_pg.Rect(rect[0],rect[1],rect[2],rect[3]),
|
||||||
width,borderRadius,borderTopLeftRadius,
|
width,borderRadius,borderTopLeftRadius,borderTopRightRadius,
|
||||||
borderTopRightRadius,borderBottomLeftRadius,
|
borderBottomLeftRadius,borderBottomRightRadius)
|
||||||
borderBottomRightRadius)
|
|
||||||
return self._surf.copy()
|
return self._surf.copy()
|
||||||
def polygon(self, color, points, width=0):
|
def polygon(self, color, points, width=0):
|
||||||
try:
|
try:
|
||||||
|
@ -119,7 +126,8 @@ class surface:
|
||||||
orig = self._surf._surface_orig
|
orig = self._surf._surface_orig
|
||||||
except:
|
except:
|
||||||
orig = self._surf._orig
|
orig = self._surf._orig
|
||||||
_pg.draw.ellipse(orig,color,_pg.Rect(rect.x,rect.y,rect.w,rect.h),width)
|
_pg.draw.ellipse(orig,color,_pg.Rect(rect[0],
|
||||||
|
rect[1],rect[2],rect[3]),width)
|
||||||
return self._surf.copy()
|
return self._surf.copy()
|
||||||
def line(self,color,start,end,width=1):
|
def line(self,color,start,end,width=1):
|
||||||
try:
|
try:
|
||||||
|
@ -133,8 +141,8 @@ class surface:
|
||||||
orig = self._surf._surface_orig
|
orig = self._surf._surface_orig
|
||||||
except:
|
except:
|
||||||
orig = self._surf._orig
|
orig = self._surf._orig
|
||||||
_pg.draw.arc(orig,color,
|
_pg.draw.arc(orig,color,_pg.Rect(rect[0],
|
||||||
_pg.Rect(rect.x,rect.y,rect.w,rect.h),
|
rect[1],rect[2],rect[3]),
|
||||||
startAngle,stopAngle,width)
|
startAngle,stopAngle,width)
|
||||||
return self._surf.copy()
|
return self._surf.copy()
|
||||||
@property
|
@property
|
||||||
|
|
|
@ -703,7 +703,7 @@ class base:
|
||||||
self._widgets[self._page].remove(i)
|
self._widgets[self._page].remove(i)
|
||||||
def put(self, widget, pos, page=0):
|
def put(self, widget, pos, page=0):
|
||||||
if page not in self._widgets:
|
if page not in self._widgets:
|
||||||
self._widgets.update({page:[]})
|
self.blankPage(page)
|
||||||
self._widgets[page].append([widget, pos])
|
self._widgets[page].append([widget, pos])
|
||||||
def selectPage(self, page):
|
def selectPage(self, page):
|
||||||
self._page = page
|
self._page = page
|
||||||
|
@ -713,3 +713,5 @@ class base:
|
||||||
return self._widgets[page]
|
return self._widgets[page]
|
||||||
def setWidgetPos(self,index,pos,page=0):
|
def setWidgetPos(self,index,pos,page=0):
|
||||||
self._widgets[page][index] = [self._widgets[page][index][0], pos]
|
self._widgets[page][index] = [self._widgets[page][index][0], pos]
|
||||||
|
def blankPage(self,page):
|
||||||
|
self._widgets.update({page:[]})
|
||||||
|
|
3
tests/main.py
Normal file
3
tests/main.py
Normal file
|
@ -0,0 +1,3 @@
|
||||||
|
import pygwin
|
||||||
|
|
||||||
|
pygwin.keyboard.isprs
|
Loading…
Add table
Add a link
Reference in a new issue