def __get_prefixed_movie_dir__(self): """ method returns prefixed movie_dir by source name and output_prefix """ movie_dir = self.p.movie_dir prefix = self.p.output_prefix + '_' \ if not is_empty(self.p.output_prefix) else '' return as_path(movie_dir, prefix + 'm_' + self.source) \ if self.p.movie_prefixed_by_source else movie_dir
def convert_file_specification(file_specification): (signal_index, annotation_index, time_index) = \ [(None if is_empty(str(index)) else int(index)) \ for index in [file_specification.signal_index, file_specification.annotation_index, file_specification.time_index]] file_specification = file_specification._replace( annotation_index=annotation_index, signal_index=signal_index, time_index=time_index) return file_specification
def __get_prefixed_movie_name__(self): """ method prefixed movie_name by source name and output_prefix """ movie_name = self.p.movie_name #append source filename movie_name = '%s_%s' % (self.source, movie_name) \ if self.p.movie_prefixed_by_source else movie_name #append output_prefix return movie_name if is_empty(self.p.output_prefix) \ else '%s_%s' % (self.p.output_prefix, movie_name)
def check_data_indexes(self, _filename, disp): """ method used by client code explicitly, because of dynamic nature of placement of data columns which have to check at runtime to manage a situation when columns are specified by names and for different files they are placed in different columns """ message = None if not nvl(self.signal_label, self.annotation_label, self.time_label) == None: headers_count = nvl(self.headers_count, 1) file_headers = DataFileHeader(_filename, _separator=self.separator, number_of_lines=headers_count) #get header's lines headers = file_headers.getHeadersLines(headers_count) if self.signal_label: self.signal_index = get_index_of_string( self.signal_label, headers, _separator=self.separator) if self.annotation_label: self.annotation_index = get_index_of_string( self.annotation_label, headers, _separator=self.separator) if self.annotation_index == -1: message = ('There is no annotation index for label %s !' % (self.annotation_label)) if self.time_label: self.time_index = get_index_of_string( self.time_label, headers, _separator=self.separator) if self.time_index == -1: message = ('There is no time index for label %s !' % (self.time_label)) if self.signal_index == -1: if self.time_label: message = ('There is no signal index for label %s !' % (self.signal_label)) else: message = 'The signal index has to be set !' if is_positive(self.time_index) and self.time_format == None: message = 'For time column a time format parameter is required !' if not is_positive(self.time_index) and not is_empty(self.time_format): message = 'Time format requires time index column selection !' if message and disp: print('File: %s \n %s \n' % (_filename, message)) return False else: return True
def setAnnotationsButtons(self, _annotation): empty = is_empty(_annotation) or pl.sum(_annotation) == 0 self.set_title(empty) if empty: self.reset() else: unique = list(pl.unique(_annotation)) if len(unique) == self.buttons_count: self.setEnabledAnnotations(ALL_ANNOTATIONS) else: self.setEnabledAnnotations(unique) self.setUncheckNotAnnotations(unique) if self.isAllUnchecked(): self.__action_button__.setChecked(False) self.__action_button__.setEnabled(False)
def globalSettingsButtonClicked(self, clicked=None): if clicked: self.globalSettingsCheckBox.setChecked(clicked) if self.globalSettingsCheckBox.isChecked(): if not self.predefinedSeparatorsButtonsGroup.checkedButton() \ == None \ or not is_empty(self.customSeparatorEdit.text()): self.predefinedSeparatorsComposite.setEnabled(False) self.params.globalHandler(True, self.getSeparatorSign()) else: self.globalSettingsCheckBox.setChecked(False) InformationWindow(message='A separator must be chosen !') else: self.predefinedSeparatorsComposite.setEnabled(True) self.params.globalHandler(False)
def getData(self): # check if a separator is a white space if is_empty(self.params.separator): _data = pl.loadtxt(self._file, dtype=(str), skiprows=self.headers_count, unpack=True) else: _data = pl.loadtxt(self._file, dtype=(str), skiprows=self.headers_count, unpack=True, delimiter=self.params.separator) #some issues with preparing data, details in prepare_data_arrays func. return prepare_data_arrays(self._file, self.headers_count, _data)
def __correct_private_property__(name, value, not_empty, skip_prefix, skip_uppercase): """ check some conditions for print_private_properties, save_private_properties functions """ if not skip_prefix == None and name.startswith(skip_prefix): return False elif skip_uppercase and name == name.upper(): return False else: if not_empty and is_empty(value): return False elif hasattr(value, '__getattr__'): return False else: return True
def getData(self): # check if a separator is a white space if is_empty(self.params.separator): _data = pl.loadtxt(self._file, skiprows=self.headers_count, unpack=True) else: try: _data = pl.loadtxt(self._file, skiprows=self.headers_count, unpack=True, delimiter=self.params.separator) except ValueError: #try to load without a separator _data = pl.loadtxt(self._file, skiprows=self.headers_count, unpack=True) #some issues with preparing data, details in prepare_data_arrays func. return prepare_data_arrays(self._file, self.headers_count, _data)
def __createAnnotationButtons__(self): self.__button_group__ = ButtonGroupWidget(self) unique_annotations0 = get_unique_annotations( self.data_accessor.annotation0) empty = is_empty(unique_annotations0) self.set_title(empty) self.__all_button__ = CheckBoxWidget(self, i18n_def='ALL', clicked_handler=self.__all_button_handler__) self.__button_group__.addButton(self.__all_button__) for unique_annotation in unique_annotations0: annotationCheckBox = CheckBoxWidget(self, i18n_def=str(unique_annotation)) self.__button_group__.addButton(annotationCheckBox) self.__button_group__.setExclusive(False) self.__button_group__.connect(self.__button_group__, BUTTON_CLICKED_SIGNAL, self.__button_handler__)
def __createAnnotationButtons__(self): self.__button_group__ = ButtonGroupWidget(self) unique_annotations0 = get_unique_annotations( self.data_accessor.annotation0) empty = is_empty(unique_annotations0) self.set_title(empty) self.__all_button__ = CheckBoxWidget( self, i18n_def='ALL', clicked_handler=self.__all_button_handler__) self.__button_group__.addButton(self.__all_button__) for unique_annotation in unique_annotations0: annotationCheckBox = CheckBoxWidget( self, i18n_def=str(unique_annotation)) self.__button_group__.addButton(annotationCheckBox) self.__button_group__.setExclusive(False) self.__button_group__.connect(self.__button_group__, BUTTON_CLICKED_SIGNAL, self.__button_handler__)
def check_data_indexes(self, _filename, disp): """ method used by client code explicitly, because of dynamic nature of placement of data columns which have to check at runtime to manage a situation when columns are specified by names and for different files they are placed in different columns """ message = None if not nvl(self.signal_label, self.annotation_label, self.time_label) == None: headers_count = nvl(self.headers_count, 1) file_headers = DataFileHeader(_filename, _separator=self.separator, number_of_lines=headers_count) # get header's lines headers = file_headers.getHeadersLines(headers_count) if self.signal_label: self.signal_index = get_index_of_string(self.signal_label, headers, _separator=self.separator) if self.annotation_label: self.annotation_index = get_index_of_string(self.annotation_label, headers, _separator=self.separator) if self.annotation_index == -1: message = "There is no annotation index for label %s !" % (self.annotation_label) if self.time_label: self.time_index = get_index_of_string(self.time_label, headers, _separator=self.separator) if self.time_index == -1: message = "There is no time index for label %s !" % (self.time_label) if self.signal_index == -1: if self.time_label: message = "There is no signal index for label %s !" % (self.signal_label) else: message = "The signal index has to be set !" if is_positive(self.time_index) and self.time_format == None: message = "For time column a time format parameter is required !" if not is_positive(self.time_index) and not is_empty(self.time_format): message = "Time format requires time index column selection !" if message and disp: print("File: %s \n %s \n" % (_filename, message)) return False else: return True
def directory(self): _dir = str(self.__dir_label__.text()) if not (is_empty(_dir) or __NOT_SET_LABEL__ == _dir): _dir = str(QDir(_dir[1:-1]).path()) return _dir
def summary_statistics_is_selected(self): """ method returns true if there is any summary statistics selected """ return not (is_empty(self.summary_statistics_names) and is_empty(self.summary_statistics_classes))
class Globals(object): to_bool = lambda p: True if p.title() == "True" else False parser = argparse.ArgumentParser() parser.add_argument( "-e", "--settings_egg", help="give an egg for settings of application", # @IgnorePep8 default="") parser.add_argument("-u", "--use_settings_egg", default=True, type=to_bool) parser.add_argument("-s", "--settings_file", default="") parser.add_argument("-p", "--settings_package", help="""a package where a settings file is located (dots representation)""", default="") parser.add_argument("-l", "--lang", default="en") parser.add_argument("-m", "--start_menu_ident", default="") parser.add_argument("-d", "--debug", default=False, type=to_bool) parser.add_argument("-n", "--use_numpy_equivalent", type=to_bool) __args = parser.parse_args() USE_NUMPY_EQUIVALENT = __args.use_numpy_equivalent USE_SETTINGS_EGG = __args.use_settings_egg #if a parameter starts with a phrase 'use' it's value has bool type, #otherwise string, 'very intuitive bahaviour' DEBUG = __args.debug if len(__args.settings_egg) > 0: sys.path.insert(0, __args.settings_egg) USE_SETTINGS_EGG = True settings_filename = basename(__args.settings_file) \ if not is_empty(__args.settings_file) else None settings_package = __args.settings_package \ if not is_empty(__args.settings_package) else None if USE_SETTINGS_EGG: SETTINGS_FILE = get_application_settings(settings_package, settings_filename) SETTINGS_DIR = None else: PROGRAM_DIR = sys.path[0] SETTINGS_FILE = __args.settings_file \ if __args.settings_file else join(PROGRAM_DIR, "settings.properties") SETTINGS_DIR = dirname(SETTINGS_FILE) LANG = __args.lang DATA_DIR = None EXT_MASK = None MENUS_FILE = None PLUGINS_FILE = None PLUGINS_DIR = None START_MENU_ID = __args.start_menu_ident \ if len(__args.start_menu_ident) > 0 else None # a value of ITEM property doesn't matter, # this property is used as a marker in a situation # when one wish to acquire a property from GLOBALS # class without defining such property in that class # but defining such property only in the properties file, # so to get such property one have to pass the name of the needed # one as a parameter (with the same name as the required property) # of the get method as the following example shows: # GLOBALS.get(ICONS_FILE=GLOBALS.ITEM) # which is equivalent to # GLOBALS.ICONS_FILE # but without explicit definition of the ICONS_FILE property ITEM = True MAIN_WINDOW_NAME = "MainWindow" WORKSPACE_NAME = "MedWorkspace" TAB_MAIN_NAME = "Main" def get(self, **params): attr = get_keys_for_value(params, GLOBALS.ITEM, _one_key_only=True) if not hasattr(self, attr): return None value = getattr( self, get_keys_for_value(params, GLOBALS.ITEM, _one_key_only=True)) if len(params) > 1: param_keys = get_for_regexpr(params.keys(), '^PARAM[0-9]*$') if param_keys: for key in param_keys: if is_resource(value): value.resource = \ value.resource.replace("{" + key[5:] + "}", params[key]) else: value = value.replace("{" + key[5:] + "}", params[key]) return value
def max_value(self, _max_value): if isinstance(_max_value, int): self.__max_value__ = _max_value else: self.__max_value__ = 0 if is_empty(_max_value) else int(_max_value)
def summary_statistics_is_selected(self): """ method returns true if there is any summary statistics selected """ return not (is_empty(self.summary_statistics_names) and \ is_empty(self.summary_statistics_classes))
def get_application_settings(settings_package, settings_name): return get_resource_item( 'settings.etc' if is_empty(settings_package) else settings_package, 'settings.properties' if is_empty(settings_name) else settings_name)