Last change
on this file since 1303 was
1211,
checked in by sz, 20 months ago
|
linux compatibility (can't use the window state "zoomed", some state changes need wait_visibility())
|
File size:
2.1 KB
|
Rev | Line | |
---|
[1198] | 1 | from threading import Timer
|
---|
[1211] | 2 | import os
|
---|
[1198] | 3 |
|
---|
| 4 | class Swap:
|
---|
| 5 | def __init__(self, init = None) -> None:
|
---|
| 6 | self.init = init
|
---|
| 7 | self.clear()
|
---|
| 8 | self.select = False
|
---|
| 9 | self.empty = False
|
---|
| 10 |
|
---|
| 11 | def update(self, new):
|
---|
| 12 | if not new:
|
---|
| 13 | if self.empty == False:
|
---|
| 14 | self.empty = True
|
---|
| 15 | return
|
---|
| 16 | else:
|
---|
| 17 | self.empty = False
|
---|
| 18 |
|
---|
| 19 | if self.select:
|
---|
| 20 | self.one = new
|
---|
| 21 | else:
|
---|
| 22 | self.two = new
|
---|
| 23 | self.select = not self.select
|
---|
| 24 |
|
---|
| 25 | def get(self):
|
---|
| 26 | if self.select:
|
---|
| 27 | return self.two
|
---|
| 28 | else:
|
---|
| 29 | return self.one
|
---|
| 30 |
|
---|
| 31 | def clear(self):
|
---|
| 32 | self.one = self.init
|
---|
| 33 | self.two = self.init
|
---|
| 34 |
|
---|
[1202] | 35 |
|
---|
[1198] | 36 | #source: https://gist.github.com/walkermatt/2871026
|
---|
| 37 | def debounce(wait):
|
---|
| 38 | """ Decorator that will postpone a function's
|
---|
| 39 | execution until after wait seconds
|
---|
| 40 | have elapsed since the last time it was invoked. """
|
---|
| 41 | def decorator(fn):
|
---|
| 42 | def debounced(*args, **kwargs):
|
---|
| 43 | def call_it():
|
---|
| 44 | fn(*args, **kwargs)
|
---|
| 45 | try:
|
---|
| 46 | debounced.t.cancel()
|
---|
| 47 | except(AttributeError):
|
---|
| 48 | pass
|
---|
| 49 | debounced.t = Timer(wait, call_it)
|
---|
| 50 | debounced.t.start()
|
---|
| 51 | return debounced
|
---|
[1202] | 52 | return decorator
|
---|
| 53 |
|
---|
| 54 |
|
---|
| 55 | # https://stackoverflow.com/questions/39058038/wm-attributes-and-zoomed-doesnt-work
|
---|
| 56 | # https://stackoverflow.com/questions/18394597/is-there-a-way-to-create-transparent-windows-with-tkinter
|
---|
| 57 | def windowHideAndMaximize(wnd): # to get the size of working area on screen (screen minus taskbars, toolbars etc.) - make invisible maximized window
|
---|
[1211] | 58 | if os.name=='posix':
|
---|
| 59 | wnd.wait_visibility()
|
---|
[1202] | 60 | wnd.attributes("-alpha", 0)
|
---|
[1211] | 61 | if os.name=='posix':
|
---|
| 62 | wnd.attributes("-zoomed", 1)
|
---|
| 63 | else:
|
---|
| 64 | wnd.state('zoomed')
|
---|
[1202] | 65 | wnd.update()
|
---|
| 66 |
|
---|
| 67 | def windowShowAndSetGeometry(wnd, geometry):
|
---|
[1211] | 68 | if os.name=='posix':
|
---|
| 69 | wnd.attributes("-zoomed", 0)
|
---|
| 70 | wnd.wait_visibility()
|
---|
| 71 | else:
|
---|
| 72 | wnd.state('normal')
|
---|
[1202] | 73 | wnd.update()
|
---|
| 74 | wnd.geometry(geometry)
|
---|
| 75 | wnd.attributes("-alpha", 1)
|
---|
| 76 | wnd.update()
|
---|
Note: See
TracBrowser
for help on using the repository browser.