class TestTextField(TestCase): def setUp(self) -> None: self.test_field = TextField() self.valid_char_num = randint(1001, 3000) self.invalid_char_num = randint(0, 999) self.valid_text = gen_random_text(self.valid_char_num) self.invalid_text = gen_random_text(self.invalid_char_num) def test_valid_text_field(self): self.assertTrue(self.test_field.is_valid(self.valid_text)) def test_invalid_text_field(self): self.assertFalse(self.test_field.is_valid(self.invalid_text))
class ExampleModelWithFk(Model): __tablename__ = 'example_model_with_fk' id = PrimaryKeyField() integer_field = IntegerField() text_field = TextField() fk_field = ForeignKey(to=SimpleExampleModel)
def on_touch_move(self, touch): if self.selected and touch.grab_current == self: for c in self.layout_maker.selections: if c == self: continue c.x += touch.dx c.y += touch.dy return TextField.on_touch_move(self, touch) return False
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)
def input_text(prompt, width, initial=None, **kwds): box = Dialog(**kwds) d = box.margin def ok(): box.dismiss(True) def cancel(): box.dismiss(False) lb = Label(prompt) lb.topleft = (d, d) tf = TextField(width) if initial: tf.set_text(initial) tf.enter_action = ok tf.escape_action = cancel tf.top = lb.top tf.left = lb.right + 5 box.add(lb) box.add(tf) tf.focus() box.shrink_wrap() if box.present(): return tf.get_text() else: return None
def BasicTextInputRow(title, *args, **kw): return Row( (Label(title, tooltipText=kw.get('tooltipText')), TextField(*args, **kw)))
def input_text_buttons(prompt, width, initial=None, **kwds): box = Dialog(**kwds) d = box.margin def ok(): box.dismiss(True) def cancel(): box.dismiss(False) buts = [] buts.append(Button("OK", action=ok)) buts.append(Button("Cancel", action=cancel)) brow = Row(buts, spacing=d) lb = Label(prompt) lb.topleft = (d, d) tf = TextField(width) if initial: tf.set_text(initial) tf.enter_action = ok tf.escape_action = cancel tf.top = lb.top tf.left = lb.right + 5 trow = Row([lb, tf], spacing=d) col = Column([trow, brow], spacing=d, align='c') col.topleft = (d, d) box.add(col) tf.focus() box.shrink_wrap() if box.present(): return tf.get_text() else: return None
class SimpleExampleModel(Model): id = PrimaryKeyField() integer_field = IntegerField() text_field = TextField(required=False) required_text_field = TextField(required=True)
def setUp(self) -> None: self.test_field = TextField() self.valid_char_num = randint(1001, 3000) self.invalid_char_num = randint(0, 999) self.valid_text = gen_random_text(self.valid_char_num) self.invalid_text = gen_random_text(self.invalid_char_num)