Reply
Thread Tools
coderus's Avatar
Posts: 6,436 | Thanked: 12,701 times | Joined on Nov 2011 @ Ängelholm, Sweden
#121
cool! [16 chars]
__________________
Telegram | Openrepos | GitHub | Revolut donations
 

The Following 2 Users Say Thank You to coderus For This Useful Post:
Markkyboy's Avatar
Posts: 433 | Thanked: 727 times | Joined on Oct 2012 @ Costa Blanca, España
#122
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?
__________________
..oO(Don't just sit there standing around, pick up a shovel and sweep up!)Oo..
 

The Following User Says Thank You to Markkyboy For This Useful Post:
coderus's Avatar
Posts: 6,436 | Thanked: 12,701 times | Joined on Nov 2011 @ Ängelholm, Sweden
#123
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
__________________
Telegram | Openrepos | GitHub | Revolut donations
 

The Following User Says Thank You to coderus For This Useful Post:
Markkyboy's Avatar
Posts: 433 | Thanked: 727 times | Joined on Oct 2012 @ Costa Blanca, España
#124
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?
__________________
..oO(Don't just sit there standing around, pick up a shovel and sweep up!)Oo..
 

The Following User Says Thank You to Markkyboy For This Useful Post:
coderus's Avatar
Posts: 6,436 | Thanked: 12,701 times | Joined on Nov 2011 @ Ängelholm, Sweden
#125
Code:
mainLights1.border.color = JSON.parse(xhttp.responseText).POWER == 'ON' ? "green" : "red"
__________________
Telegram | Openrepos | GitHub | Revolut donations
 

The Following 5 Users Say Thank You to coderus For This Useful Post:
Markkyboy's Avatar
Posts: 433 | Thanked: 727 times | Joined on Oct 2012 @ Costa Blanca, España
#126
Originally Posted by coderus View Post
Code:
mainLights1.border.color = JSON.parse(xhttp.responseText).POWER == 'ON' ? "green" : "red"
Perfect!, thanks.
__________________
..oO(Don't just sit there standing around, pick up a shovel and sweep up!)Oo..
 

The Following User Says Thank You to Markkyboy For This Useful Post:
Posts: 301 | Thanked: 531 times | Joined on Aug 2010 @ The Netherlands
#127
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?
__________________
Palm Treo -> N900 -> N9 -> Jolla -> SailfishX -> XA2
Developer mode novice, and enjoying it
 

The Following User Says Thank You to rob_kouw For This Useful Post:
coderus's Avatar
Posts: 6,436 | Thanked: 12,701 times | Joined on Nov 2011 @ Ängelholm, Sweden
#128
Originally Posted by rob_kouw View Post
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?
__________________
Telegram | Openrepos | GitHub | Revolut donations
 

The Following User Says Thank You to coderus For This Useful Post:
Posts: 301 | Thanked: 531 times | Joined on Aug 2010 @ The Netherlands
#129
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.
__________________
Palm Treo -> N900 -> N9 -> Jolla -> SailfishX -> XA2
Developer mode novice, and enjoying it
 

The Following User Says Thank You to rob_kouw For This Useful Post:
coderus's Avatar
Posts: 6,436 | Thanked: 12,701 times | Joined on Nov 2011 @ Ängelholm, Sweden
#130
Originally Posted by rob_kouw View Post
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
__________________
Telegram | Openrepos | GitHub | Revolut donations
 

The Following 2 Users Say Thank You to coderus For This Useful Post:
Reply


 
Forum Jump


All times are GMT. The time now is 21:14.