python: move get_dc_event_name() to events

This commit is contained in:
link2xt
2022-09-10 21:22:38 +00:00
parent 3cf1aad551
commit 40dc182295
3 changed files with 12 additions and 12 deletions

View File

@@ -2,7 +2,7 @@ import sys
from pkg_resources import DistributionNotFound, get_distribution
from . import capi, const, events, hookspec # noqa
from . import capi, events, hookspec # noqa
from .account import Account, get_core_info # noqa
from .capi import ffi # noqa
from .chat import Chat # noqa
@@ -17,14 +17,6 @@ except DistributionNotFound:
__version__ = "0.0.0.dev0-unknown"
def get_dc_event_name(integer, _DC_EVENTNAME_MAP={}):
if not _DC_EVENTNAME_MAP:
for name in dir(const):
if name.startswith("DC_EVENT_"):
_DC_EVENTNAME_MAP[getattr(const, name)] = name
return _DC_EVENTNAME_MAP[integer]
def register_global_plugin(plugin):
"""Register a global plugin which implements one or more
of the :class:`deltachat.hookspec.Global` hooks.

View File

@@ -8,14 +8,21 @@ import traceback
from contextlib import contextmanager
from queue import Empty, Queue
import deltachat
from . import const
from .capi import ffi, lib
from .cutil import from_optional_dc_charpointer
from .hookspec import account_hookimpl
from .message import map_system_message
def get_dc_event_name(integer, _DC_EVENTNAME_MAP={}):
if not _DC_EVENTNAME_MAP:
for name in dir(const):
if name.startswith("DC_EVENT_"):
_DC_EVENTNAME_MAP[getattr(const, name)] = name
return _DC_EVENTNAME_MAP[integer]
class FFIEvent:
def __init__(self, name: str, data1, data2):
self.name = name
@@ -239,7 +246,7 @@ class EventThread(threading.Thread):
data1 = lib.dc_event_get_data1_int(event)
# the following code relates to the deltachat/_build.py's helper
# function which provides us signature info of an event call
evt_name = deltachat.get_dc_event_name(evt)
evt_name = get_dc_event_name(evt)
if lib.dc_event_has_string_data(evt):
data2 = from_optional_dc_charpointer(lib.dc_event_get_data2_str(event))
else: