maemo.org - Talk

maemo.org - Talk (https://talk.maemo.org/index.php)
-   SailfishOS (https://talk.maemo.org/forumdisplay.php?f=52)
-   -   Help me to code for Sailfish OS (https://talk.maemo.org/showthread.php?t=100817)

coderus 2020-09-03 00:07

Re: Help me to code for Sailfish OS
 
cool! [16 chars]

Markkyboy 2020-09-03 16:14

Re: Help me to code for Sailfish OS
 
The following code is a part of a Row, the Rectangle acts as a button and sends an IR command via WiFi to a Tasmotised Sonoff RF;

Code:

               
    Rectangle {
        id: mainLights1
        width: 80
        height: 80
        radius: 40
        color: "transparent"
        border.color: "yellow"
        border.width: mini1.pressed ? 4 : 2
        MouseArea {
            id: mini1
            anchors.fill: parent
            onClicked: {
                var xhttp = new XMLHttpRequest()
                xhttp.onreadystatechange = function() {
                    if (xhttp.readyState === 4 && xhttp.status === 200) {
                        led.opacity = 1.0
                        timer.start()
                        vibrate.start()
                        mainLights1.radius = 40

                        mainLights1.border.color = "green"  <-- ON, color is green

                        console.log("Main light1" + " " + xhttp.responseText)
                    }
                    else mainLights1.radius = 20
                }
                xhttp.open("POST", "http://192.168.0.230/cm?cmnd=cmnd/mini1/power toggle")
                xhttp.send()
            }
        }
        Label { text: "<b>PATIO</b>" ; anchors.centerIn: parent; color: "white"; font.pixelSize: Theme.fontSizeTiny }
    }

I'd like the following to happen when pressing the button;

Light ON = GREEN (mainLights1.border.color) - DONE
Light OFF = YELLOW (mainLights1.border.color) - ????

I've tried so many things, too many to list. Perhaps using 'if/else' is not the way to go?

coderus 2020-09-03 18:05

Re: Help me to code for Sailfish OS
 
i'm not sure what are you doing here, but probably you need to check result of network call, or perform additional call to get actual state of lights, and change color of button

Markkyboy 2020-09-03 18:37

Re: Help me to code for Sailfish OS
 
Well, it's a button made from a rectangle, when the button is pressed it turns a light on. When the light is on, the button should be green, when the light is turned off, the button should be yellow.

Sounds like you do understand my question, but how do I check the result of the network call?

In the code, there is console.log(), this outputs the xhttp.responseText, for example, the response looks like this;

Code:

mainLights1 "{"POWER":"ON"}"
Can I somehow use this output to change color of my button?

coderus 2020-09-03 21:07

Re: Help me to code for Sailfish OS
 
Code:

mainLights1.border.color = JSON.parse(xhttp.responseText).POWER == 'ON' ? "green" : "red"

Markkyboy 2020-09-04 21:50

Re: Help me to code for Sailfish OS
 
Quote:

Originally Posted by coderus (Post 1569106)
Code:

mainLights1.border.color = JSON.parse(xhttp.responseText).POWER == 'ON' ? "green" : "red"

Perfect!, thanks.

rob_kouw 2020-09-06 16:11

Re: Help me to code for Sailfish OS
 
coderus, I read something about a FileModel. The post referred to your GitHub page, but the files have been removed from there. Is it possible to view them somewhere else?

coderus 2020-09-06 20:05

Re: Help me to code for Sailfish OS
 
Quote:

Originally Posted by rob_kouw (Post 1569142)
coderus, I read something about a FileModel. The post referred to your GitHub page, but the files have been removed from there. Is it possible to view them somewhere else?

can you give more information what are you talking about? :D

rob_kouw 2020-09-07 07:06

Re: Help me to code for Sailfish OS
 
Sure. For my app (pure QML/JS now) I would like to have the possibility to select a file in Downloads, and the content into a variable.

coderus 2020-09-07 12:30

Re: Help me to code for Sailfish OS
 
Quote:

Originally Posted by rob_kouw (Post 1569148)
Sure. For my app (pure QML/JS now) I would like to have the possibility to select a file in Downloads, and the content into a variable.

check https://github.com/CODeRUS/splashscr...SecondPage.qml

you can select file in QML, but you can't read it using qml only. You need Qt or python backend


All times are GMT. The time now is 15:22.

vBulletin® Version 3.8.8