mirror of
https://github.com/EDCD/EDMarketConnector.git
synced 2025-04-18 18:07:37 +03:00
Fix vertical window resize on macOS
Disable zoom button on Windows and macOS.
This commit is contained in:
parent
e11224ea27
commit
33b435e556
@ -156,7 +156,7 @@ class AppWindow:
|
|||||||
if platform=='darwin':
|
if platform=='darwin':
|
||||||
# Can't handle (de)iconify if topmost is set, so suppress iconify button
|
# Can't handle (de)iconify if topmost is set, so suppress iconify button
|
||||||
# http://wiki.tcl.tk/13428 and p15 of https://developer.apple.com/legacy/library/documentation/Carbon/Conceptual/HandlingWindowsControls/windowscontrols.pdf
|
# http://wiki.tcl.tk/13428 and p15 of https://developer.apple.com/legacy/library/documentation/Carbon/Conceptual/HandlingWindowsControls/windowscontrols.pdf
|
||||||
root.call('tk::unsupported::MacWindowStyle', 'style', root, 'document', 'closeBox horizontalZoom resizable')
|
root.call('tk::unsupported::MacWindowStyle', 'style', root, 'document', 'closeBox resizable')
|
||||||
|
|
||||||
# https://www.tcl.tk/man/tcl/TkCmd/menu.htm
|
# https://www.tcl.tk/man/tcl/TkCmd/menu.htm
|
||||||
self.system_menu = tk.Menu(self.menubar, name='apple')
|
self.system_menu = tk.Menu(self.menubar, name='apple')
|
||||||
@ -187,6 +187,7 @@ class AppWindow:
|
|||||||
self.w.createcommand("::tk::mac::ShowPreferences", lambda:prefs.PreferencesDialog(self.w, self.postprefs))
|
self.w.createcommand("::tk::mac::ShowPreferences", lambda:prefs.PreferencesDialog(self.w, self.postprefs))
|
||||||
self.w.createcommand("::tk::mac::ReopenApplication", self.w.deiconify) # click on app in dock = restore
|
self.w.createcommand("::tk::mac::ReopenApplication", self.w.deiconify) # click on app in dock = restore
|
||||||
self.w.protocol("WM_DELETE_WINDOW", self.w.withdraw) # close button shouldn't quit app
|
self.w.protocol("WM_DELETE_WINDOW", self.w.withdraw) # close button shouldn't quit app
|
||||||
|
self.w.resizable(tk.FALSE, tk.FALSE) # Can't be only resizable on one axis
|
||||||
else:
|
else:
|
||||||
self.file_menu = self.view_menu = tk.Menu(self.menubar, tearoff=tk.FALSE)
|
self.file_menu = self.view_menu = tk.Menu(self.menubar, tearoff=tk.FALSE)
|
||||||
self.file_menu.add_command(command=lambda:stats.StatsDialog(self))
|
self.file_menu.add_command(command=lambda:stats.StatsDialog(self))
|
||||||
@ -248,6 +249,7 @@ class AppWindow:
|
|||||||
tk.Label(self.blank_menubar).grid()
|
tk.Label(self.blank_menubar).grid()
|
||||||
tk.Label(self.blank_menubar).grid()
|
tk.Label(self.blank_menubar).grid()
|
||||||
theme.register_alternate((self.menubar, self.theme_menubar, self.blank_menubar), {'row':0, 'columnspan':2, 'sticky':tk.NSEW})
|
theme.register_alternate((self.menubar, self.theme_menubar, self.blank_menubar), {'row':0, 'columnspan':2, 'sticky':tk.NSEW})
|
||||||
|
self.w.resizable(tk.TRUE, tk.FALSE)
|
||||||
|
|
||||||
# update geometry
|
# update geometry
|
||||||
if config.get('geometry'):
|
if config.get('geometry'):
|
||||||
@ -267,7 +269,6 @@ class AppWindow:
|
|||||||
else:
|
else:
|
||||||
self.w.geometry(config.get('geometry'))
|
self.w.geometry(config.get('geometry'))
|
||||||
self.w.attributes('-topmost', config.getint('always_ontop') and 1 or 0)
|
self.w.attributes('-topmost', config.getint('always_ontop') and 1 or 0)
|
||||||
self.w.resizable(tk.TRUE, tk.FALSE)
|
|
||||||
|
|
||||||
theme.register(frame)
|
theme.register(frame)
|
||||||
theme.apply(self.w)
|
theme.apply(self.w)
|
||||||
@ -310,7 +311,7 @@ class AppWindow:
|
|||||||
tkMessageBox.showerror(applongname,
|
tkMessageBox.showerror(applongname,
|
||||||
_('This app requires accurate timestamps.') + '\n' + # Error message shown if system time is wrong
|
_('This app requires accurate timestamps.') + '\n' + # Error message shown if system time is wrong
|
||||||
(TZ_THRESHOLD < drift < CLOCK_THRESHOLD and
|
(TZ_THRESHOLD < drift < CLOCK_THRESHOLD and
|
||||||
_("Check your system's Time Zone setting.") or # Error message shown if system time is wrong
|
_("Check your system's Time Zone setting.") or # Error message shown if system time is wrong
|
||||||
_("Check your system's Date and Time settings.")), # Error message shown if system time is wrong
|
_("Check your system's Date and Time settings.")), # Error message shown if system time is wrong
|
||||||
parent = self.w)
|
parent = self.w)
|
||||||
self.w.destroy()
|
self.w.destroy()
|
||||||
|
28
theme.py
28
theme.py
@ -161,40 +161,36 @@ class _Theme:
|
|||||||
self.active = theme
|
self.active = theme
|
||||||
|
|
||||||
if platform == 'darwin':
|
if platform == 'darwin':
|
||||||
from AppKit import NSApplication, NSAppearance, NSColor
|
from AppKit import NSApplication, NSAppearance, NSMiniaturizableWindowMask, NSResizableWindowMask
|
||||||
root.update_idletasks() # need main window to be created
|
root.update_idletasks() # need main window to be created
|
||||||
appearance = NSAppearance.appearanceNamed_(theme and
|
appearance = NSAppearance.appearanceNamed_(theme and
|
||||||
'NSAppearanceNameVibrantDark' or
|
'NSAppearanceNameVibrantDark' or
|
||||||
'NSAppearanceNameAqua')
|
'NSAppearanceNameAqua')
|
||||||
for window in NSApplication.sharedApplication().windows():
|
for window in NSApplication.sharedApplication().windows():
|
||||||
|
window.setStyleMask_(window.styleMask() & ~(NSMiniaturizableWindowMask | NSResizableWindowMask)) # disable zoom
|
||||||
window.setAppearance_(appearance)
|
window.setAppearance_(appearance)
|
||||||
|
|
||||||
if not self.minwidth:
|
|
||||||
self.minwidth = root.winfo_width() # Minimum width = width on first creation
|
|
||||||
# resizable(0,0) doesn't do anything on OSX
|
|
||||||
root.minsize(self.minwidth, root.winfo_height())
|
|
||||||
root.maxsize(-1, root.winfo_height())
|
|
||||||
|
|
||||||
elif platform == 'win32':
|
elif platform == 'win32':
|
||||||
# tk8.5.9/win/tkWinWm.c:342
|
|
||||||
import ctypes
|
import ctypes
|
||||||
|
GWL_STYLE = -16
|
||||||
|
WS_MAXIMIZEBOX = 0x00010000
|
||||||
|
# tk8.5.9/win/tkWinWm.c:342
|
||||||
GWL_EXSTYLE = -20
|
GWL_EXSTYLE = -20
|
||||||
WS_EX_APPWINDOW = 0x00040000
|
WS_EX_APPWINDOW = 0x00040000
|
||||||
WS_EX_LAYERED = 0x00080000
|
WS_EX_LAYERED = 0x00080000
|
||||||
|
GetWindowLongW = ctypes.windll.user32.GetWindowLongW
|
||||||
|
SetWindowLongW = ctypes.windll.user32.SetWindowLongW
|
||||||
|
|
||||||
root.overrideredirect(theme and 1 or 0)
|
root.overrideredirect(theme and 1 or 0)
|
||||||
root.attributes("-transparentcolor", theme > 1 and 'grey4' or '')
|
root.attributes("-transparentcolor", theme > 1 and 'grey4' or '')
|
||||||
root.withdraw()
|
root.withdraw()
|
||||||
root.update_idletasks() # Size and windows styles get recalculated here
|
root.update_idletasks() # Size and windows styles get recalculated here
|
||||||
hwnd = ctypes.windll.user32.GetParent(root.winfo_id())
|
hwnd = ctypes.windll.user32.GetParent(root.winfo_id())
|
||||||
ctypes.windll.user32.SetWindowLongW(hwnd, GWL_EXSTYLE, theme > 1 and WS_EX_APPWINDOW|WS_EX_LAYERED or WS_EX_APPWINDOW) # Add to taskbar
|
SetWindowLongW(hwnd, GWL_STYLE, GetWindowLongW(hwnd, GWL_STYLE) & ~WS_MAXIMIZEBOX) # disable maximize
|
||||||
|
SetWindowLongW(hwnd, GWL_EXSTYLE, theme > 1 and WS_EX_APPWINDOW|WS_EX_LAYERED or WS_EX_APPWINDOW) # Add to taskbar
|
||||||
root.deiconify()
|
root.deiconify()
|
||||||
root.wait_visibility() # need main window to be displayed before returning
|
root.wait_visibility() # need main window to be displayed before returning
|
||||||
|
|
||||||
if not self.minwidth:
|
|
||||||
self.minwidth = root.winfo_width() # Minimum width = width on first creation
|
|
||||||
root.minsize(self.minwidth, -1)
|
|
||||||
|
|
||||||
else:
|
else:
|
||||||
root.overrideredirect(theme and 1 or 0)
|
root.overrideredirect(theme and 1 or 0)
|
||||||
root.withdraw()
|
root.withdraw()
|
||||||
@ -202,9 +198,9 @@ class _Theme:
|
|||||||
root.deiconify()
|
root.deiconify()
|
||||||
root.wait_visibility() # need main window to be displayed before returning
|
root.wait_visibility() # need main window to be displayed before returning
|
||||||
|
|
||||||
if not self.minwidth:
|
if not self.minwidth:
|
||||||
self.minwidth = root.winfo_width() # Minimum width = width on first creation
|
self.minwidth = root.winfo_width() # Minimum width = width on first creation
|
||||||
root.minsize(self.minwidth, -1)
|
root.minsize(self.minwidth, -1)
|
||||||
|
|
||||||
# singleton
|
# singleton
|
||||||
theme = _Theme()
|
theme = _Theme()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user