Merge pull request #165 from RobinD42/issue158-use-dispatcher-disconnect

Disconnect dispatcher receivers
This commit is contained in:
Robin Dunn
2016-09-02 22:25:41 -07:00
committed by GitHub
6 changed files with 55 additions and 10 deletions

View File

@@ -169,6 +169,9 @@ class Display(editwindow.EditWindow):
def push(self, command, more):
"""Receiver for Interpreter.push signal."""
if not self:
dispatcher.disconnect(receiver=self.push, signal='Interpreter.push')
return
self.Refresh()
def Refresh(self):
@@ -205,7 +208,11 @@ class Calltip(wx.TextCtrl):
self.SetFont(font)
def display(self, calltip):
"""Receiver for """+self.ShellClassName+""".calltip signal."""
"""Receiver for this.calltip signal."""
if not self:
dispatcher.disconnect(receiver=self.display, signal=self.ShellClassName+'.calltip')
return
## self.SetValue(calltip) # Caused refresh problem on Windows.
self.Clear()
self.AppendText(calltip)
@@ -220,30 +227,50 @@ class SessionListing(wx.TextCtrl):
style = (wx.TE_MULTILINE | wx.TE_READONLY |
wx.TE_RICH2 | wx.TE_DONTWRAP)
wx.TextCtrl.__init__(self, parent, id, style=style)
self.ShellClassName = ShellClassName
dispatcher.connect(receiver=self.addHistory,
signal=ShellClassName+".addHistory")
signal=self.ShellClassName+".addHistory")
dispatcher.connect(receiver=self.clearHistory,
signal=ShellClassName+".clearHistory")
signal=self.ShellClassName+".clearHistory")
dispatcher.connect(receiver=self.loadHistory,
signal=ShellClassName+".loadHistory")
signal=self.ShellClassName+".loadHistory")
df = self.GetFont()
font = wx.Font(df.GetPointSize(), wx.FONTFAMILY_TELETYPE, wx.FONTSTYLE_NORMAL, wx.FONTWEIGHT_NORMAL)
self.SetFont(font)
def _disconnect(self):
dispatcher.disconnect(receiver=self.addHistory,
signal=self.ShellClassName+".addHistory")
dispatcher.disconnect(receiver=self.clearHistory,
signal=self.ShellClassName+".clearHistory")
dispatcher.disconnect(receiver=self.loadHistory,
signal=self.ShellClassName+".loadHistory")
def loadHistory(self, history):
# preload the existing history, if any
if not self:
self._disconnect()
return
hist = history[:]
hist.reverse()
self.SetValue('\n'.join(hist) + '\n')
self.SetInsertionPointEnd()
def addHistory(self, command):
if not self:
self._disconnect()
return
if command:
self.SetInsertionPointEnd()
self.AppendText(command + '\n')
def clearHistory(self):
if not self:
self._disconnect()
return
self.SetValue("")
@@ -262,6 +289,9 @@ class DispatcherListing(wx.TextCtrl):
def spy(self, signal, sender):
"""Receiver for Any signal from Any sender."""
if not self:
dispatcher.disconnect(receiver=self.spy)
return
text = '%r from %s' % (signal, sender)
self.SetInsertionPointEnd()
start, end = self.GetSelection()

View File

@@ -23,7 +23,7 @@ class Document:
def read(self):
"""Return contents of file."""
if self.filepath and os.path.exists(self.filepath):
f = file(self.filepath, 'rb')
f = open(self.filepath, 'rb')
try:
return f.read()
finally:
@@ -34,7 +34,7 @@ class Document:
def write(self, text):
"""Write text to file."""
try:
f = file(self.filepath, 'wb')
f = open(self.filepath, 'wb')
f.write(text)
finally:
if f:

View File

@@ -292,6 +292,10 @@ class EditorNotebookFrame(EditorFrame):
def _editorChange(self, editor):
"""Editor change signal receiver."""
if not self:
dispatcher.disconnect(receiver=self._editorChange,
signal='EditorChange', sender=self.notebook)
return
self.setEditor(editor)
def OnAbout(self, event):

View File

@@ -81,6 +81,11 @@ class EditWindow(stc.StyledTextCtrl):
def _fontsizer(self, signal):
"""Receiver for Font* signals."""
if not self:
dispatcher.disconnect(receiver=self._fontsizer, signal='FontIncrease')
dispatcher.disconnect(receiver=self._fontsizer, signal='FontDecrease')
dispatcher.disconnect(receiver=self._fontsizer, signal='FontDefault')
return
size = self.GetZoom()
if signal == 'FontIncrease':
size += 1

View File

@@ -66,6 +66,9 @@ class FillingTree(wx.TreeCtrl):
def push(self, command, more):
"""Receiver for Interpreter.push signal."""
if not self:
dispatcher.disconnect(receiver=self.push, signal='Interpreter.push')
return
self.display()
def OnItemExpanding(self, event):
@@ -258,6 +261,9 @@ class FillingText(editwindow.EditWindow):
def push(self, command, more):
"""Receiver for Interpreter.push signal."""
if not self:
dispatcher.disconnect(receiver=self.push, signal='Interpreter.push')
return
self.Refresh()
def SetText(self, *args, **kwds):

View File

@@ -845,7 +845,7 @@ class ShellFrameMixin:
if self.dataDir:
try:
name = os.path.join(self.dataDir, 'history')
f = file(name, 'w')
f = open(name, 'w')
hist = []
enc = 'utf-8'
for h in self.shell.history:
@@ -867,7 +867,7 @@ class ShellFrameMixin:
name = os.path.join(self.dataDir, 'history')
if os.path.exists(name):
try:
f = file(name, 'U')
f = open(name, 'U')
hist = f.read()
f.close()
self.shell.history = hist.split('\x00\n')
@@ -921,7 +921,7 @@ class ShellFrameMixin:
def EditStartupScript(self):
if os.path.exists(self.startupScript):
text = file(self.startupScript, 'U').read()
text = open(self.startupScript, 'U').read()
else:
text = ''
@@ -929,7 +929,7 @@ class ShellFrameMixin:
if dlg.ShowModal() == wx.ID_OK:
text = dlg.GetText()
try:
f = file(self.startupScript, 'w')
f = open(self.startupScript, 'w')
f.write(text)
f.close()
except: