Skip to content

Commit 4fd2ae4

Browse files
committed
-
1 parent 7b9e2bc commit 4fd2ae4

File tree

6 files changed

+45
-43
lines changed

6 files changed

+45
-43
lines changed

python_toolbox/wx_tools/widgets/cute_window/bind_savvy_window/__init__.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@
22
# This program is distributed under the LGPL2.1 license.
33

44
'''
5-
This module defines the `BindSavvyWindow` class.
5+
This module defines the `BindSavvyEvtHandler` class.
66
7-
See documentation of the `BindSavvyWindow` class and its metaclass
8-
`BindSavvyWindowType` for more information.
7+
See documentation of the `BindSavvyEvtHandler` class and its metaclass
8+
`BindSavvyEvtHandlerType` for more information.
99
'''
1010

11-
from .bind_savvy_window import BindSavvyWindow
11+
from .bind_savvy_evt_handler import BindSavvyEvtHandler

python_toolbox/wx_tools/widgets/cute_window/bind_savvy_window/bind_savvy_window.py renamed to python_toolbox/wx_tools/widgets/cute_window/bind_savvy_window/bind_savvy_evt_handler.py

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
# This program is distributed under the LGPL2.1 license.
33

44
'''
5-
This module defines the `BindSavvyWindow` class.
5+
This module defines the `BindSavvyEvtHandler` class.
66
77
See its documentation for more information.
88
'''
@@ -12,29 +12,29 @@
1212
from python_toolbox import wx_tools
1313
from python_toolbox import caching
1414

15-
from .bind_savvy_window_type import BindSavvyWindowType
15+
from .bind_savvy_evt_handler_type import BindSavvyEvtHandlerType
1616
from . import name_parser
1717

1818

19-
class BindSavvyWindow(wx.Window):
19+
class BindSavvyEvtHandler(wx.EvtHandler):
2020
'''
21-
Window type that allows binding events automatically by method name.
21+
Event handler type that allows binding events automatically by method name.
2222
2323
Use the `.bind_event_handlers` method to bind event handlers by name.
2424
2525
Some of this class's functionality is in its metaclass; see documentation
26-
of `BindSavvyWindowType`'s methods and attributes for more details.
26+
of `BindSavvyEvtHandlerType`'s methods and attributes for more details.
2727
'''
2828

29-
__metaclass__ = BindSavvyWindowType
29+
__metaclass__ = BindSavvyEvtHandlerType
3030

3131

