Add files via upload

This commit is contained in:
themixray 2021-12-19 17:05:10 +03:00 committed by GitHub
parent 741ea4081f
commit c62119243e
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
60 changed files with 422 additions and 130 deletions

View file

@ -1,6 +1,7 @@
from pygwin.surface import surface
import pygwin.keyboard as keyboard
from pygwin.console import console
from pygwin.color import color
import pygwin.gamepad as _gp
import pygwin.mouse as mouse
from pygwin.rect import rect

View file

@ -10,9 +10,12 @@ import win32con as _w32c
import win32gui as _w32g
import requests as _req
import tempfile as _tf
import threading as _t
import pickle as _p
import mouse as _m
import time as _ti
class win(_surface):
class _win(_surface):
def __init__(self, iconpath=None):
self._orig = _pg.display.get_surface()
super().__init__(self._orig.get_size())
@ -20,6 +23,8 @@ class win(_surface):
self._clock = _pg.time.Clock()
self._withfps = False
self._iconpath = iconpath
self._isallowdrag = False
# self._issmartdrag = False
if iconpath != None:
self.tray = _tray(self.title,iconpath)
def update(self, fps=-1):
@ -27,6 +32,11 @@ class win(_surface):
self._clock.tick(fps)
self._withfps = True
_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 fget(self):
return _pg.display.get_caption()[0]
@ -55,27 +65,67 @@ class win(_surface):
def fullscreen(self):
_pg.display.toogle_fullscreen()
def close(self):
# _w32g.PostMessage(self.hwnd, _w32c.WM_CLOSE, 0, 0)
_pg.display.quit()
_w32g.PostMessage(self.hwnd, _w32c.WM_CLOSE, 0, 0)
self.tray.stop()
try:self.tray.stop()
except:pass
def focus(self):
self.hide()
self.show()
_w32g.BringWindowToTop(self.hwnd)
_w32g.ShowWindow(self.hwnd, _w32c.SW_SHOWNORMAL)
_w32g.SetForegroundWindow(self.hwnd)
def unfocus(self):
pass
def hide(self):
_w32g.ShowWindow(self.hwnd, _w32c.SW_HIDE)
def show(self):
_w32g.ShowWindow(self.hwnd, _w32c.SW_SHOW)
def move(self, x, y):
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):
_s(self._orig, 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
def position(self):
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)
if icon != None:
_pg.display.set_icon(_pg.image.load(icon))
return win(icon)
return _win(icon)
def ramLimit(memory_limit):
hjob = _w32j.CreateJobObject(None,job_name)

27
build/lib/pygwin/color.py Normal file
View 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__())})'

View file

@ -1,6 +1,7 @@
import win32console as w32con
import win32con as w32c
import win32gui as w32g
import win32api as w32a
import pyautogui as pag
class console:
@ -40,6 +41,9 @@ class console:
pass
return locals()
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
def visible(self):
return w32g.IsWindowVisible(self.hwnd)

View file

@ -1,19 +1,26 @@
from pygwin._pg import pg as _pg
from pygwin.surface import surface as _surface
from PIL import Image as _im
import tempfile as _tf
import randstr as _rs
import pickle as _p
import bz2 as _bz2
import os as _os
def load(path):
if path.endswith('.gif'):
im = _im.open(path)
with _tf.TemporaryDirectory() as td:
surfs = []
for i in range(im.n_frames):
im.seek(i)
image = _pg.image.fromstring(im.tobytes(),im.size,im.mode)
surf = _surface(image.get_size())
surf._surface_orig = image
surfs.append(surf)
p = _os.path.join(td,f'{i}.png')
im.save(p)
s = _pg.image.load(p)
_os.remove(p)
sg = _surface(s.get_size())
sg.blit(s,(0,0))
surfs.append(sg)
return surfs
else:
im = _im.open(path.encode('utf8').decode('utf8'))
@ -23,18 +30,10 @@ def load(path):
return surf
def save(surface, dest):
if type(surface) == _surface:
orig = surface._surface_orig
else:
orig = surface._orig
_pg.image.save_extended(orig, dest)
_pg.image.save_extended(surface._grp(), dest)
def toBytes(surface):
try:
orig = surface._surface_orig
except:
orig = surface._orig
return _bz2.compress(_p.dumps([_pg.image.tostring(orig,"RGBA"),list(surface.size)]))
return _bz2.compress(_p.dumps([_pg.image.tostring(surface._grp(),"RGBA"),list(surface.size)]))
def fromBytes(bytes):
string = _p.loads(_bz2.decompress(bytes))

