fixed ramlimit3
This commit is contained in:
parent
fe455d2938
commit
97b97310d0
5 changed files with 126 additions and 78 deletions
|
@ -4,10 +4,14 @@ from datetime import datetime as _dt
|
||||||
from pygwin.image import save as _s
|
from pygwin.image import save as _s
|
||||||
from pygwin._pg import pg as _pg
|
from pygwin._pg import pg as _pg
|
||||||
import pygwin.image as _img
|
import pygwin.image as _img
|
||||||
import win32job as _w32j
|
try:
|
||||||
import win32api as _w32a
|
import win32job as _w32j
|
||||||
import win32con as _w32c
|
import win32api as _w32a
|
||||||
import win32gui as _w32g
|
import win32con as _w32c
|
||||||
|
import win32gui as _w32g
|
||||||
|
nonwin32api = False
|
||||||
|
except:
|
||||||
|
nonwin32api = True
|
||||||
import requests as _req
|
import requests as _req
|
||||||
import tempfile as _tf
|
import tempfile as _tf
|
||||||
import threading as _t
|
import threading as _t
|
||||||
|
@ -70,37 +74,46 @@ class _win(_surface):
|
||||||
try:self.tray.stop()
|
try:self.tray.stop()
|
||||||
except:pass
|
except:pass
|
||||||
def focus(self):
|
def focus(self):
|
||||||
self.hide()
|
if not nonwin32api:
|
||||||
self.show()
|
self.hide()
|
||||||
_w32g.BringWindowToTop(self.hwnd)
|
self.show()
|
||||||
_w32g.ShowWindow(self.hwnd, _w32c.SW_SHOWNORMAL)
|
_w32g.BringWindowToTop(self.hwnd)
|
||||||
_w32g.SetForegroundWindow(self.hwnd)
|
_w32g.ShowWindow(self.hwnd, _w32c.SW_SHOWNORMAL)
|
||||||
|
_w32g.SetForegroundWindow(self.hwnd)
|
||||||
def hide(self):
|
def hide(self):
|
||||||
_w32g.ShowWindow(self.hwnd, _w32c.SW_HIDE)
|
if not nonwin32api:
|
||||||
|
_w32g.ShowWindow(self.hwnd, _w32c.SW_HIDE)
|
||||||
def show(self):
|
def show(self):
|
||||||
_w32g.ShowWindow(self.hwnd, _w32c.SW_SHOW)
|
if not nonwin32api:
|
||||||
|
_w32g.ShowWindow(self.hwnd, _w32c.SW_SHOW)
|
||||||
def move(self, x, y):
|
def move(self, x, y):
|
||||||
rect = _w32g.GetWindowRect(self.hwnd)
|
if not nonwin32api:
|
||||||
_w32g.MoveWindow(self.hwnd, int(x), int(y),
|
rect = self._getRect()
|
||||||
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,
|
def center(self,x=_pg.display.get_desktop_sizes()[0][0]/2,
|
||||||
y=_w32a.GetSystemMetrics(1)/2):
|
y=_pg.display.get_desktop_sizes()[0][1]/2):
|
||||||
self.move(x-self.size[0]/2,y-self.size[1]/2)
|
self.move(x-self.size[0]/2,y-self.size[1]/2)
|
||||||
|
def _getRect(self):
|
||||||
|
if not nonwin32api:
|
||||||
|
return _w32g.GetWindowRect(self.hwnd)
|
||||||
def denyDrag(self):
|
def denyDrag(self):
|
||||||
self._isallowdrag = True
|
if not nonwin32api:
|
||||||
def loop(self):
|
self._isallowdrag = True
|
||||||
while self._isallowdrag:
|
def loop(self):
|
||||||
pos = _m.get_position()
|
while self._isallowdrag:
|
||||||
pos = [pos[i]-self.position[i] for i in range(2)]
|
pos = _m.get_position()
|
||||||
if pos[0] < _w32g.GetWindowRect(self.hwnd)[2]-137:
|
pos = [pos[i]-self.position[i] for i in range(2)]
|
||||||
if pos[1] < 30:
|
if pos[0] < self._getRect()[2]-137:
|
||||||
_m.release('left')
|
if pos[1] < 30:
|
||||||
_t.Thread(target=lambda:loop(self),daemon=1).start()
|
_m.release('left')
|
||||||
|
_t.Thread(target=lambda:loop(self),daemon=1).start()
|
||||||
def allowDrag(self):
|
def allowDrag(self):
|
||||||
self._isallowdrag = False
|
if not nonwin32api:
|
||||||
|
self._isallowdrag = False
|
||||||
# def smartDrag(self, x):
|
# def smartDrag(self, x):
|
||||||
# self.allowDrag()
|
# self.allowDrag()
|
||||||
# self._issmartdrag = x
|
# self._issmartdrag = x
|
||||||
|
@ -128,10 +141,11 @@ class _win(_surface):
|
||||||
# _t.Thread(target=lambda:loop(self),daemon=1).start()
|
# _t.Thread(target=lambda:loop(self),daemon=1).start()
|
||||||
@property
|
@property
|
||||||
def position(self):
|
def position(self):
|
||||||
rect = _w32g.GetWindowRect(self.hwnd)
|
if not nonwin32api:
|
||||||
x = rect[0]
|
rect = self._getRect()
|
||||||
y = rect[1]
|
x = rect[0]
|
||||||
return (x, y)
|
y = rect[1]
|
||||||
|
return (x, y)
|
||||||
@property
|
@property
|
||||||
def rawFps(self):
|
def rawFps(self):
|
||||||
if self._withfps:
|
if self._withfps:
|
||||||
|
@ -143,10 +157,12 @@ class _win(_surface):
|
||||||
return int(self.rawFps)
|
return int(self.rawFps)
|
||||||
@property
|
@property
|
||||||
def hwnd(self):
|
def hwnd(self):
|
||||||
return _pg.display.get_wm_info()['window']
|
if not nonwin32api:
|
||||||
|
return _pg.display.get_wm_info()['window']
|
||||||
@property
|
@property
|
||||||
def visible(self):
|
def visible(self):
|
||||||
return _w32g.IsWindowVisible(self._win)
|
if not nonwin32api:
|
||||||
|
return _w32g.IsWindowVisible(self._win)
|
||||||
|
|
||||||
def create(title=None, size=(0,0), icon=None, resizable=False, noframe=False):
|
def create(title=None, size=(0,0), icon=None, resizable=False, noframe=False):
|
||||||
screen = _pg.display.set_mode(size)
|
screen = _pg.display.set_mode(size)
|
||||||
|
@ -162,23 +178,26 @@ def create(title=None, size=(0,0), icon=None, resizable=False, noframe=False):
|
||||||
return _win(icon)
|
return _win(icon)
|
||||||
|
|
||||||
def ramLimit(memory_limit):
|
def ramLimit(memory_limit):
|
||||||
hjob = _w32j.CreateJobObject(None,job_name)
|
if not nonwin32api:
|
||||||
if breakaway:
|
job_name = ''
|
||||||
info = _w32j.QueryInformationJobObject(hjob,_w32j.JobObjectExtendedLimitInformation)
|
breakaway = 'silent'
|
||||||
if breakaway=='silent':info['BasicLimitInformation']['LimitFlags']|=(_w32j.JOB_OBJECT_LIMIT_SILENT_BREAKAWAY_OK)
|
hjob = _w32j.CreateJobObject(None,job_name)
|
||||||
else:info['BasicLimitInformation']['LimitFlags']|=(_w32j.JOB_OBJECT_LIMIT_BREAKAWAY_OK)
|
if breakaway:
|
||||||
_w32j.SetInformationJobObject(hjob,_w32j.JobObjectExtendedLimitInformation,info)
|
info = _w32j.QueryInformationJobObject(hjob,_w32j.JobObjectExtendedLimitInformation)
|
||||||
hprocess = _w32a.GetCurrentProcess()
|
if breakaway=='silent':info['BasicLimitInformation']['LimitFlags']|=(_w32j.JOB_OBJECT_LIMIT_SILENT_BREAKAWAY_OK)
|
||||||
try:_w32j.AssignProcessToJobObject(hjob, hprocess);g_hjob=hjob
|
else:info['BasicLimitInformation']['LimitFlags']|=(_w32j.JOB_OBJECT_LIMIT_BREAKAWAY_OK)
|
||||||
except _w32j.error as e:
|
_w32j.SetInformationJobObject(hjob,_w32j.JobObjectExtendedLimitInformation,info)
|
||||||
if e.winerror!=winerror.ERROR_ACCESS_DENIED:raise
|
hprocess = _w32a.GetCurrentProcess()
|
||||||
elif sys.getwindowsversion()>=(6,2):raise
|
try:_w32j.AssignProcessToJobObject(hjob, hprocess);g_hjob=hjob
|
||||||
elif _w32j.IsProcessInJob(hprocess,None):raise
|
except _w32j.error as e:
|
||||||
warnings.warn('The process is already in a job. Nested jobs are not supported prior to Windows 8.')
|
if e.winerror!=winerror.ERROR_ACCESS_DENIED:raise
|
||||||
info=_w32j.QueryInformationJobObject(g_hjob,_w32j.JobObjectExtendedLimitInformation)
|
elif sys.getwindowsversion()>=(6,2):raise
|
||||||
info['ProcessMemoryLimit']=memory_limit
|
elif _w32j.IsProcessInJob(hprocess,None):raise
|
||||||
info['BasicLimitInformation']['LimitFlags']|=(_w32j.JOB_OBJECT_LIMIT_PROCESS_MEMORY)
|
warnings.warn('The process is already in a job. Nested jobs are not supported prior to Windows 8.')
|
||||||
_w32j.SetInformationJobObject(g_hjob,_w32j.JobObjectExtendedLimitInformation,info)
|
info=_w32j.QueryInformationJobObject(g_hjob,_w32j.JobObjectExtendedLimitInformation)
|
||||||
|
info['ProcessMemoryLimit']=memory_limit
|
||||||
|
info['BasicLimitInformation']['LimitFlags']|=(_w32j.JOB_OBJECT_LIMIT_PROCESS_MEMORY)
|
||||||
|
_w32j.SetInformationJobObject(g_hjob,_w32j.JobObjectExtendedLimitInformation,info)
|
||||||
|
|
||||||
def close():
|
def close():
|
||||||
_pg.quit()
|
_pg.quit()
|
||||||
|
|
|
@ -646,15 +646,20 @@ class checkBox(widget):
|
||||||
def draw(self, win, pos):
|
def draw(self, win, pos):
|
||||||
self._generate(pos)
|
self._generate(pos)
|
||||||
win.blit(self.surface,pos)
|
win.blit(self.surface,pos)
|
||||||
# class colorPicker(widget):
|
class comboBox(widget):
|
||||||
# def __init__(self):
|
def __init__(self,text,values=[],
|
||||||
# self._generate()
|
fontSize=30,font=_df,width=None,height=None,
|
||||||
# def _generate(self, position=None):
|
bg=(70,70,70),fg=(180,180,200),afg=(50,50,50),
|
||||||
# self.surface = _s((255,self.width))
|
abg=(200,200,200),borderColor=(50,50,50),borderWidth=5):
|
||||||
#
|
super()._args(locals())
|
||||||
# def draw(self, win, pos):
|
self._generate()
|
||||||
# self._generate(pos)
|
|
||||||
# win.blit(self.surface,pos)
|
def _generate(self, position=None):
|
||||||
|
self.surface = _s((255,self.width))
|
||||||
|
|
||||||
|
def draw(self, win, pos):
|
||||||
|
self._generate(pos)
|
||||||
|
win.blit(self.surface,pos)
|
||||||
class tip(widget):
|
class tip(widget):
|
||||||
def __init__(self,text,responceWidth,responceHeight,fontSize=15,font=_df,
|
def __init__(self,text,responceWidth,responceHeight,fontSize=15,font=_df,
|
||||||
borderColor=(180,180,50),borderWidth=2,bg=(255,255,128),
|
borderColor=(180,180,50),borderWidth=2,bg=(255,255,128),
|
||||||
|
|
BIN
dist/pgw-0.1.2-py3.7.egg
vendored
Normal file
BIN
dist/pgw-0.1.2-py3.7.egg
vendored
Normal file
Binary file not shown.
|
@ -1,6 +1,6 @@
|
||||||
Metadata-Version: 2.1
|
Metadata-Version: 2.1
|
||||||
Name: pgw
|
Name: pgw
|
||||||
Version: 0.1.0
|
Version: 0.1.2
|
||||||
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
|
||||||
|
|
|
@ -12,6 +12,9 @@ try:
|
||||||
nonwin32api = False
|
nonwin32api = False
|
||||||
except:
|
except:
|
||||||
nonwin32api = True
|
nonwin32api = True
|
||||||
|
import sys as _sys
|
||||||
|
import warnings as _warn
|
||||||
|
import winwerror as _we
|
||||||
import requests as _req
|
import requests as _req
|
||||||
import tempfile as _tf
|
import tempfile as _tf
|
||||||
import threading as _t
|
import threading as _t
|
||||||
|
@ -179,25 +182,46 @@ def create(title=None, size=(0,0), icon=None, resizable=False, noframe=False):
|
||||||
|
|
||||||
def ramLimit(memory_limit):
|
def ramLimit(memory_limit):
|
||||||
if not nonwin32api:
|
if not nonwin32api:
|
||||||
job_name = ''
|
g_hjob = None
|
||||||
breakaway = 'silent'
|
def create_job(job_name='', breakaway='silent'):
|
||||||
hjob = _w32j.CreateJobObject(None,job_name)
|
hjob = _w32j.CreateJobObject(None, job_name)
|
||||||
if breakaway:
|
if breakaway:
|
||||||
info = _w32j.QueryInformationJobObject(hjob,_w32j.JobObjectExtendedLimitInformation)
|
info = _w32j.QueryInformationJobObject(hjob,
|
||||||
if breakaway=='silent':info['BasicLimitInformation']['LimitFlags']|=(_w32j.JOB_OBJECT_LIMIT_SILENT_BREAKAWAY_OK)
|
_w32j.JobObjectExtendedLimitInformation)
|
||||||
else:info['BasicLimitInformation']['LimitFlags']|=(_w32j.JOB_OBJECT_LIMIT_BREAKAWAY_OK)
|
if breakaway == 'silent':
|
||||||
_w32j.SetInformationJobObject(hjob,_w32j.JobObjectExtendedLimitInformation,info)
|
info['BasicLimitInformation']['LimitFlags'] |= (
|
||||||
hprocess = _w32a.GetCurrentProcess()
|
_w32j.JOB_OBJECT_LIMIT_SILENT_BREAKAWAY_OK)
|
||||||
try:_w32j.AssignProcessToJobObject(hjob, hprocess);g_hjob=hjob
|
else:
|
||||||
except _w32j.error as e:
|
info['BasicLimitInformation']['LimitFlags'] |= (
|
||||||
if e.winerror!=winerror.ERROR_ACCESS_DENIED:raise
|
_w32j.JOB_OBJECT_LIMIT_BREAKAWAY_OK)
|
||||||
elif sys.getwindowsversion()>=(6,2):raise
|
_w32j.SetInformationJobObject(hjob,
|
||||||
elif _w32j.IsProcessInJob(hprocess,None):raise
|
_w32j.JobObjectExtendedLimitInformation, info)
|
||||||
warnings.warn('The process is already in a job. Nested jobs are not supported prior to Windows 8.')
|
return hjob
|
||||||
info=_w32j.QueryInformationJobObject(g_hjob,_w32j.JobObjectExtendedLimitInformation)
|
def assign_job(hjob):
|
||||||
info['ProcessMemoryLimit']=memory_limit
|
global g_hjob
|
||||||
info['BasicLimitInformation']['LimitFlags']|=(_w32j.JOB_OBJECT_LIMIT_PROCESS_MEMORY)
|
hprocess = _w32a.GetCurrentProcess()
|
||||||
_w32j.SetInformationJobObject(g_hjob,_w32j.JobObjectExtendedLimitInformation,info)
|
try:
|
||||||
|
_w32j.AssignProcessToJobObject(hjob, hprocess)
|
||||||
|
g_hjob = hjob
|
||||||
|
except _w32j.error as e:
|
||||||
|
if (e._we != _we.ERROR_ACCESS_DENIED or
|
||||||
|
_sys.getwindowsversion() >= (6, 2) or
|
||||||
|
not _w32j.IsProcessInJob(hprocess, None)):
|
||||||
|
raise
|
||||||
|
_warn.warn('The process is already in a job. Nested jobs are not '
|
||||||
|
'supported prior to Windows 8.')
|
||||||
|
def limit_memory(memory_limit):
|
||||||
|
if g_hjob is None:
|
||||||
|
return
|
||||||
|
info = _w32j.QueryInformationJobObject(g_hjob,
|
||||||
|
_w32j.JobObjectExtendedLimitInformation)
|
||||||
|
info['ProcessMemoryLimit'] = memory_limit
|
||||||
|
info['BasicLimitInformation']['LimitFlags'] |= (
|
||||||
|
_w32j.JOB_OBJECT_LIMIT_PROCESS_MEMORY)
|
||||||
|
_w32j.SetInformationJobObject(g_hjob,
|
||||||
|
_w32j.JobObjectExtendedLimitInformation, info)
|
||||||
|
assign_job(create_job())
|
||||||
|
limit_memory(memory_limit)
|
||||||
|
|
||||||
def close():
|
def close():
|
||||||
_pg.quit()
|
_pg.quit()
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue