Changing the QLabel frameshape
-
OK. Thank you. self.Temp_bar = self.ui.Temp_bar brought the Progressbar up that I designed immediately.
This is the part I have been struggling with, as I have found the wealth of information regarding these features on the web... difficult to wade through at best.
Still learning, but you guys have been super helpful. Thank you for your valuable time
-
I import 6 values from a separate Python routine that obtains the serial data from my Arduino (it's a pan/tilt camera with fake gun)
self.current_tilt = 0 # Current tilt (info received from arduino and displayed in LCD numbers)
self.current_pan = 0 # Current pan (info received from arduino and displayed in LCD numbers)
self.ammo_value = 0 # Ammo value (info received from arduino and displayed in LCD numbers)
self.time_value = 0 # Time at 100% (info received from arduino and displayed in LCD numbers)
self.tmp_value = 0 # Temp level (info received from arduino and displayed on ProgressBar)
self.rpm_value = 0 # Rounds per minute (info received from arduino and displayed on ProgressBar)If I print these imported values, they print out fine and track the changing values as they arrive from the Arduino.
print(self.current_pan)
print(self.current_tilt)
print(self.ammo_value)
print(self.time_value)
print(self.tmp_value)
print(self.rpm_value)However, when I go to use these variables, two of them are causing an issue.
self.Pan_LCD.display(self.current_pan) # All these values are retrieved in Comm_ard.py
self.Tilt_LCD.display(self.current_tilt)
self.Ammo_LCD.display(self.ammo_value)
self.Time_LCD.display(self.time_value)
self.Temp_bar.setValue(self.tmp_value)
self.Rounds_bar.setValue(self.rpm_value)The top 4 LCD.display lines work fine. But, the bottom 2 updates for the ProgressBar create an exception error (Error split data : 6) in the Comm_ard.py routine.
I don't understand how it can print the correct variable, yet using it causes a problem?
If I use one of the 2 troublesome variables in the LCD update lines instead... it works. So that leads me to believe that all the variables are fine and this is an update to the ProgressBar problem.
Could it be a timing issue? (messing up the serial comms). Edit. Checked this.... don't think so
-
Ah the joys of programming...
For some reason, it needs to be stated as an int:
self.Temp_bar.setValue(int(self.tmp_value))
This works
-
Ah the joys of programming...
For some reason, it needs to be stated as an int:
self.Temp_bar.setValue(int(self.tmp_value))
This works
@Stevolution
I was about to tell you this :)Ah the joys of programming...
This is (probably) from the "joys" of programming in Python. Unlike, say, C++ it's not a rigorously typed language, and that can lead to problems with type conversion.
I'm not sure why it did not implicitly convert your
self.tmp_value
toint
, you would have to show exactly what was inself.tmp_value
. And I don't know how/why calling aQProgressBar.setValue()
seems to cause an issue in some arduino code. -
Yes it is odd. They are all ints.... counting in 1's from 0. Doesn't seem to matter to the LCD lines, but the ProgressBar complained.
-
Forgive the varying questions, but they are on a theme (as in - same project).
I want to flash a Qlabel on and off. How can I achieve that? (I know the code to actually make it go on and off)
I tried Qtimer, but my routine really doesn't like that. Probably my bad implementation of it.
My (probably bad) idea was:
def LowAmmo(self): if (int(self.ammo_value<50)) and (self.is_connected): self.Ammo_flash +=1 if self.Ammo_flash == 50: self.Critical_centre.setStyleSheet("QLabel {background-color: black; color: rgb(255, 209, 42);}"); self.Critical_border.setFrameShape(QFrame.NoFrame) elif self.Ammo_flash>100: self.Ammo_flash = 0 self.Critical_centre.setStyleSheet("QLabel {background-color: rgb(255, 209, 42); color: black;}"); self.Critical_border.setFrameShape(QFrame.Box)
Trouble is, what calls self.LowAmmo() ? This routine never gets checked.
If I throw this code in somewhere else (like the routine where it displays the ammo value on the LCD), it throws up this damn Error split data : 6 error again.Still don't understand that error or what creates it
-
Forgive the varying questions, but they are on a theme (as in - same project).
I want to flash a Qlabel on and off. How can I achieve that? (I know the code to actually make it go on and off)
I tried Qtimer, but my routine really doesn't like that. Probably my bad implementation of it.
My (probably bad) idea was:
def LowAmmo(self): if (int(self.ammo_value<50)) and (self.is_connected): self.Ammo_flash +=1 if self.Ammo_flash == 50: self.Critical_centre.setStyleSheet("QLabel {background-color: black; color: rgb(255, 209, 42);}"); self.Critical_border.setFrameShape(QFrame.NoFrame) elif self.Ammo_flash>100: self.Ammo_flash = 0 self.Critical_centre.setStyleSheet("QLabel {background-color: rgb(255, 209, 42); color: black;}"); self.Critical_border.setFrameShape(QFrame.Box)
Trouble is, what calls self.LowAmmo() ? This routine never gets checked.
If I throw this code in somewhere else (like the routine where it displays the ammo value on the LCD), it throws up this damn Error split data : 6 error again.Still don't understand that error or what creates it
tried Qtimer, but my routine really doesn't like that. Probably my bad implementation of it.
Trouble is, what calls self.LowAmmo() ? This routine never gets checked.You do indeed need to use
QTimer
to callLowAmmo()
periodically. -
Thanks. That is what I have done.
Also worked out the issue with the Split data error... Int issue somewhere else -
Just like to finish off this thread by saying thank you for all the assistance.
By reverse engineering the project I found online, I have managed to far exceed my expectations of my first attempt at Python.
I found a camera tracking .py, and used that as a basis. Hardly any of that original code left now.LONG way to go learning Python, but I now have a working GUI, that communicates with a webcam input, and my Arduino project (Replica of the Sentry gun from Aliens).
Nice to be part of a forum where people assist rather than criticize.
The project.. The Sentry gun has full pan & tilt, controlled by the Python camera looking for a face. Gun pans while searching for target (camera is mounted on the gun). Tracks and fires when locked on (very bright barrel leds, smoke and SFX when firing).
Got the range of the webcam up to 15m using a lens.
Also has full control from the PC, 10m PIR sensor, Ultrasonic for close range etc.Gotta do something during lockdown!
-
Just like to finish off this thread by saying thank you for all the assistance.
By reverse engineering the project I found online, I have managed to far exceed my expectations of my first attempt at Python.
I found a camera tracking .py, and used that as a basis. Hardly any of that original code left now.LONG way to go learning Python, but I now have a working GUI, that communicates with a webcam input, and my Arduino project (Replica of the Sentry gun from Aliens).
Nice to be part of a forum where people assist rather than criticize.
The project.. The Sentry gun has full pan & tilt, controlled by the Python camera looking for a face. Gun pans while searching for target (camera is mounted on the gun). Tracks and fires when locked on (very bright barrel leds, smoke and SFX when firing).
Got the range of the webcam up to 15m using a lens.
Also has full control from the PC, 10m PIR sensor, Ultrasonic for close range etc.Gotta do something during lockdown!
@Stevolution said in Changing the QLabel frameshape:
Wow! :)
The Sentry gun has full pan & tilt, controlled by the Python camera looking for a face. Gun pans while searching for target (camera is mounted on the gun). Tracks and fires when locked on (very bright barrel leds, smoke and SFX when firing).
This is good, shooting looters automatically sounds fun. However, I'm not sure Qt's LGPL licence allows you to use it for murder...