View file

@ -8,3 +8,15 @@ def getPressed():
return fkeys
def isPressed(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})")

View file

@ -4,7 +4,7 @@ def getPressed():
orig = _pg.mouse.get_pressed(3)
return {'left':orig[0],'middle':orig[1],'right':orig[2]}
def isPressed(x):
return getPressed()[x]
return getPressed()[x.lower()]
def setPosition(x):
_pg.mouse.set_pos(x)
def getPosition():
@ -20,3 +20,17 @@ def setCursor(size, hotspot=None, xormasks=None, andmasks=None):
_pg.mouse.set_system_cursor(size)
else:
_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})")

View file

@ -1,34 +1,60 @@
from pygwin._pg import pg
_aliases = {'w':['width'],'h':['height'],
'c':['center','middle'],
'x':['left'],'y':['up'],
'r':['right'],'d':['down']}
class rect:
def __init__(self,x,y,w,h):
self.x = x
self.y = y
self.w = w
self.h = h
self._rect = pg.Rect(x,y,w,h)
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())
self._reload()
def collide(self, x):
try:
return self._rect.colliderect(x._rect_rect)
except:
return self._rect.colliderect(x._rect)
try:return self._rect.colliderect(x._rect_rect)
except:return self._rect.colliderect(x._rect)
def contains(self, 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)

View file

@ -1,5 +1,11 @@
from pygwin.rect import rect as _r
from pygwin.color import color as _clr
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:
def __init__(self, size):
@ -8,15 +14,16 @@ class surface:
@property
def pixels(self):
pixels = []
pxls = _pg.PixelArray(self._orig)
for x in range(self.size[0]):
pixels.append([])
for y in range(self.size[1]):
pixels[x].append(pxls[x, y])
pixels[x].append(self.getPixel(x,y))
return pixels
@property
def size(self):
return self._size
def _grp(self):
return self._orig
def rect(self, x=0, y=0, center=[]):
if center == []:
return _r(x, y, self.size[0], self.size[1])
@ -30,7 +37,7 @@ class surface:
surf._surface_size = self._size
return surf
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):
self._orig.set_at((x,y),color)
return self.copy()
@ -47,10 +54,10 @@ class surface:
self._orig.blit(surf, xy)
return self.copy()
def fill(self, color):
self._orig.fill(color)
self._orig.fill(list(color))
return self.copy()
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()
return self.copy()
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,size)
return self.copy()
class _draw:
def __init__(self,surface):
self._surf = surface
@ -88,10 +96,9 @@ class surface:
orig = self._surf._surface_orig
except:
orig = self._surf._orig
_pg.draw.rect(orig,color,_pg.Rect(rect.x,rect.y,rect.w,rect.h),
width,borderRadius,borderTopLeftRadius,
borderTopRightRadius,borderBottomLeftRadius,
borderBottomRightRadius)
_pg.draw.rect(orig,color,_pg.Rect(rect[0],rect[1],rect[2],rect[3]),
width,borderRadius,borderTopLeftRadius,borderTopRightRadius,
borderBottomLeftRadius,borderBottomRightRadius)
return self._surf.copy()
def polygon(self, color, points, width=0):
try:
@ -119,7 +126,8 @@ class surface:
orig = self._surf._surface_orig
except:
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()
def line(self,color,start,end,width=1):
try:
@ -133,8 +141,8 @@ class surface:
orig = self._surf._surface_orig
except:
orig = self._surf._orig
_pg.draw.arc(orig,color,
_pg.Rect(rect.x,rect.y,rect.w,rect.h),
_pg.draw.arc(orig,color,_pg.Rect(rect[0],
rect[1],rect[2],rect[3]),
startAngle,stopAngle,width)
return self._surf.copy()
@property

View file

@ -703,7 +703,7 @@ class base:
self._widgets[self._page].remove(i)
def put(self, widget, pos, page=0):
if page not in self._widgets:
self._widgets.update({page:[]})
self.blankPage(page)
self._widgets[page].append([widget, pos])
def selectPage(self, page):
self._page = page
@ -713,3 +713,5 @@ class base:
return self._widgets[page]
def setWidgetPos(self,index,pos,page=0):
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

Binary file not shown.

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

Binary file not shown.

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

Binary file not shown.

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

Binary file not shown.

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

Binary file not shown.

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

Binary file not shown.

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

Binary file not shown.

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

Binary file not shown.

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

Binary file not shown.

BIN
dist/pgw-0.1.0.tar.gz vendored Normal file

Binary file not shown.

View file

@ -8,6 +8,7 @@ requires = [
"inputs",
"pillow",
"wxPython",
"randstr",
"setuptools >=42"
]
build-backend = "setuptools.build_meta"

View file

@ -1,2 +1,4 @@
@echo off
pip uninstall pgw -y
python setup.py install
pipwin install pyaudio

View file

@ -1,6 +1,6 @@
[metadata]
name = pgw
version = 0.0.4
version = 0.1.0
author = themixray
author_email = simindeymo@gmail.com
description = Python Grapchical Window.

View file

@ -1,8 +1,6 @@
from setuptools import setup
setup(name='pgw',packages=['pygwin'],version='0.0.4',author='themixray',
description='A library for creating Python applications.',
license='MIT',install_requires=
['cython','pywin32','pygame','inputs',
'pydub','wxPython','pyautogui','moviepy',
'pipwin','wave','opencv-python'])
setup(name='pgw',packages=['pygwin'],version='0.1.0',
author='themixray',description='A library for creating Python applications.',
license='MIT',install_requires=['cython','pywin32','pygame','inputs','randstr',
'pydub','wxPython','pyautogui','moviepy','pipwin','wave','opencv-python'])

View file

@ -1,6 +1,6 @@
Metadata-Version: 2.1
Name: pgw
Version: 0.0.4
Version: 0.1.0
Summary: A library for creating Python applications.
Home-page: https://github.com/themixray/pygwin
Author: themixray

View file

@ -11,6 +11,7 @@ src/pgw.egg-info/top_level.txt
src/pygwin/__init__.py
src/pygwin/_pg.py
src/pygwin/_win.py
src/pygwin/color.py
src/pygwin/console.py
src/pygwin/font.py
src/pygwin/gamepad.py

View file

@ -2,6 +2,7 @@ cython
pywin32
pygame
inputs
randstr
pydub
wxPython
pyautogui

View file

@ -1,6 +1,7 @@
from pygwin.surface import surface
import pygwin.keyboard as keyboard
from pygwin.console import console
from pygwin.color import color
import pygwin.gamepad as _gp
import pygwin.mouse as mouse
from pygwin.rect import rect

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

View file

@ -10,9 +10,12 @@ import win32con as _w32c
import win32gui as _w32g
import requests as _req
import tempfile as _tf
import threading as _t
import pickle as _p
import mouse as _m
import time as _ti
class win(_surface):
class _win(_surface):
def __init__(self, iconpath=None):
self._orig = _pg.display.get_surface()
super().__init__(self._orig.get_size())
@ -20,6 +23,8 @@ class win(_surface):
self._clock = _pg.time.Clock()
self._withfps = False
self._iconpath = iconpath
self._isallowdrag = False
# self._issmartdrag = False
if iconpath != None:
self.tray = _tray(self.title,iconpath)
def update(self, fps=-1):
@ -27,6 +32,11 @@ class win(_surface):
self._clock.tick(fps)
self._withfps = True
_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 fget(self):
return _pg.display.get_caption()[0]
@ -55,27 +65,67 @@ class win(_surface):
def fullscreen(self):
_pg.display.toogle_fullscreen()
def close(self):
# _w32g.PostMessage(self.hwnd, _w32c.WM_CLOSE, 0, 0)
_pg.display.quit()
_w32g.PostMessage(self.hwnd, _w32c.WM_CLOSE, 0, 0)
self.tray.stop()
try:self.tray.stop()
except:pass
def focus(self):
self.hide()
self.show()
_w32g.BringWindowToTop(self.hwnd)
_w32g.ShowWindow(self.hwnd, _w32c.SW_SHOWNORMAL)
_w32g.SetForegroundWindow(self.hwnd)
def unfocus(self):
pass
def hide(self):
_w32g.ShowWindow(self.hwnd, _w32c.SW_HIDE)
def show(self):
_w32g.ShowWindow(self.hwnd, _w32c.SW_SHOW)
def move(self, x, y):
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):
_s(self._orig, 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
def position(self):
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)
if icon != None:
_pg.display.set_icon(_pg.image.load(icon))
return win(icon)
return _win(icon)
def ramLimit(memory_limit):
hjob = _w32j.CreateJobObject(None,job_name)