32-
_BindSavvyWindowType__name_parser = name_parser.NameParser(
32+
_BindSavvyEvtHandlerType__name_parser = name_parser.NameParser(
3333
(name_parser.LowerCase,),
3434
n_preceding_underscores_possibilities=(1,)
3535
)
3636
'''
37-
The name parser used by this window class for parsing event handlers.
37+
The name parser used by this event handler class for parsing event handlers.
3838
3939
Override this with a different instance of `NameParser` in order to use a
4040
different naming convention for event handlers.
@@ -52,11 +52,11 @@ def bind_event_handlers(self, cls):
5252
`bind_event_handlers` function is being called.
5353
'''
5454
if not isinstance(self, cls):
55-
raise TypeError('`cls` must be a class that the window is an '
55+
raise TypeError('`cls` must be a class that the event handler is an '
5656
'instance of; you gave a `cls` of `%s`, which '
5757
'`%s` is not an instance of.' % (cls, self))
5858
event_handler_grokkers = \
59-
cls._BindSavvyWindowType__event_handler_grokkers
59+
cls._BindSavvyEvtHandlerType__event_handler_grokkers
6060
for event_handler_grokker in event_handler_grokkers:
6161
event_handler_grokker.bind(self)
6262

python_toolbox/wx_tools/widgets/cute_window/bind_savvy_window/bind_savvy_window_type.py renamed to python_toolbox/wx_tools/widgets/cute_window/bind_savvy_window/bind_savvy_evt_handler_type.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@
22
# This program is distributed under the LGPL2.1 license.
33

44
'''
5-
This module defines the `BindSavvyWindowType` metaclass.
5+
This module defines the `BindSavvyEvtHandlerType` metaclass.
66
7-
See documentation of `BindSavvyWindow` for more information.
7+
See documentation of `BindSavvyEvtHandler` for more information.
88
'''
99

1010
import wx
@@ -15,11 +15,11 @@
1515
from .event_handler_grokker import EventHandlerGrokker
1616

1717

18-
class BindSavvyWindowType(type):
18+
class BindSavvyEvtHandlerType(type):
1919
'''
20-
Metaclass for the `BindSavvyWindow` class.
20+
Metaclass for the `BindSavvyEvtHandler` class.
2121
22-
See documentation of `BindSavvyWindow` for more information.
22+
See documentation of `BindSavvyEvtHandler` for more information.
2323
'''
2424

2525
event_modules = []
@@ -33,7 +33,7 @@ class BindSavvyWindowType(type):
3333

3434
@property
3535
@caching.cache()
36-
def _BindSavvyWindowType__event_handler_grokkers(cls):
36+
def _BindSavvyEvtHandlerType__event_handler_grokkers(cls):
3737
'''
3838
The `EventHandlerGrokker` objects for this window.
3939
@@ -46,10 +46,10 @@ def _BindSavvyWindowType__event_handler_grokkers(cls):
4646
names_to_event_handlers = dict_tools.filter_items(
4747
vars(cls),
4848
lambda name, value:
49-
cls._BindSavvyWindowType__name_parser.match(name,
49+
cls._BindSavvyEvtHandlerType__name_parser.match(name,
5050
cls.__name__) and
5151
callable(value) and
52-
getattr(value, '_BindSavvyWindowType__dont_bind_automatically',
52+
getattr(value, '_BindSavvyEvtHandlerType__dont_bind_automatically',
5353
None) is not True
5454
)
5555
'''Dict mapping names to event handling functions.'''
@@ -63,5 +63,5 @@ def dont_bind_automatically(function):
6363
'''
6464
Decorate a method to not be bound automatically as an event handler.
6565
'''
66-
function._BindSavvyWindowType__dont_bind_automatically = True
66+
function._BindSavvyEvtHandlerType__dont_bind_automatically = True
6767
return function

python_toolbox/wx_tools/widgets/cute_window/bind_savvy_window/event_codes.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -35,25 +35,25 @@ def get_event_codes_of_component(component):
3535

3636

3737
@caching.cache()
38-
def get_event_code_from_name(name, window_type):
38+
def get_event_code_from_name(name, evt_handler_type):
3939
'''
40-
Get an event code given a `name` and a `window_type`.
40+
Get an event code given a `name` and an `evt_handler_type`.
4141
4242
For example, given a `name` of `left_down` this function will return the
4343
event code `wx.EVT_LEFT_DOWN`.
4444
45-
If `window_type` has an `.event_modules` attribute, these modules will be
46-
searched for event codes in precedence to `wx` and the window type's own
45+
If `evt_handler_type` has an `.event_modules` attribute, these modules will be
46+
searched for event codes in precedence to `wx` and the event handler type's own
4747
module.
4848
'''
4949
processed_name = 'EVT_%s' % string_tools.conversions.\
5050
camelcase_to_underscore(name).upper()
5151
raw_event_modules = \
52-
(window_type.event_modules if
53-
sequence_tools.is_sequence(window_type.event_modules) else
54-
[window_type.event_modules])
52+
(evt_handler_type.event_modules if
53+
sequence_tools.is_sequence(evt_handler_type.event_modules) else
54+
[evt_handler_type.event_modules])
5555
event_modules = raw_event_modules + [
56-
address_tools.resolve(window_type.__module__),
56+
address_tools.resolve(evt_handler_type.__module__),
5757
wx
5858
]
5959
for event_module in event_modules:

python_toolbox/wx_tools/widgets/cute_window/bind_savvy_window/event_handler_grokker.py

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -20,32 +20,34 @@
2020
class EventHandlerGrokker(object):
2121
'''Wraps an event handling function and figures out what to bind it to.'''
2222

23-
def __init__(self, name, event_handler_self_taking_function, window_type):
23+
def __init__(self, name, event_handler_self_taking_function,
24+
evt_handler_type):
2425
'''
2526
Construct the `EventHandlerGrokker`.
2627
2728
`name` is the name of the event handling function.
2829
`event_handler_self_taking_function` is the function itself, as proper
29-
function. (i.e. taking two arguments `self` and `event`.) `window_type`
30-
is the class in which that event handler is defined.
30+
function. (i.e. taking two arguments `self` and `event`.)
31+
`evt_handler_type` is the class in which that event handler is defined.
3132
'''
32-
assert window_type._BindSavvyWindowType__name_parser.match(
33+
assert evt_handler_type._BindSavvyEvtHandlerType__name_parser.match(
3334
name,
34-
window_type.__name__
35+
evt_handler_type.__name__
3536
)
3637

3738
self.name = name
3839

3940
self.event_handler_self_taking_function = \
4041
event_handler_self_taking_function
4142

42-
self.window_type = window_type
43+
self.evt_handler_type = evt_handler_type
4344

4445

4546
parsed_words = caching.CachedProperty(
46-
lambda self: self.window_type._BindSavvyWindowType__name_parser.parse(
47+
lambda self: self.evt_handler_type. \
48+
_BindSavvyEvtHandlerType__name_parser.parse(
4749
self.name,
48-
self.window_type.__name__
50+
self.evt_handler_type.__name__
4951
),
5052
doc=''' '''
5153
)
@@ -56,7 +58,7 @@ def bind(self, window):
5658
event_handler_bound_method = types.MethodType(
5759
self.event_handler_self_taking_function,
5860
window,
59-
self.window_type
61+
self.evt_handler_type
6062
)
6163
if len(self.parsed_words) >= 2:
6264
closer_window = address_tools.resolve(
@@ -81,7 +83,7 @@ def bind(self, window):
8183
else:
8284
window.Bind(
8385
get_event_code_from_name(last_word,
84-
self.window_type),
86+
self.evt_handler_type),
8587
event_handler_bound_method,
8688
)
8789

python_toolbox/wx_tools/widgets/cute_window/cute_window.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,10 @@
1515
from python_toolbox.context_managers import ContextManager
1616

1717
from .accelerator_savvy_window import AcceleratorSavvyWindow
18-
from .bind_savvy_window import BindSavvyWindow
18+
from .bind_savvy_evt_handler import BindSavvyEvtHandler
1919

2020

21-
class CuteWindow(AcceleratorSavvyWindow, BindSavvyWindow, wx.Window):
21+
class CuteWindow(AcceleratorSavvyWindow, BindSavvyEvtHandler, wx.Window):
2222
'''
2323
An improved `wx.Window`.
2424

0 commit comments

Comments
 (0)