Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 8 additions & 8 deletions PYME/Acquire/ExecTools.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,20 +91,20 @@ def execBG(codeObj, localVars = defLocals, globalVars = defGlobals):
t.start()
return t

def execFile(filename, localVars = defLocals, globalVars = defGlobals):
def execFile(filename, localVars = defLocals, globalVars = defGlobals, then=None):
#fid = open(checkFilename(filename))
#code = fid.read()
#fid.close()

_execfile(filename, localVars, globalVars)
if then is not None:
then()

def execFileBG(filename, localVars = defLocals, globalVars = defGlobals):
#fid = open(checkFilename(filename))
#code = fid.read()
#fid.close()

#execBG(checkFilename(filename), localVars, globalVars)
threading.Thread(target=execFile, args = (filename, localVars, globalVars)).start()
def execFileBG(filename, localVars = defLocals, globalVars = defGlobals, then=None):
t = threading.Thread(target=execFile, args = (filename, localVars, globalVars, then))
t.start()
#return the thread so we can join it ...
return t

def _bginit(name, codeObj):
global defGlobals
Expand Down
5 changes: 1 addition & 4 deletions PYME/Acquire/acquire_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -126,10 +126,7 @@ def _initialize_hardware(self):
logger.debug('Init run, waiting on background threads')

def _wait_for_init_complete(self):
while not self.scope.initDone:
time.sleep(0.1)

#if self.scope.initDone == True:
self.scope.wait_for_init()
logger.debug('Backround initialization done')

def _on_frame_group(self, *args, **kwargs):
Expand Down
2 changes: 1 addition & 1 deletion PYME/Acquire/acquiremainframe.py
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ def _initialize_hardware(self):


def _check_init_done(self):
if self.scope.initDone == True and self._check_init_done in self.time1.WantNotification:
if self.scope.initialized == True and self._check_init_done in self.time1.WantNotification:
logger.debug('Backround initialization done')
self.time1.WantNotification.remove(self._check_init_done)

Expand Down
38 changes: 37 additions & 1 deletion PYME/Acquire/microscope.py
Original file line number Diff line number Diff line change
Expand Up @@ -877,7 +877,43 @@ def initialize(self, init_script_name, locals={}):

locals.update(scope=self)
ExecTools.setDefaultNamespace(locals, globals())
ExecTools.execFileBG(init_script_name, locals, globals())
self._init_thread = ExecTools.execFileBG(init_script_name, locals, globals(), then=self._post_init)

return self._init_thread

@property
def initialized(self):
"""
Checks if the initialisation thread has run (replaces check of initDone flag which needed to be manually set
in initialisation script). Semantics are slightly different in that this returns true even if there is an error
whist the old way of checking would get forever stuck at the splash screen.

Returns
-------

True if the initialisation script has run, False otherwise

"""
try:
return not self._init_thread.is_alive()
except AttributeError:
# don't have and _init_thread yet
return False

def wait_for_init(self):
self._init_thread.join()

def _post_init(self):
"""
Called after the init script runs to do stuff based on what hardware is present
"""

if len(self.positioning) > 0:
# we have registered piezos => we can do z-stacks
from PYME.Acquire import stackSettings

# FIXME - this looks like it will create a circular reference
self.stackSettings = stackSettings.StackSettings(self)

def register_piezo(self, piezo, axis_name, multiplier=1, needCamRestart=False, channel=0):
"""
Expand Down
14 changes: 9 additions & 5 deletions PYME/Acquire/ui/HDFSpoolFrame.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,9 @@ def _protocol_pan(self):
self.rbZStepped = wx.RadioButton(pan, -1, 'Z stepped')
self.rbZStepped.Bind(wx.EVT_RADIOBUTTON, self.OnToggleZStepping)
hsizer.Add(self.rbZStepped, 0, wx.ALL | wx.ALIGN_CENTER_VERTICAL, 2)

if not hasattr(self.scope, 'stackSettings'):
self.rbZStepped.Disable()

if self.spoolController.z_stepped:
self.rbZStepped.SetValue(True)
Expand Down Expand Up @@ -279,11 +282,12 @@ def _spool_pan(self):
def _init_ctrls(self):
self.AddNewElement(self._protocol_pan())

clp = afp.collapsingPane(self, caption='Z stepping ...')
self._seq_panel = seqdialog.seqPanel(clp, self.scope, mode='sequence')
clp.AddNewElement(self._seq_panel)
self.AddNewElement(clp)
self.seq_pan = clp
if hasattr(self.scope, 'stackSettings'):
clp = afp.collapsingPane(self, caption='Z stepping ...')
self._seq_panel = seqdialog.seqPanel(clp, self.scope, mode='sequence')
clp.AddNewElement(self._seq_panel)
self.AddNewElement(clp)
self.seq_pan = clp

self.AddNewElement(self._spool_to_pan())

Expand Down
4 changes: 2 additions & 2 deletions PYME/Acquire/ui/seqdialog.py
Original file line number Diff line number Diff line change
Expand Up @@ -205,9 +205,9 @@ def __init__(self, parent, scope, mode='default'):

#if not ('sa' in self.scope.__dict__):
# self.stackSettings = simplesequenceaquisator.SimpleSequenceAquisitor(self.scope.chaninfo, self.scope.cam, self.scope.shutters, self.scope.piezos)
if not 'stackSettings' in dir(self.scope):
#if not 'stackSettings' in dir(self.scope):
#inject stack settings into the scope object
self.scope.stackSettings = stackSettings.StackSettings(scope)
# self.scope.stackSettings = stackSettings.StackSettings(scope)
#for pz in self.scope.piezos:
# self.chPiezo.Append(pz[2])

Expand Down