def do_import(self): count = 0 for datum_text in self.datums: count += 1 self.grid.status_bar.showMessage('Importing {}'.format( pluralize(count, 'Datum'))) x, y = self.grid._get_next_coords() self.grid.new_datum_and_clip(x - self.grid.model.x_offset, y - self.grid.model.y_offset, datum_text, 0, emit=False) self.grid.view.clip_changed.emit() self.grid.status_bar.showMessage( 'Import file {} complete - {} imported'.format( self.file_name, pluralize(count, 'Datum')))
def __new__(mcs, name, bases, new_attrs): """Create a new class. Args: mcs: The metaclass. name: The name of the class. bases: List of base classes from which mcs inherits. new_attrs: The class attribute dictionary. """ if 'rest_entity_path' not in new_attrs: new_attrs['rest_entity_path'] = util.pluralize(util.underscore(name)) return type.__new__(mcs, name, bases, new_attrs)
def __new__(mcs, name, bases, new_attrs): """Create a new class. Args: mcs: The metaclass. name: The name of the class. bases: List of base classes from which mcs inherits. new_attrs: The class attribute dictionary. """ if 'rest_entity_path' not in new_attrs: new_attrs['rest_entity_path'] = util.pluralize( util.underscore(name)) return type.__new__(mcs, name, bases, new_attrs)
def open_file_name_dialog(self): files, _ = QFileDialog.getOpenFileNames( self, "Select Text Files for Import") self.files = files self.datums = [] self.file_name = ', '.join(files) for file_name in files: self.grid.status_bar.showMessage( 'Reading file {}'.format(file_name)) with open(file_name) as f: text = f.read() self.datums += list(filter(lambda y: y != '', text.split('-'))) self.grid.status_bar.showMessage('Prepare to Import {}'.format( pluralize(self.datums, 'Datum'))) self.output.setPlainText('\n'.join(self.datums))
def __init__(self, items=None, admin=None): self.all_items = [] if items is None else items self.admin = admin # Groups items under attrs with the snake_case plural form of the item class for item in self.all_items: setattr(item, 'network', self) if admin is not None: setattr(item, 'admin', self) if hasattr(self.admin, 'env'): setattr(item, 'env', self.admin.env) item_type = snake_case(pluralize(item.__class__.__name__)) if hasattr(self, item_type): getattr(self, item_type).append(item) else: setattr(self, item_type, [item])
def __new__(mcs, name, bases, new_attrs): """Create a new class. Args: mcs: The metaclass. name: The name of the class. bases: List of base classes from which mcs inherits. new_attrs: The class attribute dictionary. """ if '_singular' not in new_attrs or not new_attrs['_singular']: new_attrs['_singular'] = util.underscore(name) if '_plural' not in new_attrs or not new_attrs['_plural']: new_attrs['_plural'] = util.pluralize(new_attrs['_singular']) klass = type.__new__(mcs, name, bases, new_attrs) # if _site is defined, use the site property to ensure that user # and password are properly initialized. if '_site' in new_attrs: klass.site = new_attrs['_site'] return klass
def pn(cls): return pluralize(cls.__name__)
store.activateConfiguration = store.activateConfig def mkcv(klass): def cv(self, eset): valid_ents = set(self.cm.list_objects(klass)) return [ent for ent in eset if ent not in valid_ents] return cv def mkle(klass): def le(self): return self.cm.list_objects(klass) return le for klass in ["Feature", "Group", "Node", "Parameter", "Subsystem", "Branch", "Tag"]: setattr(store, "check%sValidity" % klass, mkcv(klass)) setattr(store, pluralize(klass), property(mkle(klass))) def mkgsg(grp): def get_special_group(self): return self.cm.make_proxy_object("group", grp) return get_special_group for msg, grp in [("getDefaultGroup", "+++DEFAULT"), ("getSkeletonGroup", "+++SKEL")]: setattr(store, msg, mkgsg(grp)) def setup_labeling(the_store): set_store_singleton(the_store) the_store.getPartitionGroup() return the_store def connect(**options):
return cv def mkle(klass): def le(self): return self.cm.list_objects(klass) return le for klass in [ "Feature", "Group", "Node", "Parameter", "Subsystem", "Branch", "Tag" ]: setattr(store, "check%sValidity" % klass, mkcv(klass)) setattr(store, pluralize(klass), property(mkle(klass))) def mkgsg(grp): def get_special_group(self): return self.cm.make_proxy_object("group", grp) return get_special_group for msg, grp in [("getDefaultGroup", "+++DEFAULT"), ("getSkeletonGroup", "+++SKEL")]: setattr(store, msg, mkgsg(grp)) def setup_labeling(the_store):