Go to advanced search

by paddyg
Thu Apr 19, 2018 8:10 pm
Forum: Python
Topic: Stop to play file!
Replies: 7
Views: 210

Re: Stop to play file!

well, stick with the system as before. in v.2 you need to replace 'a' with Button(2) etc in the definition of button_sounds. Then after that set the callback for each button. Do it in a loop as I suggested before. It's effectively doing for b in button_sounds: b.when_pressed = toggle_sound I'm in th...
by paddyg
Mon Apr 16, 2018 7:28 pm
Forum: Python
Topic: writing I32 to binary file: endian-ness on R-Pi
Replies: 12
Views: 254

Re: writing I32 to binary file: endian-ness on R-Pi

Not sure about your multiplication machine but the standard hardware works along these lines i.e there is addition but just like you do with 'long' multiplication where you add up the columns. Yes, at the machine level, multiplication is a lot more expensive than bit shifting and all modern compiler...
by paddyg
Mon Apr 16, 2018 2:04 pm
Forum: Python
Topic: writing I32 to binary file: endian-ness on R-Pi
Replies: 12
Views: 254

Re: writing I32 to binary file: endian-ness on R-Pi

what do you get if you change the endianness with > or < (in the struct pack formatter)?

PS or when importing into audacity?
by paddyg
Mon Apr 16, 2018 11:39 am
Forum: Python
Topic: writing I32 to binary file: endian-ness on R-Pi
Replies: 12
Views: 254

Re: writing I32 to binary file: endian-ness on R-Pi

