Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
# todo: how to serialize the shaders? base64 or via a custom hook?
triangle.vertex_shader = "something that flexx can serialize"
triangle.fragment_shader = "something that flexx can serialize"
class Example(flx.Widget):
def init(self):
# All of this gets executed in JS
super().init()
with flx.HBox():
self.canvas = WgpuCanvas()
triangle.main(self.canvas)
if __name__ == "__main__":
m = flx.launch(Example, "chrome-browser")
flx.run()
RawJS('$')(node).datepicker()
return node
class Example(flx.Widget):
def init(self):
with flx.FormLayout():
self.start = DatePicker(title='Start date')
self.end = DatePicker(title='End date')
flx.Widget(flex=1)
if __name__ == '__main__':
m = flx.launch(Example, 'app')
flx.run()
"""
Simple hello world following the recommended style of writing apps,
using a custom widget that is populated in its ``init()``.
"""
from flexx import flx
class Main(flx.Widget):
def init(self):
self.b1 = flx.Button(text='Hello')
self.b2 = flx.Button(text='World')
if __name__ == '__main__':
m = flx.launch(Main)
flx.run()
with self.tree:
for cat in ('foo', 'bar', 'spam'):
with flx.TreeItem(text=cat):
for name in ('Martin', 'Kees', 'Hans'):
item = flx.TreeItem(title=name)
item.set_checked(cat=='foo' or None)
@flx.reaction('combo.text')
def _combo_text_changed(self, *events):
for ev in events:
print('combo text is now', ev.new_value)
if __name__ == '__main__':
m = flx.launch(KeyboardControlsTester)
flx.run()
self.map.add_osm_layers()
@flx.reaction('btnr.pointer_click')
def handle_remove_layers(self, *events):
self.map.remove_layers()
self.coords.set_text("Removing GEOJSON")
@flx.reaction('map.pointer_event')
def map_click(self, *events):
ev = events[-1]
coord = ev['event']['coordinate']
self.coords.set_text("Clicking on coordinate " + str(coord))
if __name__ == '__main__':
flx.launch(MainWidget, 'firefox-browser')
flx.run()
@flx.action
def set_data(self, data):
# We receive the data as a typed array.
# If we would send raw bytes, we would receive it as a DataView, which
# we can map to e.g. a Int16Array like so:
# data = Int16Array(blob.buffer, blob.byteOffset, blob.byteLength/2)
# Show the data as text. We could also e.g. plot it.
text = ['%i: %f<br>' % (i, data[i]) for i in range(len(data))]
header = 'This data (%i elements) was send in binary form:<br>' % len(data)
self.label.set_html(header + ''.join(text))
if __name__ == '__main__':
m = flx.launch(SendData, 'app')
flx.run()
self.but2 = flx.Button(text='Open new page')
@flx.reaction('but1.pointer_click')
def on_redirect(self, *events):
global window
window.location.href = 'http://python.org' # allow going back
# window.location.replace('http://python.org') # hard redirect
@flx.reaction('but2.pointer_click')
def on_opennew(self, *events):
global window
window.open('http://python.org', '_blank')
if __name__ == '__main__':
m = flx.launch(Redirect, 'browser')
flx.start()
self.slider2 = flx.Slider(min=0, max=6, value=0, flex=1)
self.plot = flx.PlotWidget(flex=1, xdata=time, xlabel='time',
ylabel='amplitude', title='a sinusoid')
@flx.reaction
def __update_amplitude(self, *events):
global Math
freq, phase = self.slider1.value, self.slider2.value
ydata = []
for x in self.plot.xdata:
ydata.append(Math.sin(freq*x*2*Math.PI+phase))
self.plot.set_data(self.plot.xdata, ydata)
if __name__ == '__main__':
m = flx.launch(SineExample)
flx.run()