Last change
on this file since 1201 was
1198,
checked in by Maciej Komosinski, 22 months ago
|
Added simple Python GUI for Framsticks library/server
|
File size:
1.3 KB
|
Line | |
---|
1 | from threading import Timer
|
---|
2 |
|
---|
3 | class Swap:
|
---|
4 | def __init__(self, init = None) -> None:
|
---|
5 | self.init = init
|
---|
6 | self.clear()
|
---|
7 | self.select = False
|
---|
8 | self.empty = False
|
---|
9 |
|
---|
10 | def update(self, new):
|
---|
11 | if not new:
|
---|
12 | if self.empty == False:
|
---|
13 | self.empty = True
|
---|
14 | return
|
---|
15 | else:
|
---|
16 | self.empty = False
|
---|
17 |
|
---|
18 | if self.select:
|
---|
19 | self.one = new
|
---|
20 | else:
|
---|
21 | self.two = new
|
---|
22 | self.select = not self.select
|
---|
23 |
|
---|
24 | def get(self):
|
---|
25 | if self.select:
|
---|
26 | return self.two
|
---|
27 | else:
|
---|
28 | return self.one
|
---|
29 |
|
---|
30 | def clear(self):
|
---|
31 | self.one = self.init
|
---|
32 | self.two = self.init
|
---|
33 |
|
---|
34 | #source: https://gist.github.com/walkermatt/2871026
|
---|
35 | def debounce(wait):
|
---|
36 | """ Decorator that will postpone a function's
|
---|
37 | execution until after wait seconds
|
---|
38 | have elapsed since the last time it was invoked. """
|
---|
39 | def decorator(fn):
|
---|
40 | def debounced(*args, **kwargs):
|
---|
41 | def call_it():
|
---|
42 | fn(*args, **kwargs)
|
---|
43 | try:
|
---|
44 | debounced.t.cancel()
|
---|
45 | except(AttributeError):
|
---|
46 | pass
|
---|
47 | debounced.t = Timer(wait, call_it)
|
---|
48 | debounced.t.start()
|
---|
49 | return debounced
|
---|
50 | return decorator |
---|
Note: See
TracBrowser
for help on using the repository browser.