def testEpoch(self):
self.curChoice = self.curChoices.pop()
self.pieMenu.highlight(self.curChoice, style='pop')
self.src.setMarker(10.0*(self.choices.index(self.curChoice)+1.0))
# a little extra at the end to make sure we get the last segment
wx.CallLater(1000.0*self.trialSecs*1.1, self.testClassify)
python类CallLater()的实例源码
def testClassify(self):
testCap = self.getCap(np.min((self.getSessionTime(), 2.0*self.trialSecs)))
segs = testCap.segment(start=0.0, end=self.trialSecs)
# select the last segment only
segs = (segs.setMarkers(None)
.select(lambda mark: np.isclose(mark, np.max(segs.markers))))
assert segs.getNSeg() == 1
##print 'test nSeg: ', segs.nSeg
##print segs.data.shape
##print ''
freqs, testData = self.powerize((segs,))
testData = self.stand.apply(testData)[0]
label = self.classifier.label(testData)
selection = self.choices[label]
self.src.incrementMarker(label+1)
self.pieMenu.growBar(selection, 1.0)
self.confusion[label, self.choices.index(self.curChoice)] += 1.0
wx.CallLater(1000.0*self.iti, self.testClearTrial)
def testClearTrial(self, event=None):
self.pieMenu.zeroBars()
self.pieMenu.clearAllHighlights()
self.src.setMarker(0.0)
if len(self.curChoices) > 0:
wx.CallLater(1000.0*self.iti, self.runTestEpoch)
else:
wx.CallLater(1000.0*self.iti, self.endTest)
def play(self, event=None):
self.loadAndPlay()
wx.CallLater(1000.0*3.0*self.previewSecs, self.stop)
def preview(self, event=None):
self.loadAndPlay()
wx.CallLater(1000.0*self.previewSecs, self.stop)
def highlight(self, choice, style='pop', secs=None, refresh=True):
"""Turn on a highlight for a given cell.
Args:
choice: Name of cell where highlight should be
turned on.
style: String describing the type of highlight.
Current possible values are 'jump' or
'pop'.
secs: Floating point seconds until the
highlight should be turned off. If
None, highlight will be left on until
manually cleared.
"""
if style.lower() == 'pop':
self.highlightPop.add(choice)
elif style.lower() == 'jump':
self.highlightJump.add(choice)
else:
raise Exception('Unknown highlight style %s.' % style)
if refresh:
self.refresh()
if secs != None:
wx.CallLater(1000.0*secs, self.clearHighlight, choice=choice, refresh=refresh)
def OnMouseDoubleClick(self, event):
if self._zoomEnabled:
# Give a little time for the click to be totally finished
# before (possibly) removing the scrollbars and trigering
# size events, etc.
wx.CallLater(200, self.Reset)
def DoSwipeOrInput(self, msg):
global recordStatus
global treeDic
global recordTimeDelay
if treeDic!=None:
if recordStatus=="?":
if "??" in msg:
d = msg.replace("??\n", "").split("\n")
print("?????,", "???: ",d)
os.system("adb shell input swipe %d %d %d %d" % (int(d[0]), int(d[1]),int(d[2]),int(d[3])))
dlg = MessageDialog('??????????(?????%d?)' % recordTimeDelay, '??')
wx.CallLater(recordTimeDelay*1000, dlg.Destroy)
dlg.ShowModal()
getNewScreenShotAndDomFileThread()
else:
c = msg.split("\n")[0]
kT = msg.split("\n")[1]
print("?????,", "???",c)
if c!='':
if kT == "ADB":
os.system("adb shell am broadcast -a ADB_INPUT_TEXT --es msg '%s'" %c)
else:
os.system("adb shell input text '%s'" %c)
dlg = MessageDialog('??????????(?????%d?)' % recordTimeDelay, '??')
wx.CallLater(recordTimeDelay*1000, dlg.Destroy)
dlg.ShowModal()
getNewScreenShotAndDomFileThread()
else:
dlg = wx.MessageDialog(self, u"???????", u"????????", wx.OK | wx.ICON_ERROR)
if dlg.ShowModal() == wx.ID_OK:
dlg.Destroy()
else:
msg = "????????????????"
print(msg)
wx.CallAfter(pub.sendMessage, "update", msg=msg)
else:
msg = "?????????????"
print(msg)
wx.CallAfter(pub.sendMessage, "update", msg=msg)
def delayExit(self, e=None):
wx.CallLater(5000, self.onExit)
def __init__(self):
wx.Frame.__init__(self, parent=None, id=wx.ID_ANY,
title='Janet', size=(WIDTH, HEIGHT))
self.SetMinSize((WIDTH, HEIGHT))
self.browser = None
global g_count_windows
g_count_windows += 1
self.setup_icon()
# self.create_menu()
self.Bind(wx.EVT_CLOSE, self.OnClose)
# Set wx.WANTS_CHARS style for the keyboard to work.
# This style also needs to be set for all parent controls.
self.browser_panel = wx.Panel(self, style=wx.WANTS_CHARS)
self.browser_panel.Bind(wx.EVT_SET_FOCUS, self.OnSetFocus)
self.browser_panel.Bind(wx.EVT_SIZE, self.OnSize)
# On Linux must show before embedding browser, so that handle
# is available.
if LINUX:
self.Show()
self.embed_browser()
else:
self.embed_browser()
self.Show()
wx.CallLater(500, self.setup_gamepad) # this has to be delayed to make sure the DOM has loaded the list of games
def schedulePoll(self):
self.cancelPoll()
self.pollTimer = wx.CallLater(100, self.poll)
def on_timer(self):
w,h = self.size[0], self.size[1]
oldPosBlue = [self.blueCircle.x, self.blueCircle.y]
oldPosRed = [self.redCircle.x, self.redCircle.y]
changed = False
if self.mode2:
rate = 30
self.blueCircle.x = floatmap(self.absPos[0], 0, w)
self.blueCircle.y = floatmap(self.absPos[1], 0, h)
self.redCircle.x = floatmap(self.absPos[2], 0, w)
self.redCircle.y = floatmap(self.absPos[3], 0, h)
else:
rate = 40
self.blueCircle.x += self.incs[0]
self.blueCircle.y += self.incs[1]
self.redCircle.x += self.incs[2]
self.redCircle.y += self.incs[3]
if self.blueCircle.x < 0:
self.blueCircle.x = 0
elif self.blueCircle.x > w:
self.blueCircle.x = w
if self.blueCircle.y < 0:
self.blueCircle.y = 0
elif self.blueCircle.y > h:
self.blueCircle.y = h
if self.redCircle.x < 0:
self.redCircle.x = 0
elif self.redCircle.x > w:
self.redCircle.x = w
if self.redCircle.y < 0:
self.redCircle.y = 0
elif self.redCircle.y > h:
self.redCircle.y = h
if oldPosBlue[0] != self.blueCircle.x or oldPosBlue[1] != self.blueCircle.y:
self.currentCircle = self.blueCircle
newPos = [self.blueCircle.x, self.blueCircle.y]
self.distance(newPos)
changed = True
if oldPosRed[0] != self.redCircle.x or oldPosRed[1] != self.redCircle.y:
self.currentCircle = self.redCircle
newPos = [self.redCircle.x, self.redCircle.y]
self.distance(newPos)
changed = True
if changed:
self.Refresh()
wx.CallLater(rate, self.on_timer)
# FL END 23/05/2017
# FL START 29/05/17
# Fonction qui ajuste les volumes quand on change les radius des speakers
def _downloadSuccess(self):
self._stopped()
# Emulate add-on update (don't prompt to install).
from gui import addonGui
closeAfter = addonGui.AddonsDialog._instance is None
try:
try:
bundle=addonHandler.AddonBundle(self.destPath.decode("mbcs"))
except:
log.error("Error opening addon bundle from %s"%self.destPath,exc_info=True)
# Translators: The message displayed when an error occurs when opening an add-on package for adding.
gui.messageBox(_("Failed to open add-on package file at %s - missing file or invalid file format")%self.destPath,
# Translators: The title of a dialog presented when an error occurs.
_("Error"),
wx.OK | wx.ICON_ERROR)
return
bundleName=bundle.manifest['name']
for addon in addonHandler.getAvailableAddons():
if not addon.isPendingRemove and bundleName==addon.manifest['name']:
addon.requestRemove()
break
progressDialog = gui.IndeterminateProgressDialog(gui.mainFrame,
# Translators: The title of the dialog presented while an Addon is being updated.
_("Updating Add-on"),
# Translators: The message displayed while an addon is being updated.
_("Please wait while the add-on is being updated."))
try:
gui.ExecAndPump(addonHandler.installAddonBundle,bundle)
except:
log.error("Error installing addon bundle from %s"%self.destPath,exc_info=True)
if not closeAfter: addonGui.AddonsDialog(gui.mainFrame).refreshAddonsList()
progressDialog.done()
del progressDialog
# Translators: The message displayed when an error occurs when installing an add-on package.
gui.messageBox(_("Failed to update add-on from %s")%self.destPath,
# Translators: The title of a dialog presented when an error occurs.
_("Error"),
wx.OK | wx.ICON_ERROR)
return
else:
if not closeAfter: addonGui.AddonsDialog(gui.mainFrame).refreshAddonsList(activeIndex=-1)
progressDialog.done()
del progressDialog
finally:
try:
os.remove(self.destPath)
except OSError:
pass
if closeAfter:
wx.CallLater(1, addonGui.AddonsDialog(gui.mainFrame).Close)