py fixes
This commit is contained in:
@@ -1,5 +1,4 @@
|
||||
import app
|
||||
import constInfo
|
||||
import dbg
|
||||
|
||||
APP_GET_LOCALE_PATH = app.GetLocalePath()
|
||||
@@ -26,7 +25,7 @@ ERROR_MARK_CHECK_NEED_RECONNECT = 'CheckMark: Reconnect to game'
|
||||
VIRTUAL_KEY_ALPHABET_LOWERS = r"[1234567890]/qwertyuiop\=asdfghjkl;`'zxcvbnm.,"
|
||||
VIRTUAL_KEY_ALPHABET_UPPERS = r"{1234567890}?QWERTYUIOP|+ASDFGHJKL:~'ZXCVBNM<>"
|
||||
VIRTUAL_KEY_SYMBOLS = "!@#$%^&*()_+|{}:'<>?~"
|
||||
VIRTUAL_KEY_NUMBERS = "1234567890-=\[];',./`"
|
||||
VIRTUAL_KEY_NUMBERS = "1234567890-=\\[];',./`"
|
||||
VIRTUAL_KEY_SYMBOLS_BR = "!@#$%^&*()_+|{}:'<>?~aaaaeeeiioooouuc"
|
||||
|
||||
# Multi-language hot-reload support
|
||||
|
||||
@@ -7,6 +7,7 @@ import _frozen_importlib_external as _bootstrap_external
|
||||
import marshal
|
||||
import pack
|
||||
import __main__
|
||||
import re
|
||||
|
||||
# Keep import paths deterministic for the embedded runtime.
|
||||
sys.path = [p for p in sys.path if isinstance(p, str)]
|
||||
@@ -59,33 +60,77 @@ class pack_file_iterator(object):
|
||||
|
||||
_chr = builtins.chr
|
||||
|
||||
_SOURCE_ENCODING_RE = re.compile(br"coding[:=]\s*([-\w.]+)")
|
||||
|
||||
def _extract_source_encoding(data):
|
||||
for line in data.splitlines()[:2]:
|
||||
match = _SOURCE_ENCODING_RE.search(line)
|
||||
if not match:
|
||||
continue
|
||||
try:
|
||||
return match.group(1).decode("ascii")
|
||||
except Exception:
|
||||
return None
|
||||
return None
|
||||
|
||||
def _decode_pack_text(data):
|
||||
if isinstance(data, str):
|
||||
return data
|
||||
|
||||
if isinstance(data, bytearray):
|
||||
data = bytes(data)
|
||||
elif not isinstance(data, bytes):
|
||||
data = bytes(data)
|
||||
|
||||
encodings = []
|
||||
source_encoding = _extract_source_encoding(data)
|
||||
if source_encoding:
|
||||
encodings.append(source_encoding)
|
||||
encodings.extend(("utf-8-sig", "cp949", "latin-1"))
|
||||
|
||||
seen = set()
|
||||
for encoding in encodings:
|
||||
if encoding in seen:
|
||||
continue
|
||||
seen.add(encoding)
|
||||
try:
|
||||
return data.decode(encoding)
|
||||
except (LookupError, UnicodeDecodeError):
|
||||
pass
|
||||
|
||||
return data.decode("utf-8", "replace")
|
||||
|
||||
class pack_file(object):
|
||||
|
||||
def __init__(self, filename, mode = 'rb'):
|
||||
assert mode in ('r', 'rb')
|
||||
if not pack.Exist(filename):
|
||||
raise IOError('No file or directory')
|
||||
self.mode = mode
|
||||
self.data = pack.Get(filename)
|
||||
if mode == 'r':
|
||||
self.data=_chr(10).join(self.data.split(_chr(13)+_chr(10)))
|
||||
self.data = _decode_pack_text(self.data)
|
||||
self.data = self.data.replace(_chr(13) + _chr(10), _chr(10)).replace(_chr(13), _chr(10))
|
||||
|
||||
def __iter__(self):
|
||||
return pack_file_iterator(self)
|
||||
|
||||
def read(self, length = None):
|
||||
empty = b'' if self.mode == 'rb' else ''
|
||||
if not self.data:
|
||||
return ''
|
||||
return empty
|
||||
if length:
|
||||
tmp = self.data[:length]
|
||||
self.data = self.data[length:]
|
||||
return tmp
|
||||
else:
|
||||
tmp = self.data
|
||||
self.data = ''
|
||||
self.data = b'' if self.mode == 'rb' else ''
|
||||
return tmp
|
||||
|
||||
def readline(self):
|
||||
return self.read(self.data.find(_chr(10))+1)
|
||||
newline = b'\n' if self.mode == 'rb' else _chr(10)
|
||||
return self.read(self.data.find(newline)+1)
|
||||
|
||||
def readlines(self):
|
||||
return [x for x in self]
|
||||
@@ -293,7 +338,10 @@ def ShowException(excTitle):
|
||||
|
||||
def RunMainScript(name):
|
||||
try:
|
||||
exec(compile(open(name, "rb").read(), name, 'exec'), __main__.__dict__)
|
||||
source = open(name, "rb").read()
|
||||
if isinstance(source, (bytes, bytearray)):
|
||||
source = _decode_pack_text(source)
|
||||
exec(compile(source, name, 'exec'), __main__.__dict__)
|
||||
except RuntimeError as msg:
|
||||
msg = str(msg)
|
||||
|
||||
|
||||
@@ -196,10 +196,12 @@ class Window(object):
|
||||
return wndMgr.GetWindowRect(self.hWnd)
|
||||
|
||||
def SetPosition(self, x, y):
|
||||
wndMgr.SetWindowPosition(self.hWnd, x, y)
|
||||
wndMgr.SetWindowPosition(self.hWnd, int(x), int(y))
|
||||
|
||||
def SetCenterPosition(self, x = 0, y = 0):
|
||||
self.SetPosition((wndMgr.GetScreenWidth() - self.GetWidth()) / 2 + x, (wndMgr.GetScreenHeight() - self.GetHeight()) / 2 + y)
|
||||
center_x = (wndMgr.GetScreenWidth() - self.GetWidth()) // 2 + int(x)
|
||||
center_y = (wndMgr.GetScreenHeight() - self.GetHeight()) // 2 + int(y)
|
||||
self.SetPosition(center_x, center_y)
|
||||
|
||||
def IsFocus(self):
|
||||
return wndMgr.IsFocus(self.hWnd)
|
||||
@@ -2375,7 +2377,7 @@ class ListBox(Window):
|
||||
self._LocateItem()
|
||||
|
||||
def GetViewItemCount(self):
|
||||
return int(self.GetHeight() / self.stepSize)
|
||||
return int(self.GetHeight() // self.stepSize)
|
||||
|
||||
def GetItemCount(self):
|
||||
return len(self.itemList)
|
||||
@@ -2415,7 +2417,7 @@ class ListBox(Window):
|
||||
xMouse, yMouse = wndMgr.GetMousePosition()
|
||||
|
||||
if yMouse - y < height - 1:
|
||||
self.overLine = (yMouse - y) / self.stepSize
|
||||
self.overLine = (yMouse - y) // self.stepSize
|
||||
|
||||
if self.overLine < 0:
|
||||
self.overLine = -1
|
||||
@@ -2486,8 +2488,8 @@ class ListBox2(ListBox):
|
||||
gx, gy = self.GetGlobalPosition()
|
||||
lx, ly = px - gx, py - gy
|
||||
|
||||
col = lx / self.barWidth
|
||||
row = ly / self.stepSize
|
||||
col = lx // self.barWidth
|
||||
row = ly // self.stepSize
|
||||
idx = col * self.rowCount + row
|
||||
if col >= 0 and col < self.colCount:
|
||||
if row >= 0 and row < self.rowCount:
|
||||
@@ -2499,7 +2501,7 @@ class ListBox2(ListBox):
|
||||
def _CalcRenderPos(self, pos, idx):
|
||||
x, y = pos
|
||||
row = idx % self.rowCount
|
||||
col = idx / self.rowCount
|
||||
col = idx // self.rowCount
|
||||
return (x + col * self.barWidth, y + row * self.stepSize)
|
||||
|
||||
def _RenderBar(self, basePos, idx):
|
||||
@@ -2519,12 +2521,12 @@ class ListBox2(ListBox):
|
||||
|
||||
def _RefreshForm(self):
|
||||
if len(self.itemList) % self.rowCount:
|
||||
self.colCount = len(self.itemList) / self.rowCount + 1
|
||||
self.colCount = len(self.itemList) // self.rowCount + 1
|
||||
else:
|
||||
self.colCount = len(self.itemList) / self.rowCount
|
||||
self.colCount = len(self.itemList) // self.rowCount
|
||||
|
||||
if self.colCount:
|
||||
self.barWidth = self.width / self.colCount
|
||||
self.barWidth = self.width // self.colCount
|
||||
else:
|
||||
self.barWidth = self.width
|
||||
|
||||
@@ -2581,9 +2583,11 @@ class ComboBox(Window):
|
||||
self.listBox = None
|
||||
|
||||
def SetPosition(self, x, y):
|
||||
Window.SetPosition(self, x, y)
|
||||
self.x = x
|
||||
self.y = y
|
||||
ix = int(x)
|
||||
iy = int(y)
|
||||
Window.SetPosition(self, ix, iy)
|
||||
self.x = ix
|
||||
self.y = iy
|
||||
self.__ArrangeListBox()
|
||||
|
||||
def SetSize(self, width, height):
|
||||
|
||||
Reference in New Issue
Block a user