27
src/pygwin/color.py Normal file
View 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__())})'

View file

@ -1,6 +1,7 @@
import win32console as w32con
import win32con as w32c
import win32gui as w32g
import win32api as w32a
import pyautogui as pag
class console:
@ -40,6 +41,9 @@ class console:
pass
return locals()
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
def visible(self):
return w32g.IsWindowVisible(self.hwnd)

View file

@ -1,19 +1,26 @@
from pygwin._pg import pg as _pg
from pygwin.surface import surface as _surface
from PIL import Image as _im
import tempfile as _tf
import randstr as _rs
import pickle as _p
import bz2 as _bz2
import os as _os
def load(path):
if path.endswith('.gif'):
im = _im.open(path)
with _tf.TemporaryDirectory() as td:
surfs = []
for i in range(im.n_frames):
im.seek(i)
image = _pg.image.fromstring(im.tobytes(),im.size,im.mode)
surf = _surface(image.get_size())
surf._surface_orig = image
surfs.append(surf)
p = _os.path.join(td,f'{i}.png')
im.save(p)
s = _pg.image.load(p)
_os.remove(p)
sg = _surface(s.get_size())
sg.blit(s,(0,0))
surfs.append(sg)
return surfs
else:
im = _im.open(path.encode('utf8').decode('utf8'))
@ -23,18 +30,10 @@ def load(path):
return surf
def save(surface, dest):
if type(surface) == _surface:
orig = surface._surface_orig
else:
orig = surface._orig
_pg.image.save_extended(orig, dest)
_pg.image.save_extended(surface._grp(), dest)
def toBytes(surface):
try:
orig = surface._surface_orig
except:
orig = surface._orig
return _bz2.compress(_p.dumps([_pg.image.tostring(orig,"RGBA"),list(surface.size)]))
return _bz2.compress(_p.dumps([_pg.image.tostring(surface._grp(),"RGBA"),list(surface.size)]))
def fromBytes(bytes):
string = _p.loads(_bz2.decompress(bytes))

View file

@ -8,3 +8,15 @@ def getPressed():
return fkeys
def isPressed(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})")

View file

@ -4,7 +4,7 @@ def getPressed():
orig = _pg.mouse.get_pressed(3)
return {'left':orig[0],'middle':orig[1],'right':orig[2]}
def isPressed(x):
return getPressed()[x]
return getPressed()[x.lower()]
def setPosition(x):
_pg.mouse.set_pos(x)
def getPosition():
@ -20,3 +20,17 @@ def setCursor(size, hotspot=None, xormasks=None, andmasks=None):
_pg.mouse.set_system_cursor(size)
else:
_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})")

