Add files via upload
This commit is contained in:
parent
e87b3c276a
commit
1170f1521c
12 changed files with 764 additions and 0 deletions
91
pygwin/_win.py
Normal file
91
pygwin/_win.py
Normal file
|
@ -0,0 +1,91 @@
|
|||
from pygwin.surface import surface as _surface
|
||||
from datetime import datetime as _dt
|
||||
from pygwin._pg import pg as _pg
|
||||
import win32job as _w32j
|
||||
import win32api as _w32a
|
||||
|
||||
class win(_surface):
|
||||
def __init__(self):
|
||||
self._orig = _pg.display.get_surface()
|
||||
super().__init__(self._orig.get_size())
|
||||
self._orig = _pg.display.get_surface()
|
||||
self._clock = _pg.time.Clock()
|
||||
self._withfps = False
|
||||
def update(self, fps=-1):
|
||||
if fps != -1:
|
||||
self._clock.tick(fps)
|
||||
self._withfps = True
|
||||
_pg.display.update()
|
||||
def title(self, title):
|
||||
_pg.display.set_caption(title)
|
||||
def icon(self, path):
|
||||
_pg.display.set_icon(_pg.image.load(path))
|
||||
def resize(self, size):
|
||||
_pg.display.set_mode(size)
|
||||
def fullscreen(self):
|
||||
_pg.display.toogle_fullscreen()
|
||||
def close(self):
|
||||
_pg.display.quit()
|
||||
@property
|
||||
def rawFps(self):
|
||||
if self._withfps:
|
||||
return self._clock.get_fps()
|
||||
else:
|
||||
return float(f'2010.{_dt.now().year}')
|
||||
@property
|
||||
def fps(self):
|
||||
return int(self.rawFps)
|
||||
@property
|
||||
def hwnd(self):
|
||||
return _pg.display.get_wm_info()['window']
|
||||
|
||||
def create(title=None, size=(0,0), icon=None):
|
||||
screen = _pg.display.set_mode(size)
|
||||
if title != None: _pg.display.set_caption(title)
|
||||
if icon != None: _pg.display.set_icon(_pg.image.load(icon))
|
||||
return win()
|
||||
|
||||
def ramLimit(bytes):
|
||||
def create_job(job_name='', breakaway='silent'):
|
||||
hjob = _w32j.CreateJobObject(None, job_name)
|
||||
if breakaway:
|
||||
info = _w32j.QueryInformationJobObject(hjob,
|
||||
_w32j.JobObjectExtendedLimitInformation)
|
||||
if breakaway == 'silent':
|
||||
info['BasicLimitInformation']['LimitFlags'] |= (
|
||||
_w32j.JOB_OBJECT_LIMIT_SILENT_BREAKAWAY_OK)
|
||||
else:
|
||||
info['BasicLimitInformation']['LimitFlags'] |= (
|
||||
_w32j.JOB_OBJECT_LIMIT_BREAKAWAY_OK)
|
||||
_w32j.SetInformationJobObject(hjob,
|
||||
_w32j.JobObjectExtendedLimitInformation, info)
|
||||
return hjob
|
||||
def assign_job(hjob):
|
||||
global g_hjob
|
||||
hprocess = _w32a.GetCurrentProcess()
|
||||
try:
|
||||
_w32j.AssignProcessToJobObject(hjob, hprocess)
|
||||
g_hjob = hjob
|
||||
except _w32j.error as e:
|
||||
if (e.winerror != winerror.ERROR_ACCESS_DENIED or
|
||||
sys.getwindowsversion() >= (6, 2) or
|
||||
not _w32j.IsProcessInJob(hprocess, None)):
|
||||
raise
|
||||
warnings.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(bytes)
|
||||
|
||||
def close():
|
||||
_pg.quit()
|
||||
quit()
|
Loading…
Add table
Add a link
Reference in a new issue