下面这段win32获得当前鼠标类型的代码,self.type是个数字,我想要的是对象的名字(比如ARROW、HAND)怎么做?只能在init里加个参数,挨个写后面?
比如,get_current_cursor().type 返回的是 32641,我想要返回字串ARROW
https://stackoverflow.com/questions/1690400/getting-an-instance-name-inside-class-init
这里有个查栈的方法,太丑陋了
from win32con import IDC_APPSTARTING, IDC_ARROW, IDC_CROSS, IDC_HAND, \
IDC_HELP, IDC_IBEAM, IDC_ICON, IDC_NO, IDC_SIZE, IDC_SIZEALL, \
IDC_SIZENESW, IDC_SIZENS, IDC_SIZENWSE, IDC_SIZEWE, IDC_UPARROW, IDC_WAIT
from win32gui import LoadCursor, GetCursorInfo
def get_current_cursor():
curr_cursor_handle = GetCursorInfo()[1]
return Cursor.from_handle(curr_cursor_handle)
class Cursor(object):
@classmethod
def from_handle(cls, handle):
for cursor in DEFAULT_CURSORS:
if cursor.handle == handle:
return cursor
return cls(handle=handle)
def __init__(self, cursor_type=None, handle=None):
if handle is None:
handle = LoadCursor(0, cursor_type)
self.type = cursor_type
self.handle = handle
DEFAULT_CURSORS \
= APPSTARTING, ARROW, CROSS, HAND, HELP, IBEAM, ICON, NO, SIZE, SIZEALL, \
SIZENESW, SIZENS, SIZENWSE, SIZEWE, UPARROW, WAIT \
= Cursor(IDC_APPSTARTING), Cursor(IDC_ARROW), Cursor(IDC_CROSS), \
Cursor(IDC_HAND), Cursor(IDC_HELP), Cursor(IDC_IBEAM), Cursor(IDC_ICON), \
Cursor(IDC_NO), Cursor(IDC_SIZE), Cursor(IDC_SIZEALL), \
Cursor(IDC_SIZENESW), Cursor(IDC_SIZENS), Cursor(IDC_SIZENWSE), \
Cursor(IDC_SIZEWE), Cursor(IDC_UPARROW), Cursor(IDC_WAIT)
--
修改:vale FROM 218.241.217.*
FROM 218.241.217.*