ruff fixes
This commit is contained in:
parent
5932aac00d
commit
8f41f41455
34 changed files with 1435 additions and 896 deletions
|
@ -1,48 +1,50 @@
|
||||||
import pygwin # Importing pygwin
|
import pygwin # Importing pygwin
|
||||||
import random # Importing random
|
import random # Importing random
|
||||||
|
|
||||||
win = pygwin.create('A Simple Game', (500,500)) # Creating window
|
win = pygwin.create("A Simple Game", (500, 500)) # Creating window
|
||||||
|
|
||||||
player = [250,250] # Player position
|
player = [250, 250] # Player position
|
||||||
apple = pygwin.rect(random.randint(0,490),
|
apple = pygwin.rect(
|
||||||
random.randint(0,490),20,20) # Apple rect
|
random.randint(0, 490), random.randint(0, 490), 20, 20
|
||||||
score = 0 # Player score
|
) # Apple rect
|
||||||
|
score = 0 # Player score
|
||||||
|
|
||||||
run = True # Is loop running
|
run = True # Is loop running
|
||||||
while run: # Creating loop
|
while run: # Creating loop
|
||||||
for event in pygwin.getEvents(): # Events loop
|
for event in pygwin.getEvents(): # Events loop
|
||||||
if event.type == pygwin.QUIT: # If window quit
|
if event.type == pygwin.QUIT: # If window quit
|
||||||
run = False # Break loop
|
run = False # Break loop
|
||||||
win.fill((255,255,255)) # Fill window with color
|
win.fill((255, 255, 255)) # Fill window with color
|
||||||
|
|
||||||
win.blit(score,(0,0)) # Writing player score
|
win.blit(score, (0, 0)) # Writing player score
|
||||||
|
|
||||||
if pygwin.keyboard.isPressed('w'): # If keyboard key w pressed
|
if pygwin.keyboard.isPressed("w"): # If keyboard key w pressed
|
||||||
player[1] -= 5 # Player position up
|
player[1] -= 5 # Player position up
|
||||||
if pygwin.keyboard.isPressed('s'): # If keyboard key s pressed
|
if pygwin.keyboard.isPressed("s"): # If keyboard key s pressed
|
||||||
player[1] += 5 # Player position down
|
player[1] += 5 # Player position down
|
||||||
if pygwin.keyboard.isPressed('d'): # If keyboard key d pressed
|
if pygwin.keyboard.isPressed("d"): # If keyboard key d pressed
|
||||||
player[0] += 5 # Player position right
|
player[0] += 5 # Player position right
|
||||||
if pygwin.keyboard.isPressed('a'): # If keyboard key a pressed
|
if pygwin.keyboard.isPressed("a"): # If keyboard key a pressed
|
||||||
player[0] -= 5 # Player position left
|
player[0] -= 5 # Player position left
|
||||||
|
|
||||||
if player[0] <= -10: # If player out of the screen (left)
|
if player[0] <= -10: # If player out of the screen (left)
|
||||||
player[0] = 510 # Set player position in right
|
player[0] = 510 # Set player position in right
|
||||||
if player[1] <= -10: # If player out of the screen (up)
|
if player[1] <= -10: # If player out of the screen (up)
|
||||||
player[1] = 510 # Set player position in down
|
player[1] = 510 # Set player position in down
|
||||||
if player[0] > 510: # If player out of the screen (right)
|
if player[0] > 510: # If player out of the screen (right)
|
||||||
player[0] = -10 # Set player position in left
|
player[0] = -10 # Set player position in left
|
||||||
if player[1] > 510: # If player out of the screen (down)
|
if player[1] > 510: # If player out of the screen (down)
|
||||||
player[1] = -10 # Set player position in up
|
player[1] = -10 # Set player position in up
|
||||||
|
|
||||||
playerRect = pygwin.rect(player[0]-10,player[1]-10,20,20) # Player rect
|
playerRect = pygwin.rect(player[0] - 10, player[1] - 10, 20, 20) # Player rect
|
||||||
win.draw.rect((0,0,0),playerRect) # Drawing player rect
|
win.draw.rect((0, 0, 0), playerRect) # Drawing player rect
|
||||||
win.draw.rect((200,50,50),apple) # Drawing apple rect
|
win.draw.rect((200, 50, 50), apple) # Drawing apple rect
|
||||||
|
|
||||||
if playerRect.collide(apple): # If player rect collide apple rect
|
if playerRect.collide(apple): # If player rect collide apple rect
|
||||||
apple = pygwin.rect(random.randint(0,490),
|
apple = pygwin.rect(
|
||||||
random.randint(0,490),20,20) # Change apple rect
|
random.randint(0, 490), random.randint(0, 490), 20, 20
|
||||||
score += 1 # Update player score
|
) # Change apple rect
|
||||||
|
score += 1 # Update player score
|
||||||
|
|
||||||
win.update(60) # Update window
|
win.update(60) # Update window
|
||||||
pygwin.close() # Close pygwin
|
pygwin.close() # Close pygwin
|
||||||
|
|
|
@ -1,37 +1,36 @@
|
||||||
import pygwin
|
import pygwin
|
||||||
import random
|
import random
|
||||||
|
|
||||||
win = pygwin.create('A Simple Game', (500,500))
|
win = pygwin.create("A Simple Game", (500, 500))
|
||||||
|
|
||||||
player = [250,250]
|
player = [250, 250]
|
||||||
apple = pygwin.rect(random.randint(0,490),
|
apple = pygwin.rect(random.randint(0, 490), random.randint(0, 490), 20, 20)
|
||||||
random.randint(0,490),20,20)
|
|
||||||
score = 0
|
score = 0
|
||||||
|
|
||||||
record = pygwin.record(win,True) # Init recording
|
record = pygwin.record(win, True) # Init recording
|
||||||
record.start() # Start recording
|
record.start() # Start recording
|
||||||
|
|
||||||
run = True
|
run = True
|
||||||
while run:
|
while run:
|
||||||
for event in pygwin.getEvents():
|
for event in pygwin.getEvents():
|
||||||
if event.type == pygwin.QUIT:
|
if event.type == pygwin.QUIT:
|
||||||
run = False
|
run = False
|
||||||
record.stop() # Stop recording
|
record.stop() # Stop recording
|
||||||
win.fill((255,255,255))
|
win.fill((255, 255, 255))
|
||||||
|
|
||||||
playerRect = pygwin.rect(player[0]-10,player[1]-10,20,20)
|
playerRect = pygwin.rect(player[0] - 10, player[1] - 10, 20, 20)
|
||||||
win.draw.rect((0,0,0),playerRect)
|
win.draw.rect((0, 0, 0), playerRect)
|
||||||
win.draw.rect((200,50,50),apple)
|
win.draw.rect((200, 50, 50), apple)
|
||||||
|
|
||||||
win.blit(score,(0,0))
|
win.blit(score, (0, 0))
|
||||||
|
|
||||||
if pygwin.keyboard.isPressed('w'):
|
if pygwin.keyboard.isPressed("w"):
|
||||||
player[1] -= 5
|
player[1] -= 5
|
||||||
if pygwin.keyboard.isPressed('s'):
|
if pygwin.keyboard.isPressed("s"):
|
||||||
player[1] += 5
|
player[1] += 5
|
||||||
if pygwin.keyboard.isPressed('d'):
|
if pygwin.keyboard.isPressed("d"):
|
||||||
player[0] += 5
|
player[0] += 5
|
||||||
if pygwin.keyboard.isPressed('a'):
|
if pygwin.keyboard.isPressed("a"):
|
||||||
player[0] -= 5
|
player[0] -= 5
|
||||||
|
|
||||||
if player[0] <= -10:
|
if player[0] <= -10:
|
||||||
|
@ -44,10 +43,9 @@ while run:
|
||||||
player[1] = -10
|
player[1] = -10
|
||||||
|
|
||||||
if playerRect.collide(apple):
|
if playerRect.collide(apple):
|
||||||
apple = pygwin.rect(random.randint(0,490),
|
apple = pygwin.rect(random.randint(0, 490), random.randint(0, 490), 20, 20)
|
||||||
random.randint(0,490),20,20)
|
|
||||||
score += 1
|
score += 1
|
||||||
|
|
||||||
win.update(60)
|
win.update(60)
|
||||||
record.render('Recording.mp4') # Render recording
|
record.render("Recording.mp4") # Render recording
|
||||||
pygwin.close()
|
pygwin.close()
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
import pygwin
|
import pygwin
|
||||||
|
|
||||||
win = pygwin.create('Title',(500,500))
|
win = pygwin.create("Title", (500, 500))
|
||||||
|
|
||||||
run = True
|
run = True
|
||||||
while run:
|
while run:
|
||||||
|
|
|
@ -1,43 +1,47 @@
|
||||||
import pygwin
|
import pygwin
|
||||||
|
|
||||||
win = pygwin.create('UI example',(270,350))
|
win = pygwin.create("UI example", (270, 350))
|
||||||
base = pygwin.ui.base(win) # Creating ui base
|
base = pygwin.ui.base(win) # Creating ui base
|
||||||
|
|
||||||
lbl = pygwin.ui.label('Label') # Creating label
|
lbl = pygwin.ui.label("Label") # Creating label
|
||||||
base.put(lbl,(130-(lbl.surface.size[0]/2),10)) # Putting label to base
|
base.put(lbl, (130 - (lbl.surface.size[0] / 2), 10)) # Putting label to base
|
||||||
base.put(pygwin.ui.button('Button',width=250),(10,50)) # Putting button to base
|
base.put(pygwin.ui.button("Button", width=250), (10, 50)) # Putting button to base
|
||||||
base.put(pygwin.ui.entry('Entry',width=123),(10,100)) # Putting entry to base
|
base.put(pygwin.ui.entry("Entry", width=123), (10, 100)) # Putting entry to base
|
||||||
base.put(pygwin.ui.keySelect('Key',width=122),(138,100)) # Putting key selector to base
|
base.put(
|
||||||
loadbar = pygwin.ui.loadingBar(250,25) # Creating loading bar
|
pygwin.ui.keySelect("Key", width=122), (138, 100)
|
||||||
base.put(loadbar,(10,150)) # Putting loading bar to base
|
) # Putting key selector to base
|
||||||
slider = pygwin.ui.slider(250) # Creating slider
|
loadbar = pygwin.ui.loadingBar(250, 25) # Creating loading bar
|
||||||
base.put(slider,(10,170)) # Putting slider to base
|
base.put(loadbar, (10, 150)) # Putting loading bar to base
|
||||||
cb = pygwin.ui.checkBox(25,borderWidth=2) # Creating checkbox
|
slider = pygwin.ui.slider(250) # Creating slider
|
||||||
base.put(cb,(10,220)) # Putting checkbox to base
|
base.put(slider, (10, 170)) # Putting slider to base
|
||||||
base.put(pygwin.ui.label('Checkbox',20),(45,225)) # Putting checkbox label to base
|
cb = pygwin.ui.checkBox(25, borderWidth=2) # Creating checkbox
|
||||||
ta = pygwin.ui.textarea('Textarea',width=250,maxSymbols=20) # Creating textarea
|
base.put(cb, (10, 220)) # Putting checkbox to base
|
||||||
ta.text += '0123456789\n0123456789' # Set text to textarea
|
base.put(pygwin.ui.label("Checkbox", 20), (45, 225)) # Putting checkbox label to base
|
||||||
ta.focus = True # Focus textarea
|
ta = pygwin.ui.textarea("Textarea", width=250, maxSymbols=20) # Creating textarea
|
||||||
ta._generate() # Generate textarea surface
|
ta.text += "0123456789\n0123456789" # Set text to textarea
|
||||||
ta.focus = False # Unfocus textarea
|
ta.focus = True # Focus textarea
|
||||||
base.put(ta,(10,255)) # Putting textarea to base
|
ta._generate() # Generate textarea surface
|
||||||
tta = pygwin.ui.tip('textarea',
|
ta.focus = False # Unfocus textarea
|
||||||
*ta.surface.size,
|
base.put(ta, (10, 255)) # Putting textarea to base
|
||||||
waitBeforeShowing=30) # Creating textarea tip
|
tta = pygwin.ui.tip(
|
||||||
base.put(tta,(10,255)) # Putting textarea tip to base
|
"textarea", *ta.surface.size, waitBeforeShowing=30
|
||||||
|
) # Creating textarea tip
|
||||||
|
base.put(tta, (10, 255)) # Putting textarea tip to base
|
||||||
|
|
||||||
run = True
|
run = True
|
||||||
while run:
|
while run:
|
||||||
for event in pygwin.getEvents():
|
for event in pygwin.getEvents():
|
||||||
if event.type == pygwin.QUIT:
|
if event.type == pygwin.QUIT:
|
||||||
run = False
|
run = False
|
||||||
base.draw() # Drawing base
|
base.draw() # Drawing base
|
||||||
if cb.get(): # If checkbox
|
if cb.get(): # If checkbox
|
||||||
loadbar.set(slider.get()) # If checkbox
|
loadbar.set(slider.get()) # If checkbox
|
||||||
else:
|
else:
|
||||||
loadbar.step() # Step loading bar
|
loadbar.step() # Step loading bar
|
||||||
if loadbar.get() == loadbar.length: # If loading bar is full
|
if loadbar.get() == loadbar.length: # If loading bar is full
|
||||||
loadbar.set(0) # Reset loading bar
|
loadbar.set(0) # Reset loading bar
|
||||||
tta.responceWidth,tta.responceHeight=ta.surface.size # Set responce width, height to textarea tip
|
tta.responceWidth, tta.responceHeight = (
|
||||||
|
ta.surface.size
|
||||||
|
) # Set responce width, height to textarea tip
|
||||||
win.update(30)
|
win.update(30)
|
||||||
pygwin.close()
|
pygwin.close()
|
||||||
|
|
|
@ -1,13 +1,12 @@
|
||||||
import pygwin
|
import pygwin
|
||||||
import random
|
import random
|
||||||
|
|
||||||
win = pygwin.create('A Simple Game', (500,500))
|
win = pygwin.create("A Simple Game", (500, 500))
|
||||||
win.denyDrag() # Prohibit dragging the window
|
win.denyDrag() # Prohibit dragging the window
|
||||||
start_pos = win.position # Start window pos
|
start_pos = win.position # Start window pos
|
||||||
|
|
||||||
player = [250,250]
|
player = [250, 250]
|
||||||
apple = pygwin.rect(random.randint(0,490),
|
apple = pygwin.rect(random.randint(0, 490), random.randint(0, 490), 20, 20)
|
||||||
random.randint(0,490),20,20)
|
|
||||||
score = 0
|
score = 0
|
||||||
|
|
||||||
run = True
|
run = True
|
||||||
|
@ -15,38 +14,45 @@ while run:
|
||||||
for event in pygwin.getEvents():
|
for event in pygwin.getEvents():
|
||||||
if event.type == pygwin.QUIT:
|
if event.type == pygwin.QUIT:
|
||||||
run = False
|
run = False
|
||||||
win.fill((255,255,255))
|
win.fill((255, 255, 255))
|
||||||
|
|
||||||
win.blit(score,(0,0))
|
win.blit(score, (0, 0))
|
||||||
|
|
||||||
set_position = list(win.position)
|
set_position = list(win.position)
|
||||||
if pygwin.keyboard.isPressed('w'):
|
if pygwin.keyboard.isPressed("w"):
|
||||||
player[1] -= 5
|
player[1] -= 5
|
||||||
set_position[1] -= 5 # Move window up
|
set_position[1] -= 5 # Move window up
|
||||||
if pygwin.keyboard.isPressed('s'):
|
if pygwin.keyboard.isPressed("s"):
|
||||||
player[1] += 5
|
player[1] += 5
|
||||||
set_position[1] += 5 # Move window down
|
set_position[1] += 5 # Move window down
|
||||||
if pygwin.keyboard.isPressed('d'):
|
if pygwin.keyboard.isPressed("d"):
|
||||||
player[0] += 5
|
player[0] += 5
|
||||||
set_position[0] += 5 # Move window right
|
set_position[0] += 5 # Move window right
|
||||||
if pygwin.keyboard.isPressed('a'):
|
if pygwin.keyboard.isPressed("a"):
|
||||||
player[0] -= 5
|
player[0] -= 5
|
||||||
set_position[0] -= 5 # Move window left
|
set_position[0] -= 5 # Move window left
|
||||||
win.move(*set_position) # Set position
|
win.move(*set_position) # Set position
|
||||||
|
|
||||||
playerRect = pygwin.rect(player[0]-10,player[1]-10,20,20)
|
playerRect = pygwin.rect(player[0] - 10, player[1] - 10, 20, 20)
|
||||||
playerRect.x += start_pos[0]-win.position[0] # Set player rect x pos relatively start window position
|
playerRect.x += (
|
||||||
playerRect.y += start_pos[1]-win.position[1] # Set player rect y pos relatively start window position
|
start_pos[0] - win.position[0]
|
||||||
win.draw.rect((0,0,0),playerRect)
|
) # Set player rect x pos relatively start window position
|
||||||
|
playerRect.y += (
|
||||||
|
start_pos[1] - win.position[1]
|
||||||
|
) # Set player rect y pos relatively start window position
|
||||||
|
win.draw.rect((0, 0, 0), playerRect)
|
||||||
|
|
||||||
atemp = apple.copy() # Create copy of apple rect
|
atemp = apple.copy() # Create copy of apple rect
|
||||||
atemp.x += start_pos[0]-win.position[0] # Set apple x pos relatively start window position
|
atemp.x += (
|
||||||
atemp.y += start_pos[1]-win.position[1] # Set apple y pos relatively start window position
|
start_pos[0] - win.position[0]
|
||||||
win.draw.rect((200,50,50),atemp)
|
) # Set apple x pos relatively start window position
|
||||||
|
atemp.y += (
|
||||||
|
start_pos[1] - win.position[1]
|
||||||
|
) # Set apple y pos relatively start window position
|
||||||
|
win.draw.rect((200, 50, 50), atemp)
|
||||||
|
|
||||||
if atemp.collide(playerRect):
|
if atemp.collide(playerRect):
|
||||||
apple = pygwin.rect(random.randint(50,490),
|
apple = pygwin.rect(random.randint(50, 490), random.randint(50, 490), 20, 20)
|
||||||
random.randint(50,490),20,20)
|
|
||||||
score += 1
|
score += 1
|
||||||
|
|
||||||
win.update(60)
|
win.update(60)
|
||||||
|
|
|
@ -1,16 +1,32 @@
|
||||||
import .pygame
|
__all__ = [
|
||||||
from pygame.locals import *
|
"pygame",
|
||||||
|
"tray",
|
||||||
|
"rect",
|
||||||
|
"surface",
|
||||||
|
"console",
|
||||||
|
"color",
|
||||||
|
"keyboard",
|
||||||
|
"mouse",
|
||||||
|
"mixer",
|
||||||
|
"image",
|
||||||
|
"font",
|
||||||
|
"ui",
|
||||||
|
]
|
||||||
|
|
||||||
|
from . import pygame
|
||||||
|
from .pygame.locals import *
|
||||||
from .tray import tray
|
from .tray import tray
|
||||||
from .rect import rect
|
from .rect import rect
|
||||||
from .surface import surface
|
from .surface import surface
|
||||||
from .console import console
|
from .console import console
|
||||||
from .color import color
|
from .color import color
|
||||||
from .window import *
|
from .window import *
|
||||||
import .keyboard
|
from . import keyboard
|
||||||
import .mouse
|
from . import mouse
|
||||||
import .image
|
from . import image
|
||||||
import .mixer
|
from . import mixer
|
||||||
import .font
|
from . import font
|
||||||
import .ui
|
from . import ui
|
||||||
import .gamepad as _gp
|
from . import gamepad as _gp
|
||||||
|
|
||||||
gamepad = _gp.gamepad(pygame)
|
gamepad = _gp.gamepad(pygame)
|
||||||
|
|
|
@ -1,27 +1,34 @@
|
||||||
class color:
|
class color:
|
||||||
def __init__(self,r,g=None,b=None,a=255):
|
def __init__(self, r, g=None, b=None, a=255):
|
||||||
try:
|
try:
|
||||||
r,g,b = tuple(int(r[i:i+2],16)for i in(0,2,4))
|
r, g, b = tuple(int(r[i : i + 2], 16) for i in (0, 2, 4))
|
||||||
except:
|
except Exception as _:
|
||||||
pass
|
pass
|
||||||
self.r = r
|
self.r = r
|
||||||
self.g = g
|
self.g = g
|
||||||
self.b = b
|
self.b = b
|
||||||
self.a = a
|
self.a = a
|
||||||
|
|
||||||
def hex(self):
|
def hex(self):
|
||||||
return '%02x%02x%02x' % (self.r,self.g,self.b)
|
return "%02x%02x%02x" % (self.r, self.g, self.b)
|
||||||
|
|
||||||
def rgb(self):
|
def rgb(self):
|
||||||
return (self.r,self.g,self.b,self.a)
|
return (self.r, self.g, self.b, self.a)
|
||||||
|
|
||||||
def inverse(self):
|
def inverse(self):
|
||||||
return color(255-self.r,255-self.g,
|
return color(255 - self.r, 255 - self.g, 255 - self.b, 255 - self.a)
|
||||||
255-self.b,255-self.a)
|
|
||||||
def __getitem__(self,x):
|
def __getitem__(self, x):
|
||||||
return [self.r,self.g,self.b,self.a][x]
|
return [self.r, self.g, self.b, self.a][x]
|
||||||
|
|
||||||
def __list__(self):
|
def __list__(self):
|
||||||
return [self.r,self.g,self.b,self.a]
|
return [self.r, self.g, self.b, self.a]
|
||||||
|
|
||||||
def __tuple__(self):
|
def __tuple__(self):
|
||||||
return self.rgb()
|
return self.rgb()
|
||||||
|
|
||||||
def __repr__(self):
|
def __repr__(self):
|
||||||
return self.__str__()
|
return self.__str__()
|
||||||
|
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
return f'({",".join(str(i)for i in self.__list__())})'
|
return f"({','.join(str(i) for i in self.__list__())})"
|
||||||
|
|
|
@ -1,21 +1,26 @@
|
||||||
import .pygame
|
from . import pygame
|
||||||
|
|
||||||
try:
|
try:
|
||||||
import win32console
|
import win32console
|
||||||
import win32con
|
import win32con
|
||||||
import win32gui
|
import win32gui
|
||||||
|
|
||||||
nonwin = False
|
nonwin = False
|
||||||
except:
|
except Exception as _:
|
||||||
nonwin = True
|
nonwin = True
|
||||||
import pyautogui
|
import pyautogui
|
||||||
|
|
||||||
|
|
||||||
class console:
|
class console:
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
if not nonwin:
|
if not nonwin:
|
||||||
self._hwnd = win32console.GetConsoleWindow()
|
self._hwnd = win32console.GetConsoleWindow()
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def hwnd(self):
|
def hwnd(self):
|
||||||
if not nonwin:
|
if not nonwin:
|
||||||
return self._hwnd
|
return self._hwnd
|
||||||
|
|
||||||
def focus(self):
|
def focus(self):
|
||||||
if not nonwin:
|
if not nonwin:
|
||||||
self.hide()
|
self.hide()
|
||||||
|
@ -23,63 +28,86 @@ class console:
|
||||||
win32gui.BringWindowToTop(self.hwnd)
|
win32gui.BringWindowToTop(self.hwnd)
|
||||||
win32gui.ShowWindow(self.hwnd, win32con.SW_SHOWNORMAL)
|
win32gui.ShowWindow(self.hwnd, win32con.SW_SHOWNORMAL)
|
||||||
win32gui.SetForegroundWindow(self.hwnd)
|
win32gui.SetForegroundWindow(self.hwnd)
|
||||||
|
|
||||||
def hide(self):
|
def hide(self):
|
||||||
if not nonwin:
|
if not nonwin:
|
||||||
win32gui.ShowWindow(self.hwnd, win32con.SW_HIDE)
|
win32gui.ShowWindow(self.hwnd, win32con.SW_HIDE)
|
||||||
|
|
||||||
def show(self):
|
def show(self):
|
||||||
if not nonwin:
|
if not nonwin:
|
||||||
win32gui.ShowWindow(self.hwnd, win32con.SW_SHOW)
|
win32gui.ShowWindow(self.hwnd, win32con.SW_SHOW)
|
||||||
|
|
||||||
def move(self, x, y):
|
def move(self, x, y):
|
||||||
if not nonwin:
|
if not nonwin:
|
||||||
win32gui.SetWindowPos(self.hwnd, x, y, self.size[0], self.size[1])
|
win32gui.SetWindowPos(self.hwnd, x, y, self.size[0], self.size[1])
|
||||||
|
|
||||||
def resize(self, width, height):
|
def resize(self, width, height):
|
||||||
if not nonwin:
|
if not nonwin:
|
||||||
win32gui.SetWindowPos(self.hwnd, self.position[0], self.position[1], width, height)
|
win32gui.SetWindowPos(
|
||||||
|
self.hwnd, self.position[0], self.position[1], width, height
|
||||||
|
)
|
||||||
|
|
||||||
def minimize(self):
|
def minimize(self):
|
||||||
if not nonwin:
|
if not nonwin:
|
||||||
win32gui.ShowWindow(hwnd, win32con.SW_MINIMIZE)
|
win32gui.ShowWindow(self.hwnd, win32con.SW_MINIMIZE)
|
||||||
return self.size
|
return self.size
|
||||||
|
|
||||||
def maximize(self):
|
def maximize(self):
|
||||||
if not nonwin:
|
if not nonwin:
|
||||||
win32gui.ShowWindow(hwnd, win32con.SW_MAXIMIZE)
|
win32gui.ShowWindow(self.hwnd, win32con.SW_MAXIMIZE)
|
||||||
return self.size
|
return self.size
|
||||||
|
|
||||||
def title():
|
def title():
|
||||||
def fget(self):
|
def fget(self):
|
||||||
if not nonwin:
|
if not nonwin:
|
||||||
return win32console.GetConsoleTitle()
|
return win32console.GetConsoleTitle()
|
||||||
|
|
||||||
def fset(self, value):
|
def fset(self, value):
|
||||||
if not nonwin:
|
if not nonwin:
|
||||||
win32console.SetConsoleTitle(str(value))
|
win32console.SetConsoleTitle(str(value))
|
||||||
|
|
||||||
def fdel(self):
|
def fdel(self):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
return locals()
|
return locals()
|
||||||
|
|
||||||
title = property(**title())
|
title = property(**title())
|
||||||
def center(self,x=pygame.display.get_desktop_sizes()[0][0]/2,
|
|
||||||
y=pygame.display.get_desktop_sizes()[0][1]/2):
|
def center(
|
||||||
|
self,
|
||||||
|
x=pygame.display.get_desktop_sizes()[0][0] / 2,
|
||||||
|
y=pygame.display.get_desktop_sizes()[0][1] / 2,
|
||||||
|
):
|
||||||
if not nonwin:
|
if not nonwin:
|
||||||
self.move(x-self.size[0]/2,y-self.size[1]/2)
|
self.move(x - self.size[0] / 2, y - self.size[1] / 2)
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def visible(self):
|
def visible(self):
|
||||||
if not nonwin:
|
if not nonwin:
|
||||||
return win32gui.IsWindowVisible(self.hwnd)
|
return win32gui.IsWindowVisible(self.hwnd)
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def position(self):
|
def position(self):
|
||||||
if not nonwin:
|
if not nonwin:
|
||||||
rect = win32gui.GetWindowRect(self.hwnd)
|
rect = win32gui.GetWindowRect(self.hwnd)
|
||||||
x = rect[0]+7
|
x = rect[0] + 7
|
||||||
y = rect[1]
|
y = rect[1]
|
||||||
return (x, y)
|
return (x, y)
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def size(self):
|
def size(self):
|
||||||
if not nonwin:
|
if not nonwin:
|
||||||
rect = win32gui.GetWindowRect(self.hwnd)
|
rect = win32gui.GetWindowRect(self.hwnd)
|
||||||
w = rect[2] - self.position[0]-7
|
w = rect[2] - self.position[0] - 7
|
||||||
h = rect[3] - self.position[1]-7
|
h = rect[3] - self.position[1] - 7
|
||||||
return (w, h)
|
return (w, h)
|
||||||
|
|
||||||
def screenshot(self, path):
|
def screenshot(self, path):
|
||||||
if not nonwin:
|
if not nonwin:
|
||||||
rect = self.position+self.size
|
rect = self.position + self.size
|
||||||
self.focus()
|
self.focus()
|
||||||
pyautogui.screenshot(path, region=rect)
|
pyautogui.screenshot(path, region=rect)
|
||||||
return path
|
return path
|
||||||
|
|
||||||
|
|
||||||
console = console()
|
console = console()
|
||||||
|
|
|
@ -1,22 +1,38 @@
|
||||||
from .surface import surface
|
from .surface import surface
|
||||||
import .pygame
|
from . import pygame
|
||||||
|
|
||||||
|
|
||||||
class font:
|
class font:
|
||||||
def __init__(self, path):
|
def __init__(self, path):
|
||||||
self._path = path
|
self._path = path
|
||||||
|
|
||||||
def _font(self, size):
|
def _font(self, size):
|
||||||
return pygame.font.Font(self._path,size)
|
return pygame.font.Font(self._path, size)
|
||||||
def render(self, text, size, color, newLineSpace=5,
|
|
||||||
italic=False, bold=False, underline=False):
|
def render(
|
||||||
|
self,
|
||||||
|
text,
|
||||||
|
size,
|
||||||
|
color,
|
||||||
|
newLineSpace=5,
|
||||||
|
italic=False,
|
||||||
|
bold=False,
|
||||||
|
underline=False,
|
||||||
|
):
|
||||||
text = str(text)
|
text = str(text)
|
||||||
font = self._font(size)
|
font = self._font(size)
|
||||||
font.set_italic(italic)
|
font.set_italic(italic)
|
||||||
font.set_bold(bold)
|
font.set_bold(bold)
|
||||||
font.set_underline(underline)
|
font.set_underline(underline)
|
||||||
if text.replace('\n', '') != text:
|
if text.replace("\n", "") != text:
|
||||||
text = text.split('\n')
|
text = text.split("\n")
|
||||||
surf = pygame.Surface([font.size(max(text,key=lambda x:font.size(x)[0]))[0],
|
surf = pygame.Surface(
|
||||||
(font.size('123')[1]+newLineSpace)*len(text)],pygame.SRCALPHA)
|
[
|
||||||
|
font.size(max(text, key=lambda x: font.size(x)[0]))[0],
|
||||||
|
(font.size("123")[1] + newLineSpace) * len(text),
|
||||||
|
],
|
||||||
|
pygame.SRCALPHA,
|
||||||
|
)
|
||||||
y = 0
|
y = 0
|
||||||
for i in text:
|
for i in text:
|
||||||
r = font.render(i, True, color)
|
r = font.render(i, True, color)
|
||||||
|
@ -26,18 +42,27 @@ class font:
|
||||||
y += newLineSpace
|
y += newLineSpace
|
||||||
else:
|
else:
|
||||||
surf = font.render(text, True, color)
|
surf = font.render(text, True, color)
|
||||||
surface = surface(surf.get_size())
|
surface2 = surface(surf.get_size())
|
||||||
surface._surface_orig = surf
|
surface2._surface_orig = surf
|
||||||
return surface
|
return surface2
|
||||||
def size(self, text, size, newLineSpace=5,
|
|
||||||
italic=False,bold=False,underline=False):
|
def size(
|
||||||
return self.render(text, size, (255,255,255),
|
self, text, size, newLineSpace=5, italic=False, bold=False, underline=False
|
||||||
newLineSpace=newLineSpace,
|
):
|
||||||
italic=italic, bold=bold,
|
return self.render(
|
||||||
underline=underline).size
|
text,
|
||||||
|
size,
|
||||||
|
(255, 255, 255),
|
||||||
|
newLineSpace=newLineSpace,
|
||||||
|
italic=italic,
|
||||||
|
bold=bold,
|
||||||
|
underline=underline,
|
||||||
|
).size
|
||||||
|
|
||||||
|
|
||||||
class sysFont(font):
|
class sysFont(font):
|
||||||
def __init__(self, name):
|
def __init__(self, name):
|
||||||
self._path = pygame.font.match_font(name)
|
self._path = pygame.font.match_font(name)
|
||||||
|
|
||||||
|
|
||||||
defaultFont = font(pygame.font.get_default_font())
|
defaultFont = font(pygame.font.get_default_font())
|
||||||
|
|
|
@ -3,111 +3,121 @@ import threading as _threading
|
||||||
|
|
||||||
class gamepad:
|
class gamepad:
|
||||||
def __init__(self, pygame):
|
def __init__(self, pygame):
|
||||||
self._lasty = ''
|
self._lasty = ""
|
||||||
self._lastx = ''
|
self._lastx = ""
|
||||||
self.founded = False
|
self.founded = False
|
||||||
self._buttons = {'left-joystick': False,
|
self._buttons = {
|
||||||
'right-joystick': False,
|
"left-joystick": False,
|
||||||
'north': False,
|
"right-joystick": False,
|
||||||
'south': False,
|
"north": False,
|
||||||
'west': False,
|
"south": False,
|
||||||
'east': False,
|
"west": False,
|
||||||
'l1': False,
|
"east": False,
|
||||||
'l2': False,
|
"l1": False,
|
||||||
'r1': False,
|
"l2": False,
|
||||||
'r2': False,
|
"r1": False,
|
||||||
'up': False,
|
"r2": False,
|
||||||
'down': False,
|
"up": False,
|
||||||
'left': False,
|
"down": False,
|
||||||
'right': False,
|
"left": False,
|
||||||
'start': False,
|
"right": False,
|
||||||
'select': False}
|
"start": False,
|
||||||
|
"select": False,
|
||||||
|
}
|
||||||
self.leftJoystick = [0, 0]
|
self.leftJoystick = [0, 0]
|
||||||
self.rightJoystick = [0, 0]
|
self.rightJoystick = [0, 0]
|
||||||
self._pygame = pygame
|
self._pygame = pygame
|
||||||
self._start()
|
self._start()
|
||||||
|
|
||||||
def _tick(self):
|
def _tick(self):
|
||||||
try:
|
try:
|
||||||
events = _inputs.get_gamepad()
|
events = _inputs.get_gamepad()
|
||||||
except:
|
except Exception as _:
|
||||||
return
|
return
|
||||||
if not self._pygame.display.get_active():
|
if not self._pygame.display.get_active():
|
||||||
return
|
return
|
||||||
self.founded = True
|
self.founded = True
|
||||||
if events:
|
if events:
|
||||||
for event in events:
|
for event in events:
|
||||||
if event.code == 'ABS_X':
|
if event.code == "ABS_X":
|
||||||
self.leftJoystick[0] = event.state
|
self.leftJoystick[0] = event.state
|
||||||
elif event.code == 'ABS_Y':
|
elif event.code == "ABS_Y":
|
||||||
self.leftJoystick[1] = event.state
|
self.leftJoystick[1] = event.state
|
||||||
elif event.code == 'ABS_RY':
|
elif event.code == "ABS_RY":
|
||||||
self.rightJoystick[1] = event.state
|
self.rightJoystick[1] = event.state
|
||||||
elif event.code == 'ABS_RX':
|
elif event.code == "ABS_RX":
|
||||||
self.rightJoystick[0] = event.state
|
self.rightJoystick[0] = event.state
|
||||||
elif event.code == 'BTN_THUMBL':
|
elif event.code == "BTN_THUMBL":
|
||||||
self._buttons['left-joystick'] = event.state
|
self._buttons["left-joystick"] = event.state
|
||||||
elif event.code == 'BTN_THUMBR':
|
elif event.code == "BTN_THUMBR":
|
||||||
self._buttons['right-joystick'] = event.state
|
self._buttons["right-joystick"] = event.state
|
||||||
elif event.code == 'BTN_TL':
|
elif event.code == "BTN_TL":
|
||||||
self._buttons['l1'] = event.state
|
self._buttons["l1"] = event.state
|
||||||
elif event.code == 'BTN_TR':
|
elif event.code == "BTN_TR":
|
||||||
self._buttons['r1'] = event.state
|
self._buttons["r1"] = event.state
|
||||||
elif event.code == 'ABS_Z':
|
elif event.code == "ABS_Z":
|
||||||
if event.state == 255:
|
if event.state == 255:
|
||||||
self._buttons['l2'] = 1
|
self._buttons["l2"] = 1
|
||||||
elif event.state == 0:
|
elif event.state == 0:
|
||||||
self._buttons['l2'] = 0
|
self._buttons["l2"] = 0
|
||||||
elif event.code == 'ABS_RZ':
|
elif event.code == "ABS_RZ":
|
||||||
if event.state == 255:
|
if event.state == 255:
|
||||||
self._buttons['r2'] = 1
|
self._buttons["r2"] = 1
|
||||||
elif event.state == 0:
|
elif event.state == 0:
|
||||||
self._buttons['r2'] = 0
|
self._buttons["r2"] = 0
|
||||||
elif event.code == 'BTN_WEST':
|
elif event.code == "BTN_WEST":
|
||||||
self._buttons['west'] = event.state
|
self._buttons["west"] = event.state
|
||||||
elif event.code == 'BTN_NORTH':
|
elif event.code == "BTN_NORTH":
|
||||||
self._buttons['north'] = event.state
|
self._buttons["north"] = event.state
|
||||||
elif event.code == 'BTN_EAST':
|
elif event.code == "BTN_EAST":
|
||||||
self._buttons['east'] = event.state
|
self._buttons["east"] = event.state
|
||||||
elif event.code == 'BTN_SOUTH':
|
elif event.code == "BTN_SOUTH":
|
||||||
self._buttons['south'] = event.state
|
self._buttons["south"] = event.state
|
||||||
elif event.code == 'ABS_HAT0Y':
|
elif event.code == "ABS_HAT0Y":
|
||||||
if event.state == 1:
|
if event.state == 1:
|
||||||
self._buttons['down'] = True
|
self._buttons["down"] = True
|
||||||
self._lasty = 'down'
|
self._lasty = "down"
|
||||||
elif event.state == -1:
|
elif event.state == -1:
|
||||||
self._buttons['up'] = True
|
self._buttons["up"] = True
|
||||||
self._lasty = 'up'
|
self._lasty = "up"
|
||||||
else:
|
else:
|
||||||
self._buttons[self._lasty] = False
|
self._buttons[self._lasty] = False
|
||||||
elif event.code == 'ABS_HAT0X':
|
elif event.code == "ABS_HAT0X":
|
||||||
if event.state == 1:
|
if event.state == 1:
|
||||||
self._buttons['right'] = True
|
self._buttons["right"] = True
|
||||||
self._lastx = 'right'
|
self._lastx = "right"
|
||||||
elif event.state == -1:
|
elif event.state == -1:
|
||||||
self._buttons['left'] = True
|
self._buttons["left"] = True
|
||||||
self._lastx = 'left'
|
self._lastx = "left"
|
||||||
else:
|
else:
|
||||||
self._buttons[self._lastx] = False
|
self._buttons[self._lastx] = False
|
||||||
elif event.code == 'BTN_START':
|
elif event.code == "BTN_START":
|
||||||
self._buttons['select'] = event.state
|
self._buttons["select"] = event.state
|
||||||
elif event.code == 'BTN_SELECT':
|
elif event.code == "BTN_SELECT":
|
||||||
self._buttons['start'] = event.state
|
self._buttons["start"] = event.state
|
||||||
|
|
||||||
def _start(self):
|
def _start(self):
|
||||||
self.founded = False
|
self.founded = False
|
||||||
self._started = True
|
self._started = True
|
||||||
|
|
||||||
def ttcb(self):
|
def ttcb(self):
|
||||||
while self._started:
|
while self._started:
|
||||||
self._tick()
|
self._tick()
|
||||||
_threading.Thread(target=lambda:ttcb(self),daemon=True).start()
|
|
||||||
|
_threading.Thread(target=lambda: ttcb(self), daemon=True).start()
|
||||||
|
|
||||||
def close(self):
|
def close(self):
|
||||||
self._started = False
|
self._started = False
|
||||||
|
|
||||||
def isPressed(self, btn):
|
def isPressed(self, btn):
|
||||||
return btn in self._buttons
|
return btn in self._buttons
|
||||||
|
|
||||||
def reset(self):
|
def reset(self):
|
||||||
self._lasty = ''
|
self._lasty = ""
|
||||||
self._lastx = ''
|
self._lastx = ""
|
||||||
self._buttons = []
|
self._buttons = []
|
||||||
self.leftJoystick = [0, 0]
|
self.leftJoystick = [0, 0]
|
||||||
self.rightJoystick = [0, 0]
|
self.rightJoystick = [0, 0]
|
||||||
|
|
||||||
def getPressed(self):
|
def getPressed(self):
|
||||||
return self._buttons
|
return self._buttons
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
import .pygame
|
from . import pygame
|
||||||
from .surface import surface
|
from .surface import surface
|
||||||
from PIL import Image
|
from PIL import Image
|
||||||
import tempfile
|
import tempfile
|
||||||
|
@ -6,37 +6,45 @@ import pickle
|
||||||
import bz2
|
import bz2
|
||||||
import os
|
import os
|
||||||
|
|
||||||
|
|
||||||
def load(path):
|
def load(path):
|
||||||
if path.endswith('.gif'):
|
if path.endswith(".gif"):
|
||||||
im = Image.open(path)
|
im = Image.open(path)
|
||||||
with tempfile.TemporaryDirectory() as td:
|
with tempfile.TemporaryDirectory() as td:
|
||||||
surfs = []
|
surfs = []
|
||||||
for i in range(im.n_frames):
|
for i in range(im.n_frames):
|
||||||
im.seek(i)
|
im.seek(i)
|
||||||
p = os.path.join(td,f'{i}.png')
|
p = os.path.join(td, f"{i}.png")
|
||||||
im.save(p)
|
im.save(p)
|
||||||
s = pygame.image.load(p)
|
s = pygame.image.load(p)
|
||||||
os.remove(p)
|
os.remove(p)
|
||||||
sg = surface(s.get_size())
|
sg = surface(s.get_size())
|
||||||
sg.blit(s,(0,0))
|
sg.blit(s, (0, 0))
|
||||||
surfs.append(sg)
|
surfs.append(sg)
|
||||||
return surfs
|
return surfs
|
||||||
else:
|
else:
|
||||||
im = Image.open(path.encode('utf8').decode('utf8'))
|
im = Image.open(path.encode("utf8").decode("utf8"))
|
||||||
image = pygame.image.fromstring(im.tobytes(),im.size,im.mode)
|
image = pygame.image.fromstring(im.tobytes(), im.size, im.mode)
|
||||||
surf = surface(im.size)
|
surf = surface(im.size)
|
||||||
surf.blit(image,(0,0))
|
surf.blit(image, (0, 0))
|
||||||
return surf
|
return surf
|
||||||
|
|
||||||
def save(surface, dest):
|
|
||||||
pygame.image.save_extended(surface._grp(), dest)
|
|
||||||
|
|
||||||
def toBytes(surface):
|
def save(surf, dest):
|
||||||
return bz2.compress(pickle.dumps([pygame.image.tostring(surface._grp(),"RGBA"),list(surface.size)]))
|
pygame.image.save_extended(surf._grp(), dest)
|
||||||
|
|
||||||
|
|
||||||
|
def toBytes(surf):
|
||||||
|
return bz2.compress(
|
||||||
|
pickle.dumps(
|
||||||
|
[pygame.image.tostring(surf._grp(), "RGBA"), list(surf.size)]
|
||||||
|
)
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
def fromBytes(bytes):
|
def fromBytes(bytes):
|
||||||
string = pickle.loads(bz2.decompress(bytes))
|
string = pickle.loads(bz2.decompress(bytes))
|
||||||
surf = pygame.image.fromstring(string[0],tuple(string[1]),"RGBA")
|
surf = pygame.image.fromstring(string[0], tuple(string[1]), "RGBA")
|
||||||
surface = surface(tuple(string[1]))
|
surface2 = surface(tuple(string[1]))
|
||||||
surface.blit(surf,(0,0))
|
surface2.blit(surf, (0, 0))
|
||||||
return surface
|
return surface2
|
||||||
|
|
|
@ -1,22 +1,13 @@
|
||||||
import .pygame
|
from . import pygame
|
||||||
|
|
||||||
|
|
||||||
def getPressed():
|
def getPressed():
|
||||||
fkeys = {}
|
fkeys = {}
|
||||||
keys = pygame.key.get_pressed()
|
keys = pygame.key.get_pressed()
|
||||||
for i in range(len(keys)):
|
for i in range(len(keys)):
|
||||||
fkeys.update({pygame.key.name(i):keys[i]})
|
fkeys.update({pygame.key.name(i): keys[i]})
|
||||||
return fkeys
|
return fkeys
|
||||||
|
|
||||||
|
|
||||||
def isPressed(key):
|
def isPressed(key):
|
||||||
return getPressed()[key]
|
return getPressed()[key]
|
||||||
|
|
||||||
import inspect
|
|
||||||
|
|
||||||
_aliases = {'getPressed':['gprs','getkeys'],
|
|
||||||
'isPressed':['isprs','keyprs']}
|
|
||||||
|
|
||||||
for i in _aliases.items():
|
|
||||||
exec(f'args = inspect.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})")
|
|
||||||
|
|
|
@ -1,92 +1,122 @@
|
||||||
import .pygame
|
from . import pygame
|
||||||
import os
|
import os
|
||||||
import tempfile
|
import tempfile
|
||||||
|
|
||||||
ffmpeg = None
|
ffmpeg = None
|
||||||
|
|
||||||
|
|
||||||
class sound:
|
class sound:
|
||||||
def __init__(self, path):
|
def __init__(self, path):
|
||||||
if not (path.endswith('.wav') or path.endswith('.ogg')):
|
if not (path.endswith(".wav") or path.endswith(".ogg")):
|
||||||
try:
|
try:
|
||||||
from pydub import AudioSegment as as
|
from pydub import AudioSegment
|
||||||
if ffmpeg != None:
|
|
||||||
as.ffmpeg = ffmpeg
|
if ffmpeg is not None:
|
||||||
as.converter = ffmpeg
|
AudioSegment.ffmpeg = ffmpeg
|
||||||
sound = as.from_file(path, os.path.splitext(path)[1])
|
AudioSegment.converter = ffmpeg
|
||||||
path = tempfile.mkstemp('.wav')
|
sound = AudioSegment.from_file(path, os.path.splitext(path)[1])
|
||||||
|
path = tempfile.mkstemp(".wav")
|
||||||
sound.export(path, format="wav")
|
sound.export(path, format="wav")
|
||||||
except:
|
except Exception as _:
|
||||||
print('Set ffmpeg to path so that you don'+\
|
print(
|
||||||
"'t have to convert the file to "+\
|
"Set ffmpeg to path so that you don"
|
||||||
'".wav". If you have installed, but the error still appears, write down the path to ffmpeg.exe in plugin.ffmpeg.')
|
+ "'t have to convert the file to "
|
||||||
|
+ '".wav". If you have installed, but the error still appears, write down the path to ffmpeg.exe in plugin.ffmpeg.'
|
||||||
|
)
|
||||||
self._sound = pygame.mixer.Sound(path)
|
self._sound = pygame.mixer.Sound(path)
|
||||||
|
|
||||||
def play(self):
|
def play(self):
|
||||||
self._sound.play()
|
self._sound.play()
|
||||||
|
|
||||||
def stop(self):
|
def stop(self):
|
||||||
self._sound.stop()
|
self._sound.stop()
|
||||||
|
|
||||||
def volume():
|
def volume():
|
||||||
def fget(self):
|
def fget(self):
|
||||||
return self._sound.get_volume()
|
return self._sound.get_volume()
|
||||||
|
|
||||||
def fset(self, value):
|
def fset(self, value):
|
||||||
if type(value) == int:
|
if type(value) is int:
|
||||||
self._sound.set_volume(value)
|
self._sound.set_volume(value)
|
||||||
|
|
||||||
def fdel(self):
|
def fdel(self):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
return locals()
|
return locals()
|
||||||
|
|
||||||
volume = property(**volume())
|
volume = property(**volume())
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def length(self):
|
def length(self):
|
||||||
return self._sound.get_length()
|
return self._sound.get_length()
|
||||||
|
|
||||||
|
|
||||||
class music:
|
class music:
|
||||||
def __init__(self, path):
|
def __init__(self, path):
|
||||||
if path.endswith('.wav') or path.endswith('.ogg'):
|
if path.endswith(".wav") or path.endswith(".ogg"):
|
||||||
self._path = path
|
self._path = path
|
||||||
else:
|
else:
|
||||||
try:
|
try:
|
||||||
from pydub import AudioSegment as as
|
from pydub import AudioSegment
|
||||||
if ffmpeg != None:
|
|
||||||
as.ffmpeg = ffmpeg
|
if ffmpeg is not None:
|
||||||
as.converter = ffmpeg
|
AudioSegment.ffmpeg = ffmpeg
|
||||||
sound = as.from_file(path, os.path.splitext(path)[1])
|
AudioSegment.converter = ffmpeg
|
||||||
path = tempfile.mkstemp('.wav')
|
sound = AudioSegment.from_file(path, os.path.splitext(path)[1])
|
||||||
|
path = tempfile.mkstemp(".wav")
|
||||||
sound.export(path, format="wav")
|
sound.export(path, format="wav")
|
||||||
except:
|
except Exception as _:
|
||||||
print('Set ffmpeg to path so that you don'+\
|
print(
|
||||||
"'t have to convert the file to "+\
|
"Set ffmpeg to path so that you don"
|
||||||
'".wav". If you have installed, but the error still appears, write down the path to ffmpeg.exe in plugin.ffmpeg.')
|
+ "'t have to convert the file to "
|
||||||
|
+ '".wav". If you have installed, but the error still appears, write down the path to ffmpeg.exe in plugin.ffmpeg.'
|
||||||
|
)
|
||||||
pygame.mixer.music.load(path)
|
pygame.mixer.music.load(path)
|
||||||
|
|
||||||
def play(self, loops=0):
|
def play(self, loops=0):
|
||||||
pygame.mixer.music.play(loops)
|
pygame.mixer.music.play(loops)
|
||||||
|
|
||||||
def stop(self):
|
def stop(self):
|
||||||
pygame.mixer.music.stop()
|
pygame.mixer.music.stop()
|
||||||
|
|
||||||
def restart(self):
|
def restart(self):
|
||||||
pygame.mixer.music.rewind()
|
pygame.mixer.music.rewind()
|
||||||
|
|
||||||
def pause(self):
|
def pause(self):
|
||||||
pygame.mixer.music.pause()
|
pygame.mixer.music.pause()
|
||||||
|
|
||||||
def release(self):
|
def release(self):
|
||||||
pygame.mixer.music.unpause()
|
pygame.mixer.music.unpause()
|
||||||
|
|
||||||
def queue(self):
|
def queue(self):
|
||||||
pygame.mixer.music.queue(self._path)
|
pygame.mixer.music.queue(self._path)
|
||||||
|
|
||||||
def volume():
|
def volume():
|
||||||
def fget(self):
|
def fget(self):
|
||||||
return pygame.mixer.music.get_volume()
|
return pygame.mixer.music.get_volume()
|
||||||
|
|
||||||
def fset(self, value):
|
def fset(self, value):
|
||||||
if type(value) == int:
|
if type(value) is int:
|
||||||
pygame.mixer.music.set_volume(value)
|
pygame.mixer.music.set_volume(value)
|
||||||
|
|
||||||
def fdel(self):
|
def fdel(self):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
return locals()
|
return locals()
|
||||||
|
|
||||||
volume = property(**volume())
|
volume = property(**volume())
|
||||||
|
|
||||||
def pos():
|
def pos():
|
||||||
def fget(self):
|
def fget(self):
|
||||||
return pygame.mixer.music.get_pos()
|
return pygame.mixer.music.get_pos()
|
||||||
|
|
||||||
def fset(self, value):
|
def fset(self, value):
|
||||||
if type(value) == int:
|
if type(value) is int:
|
||||||
pygame.mixer.music.set_pos(value)
|
pygame.mixer.music.set_pos(value)
|
||||||
|
|
||||||
def fdel(self):
|
def fdel(self):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
return locals()
|
return locals()
|
||||||
|
|
||||||
pos = property(**pos())
|
pos = property(**pos())
|
||||||
|
|
|
@ -1,35 +1,37 @@
|
||||||
import .pygame
|
from . import pygame
|
||||||
import inspect
|
|
||||||
|
|
||||||
def getPressed():
|
def getPressed():
|
||||||
orig = pygame.mouse.get_pressed(3)
|
orig = pygame.mouse.get_pressed(3)
|
||||||
return {'left':orig[0],'middle':orig[1],'right':orig[2]}
|
return {"left": orig[0], "middle": orig[1], "right": orig[2]}
|
||||||
|
|
||||||
|
|
||||||
def isPressed(x):
|
def isPressed(x):
|
||||||
return getPressed()[x.lower()]
|
return getPressed()[x.lower()]
|
||||||
|
|
||||||
|
|
||||||
def setPosition(x):
|
def setPosition(x):
|
||||||
pygame.mouse.set_pos(x)
|
pygame.mouse.set_pos(x)
|
||||||
|
|
||||||
|
|
||||||
def getPosition():
|
def getPosition():
|
||||||
return pygame.mouse.get_pos()
|
return pygame.mouse.get_pos()
|
||||||
|
|
||||||
|
|
||||||
def setVisible(x):
|
def setVisible(x):
|
||||||
pygame.mouse.set_visible(x)
|
pygame.mouse.set_visible(x)
|
||||||
|
|
||||||
|
|
||||||
def getVisible():
|
def getVisible():
|
||||||
return pygame.mouse.get_visible()
|
return pygame.mouse.get_visible()
|
||||||
|
|
||||||
|
|
||||||
def getCursor():
|
def getCursor():
|
||||||
return pygame.mouse.get_cursor()
|
return pygame.mouse.get_cursor()
|
||||||
|
|
||||||
|
|
||||||
def setCursor(size, hotspot=None, xormasks=None, andmasks=None):
|
def setCursor(size, hotspot=None, xormasks=None, andmasks=None):
|
||||||
if hotspot == None and xormasks == None and andmasks == None:
|
if hotspot is None and xormasks is None and andmasks is None:
|
||||||
pygame.mouse.set_system_cursor(size)
|
pygame.mouse.set_system_cursor(size)
|
||||||
else:
|
else:
|
||||||
pygame.mouse.set_cursor(size, hotspot, xormasks, andmasks)
|
pygame.mouse.set_cursor(size, hotspot, xormasks, andmasks)
|
||||||
|
|
||||||
_aliases = {'getPressed':['gprs','getbtns'],
|
|
||||||
'isPressed':['isprs','btnprs'],
|
|
||||||
'setPosition':['spos','setpos','move'],
|
|
||||||
'getPosition':['gpos','getpos']}
|
|
||||||
|
|
||||||
for i in _aliases.items():
|
|
||||||
exec(f'args = inspect.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})")
|
|
||||||
|
|
|
@ -2,6 +2,7 @@ from contextlib import contextmanager
|
||||||
import os
|
import os
|
||||||
import sys
|
import sys
|
||||||
|
|
||||||
|
|
||||||
@contextmanager
|
@contextmanager
|
||||||
def suppress_stdout():
|
def suppress_stdout():
|
||||||
with open(os.devnull, "w") as devnull:
|
with open(os.devnull, "w") as devnull:
|
||||||
|
@ -11,7 +12,9 @@ def suppress_stdout():
|
||||||
yield
|
yield
|
||||||
finally:
|
finally:
|
||||||
sys.stdout = old_stdout
|
sys.stdout = old_stdout
|
||||||
|
|
||||||
|
|
||||||
with suppress_stdout():
|
with suppress_stdout():
|
||||||
from pygame import *
|
from pygame import *
|
||||||
|
|
||||||
init()
|
init()
|
||||||
|
|
|
@ -1,24 +1,23 @@
|
||||||
from contextlib import contextmanager
|
from contextlib import contextmanager
|
||||||
import .pygame
|
from . import pygame
|
||||||
import moviepy.editor as mpe
|
import moviepy.editor as mpe
|
||||||
from array import array
|
from array import array
|
||||||
from PIL import Image
|
|
||||||
import numpy
|
import numpy
|
||||||
import threading
|
import threading
|
||||||
import pyautogui
|
|
||||||
import tempfile
|
import tempfile
|
||||||
import pyaudio
|
import pyaudio
|
||||||
import wave
|
import wave
|
||||||
import time
|
|
||||||
import sys
|
import sys
|
||||||
import cv2
|
import cv2
|
||||||
import os
|
import os
|
||||||
|
|
||||||
|
|
||||||
class record:
|
class record:
|
||||||
def __init__(self,win,audio=False):
|
def __init__(self, win, audio=False):
|
||||||
self._isaudio = audio
|
self._isaudio = audio
|
||||||
self._surface = win
|
self._surface = win
|
||||||
self.reset()
|
self.reset()
|
||||||
|
|
||||||
def reset(self):
|
def reset(self):
|
||||||
self._run = False
|
self._run = False
|
||||||
self._fpss = []
|
self._fpss = []
|
||||||
|
@ -27,57 +26,69 @@ class record:
|
||||||
if self._isaudio:
|
if self._isaudio:
|
||||||
self._apy = pyaudio.PyAudio()
|
self._apy = pyaudio.PyAudio()
|
||||||
self._aframs = []
|
self._aframs = []
|
||||||
self._astrm = self.apy.open(format=pyaudio.paInt16,channels=1,
|
self._astrm = self.apy.open(
|
||||||
rate=44100,input=True,frames_per_buffer=1024)
|
format=pyaudio.paInt16,
|
||||||
def start(self,newThread=True):
|
channels=1,
|
||||||
|
rate=44100,
|
||||||
|
input=True,
|
||||||
|
frames_per_buffer=1024,
|
||||||
|
)
|
||||||
|
|
||||||
|
def start(self, newThread=True):
|
||||||
self._run = True
|
self._run = True
|
||||||
if self._isaudio:
|
if self._isaudio:
|
||||||
|
|
||||||
def audiot(self):
|
def audiot(self):
|
||||||
while self._run:
|
while self._run:
|
||||||
self._aframs.append(self.astrm.read(1024))
|
self._aframs.append(self.astrm.read(1024))
|
||||||
self._athread = threading.Thread(target=lambda:audiot(self))
|
|
||||||
|
self._athread = threading.Thread(target=lambda: audiot(self))
|
||||||
self._athread.start()
|
self._athread.start()
|
||||||
|
|
||||||
def main(self):
|
def main(self):
|
||||||
while self.run:
|
while self.run:
|
||||||
self._record()
|
self._record()
|
||||||
|
|
||||||
if newThread:
|
if newThread:
|
||||||
self._thread = threading.Thread(target=lambda:main(self))
|
self._thread = threading.Thread(target=lambda: main(self))
|
||||||
self._thread.start()
|
self._thread.start()
|
||||||
else:main()
|
else:
|
||||||
|
main()
|
||||||
|
|
||||||
def _record(self):
|
def _record(self):
|
||||||
if self._run:
|
if self._run:
|
||||||
try:
|
try:
|
||||||
self._frames.append(self._surface)
|
self._frames.append(self._surface)
|
||||||
self._fpss.append(self._surface.rawFps)
|
self._fpss.append(self._surface.rawFps)
|
||||||
except:
|
except Exception as _:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
def render(self, path):
|
def render(self, path):
|
||||||
temp = tempfile.gettempdir()
|
temp = tempfile.gettempdir()
|
||||||
if self.isaudio:
|
if self.isaudio:
|
||||||
wavpath = os.path.join(temp, 'audio.wav')
|
wavpath = os.path.join(temp, "audio.wav")
|
||||||
wavfile = wave.open(wavpath, 'wb')
|
wavfile = wave.open(wavpath, "wb")
|
||||||
wavfile.setnchannels(1)
|
wavfile.setnchannels(1)
|
||||||
wavfile.setsampwidth(self._apy.get_sample_size(pyaudio.paInt16))
|
wavfile.setsampwidth(self._apy.get_sample_size(pyaudio.paInt16))
|
||||||
wavfile.setframerate(44100)
|
wavfile.setframerate(44100)
|
||||||
af = []
|
af = []
|
||||||
for i in self._aframs:
|
for i in self._aframs:
|
||||||
af.append(array('h',i))
|
af.append(array("h", i))
|
||||||
wavfile.writeframes(b''.join(af))
|
wavfile.writeframes(b"".join(af))
|
||||||
wavfile.close()
|
wavfile.close()
|
||||||
|
|
||||||
fps = 0
|
fps = 0
|
||||||
for i in self._fpss:
|
for i in self._fpss:
|
||||||
fps += i
|
fps += i
|
||||||
fps = fps/len(self._fpss)
|
fps = fps / len(self._fpss)
|
||||||
if self._isaudio:
|
if self._isaudio:
|
||||||
noaudiopath = os.path.join(temp, 'noaudio.mp4')
|
noaudiopath = os.path.join(temp, "noaudio.mp4")
|
||||||
else:
|
else:
|
||||||
noaudiopath = path
|
noaudiopath = path
|
||||||
out = cv2.VideoWriter(noaudiopath,self._codec,
|
out = cv2.VideoWriter(noaudiopath, self._codec, fps, self._surface.size)
|
||||||
fps,self._surface.size)
|
|
||||||
for i in self._frames:
|
for i in self._frames:
|
||||||
frame = numpy.array(pygame.surfarray.array3d(i).swapaxes(0,1))
|
frame = numpy.array(pygame.surfarray.array3d(i).swapaxes(0, 1))
|
||||||
frame = cv2.cvtColor(frame,cv2.COLOR_BGR2RGB)
|
frame = cv2.cvtColor(frame, cv2.COLOR_BGR2RGB)
|
||||||
out.write(frame)
|
out.write(frame)
|
||||||
out.release()
|
out.release()
|
||||||
|
|
||||||
|
@ -86,22 +97,27 @@ class record:
|
||||||
audioclip = mpe.AudioFileClip(wavpath)
|
audioclip = mpe.AudioFileClip(wavpath)
|
||||||
new_audioclip = mpe.CompositeAudioClip([audioclip])
|
new_audioclip = mpe.CompositeAudioClip([audioclip])
|
||||||
videoclip.audio = new_audioclip
|
videoclip.audio = new_audioclip
|
||||||
|
|
||||||
@contextmanager
|
@contextmanager
|
||||||
def ss():
|
def ss():
|
||||||
with open(os.devnull, "w") as devnull:
|
with open(os.devnull, "w") as devnull:
|
||||||
oso = sys.stdout
|
oso = sys.stdout
|
||||||
sys.stdout = devnull
|
sys.stdout = devnull
|
||||||
try:yield
|
try:
|
||||||
finally:sys.stdout=oso
|
yield
|
||||||
|
finally:
|
||||||
|
sys.stdout = oso
|
||||||
|
|
||||||
with ss():
|
with ss():
|
||||||
videoclip.write_videofile(path)
|
videoclip.write_videofile(path)
|
||||||
os.remove(noaudiopath)
|
os.remove(noaudiopath)
|
||||||
os.remove(wavpath)
|
os.remove(wavpath)
|
||||||
|
|
||||||
def stop(self):
|
def stop(self):
|
||||||
self._run = False
|
self._run = False
|
||||||
try:
|
try:
|
||||||
self._thread.join()
|
self._thread.join()
|
||||||
except:
|
except Exception as _:
|
||||||
pass
|
pass
|
||||||
if self._isaudio:
|
if self._isaudio:
|
||||||
self._athread.join()
|
self._athread.join()
|
||||||
|
|
|
@ -1,38 +1,55 @@
|
||||||
import .pygame
|
from . import pygame
|
||||||
|
|
||||||
|
_aliases = {
|
||||||
|
"w": ["width"],
|
||||||
|
"h": ["height"],
|
||||||
|
"c": ["center", "middle"],
|
||||||
|
"x": ["left"],
|
||||||
|
"y": ["up"],
|
||||||
|
"r": ["right"],
|
||||||
|
"d": ["down"],
|
||||||
|
}
|
||||||
|
|
||||||
_aliases = {'w':['width'],'h':['height'],
|
|
||||||
'c':['center','middle'],
|
|
||||||
'x':['left'],'y':['up'],
|
|
||||||
'r':['right'],'d':['down']}
|
|
||||||
|
|
||||||
class rect:
|
class rect:
|
||||||
def __init__(self,x,y,w,h):
|
def __init__(self, x, y, w, h):
|
||||||
self.x = x
|
self.x = x
|
||||||
self.y = y
|
self.y = y
|
||||||
self.w = w
|
self.w = w
|
||||||
self.h = h
|
self.h = h
|
||||||
self._reload()
|
self._reload()
|
||||||
|
|
||||||
def collide(self, x):
|
def collide(self, x):
|
||||||
try:return self._rect.colliderect(x._rect_rect)
|
try:
|
||||||
except:return self._rect.colliderect(x._rect)
|
return self._rect.colliderect(x._rect_rect)
|
||||||
|
except Exception as _:
|
||||||
|
return self._rect.colliderect(x._rect)
|
||||||
|
|
||||||
def contains(self, x, y):
|
def contains(self, x, y):
|
||||||
return self._rect.collidepoint(x,y)
|
return self._rect.collidepoint(x, y)
|
||||||
|
|
||||||
def copy(self):
|
def copy(self):
|
||||||
return rect(self.x,self.y,self.w,self.h)
|
return rect(self.x, self.y, self.w, self.h)
|
||||||
|
|
||||||
def _reload(self):
|
def _reload(self):
|
||||||
self.c = (self.x/2+self.w/2,self.y/2+self.h/2)
|
self.c = (self.x / 2 + self.w / 2, self.y / 2 + self.h / 2)
|
||||||
self.cx, self.cy = self.c
|
self.cx, self.cy = self.c
|
||||||
self.r,self.d = self.x+self.w,self.y+self.h
|
self.r, self.d = self.x + self.w, self.y + self.h
|
||||||
self._rect = pygame.Rect(self.x,self.y,self.w,self.h)
|
self._rect = pygame.Rect(self.x, self.y, self.w, self.h)
|
||||||
def __getitem__(self,x):
|
|
||||||
return [self.x,self.y,self.w,self.h][x]
|
def __getitem__(self, x):
|
||||||
|
return [self.x, self.y, self.w, self.h][x]
|
||||||
|
|
||||||
def __list__(self):
|
def __list__(self):
|
||||||
return [self.x,self.y,self.w,self.h]
|
return [self.x, self.y, self.w, self.h]
|
||||||
|
|
||||||
def __tuple__(self):
|
def __tuple__(self):
|
||||||
return (self.x,self.y,self.w,self.h)
|
return (self.x, self.y, self.w, self.h)
|
||||||
|
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
return f'<{self.x}x{self.y},{self.w}x{self.h}>'
|
return f"<{self.x}x{self.y},{self.w}x{self.h}>"
|
||||||
def __setattr__(self,attr,data):
|
|
||||||
|
def __setattr__(self, attr, data):
|
||||||
if attr in _aliases.values():
|
if attr in _aliases.values():
|
||||||
ma = None
|
ma = None
|
||||||
for i in _aliases.items():
|
for i in _aliases.items():
|
||||||
|
@ -40,8 +57,9 @@ class rect:
|
||||||
ma = i[0]
|
ma = i[0]
|
||||||
break
|
break
|
||||||
attr = ma
|
attr = ma
|
||||||
object.__setattr__(self,attr,data)
|
object.__setattr__(self, attr, data)
|
||||||
def __getattr__(self,attr):
|
|
||||||
|
def __getattr__(self, attr):
|
||||||
if attr in _aliases.values():
|
if attr in _aliases.values():
|
||||||
ma = None
|
ma = None
|
||||||
for i in _aliases.items():
|
for i in _aliases.items():
|
||||||
|
|
|
@ -1,60 +1,76 @@
|
||||||
from .rect import rect
|
from .rect import rect
|
||||||
from .color import color
|
from .color import color
|
||||||
import .pygame
|
from . import pygame
|
||||||
|
|
||||||
|
|
||||||
class surface:
|
class surface:
|
||||||
def __init__(self, size):
|
def __init__(self, size):
|
||||||
self._size = size
|
self._size = size
|
||||||
self._orig = pygame.Surface(size, pygame.SRCALPHA)
|
self._orig = pygame.Surface(size, pygame.SRCALPHA)
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def pixels(self):
|
def pixels(self):
|
||||||
pixels = []
|
pixels = []
|
||||||
for x in range(self.size[0]):
|
for x in range(self.size[0]):
|
||||||
pixels.append([])
|
pixels.append([])
|
||||||
for y in range(self.size[1]):
|
for y in range(self.size[1]):
|
||||||
pixels[x].append(self.getPixel(x,y))
|
pixels[x].append(self.getPixel(x, y))
|
||||||
return pixels
|
return pixels
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def size(self):
|
def size(self):
|
||||||
return self._size
|
return self._size
|
||||||
|
|
||||||
def _grp(self):
|
def _grp(self):
|
||||||
return self._orig
|
return self._orig
|
||||||
|
|
||||||
def rect(self, x=0, y=0, center=[]):
|
def rect(self, x=0, y=0, center=[]):
|
||||||
if center == []:
|
if center == []:
|
||||||
return rect(x, y, self.size[0], self.size[1])
|
return rect(x, y, self.size[0], self.size[1])
|
||||||
else:
|
else:
|
||||||
return rect(center[0]-(self.size[0]/2),
|
return rect(
|
||||||
center[1]-(self.size[1]/2),
|
center[0] - (self.size[0] / 2),
|
||||||
self.size[0], self.size[1])
|
center[1] - (self.size[1] / 2),
|
||||||
|
self.size[0],
|
||||||
|
self.size[1],
|
||||||
|
)
|
||||||
|
|
||||||
def copy(self):
|
def copy(self):
|
||||||
surf = surface(self._size)
|
surf = surface(self._size)
|
||||||
surf._surface_orig = self._orig
|
surf._surface_orig = self._orig
|
||||||
surf._surface_size = self._size
|
surf._surface_size = self._size
|
||||||
return surf
|
return surf
|
||||||
|
|
||||||
def getPixel(self, x, y):
|
def getPixel(self, x, y):
|
||||||
return color(*self._orig.get_at((x,y)))
|
return color(*self._orig.get_at((x, y)))
|
||||||
|
|
||||||
def setPixel(self, x, y, color):
|
def setPixel(self, x, y, color):
|
||||||
self._orig.set_at((x,y),color)
|
self._orig.set_at((x, y), color)
|
||||||
return self.copy()
|
return self.copy()
|
||||||
|
|
||||||
def blit(self, surf, xy):
|
def blit(self, surf, xy):
|
||||||
if type(surf) != surface and type(surf) != pygame.Surface:
|
if type(surf) is not surface and type(surf) is pygame.Surface:
|
||||||
from pygwin.font import defaultFont as _df
|
from pygwin.font import defaultFont as _df
|
||||||
surf = _df.render(surf, 25, (0,0,0))
|
|
||||||
|
surf = _df.render(surf, 25, (0, 0, 0))
|
||||||
try:
|
try:
|
||||||
self._orig.blit(surf._surface_orig, xy)
|
self._orig.blit(surf._surface_orig, xy)
|
||||||
except:
|
except Exception as _:
|
||||||
try:
|
try:
|
||||||
self._orig.blit(surf._orig, xy)
|
self._orig.blit(surf._orig, xy)
|
||||||
except:
|
except Exception as _:
|
||||||
self._orig.blit(surf, xy)
|
self._orig.blit(surf, xy)
|
||||||
return self.copy()
|
return self.copy()
|
||||||
|
|
||||||
def fill(self, color):
|
def fill(self, color):
|
||||||
self._orig.fill(list(color))
|
self._orig.fill(list(color))
|
||||||
return self.copy()
|
return self.copy()
|
||||||
|
|
||||||
def crop(self, rect):
|
def crop(self, rect):
|
||||||
self._orig = self._orig.subsurface(rect)
|
self._orig = self._orig.subsurface(rect)
|
||||||
self._size = self._orig.get_size()
|
self._size = self._orig.get_size()
|
||||||
return self.copy()
|
return self.copy()
|
||||||
|
|
||||||
def scale(self, size, smooth=False):
|
def scale(self, size, smooth=False):
|
||||||
if not smooth:
|
if not smooth:
|
||||||
self._orig = pygame.transform.scale(self._orig, size)
|
self._orig = pygame.transform.scale(self._orig, size)
|
||||||
|
@ -62,84 +78,129 @@ class surface:
|
||||||
self._orig = pygame.transform.smoothscale(self._orig, size)
|
self._orig = pygame.transform.smoothscale(self._orig, size)
|
||||||
self._size = self._orig.get_size()
|
self._size = self._orig.get_size()
|
||||||
return self.copy()
|
return self.copy()
|
||||||
|
|
||||||
def rotate(self, angle):
|
def rotate(self, angle):
|
||||||
self._orig = pygame.transform.rotate(self._orig, angle)
|
self._orig = pygame.transform.rotate(self._orig, angle)
|
||||||
self._size = self._orig.get_size()
|
self._size = self._orig.get_size()
|
||||||
return self.copy()
|
return self.copy()
|
||||||
|
|
||||||
def flip(self, x, y):
|
def flip(self, x, y):
|
||||||
self._orig = pygame.transform.flip(self._orig, x, y)
|
self._orig = pygame.transform.flip(self._orig, x, y)
|
||||||
return self.copy()
|
return self.copy()
|
||||||
|
|
||||||
def blur(self, amt):
|
def blur(self, amt):
|
||||||
if amt < 0:return self.copy()
|
if amt < 0:
|
||||||
scale = (int(self._orig.get_width()*(amt+1)),
|
return self.copy()
|
||||||
int(self._orig.get_height()*(amt+1)))
|
scale = (
|
||||||
|
int(self._orig.get_width() * (amt + 1)),
|
||||||
|
int(self._orig.get_height() * (amt + 1)),
|
||||||
|
)
|
||||||
size = self._orig.get_size()
|
size = self._orig.get_size()
|
||||||
self._orig = pygame.transform.smoothscale(self._orig,scale)
|
self._orig = pygame.transform.smoothscale(self._orig, scale)
|
||||||
self._orig = pygame.transform.smoothscale(self._orig,size)
|
self._orig = pygame.transform.smoothscale(self._orig, size)
|
||||||
return self.copy()
|
return self.copy()
|
||||||
|
|
||||||
class _draw:
|
class _draw:
|
||||||
def __init__(self,surface):
|
def __init__(self, surface):
|
||||||
self._surf = surface
|
self._surf = surface
|
||||||
def rect(self,color,rect,
|
|
||||||
width=0,borderRadius=0,
|
def rect(
|
||||||
borderTopLeftRadius=-1,
|
self,
|
||||||
borderTopRightRadius=-1,
|
color,
|
||||||
borderBottomLeftRadius=-1,
|
rect,
|
||||||
borderBottomRightRadius=-1):
|
width=0,
|
||||||
|
borderRadius=0,
|
||||||
|
borderTopLeftRadius=-1,
|
||||||
|
borderTopRightRadius=-1,
|
||||||
|
borderBottomLeftRadius=-1,
|
||||||
|
borderBottomRightRadius=-1,
|
||||||
|
):
|
||||||
try:
|
try:
|
||||||
orig = self._surf._surface_orig
|
orig = self._surf._surface_orig
|
||||||
except:
|
except Exception as _:
|
||||||
orig = self._surf._orig
|
orig = self._surf._orig
|
||||||
pygame.draw.rect(orig,color,pygame.Rect(rect[0],rect[1],rect[2],rect[3]),
|
pygame.draw.rect(
|
||||||
width,borderRadius,borderTopLeftRadius,borderTopRightRadius,
|
orig,
|
||||||
borderBottomLeftRadius,borderBottomRightRadius)
|
color,
|
||||||
|
pygame.Rect(rect[0], rect[1], rect[2], rect[3]),
|
||||||
|
width,
|
||||||
|
borderRadius,
|
||||||
|
borderTopLeftRadius,
|
||||||
|
borderTopRightRadius,
|
||||||
|
borderBottomLeftRadius,
|
||||||
|
borderBottomRightRadius,
|
||||||
|
)
|
||||||
return self._surf.copy()
|
return self._surf.copy()
|
||||||
|
|
||||||
def polygon(self, color, points, width=0):
|
def polygon(self, color, points, width=0):
|
||||||
try:
|
try:
|
||||||
orig = self._surf._surface_orig
|
orig = self._surf._surface_orig
|
||||||
except:
|
except Exception as _:
|
||||||
orig = self._surf._orig
|
orig = self._surf._orig
|
||||||
pygame.draw.polygon(orig,color,points,width)
|
pygame.draw.polygon(orig, color, points, width)
|
||||||
return self._surf.copy()
|
return self._surf.copy()
|
||||||
def circle(self,color,center,
|
|
||||||
radius,width=0,
|
def circle(
|
||||||
drawTopLeft=1,
|
self,
|
||||||
drawTopRight=1,
|
color,
|
||||||
drawBottomLeft=1,
|
center,
|
||||||
drawBottomRight=1):
|
radius,
|
||||||
|
width=0,
|
||||||
|
drawTopLeft=1,
|
||||||
|
drawTopRight=1,
|
||||||
|
drawBottomLeft=1,
|
||||||
|
drawBottomRight=1,
|
||||||
|
):
|
||||||
try:
|
try:
|
||||||
orig = self._surf._surface_orig
|
orig = self._surf._surface_orig
|
||||||
except:
|
except Exception as _:
|
||||||
orig = self._surf._orig
|
orig = self._surf._orig
|
||||||
pygame.draw.circle(orig,color,center,radius,
|
pygame.draw.circle(
|
||||||
width,drawTopRight,drawTopLeft,
|
orig,
|
||||||
drawBottomLeft,drawBottomRight)
|
color,
|
||||||
|
center,
|
||||||
|
radius,
|
||||||
|
width,
|
||||||
|
drawTopRight,
|
||||||
|
drawTopLeft,
|
||||||
|
drawBottomLeft,
|
||||||
|
drawBottomRight,
|
||||||
|
)
|
||||||
return self._surf.copy()
|
return self._surf.copy()
|
||||||
def ellipse(self,color,rect,width=0):
|
|
||||||
|
def ellipse(self, color, rect, width=0):
|
||||||
try:
|
try:
|
||||||
orig = self._surf._surface_orig
|
orig = self._surf._surface_orig
|
||||||
except:
|
except Exception as _:
|
||||||
orig = self._surf._orig
|
orig = self._surf._orig
|
||||||
pygame.draw.ellipse(orig,color,pygame.Rect(rect[0],
|
pygame.draw.ellipse(
|
||||||
rect[1],rect[2],rect[3]),width)
|
orig, color, pygame.Rect(rect[0], rect[1], rect[2], rect[3]), width
|
||||||
|
)
|
||||||
return self._surf.copy()
|
return self._surf.copy()
|
||||||
def line(self,color,start,end,width=1):
|
|
||||||
|
def line(self, color, start, end, width=1):
|
||||||
try:
|
try:
|
||||||
orig = self._surf._surface_orig
|
orig = self._surf._surface_orig
|
||||||
except:
|
except Exception as _:
|
||||||
orig = self._surf._orig
|
orig = self._surf._orig
|
||||||
pygame.draw.line(orig,color,start,end,width)
|
pygame.draw.line(orig, color, start, end, width)
|
||||||
return self._surf.copy()
|
return self._surf.copy()
|
||||||
def arc(self,color,rect,startAngle,stopAngle,width=1):
|
|
||||||
|
def arc(self, color, rect, startAngle, stopAngle, width=1):
|
||||||
try:
|
try:
|
||||||
orig = self._surf._surface_orig
|
orig = self._surf._surface_orig
|
||||||
except:
|
except Exception as _:
|
||||||
orig = self._surf._orig
|
orig = self._surf._orig
|
||||||
pygame.draw.arc(orig,color,pygame.Rect(rect[0],
|
pygame.draw.arc(
|
||||||
rect[1],rect[2],rect[3]),
|
orig,
|
||||||
startAngle,stopAngle,width)
|
color,
|
||||||
|
pygame.Rect(rect[0], rect[1], rect[2], rect[3]),
|
||||||
|
startAngle,
|
||||||
|
stopAngle,
|
||||||
|
width,
|
||||||
|
)
|
||||||
return self._surf.copy()
|
return self._surf.copy()
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def draw(self):
|
def draw(self):
|
||||||
return self._draw(self)
|
return self._draw(self)
|
||||||
|
|
|
@ -2,6 +2,7 @@ import threading
|
||||||
import wx
|
import wx
|
||||||
import wx.adv
|
import wx.adv
|
||||||
|
|
||||||
|
|
||||||
class tray(wx.adv.TaskBarIcon):
|
class tray(wx.adv.TaskBarIcon):
|
||||||
def __init__(self, tooltip, iconpath):
|
def __init__(self, tooltip, iconpath):
|
||||||
class App(wx.App):
|
class App(wx.App):
|
||||||
|
@ -9,6 +10,7 @@ class tray(wx.adv.TaskBarIcon):
|
||||||
self.frame = wx.Frame(None)
|
self.frame = wx.Frame(None)
|
||||||
self.SetTopWindow(self.frame)
|
self.SetTopWindow(self.frame)
|
||||||
return True
|
return True
|
||||||
|
|
||||||
self._app = App(False)
|
self._app = App(False)
|
||||||
self.frame = self._app.frame
|
self.frame = self._app.frame
|
||||||
super().__init__()
|
super().__init__()
|
||||||
|
@ -16,33 +18,41 @@ class tray(wx.adv.TaskBarIcon):
|
||||||
self._iconpath = iconpath
|
self._iconpath = iconpath
|
||||||
self.setIcon(iconpath)
|
self.setIcon(iconpath)
|
||||||
self._menu = wx.Menu()
|
self._menu = wx.Menu()
|
||||||
|
|
||||||
def CreatePopupMenu(self):
|
def CreatePopupMenu(self):
|
||||||
return self._menu
|
return self._menu
|
||||||
|
|
||||||
def GetPopupMenu(self):
|
def GetPopupMenu(self):
|
||||||
return self._menu
|
return self._menu
|
||||||
|
|
||||||
def setIcon(self, path):
|
def setIcon(self, path):
|
||||||
self._bicon = wx.Icon(wx.Bitmap(path))
|
self._bicon = wx.Icon(wx.Bitmap(path))
|
||||||
self.SetIcon(self._bicon, self._tooltip)
|
self.SetIcon(self._bicon, self._tooltip)
|
||||||
|
|
||||||
def setTooltip(self, tooltip):
|
def setTooltip(self, tooltip):
|
||||||
self.SetIcon(self._bicon, tooltip)
|
self.SetIcon(self._bicon, tooltip)
|
||||||
self._tooltip = tooltip
|
self._tooltip = tooltip
|
||||||
|
|
||||||
def onLeftMouseButton(self):
|
def onLeftMouseButton(self):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
def addSeparator(self):
|
def addSeparator(self):
|
||||||
self._menu.AppendSeparator()
|
self._menu.AppendSeparator()
|
||||||
def addCommand(self,text,func=lambda:None):
|
|
||||||
item = wx.MenuItem(self._menu,-1,text)
|
def addCommand(self, text, func=lambda: None):
|
||||||
self._menu.Bind(wx.EVT_MENU,
|
item = wx.MenuItem(self._menu, -1, text)
|
||||||
lambda x:func(),
|
self._menu.Bind(wx.EVT_MENU, lambda x: func(), id=item.GetId())
|
||||||
id=item.GetId())
|
|
||||||
self._menu.Append(item)
|
self._menu.Append(item)
|
||||||
|
|
||||||
def start(self, thread=True):
|
def start(self, thread=True):
|
||||||
def cbotld(x):
|
def cbotld(x):
|
||||||
return self.onLeftMouseButton()
|
return self.onLeftMouseButton()
|
||||||
self.Bind(wx.adv.EVT_TASKBAR_LEFT_DOWN,cbotld)
|
|
||||||
if thread: threading.Thread(
|
self.Bind(wx.adv.EVT_TASKBAR_LEFT_DOWN, cbotld)
|
||||||
target=self._app.MainLoop,
|
if thread:
|
||||||
daemon=1).start()
|
threading.Thread(target=self._app.MainLoop, daemon=1).start()
|
||||||
else: self._app.MainLoop()
|
else:
|
||||||
|
self._app.MainLoop()
|
||||||
|
|
||||||
def stop(self):
|
def stop(self):
|
||||||
wx.CallAfter(self._app.frame.Close)
|
wx.CallAfter(self._app.frame.Close)
|
||||||
|
|
|
@ -1,2 +1,4 @@
|
||||||
|
__all__ = ["widget", "base"]
|
||||||
|
|
||||||
from . import widget
|
from . import widget
|
||||||
from . import base
|
from . import base
|
||||||
|
|
|
@ -1,32 +1,32 @@
|
||||||
import ...pygame
|
|
||||||
from ...surface import surface as _s
|
|
||||||
from ...font import defaultFont as _df
|
|
||||||
from ...image import load as _l
|
|
||||||
from ...rect import rect as _r
|
|
||||||
import ...mouse as _m
|
|
||||||
import ...keyboard as _k
|
|
||||||
import ctypes as _ct
|
|
||||||
import copy as _copy
|
import copy as _copy
|
||||||
|
|
||||||
|
|
||||||
class widget:
|
class widget:
|
||||||
power = True
|
power = True
|
||||||
destroyed = False
|
destroyed = False
|
||||||
|
|
||||||
def _args(self, locals):
|
def _args(self, locals):
|
||||||
args = _copy.copy(locals)
|
args = _copy.copy(locals)
|
||||||
for i in args.items():
|
for i in args.items():
|
||||||
if i[0] != 'self':
|
if i[0] != "self":
|
||||||
exec(f'self.{i[0]} = args["{i[0]}"]')
|
exec(f'self.{i[0]} = args["{i[0]}"]')
|
||||||
self._args = args
|
self._args = args
|
||||||
|
|
||||||
def __init__(self, surface):
|
def __init__(self, surface):
|
||||||
self._args(locals())
|
self._args(locals())
|
||||||
|
|
||||||
def draw(self, win, pos):
|
def draw(self, win, pos):
|
||||||
win.blit(self.surface,pos)
|
win.blit(self.surface, pos)
|
||||||
|
|
||||||
def on(self):
|
def on(self):
|
||||||
self.power = True
|
self.power = True
|
||||||
|
|
||||||
def off(self):
|
def off(self):
|
||||||
self.power = False
|
self.power = False
|
||||||
|
|
||||||
def destroy(self):
|
def destroy(self):
|
||||||
self.destroyed = True
|
self.destroyed = True
|
||||||
|
|
||||||
def config(self, **parameters):
|
def config(self, **parameters):
|
||||||
if parameters != {}:
|
if parameters != {}:
|
||||||
for i in parameters.items():
|
for i in parameters.items():
|
||||||
|
@ -37,12 +37,14 @@ class widget:
|
||||||
return self._args
|
return self._args
|
||||||
self.__init__(**self._args)
|
self.__init__(**self._args)
|
||||||
|
|
||||||
|
|
||||||
class base:
|
class base:
|
||||||
def __init__(self, win, bg=(128,128,128)):
|
def __init__(self, win, bg=(128, 128, 128)):
|
||||||
self._widgets = {}
|
self._widgets = {}
|
||||||
self._bg = bg
|
self._bg = bg
|
||||||
self._win = win
|
self._win = win
|
||||||
self._page = 0
|
self._page = 0
|
||||||
|
|
||||||
def draw(self):
|
def draw(self):
|
||||||
self._win.fill(self._bg)
|
self._win.fill(self._bg)
|
||||||
for i in self._widgets[self._page]:
|
for i in self._widgets[self._page]:
|
||||||
|
@ -50,17 +52,23 @@ class base:
|
||||||
i[0].draw(self._win, i[1])
|
i[0].draw(self._win, i[1])
|
||||||
if i[0].destroyed:
|
if i[0].destroyed:
|
||||||
self._widgets[self._page].remove(i)
|
self._widgets[self._page].remove(i)
|
||||||
|
|
||||||
def put(self, widget, pos, page=0):
|
def put(self, widget, pos, page=0):
|
||||||
if page not in self._widgets:
|
if page not in self._widgets:
|
||||||
self.blankPage(page)
|
self.blankPage(page)
|
||||||
self._widgets[page].append([widget, pos])
|
self._widgets[page].append([widget, pos])
|
||||||
|
|
||||||
def selectPage(self, page):
|
def selectPage(self, page):
|
||||||
self._page = page
|
self._page = page
|
||||||
|
|
||||||
def getPage(self):
|
def getPage(self):
|
||||||
return self._page
|
return self._page
|
||||||
|
|
||||||
def getWidgets(self, page=0):
|
def getWidgets(self, page=0):
|
||||||
return self._widgets[page]
|
return self._widgets[page]
|
||||||
def setWidgetPos(self,index,pos,page=0):
|
|
||||||
|
def setWidgetPos(self, index, pos, page=0):
|
||||||
self._widgets[page][index] = [self._widgets[page][index][0], pos]
|
self._widgets[page][index] = [self._widgets[page][index][0], pos]
|
||||||
def blankPage(self,page):
|
|
||||||
self._widgets.update({page:[]})
|
def blankPage(self, page):
|
||||||
|
self._widgets.update({page: []})
|
||||||
|
|
|
@ -1,3 +1,17 @@
|
||||||
|
__all__ = [
|
||||||
|
"checkbox",
|
||||||
|
"entry",
|
||||||
|
"keyselect",
|
||||||
|
"button",
|
||||||
|
"combobox",
|
||||||
|
"image",
|
||||||
|
"label",
|
||||||
|
"loadingbar",
|
||||||
|
"textarea",
|
||||||
|
"tip",
|
||||||
|
"slider",
|
||||||
|
]
|
||||||
|
|
||||||
from . import checkbox
|
from . import checkbox
|
||||||
from . import entry
|
from . import entry
|
||||||
from . import keyselect
|
from . import keyselect
|
||||||
|
|
|
@ -1,41 +1,49 @@
|
||||||
import ...pygame
|
from ... import pygame
|
||||||
from ...surface import surface as _s
|
from ...surface import surface as _s
|
||||||
from ...font import defaultFont as _df
|
from ...font import deaultFont as _df
|
||||||
from ...image import load as _l
|
|
||||||
from ...rect import rect as _r
|
from ...rect import rect as _r
|
||||||
import ...mouse as _m
|
from ... import mouse as _m
|
||||||
import ...keyboard as _k
|
from .base import widget
|
||||||
import ctypes as _ct
|
|
||||||
import copy as _copy
|
|
||||||
|
|
||||||
class button(widget):
|
class button(widget):
|
||||||
def __init__(self,text,
|
def __init__(
|
||||||
func=lambda:None,
|
self,
|
||||||
fontSize=30,font=_df,
|
text,
|
||||||
width=None,height=None,
|
func=lambda: None,
|
||||||
bg=(70,70,70),fg=(180,180,200),
|
fontSize=30,
|
||||||
afg=(50,50,50),abg=(200,200,200),
|
font=_df,
|
||||||
borderColor=(50,50,50),borderWidth=5):
|
width=None,
|
||||||
|
height=None,
|
||||||
|
bg=(70, 70, 70),
|
||||||
|
fg=(180, 180, 200),
|
||||||
|
afg=(50, 50, 50),
|
||||||
|
abg=(200, 200, 200),
|
||||||
|
borderColor=(50, 50, 50),
|
||||||
|
borderWidth=5,
|
||||||
|
):
|
||||||
super()._args(locals())
|
super()._args(locals())
|
||||||
self.cl0 = False
|
self.cl0 = False
|
||||||
self.cl1 = False
|
self.cl1 = False
|
||||||
self.nc0 = True
|
self.nc0 = True
|
||||||
self._generate()
|
self._generate()
|
||||||
|
|
||||||
def _generate(self, position=None):
|
def _generate(self, position=None):
|
||||||
if self.width == None or self.height == None:
|
if self.width is None or self.height is None:
|
||||||
textSize = self.font.size(self.text,self.fontSize)
|
textSize = self.font.size(self.text, self.fontSize)
|
||||||
if self.width != None:
|
if self.width is not None:
|
||||||
self.surface = _s((self.width,textSize[1]+10))
|
self.surface = _s((self.width, textSize[1] + 10))
|
||||||
elif self.height != None:
|
elif self.height is not None:
|
||||||
self.surface = _s((textSize[0]+50,self.height))
|
self.surface = _s((textSize[0] + 50, self.height))
|
||||||
else:
|
else:
|
||||||
self.surface = _s((textSize[0]+50,textSize[1]+10))
|
self.surface = _s((textSize[0] + 50, textSize[1] + 10))
|
||||||
else:
|
else:
|
||||||
self.surface = _s((self.width,self.height))
|
self.surface = _s((self.width, self.height))
|
||||||
if position != None:
|
if position is not None:
|
||||||
contains = self.surface.rect(position[0], position[1]).contains(
|
contains = self.surface.rect(position[0], position[1]).contains(
|
||||||
_m.getPosition()[0], _m.getPosition()[1])
|
_m.getPosition()[0], _m.getPosition()[1]
|
||||||
cacm = contains and _m.isPressed('left')
|
)
|
||||||
|
cacm = contains and _m.isPressed("left")
|
||||||
else:
|
else:
|
||||||
contains = False
|
contains = False
|
||||||
cacm = False
|
cacm = False
|
||||||
|
@ -55,23 +63,33 @@ class button(widget):
|
||||||
self.cl1 = False
|
self.cl1 = False
|
||||||
self.surface.fill(self.borderColor)
|
self.surface.fill(self.borderColor)
|
||||||
if cacm:
|
if cacm:
|
||||||
self.surface.draw.rect(self.abg,_r(self.borderWidth,self.borderWidth,
|
self.surface.draw.rect(
|
||||||
self.surface.size[0]-self.borderWidth*2,
|
self.abg,
|
||||||
self.surface.size[1]-self.borderWidth*2))
|
_r(
|
||||||
|
self.borderWidth,
|
||||||
|
self.borderWidth,
|
||||||
|
self.surface.size[0] - self.borderWidth * 2,
|
||||||
|
self.surface.size[1] - self.borderWidth * 2,
|
||||||
|
),
|
||||||
|
)
|
||||||
else:
|
else:
|
||||||
self.surface.draw.rect(self.bg,_r(self.borderWidth,self.borderWidth,
|
self.surface.draw.rect(
|
||||||
self.surface.size[0]-self.borderWidth*2,
|
self.bg,
|
||||||
self.surface.size[1]-self.borderWidth*2))
|
_r(
|
||||||
|
self.borderWidth,
|
||||||
|
self.borderWidth,
|
||||||
|
self.surface.size[0] - self.borderWidth * 2,
|
||||||
|
self.surface.size[1] - self.borderWidth * 2,
|
||||||
|
),
|
||||||
|
)
|
||||||
if cacm:
|
if cacm:
|
||||||
text = self.font.render(self.text,self.fontSize,self.afg)
|
text = self.font.render(self.text, self.fontSize, self.afg)
|
||||||
else:
|
else:
|
||||||
text = self.font.render(self.text,self.fontSize,self.fg)
|
text = self.font.render(self.text, self.fontSize, self.fg)
|
||||||
pos = text.rect(center=(
|
pos = text.rect(center=(self.surface.size[0] / 2, self.surface.size[1] / 2))
|
||||||
self.surface.size[0]/2,
|
|
||||||
self.surface.size[1]/2))
|
|
||||||
pos = [pos.x, pos.y]
|
pos = [pos.x, pos.y]
|
||||||
self.surface.blit(text,pos)
|
self.surface.blit(text, pos)
|
||||||
|
|
||||||
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)
|
||||||
|
|
||||||
|
|
|
@ -1,34 +1,41 @@
|
||||||
import ...pygame
|
from ... import pygame
|
||||||
from ...surface import surface as _s
|
from ...surface import surface as _s
|
||||||
from ...font import defaultFont as _df
|
|
||||||
from ...image import load as _l
|
|
||||||
from ...rect import rect as _r
|
from ...rect import rect as _r
|
||||||
import ...mouse as _m
|
from ... import mouse as _m
|
||||||
import ...keyboard as _k
|
from .base import widget
|
||||||
import ctypes as _ct
|
|
||||||
import copy as _copy
|
|
||||||
|
|
||||||
class checkBox(widget):
|
class checkBox(widget):
|
||||||
def __init__(self,width=50,bg=(180,180,180),
|
def __init__(
|
||||||
fg=(50,180,50),afg=(70,200,70),
|
self,
|
||||||
abg=(120,120,120),borderColor=(220,220,220),
|
width=50,
|
||||||
borderWidth=5):
|
bg=(180, 180, 180),
|
||||||
|
fg=(50, 180, 50),
|
||||||
|
afg=(70, 200, 70),
|
||||||
|
abg=(120, 120, 120),
|
||||||
|
borderColor=(220, 220, 220),
|
||||||
|
borderWidth=5,
|
||||||
|
):
|
||||||
super()._args(locals())
|
super()._args(locals())
|
||||||
self.cl0 = False
|
self.cl0 = False
|
||||||
self.cl1 = False
|
self.cl1 = False
|
||||||
self.nc0 = True
|
self.nc0 = True
|
||||||
self.x = False
|
self.x = False
|
||||||
self._generate()
|
self._generate()
|
||||||
|
|
||||||
def set(self, x):
|
def set(self, x):
|
||||||
self.x = x
|
self.x = x
|
||||||
|
|
||||||
def get(self):
|
def get(self):
|
||||||
return self.x
|
return self.x
|
||||||
|
|
||||||
def _generate(self, position=None):
|
def _generate(self, position=None):
|
||||||
self.surface = _s((self.width,self.width))
|
self.surface = _s((self.width, self.width))
|
||||||
if position != None:
|
if position is not None:
|
||||||
contains = self.surface.rect(position[0], position[1]).contains(
|
contains = self.surface.rect(position[0], position[1]).contains(
|
||||||
_m.getPosition()[0], _m.getPosition()[1])
|
_m.getPosition()[0], _m.getPosition()[1]
|
||||||
cacm = contains and _m.isPressed('left')
|
)
|
||||||
|
cacm = contains and _m.isPressed("left")
|
||||||
else:
|
else:
|
||||||
contains = False
|
contains = False
|
||||||
cacm = False
|
cacm = False
|
||||||
|
@ -42,30 +49,58 @@ class checkBox(widget):
|
||||||
self.nc0 = False
|
self.nc0 = False
|
||||||
self.cl0 = False
|
self.cl0 = False
|
||||||
if cacm and not self.cl1:
|
if cacm and not self.cl1:
|
||||||
self.x=self.x==0
|
self.x = self.x == 0
|
||||||
self.cl1 = True
|
self.cl1 = True
|
||||||
elif not cacm:
|
elif not cacm:
|
||||||
self.cl1 = False
|
self.cl1 = False
|
||||||
self.surface.fill(self.borderColor)
|
self.surface.fill(self.borderColor)
|
||||||
if cacm:
|
if cacm:
|
||||||
self.surface.draw.rect(self.abg,_r(self.borderWidth,self.borderWidth,
|
self.surface.draw.rect(
|
||||||
self.surface.size[0]-self.borderWidth*2,
|
self.abg,
|
||||||
self.surface.size[1]-self.borderWidth*2))
|
_r(
|
||||||
|
self.borderWidth,
|
||||||
|
self.borderWidth,
|
||||||
|
self.surface.size[0] - self.borderWidth * 2,
|
||||||
|
self.surface.size[1] - self.borderWidth * 2,
|
||||||
|
),
|
||||||
|
)
|
||||||
if self.x:
|
if self.x:
|
||||||
self.surface.draw.line(self.afg,[self.borderWidth,self.width/2+self.borderWidth],
|
self.surface.draw.line(
|
||||||
[self.width/2,self.width-self.borderWidth],self.borderWidth)
|
self.afg,
|
||||||
self.surface.draw.line(self.afg,[self.width/2,self.width-self.borderWidth],
|
[self.borderWidth, self.width / 2 + self.borderWidth],
|
||||||
[self.width-self.borderWidth,self.borderWidth],self.borderWidth)
|
[self.width / 2, self.width - self.borderWidth],
|
||||||
|
self.borderWidth,
|
||||||
|
)
|
||||||
|
self.surface.draw.line(
|
||||||
|
self.afg,
|
||||||
|
[self.width / 2, self.width - self.borderWidth],
|
||||||
|
[self.width - self.borderWidth, self.borderWidth],
|
||||||
|
self.borderWidth,
|
||||||
|
)
|
||||||
else:
|
else:
|
||||||
self.surface.draw.rect(self.bg,_r(self.borderWidth,self.borderWidth,
|
self.surface.draw.rect(
|
||||||
self.surface.size[0]-self.borderWidth*2,
|
self.bg,
|
||||||
self.surface.size[1]-self.borderWidth*2))
|
_r(
|
||||||
|
self.borderWidth,
|
||||||
|
self.borderWidth,
|
||||||
|
self.surface.size[0] - self.borderWidth * 2,
|
||||||
|
self.surface.size[1] - self.borderWidth * 2,
|
||||||
|
),
|
||||||
|
)
|
||||||
if self.x:
|
if self.x:
|
||||||
self.surface.draw.line(self.fg,[self.borderWidth,self.width/2+self.borderWidth],
|
self.surface.draw.line(
|
||||||
[self.width/2,self.width-self.borderWidth],self.borderWidth)
|
self.fg,
|
||||||
self.surface.draw.line(self.fg,[self.width/2,self.width-self.borderWidth],
|
[self.borderWidth, self.width / 2 + self.borderWidth],
|
||||||
[self.width-self.borderWidth,self.borderWidth],self.borderWidth)
|
[self.width / 2, self.width - self.borderWidth],
|
||||||
|
self.borderWidth,
|
||||||
|
)
|
||||||
|
self.surface.draw.line(
|
||||||
|
self.fg,
|
||||||
|
[self.width / 2, self.width - self.borderWidth],
|
||||||
|
[self.width - self.borderWidth, self.borderWidth],
|
||||||
|
self.borderWidth,
|
||||||
|
)
|
||||||
|
|
||||||
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)
|
||||||
|
|
||||||
|
|
|
@ -1,25 +1,30 @@
|
||||||
import ...pygame
|
|
||||||
from ...surface import surface as _s
|
from ...surface import surface as _s
|
||||||
from ...font import defaultFont as _df
|
from ...font import deaultFont as _df
|
||||||
from ...image import load as _l
|
from .base import widget
|
||||||
from ...rect import rect as _r
|
|
||||||
import ...mouse as _m
|
|
||||||
import ...keyboard as _k
|
|
||||||
import ctypes as _ct
|
|
||||||
import copy as _copy
|
|
||||||
|
|
||||||
class comboBox(widget):
|
class comboBox(widget):
|
||||||
def __init__(self,text,values=[],
|
def __init__(
|
||||||
fontSize=30,font=_df,width=None,height=None,
|
self,
|
||||||
bg=(70,70,70),fg=(180,180,200),afg=(50,50,50),
|
text,
|
||||||
abg=(200,200,200),borderColor=(50,50,50),borderWidth=5):
|
values=[],
|
||||||
|
fontSize=30,
|
||||||
|
font=_df,
|
||||||
|
width=None,
|
||||||
|
height=None,
|
||||||
|
bg=(70, 70, 70),
|
||||||
|
fg=(180, 180, 200),
|
||||||
|
afg=(50, 50, 50),
|
||||||
|
abg=(200, 200, 200),
|
||||||
|
borderColor=(50, 50, 50),
|
||||||
|
borderWidth=5,
|
||||||
|
):
|
||||||
super()._args(locals())
|
super()._args(locals())
|
||||||
self._generate()
|
self._generate()
|
||||||
|
|
||||||
def _generate(self, position=None):
|
def _generate(self, position=None):
|
||||||
self.surface = _s((255,self.width))
|
self.surface = _s((255, self.width))
|
||||||
|
|
||||||
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)
|
||||||
|
|
||||||
|
|
|
@ -1,117 +1,157 @@
|
||||||
import ...pygame
|
from ... import pygame
|
||||||
from ...surface import surface as _s
|
from ...surface import surface as _s
|
||||||
from ...font import defaultFont as _df
|
from ...font import deaultFont as _df
|
||||||
from ...image import load as _l
|
|
||||||
from ...rect import rect as _r
|
from ...rect import rect as _r
|
||||||
import ...mouse as _m
|
from ... import mouse as _m
|
||||||
import ...keyboard as _k
|
from ... import keyboard as _k
|
||||||
import ctypes as _ct
|
from ... import pes as _ct
|
||||||
import copy as _copy
|
from .base import widget
|
||||||
|
|
||||||
|
|
||||||
class entry(widget):
|
class entry(widget):
|
||||||
def __init__(self,hint='',fontSize=30,font=_df,
|
def __init__(
|
||||||
width=None,height=None,hide=False,
|
self,
|
||||||
bg=(70,70,70),fg=(180,180,200),
|
hint="",
|
||||||
afg=(200,200,200),abg=(50,50,50),
|
fontSize=30,
|
||||||
hintColor=(100,100,100),
|
font=_df,
|
||||||
lineColor=(200,200,200),
|
width=None,
|
||||||
borderColor=(50,50,50),
|
height=None,
|
||||||
borderWidth=5,maxSymbols=None,
|
hide=False,
|
||||||
whitelist=None,blacklist=[]):
|
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())
|
super()._args(locals())
|
||||||
self.text = ''
|
self.text = ""
|
||||||
self.focus = False
|
self.focus = False
|
||||||
self.tick = 0
|
self.tick = 0
|
||||||
self.wcl = False
|
self.wcl = False
|
||||||
self.startHint = self.hint
|
self.startHint = self.hint
|
||||||
self.ws = False
|
self.ws = False
|
||||||
if self.width == None or self.height == None:
|
if self.width is None or self.height is None:
|
||||||
if self.hint != '':
|
if self.hint != "":
|
||||||
hintSize = self.font.size(self.hint,self.fontSize)
|
hintSize = self.font.size(self.hint, self.fontSize)
|
||||||
else:
|
else:
|
||||||
hintSize = (150,self.font.size('X',self.fontSize)[1])
|
hintSize = (150, self.font.size("X", self.fontSize)[1])
|
||||||
if self.height == None:
|
if self.height is None:
|
||||||
self.height = hintSize[1]+10
|
self.height = hintSize[1] + 10
|
||||||
if self.width == None:
|
if self.width is None:
|
||||||
self.width = hintSize[0]+50
|
self.width = hintSize[0] + 50
|
||||||
self.surface = _s((self.width,self.height))
|
self.surface = _s((self.width, self.height))
|
||||||
self.wclk = []
|
self.wclk = []
|
||||||
self.wsnr = False
|
self.wsnr = False
|
||||||
def _generate(self,position=None):
|
|
||||||
|
def _generate(self, position=None):
|
||||||
self.surface.fill(self.borderColor)
|
self.surface.fill(self.borderColor)
|
||||||
if self.focus:
|
if self.focus:
|
||||||
self.surface.draw.rect(self.abg,_r(self.borderWidth,self.borderWidth,
|
self.surface.draw.rect(
|
||||||
self.surface.size[0]-self.borderWidth*2,
|
self.abg,
|
||||||
self.surface.size[1]-self.borderWidth*2))
|
_r(
|
||||||
if self.text == '':
|
self.borderWidth,
|
||||||
|
self.borderWidth,
|
||||||
|
self.surface.size[0] - self.borderWidth * 2,
|
||||||
|
self.surface.size[1] - self.borderWidth * 2,
|
||||||
|
),
|
||||||
|
)
|
||||||
|
if self.text == "":
|
||||||
if not self.hide:
|
if not self.hide:
|
||||||
text = self.font.render(self.hint,self.fontSize,self.hintColor)
|
text = self.font.render(self.hint, self.fontSize, self.hintColor)
|
||||||
else:
|
else:
|
||||||
text = self.font.render('*'*len(self.hint),self.fontSize,self.hintColor)
|
text = self.font.render(
|
||||||
|
"*" * len(self.hint), self.fontSize, self.hintColor
|
||||||
|
)
|
||||||
else:
|
else:
|
||||||
if not self.hide:
|
if not self.hide:
|
||||||
text = self.font.render(self.text,self.fontSize,self.afg)
|
text = self.font.render(self.text, self.fontSize, self.afg)
|
||||||
else:
|
else:
|
||||||
text = self.font.render('*'*len(self.text),self.fontSize,self.afg)
|
text = self.font.render(
|
||||||
|
"*" * len(self.text), self.fontSize, self.afg
|
||||||
|
)
|
||||||
x = 10
|
x = 10
|
||||||
if text.size[0] >= self.surface.size[0]-20:
|
if text.size[0] >= self.surface.size[0] - 20:
|
||||||
x = self.surface.size[0]-text.size[0]-10
|
x = self.surface.size[0] - text.size[0] - 10
|
||||||
self.surface.blit(text,(x,self.surface.size[1]/2-text.size[1]/2))
|
self.surface.blit(text, (x, self.surface.size[1] / 2 - text.size[1] / 2))
|
||||||
for i in _k.getPressed().items():
|
for i in _k.getPressed().items():
|
||||||
if i[1]:
|
if i[1]:
|
||||||
if i[0] not in self.wclk:
|
if i[0] not in self.wclk:
|
||||||
if len(i[0]) == 1:
|
if len(i[0]) == 1:
|
||||||
self.insert(i[0])
|
self.insert(i[0])
|
||||||
elif i[0] == 'backspace':
|
elif i[0] == "backspace":
|
||||||
self.delete()
|
self.delete()
|
||||||
elif i[0] == 'return':
|
elif i[0] == "return":
|
||||||
self.focus = False
|
self.focus = False
|
||||||
elif i[0] == 'space':
|
elif i[0] == "space":
|
||||||
self.insert(' ')
|
self.insert(" ")
|
||||||
self.wclk.append(i[0])
|
self.wclk.append(i[0])
|
||||||
else:
|
else:
|
||||||
if i[0] in self.wclk:
|
if i[0] in self.wclk:
|
||||||
self.wclk.remove(i[0])
|
self.wclk.remove(i[0])
|
||||||
self.tick += 1
|
self.tick += 1
|
||||||
if self.tick >= 60:
|
if self.tick >= 60:
|
||||||
if self.text != '':
|
if self.text != "":
|
||||||
points = [[x+text.size[0],self.surface.size[1]/2-text.size[1]/2],
|
points = [
|
||||||
[x+text.size[0],self.surface.size[1]/2-text.size[1]/2+self.surface.size[1]-10]]
|
[x + text.size[0], self.surface.size[1] / 2 - text.size[1] / 2],
|
||||||
self.surface.draw.line(self.lineColor,points[0],points[1],3)
|
[
|
||||||
|
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:
|
if self.tick == 120:
|
||||||
self.tick = 0
|
self.tick = 0
|
||||||
else:
|
else:
|
||||||
self.surface.draw.rect(self.bg,_r(self.borderWidth,self.borderWidth,
|
self.surface.draw.rect(
|
||||||
self.surface.size[0]-self.borderWidth*2,
|
self.bg,
|
||||||
self.surface.size[1]-self.borderWidth*2))
|
_r(
|
||||||
if self.text == '':
|
self.borderWidth,
|
||||||
|
self.borderWidth,
|
||||||
|
self.surface.size[0] - self.borderWidth * 2,
|
||||||
|
self.surface.size[1] - self.borderWidth * 2,
|
||||||
|
),
|
||||||
|
)
|
||||||
|
if self.text == "":
|
||||||
if not self.hide:
|
if not self.hide:
|
||||||
text = self.font.render(self.hint,self.fontSize,self.hintColor)
|
text = self.font.render(self.hint, self.fontSize, self.hintColor)
|
||||||
else:
|
else:
|
||||||
text = self.font.render('*'*len(self.hint),self.fontSize,self.hintColor)
|
text = self.font.render(
|
||||||
|
"*" * len(self.hint), self.fontSize, self.hintColor
|
||||||
|
)
|
||||||
else:
|
else:
|
||||||
if self.hide:
|
if self.hide:
|
||||||
text = self.font.render(self.text,self.fontSize,self.fg)
|
text = self.font.render(self.text, self.fontSize, self.fg)
|
||||||
else:
|
else:
|
||||||
text = self.font.render('*'*len(self.text),self.fontSize,self.fg)
|
text = self.font.render(
|
||||||
x = self.surface.size[0]/2-text.size[0]/2
|
"*" * len(self.text), self.fontSize, self.fg
|
||||||
if text.size[0] >= self.surface.size[0]-20:
|
)
|
||||||
x = self.surface.size[0]-text.size[0]-10
|
x = self.surface.size[0] / 2 - text.size[0] / 2
|
||||||
self.surface.blit(text,(x,self.surface.size[1]/2-text.size[1]/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 position is not None:
|
||||||
if self.surface.rect(position[0],
|
if self.surface.rect(position[0], position[1]).contains(
|
||||||
position[1]).contains(_m.getPosition()[0],
|
_m.getPosition()[0], _m.getPosition()[1]
|
||||||
_m.getPosition()[1]):
|
):
|
||||||
if not self.wcl:
|
if not self.wcl:
|
||||||
_m.setCursor(pygame.SYSTEM_CURSOR_HAND)
|
_m.setCursor(pygame.SYSTEM_CURSOR_HAND)
|
||||||
else:
|
else:
|
||||||
if not self.ws:
|
if not self.ws:
|
||||||
_m.setCursor(pygame.SYSTEM_CURSOR_ARROW)
|
_m.setCursor(pygame.SYSTEM_CURSOR_ARROW)
|
||||||
self.ws = True
|
self.ws = True
|
||||||
if _m.isPressed('left'):
|
if _m.isPressed("left"):
|
||||||
if not self.wcl:
|
if not self.wcl:
|
||||||
self.focus=self.focus==0
|
self.focus = self.focus == 0
|
||||||
self.wcl = True
|
self.wcl = True
|
||||||
else:
|
else:
|
||||||
self.wcl = False
|
self.wcl = False
|
||||||
|
@ -120,33 +160,55 @@ class entry(widget):
|
||||||
if not self.wsnr:
|
if not self.wsnr:
|
||||||
_m.setCursor(pygame.SYSTEM_CURSOR_ARROW)
|
_m.setCursor(pygame.SYSTEM_CURSOR_ARROW)
|
||||||
self.wsnr = True
|
self.wsnr = True
|
||||||
if _m.isPressed('left'):
|
if _m.isPressed("left"):
|
||||||
self.focus = False
|
self.focus = False
|
||||||
def insert(self,text):
|
|
||||||
|
def insert(self, text):
|
||||||
if _ct.WinDLL("User32.dll").GetKeyState(0x14):
|
if _ct.WinDLL("User32.dll").GetKeyState(0x14):
|
||||||
text = text.upper()
|
text = text.upper()
|
||||||
if hex(getattr(_ct.windll.LoadLibrary("user32.dll"), "GetKeyboardLayout")(0))=='0x4190419':
|
if (
|
||||||
text = text.translate(dict(zip(map(ord,
|
hex(getattr(_ct.windll.LoadLibrary("user32.dll"), "GetKeyboardLayout")(0))
|
||||||
'''qwertyuiop[]asdfghjkl;'zxcvbnm,./`QWERTYUIOPASDFGHJKLZXCVBNM'''),
|
== "0x4190419"
|
||||||
'''йцукенгшщзхъфывапролджэячсмитьбю.ёЙЦУКЕНГШЩЗФЫВАПРОЛДЯЧСМИТЬ''')))
|
):
|
||||||
if pygame.key.get_pressed()[pygame.K_LSHIFT] or pygame.key.get_pressed()[pygame.K_RSHIFT]:
|
text = text.translate(
|
||||||
text = text.translate(dict(zip(map(ord,
|
dict(
|
||||||
u'''1234567890-=[]\;',./`'''),
|
zip(
|
||||||
u'''!@#$%^&*()_+{}|:"<>?~''')))
|
map(
|
||||||
|
ord,
|
||||||
|
"""qwertyuiop[]asdfghjkl;'zxcvbnm,./`QWERTYUIOPASDFGHJKLZXCVBNM""",
|
||||||
|
),
|
||||||
|
"""йцукенгшщзхъфывапролджэячсмитьбю.ёЙЦУКЕНГШЩЗФЫВАПРОЛДЯЧСМИТЬ""",
|
||||||
|
)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
if (
|
||||||
|
pygame.key.get_pressed()[pygame.K_LSHIFT]
|
||||||
|
or pygame.key.get_pressed()[pygame.K_RSHIFT]
|
||||||
|
):
|
||||||
|
text = text.translate(
|
||||||
|
dict(
|
||||||
|
zip(
|
||||||
|
map(ord, """1234567890-=[]\;',./`"""),
|
||||||
|
"""!@#$%^&*()_+{}|:"<>?~""",
|
||||||
|
)
|
||||||
|
)
|
||||||
|
)
|
||||||
if text in self.blacklist:
|
if text in self.blacklist:
|
||||||
return
|
return
|
||||||
if self.whitelist != None:
|
if self.whitelist is not None:
|
||||||
if text not in self.whitelist:
|
if text not in self.whitelist:
|
||||||
return
|
return
|
||||||
if self.maxSymbols != None:
|
if self.maxSymbols is not None:
|
||||||
if len(self.text) > self.maxSymbols:
|
if len(self.text) > self.maxSymbols:
|
||||||
return
|
return
|
||||||
self.text += text
|
self.text += text
|
||||||
def delete(self,symbols=1):
|
|
||||||
self.text = self.text[:0-symbols]
|
def delete(self, symbols=1):
|
||||||
|
self.text = self.text[: 0 - symbols]
|
||||||
|
|
||||||
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)
|
||||||
|
|
||||||
def get(self):
|
def get(self):
|
||||||
return self.text
|
return self.text
|
||||||
|
|
||||||
|
|
|
@ -1,12 +1,6 @@
|
||||||
import ...pygame
|
|
||||||
from ...surface import surface as _s
|
|
||||||
from ...font import defaultFont as _df
|
|
||||||
from ...image import load as _l
|
from ...image import load as _l
|
||||||
from ...rect import rect as _r
|
from .base import widget
|
||||||
import ...mouse as _m
|
|
||||||
import ...keyboard as _k
|
|
||||||
import ctypes as _ct
|
|
||||||
import copy as _copy
|
|
||||||
|
|
||||||
class image(widget):
|
class image(widget):
|
||||||
def __init__(self, path):
|
def __init__(self, path):
|
||||||
|
|
|
@ -1,104 +1,133 @@
|
||||||
import ...pygame
|
from ... import pygame
|
||||||
from ...surface import surface as _s
|
from ...surface import surface as _s
|
||||||
from ...font import defaultFont as _df
|
from ...font import deaultFont as _df
|
||||||
from ...image import load as _l
|
|
||||||
from ...rect import rect as _r
|
from ...rect import rect as _r
|
||||||
import ...mouse as _m
|
from ... import mouse as _m
|
||||||
import ...keyboard as _k
|
from ... import keyboard as _k
|
||||||
import ctypes as _ct
|
from .entry import entry
|
||||||
import copy as _copy
|
|
||||||
|
|
||||||
class keySelect(entry):
|
class keySelect(entry):
|
||||||
def __init__(self,keyBefore='',
|
def __init__(
|
||||||
fontSize=30,font=_df,
|
self,
|
||||||
width=None,height=None,
|
keyBefore="",
|
||||||
bg=(70,70,70),fg=(180,180,200),
|
fontSize=30,
|
||||||
afg=(200,200,200),abg=(50,50,50),
|
font=_df,
|
||||||
hintColor=(100,100,100),
|
width=None,
|
||||||
lineColor=(200,200,200),
|
height=None,
|
||||||
borderColor=(50,50,50),
|
bg=(70, 70, 70),
|
||||||
borderWidth=5,maxSymbols=None,
|
fg=(180, 180, 200),
|
||||||
whitelist=None,blacklist=[]):
|
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())
|
super()._args(locals())
|
||||||
self.hint = ''
|
self.hint = ""
|
||||||
self.text = keyBefore
|
self.text = keyBefore
|
||||||
self.focus = False
|
self.focus = False
|
||||||
self.tick = 0
|
self.tick = 0
|
||||||
self.wcl = False
|
self.wcl = False
|
||||||
self.startHint = self.hint
|
self.startHint = self.hint
|
||||||
self.ws = False
|
self.ws = False
|
||||||
if self.width == None or self.height == None:
|
if self.width is None or self.height is None:
|
||||||
if self.hint != '':
|
if self.hint != "":
|
||||||
hintSize = self.font.size(self.hint,self.fontSize)
|
hintSize = self.font.size(self.hint, self.fontSize)
|
||||||
else:
|
else:
|
||||||
hintSize = (150,self.font.size('X',self.fontSize)[1])
|
hintSize = (150, self.font.size("X", self.fontSize)[1])
|
||||||
if self.height == None:
|
if self.height is None:
|
||||||
self.height = hintSize[1]+10
|
self.height = hintSize[1] + 10
|
||||||
if self.width == None:
|
if self.width is None:
|
||||||
self.width = hintSize[0]+50
|
self.width = hintSize[0] + 50
|
||||||
self.surface = _s((self.width,self.height))
|
self.surface = _s((self.width, self.height))
|
||||||
self.wclk = []
|
self.wclk = []
|
||||||
self.wsnr = False
|
self.wsnr = False
|
||||||
def _generate(self,position=None):
|
|
||||||
|
def _generate(self, position=None):
|
||||||
self.surface.fill(self.borderColor)
|
self.surface.fill(self.borderColor)
|
||||||
if self.focus:
|
if self.focus:
|
||||||
self.surface.draw.rect(self.abg,_r(self.borderWidth,self.borderWidth,
|
self.surface.draw.rect(
|
||||||
self.surface.size[0]-self.borderWidth*2,
|
self.abg,
|
||||||
self.surface.size[1]-self.borderWidth*2))
|
_r(
|
||||||
if self.text == '':
|
self.borderWidth,
|
||||||
text = self.font.render(self.hint,self.fontSize,self.hintColor)
|
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:
|
else:
|
||||||
text = self.font.render(self.text,self.fontSize,self.afg)
|
text = self.font.render(self.text, self.fontSize, self.afg)
|
||||||
x = self.surface.size[0]/2-text.size[0]/2
|
x = self.surface.size[0] / 2 - text.size[0] / 2
|
||||||
if text.size[0] >= self.surface.size[0]-20:
|
if text.size[0] >= self.surface.size[0] - 20:
|
||||||
x = self.surface.size[0]-text.size[0]-10
|
x = self.surface.size[0] - text.size[0] - 10
|
||||||
self.surface.blit(text,(x,self.surface.size[1]/2-text.size[1]/2))
|
self.surface.blit(text, (x, self.surface.size[1] / 2 - text.size[1] / 2))
|
||||||
for i in _k.getPressed().items():
|
for i in _k.getPressed().items():
|
||||||
if i[1] and self.focus:
|
if i[1] and self.focus:
|
||||||
if i[0] in self.blacklist:
|
if i[0] in self.blacklist:
|
||||||
continue
|
continue
|
||||||
if self.whitelist != None:
|
if self.whitelist is not None:
|
||||||
if i[0] not in self.whitelist:
|
if i[0] not in self.whitelist:
|
||||||
continue
|
continue
|
||||||
if self.maxSymbols != None:
|
if self.maxSymbols is not None:
|
||||||
if len(self.text) > self.maxSymbols:
|
if len(self.text) > self.maxSymbols:
|
||||||
continue
|
continue
|
||||||
self.text = i[0]
|
self.text = i[0]
|
||||||
break
|
break
|
||||||
self.tick += 1
|
self.tick += 1
|
||||||
if self.tick >= 60:
|
if self.tick >= 60:
|
||||||
if self.text != '':
|
if self.text != "":
|
||||||
points = [[x+text.size[0],self.surface.size[1]/2-text.size[1]/2],
|
points = [
|
||||||
[x+text.size[0],self.surface.size[1]/2-text.size[1]/2+self.surface.size[1]-10]]
|
[x + text.size[0], self.surface.size[1] / 2 - text.size[1] / 2],
|
||||||
self.surface.draw.line(self.lineColor,points[0],points[1],3)
|
[
|
||||||
|
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:
|
if self.tick == 120:
|
||||||
self.tick = 0
|
self.tick = 0
|
||||||
else:
|
else:
|
||||||
self.surface.draw.rect(self.bg,_r(self.borderWidth,self.borderWidth,
|
self.surface.draw.rect(
|
||||||
self.surface.size[0]-self.borderWidth*2,
|
self.bg,
|
||||||
self.surface.size[1]-self.borderWidth*2))
|
_r(
|
||||||
if self.text == '':
|
self.borderWidth,
|
||||||
text = self.font.render(self.hint,self.fontSize,self.hintColor)
|
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:
|
else:
|
||||||
text = self.font.render(self.text,self.fontSize,self.fg)
|
text = self.font.render(self.text, self.fontSize, self.fg)
|
||||||
x = self.surface.size[0]/2-text.size[0]/2
|
x = self.surface.size[0] / 2 - text.size[0] / 2
|
||||||
if text.size[0] >= self.surface.size[0]-20:
|
if text.size[0] >= self.surface.size[0] - 20:
|
||||||
x = self.surface.size[0]-text.size[0]-10
|
x = self.surface.size[0] - text.size[0] - 10
|
||||||
self.surface.blit(text,(x,self.surface.size[1]/2-text.size[1]/2))
|
self.surface.blit(text, (x, self.surface.size[1] / 2 - text.size[1] / 2))
|
||||||
|
|
||||||
if position != None:
|
if position is not None:
|
||||||
if self.surface.rect(position[0],
|
if self.surface.rect(position[0], position[1]).contains(
|
||||||
position[1]).contains(_m.getPosition()[0],
|
_m.getPosition()[0], _m.getPosition()[1]
|
||||||
_m.getPosition()[1]):
|
):
|
||||||
if not self.wcl:
|
if not self.wcl:
|
||||||
_m.setCursor(pygame.SYSTEM_CURSOR_HAND)
|
_m.setCursor(pygame.SYSTEM_CURSOR_HAND)
|
||||||
else:
|
else:
|
||||||
if not self.ws:
|
if not self.ws:
|
||||||
_m.setCursor(pygame.SYSTEM_CURSOR_ARROW)
|
_m.setCursor(pygame.SYSTEM_CURSOR_ARROW)
|
||||||
self.ws = True
|
self.ws = True
|
||||||
if _m.isPressed('left'):
|
if _m.isPressed("left"):
|
||||||
if not self.wcl:
|
if not self.wcl:
|
||||||
self.focus=self.focus==0
|
self.focus = self.focus == 0
|
||||||
self.wcl = True
|
self.wcl = True
|
||||||
else:
|
else:
|
||||||
self.wcl = False
|
self.wcl = False
|
||||||
|
@ -107,10 +136,12 @@ class keySelect(entry):
|
||||||
if not self.wsnr:
|
if not self.wsnr:
|
||||||
_m.setCursor(pygame.SYSTEM_CURSOR_ARROW)
|
_m.setCursor(pygame.SYSTEM_CURSOR_ARROW)
|
||||||
self.wsnr = True
|
self.wsnr = True
|
||||||
if _m.isPressed('left'):
|
if _m.isPressed("left"):
|
||||||
self.focus = False
|
self.focus = False
|
||||||
|
|
||||||
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)
|
||||||
|
|
||||||
def get(self):
|
def get(self):
|
||||||
return self.text
|
return self.text
|
||||||
|
|
|
@ -1,15 +1,7 @@
|
||||||
import ...pygame
|
from ...font import deaultFont as _df
|
||||||
from ...surface import surface as _s
|
from .base import widget
|
||||||
from ...font import defaultFont as _df
|
|
||||||
from ...image import load as _l
|
|
||||||
from ...rect import rect as _r
|
|
||||||
import ...mouse as _m
|
|
||||||
import ...keyboard as _k
|
|
||||||
import ctypes as _ct
|
|
||||||
import copy as _copy
|
|
||||||
|
|
||||||
class label(widget):
|
class label(widget):
|
||||||
def __init__(self,text,size=30,
|
def __init__(self, text, size=30, color=(0, 0, 0), font=_df):
|
||||||
color=(0,0,0),font=_df):
|
self.surface = font.render(text, size, color)
|
||||||
self.surface = font.render(text,size,color)
|
|
||||||
|
|
||||||
|
|
|
@ -1,43 +1,52 @@
|
||||||
import ...pygame
|
|
||||||
from ...surface import surface as _s
|
from ...surface import surface as _s
|
||||||
from ...font import defaultFont as _df
|
|
||||||
from ...image import load as _l
|
|
||||||
from ...rect import rect as _r
|
from ...rect import rect as _r
|
||||||
import ...mouse as _m
|
from .base import widget
|
||||||
import ...keyboard as _k
|
|
||||||
import ctypes as _ct
|
|
||||||
import copy as _copy
|
|
||||||
|
|
||||||
class loadingBar(widget):
|
class loadingBar(widget):
|
||||||
def __init__(self,width,
|
def __init__(
|
||||||
height=50,
|
self,
|
||||||
length=100,
|
width,
|
||||||
bg=(70,70,70),
|
height=50,
|
||||||
loadedColor=(50,200,50),
|
length=100,
|
||||||
borderColor=(50,50,50),
|
bg=(70, 70, 70),
|
||||||
borderWidth=5):
|
loadedColor=(50, 200, 50),
|
||||||
|
borderColor=(50, 50, 50),
|
||||||
|
borderWidth=5,
|
||||||
|
):
|
||||||
super()._args(locals())
|
super()._args(locals())
|
||||||
self.loaded = 0
|
self.loaded = 0
|
||||||
def step(self,count=1):
|
|
||||||
|
def step(self, count=1):
|
||||||
self.loaded += 1
|
self.loaded += 1
|
||||||
if self.loaded > self.length:
|
if self.loaded > self.length:
|
||||||
self.loaded = self.length
|
self.loaded = self.length
|
||||||
|
|
||||||
def set(self, x):
|
def set(self, x):
|
||||||
self.loaded = x
|
self.loaded = x
|
||||||
if self.loaded > self.length:
|
if self.loaded > self.length:
|
||||||
self.loaded = self.length
|
self.loaded = self.length
|
||||||
|
|
||||||
def reset(self):
|
def reset(self):
|
||||||
self.loaded = 0
|
self.loaded = 0
|
||||||
|
|
||||||
def get(self):
|
def get(self):
|
||||||
return self.loaded
|
return self.loaded
|
||||||
def draw(self, win, pos):
|
|
||||||
self.surface = _s((self.width,self.height))
|
|
||||||
self.surface.fill(self.borderColor)
|
|
||||||
self.surface.draw.rect(self.bg,_r(5,5,
|
|
||||||
self.surface.size[0]-10,
|
|
||||||
self.surface.size[1]-10))
|
|
||||||
self.surface.draw.rect(self.loadedColor,_r(self.borderWidth,self.borderWidth,
|
|
||||||
(self.surface.size[0]/self.length*self.loaded)-self.borderWidth*2,
|
|
||||||
self.surface.size[1]-self.borderWidth*2))
|
|
||||||
win.blit(self.surface, pos)
|
|
||||||
|
|
||||||
|
def draw(self, win, pos):
|
||||||
|
self.surface = _s((self.width, self.height))
|
||||||
|
self.surface.fill(self.borderColor)
|
||||||
|
self.surface.draw.rect(
|
||||||
|
self.bg, _r(5, 5, self.surface.size[0] - 10, self.surface.size[1] - 10)
|
||||||
|
)
|
||||||
|
self.surface.draw.rect(
|
||||||
|
self.loadedColor,
|
||||||
|
_r(
|
||||||
|
self.borderWidth,
|
||||||
|
self.borderWidth,
|
||||||
|
(self.surface.size[0] / self.length * self.loaded)
|
||||||
|
- self.borderWidth * 2,
|
||||||
|
self.surface.size[1] - self.borderWidth * 2,
|
||||||
|
),
|
||||||
|
)
|
||||||
|
win.blit(self.surface, pos)
|
||||||
|
|
|
@ -1,64 +1,74 @@
|
||||||
import ...pygame
|
|
||||||
from ...surface import surface as _s
|
from ...surface import surface as _s
|
||||||
from ...font import defaultFont as _df
|
|
||||||
from ...image import load as _l
|
|
||||||
from ...rect import rect as _r
|
from ...rect import rect as _r
|
||||||
import ...mouse as _m
|
from ... import mouse as _m
|
||||||
import ...keyboard as _k
|
from .base import widget
|
||||||
import ctypes as _ct
|
|
||||||
import copy as _copy
|
|
||||||
|
|
||||||
class slider(widget):
|
class slider(widget):
|
||||||
def __init__(self,width,
|
def __init__(self, width, bg=(70, 70, 70), fg=(200, 200, 200), horizontal=True):
|
||||||
bg=(70,70,70),
|
|
||||||
fg=(200,200,200),
|
|
||||||
horizontal=True):
|
|
||||||
super()._args(locals())
|
super()._args(locals())
|
||||||
self.s = False
|
self.s = False
|
||||||
self.x = 12.5
|
self.x = 12.5
|
||||||
self._generate(None)
|
self._generate(None)
|
||||||
|
|
||||||
def _generate(self, pos):
|
def _generate(self, pos):
|
||||||
if self.horizontal:
|
if self.horizontal:
|
||||||
self.surface = _s((self.width,50))
|
self.surface = _s((self.width, 50))
|
||||||
self.surface.draw.line(self.bg,[12.5,25],[self.width-12.5,25],10)
|
self.surface.draw.line(self.bg, [12.5, 25], [self.width - 12.5, 25], 10)
|
||||||
self.surface.draw.circle(self.bg,[12.5,26],5)
|
self.surface.draw.circle(self.bg, [12.5, 26], 5)
|
||||||
self.surface.draw.circle(self.bg,[self.width-12.5,26],5)
|
self.surface.draw.circle(self.bg, [self.width - 12.5, 26], 5)
|
||||||
self.surface.draw.circle(self.fg,[self.x,25],12.5)
|
self.surface.draw.circle(self.fg, [self.x, 25], 12.5)
|
||||||
else:
|
else:
|
||||||
self.surface = _s((50,self.width))
|
self.surface = _s((50, self.width))
|
||||||
self.surface.draw.line(self.bg,[25,12.5],[25,self.width-12.5],10)
|
self.surface.draw.line(self.bg, [25, 12.5], [25, self.width - 12.5], 10)
|
||||||
self.surface.draw.circle(self.bg,[26,12.5],5)
|
self.surface.draw.circle(self.bg, [26, 12.5], 5)
|
||||||
self.surface.draw.circle(self.bg,[26,self.width-12.5],5)
|
self.surface.draw.circle(self.bg, [26, self.width - 12.5], 5)
|
||||||
self.surface.draw.circle(self.fg,[25,self.x],12.5)
|
self.surface.draw.circle(self.fg, [25, self.x], 12.5)
|
||||||
if pos != None:
|
if pos is not None:
|
||||||
if _m.isPressed('left'):
|
if _m.isPressed("left"):
|
||||||
if self.horizontal:
|
if self.horizontal:
|
||||||
rect = _r(pos[0]+5,pos[1],
|
rect = _r(
|
||||||
self.surface.size[0]-10,
|
pos[0] + 5,
|
||||||
self.surface.size[1])
|
pos[1],
|
||||||
if rect.contains(_m.getPosition()[0],
|
self.surface.size[0] - 10,
|
||||||
_m.getPosition()[1]) or self.s:
|
self.surface.size[1],
|
||||||
self.x = _m.getPosition()[0]-pos[0]
|
)
|
||||||
if self.x < 12.5: self.x = 12.5
|
if (
|
||||||
if self.x > self.width-12.5: self.x = self.width-12.5
|
rect.contains(_m.getPosition()[0], _m.getPosition()[1])
|
||||||
|
or self.s
|
||||||
|
):
|
||||||
|
self.x = _m.getPosition()[0] - pos[0]
|
||||||
|
if self.x < 12.5:
|
||||||
|
self.x = 12.5
|
||||||
|
if self.x > self.width - 12.5:
|
||||||
|
self.x = self.width - 12.5
|
||||||
self.s = True
|
self.s = True
|
||||||
else:
|
else:
|
||||||
rect = _r(pos[0],pos[1]+5,
|
rect = _r(
|
||||||
self.surface.size[0],
|
pos[0],
|
||||||
self.surface.size[1]-10)
|
pos[1] + 5,
|
||||||
if rect.contains(_m.getPosition()[0],
|
self.surface.size[0],
|
||||||
_m.getPosition()[1]) or self.s:
|
self.surface.size[1] - 10,
|
||||||
self.x = _m.getPosition()[1]-pos[1]
|
)
|
||||||
if self.x < 12.5: self.x = 12.5
|
if (
|
||||||
if self.x > self.width-12.5: self.x = self.width-12.5
|
rect.contains(_m.getPosition()[0], _m.getPosition()[1])
|
||||||
|
or self.s
|
||||||
|
):
|
||||||
|
self.x = _m.getPosition()[1] - pos[1]
|
||||||
|
if self.x < 12.5:
|
||||||
|
self.x = 12.5
|
||||||
|
if self.x > self.width - 12.5:
|
||||||
|
self.x = self.width - 12.5
|
||||||
self.s = True
|
self.s = True
|
||||||
else:
|
else:
|
||||||
self.s = False
|
self.s = False
|
||||||
|
|
||||||
def get(self):
|
def get(self):
|
||||||
return int(self.x/(self.width-10)*101)
|
return int(self.x / (self.width - 10) * 101)
|
||||||
|
|
||||||
def set(self, x):
|
def set(self, x):
|
||||||
self.x = x/101*(self.width-10)
|
self.x = x / 101 * (self.width - 10)
|
||||||
|
|
||||||
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)
|
||||||
|
|
||||||
|
|
|
@ -1,121 +1,154 @@
|
||||||
import ...pygame
|
from ... import pygame
|
||||||
from ...surface import surface as _s
|
from ...surface import surface as _s
|
||||||
from ...font import defaultFont as _df
|
from ...font import deaultFont as _df
|
||||||
from ...image import load as _l
|
|
||||||
from ...rect import rect as _r
|
from ...rect import rect as _r
|
||||||
import ...mouse as _m
|
from ... import mouse as _m
|
||||||
import ...keyboard as _k
|
from ... import keyboard as _k
|
||||||
import ctypes as _ct
|
from ... import pes as _ct
|
||||||
import copy as _copy
|
from .base import widget
|
||||||
|
|
||||||
|
|
||||||
class textarea(widget):
|
class textarea(widget):
|
||||||
def __init__(self,hint='',fontSize=30,
|
def __init__(
|
||||||
font=_df,width=None,bg=(70,70,70),
|
self,
|
||||||
fg=(180,180,200),afg=(200,200,200),
|
hint="",
|
||||||
abg=(50,50,50),hintColor=(100,100,100),
|
fontSize=30,
|
||||||
lineColor=(200,200,200),
|
font=_df,
|
||||||
borderColor=(50,50,50),
|
width=None,
|
||||||
borderWidth=5,maxSymbols=None,
|
bg=(70, 70, 70),
|
||||||
whitelist=None,blacklist=[]):
|
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())
|
super()._args(locals())
|
||||||
self.text = ''
|
self.text = ""
|
||||||
self.focus = False
|
self.focus = False
|
||||||
self.tick = 0
|
self.tick = 0
|
||||||
self.wcl = False
|
self.wcl = False
|
||||||
self.startHint = self.hint
|
self.startHint = self.hint
|
||||||
self.ws = False
|
self.ws = False
|
||||||
if self.hint != '':
|
if self.hint != "":
|
||||||
hintSize = self.font.size(self.hint,self.fontSize)
|
hintSize = self.font.size(self.hint, self.fontSize)
|
||||||
else:
|
else:
|
||||||
hintSize = (150,self.font.size('X',self.fontSize)[1])
|
hintSize = (150, self.font.size("X", self.fontSize)[1])
|
||||||
self.height = hintSize[1]+10
|
self.height = hintSize[1] + 10
|
||||||
if self.width == None:
|
if self.width is None:
|
||||||
self.width = hintSize[0]+50
|
self.width = hintSize[0] + 50
|
||||||
self.surface = _s((self.width,self.height))
|
self.surface = _s((self.width, self.height))
|
||||||
self.wclk = []
|
self.wclk = []
|
||||||
self.wsnr = False
|
self.wsnr = False
|
||||||
def _generate(self,position=None):
|
|
||||||
|
def _generate(self, position=None):
|
||||||
self.surface.fill(self.borderColor)
|
self.surface.fill(self.borderColor)
|
||||||
if self.focus:
|
if self.focus:
|
||||||
if self.text != '':
|
if self.text != "":
|
||||||
self.height = self.font.size(self.text,self.fontSize)[1]+10
|
self.height = self.font.size(self.text, self.fontSize)[1] + 10
|
||||||
else:
|
else:
|
||||||
self.height = self.font.size('X',self.fontSize)[1]+10
|
self.height = self.font.size("X", self.fontSize)[1] + 10
|
||||||
self.surface = _s((self.width,self.height))
|
self.surface = _s((self.width, self.height))
|
||||||
self.surface.fill(self.borderColor)
|
self.surface.fill(self.borderColor)
|
||||||
self.surface.draw.rect(self.abg,_r(self.borderWidth,self.borderWidth,
|
self.surface.draw.rect(
|
||||||
self.surface.size[0]-self.borderWidth*2,
|
self.abg,
|
||||||
self.surface.size[1]-self.borderWidth*2))
|
_r(
|
||||||
if self.text == '':
|
self.borderWidth,
|
||||||
text = self.font.render(self.hint,self.fontSize,self.hintColor)
|
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:
|
else:
|
||||||
text = self.font.render(self.text,self.fontSize,self.afg)
|
text = self.font.render(self.text, self.fontSize, self.afg)
|
||||||
try:
|
try:
|
||||||
last = self.text.split('\n')[-1]
|
last = self.text.split("\n")[-1]
|
||||||
except:
|
except Exception as _:
|
||||||
last = self.text
|
last = self.text
|
||||||
x = 10
|
x = 10
|
||||||
if self.font.size(last,self.fontSize)[0] >= self.surface.size[0]-20:
|
if self.font.size(last, self.fontSize)[0] >= self.surface.size[0] - 20:
|
||||||
x = self.surface.size[0]-self.font.size(last,self.fontSize)[0]
|
x = self.surface.size[0] - self.font.size(last, self.fontSize)[0]
|
||||||
self.surface.blit(text,(x,self.surface.size[1]/2-text.size[1]/2))
|
self.surface.blit(text, (x, self.surface.size[1] / 2 - text.size[1] / 2))
|
||||||
for i in _k.getPressed().items():
|
for i in _k.getPressed().items():
|
||||||
if i[1]:
|
if i[1]:
|
||||||
if i[0] not in self.wclk:
|
if i[0] not in self.wclk:
|
||||||
if len(i[0]) == 1:
|
if len(i[0]) == 1:
|
||||||
self.insert(i[0])
|
self.insert(i[0])
|
||||||
elif i[0] == 'backspace':
|
elif i[0] == "backspace":
|
||||||
self.delete()
|
self.delete()
|
||||||
elif i[0] == 'return':
|
elif i[0] == "return":
|
||||||
if self.maxSymbols != None:
|
if self.maxSymbols is not None:
|
||||||
if len(self.text) > self.maxSymbols:
|
if len(self.text) > self.maxSymbols:
|
||||||
continue
|
continue
|
||||||
self.text += '\n'
|
self.text += "\n"
|
||||||
elif i[0] == 'space':
|
elif i[0] == "space":
|
||||||
self.insert(' ')
|
self.insert(" ")
|
||||||
self.wclk.append(i[0])
|
self.wclk.append(i[0])
|
||||||
else:
|
else:
|
||||||
if i[0] in self.wclk:
|
if i[0] in self.wclk:
|
||||||
self.wclk.remove(i[0])
|
self.wclk.remove(i[0])
|
||||||
self.tick += 1
|
self.tick += 1
|
||||||
if self.tick >= 60:
|
if self.tick >= 60:
|
||||||
if self.text != '':
|
if self.text != "":
|
||||||
points = [[x+self.font.size(last,self.fontSize)[0],
|
points = [
|
||||||
self.surface.size[1]-(self.font.size('X',self.fontSize)[1])],
|
[
|
||||||
[x+self.font.size(last,self.fontSize)[0],
|
x + self.font.size(last, self.fontSize)[0],
|
||||||
self.surface.size[1]/2-text.size[1]/2+self.surface.size[1]-10]]
|
self.surface.size[1]
|
||||||
self.surface.draw.line(self.lineColor,points[0],points[1],3)
|
- (self.font.size("X", self.fontSize)[1]),
|
||||||
|
],
|
||||||
|
[
|
||||||
|
x + self.font.size(last, self.fontSize)[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:
|
if self.tick == 120:
|
||||||
self.tick = 0
|
self.tick = 0
|
||||||
else:
|
else:
|
||||||
self.surface.draw.rect(self.bg,_r(self.borderWidth,self.borderWidth,
|
self.surface.draw.rect(
|
||||||
self.surface.size[0]-self.borderWidth*2,
|
self.bg,
|
||||||
self.surface.size[1]-self.borderWidth*2))
|
_r(
|
||||||
if self.text == '':
|
self.borderWidth,
|
||||||
text = self.font.render(self.hint,self.fontSize,self.hintColor)
|
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:
|
else:
|
||||||
text = self.font.render(self.text,self.fontSize,self.fg)
|
text = self.font.render(self.text, self.fontSize, self.fg)
|
||||||
try:
|
try:
|
||||||
last = self.text.split('\n')[-1]
|
last = self.text.split("\n")[-1]
|
||||||
except:
|
except Exception as _:
|
||||||
last = self.text
|
last = self.text
|
||||||
x = self.surface.size[0]/2-text.size[0]/2
|
x = self.surface.size[0] / 2 - text.size[0] / 2
|
||||||
if self.font.size(last,self.fontSize)[0] >= self.surface.size[0]-20:
|
if self.font.size(last, self.fontSize)[0] >= self.surface.size[0] - 20:
|
||||||
x = self.surface.size[0]-self.font.size(last,self.fontSize)[0]
|
x = self.surface.size[0] - self.font.size(last, self.fontSize)[0]
|
||||||
self.surface.blit(text,(x,self.surface.size[1]/2-text.size[1]/2))
|
self.surface.blit(text, (x, self.surface.size[1] / 2 - text.size[1] / 2))
|
||||||
|
|
||||||
if position != None:
|
if position is not None:
|
||||||
if self.surface.rect(position[0],
|
if self.surface.rect(position[0], position[1]).contains(
|
||||||
position[1]).contains(_m.getPosition()[0],
|
_m.getPosition()[0], _m.getPosition()[1]
|
||||||
_m.getPosition()[1]):
|
):
|
||||||
if not self.wcl:
|
if not self.wcl:
|
||||||
_m.setCursor(pygame.SYSTEM_CURSOR_HAND)
|
_m.setCursor(pygame.SYSTEM_CURSOR_HAND)
|
||||||
else:
|
else:
|
||||||
if not self.ws:
|
if not self.ws:
|
||||||
_m.setCursor(pygame.SYSTEM_CURSOR_ARROW)
|
_m.setCursor(pygame.SYSTEM_CURSOR_ARROW)
|
||||||
self.ws = True
|
self.ws = True
|
||||||
if _m.isPressed('left'):
|
if _m.isPressed("left"):
|
||||||
if not self.wcl:
|
if not self.wcl:
|
||||||
self.focus=self.focus==0
|
self.focus = self.focus == 0
|
||||||
self.wcl = True
|
self.wcl = True
|
||||||
else:
|
else:
|
||||||
self.wcl = False
|
self.wcl = False
|
||||||
|
@ -124,33 +157,55 @@ class textarea(widget):
|
||||||
if not self.wsnr:
|
if not self.wsnr:
|
||||||
_m.setCursor(pygame.SYSTEM_CURSOR_ARROW)
|
_m.setCursor(pygame.SYSTEM_CURSOR_ARROW)
|
||||||
self.wsnr = True
|
self.wsnr = True
|
||||||
if _m.isPressed('left'):
|
if _m.isPressed("left"):
|
||||||
self.focus = False
|
self.focus = False
|
||||||
def insert(self,text):
|
|
||||||
|
def insert(self, text):
|
||||||
if _ct.WinDLL("User32.dll").GetKeyState(0x14):
|
if _ct.WinDLL("User32.dll").GetKeyState(0x14):
|
||||||
text = text.upper()
|
text = text.upper()
|
||||||
if pygame.key.get_pressed()[pygame.K_LSHIFT] or pygame.key.get_pressed()[pygame.K_RSHIFT]:
|
if (
|
||||||
text = text.translate(dict(zip(map(ord, '''1234567890-=[]\\;'''+"',./`"),
|
pygame.key.get_pressed()[pygame.K_LSHIFT]
|
||||||
'''!@#$%^&*()_+{}|:"<>?~''')))
|
or pygame.key.get_pressed()[pygame.K_RSHIFT]
|
||||||
if hex(getattr(_ct.windll.LoadLibrary("user32.dll"),
|
):
|
||||||
"GetKeyboardLayout")(0))=='0x4190419':
|
text = text.translate(
|
||||||
text = text.translate(dict(zip(map(ord,
|
dict(
|
||||||
'''qwertyuiop[]asdfghjkl;'zxcvbnm,./`QWERTYUIOP{}ASDFGHJKL:"ZXCVBNM<>?~'''),
|
zip(
|
||||||
'''йцукенгшщзхъфывапролджэячсмитьбю.ёЙЦУКЕНГШЩЗХЪФЫВАПРОЛДЖЭЯЧСМИТЬБЮ,Ё''')))
|
map(ord, """1234567890-=[]\\;""" + "',./`"),
|
||||||
|
"""!@#$%^&*()_+{}|:"<>?~""",
|
||||||
|
)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
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:
|
if text in self.blacklist:
|
||||||
return
|
return
|
||||||
if self.whitelist != None:
|
if self.whitelist is not None:
|
||||||
if text not in self.whitelist:
|
if text not in self.whitelist:
|
||||||
return
|
return
|
||||||
if self.maxSymbols != None:
|
if self.maxSymbols is not None:
|
||||||
if len(self.text) > self.maxSymbols:
|
if len(self.text) > self.maxSymbols:
|
||||||
return
|
return
|
||||||
self.text += text
|
self.text += text
|
||||||
def delete(self,symbols=1):
|
|
||||||
self.text = self.text[:0-symbols]
|
def delete(self, symbols=1):
|
||||||
|
self.text = self.text[: 0 - symbols]
|
||||||
|
|
||||||
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)
|
||||||
|
|
||||||
def get(self):
|
def get(self):
|
||||||
return self.text
|
return self.text
|
||||||
|
|
||||||
|
|
|
@ -1,55 +1,71 @@
|
||||||
import ...pygame
|
|
||||||
from ...surface import surface as _s
|
from ...surface import surface as _s
|
||||||
from ...font import defaultFont as _df
|
from ...font import deaultFont as _df
|
||||||
from ...image import load as _l
|
|
||||||
from ...rect import rect as _r
|
from ...rect import rect as _r
|
||||||
import ...mouse as _m
|
from ... import mouse as _m
|
||||||
import ...keyboard as _k
|
from .base import widget
|
||||||
import ctypes as _ct
|
|
||||||
import copy as _copy
|
|
||||||
|
|
||||||
class tip(widget):
|
class tip(widget):
|
||||||
def __init__(self,text,responceWidth,responceHeight,fontSize=15,font=_df,
|
def __init__(
|
||||||
borderColor=(180,180,50),borderWidth=2,bg=(255,255,128),
|
self,
|
||||||
fg=(35,35,5),waitBeforeShowing=0,
|
text,
|
||||||
tipPosRelativeCursor=(10,10)):
|
responceWidth,
|
||||||
|
responceHeight,
|
||||||
|
fontSize=15,
|
||||||
|
font=_df,
|
||||||
|
borderColor=(180, 180, 50),
|
||||||
|
borderWidth=2,
|
||||||
|
bg=(255, 255, 128),
|
||||||
|
fg=(35, 35, 5),
|
||||||
|
waitBeforeShowing=0,
|
||||||
|
tipPosRelativeCursor=(10, 10),
|
||||||
|
):
|
||||||
super()._args(locals())
|
super()._args(locals())
|
||||||
self.tick = -1
|
self.tick = -1
|
||||||
self.lcp = (0,0)
|
self.lcp = (0, 0)
|
||||||
self.tprc = self.tipPosRelativeCursor
|
self.tprc = self.tipPosRelativeCursor
|
||||||
self._generate()
|
self._generate()
|
||||||
|
|
||||||
def _generate(self, position=None):
|
def _generate(self, position=None):
|
||||||
self.surface = _s((self.responceWidth,
|
self.surface = _s((self.responceWidth, self.responceHeight))
|
||||||
self.responceHeight))
|
if position is not None:
|
||||||
if position != None:
|
|
||||||
self.tick += 1
|
self.tick += 1
|
||||||
if self.lcp != _m.getPosition():
|
if self.lcp != _m.getPosition():
|
||||||
self.tick = 0
|
self.tick = 0
|
||||||
self.lcp = _m.getPosition()
|
self.lcp = _m.getPosition()
|
||||||
if self.tick >= self.waitBeforeShowing:
|
if self.tick >= self.waitBeforeShowing:
|
||||||
mp = _m.getPosition()
|
mp = _m.getPosition()
|
||||||
mp = [mp[0]+self.tprc[0]-position[0],
|
mp = [
|
||||||
mp[1]+self.tprc[1]-position[1]]
|
mp[0] + self.tprc[0] - position[0],
|
||||||
rect = _r(mp[0],mp[1],
|
mp[1] + self.tprc[1] - position[1],
|
||||||
self.font.size(self.text,self.fontSize)[0]+4,
|
]
|
||||||
self.font.size(self.text,self.fontSize)[1]+6)
|
rect = _r(
|
||||||
if mp[0]<0 or mp[1]<0:return
|
mp[0],
|
||||||
if mp[0]>self.responceWidth:return
|
mp[1],
|
||||||
if mp[1]>self.responceHeight:return
|
self.font.size(self.text, self.fontSize)[0] + 4,
|
||||||
if mp[0]>self.responceWidth-rect.w:
|
self.font.size(self.text, self.fontSize)[1] + 6,
|
||||||
mp[0]=self.responceWidth-rect.w
|
)
|
||||||
if mp[1]>self.responceHeight-rect.h:
|
if mp[0] < 0 or mp[1] < 0:
|
||||||
mp[1]=self.responceHeight-rect.h
|
return
|
||||||
rect = _r(mp[0],mp[1],
|
if mp[0] > self.responceWidth:
|
||||||
self.font.size(self.text,self.fontSize)[0]+4,
|
return
|
||||||
self.font.size(self.text,self.fontSize)[1]+6)
|
if mp[1] > self.responceHeight:
|
||||||
self.surface.draw.rect(self.bg,rect)
|
return
|
||||||
self.surface.draw.rect(
|
if mp[0] > self.responceWidth - rect.w:
|
||||||
self.borderColor,rect,self.borderWidth)
|
mp[0] = self.responceWidth - rect.w
|
||||||
ts = self.font.render(
|
if mp[1] > self.responceHeight - rect.h:
|
||||||
self.text,self.fontSize,self.fg)
|
mp[1] = self.responceHeight - rect.h
|
||||||
self.surface.blit(ts,(mp[0]+2,mp[1]+3))
|
rect = _r(
|
||||||
|
mp[0],
|
||||||
|
mp[1],
|
||||||
|
self.font.size(self.text, self.fontSize)[0] + 4,
|
||||||
|
self.font.size(self.text, self.fontSize)[1] + 6,
|
||||||
|
)
|
||||||
|
self.surface.draw.rect(self.bg, rect)
|
||||||
|
self.surface.draw.rect(self.borderColor, rect, self.borderWidth)
|
||||||
|
ts = self.font.render(self.text, self.fontSize, self.fg)
|
||||||
|
self.surface.blit(ts, (mp[0] + 2, mp[1] + 3))
|
||||||
|
|
||||||
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)
|
||||||
|
|
||||||
|
|
|
@ -3,12 +3,14 @@ from pygwin.tray import tray as _tray
|
||||||
from datetime import datetime as _dt
|
from datetime import datetime as _dt
|
||||||
from pygwin.image import save as _s
|
from pygwin.image import save as _s
|
||||||
from pygwin.pygame import pg as pygame
|
from pygwin.pygame import pg as pygame
|
||||||
|
|
||||||
try:
|
try:
|
||||||
import win32job
|
import win32job
|
||||||
import win32api
|
import win32api
|
||||||
import win32con
|
import win32con
|
||||||
import win32gui
|
import win32gui
|
||||||
import winerror
|
import winerror
|
||||||
|
|
||||||
nonwin = False
|
nonwin = False
|
||||||
except Exception as _:
|
except Exception as _:
|
||||||
nonwin = True
|
nonwin = True
|
||||||
|
@ -16,6 +18,7 @@ import sys
|
||||||
import threading
|
import threading
|
||||||
import mouse
|
import mouse
|
||||||
|
|
||||||
|
|
||||||
class _win(_surface):
|
class _win(_surface):
|
||||||
def __init__(self, iconpath=None):
|
def __init__(self, iconpath=None):
|
||||||
self._orig = pygame.display.get_surface()
|
self._orig = pygame.display.get_surface()
|
||||||
|
@ -26,44 +29,59 @@ class _win(_surface):
|
||||||
self._iconpath = iconpath
|
self._iconpath = iconpath
|
||||||
self._isallowdrag = False
|
self._isallowdrag = False
|
||||||
if iconpath is not None:
|
if iconpath is not None:
|
||||||
self.tray = _tray(self.title,iconpath)
|
self.tray = _tray(self.title, iconpath)
|
||||||
|
|
||||||
def update(self, fps=-1):
|
def update(self, fps=-1):
|
||||||
if fps != -1:
|
if fps != -1:
|
||||||
self._clock.tick(fps)
|
self._clock.tick(fps)
|
||||||
self._withfps = True
|
self._withfps = True
|
||||||
pygame.display.update()
|
pygame.display.update()
|
||||||
|
|
||||||
def resize(self, size=None):
|
def resize(self, size=None):
|
||||||
if size is None:
|
if size is None:
|
||||||
return self.size
|
return self.size
|
||||||
else:
|
else:
|
||||||
self._orig = pygame.display.set_mode(size)
|
self._orig = pygame.display.set_mode(size)
|
||||||
|
|
||||||
def title():
|
def title():
|
||||||
def fget(self):
|
def fget(self):
|
||||||
return pygame.display.get_caption()[0]
|
return pygame.display.get_caption()[0]
|
||||||
|
|
||||||
def fset(self, value):
|
def fset(self, value):
|
||||||
if type(value) is str:
|
if type(value) is str:
|
||||||
return
|
return
|
||||||
pygame.display.set_caption(value)
|
pygame.display.set_caption(value)
|
||||||
|
|
||||||
def fdel(self):
|
def fdel(self):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
return locals()
|
return locals()
|
||||||
|
|
||||||
title = property(**title())
|
title = property(**title())
|
||||||
|
|
||||||
def icon(self, value):
|
def icon(self, value):
|
||||||
pygame.display.set_icon(pygame.image.load(value))
|
pygame.display.set_icon(pygame.image.load(value))
|
||||||
self._iconpath = value
|
self._iconpath = value
|
||||||
|
|
||||||
def size():
|
def size():
|
||||||
def fget(self):
|
def fget(self):
|
||||||
return pygame.display.get_window_size()
|
return pygame.display.get_window_size()
|
||||||
|
|
||||||
def fset(self, value):
|
def fset(self, value):
|
||||||
if type(value) in [list,tuple]:
|
if type(value) in [list, tuple]:
|
||||||
return
|
return
|
||||||
pygame.display.set_mode(value)
|
pygame.display.set_mode(value)
|
||||||
|
|
||||||
def fdel(self):
|
def fdel(self):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
return locals()
|
return locals()
|
||||||
|
|
||||||
size = property(**size())
|
size = property(**size())
|
||||||
|
|
||||||
def fullscreen(self):
|
def fullscreen(self):
|
||||||
pygame.display.toogle_fullscreen()
|
pygame.display.toogle_fullscreen()
|
||||||
|
|
||||||
def close(self):
|
def close(self):
|
||||||
# win32gui.PostMessage(self.hwnd, win32con.WM_CLOSE, 0, 0)
|
# win32gui.PostMessage(self.hwnd, win32con.WM_CLOSE, 0, 0)
|
||||||
pygame.display.quit()
|
pygame.display.quit()
|
||||||
|
@ -71,6 +89,7 @@ class _win(_surface):
|
||||||
self.tray.stop()
|
self.tray.stop()
|
||||||
except Exception as _:
|
except Exception as _:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
def focus(self):
|
def focus(self):
|
||||||
if not nonwin:
|
if not nonwin:
|
||||||
self.hide()
|
self.hide()
|
||||||
|
@ -78,40 +97,53 @@ class _win(_surface):
|
||||||
win32gui.BringWindowToTop(self.hwnd)
|
win32gui.BringWindowToTop(self.hwnd)
|
||||||
win32gui.ShowWindow(self.hwnd, win32con.SW_SHOWNORMAL)
|
win32gui.ShowWindow(self.hwnd, win32con.SW_SHOWNORMAL)
|
||||||
win32gui.SetForegroundWindow(self.hwnd)
|
win32gui.SetForegroundWindow(self.hwnd)
|
||||||
|
|
||||||
def hide(self):
|
def hide(self):
|
||||||
if not nonwin:
|
if not nonwin:
|
||||||
win32gui.ShowWindow(self.hwnd, win32con.SW_HIDE)
|
win32gui.ShowWindow(self.hwnd, win32con.SW_HIDE)
|
||||||
|
|
||||||
def show(self):
|
def show(self):
|
||||||
if not nonwin:
|
if not nonwin:
|
||||||
win32gui.ShowWindow(self.hwnd, win32con.SW_SHOW)
|
win32gui.ShowWindow(self.hwnd, win32con.SW_SHOW)
|
||||||
|
|
||||||
def move(self, x, y):
|
def move(self, x, y):
|
||||||
if not nonwin:
|
if not nonwin:
|
||||||
rect = self._getRect()
|
rect = self._getRect()
|
||||||
win32gui.MoveWindow(self.hwnd, int(x), int(y),
|
win32gui.MoveWindow(self.hwnd, int(x), int(y), rect[2] - x, rect[3] - y, 0)
|
||||||
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=pygame.display.get_desktop_sizes()[0][0]/2,
|
|
||||||
y=pygame.display.get_desktop_sizes()[0][1]/2):
|
def center(
|
||||||
self.move(x-self.size[0]/2,y-self.size[1]/2)
|
self,
|
||||||
|
x=pygame.display.get_desktop_sizes()[0][0] / 2,
|
||||||
|
y=pygame.display.get_desktop_sizes()[0][1] / 2,
|
||||||
|
):
|
||||||
|
self.move(x - self.size[0] / 2, y - self.size[1] / 2)
|
||||||
|
|
||||||
def _getRect(self):
|
def _getRect(self):
|
||||||
if not nonwin:
|
if not nonwin:
|
||||||
return win32gui.GetWindowRect(self.hwnd)
|
return win32gui.GetWindowRect(self.hwnd)
|
||||||
|
|
||||||
def denyDrag(self):
|
def denyDrag(self):
|
||||||
if not nonwin:
|
if not nonwin:
|
||||||
self._isallowdrag = True
|
self._isallowdrag = True
|
||||||
|
|
||||||
def loop(self):
|
def loop(self):
|
||||||
while self._isallowdrag:
|
while self._isallowdrag:
|
||||||
pos = mouse.get_position()
|
pos = mouse.get_position()
|
||||||
pos = [pos[i]-self.position[i] for i in range(2)]
|
pos = [pos[i] - self.position[i] for i in range(2)]
|
||||||
if pos[0] < self._getRect()[2]-137:
|
if pos[0] < self._getRect()[2] - 137:
|
||||||
if pos[1] < 30:
|
if pos[1] < 30:
|
||||||
mouse.release('left')
|
mouse.release("left")
|
||||||
threading.Thread(target=lambda:loop(self),daemon=1).start()
|
|
||||||
|
threading.Thread(target=lambda: loop(self), daemon=1).start()
|
||||||
|
|
||||||
def allowDrag(self):
|
def allowDrag(self):
|
||||||
if not nonwin:
|
if not nonwin:
|
||||||
self._isallowdrag = False
|
self._isallowdrag = False
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def position(self):
|
def position(self):
|
||||||
if not nonwin:
|
if not nonwin:
|
||||||
|
@ -119,30 +151,35 @@ class _win(_surface):
|
||||||
x = rect[0]
|
x = rect[0]
|
||||||
y = rect[1]
|
y = rect[1]
|
||||||
return (x, y)
|
return (x, y)
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def rawFps(self):
|
def rawFps(self):
|
||||||
if self._withfps:
|
if self._withfps:
|
||||||
return self._clock.get_fps()
|
return self._clock.get_fps()
|
||||||
else:
|
else:
|
||||||
return float(f'2010.{_dt.now().year}')
|
return float(f"2010.{_dt.now().year}")
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def fps(self):
|
def fps(self):
|
||||||
return int(self.rawFps)
|
return int(self.rawFps)
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def hwnd(self):
|
def hwnd(self):
|
||||||
if not nonwin:
|
if not nonwin:
|
||||||
return pygame.display.get_wm_info()['window']
|
return pygame.display.get_wm_info()["window"]
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def visible(self):
|
def visible(self):
|
||||||
if not nonwin:
|
if not nonwin:
|
||||||
return win32gui.IsWindowVisible(self._win)
|
return win32gui.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):
|
||||||
pygame.display.set_mode(size)
|
pygame.display.set_mode(size)
|
||||||
if resizable:
|
if resizable:
|
||||||
pygame.display.set_mode(size,pygame.RESIZABLE)
|
pygame.display.set_mode(size, pygame.RESIZABLE)
|
||||||
if noframe:
|
if noframe:
|
||||||
pygame.display.set_mode(size,pygame.NOFRAME)
|
pygame.display.set_mode(size, pygame.NOFRAME)
|
||||||
else:
|
else:
|
||||||
if title is not None:
|
if title is not None:
|
||||||
pygame.display.set_caption(title)
|
pygame.display.set_caption(title)
|
||||||
|
@ -150,23 +187,30 @@ def create(title=None, size=(0,0), icon=None, resizable=False, noframe=False):
|
||||||
pygame.display.set_icon(pygame.image.load(icon))
|
pygame.display.set_icon(pygame.image.load(icon))
|
||||||
return _win(icon)
|
return _win(icon)
|
||||||
|
|
||||||
|
|
||||||
def ramLimit(memory_limit):
|
def ramLimit(memory_limit):
|
||||||
if not nonwin:
|
if not nonwin:
|
||||||
g_hjob = None
|
g_hjob = None
|
||||||
def create_job(job_name='', breakaway='silent'):
|
|
||||||
|
def create_job(job_name="", breakaway="silent"):
|
||||||
hjob = win32job.CreateJobObject(None, job_name)
|
hjob = win32job.CreateJobObject(None, job_name)
|
||||||
if breakaway:
|
if breakaway:
|
||||||
info = win32job.QueryInformationJobObject(hjob,
|
info = win32job.QueryInformationJobObject(
|
||||||
win32job.JobObjectExtendedLimitInformation)
|
hjob, win32job.JobObjectExtendedLimitInformation
|
||||||
if breakaway == 'silent':
|
)
|
||||||
info['BasicLimitInformation']['LimitFlags'] |= (
|
if breakaway == "silent":
|
||||||
win32job.JOB_OBJECT_LIMIT_SILENT_BREAKAWAY_OK)
|
info["BasicLimitInformation"]["LimitFlags"] |= (
|
||||||
|
win32job.JOB_OBJECT_LIMIT_SILENT_BREAKAWAY_OK
|
||||||
|
)
|
||||||
else:
|
else:
|
||||||
info['BasicLimitInformation']['LimitFlags'] |= (
|
info["BasicLimitInformation"]["LimitFlags"] |= (
|
||||||
win32job.JOB_OBJECT_LIMIT_BREAKAWAY_OK)
|
win32job.JOB_OBJECT_LIMIT_BREAKAWAY_OK
|
||||||
win32job.SetInformationJobObject(hjob,
|
)
|
||||||
win32job.JobObjectExtendedLimitInformation, info)
|
win32job.SetInformationJobObject(
|
||||||
|
hjob, win32job.JobObjectExtendedLimitInformation, info
|
||||||
|
)
|
||||||
return hjob
|
return hjob
|
||||||
|
|
||||||
def assign_job(hjob):
|
def assign_job(hjob):
|
||||||
if nonwin:
|
if nonwin:
|
||||||
return
|
return
|
||||||
|
@ -176,26 +220,35 @@ def ramLimit(memory_limit):
|
||||||
win32job.AssignProcessToJobObject(hjob, hprocess)
|
win32job.AssignProcessToJobObject(hjob, hprocess)
|
||||||
g_hjob = hjob
|
g_hjob = hjob
|
||||||
except win32job.error as e:
|
except win32job.error as e:
|
||||||
if (e._we != winerror.ERROR_ACCESS_DENIED or
|
if (
|
||||||
sys.getwindowsversion() >= (6, 2) or
|
e._we != winerror.ERROR_ACCESS_DENIED
|
||||||
not win32job.IsProcessInJob(hprocess, None)):
|
or sys.getwindowsversion() >= (6, 2)
|
||||||
|
or not win32job.IsProcessInJob(hprocess, None)
|
||||||
|
):
|
||||||
raise
|
raise
|
||||||
|
|
||||||
def limit_memory(memory_limit):
|
def limit_memory(memory_limit):
|
||||||
if g_hjob is None:
|
if g_hjob is None:
|
||||||
return
|
return
|
||||||
info = win32job.QueryInformationJobObject(g_hjob,
|
info = win32job.QueryInformationJobObject(
|
||||||
win32job.JobObjectExtendedLimitInformation)
|
g_hjob, win32job.JobObjectExtendedLimitInformation
|
||||||
info['ProcessMemoryLimit'] = memory_limit
|
)
|
||||||
info['BasicLimitInformation']['LimitFlags'] |= (
|
info["ProcessMemoryLimit"] = memory_limit
|
||||||
win32job.JOB_OBJECT_LIMIT_PROCESS_MEMORY)
|
info["BasicLimitInformation"]["LimitFlags"] |= (
|
||||||
win32job.SetInformationJobObject(g_hjob,
|
win32job.JOB_OBJECT_LIMIT_PROCESS_MEMORY
|
||||||
win32job.JobObjectExtendedLimitInformation, info)
|
)
|
||||||
|
win32job.SetInformationJobObject(
|
||||||
|
g_hjob, win32job.JobObjectExtendedLimitInformation, info
|
||||||
|
)
|
||||||
|
|
||||||
assign_job(create_job())
|
assign_job(create_job())
|
||||||
limit_memory(memory_limit)
|
limit_memory(memory_limit)
|
||||||
|
|
||||||
|
|
||||||
def close():
|
def close():
|
||||||
pygame.quit()
|
pygame.quit()
|
||||||
quit()
|
quit()
|
||||||
|
|
||||||
|
|
||||||
def getEvents():
|
def getEvents():
|
||||||
return pygame.event.get()
|
return pygame.event.get()
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue