Revert "update pyglet"

This reverts commit 0173dd8b852facef2f800ab8cee81ec72afaec6d.

清理点东西
This commit is contained in:
shenjack 2022-06-20 21:08:57 +08:00
parent e9741b286f
commit 7715ee4d20
23 changed files with 83 additions and 410 deletions

View File

@ -21,5 +21,9 @@ class TexturesError(Error):
"""材质相关 error"""
class LanguageError(Error):
"""语言相关 error"""
class TestError(Error):
"""就像名字一样 用于测试的 error"""

View File

@ -1,15 +0,0 @@
# -------------------------------
# Difficult Rocket
# Copyright © 2021-2022 by shenjackyuanjie
# All rights reserved
# -------------------------------
from Difficult_Rocket.api.Exp import Error
class LanguageError(Error):
"""语言相关 error"""
class TranslateFileNotFoundError(LanguageError):
"""某个语言的翻译文件未找到"""

View File

@ -13,7 +13,9 @@ gitee: @shenjackyuanjie
# system function
import os
import sys
import time
import ctypes
import logging
import traceback
@ -29,17 +31,11 @@ from Difficult_Rocket.utils import tools, translate
from Difficult_Rocket.api.Exp.command import CommandError
from Difficult_Rocket.client.fps.fps_log import FpsLogger
# libs function
local_lib = True
if local_lib:
from libs import pyglet
from libs.pyglet.window import Window
from libs.pyglet.window import key, mouse
from libs import toml
else:
import pyglet
from pyglet.window import key, mouse
import toml
from libs import pyglet
from libs.pyglet.window import Window
from libs.pyglet.window import key, mouse
from libs import toml
class Client:
@ -133,7 +129,7 @@ class ClientWindow(Window):
multiline=True,
batch=self.label_batch, group=self.command_group)
# 设置刷新率
pyglet.clock.schedule(self.draw_update)
pyglet.clock.schedule_interval(self.update, float(self.SPF))
# 完成设置后的信息输出
self.logger.info(tr.lang('window', 'setup.done'))
self.logger.info(tr.lang('window', 'os.pid_is').format(os.getpid(), os.getppid()))
@ -204,6 +200,7 @@ class ClientWindow(Window):
def FPS_update(self, tick: Decimal):
now_FPS = pyglet.clock.get_frequency()
self.fps_log.update_tick(now_FPS, tick)
self.fps_label.text = f'FPS: {self.fps_log.fps: >5.1f}({self.fps_log.middle_fps: >5.1f})[{now_FPS: >.7f}]\n {self.fps_log.max_fps: >7.1f} {self.fps_log.min_fps:>5.1f}'
def on_draw(self, *dt):
@ -231,7 +228,7 @@ class ClientWindow(Window):
if command.match('stop'):
self.is_running = False
self.dispatch_event('on_exit')
platform_event_loop.stop()
# platform_event_loop.stop()
self.dispatch_event('on_close', 'command') # source = command
elif command.match('fps'):
if command.match('log'):

View File

@ -14,11 +14,6 @@ gitee: @shenjackyuanjie
from Difficult_Rocket import game_version
from Difficult_Rocket.command import line
class Command:
"""一个空类 用于标记命令信息"""
COMMAND = 'command'
SUB_COMMAND = 'sub_command'
INFO = 'info'

View File

@ -18,8 +18,6 @@ import logging
import logging.config
import multiprocessing
import pyglet.clock
if __name__ == '__main__': # been start will not run this
sys.path.append('/bin/libs')
sys.path.append('/bin')
@ -58,7 +56,6 @@ class Game:
def setup(self) -> None:
self.client = client.Client(net_mode='local')
pyglet.clock.schedule(self.client.window.draw_update)
self.server = server.Server(net_mode='local')
def python_version_check(self) -> None: # best 3.8+ and write at 3.8.10

View File

@ -43,6 +43,5 @@ class Server:
self.net_mode = net_mode
self.logger.info(tr.lang('server', 'setup.done'))
@new_thread('Server')
def run(self):
self.logger.info(tr.lang('server', 'os.pid_is').format(os.getpid(), os.getppid()))

