mwxlib 1.0.0__py3-none-any.whl → 1.8.0__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 = (
@@ -46,8 +46,8 @@ class EventMonitor(wx.ListCtrl, ListCtrlAutoWidthMixin, CtrlInterface):
46
46
  self.InsertColumn(k, header, width=w)
47
47
 
48
48
  self.Bind(wx.EVT_LIST_COL_CLICK, self.OnSortItems)
49
+ self.Bind(wx.EVT_LIST_ITEM_ACTIVATED, self.OnItemActivated)
49
50
  self.Bind(wx.EVT_CONTEXT_MENU, self.OnContextMenu)
50
- self.Bind(wx.EVT_LEFT_DCLICK, self.OnItemDClick)
51
51
  self.Bind(wx.EVT_SET_FOCUS, self.OnSetFocus)
52
52
  self.Bind(wx.EVT_WINDOW_DESTROY, self.OnDestroy)
53
53
 
@@ -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,9 +179,9 @@ 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
- for i, item in enumerate(data):
184
+ for item in data:
184
185
  if item[0] == event:
185
186
  stamp = item[2] + 1
186
187
  item[1:] = [name, stamp, source, attribs]
@@ -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,15 +215,16 @@ 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
+
221
223
  def _reset_color():
222
224
  if self and i < self.ItemCount:
223
225
  self.SetItemBackgroundColour(i, 'white')
224
226
  wx.CallAfter(wx.CallLater, 1000, _reset_color)
225
-
227
+
226
228
  def copy(self):
227
229
  if not self.SelectedItemCount:
228
230
  return
@@ -232,8 +234,8 @@ class EventMonitor(wx.ListCtrl, ListCtrlAutoWidthMixin, CtrlInterface):
232
234
  event, name, *_, attribs = self.__items[i]
233
235
  text += "{}\t{}\n{}\n\n".format(event, name, attribs)
234
236
  Clipboard.write(text[:-1])
235
-
236
- def OnSortItems(self, evt): #<wx._controls.ListEvent>
237
+
238
+ def OnSortItems(self, evt): # <wx._controls.ListEvent>
237
239
  n = self.ItemCount
238
240
  if n < 2:
239
241
  return
@@ -253,19 +255,16 @@ class EventMonitor(wx.ListCtrl, ListCtrlAutoWidthMixin, CtrlInterface):
253
255
  self.SetItem(i, j, str(v))
254
256
  self.Select(i, item in ls)
255
257
  self.CheckItem(i, item in lc)
256
- self.SetItemTextColour(i, 'black') # reset font
258
+ self.SetItemTextColour(i, 'black') # reset font
257
259
  if item in lb:
258
260
  self.SetItemTextColour(i, 'blue')
259
261
  if item == fi:
260
262
  self.Focus(i)
261
-
262
- def OnItemDClick(self, evt): #<wx._core.MouseEvent>
263
- i, flag = self.HitTest(evt.Position)
264
- if i >= 0:
265
- item = self.__items[i]
266
- wx.CallAfter(wx.TipWindow, self, item[-1], 512) # attribs
267
- evt.Skip()
268
-
263
+
264
+ def OnItemActivated(self, evt): # <wx._controls.ListEvent>
265
+ item = self.__items[evt.Index]
266
+ wx.CallAfter(wx.TipWindow, self, item[-1], 512) # attribs
267
+
269
268
  def OnContextMenu(self, evt):
270
269
  obj = self.target
271
270
  wnd = self._target
@@ -294,9 +293,9 @@ def monit(widget=None, **kwargs):
294
293
  return ew
295
294
 
296
295
 
297
- ## Monkey-patch for wx.core (deprecated)
296
+ ## Monkey-patch for wx.core (deprecated).
298
297
  if 0:
299
- from wx import core # PY3
298
+ from wx import core # PY3
300
299
 
301
300
  def _EvtHandler_Bind(self, event, handler=None, source=None, id=wx.ID_ANY, id2=wx.ID_ANY):
302
301
  """
@@ -350,11 +349,11 @@ if 0:
350
349
  if v[0] == id or v[1] == handler:
351
350
  handlers.remove(v)
352
351
  else:
353
- handlers.pop(0) # No optional arguments are specified.
352
+ handlers.pop(0) # No optional arguments are specified.
354
353
  if not handlers:
355
354
  del vmap[event.typeId]
356
355
  except KeyError:
357
- pass # Note: vmap is actually inconsistent, but ignored.
356
+ pass # Note: vmap is actually inconsistent, but ignored.
358
357
  return retval
359
358
 
360
359
  core.EvtHandler.Unbind = _EvtHandler_Unbind