And, apart from that, I had also assumed that bit shifting was quicker for powers of two but, in python3 anyway, it doesn't seem to be import timeit setup = ''' a = 123 ''' fns = [''' b = a * 512 ''', ''' b = a << 9 '''] for f in fns: print(timeit.timeit(f, setup=setup, number=10000000)) 0.520778725...
by paddyg
Mon Apr 16, 2018 11:09 am
Forum: Python
Topic: A Can of Worms: RPi.GPIO CleanUp
Replies: 7
Views: 368

Re: A Can of Worms: RPi.GPIO CleanUp

Isn't this the kind of structure that @joan's excellent library has? (or gpiozero if you set it to use pigpio)
by paddyg
Mon Apr 16, 2018 9:55 am
Forum: Python
Topic: Need advise on realtime programming
Replies: 7
Views: 301

Re: Need advise on realtime programming

I've had problems with callback functions on gpio state change before, and I think there are some quirks in the GPIO code, but they've generally been because of stray edges i.e. as a rotary encoder 'made' or 'broke' it produced lots of spikes, the bouncetime never seemed to filter them properly. The...
by paddyg
Sun Apr 15, 2018 5:45 pm
Forum: Python
Topic: Accessing MariaDB over SSH
Replies: 3
Views: 128

Re: Accessing MariaDB over SSH

What happens if you put the code inside the with...as tunnel: block i.e. indent the csr = ... line
by paddyg
Sun Apr 15, 2018 9:08 am
Forum: Python
Topic: Need advise on realtime programming
Replies: 7
Views: 301

Re: Need advise on realtime programming

You would find it much easier to use gpiozero which has lots of the functionality you're trying to replicate built in and there are lots of examples and recipes in the excellent documentation. Looking back at your code and trying to make it DRY will help you to restructure it and make the logic much...
by paddyg
Sat Apr 14, 2018 10:08 pm
Forum: Python
Topic: Stop to play file!
Replies: 7
Views: 210

Re: Stop to play file!

Ok So this is my quick test of the code, just running on my laptop taking keyboard input to switch on and off. It has the stop_all version and the toggle version. You should get that working first then switch to gpiozero buttons. If it stops working then make a gpiozero version that doesn't attempt ...
by paddyg
Sat Apr 14, 2018 9:12 pm
Forum: Python
Topic: Need advise on realtime programming
Replies: 7
Views: 301

Re: Need advise on realtime programming

Don't know why the callback is unreliable - have you tried putting print statements in the function to see what's happening. i.e. is the function being called but the input has changed when it does the logic, or is it turning on and off very quickly? It's a rather indirect help but over the years I ...
by paddyg
Fri Apr 13, 2018 3:32 pm
Forum: Python
Topic: Stop to play file!
Replies: 7
Views: 210

Re: Stop to play file!

Just to be clear: a) the line after your for... is indented (this is why it's a good idea to always use spaces not tabs) b) there is some code after the bit you posted to stop the program ending c) you didn't alter your existing (working) code, simply added the additional seven lines with the functi...
by paddyg
Thu Apr 12, 2018 2:24 pm
Forum: Python
Topic: Stop to play file!
Replies: 7
Views: 210

Re: Stop to play file!

I think you can just go through each Sound object and stop it. To do something more sophisticated you would need to keep track of which ones were running and which were paused. Here are the methods available to pygame.mixer.Sound https://www.pygame.org/docs/ref/mixer.html#pygame.mixer.Sound ... for ...
by paddyg
Sun Apr 08, 2018 6:47 pm
Forum: Python
Topic: Cannot import ImageTk
Replies: 3
Views: 131

Re: Cannot import ImageTk

I just checked on my new SD card and found the same issue. After I did

Code: Select all

sudo pip3 install pillow --upgrade
it replaced v4.0.0 with v5.1.0 which had been built with tk in place and could import PIL.ImageTk ok

PS do you have an unavoidable requirement to use python2?
by paddyg
Thu Apr 05, 2018 10:28 pm
Forum: Python
Topic: print the output using python
Replies: 2
Views: 142

Re: print the output using python

The existing code looks to nearly do what you describe. Unless you mean you want to do something different? see https://docs.python.org/3.5/library/string.html#format-specification-mini-language for how format works print('{}, {}, {}, {}'.format(values[0], values[1], values[2], values[3])) # *values...
by paddyg
Fri Mar 30, 2018 5:56 pm
Forum: Python
Topic: Pi3D
Replies: 225
Views: 22385

Re: Pi3D

Just put v2.23 onto github and pypi.python.org Most recent versions are minor improvements and fixes. This version has some utility methods in the Shape class to make it a bit easier to get direction vectors and Euler rotations from local to global frames of ref, which might be useful in more gamy a...
by paddyg
Thu Mar 08, 2018 9:57 am
Forum: Python
Topic: Pi Lite
Replies: 2
Views: 281

Re: Pi Lite

Does it just 'not work' or do you get any error messages?
by paddyg
Thu Mar 08, 2018 8:53 am
Forum: Python
Topic: PiQt5 checkbox resize help
Replies: 1
Views: 202

Re: PiQt5 checkbox resize help

Is this relevant https://stackoverflow.com/questions/630 ... text-in-qt you will also have to figure out using the pyqt setStyleSheet() to apply it
by paddyg
Wed Mar 07, 2018 4:32 pm
Forum: Python
Topic: Limit iterator filter to variable comparison [SOLVED]
Replies: 15
Views: 750

Re: Limit iterator filter to variable comparison [SOLVED]

In your code try printing out what you've got (this is basically what I always do if I get an error message and I'm not sure what it means) i.e. print(image) if image == None: (You don't need those brackets for python if) However it says here https://docs.opencv.org/3.0-beta/modules/imgcodecs/doc/re...
by paddyg
Wed Mar 07, 2018 4:16 pm
Forum: Python
Topic: Limit iterator filter to variable comparison [SOLVED]
Replies: 15
Views: 750

Re: Limit iterator filter to variable comparison [SOLVED]

Hi, maybe you could sort the image files first. Then add all the ones you know won't have any overlap (without doing any checking). Then work your way through the images that might overlap and check each pixel with the ones already there before adding it. On ndarrays, it's a good idea to keep in min...
by paddyg
Wed Mar 07, 2018 1:23 pm
Forum: Python
Topic: Limit iterator filter to variable comparison [SOLVED]
Replies: 15
Views: 750

Re: Limit iterator filter to variable comparison [SOLVED]

Hi, I had a look at your code though without getting too much into the detail of how it all works. One thing I would do (I think, unless I have misapprehended something) is to filter as I add the points to allPoints. i.e. inside the loop of imageToPoints(). That way you're only having to search thro...
by paddyg
Wed Mar 07, 2018 8:03 am
Forum: Python
Topic: Limit iterator filter to variable comparison [SOLVED]
Replies: 15
Views: 750

Re: Limit iterator filter to variable comparison [SOLVED]

I'll have a look at your code but these are big array's to hold in memory so probably needs a bit of optimisation.
by paddyg
Tue Mar 06, 2018 10:43 pm
Forum: Python
Topic: Limit iterator filter to variable comparison [SOLVED]
Replies: 15
Views: 750

Re: Limit iterator filter to variable comparison

I'm not 100% sure of your objective here but I would suggest using numpy if you possibly can. This will be orders of magnitude faster than normal python for this kind of thing. On this rather old laptop it only takes five seconds to make a list of points within a given radius of each of the other 69...
by paddyg
Tue Mar 06, 2018 7:14 pm
Forum: Python
Topic: Problem comparing if two images are different ( imagechops)
Replies: 11
Views: 889

Re: Problem comparing if two images are different ( imagechops)

I stupidly just looked at the code on the last post and assumed it was for checking image files that had got renamed or such like, and eliminating duplicates. On reading more of the thread I see that it is to check images from the pi camera, for which this code is completely useless as every single ...
by paddyg
Tue Mar 06, 2018 3:10 pm
Forum: Python
Topic: Problem comparing if two images are different ( imagechops)
Replies: 11
Views: 889

Re: Problem comparing if two images are different ( imagechops)

If you're not checking for any subtle differences then using cv2 is a bit of overkill. In fact numpy and PIL can do an awful lot of the straightforward stuff like from PIL import Image import numpy as np im1 = np.array(Image.open("myimage1.png")) im2 = np.array(Image.open("myimage1.png")) difference...
by paddyg
Tue Mar 06, 2018 12:06 pm
Forum: Python
Topic: Expert opinion sought (on using enums)
Replies: 8
Views: 505

Re: Expert opinion sought (on using enums)

A tidy way of encapsulating this kind of thing is to put all the enums in a different file (ideally using a module structure with all the __init__.py files etc) which is what pi3d has done for converting C code and header files like # in header.py LEFTOVERS_TREESTORE_DATE_STR = 0 LEFTOVERS_TREESTORE...

Go to advanced search