source: framspy/gui/utils.py @ 1207

Last change on this file since 1207 was 1202, checked in by Maciej Komosinski, 21 months ago

Introduced common utility functions for setting window sizes; untangled some repeated code

File size: 1.9 KB
RevLine 
[1198]1from threading import Timer
2
3class 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
[1202]34
[1198]35#source: https://gist.github.com/walkermatt/2871026
36def debounce(wait):
37    """ Decorator that will postpone a function's
38        execution until after wait seconds
39        have elapsed since the last time it was invoked. """
40    def decorator(fn):
41        def debounced(*args, **kwargs):
42            def call_it():
43                fn(*args, **kwargs)
44            try:
45                debounced.t.cancel()
46            except(AttributeError):
47                pass
48            debounced.t = Timer(wait, call_it)
49            debounced.t.start()
50        return debounced
[1202]51    return decorator
52
53
54# https://stackoverflow.com/questions/39058038/wm-attributes-and-zoomed-doesnt-work
55# https://stackoverflow.com/questions/18394597/is-there-a-way-to-create-transparent-windows-with-tkinter
56def windowHideAndMaximize(wnd): # to get the size of working area on screen (screen minus taskbars, toolbars etc.) - make invisible maximized window
57    wnd.attributes("-alpha", 0)
58    wnd.state('zoomed')
59    wnd.update()
60
61def windowShowAndSetGeometry(wnd, geometry):
62    wnd.state('normal')
63    wnd.update()
64    wnd.geometry(geometry)
65    wnd.attributes("-alpha", 1)
66    wnd.update()
Note: See TracBrowser for help on using the repository browser.