diff --git a/build/lib/pygwin/__init__.py b/build/lib/pygwin/__init__.py index 2d0e236..0e013ae 100644 --- a/build/lib/pygwin/__init__.py +++ b/build/lib/pygwin/__init__.py @@ -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 diff --git a/build/lib/pygwin/_win.py b/build/lib/pygwin/_win.py index 1faba29..7f8caf5 100644 --- a/build/lib/pygwin/_win.py +++ b/build/lib/pygwin/_win.py @@ -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) diff --git a/build/lib/pygwin/color.py b/build/lib/pygwin/color.py new file mode 100644 index 0000000..db99f34 --- /dev/null +++ b/build/lib/pygwin/color.py @@ -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__())})' diff --git a/build/lib/pygwin/console.py b/build/lib/pygwin/console.py index c6dcc2c..1495e70 100644 --- a/build/lib/pygwin/console.py +++ b/build/lib/pygwin/console.py @@ -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) diff --git a/build/lib/pygwin/image.py b/build/lib/pygwin/image.py index b61d345..bebce07 100644 --- a/build/lib/pygwin/image.py +++ b/build/lib/pygwin/image.py @@ -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) - 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) + with _tf.TemporaryDirectory() as td: + surfs = [] + for i in range(im.n_frames): + im.seek(i) + 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)) diff --git a/build/lib/pygwin/keyboard.py b/build/lib/pygwin/keyboard.py index 9d55d95..b0fb356 100644 --- a/build/lib/pygwin/keyboard.py +++ b/build/lib/pygwin/keyboard.py @@ -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})") diff --git a/build/lib/pygwin/mouse.py b/build/lib/pygwin/mouse.py index 48da5fd..6c1772d 100644 --- a/build/lib/pygwin/mouse.py +++ b/build/lib/pygwin/mouse.py @@ -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})") diff --git a/build/lib/pygwin/rect.py b/build/lib/pygwin/rect.py index 3e125fa..1792bfc 100644 --- a/build/lib/pygwin/rect.py +++ b/build/lib/pygwin/rect.py @@ -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) diff --git a/build/lib/pygwin/surface.py b/build/lib/pygwin/surface.py index dbe8fa4..804ced6 100644 --- a/build/lib/pygwin/surface.py +++ b/build/lib/pygwin/surface.py @@ -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 diff --git a/build/lib/pygwin/ui.py b/build/lib/pygwin/ui.py index e2d763f..43503fe 100644 --- a/build/lib/pygwin/ui.py +++ b/build/lib/pygwin/ui.py @@ -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:[]}) diff --git a/dist/pgw-0.0.4-py3-none-any.whl b/dist/pgw-0.0.4-py3-none-any.whl new file mode 100644 index 0000000..b2cb237 Binary files /dev/null and b/dist/pgw-0.0.4-py3-none-any.whl differ diff --git a/dist/pgw-0.0.4.tar.gz b/dist/pgw-0.0.4.tar.gz new file mode 100644 index 0000000..3fe3bc6 Binary files /dev/null and b/dist/pgw-0.0.4.tar.gz differ diff --git a/dist/pgw-0.0.5-py3-none-any.whl b/dist/pgw-0.0.5-py3-none-any.whl new file mode 100644 index 0000000..b1d524e Binary files /dev/null and b/dist/pgw-0.0.5-py3-none-any.whl differ diff --git a/dist/pgw-0.0.5-py3.7.egg b/dist/pgw-0.0.5-py3.7.egg new file mode 100644 index 0000000..591390a Binary files /dev/null and b/dist/pgw-0.0.5-py3.7.egg differ diff --git a/dist/pgw-0.0.5.tar.gz b/dist/pgw-0.0.5.tar.gz new file mode 100644 index 0000000..8217eef Binary files /dev/null and b/dist/pgw-0.0.5.tar.gz differ diff --git a/dist/pgw-0.0.6-py3-none-any.whl b/dist/pgw-0.0.6-py3-none-any.whl new file mode 100644 index 0000000..3fef320 Binary files /dev/null and b/dist/pgw-0.0.6-py3-none-any.whl differ diff --git a/dist/pgw-0.0.6-py3.7.egg b/dist/pgw-0.0.6-py3.7.egg new file mode 100644 index 0000000..4b19c59 Binary files /dev/null and b/dist/pgw-0.0.6-py3.7.egg differ diff --git a/dist/pgw-0.0.6.tar.gz b/dist/pgw-0.0.6.tar.gz new file mode 100644 index 0000000..c32c455 Binary files /dev/null and b/dist/pgw-0.0.6.tar.gz differ diff --git a/dist/pgw-0.0.7-py3-none-any.whl b/dist/pgw-0.0.7-py3-none-any.whl new file mode 100644 index 0000000..e6e6398 Binary files /dev/null and b/dist/pgw-0.0.7-py3-none-any.whl differ diff --git a/dist/pgw-0.0.7-py3.7.egg b/dist/pgw-0.0.7-py3.7.egg new file mode 100644 index 0000000..d10f606 Binary files /dev/null and b/dist/pgw-0.0.7-py3.7.egg differ diff --git a/dist/pgw-0.0.7.tar.gz b/dist/pgw-0.0.7.tar.gz new file mode 100644 index 0000000..9fa9c17 Binary files /dev/null and b/dist/pgw-0.0.7.tar.gz differ diff --git a/dist/pgw-0.0.8-py3-none-any.whl b/dist/pgw-0.0.8-py3-none-any.whl new file mode 100644 index 0000000..1c6d185 Binary files /dev/null and b/dist/pgw-0.0.8-py3-none-any.whl differ diff --git a/dist/pgw-0.0.8-py3.7.egg b/dist/pgw-0.0.8-py3.7.egg new file mode 100644 index 0000000..7b4f95c Binary files /dev/null and b/dist/pgw-0.0.8-py3.7.egg differ diff --git a/dist/pgw-0.0.8.tar.gz b/dist/pgw-0.0.8.tar.gz new file mode 100644 index 0000000..605ee60 Binary files /dev/null and b/dist/pgw-0.0.8.tar.gz differ diff --git a/dist/pgw-0.0.9-py3.7.egg b/dist/pgw-0.0.9-py3.7.egg new file mode 100644 index 0000000..d47916d Binary files /dev/null and b/dist/pgw-0.0.9-py3.7.egg differ diff --git a/dist/pgw-0.1.0-py3-none-any.whl b/dist/pgw-0.1.0-py3-none-any.whl new file mode 100644 index 0000000..e1cb555 Binary files /dev/null and b/dist/pgw-0.1.0-py3-none-any.whl differ diff --git a/dist/pgw-0.1.0-py3.7.egg b/dist/pgw-0.1.0-py3.7.egg new file mode 100644 index 0000000..c6681c2 Binary files /dev/null and b/dist/pgw-0.1.0-py3.7.egg differ diff --git a/dist/pgw-0.1.0.tar.gz b/dist/pgw-0.1.0.tar.gz new file mode 100644 index 0000000..ca0450e Binary files /dev/null and b/dist/pgw-0.1.0.tar.gz differ diff --git a/pyproject.toml b/pyproject.toml index ee28577..725617c 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -8,6 +8,7 @@ requires = [ "inputs", "pillow", "wxPython", + "randstr", "setuptools >=42" ] build-backend = "setuptools.build_meta" diff --git a/setup.bat b/setup.bat index d101598..1dfddbb 100644 --- a/setup.bat +++ b/setup.bat @@ -1,2 +1,4 @@ @echo off +pip uninstall pgw -y python setup.py install +pipwin install pyaudio diff --git a/setup.cfg b/setup.cfg index ad78919..8988111 100644 --- a/setup.cfg +++ b/setup.cfg @@ -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. diff --git a/setup.py b/setup.py index 57517ec..b8606f7 100644 --- a/setup.py +++ b/setup.py @@ -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']) diff --git a/src/pgw.egg-info/PKG-INFO b/src/pgw.egg-info/PKG-INFO index 84468b7..5fddfe9 100644 --- a/src/pgw.egg-info/PKG-INFO +++ b/src/pgw.egg-info/PKG-INFO @@ -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 diff --git a/src/pgw.egg-info/SOURCES.txt b/src/pgw.egg-info/SOURCES.txt index 86abac0..981ddec 100644 --- a/src/pgw.egg-info/SOURCES.txt +++ b/src/pgw.egg-info/SOURCES.txt @@ -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 diff --git a/src/pgw.egg-info/requires.txt b/src/pgw.egg-info/requires.txt index a13bd06..a486ac9 100644 --- a/src/pgw.egg-info/requires.txt +++ b/src/pgw.egg-info/requires.txt @@ -2,6 +2,7 @@ cython pywin32 pygame inputs +randstr pydub wxPython pyautogui diff --git a/src/pygwin/__init__.py b/src/pygwin/__init__.py index 2d0e236..0e013ae 100644 --- a/src/pygwin/__init__.py +++ b/src/pygwin/__init__.py @@ -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 diff --git a/src/pygwin/__pycache__/__init__.cpython-37.pyc b/src/pygwin/__pycache__/__init__.cpython-37.pyc new file mode 100644 index 0000000..e96bb2b Binary files /dev/null and b/src/pygwin/__pycache__/__init__.cpython-37.pyc differ diff --git a/src/pygwin/__pycache__/_pg.cpython-37.pyc b/src/pygwin/__pycache__/_pg.cpython-37.pyc new file mode 100644 index 0000000..915ad64 Binary files /dev/null and b/src/pygwin/__pycache__/_pg.cpython-37.pyc differ diff --git a/src/pygwin/__pycache__/_win.cpython-37.pyc b/src/pygwin/__pycache__/_win.cpython-37.pyc new file mode 100644 index 0000000..2224e8a Binary files /dev/null and b/src/pygwin/__pycache__/_win.cpython-37.pyc differ diff --git a/src/pygwin/__pycache__/console.cpython-37.pyc b/src/pygwin/__pycache__/console.cpython-37.pyc new file mode 100644 index 0000000..35333ae Binary files /dev/null and b/src/pygwin/__pycache__/console.cpython-37.pyc differ diff --git a/src/pygwin/__pycache__/font.cpython-37.pyc b/src/pygwin/__pycache__/font.cpython-37.pyc new file mode 100644 index 0000000..20564d1 Binary files /dev/null and b/src/pygwin/__pycache__/font.cpython-37.pyc differ diff --git a/src/pygwin/__pycache__/gamepad.cpython-37.pyc b/src/pygwin/__pycache__/gamepad.cpython-37.pyc new file mode 100644 index 0000000..9a7e697 Binary files /dev/null and b/src/pygwin/__pycache__/gamepad.cpython-37.pyc differ diff --git a/src/pygwin/__pycache__/image.cpython-37.pyc b/src/pygwin/__pycache__/image.cpython-37.pyc new file mode 100644 index 0000000..2f11e3d Binary files /dev/null and b/src/pygwin/__pycache__/image.cpython-37.pyc differ diff --git a/src/pygwin/__pycache__/keyboard.cpython-37.pyc b/src/pygwin/__pycache__/keyboard.cpython-37.pyc new file mode 100644 index 0000000..076b40c Binary files /dev/null and b/src/pygwin/__pycache__/keyboard.cpython-37.pyc differ diff --git a/src/pygwin/__pycache__/mixer.cpython-37.pyc b/src/pygwin/__pycache__/mixer.cpython-37.pyc new file mode 100644 index 0000000..d45d0db Binary files /dev/null and b/src/pygwin/__pycache__/mixer.cpython-37.pyc differ diff --git a/src/pygwin/__pycache__/mouse.cpython-37.pyc b/src/pygwin/__pycache__/mouse.cpython-37.pyc new file mode 100644 index 0000000..aa8175f Binary files /dev/null and b/src/pygwin/__pycache__/mouse.cpython-37.pyc differ diff --git a/src/pygwin/__pycache__/rect.cpython-37.pyc b/src/pygwin/__pycache__/rect.cpython-37.pyc new file mode 100644 index 0000000..b7491c9 Binary files /dev/null and b/src/pygwin/__pycache__/rect.cpython-37.pyc differ diff --git a/src/pygwin/__pycache__/surface.cpython-37.pyc b/src/pygwin/__pycache__/surface.cpython-37.pyc new file mode 100644 index 0000000..deb060c Binary files /dev/null and b/src/pygwin/__pycache__/surface.cpython-37.pyc differ diff --git a/src/pygwin/__pycache__/tray.cpython-37.pyc b/src/pygwin/__pycache__/tray.cpython-37.pyc new file mode 100644 index 0000000..89e3247 Binary files /dev/null and b/src/pygwin/__pycache__/tray.cpython-37.pyc differ diff --git a/src/pygwin/__pycache__/ui.cpython-37.pyc b/src/pygwin/__pycache__/ui.cpython-37.pyc new file mode 100644 index 0000000..3c3749b Binary files /dev/null and b/src/pygwin/__pycache__/ui.cpython-37.pyc differ diff --git a/src/pygwin/_win.py b/src/pygwin/_win.py index 1faba29..3fa9cda 100644 --- a/src/pygwin/_win.py +++ b/src/pygwin/_win.py @@ -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) diff --git a/src/pygwin/color.py b/src/pygwin/color.py new file mode 100644 index 0000000..db99f34 --- /dev/null +++ b/src/pygwin/color.py @@ -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__())})' diff --git a/src/pygwin/console.py b/src/pygwin/console.py index c6dcc2c..1495e70 100644 --- a/src/pygwin/console.py +++ b/src/pygwin/console.py @@ -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) diff --git a/src/pygwin/image.py b/src/pygwin/image.py index b61d345..bebce07 100644 --- a/src/pygwin/image.py +++ b/src/pygwin/image.py @@ -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) - 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) + with _tf.TemporaryDirectory() as td: + surfs = [] + for i in range(im.n_frames): + im.seek(i) + 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)) diff --git a/src/pygwin/keyboard.py b/src/pygwin/keyboard.py index 9d55d95..b0fb356 100644 --- a/src/pygwin/keyboard.py +++ b/src/pygwin/keyboard.py @@ -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})") diff --git a/src/pygwin/mouse.py b/src/pygwin/mouse.py index 48da5fd..6c1772d 100644 --- a/src/pygwin/mouse.py +++ b/src/pygwin/mouse.py @@ -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})") diff --git a/src/pygwin/rect.py b/src/pygwin/rect.py index 3e125fa..1792bfc 100644 --- a/src/pygwin/rect.py +++ b/src/pygwin/rect.py @@ -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) diff --git a/src/pygwin/surface.py b/src/pygwin/surface.py index dbe8fa4..804ced6 100644 --- a/src/pygwin/surface.py +++ b/src/pygwin/surface.py @@ -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 diff --git a/src/pygwin/ui.py b/src/pygwin/ui.py index e2d763f..43503fe 100644 --- a/src/pygwin/ui.py +++ b/src/pygwin/ui.py @@ -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:[]}) diff --git a/tests/main.py b/tests/main.py new file mode 100644 index 0000000..2009089 --- /dev/null +++ b/tests/main.py @@ -0,0 +1,3 @@ +import pygwin + +pygwin.keyboard.isprs