def flexx_run(loop): """ Function to start a thread containing the main loop of flexx. """ global flexx_app asyncio.set_event_loop(loop) event = flexx_app # flexx_app was initialized with an Event() flexx_app = flx.launch(Example, loop=loop) event.set() flx.run()
def main(): title = 'caph slides' icon = None app = flx.App(MyApp) #UI = app.launch('chrome-browser', title=title, icon=icon, windowmode='fullscreen') UI = app.launch('chrome-app', title=title, icon=icon, windowmode='fullscreen') flx.run() return
def main(): META = Dict() META.version = 'v1.1.0' META.source = os.path.realpath(__file__) META.srcdir = os.path.dirname(os.path.realpath(__file__)) META.exetag = f'CPCP-{platform.system()}-{platform.machine()}' META.releases_url = 'https://api.github.com/repos/caph1993/cpcp/releases/latest' arg0, *args = sys.argv META.mode = args[0] if args else 'firefox-app' META.args = args[1:] executable = os.path.realpath(sys.executable) dev = executable != os.path.realpath(arg0) if executable == os.path.realpath(arg0): META.exe = executable META.wdir = os.path.dirname(executable) else: META.exe = None # dev mode, no executable META.wdir = META.srcdir os.chdir(META.wdir) init_userdir(META.srcdir) version_init(META.version, META.exe) cpcp = CPCP() if META.mode.startswith('--update-step='): update_step(int(META.mode[14:]), *META.args) elif META.mode == 'cli': cpp.main(MyCLI()) else: app = flx.App(MyApp) title = 'CPCP' icon = os.path.join('_cpcp', 'icon.png') icon = os.path.join(META.srcdir, icon) UI = app.launch(META.mode, title=title, icon=icon) t = Thread(target=cpcp.main, args=[UI]) t.setDaemon(True) t.start() t = Thread(target=version_main, args=[UI, META]) t.setDaemon(True) t.start() flx.run() sys.exit(0) return
# print(self.cnt, ':', self.le2.text) if self.le2.text.isdigit(): if int(self.le2.text) == self.ql[self.cnt][1]: self.le3.set_text('题目' + str(self.cnt + 1) + '回答正确') else: self.le3.set_text('题目' + str(self.cnt + 1) + '回答错误') self.ql[self.cnt][2] = str('你的答案' + self.le2.text) self.cnt += 1 else: self.le3.set_text('请输入整数答案') else: self.le3.set_text('答题结束,停止作答') self.cnt = 0 self.flag = 0 else: self.le3.set_text('未开始答题') class MainView(flx.PyComponent): def init(self): self.MW = MainWindow() if __name__ == '__main__': app = flx.App(MainView) app.launch('browser') # app.export('example.html') flx.run()
def main(): resourceserver.run_server() a = flx.App(ReticoBuilder) a.launch(runtime="chrome-browser", title="ReTiCo Builder") flx.run() # Or .run() if the App should terminate after closing. resourceserver.stop_server()
# doc-export: Split """ Splitter widgets are cool! """ from flexx import flx class Split(flx.Widget): def init(self): with flx.HSplit(): flx.Widget(style='background:#f00') with flx.VSplit(): flx.Widget(style='background:#0f0') with flx.HSplit(): flx.Widget(style='background:#ff0') with flx.VSplit(): flx.Widget(style='background:#f0f') with flx.HSplit(): flx.Widget(style='background:#0ff') flx.Widget(style='background:#00f') if __name__ == '__main__': m = flx.launch(Split) flx.run()
def increase_age(self): self._mutate_age(self.age + 1) def _create_dom(self): # Use this method to create a root element for this widget. # If you just want a <div> you don't have to implement this. return flx.create_element('div') # the default is <div> def _render_dom(self): # Use this to determine the content. This method may return a # string, a list of virtual nodes, or a single virtual node # (which must match the type produced in _create_dom()). return [ flx.create_element('span', {}, 'Hello', flx.create_element('b', {}, self.name), '! '), flx.create_element( 'span', {}, 'I happen to know that your age is %i.' % self.age), flx.create_element('br'), flx.create_element('button', {'onclick': self.increase_age}, 'Next year ...') ] app = flx.App(Web) app.launch('browser') # show it now in a browser flx.run() # enter the mainloop """The _render_dom() method is called from an implicit reaction. This means that when any properties that are accessed during this function change, the function is automatically called again. This thus provides a declerative way to define the appearance of a widget using HTML elements. Above, the third argument in create_element() is a string, but this may also be a list of dicts (create_element() returns a dict)."""
from flexx import flx class Example(flx.Widget): def init(self): self.set_title("A simple GUI") with flx.VBox(): flx.Label(text="This is our first GUI!") flx.Button(text='Greet') flx.Button(text='Close') app = flx.App(Example) app.launch('app') # to run as a desktop app #app.launch('browser') # to open in the browser flx.run() # mainloop will exit when the app is closed
def run(self): app = flx.App(Website) app.launch('browser') flx.run()