-1

I am trying to make a cue list that holds DMX values. I have two dictionaries:

dict1 = {'test': [0, 24, 45]}
dict2 = {'test': [24, 56, 89]}

I can do

dict1['test'] = dict2['test']

to set dict one values to equal dict2, but this happens immediately. How can I have dict1['test'] transition to the values of dict2['test'] over a span of three seconds? In a ramping motion ie: 0, 1, 2, 3, 4, 5, 6, etc but for every value in the list.

For example, dict1['test'][0] would be

1 sec: 8
2 sec: 16
3 sec: 24 = dict2['test'][0]

and the values would interpolate in between.

Thanks in advance!

  • a bit painful but you can write a function using `time.sleep()` – fonfonx Jul 28 '17 at 19:20
  • 1
    You can do that by using `time.sleep` in a loop, but why do you want to? If you're not using some kind of multithreaded code, it won't matter, since no other code will run during those three seconds to "see" the list growing. If you are using multithreaded code, then you need to worry about a lot more than just extending a list over three seconds. – BrenBarn Jul 28 '17 at 19:20
  • I assume you would like to proceed with other actions and make this periodic execution non-blocking. If so, you should take a look at [this](https://stackoverflow.com/questions/8600161/executing-periodic-actions-in-python) if not, use `time.sleep()` which is blocking. – albert Jul 28 '17 at 19:21
  • I have a pyqt ui that I am going to update. – Tom Charles Jul 28 '17 at 19:36
  • You need a timer. Look for stopwatch examples in pyqt. – Gribouillis Jul 28 '17 at 20:32
  • @TomCharles Did my answer work? If so please mark my answer as correct so people in the future can fix this issue! – James Sep 16 '17 at 19:24

1 Answers1

0
import time
dict2['test'][0] = 0
while True:
    dict2['test'][0] = dict2['test'][0] + 8
    time.sleep(1)

You can optionally print(dict2['test'][0]) after time.sleep(1) to print what the number is.

To break it down you set the variable to 0, you do a infinite loop, you set the variable to the variable + 8, then you pause the program for one second.

Good luck!

James
  • 1,928
  • 3
  • 13
  • 30