Code Monkey home page Code Monkey logo

Comments (10)

dddomodossola avatar dddomodossola commented on July 3, 2024

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

from remi.

Antonio0307 avatar Antonio0307 commented on July 3, 2024

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?

from remi.

Antonio0307 avatar Antonio0307 commented on July 3, 2024

“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?:)

from remi.

dddomodossola avatar dddomodossola commented on July 3, 2024

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 ;-)

from remi.

Antonio0307 avatar Antonio0307 commented on July 3, 2024

@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! : )

from remi.

dddomodossola avatar dddomodossola commented on July 3, 2024

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 ;-)

from remi.

Antonio0307 avatar Antonio0307 commented on July 3, 2024

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.........

from remi.

dddomodossola avatar dddomodossola commented on July 3, 2024

Which kind of errors you get?

from remi.

Antonio0307 avatar Antonio0307 commented on July 3, 2024

from remi.

Antonio0307 avatar Antonio0307 commented on July 3, 2024

from remi.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.