View file

@ -1,34 +1,60 @@
from pygwin._pg import pg
_aliases = {'w':['width'],'h':['height'],
'c':['center','middle'],
'x':['left'],'y':['up'],
'r':['right'],'d':['down']}
class rect:
def __init__(self,x,y,w,h):
self.x = x
self.y = y
self.w = w
self.h = h
self._rect = pg.Rect(x,y,w,h)
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())
self._reload()
def collide(self, x):
try:
return self._rect.colliderect(x._rect_rect)
except:
return self._rect.colliderect(x._rect)
try:return self._rect.colliderect(x._rect_rect)
except:return self._rect.colliderect(x._rect)
def contains(self, 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)

View file

@ -1,5 +1,11 @@
from pygwin.rect import rect as _r
from pygwin.color import color as _clr
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:
def __init__(self, size):
@ -8,15 +14,16 @@ class surface:
@property
def pixels(self):
pixels = []
pxls = _pg.PixelArray(self._orig)
for x in range(self.size[0]):
pixels.append([])
for y in range(self.size[1]):
pixels[x].append(pxls[x, y])
pixels[x].append(self.getPixel(x,y))
return pixels
@property
def size(self):
return self._size
def _grp(self):
return self._orig
def rect(self, x=0, y=0, center=[]):
if center == []:
return _r(x, y, self.size[0], self.size[1])
@ -30,7 +37,7 @@ class surface:
surf._surface_size = self._size
return surf
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):
self._orig.set_at((x,y),color)
return self.copy()
@ -47,10 +54,10 @@ class surface:
self._orig.blit(surf, xy)
return self.copy()
def fill(self, color):
self._orig.fill(color)
self._orig.fill(list(color))
return self.copy()
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()
return self.copy()
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,size)
return self.copy()
class _draw:
def __init__(self,surface):
self._surf = surface
@ -88,10 +96,9 @@ class surface:
orig = self._surf._surface_orig
except:
orig = self._surf._orig
_pg.draw.rect(orig,color,_pg.Rect(rect.x,rect.y,rect.w,rect.h),
width,borderRadius,borderTopLeftRadius,
borderTopRightRadius,borderBottomLeftRadius,
borderBottomRightRadius)
_pg.draw.rect(orig,color,_pg.Rect(rect[0],rect[1],rect[2],rect[3]),
width,borderRadius,borderTopLeftRadius,borderTopRightRadius,
borderBottomLeftRadius,borderBottomRightRadius)
return self._surf.copy()
def polygon(self, color, points, width=0):
try:
@ -119,7 +126,8 @@ class surface:
orig = self._surf._surface_orig
except:
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()
def line(self,color,start,end,width=1):
try:
@ -133,8 +141,8 @@ class surface:
orig = self._surf._surface_orig
except:
orig = self._surf._orig
_pg.draw.arc(orig,color,
_pg.Rect(rect.x,rect.y,rect.w,rect.h),
_pg.draw.arc(orig,color,_pg.Rect(rect[0],
rect[1],rect[2],rect[3]),
startAngle,stopAngle,width)
return self._surf.copy()
@property

View file

@ -703,7 +703,7 @@ class base:
self._widgets[self._page].remove(i)
def put(self, widget, pos, page=0):
if page not in self._widgets:
self._widgets.update({page:[]})
self.blankPage(page)
self._widgets[page].append([widget, pos])
def selectPage(self, page):
self._page = page
@ -713,3 +713,5 @@ class base:
return self._widgets[page]
def setWidgetPos(self,index,pos,page=0):
self._widgets[page][index] = [self._widgets[page][index][0], pos]
def blankPage(self,page):
self._widgets.update({page:[]})

3
tests/main.py Normal file
View file

@ -0,0 +1,3 @@
import pygwin
pygwin.keyboard.isprs