Closed Antonio0307 closed 1 year ago
Hello @Antonio0307 , you don't need to write html to make a button. Look at this very simple example https://github.com/rawpython/remi/blob/master/examples/helloworld_app.py
Hello@dddomodossola,Thank you for your reply!"https://github.com/rawpython/remi/blob/master/examples/helloworld_app.py" I know that way.But I want to know,In this "html" mode ,callback function of button,how to do it?
“Callback function of button. ” ............... is it impossible to write in this mode?Because I want to take advantage of the existing HTML and CSS.I don't know. Can you understand my description?:)
Hello @Antonio0307 ,
Here is an example for you
import remi.gui as gui
from remi import start, App
import os
class MyApp(App):
def init(self, *args):
res_path = os.path.join(os.path.dirname(os.path.abspath(file)), 'res')
super(MyApp, self).__init__(*args, static_file_path={'myres': res_path})
def idle(self):
pass
def main(self):
my_html_body = """
<body>
<div>
<button onclick="remi.sendCallback('%(emitter)s','%(listener_func_name)s')">BTN<button/>
<div/>
<body/>
"""%{'emitter':str(id(self)), 'listener_func_name':'onmousedown_btn'}
my_css_body = """
"""
self.page.children['body'].add_child('myhtml', my_html_body)
self.page.children['body'].add_child('mycss', my_css_body)
#self.page.children['body'].onmousedown.do(self.onmousedown_btn)
main_container = gui.Container()
return main_container
def onmousedown_btn(self):
print("BTN")
if __name__ == "__main__":
start(MyApp, debug=True, address='0.0.0.0', port=0, start_browser=True, username=None, password=None)
Have a nice day ;-)
@dddomodossola Thank you very much for your quick and helpful response!!You are a master of “remi”! : ) What if there are several buttons ? "'emitter':str(id(self))"",I don't understand.It looks like a button id.I tried to do it, but it was wrong.
import remi.gui as gui from remi import start, App import os
class MyApp(App): def init(self, *args): res_path = os.path.join(os.path.dirname(os.path.abspath(file)), 'res')
super(MyApp, self).__init__(*args, static_file_path={'myres': res_path})
def idle(self):
pass
def main(self):
my_html_body = """
<body>
<div>
<button id = u1 onclick="remi.sendCallback('%(emitter)s','%(listener_func_name)s')">BTN<button/>
<button id = u2 onclick="remi.sendCallback('%(emitter)s','%(listener_func_name)s')">BTN<button/>
<div/>
<body/>
"""%{'emitter':str(id(self)), 'listener_func_name':'onmousedown_btn'}
my_css_body = """
"""
self.page.children['body'].add_child('myhtml', my_html_body)
self.page.children['body'].add_child('mycss', my_css_body)
#self.page.children['body'].onmousedown.do(self.onmousedown_btn)
main_container = gui.Container()
return main_container
def onmousedown_btn(self):
print("BTN")
def onmousedown_btn1(self):
print("BTN1")
if name == "main": start(MyApp, debug=True, address='0.0.0.0', port=0, start_browser=True, username=None, password=None)
In fact, it is very simple to use the editor.In addition, I have successfully completed several projects,But I want to try new methods.Have a nice weekend!Great master! : )
Hello @Antonio0307 , Excuse me for the late reply. str(id(self)) in this case is the identifier of the App class (the class who will receive the callback on button press). But it can be every remi widget.
Here is an example for multiple buttons:
import remi.gui as gui
from remi import start, App
import os
class MyApp(App):
def init(self, *args):
res_path = os.path.join(os.path.dirname(os.path.abspath(file)), 'res')
super(MyApp, self).__init__(*args, static_file_path={'myres': res_path})
def idle(self):
pass
def main(self):
my_html_body = """
<body>
<div>
<button id ="u1" onclick="remi.sendCallback('%(emitter)s','%(listener_func_name)s')" style="margin:5px">BTN<button/>
<button id ="u2" onclick="remi.sendCallback('%(emitter2)s','%(listener_func_name2)s')" style="margin:5px;background-color:red;">BTN1<button/>
<div/>
<body/>
"""%{'emitter':str(id(self)), 'listener_func_name':'onmousedown_btn',
'emitter2':str(id(self)), 'listener_func_name2':'onmousedown_btn1'}
my_css_body = """
"""
self.page.children['body'].add_child('myhtml', my_html_body)
self.page.children['body'].add_child('mycss', my_css_body)
#self.page.children['body'].onmousedown.do(self.onmousedown_btn)
main_container = gui.Container()
return main_container
def onmousedown_btn(self):
print("BTN")
def onmousedown_btn1(self):
print("BTN1")
if __name__ == "__main__":
start(MyApp, debug=True, address='0.0.0.0', port=0, start_browser=True, username=None, password=None)
Have a nice day ;-)
Very strange!
Hello @Antonio0307 , Excuse me for the late reply. str(id(self)) in this case is the identifier of the App class (the class who will receive the callback on button press). But it can be every remi widget.
Here is an example for multiple buttons:
import remi.gui as gui from remi import start, App import os class MyApp(App): def init(self, *args): res_path = os.path.join(os.path.dirname(os.path.abspath(file)), 'res') super(MyApp, self).__init__(*args, static_file_path={'myres': res_path}) def idle(self): pass def main(self): my_html_body = """ <body> <div> <button id ="u1" onclick="remi.sendCallback('%(emitter)s','%(listener_func_name)s')" style="margin:5px">BTN<button/> <button id ="u2" onclick="remi.sendCallback('%(emitter2)s','%(listener_func_name2)s')" style="margin:5px;background-color:red;">BTN1<button/> <div/> <body/> """%{'emitter':str(id(self)), 'listener_func_name':'onmousedown_btn', 'emitter2':str(id(self)), 'listener_func_name2':'onmousedown_btn1'} my_css_body = """ """ self.page.children['body'].add_child('myhtml', my_html_body) self.page.children['body'].add_child('mycss', my_css_body) #self.page.children['body'].onmousedown.do(self.onmousedown_btn) main_container = gui.Container() return main_container def onmousedown_btn(self): print("BTN") def onmousedown_btn1(self): print("BTN1") if __name__ == "__main__": start(MyApp, debug=True, address='0.0.0.0', port=0, start_browser=True, username=None, password=None)
Have a nice day ;-)
@dddomodossola Thank you for your reply!Very strange,My solution is the same as yours,But,report errors.That's why I asked you.It seems that I will find my own mistakes.........
Which kind of errors you get?
I found the problem. My mistake. I made a mistake
------------------ 原始邮件 ------------------ 发件人: "rawpython/remi" @.>; 发送时间: 2022年9月28日(星期三) 中午1:59 @.>; 抄送: "枫枫 @.**@.>; 主题: Re: [rawpython/remi] Excuse me,Callback function of button. How should I write?The body is successful.But button,I don't konw how to do this. (Issue #497)
Which kind of errors you get?
— Reply to this email directly, view it on GitHub, or unsubscribe. You are receiving this because you were mentioned.Message ID: @.***>
Thank you. I have another question. Bad reception on bullet train, ask later. :)
------------------ 原始邮件 ------------------ 发件人: "rawpython/remi" @.>; 发送时间: 2022年9月28日(星期三) 中午1:59 @.>; 抄送: "枫枫 @.**@.>; 主题: Re: [rawpython/remi] Excuse me,Callback function of button. How should I write?The body is successful.But button,I don't konw how to do this. (Issue #497)
Which kind of errors you get?
— Reply to this email directly, view it on GitHub, or unsubscribe. You are receiving this because you were mentioned.Message ID: @.***>
import remi.gui as gui from remi import start, App import os
class MyApp(App): def init(self, *args): res_path = os.path.join(os.path.dirname(os.path.abspath(file)), 'res')
if name == "main": start(MyApp, debug=True, address='0.0.0.0', port=0, start_browser=True, username=None, password=None)