Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
# get interface and IP details of preferred interface
interface,ip = network.get_preferred_ip()
print 'Network details ' + network.unit + ' ' + interface + ' ' + ip
start_browser=False
if mode =='local':
ip= '127.0.0.1'
start_browser=True
if mode == 'native':
start(PPWebEditor, standalone=True)
exit()
else:
# start the web server to serve the Web Editor App
start(PPWebEditor,address=ip, port=network.editor_port,username=network.editor_username,password=network.editor_password,
multiple_instance=True,enable_file_cache=True, debug=False,
update_interval=0.3, start_browser=start_browser)
exit()
def run(camera, gui, raspi_headless, batch_process, raspi_gpio):
if gui:
print('starting gui...')
start(WebGui, address='0.0.0.0', websocket_port=8082, port=8081, host_name='raspberrypi.local', start_browser=True)
else:
try:
if camera or raspi_headless:
picam = importlib.import_module('picamera')
cam = picam.PiCamera()
cam.rotation=90
else:
cam = None
app = Workflow(dataset, imageprocessor, cam)
app.setup(setup_gpio=raspi_gpio)
except ImportError as e:
print('picamera module missing, please install using:\n sudo apt-get update \n'
' sudo apt-get install python-picamera')
logging.exception(e)
sys.exit()
while True:
#add the following 3 lines to your app and the on_window_close method to make the console close automatically
tag = gui.Tag(_type='script')
tag.add_child("javascript", """window.onunload=function(e){sendCallback('%s','%s');return "close?";};""" % (str(id(self)), "on_window_close"))
wid.add_child("onunloadevent", tag)
# returning the root widget
return wid
def on_window_close(self):
#here you can handle the unload
print("app closing")
self.close()
if __name__ == "__main__":
start(MyApp)
subit2 = gui.TreeItem("sub item2")
it2.append([gui.TreeItem("sub item1"), subit2, gui.TreeItem("sub item3")])
subit2.append([gui.TreeItem("sub sub item1"), gui.TreeItem("sub sub item2"), gui.TreeItem("sub sub item3")])
wid.append(self.tree)
# returning the root widget
return wid
if __name__ == "__main__":
# starts the webserver
# optional parameters
# start(MyApp,address='127.0.0.1', port=8081, multiple_instance=False,enable_file_cache=True, update_interval=0.1, start_browser=True)
start(MyApp, debug=True)
self.data[idx]['y'] = []
self.running = True
self.thread = threading.Thread(target=self.run)
self.thread.start()
else:
# self.plt.status.stop()
self.stop()
widget.set_text('Start')
widget.style['background-color'] = 'green'
self.started = not self.started
if __name__ == "__main__":
# starts the webserver
# start(MyApp,address='127.0.0.1', port=8081, multiple_instance=False,
# enable_file_cache=True, update_interval=0.1, start_browser=True)
start(MyApp, debug=False, port=8081, address='0.0.0.0', start_browser=True)
self.plotData3.scale(scale_factor_x, scale_factor_y)
def add_data(self):
with self.update_lock:
#the scale factors are used to adapt the values to the view
self.plotData1.add_coord(self.count, math.atan(self.count / 180.0 * math.pi))
self.plotData2.add_coord(self.count, math.cos(self.count / 180.0 * math.pi))
self.plotData3.add_coord(self.count, math.sin(self.count / 180.0 * math.pi))
self.svgplot.render()
self.count += 10
if not self.stop_flag:
Timer(0.1, self.add_data).start()
if __name__ == "__main__":
start(MyApp, address='0.0.0.0', port=0, update_interval=0.1, multiple_instance=True)
self.lblsession_status.set_text('LOGGED IN')
def on_renew(self, emitter):
if not self.login_manager.expired:
self.login_manager.renew_session()
self.lblsession_status.set_text('RENEW')
else:
self.lblsession_status.set_text('UNABLE TO RENEW')
def on_logout(self, emitter):
self.lblsession_status.set_text('LOGOUT')
if __name__ == "__main__":
# starts the webserver
start(MyApp, address='0.0.0.0', port=0, multiple_instance=False, debug=False)
self.mpl.ax.plot(self.plot_data)
self.mpl.redraw()
wid.append(bt)
wid.append(self.mpl)
return wid
def on_button_pressed(self, widget):
self.plot_data.append(random.random())
self.mpl.ax.plot(self.plot_data)
self.mpl.redraw()
if __name__ == "__main__":
start(MyApp, debug=True, address='0.0.0.0', port=0)
key = str(len(self.lbls_container.children))
lbl = gui.Label("label id: " + key, style={'border':'1px solid gray', 'margin':'3px'})
self.lbls_container.append(lbl, key)
def on_remove_a_label_pressed(self, emitter):
#if there are no childrens, return
if len(self.lbls_container.children) < 1:
return
key = str(len(self.lbls_container.children)-1)
self.lbls_container.remove_child(self.lbls_container.children[key])
def on_empty_pressed(self, emitter):
self.lbls_container.empty()
if __name__ == "__main__":
start(MyApp)
def onpagehide(self, emitter):
""" WebPage Event that occurs on webpage when the user navigates away """
super(MyApp, self).onpagehide(emitter)
def onpageshow(self, emitter, width, height):
""" WebPage Event that occurs on webpage gets shown """
super(MyApp, self).onpageshow(emitter, width, height)
def onresize(self, emitter, width, height):
""" WebPage Event that occurs on webpage gets resized """
super(MyApp, self).onresize(emitter, width, height)
if __name__ == "__main__":
# starts the webserver
start(MyApp, debug=True, address='0.0.0.0', port=0, start_browser=True, username=None, password=None)