mwxlib 1.0.0__py3-none-any.whl → 1.7.13__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
mwx/wxmon.py CHANGED
@@ -13,11 +13,11 @@ from .framework import CtrlInterface, Menu
13
13
 
14
14
 
15
15
  class EventMonitor(wx.ListCtrl, ListCtrlAutoWidthMixin, CtrlInterface):
16
- """Event monitor
16
+ """Event monitor.
17
17
 
18
18
  Attributes:
19
- parent : shellframe
20
- target : widget to monitor
19
+ parent: shellframe
20
+ target: widget to monitor
21
21
  """
22
22
  def __init__(self, parent, **kwargs):
23
23
  wx.ListCtrl.__init__(self, parent,
@@ -29,11 +29,11 @@ class EventMonitor(wx.ListCtrl, ListCtrlAutoWidthMixin, CtrlInterface):
29
29
 
30
30
  self.parent = parent
31
31
  self.target = None
32
- self._target = None # previous target
32
+ self._target = None # previous target
33
33
 
34
34
  self.Font = wx.Font(9, wx.DEFAULT, wx.NORMAL, wx.NORMAL)
35
35
 
36
- self.__dir = True # sort direction
36
+ self.__dir = True # sort direction
37
37
  self.__items = []
38
38
 
39
39
  _alist = (
@@ -65,7 +65,7 @@ class EventMonitor(wx.ListCtrl, ListCtrlAutoWidthMixin, CtrlInterface):
65
65
  @self.handler.bind('C-c pressed')
66
66
  def copy(evt):
67
67
  self.copy()
68
-
68
+
69
69
  def OnDestroy(self, evt):
70
70
  if evt.EventObject is self:
71
71
  try:
@@ -73,41 +73,42 @@ class EventMonitor(wx.ListCtrl, ListCtrlAutoWidthMixin, CtrlInterface):
73
73
  except Exception as e:
74
74
  print(e)
75
75
  evt.Skip()
76
-
76
+
77
77
  def OnSetFocus(self, evt):
78
78
  title = "{} target: {}".format(self.__class__.__name__, self.target)
79
79
  self.parent.handler('title_window', title)
80
80
  evt.Skip()
81
-
81
+
82
82
  ## --------------------------------
83
- ## EventWatcher wrapper interface
83
+ ## EventWatcher wrapper interface.
84
84
  ## --------------------------------
85
- ew.buildWxEventMap() # build ew._eventBinders and ew._eventIdMap
86
-
85
+ ew.buildWxEventMap() # build ew._eventBinders and ew._eventIdMap
86
+
87
87
  @staticmethod
88
88
  def get_name(event):
89
89
  return ew._eventIdMap.get(event, 'Unknown')
90
-
90
+
91
91
  @staticmethod
92
92
  def get_binder(event):
93
93
  return next(x for x in ew._eventBinders if x.typeId == event)
94
-
94
+
95
95
  @staticmethod
96
96
  def get_watchlist():
97
97
  """All watched event binders except noWatchList."""
98
98
  return (x for x in ew._eventBinders if x not in ew._noWatchList)
99
-
99
+
100
100
  def watch(self, widget=None):
101
101
  """Begin watching the widget."""
102
102
  self.unwatch()
103
103
  self.clear()
104
104
  if widget is None:
105
- widget = self._target # Resume watching the previous target.
105
+ widget = self._target # Resume watching the previous target.
106
106
  if not widget:
107
107
  return
108
108
  if not isinstance(widget, wx.Object):
109
109
  wx.MessageBox("Cannot watch the widget.\n\n"
110
- "- {!r} is not a wx.Object.".format(widget))
110
+ "- {!r} is not a wx.Object.".format(widget),
111
+ self.__module__)
111
112
  return
112
113
  self._target = widget
113
114
  self.target = widget
@@ -123,7 +124,7 @@ class EventMonitor(wx.ListCtrl, ListCtrlAutoWidthMixin, CtrlInterface):
123
124
  print(" #{:6d}:{:32s}{!s}".format(event, name, e))
124
125
  continue
125
126
  self.parent.handler('monitor_begin', widget)
126
-
127
+
127
128
  def unwatch(self):
128
129
  """End watching the widget."""
129
130
  widget = self.target
@@ -134,12 +135,12 @@ class EventMonitor(wx.ListCtrl, ListCtrlAutoWidthMixin, CtrlInterface):
134
135
  print("- Failed to unbind {}: {}".format(binder.typeId, widget))
135
136
  self.parent.handler('monitor_end', widget)
136
137
  self.target = None
137
-
138
+
138
139
  def onWatchedEvent(self, evt):
139
140
  if self:
140
141
  self.update(evt)
141
142
  evt.Skip()
142
-
143
+
143
144
  def dump(self, widget, verbose=True):
144
145
  """Dump all event handlers bound to the widget."""
145
146
  ## Note: This will not work unless [Monkey-patch for wx.core] is applied.
@@ -159,15 +160,15 @@ class EventMonitor(wx.ListCtrl, ListCtrlAutoWidthMixin, CtrlInterface):
159
160
  except AttributeError:
160
161
  pass
161
162
  return ssmap
162
-
163
+
163
164
  ## --------------------------------
164
- ## Actions on list items
165
+ ## Actions on list items.
165
166
  ## --------------------------------
166
-
167
+
167
168
  def clear(self):
168
169
  self.DeleteAllItems()
169
170
  del self.__items[:]
170
-
171
+
171
172
  def update(self, evt):
172
173
  event = evt.EventType
173
174
  obj = evt.EventObject
@@ -178,7 +179,7 @@ class EventMonitor(wx.ListCtrl, ListCtrlAutoWidthMixin, CtrlInterface):
178
179
  with ignore(DeprecationWarning):
179
180
  attribs = ew._makeAttribString(evt)
180
181
  except Exception:
181
- attribs = '' # Failed to get event attributes; possibly <BdbQuit>.
182
+ attribs = '' # Failed to get event attributes; possibly <BdbQuit>.
182
183
  data = self.__items
183
184
  for i, item in enumerate(data):
184
185
  if item[0] == event:
@@ -199,7 +200,7 @@ class EventMonitor(wx.ListCtrl, ListCtrlAutoWidthMixin, CtrlInterface):
199
200
  self.parent.debugger.set_trace()
200
201
  return
201
202
  self.blink(i)
202
-
203
+
203
204
  def append(self, event):
204
205
  data = self.__items
205
206
  if event in (item[0] for item in data):
@@ -214,7 +215,7 @@ class EventMonitor(wx.ListCtrl, ListCtrlAutoWidthMixin, CtrlInterface):
214
215
  self.SetItem(i, j, str(v))
215
216
  self.SetItemTextColour(i, 'blue')
216
217
  self.blink(i)
217
-
218
+
218
219
  def blink(self, i):
219
220
  if self.GetItemBackgroundColour(i) != wx.Colour('yellow'):
220
221
  self.SetItemBackgroundColour(i, "yellow")
@@ -222,7 +223,7 @@ class EventMonitor(wx.ListCtrl, ListCtrlAutoWidthMixin, CtrlInterface):
222
223
  if self and i < self.ItemCount:
223
224
  self.SetItemBackgroundColour(i, 'white')
224
225
  wx.CallAfter(wx.CallLater, 1000, _reset_color)
225
-
226
+
226
227
  def copy(self):
227
228
  if not self.SelectedItemCount:
228
229
  return
@@ -232,8 +233,8 @@ class EventMonitor(wx.ListCtrl, ListCtrlAutoWidthMixin, CtrlInterface):
232
233
  event, name, *_, attribs = self.__items[i]
233
234
  text += "{}\t{}\n{}\n\n".format(event, name, attribs)
234
235
  Clipboard.write(text[:-1])
235
-
236
- def OnSortItems(self, evt): #<wx._controls.ListEvent>
236
+
237
+ def OnSortItems(self, evt): #<wx._controls.ListEvent>
237
238
  n = self.ItemCount
238
239
  if n < 2:
239
240
  return
@@ -253,19 +254,19 @@ class EventMonitor(wx.ListCtrl, ListCtrlAutoWidthMixin, CtrlInterface):
253
254
  self.SetItem(i, j, str(v))
254
255
  self.Select(i, item in ls)
255
256
  self.CheckItem(i, item in lc)
256
- self.SetItemTextColour(i, 'black') # reset font
257
+ self.SetItemTextColour(i, 'black') # reset font
257
258
  if item in lb:
258
259
  self.SetItemTextColour(i, 'blue')
259
260
  if item == fi:
260
261
  self.Focus(i)
261
-
262
- def OnItemDClick(self, evt): #<wx._core.MouseEvent>
262
+
263
+ def OnItemDClick(self, evt): #<wx._core.MouseEvent>
263
264
  i, flag = self.HitTest(evt.Position)
264
265
  if i >= 0:
265
266
  item = self.__items[i]
266
- wx.CallAfter(wx.TipWindow, self, item[-1], 512) # attribs
267
+ wx.CallAfter(wx.TipWindow, self, item[-1], 512) # attribs
267
268
  evt.Skip()
268
-
269
+
269
270
  def OnContextMenu(self, evt):
270
271
  obj = self.target
271
272
  wnd = self._target
@@ -294,9 +295,9 @@ def monit(widget=None, **kwargs):
294
295
  return ew
295
296
 
296
297
 
297
- ## Monkey-patch for wx.core (deprecated)
298
+ ## Monkey-patch for wx.core (deprecated).
298
299
  if 0:
299
- from wx import core # PY3
300
+ from wx import core # PY3
300
301
 
301
302
  def _EvtHandler_Bind(self, event, handler=None, source=None, id=wx.ID_ANY, id2=wx.ID_ANY):
302
303
  """
@@ -350,11 +351,11 @@ if 0:
350
351
  if v[0] == id or v[1] == handler:
351
352
  handlers.remove(v)
352
353
  else:
353
- handlers.pop(0) # No optional arguments are specified.
354
+ handlers.pop(0) # No optional arguments are specified.
354
355
  if not handlers:
355
356
  del vmap[event.typeId]
356
357
  except KeyError:
357
- pass # Note: vmap is actually inconsistent, but ignored.
358
+ pass # Note: vmap is actually inconsistent, but ignored.
358
359
  return retval
359
360
 
360
361
  core.EvtHandler.Unbind = _EvtHandler_Unbind