View File

@ -3,7 +3,7 @@
IFS=$'\n';
# 默认值是 10个 可以一次性展示更多 就修改第15行代码 | head -n 30 或者更多
objects=`git verify-pack -v .git/objects/pack/pack-aba4bfc55979194c86dbd466c86e57d8199ae7ad.idx | grep -v chain | sort -k3nr | head -n 100`
objects=`git verify-pack -v .git/objects/pack/pack-aba4bfc55979194c86dbd466c86e57d8199ae7ad.idx | grep -v chain | sort -k3nr | head -n 50`
echo "All sizes are in kB. The pack column is the size of the object, compressed, inside the pack file."

View File

@ -8,8 +8,8 @@ fonts_folder = "libs/fonts"
[window]
style = "None"
width = 1139
height = 1145
width = 1300
height = 931
visible = true
caption = "Difficult Rocket {version}"
resizable = true

View File

@ -1,20 +0,0 @@
# -------------------------------
# Difficult Rocket
# Copyright © 2021-2022 by shenjackyuanjie
# All rights reserved
# -------------------------------
import time
import ctypes
def run_print():
# 加载dll
# ctypes.cdll.LoadLibrary('stdio')
c_print = ctypes.cdll.LoadLibrary('./print.dll')
c_print.print_it(ctypes.c_wchar_p(u'12啊3'), ctypes.c_wchar_p('\n'))
c_print.print_it(ctypes.c_wchar_p(u'12啊3'), ctypes.c_wchar_p('\n'))
if __name__ == "__main__":
run_print()

View File

@ -1,13 +0,0 @@
#define PY_SSIZE_T_CLEAN
#include <stdio.h>
#include <stdlib.h>
#include <Python.h>
void print_it(wchar_t* out, wchar_t* end){
printf("%s%s", out, end);
};
static PyObject *print_it_py(PyObject *self, PyObject *args){
PyObject *back_obj = PyObject_Str(PyObject);
return back_obj;
};

View File

