from bowtie.html import Markdown from bowtie.control import Textbox from bowtie.tests.utils import reset_uuid, server_check reset_uuid() mark = Markdown(''' # top ## middle [link]('hello.html') ''') side = Markdown(''' # sideheader ''') text = Textbox(area=True) def write(txt): """Update markdown text.""" mark.do_text(txt) @pytest.fixture def markdown(build_reset, monkeypatch): """Create markdown and text widgets.""" app = App(__name__, sidebar=True) app.add(mark) app.add_sidebar(side) app.add_sidebar(text) app.subscribe(text.on_change)(write)
#!/usr/bin/env python # -*- coding: utf-8 -*- from queue import Queue import pendulum from bowtie.control import Textbox, Button LINES = Queue(maxsize=50) talk = Textbox() click = Button('submit') chat = Textbox(autosize=True, disabled=True, area=True) def to_text(entry): return f'{entry[0].diff_for_humans()}: {entry[1]}' def update_chat(): chat.do_text('\n'.join(map(to_text, list(LINES.queue)[::-1]))) def clicked(): text = talk.get() entered(text) def entered(text): if LINES.full(): _ = LINES.get() tt = text[:144] now = pendulum.utcnow() LINES.put((now, tt))
#!/usr/bin/env python # -*- coding: utf-8 -*- from bowtie.visual import Markdown from bowtie.control import Textbox mark = Markdown(''' # Text you write ## goes here link to [bowtie](https://github.com/jwkvam/bowtie) ''') text = Textbox(area=True, autosize=True, placeholder='Enter markdown') sidemark = Markdown('# Live Markdown Editor') def write(txt): mark.do_text(txt) from bowtie import command, Layout @command def build(): layout = Layout(debug=False) layout.add(mark) layout.add_sidebar(sidemark) layout.add_sidebar(text) layout.subscribe(write, text.on_change)