def read_fields_from_spec(self): # Ordered field list. Determines the order we read in fields from # the input file, and the order we display widgets to view/edit # the field values. # Fields can have child fields too, so it's a tree structure. # The most common kind of parent-child relationship is when there's an # array, and each element in that array is a struct of multiple fields. self.fields = [] # Read field specifications from CSV, one field per row. # We'll read in each field as a dict. The first row in the CSV file # specifies the dict keys. # Here we are automatically assuming a replay file, but maybe we'll # detect and support other GCI types like ghosts later. with open('replay_fields.csv', 'r') as f: for field_spec in csv.DictReader(f): try: if field_spec['data_type'] == '': raise FieldSpecError( "One of the fields is missing a data_type.") field_type = field_spec['data_type'] if field_type == 'array': field = ArrayField(field_spec, QComboBoxWidget()) elif field_type == 'dict': field = DictField(field_spec) elif field_type == 'float': field = FloatField(field_spec, QLineEditWidget()) elif field_type == 'hex': field = HexField(field_spec, QLineEditWidget()) elif field_type == 'hex_long_read_only': # We don't support editable QTextEdits, because # QTextEdit doesn't have a callback that only responds # to user edits; it responds to any function that edits # the text content. This results in an infinite loop # during the text -> value -> text back-and-forth # writing that we do to ensure consistent text format. field = LongHexField(field_spec, QTextEditReadOnlyWidget()) elif field_type == 'int': field = IntField(field_spec, QLineEditWidget()) else: raise FieldSpecError( "One of the fields has an unsupported data_type:" f" {field_type}") except FieldSpecError as e: self.main_gui.display_error(f"Fields CSV error: {e}") return False # Add top-level fields to self.fields if not field.parent: self.fields.append(field) return True
class User(Model): __table__ = 'users' id = StringField(primary_key=True, default=next_id, ddl='varchar(50)') email = StringField(ddl='varchar(50)') passwd = StringField(ddl='varchar(50)') admin = BooleanField() name = StringField(ddl='varchar(50)') image = StringField(ddl='varchar(500)') created_at = FloatField(default=time.time)
class Comment(Model): __table__ = 'comments' id = StringField(primary_key=True, default=next_id, ddl='varchar(50)') blog_id = StringField(ddl='varchar(50)') user_id = StringField(ddl='varchar(50)') user_name = StringField(ddl='varchar(50)') user_image = StringField(ddl='varchar(500)') content = TextField() created_at = FloatField(default=time.time)
class Blog(Model): __table__ = 'blogs' id = StringField(primary_key=True, default=next_id, ddl='varchar(50)') user_id = StringField(ddl='varchar(50)') user_name = StringField(ddl='varchar(50)') user_image = StringField(ddl='varchar(500)') name = StringField(ddl='varchar(50)') summary = StringField(ddl='varchar(200)') content = TextField() created_at = FloatField(default=time.time)
class User(Model): name = StringField(required=True) description = StringField() date_added = DateField() age = IntField() coins = FloatField() is_superuser = BooleanField() def __str__(self): return 'User {}'.format(self.name, self.age) def __repr__(self): return '<User {}>'.format(self.name, self.age) def update(self): pass class Meta: table_name = 'ormtable' order_by = ('name', )
def FloatInputRow(title, *args, **kw): return Row( (Label(title, tooltipText=kw.get('tooltipText')), FloatField(*args, **kw)))
class MyModel(Model): __tablename__ = 'test' a = IntField(unique=True) b = VarcharField(num_char=255) c = FloatField()
class Point3DFieldGroup(BaseFieldGroup): cls = Point3D cls_ctor_args = () key2field = {"x": FloatField(), "y": FloatField(), "z": FloatField()}