def setup_filewatching(self, modified_times=None): folder_list = [] file_list = [ self.BLACS['connection_table_labscript'], self.BLACS['connection_table_h5file'] ] # append the list of globals file_list += self.BLACS['settings'].get_value(Setting, 'globals_list') # iterate over list, split folders off from files! calibration_list = self.BLACS['settings'].get_value( Setting, 'calibrations_list') for path in calibration_list: if os.path.isdir(path): folder_list.append(path) else: file_list.append(path) if modified_times is None: modified_times = {} # stop watching if we already were if self.filewatcher: self.filewatcher.stop() modified_times = self.filewatcher.get_modified_times() # Start the file watching! self.filewatcher = FileWatcher(lambda f, m: inmain(self._show), file_list, folder_list, modified_times=modified_times)
class Notification(object): name = name def __init__(self, BLACS): # set up the file watching self.BLACS = BLACS self.filewatcher = None # Create the widget self._ui = UiLoader().load(os.path.join(os.path.dirname(os.path.realpath(__file__)),'notification.ui')) self._ui.button.clicked.connect(self.on_recompile_connection_table) #self._ui.hide() def get_widget(self): return self._ui def get_properties(self): return {'can_hide':True, 'can_close':False} def set_functions(self,show_func,hide_func,close_func,get_state): self._show = show_func self._hide = hide_func self._close = close_func self._get_state = get_state def on_recompile_connection_table(self,*args,**kwargs): self.BLACS['plugins'][module].menu.on_recompile_connection_table() def setup_filewatching(self,modified_times = None): folder_list = [] file_list = [self.BLACS['connection_table_labscript'], self.BLACS['connection_table_h5file']] # append the list of globals file_list += self.BLACS['settings'].get_value(Setting,'globals_list') # iterate over list, split folders off from files! calibration_list = self.BLACS['settings'].get_value(Setting,'calibrations_list') for path in calibration_list: if os.path.isdir(path): folder_list.append(path) else: file_list.append(path) if modified_times is None: modified_times = {} # stop watching if we already were if self.filewatcher: self.filewatcher.stop() modified_times = self.filewatcher.get_modified_times() # Start the file watching! self.filewatcher = FileWatcher(lambda f,m: inmain(self._show),file_list,folder_list,modified_times=modified_times) def get_save_data(self): state = True if self._get_state() == 'hidden' or self._get_state() == 'shown' else False return {'modified_times':self.filewatcher.get_modified_times() if self.filewatcher else {}, 'visible':state} def close(self): self.filewatcher.stop()
def setup_filewatching(self, clean_modified_info=None): folder_list = [] file_list = [ self.BLACS['connection_table_labscript'], self.BLACS['connection_table_h5file'] ] labconfig = self.BLACS['exp_config'] try: hashable_types = labconfig.get('BLACS/plugins', 'connection_table.hashable_types') hashable_types = ast.literal_eval(hashable_types) except labconfig.NoOptionError: hashable_types = ['.py', '.txt', '.ini', '.json'] try: polling_interval = self.BLACS['exp_config'].getfloat( 'BLACS/plugins', 'connection_table.polling_interval') except labconfig.NoOptionError: polling_interval = 1 logger.info('Using hashable_types: {}; polling_interval: {}'.format( hashable_types, polling_interval)) # append the list of globals file_list += self.BLACS['settings'].get_value(Setting, 'globals_list') # iterate over list, split folders off from files! calibration_list = self.BLACS['settings'].get_value( Setting, 'calibrations_list') for path in calibration_list: if os.path.isdir(path): folder_list.append(path) else: file_list.append(path) # stop watching if we already were if self.filewatcher is not None: self.filewatcher.stop() # Should only be calling this with modified_info not None once at startup: assert clean_modified_info is None clean_modified_info = self.filewatcher.get_clean_modified_info() # Start the file watching! self.filewatcher = FileWatcher( self.callback, file_list, folder_list, clean_modified_info=clean_modified_info, hashable_types=hashable_types, interval=polling_interval, )
def setup_filewatching(self,modified_times = None): folder_list = [] file_list = [self.BLACS['connection_table_labscript'], self.BLACS['connection_table_h5file']] # append the list of globals file_list += self.BLACS['settings'].get_value(Setting,'globals_list') # iterate over list, split folders off from files! calibration_list = self.BLACS['settings'].get_value(Setting,'calibrations_list') for path in calibration_list: if os.path.isdir(path): folder_list.append(path) else: file_list.append(path) if modified_times is None: modified_times = {} # stop watching if we already were if self.filewatcher: self.filewatcher.stop() modified_times = self.filewatcher.get_modified_times() # Start the file watching! self.filewatcher = FileWatcher(lambda f,m: inmain(self._show),file_list,folder_list,modified_times=modified_times)
class Notification(object): name = name def __init__(self, BLACS): # set up the file watching self.BLACS = BLACS self.filewatcher = None # Create the widget self._ui = QUiLoader().load( os.path.join(os.path.dirname(os.path.realpath(__file__)), 'notification.ui')) self._ui.button.clicked.connect(self.on_recompile_connection_table) #self._ui.hide() def get_widget(self): return self._ui def get_properties(self): return {'can_hide': True, 'can_close': False} def set_functions(self, show_func, hide_func, close_func, get_state): self._show = show_func self._hide = hide_func self._close = close_func self._get_state = get_state def on_recompile_connection_table(self, *args, **kwargs): self.BLACS['plugins'][module].menu.on_recompile_connection_table() def setup_filewatching(self, modified_times=None): folder_list = [] file_list = [ self.BLACS['connection_table_labscript'], self.BLACS['connection_table_h5file'] ] # append the list of globals file_list += self.BLACS['settings'].get_value(Setting, 'globals_list') # iterate over list, split folders off from files! calibration_list = self.BLACS['settings'].get_value( Setting, 'calibrations_list') for path in calibration_list: if os.path.isdir(path): folder_list.append(path) else: file_list.append(path) if modified_times is None: modified_times = {} # stop watching if we already were if self.filewatcher: self.filewatcher.stop() modified_times = self.filewatcher.get_modified_times() # Start the file watching! self.filewatcher = FileWatcher(lambda f, m: inmain(self._show), file_list, folder_list, modified_times=modified_times) def get_save_data(self): state = True if self._get_state() == 'hidden' or self._get_state( ) == 'shown' else False return { 'modified_times': self.filewatcher.get_modified_times() if self.filewatcher else {}, 'visible': state } def close(self): self.filewatcher.stop()
class RecompileNotification(object): name = name def __init__(self, BLACS): # set up the file watching self.BLACS = BLACS self.filewatcher = None self.clean_modified_info = None # Create the widget self._ui = UiLoader().load( os.path.join(PLUGINS_DIR, module, 'notification.ui')) self._ui.button.clicked.connect(self.on_recompile_connection_table) def get_widget(self): return self._ui def get_properties(self): return {'can_hide': True, 'can_close': False} def set_functions(self, show_func, hide_func, close_func, get_state): self._show = show_func self._hide = hide_func self._close = close_func self._get_state = get_state def on_recompile_connection_table(self, *args, **kwargs): self.BLACS['plugins'][module].menu.on_recompile_connection_table() def callback(self, name, info, event=None): if event == 'deleted': logger.info('{} {} ({})'.format(name, event, info)) inmain(self._show) if event == 'modified': logger.info('{} {} ({})'.format(name, event, info)) inmain(self._show) elif event == 'original': logger.info('All watched files restored') inmain(self._close) elif event == 'restored': logger.info('{} {} ({})'.format(name, event, info)) elif event == 'debug': logger.info(info) def setup_filewatching(self, clean_modified_info=None): folder_list = [] file_list = [ self.BLACS['connection_table_labscript'], self.BLACS['connection_table_h5file'] ] labconfig = self.BLACS['exp_config'] try: hashable_types = labconfig.get('BLACS/plugins', 'connection_table.hashable_types') hashable_types = ast.literal_eval(hashable_types) except labconfig.NoOptionError: hashable_types = ['.py', '.txt', '.ini', '.json'] try: polling_interval = self.BLACS['exp_config'].getfloat( 'BLACS/plugins', 'connection_table.polling_interval') except labconfig.NoOptionError: polling_interval = 1 logger.info('Using hashable_types: {}; polling_interval: {}'.format( hashable_types, polling_interval)) # append the list of globals file_list += self.BLACS['settings'].get_value(Setting, 'globals_list') # iterate over list, split folders off from files! calibration_list = self.BLACS['settings'].get_value( Setting, 'calibrations_list') for path in calibration_list: if os.path.isdir(path): folder_list.append(path) else: file_list.append(path) # stop watching if we already were if self.filewatcher is not None: self.filewatcher.stop() # Should only be calling this with modified_info not None once at startup: assert clean_modified_info is None clean_modified_info = self.filewatcher.get_clean_modified_info() # Start the file watching! self.filewatcher = FileWatcher( self.callback, file_list, folder_list, clean_modified_info=clean_modified_info, hashable_types=hashable_types, interval=polling_interval, ) def get_save_data(self): if self.clean_modified_info is not None: # We are doing a restart after a recompilation - return the modified info # that was just saved: return {'clean_modified_info': self.clean_modified_info} else: return { 'clean_modified_info': self.filewatcher.get_clean_modified_info() } def on_restart(self): # Connection table has been sucessfully recompiled, we are restarting. This is # the only point, other than when they are first added for watching, that we # replace the 'clean' modified info of the files with their current modified # info. Since we just recompiled, the current state is the clean state self.filewatcher.stop() self.clean_modified_info = self.filewatcher.get_modified_info() self.filewatcher = None # Hide the notification self._close() def close(self): if self.filewatcher is not None: self.filewatcher.stop()