@ -149,7 +149,6 @@ options = {
'debug_trace_depth': 1,
'debug_trace_flush': True,
'debug_win32': False,
'debug_input': False,
'debug_x11': False,
'shadow_window': True,
'vsync': None,
@ -179,7 +178,6 @@ _option_types = {
'debug_trace_depth': int,
'debug_trace_flush': bool,
'debug_win32': bool,
'debug_input': bool,
'debug_x11': bool,
'shadow_window': bool,
'vsync': bool,

View File

@ -38,19 +38,19 @@
Measuring time
==============
The `tick` and `get_frequency` functions can be used in conjunction to fulfil most
The `tick` and `get_fps` functions can be used in conjunction to fulfil most
games' basic requirements::
from pyglet import clock
while True:
dt = clock.tick()
# ... update and render ...
print(f"FPS is {clock.get_frequency()}")
print(f"FPS is {clock.get_fps()}")
The ``dt`` value returned gives the number of seconds (as a float) since the
last "tick".
The `get_frequency` function averages the framerate over a sliding window of
The `get_fps` function averages the framerate over a sliding window of
approximately 1 second. (You can calculate the instantaneous framerate by
taking the reciprocal of ``dt``).
@ -176,7 +176,7 @@ class Clock:
self.next_ts = self.time()
self.last_ts = None
# Used by self.get_frequency to show update frequency
# Used by self.get_fps to show update frequency
self.times = _deque()
self.cumulative_time = 0
self.window_size = 60

View File

@ -1079,7 +1079,7 @@ class TabletCanvas(EventDispatcher):
:event:
"""
def on_motion(self, cursor, x, y, pressure, tilt_x, tilt_y, buttons):
def on_motion(self, cursor, x, y, pressure, tilt_x, tilt_y):
"""The cursor moved on the tablet surface.
If `pressure` is 0, then the cursor is actually hovering above the
@ -1099,9 +1099,6 @@ class TabletCanvas(EventDispatcher):
Currently undefined.
`tilt_y` : float
Currently undefined.
`buttons` : int
Button state may be provided if the platform supports it.
Supported on: Windows
:event:
"""

View File

@ -553,8 +553,7 @@ class EvdevControllerManager(ControllerManager, XlibSelectDevice):
self._controllers[name] = controller
if controller:
# Dispatch event in main thread:
pyglet.app.platform_event_loop.post_event(self, 'on_connect', controller)
self.dispatch_event('on_connect', controller)
def _make_device(self, name, count=1):
path = os.path.join('/dev/input', name)

View File

@ -34,14 +34,12 @@
# ----------------------------------------------------------------------------
import ctypes
from collections import defaultdict
import pyglet
from pyglet.input.base import DeviceOpenException
from pyglet.input.base import Tablet, TabletCanvas
from pyglet.libs.win32 import libwintab as wintab
from pyglet.util import debug_print
_debug = debug_print('debug_input')
from pyglet.libs.win32 import libwintab as wintab
lib = wintab.lib
@ -118,19 +116,12 @@ class WintabTablet(Tablet):
class WintabTabletCanvas(TabletCanvas):
override_keys = False
def __init__(self, device, window, msg_base=wintab.WT_DEFBASE):
super(WintabTabletCanvas, self).__init__(window)
self.device = device
self.msg_base = msg_base
# Get the extension masks available. Only need to do this once.
global _extension_masks
if not _extension_masks:
_extension_masks = get_extension_masks()
# Just use system context, for similarity w/ os x and xinput.
# WTI_DEFCONTEXT detaches mouse from tablet, which is nice, but not
# possible on os x afiak.
@ -141,11 +132,11 @@ class WintabTabletCanvas(TabletCanvas):
# If you change this, change definition of PACKET also.
context_info.lcPktData = (
wintab.PK_CHANGED | wintab.PK_CURSOR | wintab.PK_BUTTONS |
wintab.PK_X | wintab.PK_Y | wintab.PK_Z |
wintab.PK_NORMAL_PRESSURE | wintab.PK_TANGENT_PRESSURE |
wintab.PK_ORIENTATION) | _extension_masks
context_info.lcPktMode = 0 # All absolute (PACKETMODE)
wintab.PK_CHANGED | wintab.PK_CURSOR | wintab.PK_BUTTONS |
wintab.PK_X | wintab.PK_Y | wintab.PK_Z |
wintab.PK_NORMAL_PRESSURE | wintab.PK_TANGENT_PRESSURE |
wintab.PK_ORIENTATION)
context_info.lcPktMode = 0 # All absolute
self._context = lib.WTOpenW(window._hwnd, ctypes.byref(context_info), True)
if not self._context:
@ -154,66 +145,10 @@ class WintabTabletCanvas(TabletCanvas):
window._event_handlers[msg_base + wintab.WT_PACKET] = self._event_wt_packet
window._event_handlers[msg_base + wintab.WT_PROXIMITY] = self._event_wt_proximity
if _extension_masks:
window._event_handlers[msg_base + wintab.WT_PACKETEXT] = self._event_wt_packetext
self._current_cursor = None
self._pressure_scale = device.pressure_axis.get_scale()
self._pressure_bias = device.pressure_axis.get_bias()
self.express_keys = defaultdict(lambda: defaultdict(bool)) # [control_id][location_id]
self.express_key_ct = 0
self.touchrings = [] # Not currently implemented.
self.touchstrips = [] # Not currently implemented.
# Override test
for tablet_id in range(get_tablet_count()):
control_count = self.extension_get(wintab.WTX_EXPKEYS2, tablet_id, 0, 0,
wintab.TABLET_PROPERTY_CONTROLCOUNT)
self.express_key_ct = control_count
assert _debug(f"Controls Found: {control_count}")
if self.override_keys is True:
for control_id in range(control_count):
function_count = self.extension_get(wintab.WTX_EXPKEYS2, tablet_id, control_id, 0,
wintab.TABLET_PROPERTY_FUNCCOUNT)
for function_id in range(function_count):
self.extension_set(wintab.WTX_EXPKEYS2, tablet_id, control_id, function_id,
wintab.TABLET_PROPERTY_OVERRIDE, wintab.BOOL(True))
def extension_get(self, extension, tablet_id, control_id, function_id, property_id, value_type=wintab.UINT):
prop = wintab.EXTPROPERTY()
prop.version = 0
prop.tabletIndex = tablet_id
prop.controlIndex = control_id
prop.functionIndex = function_id
prop.propertyID = property_id
prop.reserved = 0
prop.dataSize = ctypes.sizeof(value_type)
success = lib.WTExtGet(self._context, extension, ctypes.byref(prop))
if success:
return ctypes.cast(prop.data, ctypes.POINTER(value_type)).contents.value
return 0
def extension_set(self, extension, tablet_id, control_id, function_id, property_id, value):
prop = wintab.EXTPROPERTY()
prop.version = 0
prop.tabletIndex = tablet_id
prop.controlIndex = control_id
prop.functionIndex = function_id
prop.propertyID = property_id
prop.reserved = 0
prop.dataSize = ctypes.sizeof(value)
prop.data[0] = value.value
success = lib.WTExtSet(self._context, extension, ctypes.byref(prop))
if success:
return True
return False
def close(self):
lib.WTClose(self._context)
self._context = None
@ -221,9 +156,6 @@ class WintabTabletCanvas(TabletCanvas):
del self.window._event_handlers[self.msg_base + wintab.WT_PACKET]
del self.window._event_handlers[self.msg_base + wintab.WT_PROXIMITY]
if _extension_masks:
del self.window._event_handlers[self.msg_base + wintab.WT_PACKETEXT]
def _set_current_cursor(self, cursor_type):
if self._current_cursor:
self.dispatch_event('on_leave', self._current_cursor)
@ -254,25 +186,7 @@ class WintabTabletCanvas(TabletCanvas):
if self._current_cursor is None:
self._set_current_cursor(packet.pkCursor)
self.dispatch_event('on_motion', self._current_cursor, x, y, pressure, 0., 0., packet.pkButtons)
@pyglet.window.win32.Win32EventHandler(0)
def _event_wt_packetext(self, msg, wParam, lParam):
packet = wintab.PACKETEXT()
if lib.WTPacket(lParam, wParam, ctypes.byref(packet)) == 0:
return
# Proper context exists in the packet, not the lParam.
if packet.pkBase.nContext == self._context:
if packet.pkExpKeys.nControl < self.express_key_ct:
current_state = self.express_keys[packet.pkExpKeys.nControl][packet.pkExpKeys.nLocation]
new_state = bool(packet.pkExpKeys.nState)
if current_state != new_state:
event_type = "on_express_key_press" if new_state else "on_express_key_release"
self.express_keys[packet.pkExpKeys.nControl][packet.pkExpKeys.nLocation] = new_state
self.dispatch_event(event_type, packet.pkExpKeys.nControl, packet.pkExpKeys.nLocation)
self.dispatch_event('on_motion', self._current_cursor, x, y, pressure, 0., 0.)
@pyglet.window.win32.Win32EventHandler(0)
def _event_wt_proximity(self, msg, wParam, lParam):
@ -291,40 +205,6 @@ class WintabTabletCanvas(TabletCanvas):
# can actually grab a cursor id.
self._current_cursor = None
def on_express_key_press(self, control_id: int, location_id: int):
"""An event called when an ExpressKey is pressed down.
:Parameters:
`control_id` : int
Zero-based index number given to the assigned key by the driver.
The same control_id may exist in multiple locations, which the location_id is used to differentiate.
`location_id: int
Zero-based index indicating side of tablet where control id was found.
Some tablets may have clusters of ExpressKey's on various areas of the tablet.
(0 = left, 1 = right, 2 = top, 3 = bottom, 4 = transducer).
:event:
"""
def on_express_key_release(self, control_id: int, location_id: int):
"""An event called when an ExpressKey is released.
:Parameters:
`control_id` : int
Zero-based index number given to the assigned key by the driver.
The same control_id may exist in multiple locations, which the location_id is used to differentiate.
`location_id: int
Zero-based index indicating side of tablet where control id was found.
Some tablets may have clusters of ExpressKey's on various areas of the tablet.
(0 = left, 1 = right, 2 = top, 3 = bottom, 4 = transducer).
:event:
"""
WintabTabletCanvas.register_event_type('on_express_key_press')
WintabTabletCanvas.register_event_type('on_express_key_release')
class WintabTabletCursor:
def __init__(self, device, index):
@ -364,73 +244,11 @@ def get_implementation_version():
return impl_version
def extension_index(ext):
"""Check if a particular extension exists within the driver."""
exists = True
i = 0
index = 0xFFFFFFFF
while exists:
tag = wintab.UINT()
exists = lib.WTInfoW(wintab.WTI_EXTENSIONS + i, wintab.EXT_TAG, ctypes.byref(tag))
if tag.value == ext:
index = i
break
i += 1
if index != 0xFFFFFFFF:
return index
return None
def get_extension_masks():
"""Determine which extension support is available by getting the masks."""
masks = 0
tr_idx = extension_index(wintab.WTX_TOUCHRING)
if tr_idx is not None:
assert _debug("Touchring support found")
masks |= wtinfo_uint(wintab.WTI_EXTENSIONS + tr_idx, wintab.EXT_MASK)
else:
assert _debug("Touchring extension not found.")
ts_idx = extension_index(wintab.WTX_TOUCHSTRIP)
if ts_idx is not None:
assert _debug("Touchstrip support found.")
masks |= wtinfo_uint(wintab.WTI_EXTENSIONS + ts_idx, wintab.EXT_MASK)
else:
assert _debug("Touchstrip extension not found.")
expkeys_idx = extension_index(wintab.WTX_EXPKEYS2)
if expkeys_idx is not None:
assert _debug("ExpressKey support found.")
masks |= wtinfo_uint(wintab.WTI_EXTENSIONS + expkeys_idx, wintab.EXT_MASK)
else:
assert _debug("ExpressKey extension not found.")
return masks
def get_tablet_count():
"""Return just the number of current devices."""
spec_version = get_spec_version()
assert _debug(f"Wintab Version: {spec_version}")
if spec_version < 0x101:
return 0
n_devices = wtinfo_uint(wintab.WTI_INTERFACE, wintab.IFC_NDEVICES)
return n_devices
_extension_masks = None
def get_tablets(display=None):
# Require spec version 1.1 or greater
n_devices = get_tablet_count()
if not n_devices:
if get_spec_version() < 0x101:
return []
n_devices = wtinfo_uint(wintab.WTI_INTERFACE, wintab.IFC_NDEVICES)
devices = [WintabTablet(i) for i in range(n_devices)]
return devices

View File

@ -93,7 +93,7 @@ class XInputTabletCanvas(DeviceResponder, TabletCanvas):
x = e.x
y = self.window.height - e.y
pressure = e.axis_data[2] / float(cursor.max_pressure)
self.dispatch_event('on_motion', cursor, x, y, pressure, 0.0, 0.0, 0.0)
self.dispatch_event('on_motion', cursor, x, y, pressure, 0.0, 0.0)
def _proximity_in(self, e):
cursor = self._cursor_map.get(e.deviceid)

View File

@ -436,7 +436,6 @@ class XInputDeviceManager(EventDispatcher):
with self._dev_lock:
return [dev for dev in self.all_devices if dev.connected]
# Threaded method:
def _get_state(self):
xuser_max_count = set(range(XUSER_MAX_COUNT)) # {0, 1, 2, 3}
polling_rate = self._polling_rate
@ -458,8 +457,7 @@ class XInputDeviceManager(EventDispatcher):
# Found a new connection:
device.connected = True
self._connected_devices.add(i)
# Dispatch event in main thread:
pyglet.app.platform_event_loop.post_event(self, 'on_connect', device)
self.dispatch_event('on_connect', device)
elapsed = 0.0
@ -474,8 +472,7 @@ class XInputDeviceManager(EventDispatcher):
if device.connected:
device.connected = False
self._connected_devices.remove(i)
# Dispatch event in main thread:
pyglet.app.platform_event_loop.post_event(self, 'on_disconnect', device)
self.dispatch_event('on_disconnect', device)
continue
elif result == ERROR_SUCCESS and device.is_open:

View File

@ -35,7 +35,6 @@
import atexit
import struct
import warnings
import pyglet
from . import com

View File

@ -34,13 +34,17 @@
# ----------------------------------------------------------------------------
import ctypes
from ctypes.wintypes import HANDLE, BYTE, HWND, BOOL, UINT, LONG, WORD, DWORD, WCHAR, LPVOID
lib = ctypes.windll.wintab32
LONG = ctypes.c_long
BOOL = ctypes.c_int
UINT = ctypes.c_uint
WORD = ctypes.c_uint16
DWORD = ctypes.c_uint32
WCHAR = ctypes.c_wchar
FIX32 = DWORD
WTPKT = DWORD
HCTX = HANDLE # CONTEXT HANDLE
LCNAMELEN = 40
@ -115,56 +119,6 @@ class LOGCONTEXT(ctypes.Structure):
)
class TILT(ctypes.Structure): # 1.1
_fields_ = (
('tiltX', ctypes.c_int),
('tiltY', ctypes.c_int),
)
class EXTENSIONBASE(ctypes.Structure): # 1.4
_fields_ = (
('nContext', HCTX), # Specifies the Wintab context to which these properties apply.
('nStatus', UINT), # Status of setting/getting properties.
('nTime', DWORD), # Timestamp applied to property transaction.
('nSerialNumber', UINT), # Reserved - not use
)
class EXPKEYSDATA(ctypes.Structure): # 1.4
_fields_ = (
('nTablet', BYTE), # Tablet index where control is found.
('nControl', BYTE), # Zero-based control index.
('nLocation', BYTE), # Zero-based index indicating side of tablet where control found (0 = left, 1 = right).
('nReserved', BYTE), # Reserved - not used
('nState', DWORD) # Indicates Express Key button press (1 = pressed, 0 = released)
)
class SLIDERDATA(ctypes.Structure): # 1.4
_fields_ = (
('nTablet', BYTE), # Tablet index where control is found.
('nControl', BYTE), # Zero-based control index.
('nMode', BYTE), # Zero-based current active mode of control. Mode selected by control's toggle button.
('nReserved', BYTE), # Reserved - not used
('nPosition', DWORD) # An integer representing the position of the user's finger on the control.
# When there is no finger on the control, this value is negative.
)
class EXTPROPERTY(ctypes.Structure): # 1.4
_fields_ = (
('version', BYTE), # Structure version, 0 for now
('tabletIndex', BYTE), # 0-based index for tablet
('controlIndex', BYTE), # 0-based index for control
('functionIndex', BYTE), # 0-based index for control's sub-function
('propertyID', WORD), # property ID
('reserved', WORD), # DWORD-alignment filler
('dataSize', DWORD), # number of bytes in data[] buffer
('data', BYTE * 1), # raw data
)
# Custom packet format with fields
# PK_CHANGED
# PK_CURSOR
@ -189,15 +143,6 @@ class PACKET(ctypes.Structure):
)
class PACKETEXT(ctypes.Structure):
_fields_ = (
('pkBase', EXTENSIONBASE), # Extension control properties common to all control types.
('pkExpKeys', EXPKEYSDATA), # Extension data for one Express Key.
('pkTouchStrip', SLIDERDATA), # Extension data for one Touch Strip.
('pkTouchRing', SLIDERDATA) # Extension data for one Touch Ring.
)
PK_CONTEXT = 0x0001 # reporting context
PK_STATUS = 0x0002 # status bits
PK_TIME = 0x0004 # time stamp
@ -229,7 +174,6 @@ WT_CTXOVERLAP = 4
WT_PROXIMITY = 5
WT_INFOCHANGE = 6
WT_CSRCHANGE = 7
WT_PACKETEXT = 8
# system button assignment values
SBN_NONE = 0x00
@ -426,47 +370,4 @@ WTX_FKEYS = 1 # Function keys
WTX_TILT = 2 # Raw Cartesian tilt; 1.1
WTX_CSRMASK = 3 # select input by cursor type; 1.1
WTX_XBTNMASK = 4 # Extended button mask; 1.1
WTX_EXPKEYS = 5 # ExpressKeys; 1.3 - DEPRECATED USE 2
WTX_TOUCHSTRIP = 6 # TouchStrips; 1.4
WTX_TOUCHRING = 7 # TouchRings; 1.4
WTX_EXPKEYS2 = 8 # ExpressKeys; 1.4
TABLET_PROPERTY_CONTROLCOUNT = 0 # UINT32: number of physical controls on tablet
TABLET_PROPERTY_FUNCCOUNT = 1 # UINT32: number of functions of control
TABLET_PROPERTY_AVAILABLE = 2 # BOOL: control/mode is available for override
TABLET_PROPERTY_MIN = 3 # UINT32: minimum value
TABLET_PROPERTY_MAX = 4 # UINT32: maximum value
TABLET_PROPERTY_OVERRIDE = 5 # BOOL: control is overridden
TABLET_PROPERTY_OVERRIDE_NAME = 6 # UTF-8: Displayable name when control is overridden
TABLET_PROPERTY_OVERRIDE_ICON = 7 # Image: Icon to show when control is overridden
TABLET_PROPERTY_ICON_WIDTH = 8 # UINT32: Pixel width of icon display
TABLET_PROPERTY_ICON_HEIGHT = 9 # UINT32: Pixel height of icon display
TABLET_PROPERTY_ICON_FORMAT = 10 # UINT32: UINT32: Pixel format of icon display (see TABLET_ICON_FMT_*)
TABLET_PROPERTY_LOCATION = 11 # UINT32: Physical location of control (see TABLET_LOC_*)
TABLET_LOC_LEFT = 0
TABLET_LOC_RIGHT = 1
TABLET_LOC_TOP = 2
TABLET_LOC_BOTTOM = 3
TABLET_LOC_TRANSDUCER = 4
lib.WTOpenW.restype = HCTX
lib.WTOpenW.argtypes = [HWND, ctypes.POINTER(LOGCONTEXT), BOOL]
lib.WTClose.restype = BOOL
lib.WTClose.argtypes = [HCTX]
lib.WTInfoW.restype = UINT
lib.WTInfoW.argtypes = [UINT, UINT, LPVOID]
lib.WTPacket.restype = BOOL
lib.WTPacket.argtypes = [HCTX, UINT, LPVOID]
lib.WTGetW.restype = BOOL
lib.WTGetW.argtypes = [HCTX, BOOL]
lib.WTExtGet.restype = BOOL
lib.WTExtGet.argtypes = [HCTX, UINT, LPVOID]
lib.WTExtSet.restype = BOOL
lib.WTExtSet.argtypes = [HCTX, UINT, LPVOID]
WTX_EXPKEYS = 5 # ExpressKeys; 1.3

View File

@ -73,11 +73,9 @@ creating scrollable layouts.
.. versionadded:: 1.1
"""
from os.path import dirname as _dirname
from os.path import splitext as _splitext
import os.path
import pyglet
from pyglet.text import layout, document, caret
@ -132,7 +130,7 @@ def get_decoder(filename, mimetype=None):
:rtype: `DocumentDecoder`
"""
if mimetype is None:
_, ext = _splitext(filename)
_, ext = os.path.splitext(filename)
if ext.lower() in ('.htm', '.html', '.xhtml'):
mimetype = 'text/html'
else:
@ -178,7 +176,7 @@ def load(filename, file=None, mimetype=None):
if hasattr(file_contents, "decode"):
file_contents = file_contents.decode()
location = pyglet.resource.FileLocation(_dirname(filename))
location = pyglet.resource.FileLocation(os.path.dirname(filename))
return decoder.decode(file_contents, location)
@ -267,7 +265,11 @@ class DocumentLabel(layout.TextLayout):
Optional graphics group to use.
"""
super().__init__(document, width, height, multiline, dpi, batch, group)
super(DocumentLabel, self).__init__(document,
width=width, height=height,
multiline=multiline,
dpi=dpi, batch=batch, group=group)
self._x = x
self._y = y
self._anchor_x = anchor_x
@ -345,7 +347,8 @@ class DocumentLabel(layout.TextLayout):
@font_size.setter
def font_size(self, font_size):
self.document.set_style(0, len(self.document.text), {'font_size': font_size})
self.document.set_style(0, len(self.document.text),
{'font_size': font_size})
@property
def bold(self):
@ -357,7 +360,8 @@ class DocumentLabel(layout.TextLayout):
@bold.setter
def bold(self, bold):
self.document.set_style(0, len(self.document.text), {'bold': bold})
self.document.set_style(0, len(self.document.text),
{'bold': bold})
@property
def italic(self):
@ -369,7 +373,8 @@ class DocumentLabel(layout.TextLayout):
@italic.setter
def italic(self, italic):
self.document.set_style(0, len(self.document.text), {'italic': italic})
self.document.set_style(0, len(self.document.text),
{'italic': italic})
def get_style(self, name):
"""Get a document style value by name.
@ -399,9 +404,6 @@ class DocumentLabel(layout.TextLayout):
"""
self.document.set_style(0, len(self.document.text), {name: value})
def __del__(self):
self.delete()
class Label(DocumentLabel):
"""Plain text label.
@ -461,8 +463,10 @@ class Label(DocumentLabel):
Optional graphics group to use.
"""
doc = decode_text(text)
super().__init__(doc, x, y, width, height, anchor_x, anchor_y, multiline, dpi, batch, group)
document = decode_text(text)
super(Label, self).__init__(document, x, y, width, height,
anchor_x, anchor_y,
multiline, dpi, batch, group)
self.document.set_style(0, len(self.document.text), {
'font_name': font_name,
@ -521,8 +525,10 @@ class HTMLLabel(DocumentLabel):
"""
self._text = text
self._location = location
doc = decode_html(text, location)
super().__init__(doc, x, y, width, height, anchor_x, anchor_y, multiline, dpi, batch, group)
document = decode_html(text, location)
super(HTMLLabel, self).__init__(document, x, y, width, height,
anchor_x, anchor_y,
multiline, dpi, batch, group)
@property
def text(self):
@ -536,3 +542,4 @@ class HTMLLabel(DocumentLabel):
def text(self, text):
self._text = text
self.document = decode_html(text, self._location)

View File

@ -1851,7 +1851,7 @@ class FPSDisplay:
#: :type: float
update_period = 0.25
def __init__(self, window, color=(127, 127, 127, 127), samples=240):
def __init__(self, window, color=(127, 127, 127, 127), samples=60):
from time import time
from statistics import mean
from collections import deque
@ -1879,7 +1879,19 @@ class FPSDisplay:
if self._elapsed >= self.update_period:
self._elapsed = 0
self.label.text = f"{1 / self._mean(self._delta_times):.2f}"
self._set_fps_text(1 / self._mean(self._delta_times))
def _set_fps_text(self, fps):
"""Set the label text for the given FPS estimation.
Called by `update` every `update_period` seconds.
:Parameters:
`fps` : float
Estimated framerate of the window.
"""
self.label.text = '%.2f' % fps
def draw(self):
"""Draw the label."""

View File

@ -7,6 +7,7 @@
import os
import sys
import getopt
# input_args = sys.argv
@ -16,5 +17,5 @@ dllname = "./data_types.dll"
python_include_path = "C:/Users/shenjack.SHENJACK-5600X/AppData/Local/Programs/Python/Python38/include/"
os.system("gcc -O3 -I {} -shared {} -o {}".format(python_include_path, filename, dllname))
# gcc -I C:/Users/shenjack.SHENJACK-5600X/AppData/Local/Programs/Python/Python38/include/ -shared .\data_types.c -o .\data_types.dll
os.system("gcc -I {} -shared {} -o {}".format(python_include_path, filename, dllname))
# gcc -I C:/Users/shenjack.SHENJACK-5600X/AppData/Local/Programs/Python/Python38/include/ -shared .\data_types.c -o .\data_types.dll