Add files via upload
This commit is contained in:
parent
a1b949ff7d
commit
7efd341276
9 changed files with 274 additions and 44 deletions
|
@ -3,7 +3,6 @@ from pygwin.tray import tray as _tray
|
|||
from datetime import datetime as _dt
|
||||
from pygwin.image import save as _s
|
||||
from pygwin._pg import pg as _pg
|
||||
import pygwin._icon as _icon
|
||||
import pygwin.image as _img
|
||||
import win32job as _w32j
|
||||
import win32api as _w32a
|
||||
|
@ -30,7 +29,7 @@ class win(_surface):
|
|||
_pg.display.update()
|
||||
def title():
|
||||
def fget(self):
|
||||
return _pg.display.get_caption()
|
||||
return _pg.display.get_caption()[0]
|
||||
def fset(self, value):
|
||||
if type(value) != str:
|
||||
return
|
||||
|
@ -109,15 +108,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)
|
||||
else:
|
||||
surf = _img.fromBytes(_icon.iconbytes)
|
||||
try:
|
||||
orig = surf._surface_orig
|
||||
except:
|
||||
orig = surf._orig
|
||||
_pg.display.set_icon(orig)
|
||||
return win()
|
||||
return win(icon)
|
||||
|
||||
def ramLimit(memory_limit):
|
||||
hjob = _w32j.CreateJobObject(None, job_name)
|
||||
|
|
|
@ -2,6 +2,7 @@ import threading
|
|||
import wx
|
||||
import wx.adv
|
||||
from pygwin._pg import pg
|
||||
import copy
|
||||
|
||||
class tray(wx.adv.TaskBarIcon):
|
||||
def __init__(self, tooltip, iconpath):
|
||||
|
@ -14,40 +15,35 @@ class tray(wx.adv.TaskBarIcon):
|
|||
self.frame = self._app.frame
|
||||
super().__init__()
|
||||
self._tooltip = tooltip
|
||||
self._iconpath = iconpath
|
||||
self.setIcon(iconpath)
|
||||
self.Bind(wx.adv.EVT_TASKBAR_LEFT_DOWN,
|
||||
lambda x:self.onLeftMouseButton())
|
||||
self._menu = wx.Menu()
|
||||
|
||||
def CreatePopupMenu(self):
|
||||
return self._menu
|
||||
|
||||
def GetPopupMenu(self):
|
||||
return self._menu
|
||||
def setIcon(self, path):
|
||||
self._bicon = wx.Icon(wx.Bitmap(path))
|
||||
self.SetIcon(self._bicon, self._tooltip)
|
||||
|
||||
def setTooltip(self, tooltip):
|
||||
self.SetIcon(self._bicon, tooltip)
|
||||
self._tooltip = tooltip
|
||||
|
||||
def onLeftMouseButton(self):
|
||||
pass
|
||||
|
||||
def addSeparator(self):
|
||||
self._menu.AppendSeparator()
|
||||
|
||||
def addCommand(self,text,func=lambda:None):
|
||||
item = wx.MenuItem(self._menu,-1,text)
|
||||
self._menu.Bind(wx.EVT_MENU,
|
||||
lambda x:func(),
|
||||
id=item.GetId())
|
||||
self._menu.Append(item)
|
||||
|
||||
def start(self, thread=True):
|
||||
cbotld = lambda x:self.onLeftMouseButton()
|
||||
self.Bind(wx.adv.EVT_TASKBAR_LEFT_DOWN,cbotld)
|
||||
if thread: threading.Thread(
|
||||
target=self._app.MainLoop,
|
||||
daemon=1).start()
|
||||
else: self._app.MainLoop()
|
||||
|
||||
def stop(self):
|
||||
wx.CallAfter(self._app.frame.Close)
|
||||
|
|
129
pygwin/ui.py
129
pygwin/ui.py
|
@ -182,6 +182,135 @@ class entry(widget):
|
|||
x = self.surface.size[0]-text.size[0]-10
|
||||
self.surface.blit(text,(x,self.surface.size[1]/2-text.size[1]/2))
|
||||
|
||||
if position != None:
|
||||
if self.surface.rect(position[0],
|
||||
position[1]).contains(_m.getPosition()[0],
|
||||
_m.getPosition()[1]):
|
||||
if not self.wcl:
|
||||
_m.setCursor(_pg.SYSTEM_CURSOR_HAND)
|
||||
else:
|
||||
if not self.ws:
|
||||
_m.setCursor(_pg.SYSTEM_CURSOR_ARROW)
|
||||
self.ws = True
|
||||
if _m.isPressed('left'):
|
||||
if not self.wcl:
|
||||
self.focus=self.focus==0
|
||||
self.wcl = True
|
||||
else:
|
||||
self.wcl = False
|
||||
self.wsnr = False
|
||||
else:
|
||||
if not self.wsnr:
|
||||
_m.setCursor(_pg.SYSTEM_CURSOR_ARROW)
|
||||
self.wsnr = True
|
||||
if _m.isPressed('left'):
|
||||
self.focus = False
|
||||
def insert(self,text):
|
||||
if _ct.WinDLL("User32.dll").GetKeyState(0x14):
|
||||
text = text.upper()
|
||||
if hex(getattr(_ct.windll.LoadLibrary("user32.dll"), "GetKeyboardLayout")(0))=='0x4190419':
|
||||
text = text.translate(dict(zip(map(ord, '''qwertyuiop[]asdfghjkl;'zxcvbnm,./`QWERTYUIOP{}ASDFGHJKL:"ZXCVBNM<>?~'''),
|
||||
'''йцукенгшщзхъфывапролджэячсмитьбю.ёЙЦУКЕНГШЩЗХЪФЫВАПРОЛДЖЭЯЧСМИТЬБЮ,Ё''')))
|
||||
if text in self.blacklist:
|
||||
return
|
||||
if self.whitelist != None:
|
||||
if text not in self.whitelist:
|
||||
return
|
||||
if self.maxSymbols != None:
|
||||
if len(text) > self.maxSymbols:
|
||||
return
|
||||
self.text += text
|
||||
def delete(self,symbols=1):
|
||||
self.text = self.text[:0-symbols]
|
||||
def draw(self, win, pos):
|
||||
self._generate(pos)
|
||||
win.blit(self.surface,pos)
|
||||
def get(self):
|
||||
return text
|
||||
class textarea(widget):
|
||||
def __init__(self,hint='',fontSize=30,
|
||||
font=_df,width=None,bg=(70,70,70),
|
||||
fg=(180,180,200),afg=(200,200,200),
|
||||
abg=(50,50,50),hintColor=(100,100,100),
|
||||
lineColor=(200,200,200),
|
||||
borderColor=(50,50,50),
|
||||
borderWidth=5,maxSymbols=None,
|
||||
whitelist=None,blacklist=[]):
|
||||
super()._args(locals())
|
||||
self.text = ''
|
||||
self.focus = False
|
||||
self.tick = 0
|
||||
self.wcl = False
|
||||
self.startHint = self.hint
|
||||
self.ws = False
|
||||
if self.width == None:
|
||||
if self.hint != '':
|
||||
hintSize = self.font.size(self.hint,self.fontSize)
|
||||
else:
|
||||
hintSize = (150,self.font.size('X',self.fontSize)[1])
|
||||
self.height = hintSize[1]+10
|
||||
if self.width == None:
|
||||
self.width = hintSize[0]+50
|
||||
self.surface = _s((self.width,self.height))
|
||||
self.wclk = []
|
||||
self.wsnr = False
|
||||
def _generate(self,position=None):
|
||||
self.surface.fill(self.borderColor)
|
||||
if self.focus:
|
||||
if self.text != '':
|
||||
self.height = self.font.size(self.text,self.fontSize)[1]+10
|
||||
self.surface = _s((self.width,self.height))
|
||||
self.surface.fill(self.borderColor)
|
||||
self.surface.draw.rect(self.abg,_r(self.borderWidth,self.borderWidth,
|
||||
self.surface.size[0]-self.borderWidth*2,
|
||||
self.surface.size[1]-self.borderWidth*2))
|
||||
if self.text == '':
|
||||
text = self.font.render(self.hint,self.fontSize,self.hintColor)
|
||||
else:
|
||||
text = self.font.render(self.text,self.fontSize,self.afg)
|
||||
x = 10
|
||||
if text.size[0] >= self.surface.size[0]-20:
|
||||
x = self.surface.size[0]-text.size[0]-10
|
||||
self.surface.blit(text,(x,self.surface.size[1]/2-text.size[1]/2))
|
||||
for i in _k.getPressed().items():
|
||||
if i[1]:
|
||||
if i[0] not in self.wclk:
|
||||
if len(i[0]) == 1:
|
||||
self.insert(i[0])
|
||||
elif i[0] == 'backspace':
|
||||
self.delete()
|
||||
elif i[0] == 'return':
|
||||
if self.maxSymbols != None:
|
||||
if len(text) > self.maxSymbols:
|
||||
continue
|
||||
self.text += '\n'
|
||||
elif i[0] == 'space':
|
||||
self.insert(' ')
|
||||
self.wclk.append(i[0])
|
||||
else:
|
||||
if i[0] in self.wclk:
|
||||
self.wclk.remove(i[0])
|
||||
self.tick += 1
|
||||
if self.tick >= 60:
|
||||
if self.text != '':
|
||||
points = [[x+text.size[0],self.surface.size[1]/2-text.size[1]/2],
|
||||
[x+text.size[0],self.surface.size[1]/2-text.size[1]/2+self.surface.size[1]-10]]
|
||||
self.surface.draw.line(self.lineColor,points[0],points[1],3)
|
||||
if self.tick == 120:
|
||||
self.tick = 0
|
||||
else:
|
||||
self.surface.draw.rect(self.bg,_r(self.borderWidth,self.borderWidth,
|
||||
self.surface.size[0]-self.borderWidth*2,
|
||||
self.surface.size[1]-self.borderWidth*2))
|
||||
if self.text == '':
|
||||
text = self.font.render(self.hint,self.fontSize,self.hintColor)
|
||||
else:
|
||||
text = self.font.render(self.text,self.fontSize,self.fg)
|
||||
x = self.surface.size[0]/2-text.size[0]/2
|
||||
if text.size[0] >= self.surface.size[0]-20:
|
||||
x = self.surface.size[0]-text.size[0]-10
|
||||
self.surface.blit(text,(x,self.surface.size[1]/2-text.size[1]/2))
|
||||
|
||||
if position != None:
|
||||
if self.surface.rect(position[0],
|
||||
position[1]).contains(_m.getPosition()[0],
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue