Changeset 1202


Ignore:
Timestamp:
02/08/23 01:19:53 (23 months ago)
Author:
Maciej Komosinski
Message:

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

Location:
framspy/gui
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • framspy/gui/utils.py

    r1198 r1202  
    3232        self.two = self.init
    3333
     34
    3435#source: https://gist.github.com/walkermatt/2871026
    3536def debounce(wait):
     
    4950        return debounced
    5051    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()
  • framspy/gui/widgets/ConsoleWindow.py

    r1198 r1202  
    22from gui.widgets.ScrolledText import ScrolledText
    33from gui.framsutils.FramsSocket import FramsSocket
     4from gui.utils import windowHideAndMaximize, windowShowAndSetGeometry
    45from typing import Tuple, Callable
    56
     
    4546            return maxwidth, maxheight, x, y
    4647
    47         self.attributes("-alpha", 0)
    4848        self.update_idletasks()
    4949
    5050        width, height, x, y = parseGeometryString(self.winfo_geometry())
    51 
    52         self.state('zoomed')
    53         self.update()
     51        windowHideAndMaximize(self)
    5452        rootx = self.winfo_rootx()
    55 
    5653        maxWidth, maxHeight, x, y = parseGeometryString(self.winfo_geometry())
    57 
    58         self.state("normal")
    59         self.update()
    60 
    6154        x = (maxWidth - width) / 2
    6255        y = (maxHeight - height) / 2
    63 
    64         self.geometry("+%d+%d" % (int(rootx + x), int(y)))
    65         self.attributes("-alpha", 1)
    66         self.update()
     56        windowShowAndSetGeometry(self, "+%d+%d" % (int(rootx + x), int(y)))
    6757        self.maxsize(maxWidth, maxHeight)
    6858
  • framspy/gui/widgets/mainPage.py

    r1201 r1202  
    1616from gui.socketInterface import SocketInterface
    1717from gui.utils import debounce
     18from gui.utils import windowHideAndMaximize, windowShowAndSetGeometry
    1819from gui.widgets.ToolTip import CreateToolTip
    1920from time import perf_counter
     
    171172        #ORGANIZE WINDOWS POSITIONS
    172173        ## need to do some workaround to determine screen width and height
    173         self.attributes("-alpha", 0)
    174         self.state('zoomed')
    175         self.update()
     174        windowHideAndMaximize(self)
    176175        maxHeight = self.winfo_rooty() + self.winfo_height()
    177176        maxWidth = self.winfo_rootx() + self.winfo_width()
    178177        self.rootx = self.winfo_rootx()
    179         self.state("normal")
    180         self.update()
    181         self.geometry("%dx%d+%d+%d" % (self.OPENGL_WIDTH + self.SIDEBAR_WIDTH, self.OPENGL_HEIGHT, self.rootx, 0))
    182         self.attributes("-alpha", 1)
    183         self.update()
     178        windowShowAndSetGeometry(self, "%dx%d+%d+%d" % (self.OPENGL_WIDTH + self.SIDEBAR_WIDTH, self.OPENGL_HEIGHT, self.rootx, 0))
    184179        height = self.winfo_rooty() + self.winfo_height() - self.winfo_y()
    185180
  • framspy/gui/widgets/propertyWindow.py

    r1198 r1202  
    44from typing import Dict, List, Callable, Tuple
    55from gui.framsutils.framsProperty import Property, PropertyCallback, propertyToTkinter
     6from gui.framsutils.FramsInterface import FramsInterface, InterfaceType
    67from gui.widgets.ToolTip import CreateToolTip
    7 from gui.framsutils.FramsInterface import FramsInterface, InterfaceType
     8from gui.utils import windowHideAndMaximize, windowShowAndSetGeometry
    89
    910'''
     
    105106            return maxwidth, maxheight, x, y
    106107
    107         self.attributes("-alpha", 0)
    108108        self.update_idletasks()
    109109
    110110        width, height, x, y = parseGeometryString(self.winfo_geometry())
    111111
    112         self.state('zoomed')
    113         self.update()
     112        windowHideAndMaximize(self)
    114113        rootx = self.winfo_rootx()
    115114
    116115        maxWidth, maxHeight, x, y = parseGeometryString(self.winfo_geometry())
    117 
    118         self.state("normal")
    119         self.update()
    120 
    121116        x = (maxWidth - width) / 2
    122117        y = (maxHeight - height) / 2
    123118
    124         self.geometry("+%d+%d" % (int(rootx + x), int(y)))
    125         self.attributes("-alpha", 1)
    126         self.update()
     119        windowShowAndSetGeometry(self, "+%d+%d" % (int(rootx + x), int(y)))
    127120        self.maxsize(maxWidth, maxHeight)
    128121
Note: See TracChangeset for help on using the changeset viewer.