Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

pull request #414

Draft
wants to merge 60 commits into
base: develop
Choose a base branch
from
Draft
Changes from 1 commit
Commits
Show all changes
60 commits
Select commit Hold shift + click to select a range
e6640c8
Add Windows testing to GitHub Actions
oldgithubman Oct 13, 2024
f384db5
Refactor and improve type annotations in mocks.py
oldgithubman Oct 13, 2024
d981a17
Update AGW package documentation to version 0.9.7
oldgithubman Oct 13, 2024
d141daf
Refactor and enhance AGW artmanager module
oldgithubman Oct 13, 2024
0c917df
Add bold tab selection style and improve type hints
oldgithubman Oct 13, 2024
307a1a2
Update FourWaySplitter for better documentation and Python 3 compatib…
oldgithubman Oct 13, 2024
b4e65a6
Update GradientButton for Python 3 and Phoenix
oldgithubman Oct 13, 2024
90851e5
Update LabelBook and FlatImageBook documentation
oldgithubman Oct 13, 2024
3b94aa2
Update PyGauge to support drawing value or percentage
oldgithubman Oct 13, 2024
c5cfcc8
Refactor and improve audio module documentation
oldgithubman Oct 13, 2024
e382e2c
Refactor and improve code readability in config.py
oldgithubman Oct 14, 2024
3ac2eb6
Update win32com imports to win32comext
oldgithubman Oct 14, 2024
ddc0696
Refactor imports and improve readability
oldgithubman Oct 14, 2024
c6dd4bb
Update flake8 config for stricter checks
oldgithubman Oct 14, 2024
5a39997
Reorganize and update .gitignore file
oldgithubman Oct 14, 2024
bd8ac7a
Update requirements.txt with new dependencies
oldgithubman Oct 14, 2024
3101b65
Add type hints to ArtManager.Initialize
oldgithubman Oct 14, 2024
e614e63
Refactor and document EDID retrieval and parsing
oldgithubman Oct 14, 2024
4d75b98
Refactor and clean up freeze.py script
oldgithubman Oct 14, 2024
83eec46
Refactor imports and Python version check
oldgithubman Oct 14, 2024
cf9dc8c
Fix formatting and minor typos in pnp.ids
oldgithubman Oct 14, 2024
69421d6
Refactor imports and improve readability in profile_loader.py
oldgithubman Oct 14, 2024
77f82ef
Refactor and improve RealDisplaySizeMM.py
oldgithubman Oct 14, 2024
72eeeb7
Refactor and enhance AGW artmanager module
oldgithubman Oct 13, 2024
9648079
Refactor and improve code readability in config.py
oldgithubman Oct 14, 2024
c1de081
Refactor imports and improve readability
oldgithubman Oct 14, 2024
24951ea
Refactor and document EDID retrieval and parsing
oldgithubman Oct 14, 2024
00a5a9a
- [#414] Fixed `DisplayCAL.lib.agw.artmanager` for MacOS (and possibl…
eoyilmaz Oct 14, 2024
e49641e
Refactor taskbar progress using ctypes for ITaskbarList3
oldgithubman Oct 14, 2024
51b663d
- [#414] Trying to fix Windows workflow (1).
eoyilmaz Oct 14, 2024
2d5291b
Format taskbar.py
oldgithubman Oct 14, 2024
2bfb3a4
Refactor and enhance util_os.py for better readability and functionality
oldgithubman Oct 14, 2024
39fdba8
Add docstrings and improve code readability
oldgithubman Oct 14, 2024
52698ac
- [#414] Trying to fix Windows workflow (2).
eoyilmaz Oct 14, 2024
35693df
Reorganize imports and fix indentation
oldgithubman Oct 14, 2024
acb860f
Refactor imports in wxCCXXPlot.py for clarity and consistency
oldgithubman Oct 14, 2024
e546a57
Refactor imports for better readability and organization
oldgithubman Oct 14, 2024
bd55ea5
Refactor imports in wxLUTViewer.py for clarity and organization
oldgithubman Oct 14, 2024
c80a73e
Refactor imports in wxMeasureFrame.py for clarity
oldgithubman Oct 14, 2024
9666556
Reorganize imports for better readability and structure
oldgithubman Oct 15, 2024
a78b04e
Refactor imports in wxScriptingClient.py
oldgithubman Oct 15, 2024
43242b3
Refactor imports in wxSynthICCFrame.py
oldgithubman Oct 15, 2024
7bb3e09
Refactor imports and improve readability
oldgithubman Oct 15, 2024
59b30ad
Refactor imports and improve code readability
oldgithubman Oct 15, 2024
bc4a3dc
Refactor and improve comments in tests/conftest.py
oldgithubman Oct 15, 2024
7e90ba2
Update test_colord.py to use platform module and fix import order
oldgithubman Oct 15, 2024
a945d1e
Update tests and dependencies for Python 3.11
oldgithubman Oct 15, 2024
96ef5af
Add debugging print statements to test_ICCProfile.py
oldgithubman Oct 15, 2024
feda88d
Convert AGW package docstring to use double quotes
oldgithubman Oct 15, 2024
3afeea1
Refactor and update project configuration files
oldgithubman Oct 16, 2024
84f7f94
Delete .flake8 and update .gitignore
oldgithubman Oct 16, 2024
105cd7d
Refactor and improve FourWaySplitter documentation and types
oldgithubman Oct 18, 2024
80a2842
Refactor GradientButton for better type hints and readability
oldgithubman Oct 18, 2024
f00706f
Refactor and improve LabelBook and FlatImageBook
oldgithubman Oct 23, 2024
561e825
[#414] Updated `.github/workflows/pytest.yml` to disable C-Extension …
eoyilmaz Oct 24, 2024
eabc81b
[#414] Removed all the `# noqa: SC100` comments as it is better to ad…
eoyilmaz Oct 24, 2024
23f40ad
[#414] Refactored the `DisplayCAL.lib.agw.artmanager`.
eoyilmaz Oct 24, 2024
b433eba
[#414] Refactored the `DisplayCAL.lib.agw.fmresources`.
eoyilmaz Oct 24, 2024
3f3d66f
[#414] Fixed most of the linting errors in `DisplayCAL.lib.agw.artman…
eoyilmaz Oct 24, 2024
ea2febe
[#414] Introduced some more style changes to `fourwaysplitter` and `g…
eoyilmaz Oct 24, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Refactor and improve FourWaySplitter documentation and types
  * Add type hints to methods
  * Improve docstring formatting
  * Clarify method descriptions
  * Fix minor bugs and inconsistencies
oldgithubman committed Oct 24, 2024
commit 105cd7d789eabbc76245099b673d6776b476085e
730 changes: 379 additions & 351 deletions DisplayCAL/lib/agw/fourwaysplitter.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# ---------------------------------------------------------------------------- #
# FOURWAYSPLITTER wxPython IMPLEMENTATION # noqa: SC100
# ------------------------------------------------------------------------------------ #
# FOURWAYSPLITTER wxPython IMPLEMENTATION
#
# Andrea Gavana, @ 03 Nov 2006 # noqa: SC100
# Andrea Gavana, @ 03 Nov 2006
# Latest Revision: 16 Jul 2012, 15.00 GMT
#
#
@@ -12,30 +12,27 @@
# For All Kind Of Problems, Requests Of Enhancements And Bug Reports,
# Please Write To Me At:
#
# andrea.gavana@maerskoil.com # noqa: SC100
# andrea.gavana@gmail.com # noqa: SC100
# andrea.gavana@maerskoil.com
# andrea.gavana@gmail.com
#
# Or, Obviously, To The wxPython Mailing List!!! # noqa: SC100
# Or, Obviously, To The wxPython Mailing List!!!
#
# Tags: phoenix-port, unittest, documented, py3-port # noqa: SC100
# Tags: phoenix-port, unittest, documented, py3-port
#
# End Of Comments
# ---------------------------------------------------------------------------- #
# ------------------------------------------------------------------------------------ #

"""
FourWaySplitter is a layout manager that arranges 4 child panes in a window.
"""FourWaySplitter is a layout manager that arranges 4 child panes in a window.
Description
===========
The :class:`FourWaySplitter` is a layout manager which manages four children
like four panes in a window. You can use a four-way splitter for example in a
CAD program where you may want to maintain three orthographic views,
and one oblique view of a model.
The :class:`FourWaySplitter` is a layout manager which manages four children like four
panes in a window. You can use a four-way splitter for example in a CAD program where
you may want to maintain three orthographic views, and one oblique view of a model.
The :class:`FourWaySplitter` allows interactive repartitioning of the panes by
means of moving the central splitter bars.
When the :class:`FourWaySplitter` is itself resized,
The :class:`FourWaySplitter` allows interactive repartitioning of the panes by means of
moving the central splitter bars. When the :class:`FourWaySplitter` is itself resized,
each child is proportionally resized, maintaining the same split-percentage.
The main characteristics of :class:`FourWaySplitter` are:
@@ -44,7 +41,7 @@
- Delayed or live update when resizing;
- Possibility to swap windows;
- Setting the vertical and horizontal split fractions;
- Possibility to expand a window by hiding the onther 3.
- Possibility to expand a window by hiding the other 3.
And a lot more. See the demo for a complete review of the functionalities.
@@ -59,7 +56,7 @@
class MyFrame(wx.Frame):
def __init__(self, parent):
def __init__(self, parent: wx.Window | None) -> None:
wx.Frame.__init__(self, parent, -1, "FourWaySplitter Demo")
@@ -99,40 +96,38 @@ def __init__(self, parent):
This class supports the following window styles:
================== =========== =================================================
================== =========== =========================================================
Window Styles Hex Value Description
================== =========== =================================================
================== =========== =========================================================
``SP_NOSASH`` 0x10 No sash will be drawn on :class:`FourWaySplitter`.
``SP_LIVE_UPDATE`` 0x80 Don't draw XOR line but resize the child windows
immediately.
``SP_3DBORDER`` 0x200 Draws a 3D effect border.
================== =========== =================================================
================== =========== =========================================================
Events Processing
=================
This class processes the following events:
================================== =============================================
================================== =====================================================
Event Name Description
================================== =============================================
================================== =====================================================
``EVT_SPLITTER_SASH_POS_CHANGED`` The sash position was changed.
This event is generated after the user
releases the mouse after dragging the splitter.
Processes a
This event is generated after the user releases the
mouse after dragging the splitter. Processes a
``wx.wxEVT_COMMAND_SPLITTER_SASH_POS_CHANGED``
event.
``EVT_SPLITTER_SASH_POS_CHANGING`` The sash position is in the process of being changed.
You may prevent this change from happening
by calling `Veto` or you may also modify the
position of the tracking bar to properly
reflect the position that would be set if
the drag were to be completed at this point.
Processes a
You may prevent this change from happening by
calling `Veto` or you may also modify the position
of the tracking bar to properly reflect the position
that would be set if the drag were to be completed
at this point. Processes a
``wx.wxEVT_COMMAND_SPLITTER_SASH_POS_CHANGING``
event.
================================== =============================================
================================== =====================================================
License And Version
@@ -143,13 +138,11 @@ def __init__(self, parent):
Latest Revision: Andrea Gavana @ 16 Jul 2012, 15.00 GMT
Version 0.5
"""


import wx

_RENDER_VER = (2, 6, 1, 1)
_RENDER_VER: tuple[int, int, int, int] = (2, 6, 1, 1)

# Tolerance for mouse shape and sizing
_TOLERANCE = 5
@@ -162,147 +155,149 @@ def __init__(self, parent):
FLAG_PRESSED = 2
"""Sashes are in a pressed state."""

# FourWaySplitter styles # noqa: SC100
SP_NOSASH = wx.SP_NOSASH
# FourWaySplitter styles
SP_NOSASH: int = wx.SP_NOSASH
"""No sash will be drawn on :class:`FourWaySplitter`."""
SP_LIVE_UPDATE = wx.SP_LIVE_UPDATE
SP_LIVE_UPDATE: int = wx.SP_LIVE_UPDATE
"""Don't draw XOR line but resize the child windows immediately."""
SP_3DBORDER = wx.SP_3DBORDER
SP_3DBORDER: int = wx.SP_3DBORDER
"""Draws a 3D effect border."""

# FourWaySplitter events # noqa: SC100
EVT_SPLITTER_SASH_POS_CHANGING = wx.EVT_SPLITTER_SASH_POS_CHANGING
"""
The sash position is in the process of being changed.
# FourWaySplitter events
EVT_SPLITTER_SASH_POS_CHANGING: wx.PyEventBinder = wx.EVT_SPLITTER_SASH_POS_CHANGING
"""The sash position is in the process of being changed.
You may prevent this change from happening by calling `Veto` or you may also
modify the position of the tracking bar to properly reflect the position that
would be set if the drag were to be completed at this point.
You may prevent this change from happening by calling `Veto` or you may also modify the
position of the tracking bar to properly reflect the position that would be set if the
drag were to be completed at this point.
Processes a ``wx.wxEVT_COMMAND_SPLITTER_SASH_POS_CHANGING`` event.
"""
EVT_SPLITTER_SASH_POS_CHANGED = wx.EVT_SPLITTER_SASH_POS_CHANGED
"""
The sash position was changed.
EVT_SPLITTER_SASH_POS_CHANGED: wx.PyEventBinder = wx.EVT_SPLITTER_SASH_POS_CHANGED
"""The sash position was changed.
This event is generated after the user releases the mouse after dragging the splitter.
Processes a ``wx.wxEVT_COMMAND_SPLITTER_SASH_POS_CHANGED`` event.
"""

# ---------------------------------------------------------------------------- #
# Class FourWaySplitterEvent # noqa: SC100
# ---------------------------------------------------------------------------- #
# ------------------------------------------------------------------------------------ #
# Class FourWaySplitterEvent
# ------------------------------------------------------------------------------------ #


class FourWaySplitterEvent(wx.CommandEvent):
"""
This event class adds a sash index accessor to :class:`SplitterEvent`.
"""This event class adds a sash index accessor to :class:`SplitterEvent`.
The same event type IDs and event binders are used as with :class:`SplitterEvent`.
"""

def __init__(self, evtType=wx.wxEVT_NULL, splitter=None):
"""
Construct the default class.
def __init__(
self, evtType: int = wx.wxEVT_NULL, splitter: "None | FourWaySplitter" = None
) -> None:
"""Construct the default class.
Args:
evtType: the event type;
splitter: the associated :class:`FourWaySplitter` window.
evtType (int): the event type;
splitter ("None | FourWaySplitter"): the associated :class:`FourWaySplitter`
window.
"""
wx.CommandEvent.__init__(self, evtType)

if splitter:
self.SetEventObject(splitter)
self.SetId(splitter.GetId())

self.sashIdx = -1
self.sashPos = -1
self.isAllowed = True
self.sashIdx: int = -1
self.sashPos: int | wx.Point = -1
self.isAllowed: bool = True

def SetSashIdx(self, idx):
"""
Set the index of the sash currently involved in the event.
def SetSashIdx(self, idx: int) -> None:
"""Set the index of the sash currently involved in the event.
Args:
idx: an integer between 0 and 3,
idx (int): an integer between 0 and 3,
representing the index of the sash involved in the event.
"""
self.sashIdx = idx
self.sashIdx: int = idx

def SetSashPosition(self, pos):
def SetSashPosition(self, pos: int | wx.Point) -> None:
"""
For EVT_SPLITTER_SASH_POS_CHANGED events, sets the new sash position.
For EVT_SPLITTER_SASH_POS_CHANGED events, set the new sash position.
In the case of ``EVT_SPLITTER_SASH_POS_CHANGING`` events,
sets the new tracking bar position so visual feedback during dragging
will represent that change that will actually take place.
sets the new tracking bar position so visual feedback during dragging will
represent that change that will actually take place.
Set to -1 from the event handler code to prevent repositioning.
Args:
pos: the new sash position.
pos (int | wx.Point): the new sash position.
Note:
May only be called while processing
``EVT_SPLITTER_SASH_POS_CHANGING`` and
May only be called while processing ``EVT_SPLITTER_SASH_POS_CHANGING`` and
``EVT_SPLITTER_SASH_POS_CHANGED`` events.
"""
self.sashPos = pos
self.sashPos: int | wx.Point = pos

def GetSashIdx(self):
"""Return the index of the sash currently involved in the event."""
return self.sashIdx
def GetSashIdx(self) -> int:
"""Return the index of the sash currently involved in the event.
def GetSashPosition(self):
Returns:
int: the index of the sash currently involved in the event.
"""
Return the new sash position.
return self.sashIdx

def GetSashPosition(self) -> int | wx.Point:
"""Return the new sash position.
Returns:
int | wx.Point: the new sash position.
Note:
May only be called while processing
``EVT_SPLITTER_SASH_POS_CHANGING`` and
May only be called while processing ``EVT_SPLITTER_SASH_POS_CHANGING`` and
``EVT_SPLITTER_SASH_POS_CHANGED`` events.
"""
return self.sashPos

# methods from wx.NotifyEvent # noqa: SC100
def Veto(self):
"""
Prevents the change announced by this event from happening.
# methods from wx.NotifyEvent
def Veto(self) -> None:
"""Prevent the change announced by this event from happening.
Note:
It is in general a good idea to notify the user about the reasons
for vetoing the change because otherwise the applications
behaviour (which just refuses to do what the user wants) might
be quite surprising.
It is in general a good idea to notify the user about the reasons for
vetoing the change because otherwise the applications behaviour (which
just refuses to do what the user wants) might be quite surprising.
"""
self.isAllowed = False
self.isAllowed: bool = False

def Allow(self):
"""
Do the opposite of :meth:`~FourWaySplitterEvent.Veto`.
def Allow(self) -> None:
"""Do the opposite of :meth:`~FourWaySplitterEvent.Veto`.
It explicitly allows the event to be processed.
For most events it is not necessary to call this method as the events
are allowed anyhow but some are forbidden by default
For most events it is not necessary to call this method as the events are
allowed anyhow but some are forbidden by default
(this will be mentioned in the corresponding event description).
"""
self.isAllowed = True
self.isAllowed: bool = True

def IsAllowed(self):
"""Return ``True`` if change is allowed, ``False`` if vetoed."""
def IsAllowed(self) -> bool:
"""Return ``True`` if change is allowed, ``False`` if vetoed.
Returns:
bool: ``True`` if change is allowed, ``False`` if vetoed.
"""
return self.isAllowed


# ---------------------------------------------------------------------------- #
# Class FourWaySplitter # noqa: SC100
# Class FourWaySplitter
# ---------------------------------------------------------------------------- #


class FourWaySplitter(wx.Panel):
"""
Similar to :class:`SplitterWindow`, but with four windows and two sashes.
"""Similar to :class:`SplitterWindow`, but with four windows and two sashes.
Many of the same styles, constants,
and methods behave the same as in :class:`SplitterWindow`.
However, in addition of the ability to drag the vertical and the horizontal sash,
However, in addition to the ability to drag the vertical and the horizontal sash,
by dragging at the intersection between the two sashes,
it is possible to resize the four windows at the same time.
@@ -318,39 +313,38 @@ class FourWaySplitter(wx.Panel):

def __init__(
self,
parent,
id=wx.ID_ANY,
pos=wx.DefaultPosition,
size=wx.DefaultSize,
style=0,
agwStyle=0,
name="FourWaySplitter",
):
"""
Construct the default class.
parent: wx.Window,
id: int = wx.ID_ANY,
pos: wx.Point = wx.DefaultPosition,
size: wx.Size = wx.DefaultSize,
style: int = 0,
agwStyle: int = 0,
name: str = "FourWaySplitter",
) -> None:
"""Construct the default class.
Args:
parent: parent window. Must not be ``None``;
id: window identifier. A value of -1 indicates a default value;
pos: the control position. A value of (-1, -1) indicates a default position,
chosen by either the windowing system or wxPython,
depending on platform;
size: the control size. A value of (-1, -1) indicates a default size,
chosen by either the windowing system or wxPython,
depending on platform;
style: the underlying :class:`Panel` window style;
agwStyle: the AGW-specific window style.
parent (wx.Window): parent window. Must not be ``None``;
id (int): window identifier. A value of -1 indicates a default value;
pos (wx.Point): the control position.
A value of (-1, -1) indicates a default position, chosen by either the
windowing system or wxPython, depending on platform;
size (wx.Size): the control size.
A value of (-1, -1) indicates a default size, chosen by either the
windowing system or wxPython, depending on platform;
style (int): the underlying :class:`Panel` window style;
agwStyle (int): the AGW-specific window style.
It can be a combination of the following bits:
================== =========== =================================
================== =========== =========================================
Window Styles Hex Value Description
================== =========== =================================
================== =========== =========================================
``SP_NOSASH`` 0x10 No sash will be drawn on
:class:`FourWaySplitter`.
``SP_LIVE_UPDATE`` 0x80 Don't draw XOR line but resize
the child windows immediately.
``SP_LIVE_UPDATE`` 0x80 Don't draw XOR line but resize the child
windows immediately.
``SP_3DBORDER`` 0x200 Draws a 3D effect border.
================== =========== =================================
name: the window name.
================== =========== =========================================
name (str): the window name.
"""
# always turn on tab traversal
style |= wx.TAB_TRAVERSAL
@@ -359,24 +353,24 @@ def __init__(
style &= ~wx.BORDER_MASK
style |= wx.BORDER_NONE

self._agwStyle = agwStyle
self._agwStyle: int = agwStyle

# initialize the base class
wx.Panel.__init__(self, parent, id, pos, size, style, name)
self.SetBackgroundStyle(wx.BG_STYLE_CUSTOM)

self._windows = []
self._windows: list[wx.Window] = []

self._splitx = 0
self._splity = 0
self._expanded = -1
self._fhor = 5000
self._fver = 5000
self._offx = 0
self._offy = 0
self._mode = NOWHERE
self._flags = 0
self._isHot = False
self._splitx: int = 0
self._splity: int = 0
self._expanded: int = -1
self._fhor: int = 5000
self._fver: int = 5000
self._offx: int = 0
self._offy: int = 0
self._mode: int = NOWHERE
self._flags: int = 0
self._isHot: bool = False

self._sashTrackerPen = wx.Pen(wx.BLACK, 2, wx.PENSTYLE_SOLID)

@@ -392,18 +386,17 @@ def __init__(
self.Bind(wx.EVT_LEAVE_WINDOW, self.OnLeaveWindow)
self.Bind(wx.EVT_ENTER_WINDOW, self.OnEnterWindow)

def _IsVersionGreaterOrEqual(self, version):
"""
Compare the current wxPython version with the given version.
def _IsVersionGreaterOrEqual(self, version: tuple[int, int, int, int]) -> bool:
"""Compare the current wxPython version with the given version.
Args:
version: a tuple of (major, minor, micro) version numbers.
version (tuple[int, int, int, int]): a tuple of version numbers.
Returns:
True if the current wxPython version is greater or equal to the
bool: ``True`` if the current wxPython version is greater or equal to the
given version.
"""
wx_version = wx.VERSION[:3]
wx_version: tuple[int, int, int] = wx.VERSION[:3]
return (
wx_version[0] > version[0]
or (wx_version[0] == version[0] and wx_version[1] > version[1])
@@ -414,107 +407,102 @@ def _IsVersionGreaterOrEqual(self, version):
)
)

def SetAGWWindowStyleFlag(self, agwStyle):
"""
Set the :class:`FourWaySplitter` window style flags.
def SetAGWWindowStyleFlag(self, agwStyle: int) -> None:
"""Set the :class:`FourWaySplitter` window style flags.
Args:
agwStyle: the AGW-specific window style.
agwStyle (int): the AGW-specific window style.
This can be a combination of the following bits:
================== =========== =================================
================== =========== =========================================
Window Styles Hex Value Description
================== =========== =================================
================== =========== =========================================
``SP_NOSASH`` 0x10 No sash will be drawn on
:class:`FourWaySplitter`.
``SP_LIVE_UPDATE`` 0x80 Don't draw XOR line but resize
the child windows immediately.
``SP_LIVE_UPDATE`` 0x80 Don't draw XOR line but resize the child
windows immediately.
``SP_3DBORDER`` 0x200 Draws a 3D effect border.
================== =========== =================================
================== =========== =========================================
"""
self._agwStyle = agwStyle
self.Refresh()

def GetAGWWindowStyleFlag(self):
"""
Return the :class:`FourWaySplitter` window style.
def GetAGWWindowStyleFlag(self) -> int:
"""Return the :class:`FourWaySplitter` window style.
See:
:meth:`~FourWaySplitter.SetAGWWindowStyleFlag` for a list of
possible window styles.
:meth:`~FourWaySplitter.SetAGWWindowStyleFlag` for a list of possible window
styles.
Returns:
int: The AGW-specific window style.
"""
return self._agwStyle

def AppendWindow(self, window):
"""
Add a new window to the splitter at the right or bottom.
def AppendWindow(self, window: wx.Window) -> None:
"""Add a new window to the splitter at the right or bottom.
Args:
window: an instance of :class:`wx.Window`.
window (wx.Window): an instance of :class:`wx.Window`.
"""
self.InsertWindow(len(self._windows), window)

def InsertWindow(self, idx, window, sashPos=-1):
"""
Insert a new window into the splitter at the position given in `idx`.
def InsertWindow(self, idx: int, window: wx.Window) -> None:
"""Insert a new window into the splitter at the position given in `idx`.
Args:
idx: the index at which the window will be inserted;
window: an instance of :class:`wx.Window`;
sashPos: the sash position after the window insertion.
idx (int): the index at which the window will be inserted;
window (wx.Window): an instance of :class:`wx.Window`.
"""
assert window not in self._windows, "A window can only be in the splitter once!"

self._windows.insert(idx, window)

self._SizeWindows()

def DetachWindow(self, window):
"""
Remove the window from the stack of windows managed by the splitter.
def DetachWindow(self, window: wx.Window) -> None:
"""Remove the window from the stack of windows managed by the splitter.
The window will still exist so you should `Hide` or `Destroy` it as needed.
Args:
window: an instance of :class:`wx.Window`.
window (wx.Window): an instance of :class:`wx.Window`.
"""
assert window in self._windows, "Unknown window!"

idx = self._windows.index(window)
idx: int = self._windows.index(window)
del self._windows[idx]

self._SizeWindows()

def ReplaceWindow(self, oldWindow, newWindow):
"""
Replace `oldWindow` with `newWindow` in the splitter.
def ReplaceWindow(self, oldWindow: wx.Window, newWindow: wx.Window) -> None:
"""Replace `oldWindow` with `newWindow` in the splitter.
The `oldWindow` window will still exist so you should `Hide` or
`Destroy` it as needed.
The `oldWindow` window will still exist so you should `Hide` or `Destroy` it as
needed.
Args:
oldWindow: an instance of :class:`wx.Window`;
newWindow: another instance of :class:`wx.Window`.
oldWindow (wx.Window): an instance of :class:`wx.Window`;
newWindow (wx.Window): another instance of :class:`wx.Window`.
"""
assert oldWindow in self._windows, "Unknown window!"

idx = self._windows.index(oldWindow)
idx: int = self._windows.index(oldWindow)
self._windows[idx] = newWindow

self._SizeWindows()

def ExchangeWindows(self, window1, window2):
"""
Trade the positions in the splitter of the two windows.
def ExchangeWindows(self, window1: wx.Window, window2: wx.Window) -> None:
"""Trade the positions in the splitter of the two windows.
Args:
window1: an instance of :class:`wx.Window`;
window2: another instance of :class:`wx.Window`.
window1 (wx.Window): an instance of :class:`wx.Window`;
window2 (wx.Window): another instance of :class:`wx.Window`.
"""
assert window1 in self._windows, "Unknown window!"
assert window2 in self._windows, "Unknown window!"

idx1 = self._windows.index(window1)
idx2 = self._windows.index(window2)
idx1: int = self._windows.index(window1)
idx2: int = self._windows.index(window2)
self._windows[idx1] = window2
self._windows[idx2] = window1

@@ -526,59 +514,85 @@ def ExchangeWindows(self, window1, window2):
if "__WXMSW__" in wx.Platform:
self.Thaw()

def GetWindow(self, idx):
"""
Return the window at the index `idx`.
def GetWindow(self, idx: int) -> wx.Window | None:
"""Return the window at the index `idx`.
Args:
idx: the index at which the window is located.
idx (int): the index at which the window is located.
Returns:
wx.Window | None: The window at the specified index or ``None`` if the index
is out of range.
"""
if len(self._windows) > idx:
return self._windows[idx]

return None

# Get top left child
def GetTopLeft(self):
"""Return the top left window (window index: 0)."""
def GetTopLeft(self) -> wx.Window | None:
"""Return the top left window (window index: 0).
Returns:
wx.Window | None: The top left window or ``None`` if the index is out of
range.
"""
return self.GetWindow(0)

# Get top right child
def GetTopRight(self):
"""Return the top right window (window index: 1)."""
def GetTopRight(self) -> wx.Window | None:
"""Return the top right window (window index: 1).
Returns:
wx.Window | None: The top right window or ``None`` if the index is out of
range.
"""
return self.GetWindow(1)

# Get bottom left child
def GetBottomLeft(self):
"""Return the bottom left window (window index: 2)."""
def GetBottomLeft(self) -> wx.Window | None:
"""Return the bottom left window (window index: 2).
Returns:
wx.Window | None: The bottom left window or ``None`` if the index is out of
range.
"""
return self.GetWindow(2)

# Get bottom right child
def GetBottomRight(self):
"""Return the bottom right window (window index: 3)."""
return self.GetWindow(3)
def GetBottomRight(self) -> wx.Window | None:
"""Return the bottom right window (window index: 3).
def DoGetBestSize(self):
Returns:
wx.Window | None: The bottom right window or ``None`` if the index is out of
range.
"""
Get the size which best suits the window.
return self.GetWindow(3)

def DoGetBestSize(self) -> wx.Size:
"""Get the size which best suits the window.
For a control, it would be the minimal size which doesn't truncate the control,
for a panel - the same size as it would have after a call to `Fit()`.
Note:
Overridden from :class:`Panel`.
Returns:
wx.Size: The best size for the window.
"""
if not self._windows:
# something is better than nothing...
return wx.Size(10, 10)

width = height = 0
border = self._GetBorderSize()
width: int = 0
height: int = 0
border: int = self._GetBorderSize()

tl = self.GetTopLeft()
tr = self.GetTopRight()
bl = self.GetBottomLeft()
br = self.GetBottomRight()
tl: wx.Window | None = self.GetTopLeft()
tr: wx.Window | None = self.GetTopRight()
bl: wx.Window | None = self.GetBottomLeft()
br: wx.Window | None = self.GetBottomRight()

for win in self._windows:
w, h = win.GetEffectiveMinSize()
@@ -594,31 +608,29 @@ def DoGetBestSize(self):
return wx.Size(width + 2 * border, height + 2 * border)

# Recompute layout
def _SizeWindows(self):
"""
Recalculate the layout based on split positions and split fractions.
def _SizeWindows(self) -> None:
"""Recalculate the layout based on split positions and split fractions.
See:
:meth:`~FourWaySplitter.SetHSplit` and
:meth:`~FourWaySplitter.SetVSplit` for more information about
split fractions.
:meth:`~FourWaySplitter.SetHSplit` and :meth:`~FourWaySplitter.SetVSplit`
for more information about split fractions.
"""
win0 = self.GetTopLeft()
win1 = self.GetTopRight()
win2 = self.GetBottomLeft()
win3 = self.GetBottomRight()
win0: wx.Window | None = self.GetTopLeft()
win1: wx.Window | None = self.GetTopRight()
win2: wx.Window | None = self.GetBottomLeft()
win3: wx.Window | None = self.GetBottomRight()

width, height = self.GetSize()
barSize = self._GetSashSize()
border = self._GetBorderSize()
barSize: int = self._GetSashSize()
border: int = self._GetBorderSize()

if self._expanded < 0:
totw = width - barSize - 2 * border
toth = height - barSize - 2 * border
self._splitx = (self._fhor * totw) // 10000
self._splity = (self._fver * toth) // 10000
rightw = totw - self._splitx
bottomh = toth - self._splity
totw: int = width - barSize - 2 * border
toth: int = height - barSize - 2 * border
self._splitx: int = (self._fhor * totw) // 10000
self._splity: int = (self._fver * toth) // 10000
rightw: int = totw - self._splitx
bottomh: int = toth - self._splity
if win0:
win0.SetSize(0, 0, self._splitx, self._splity)
win0.Show()
@@ -645,28 +657,26 @@ def _SizeWindows(self):
win.Hide()

# Determine split mode
def GetMode(self, pt):
"""
Determine the split mode for :class:`FourWaySplitter`.
def GetMode(self, pt: wx.Point) -> int:
"""Determine the split mode for :class:`FourWaySplitter`.
Args:
pt: the point at which the mouse has been clicked,
pt (wx.Point): the point at which the mouse has been clicked,
an instance of :class:`wx.Point`.
Returns:
One of the following 3 split modes:
================= ==============================
int: One of the following 3 split modes:
================= ======================================================
Split Mode Description
================= ==============================
================= ======================================================
``wx.HORIZONTAL`` the user has clicked on the horizontal sash
``wx.VERTICAL`` The user has clicked on the vertical sash
``wx.BOTH`` The user has clicked at the intersection
between the 2 sashes
================= ==============================
``wx.VERTICAL`` the user has clicked on the vertical sash
``wx.BOTH`` the user has clicked at the intersection between the 2
sashes
================= ======================================================
"""
barSize = self._GetSashSize()
flag = wx.BOTH
barSize: int = self._GetSashSize()
flag: int = wx.BOTH

if pt.x < self._splitx - _TOLERANCE:
flag &= ~wx.VERTICAL
@@ -683,16 +693,15 @@ def GetMode(self, pt):
return flag

# Move the split intelligently
def MoveSplit(self, x, y):
"""
Move the split accordingly to user action.
def MoveSplit(self, x: int, y: int) -> None:
"""Move the split accordingly to user action.
Args:
x: the new splitter `x` coordinate;
y: the new splitter `y` coordinate.
x (int): the new splitter `x` coordinate;
y (int): the new splitter `y` coordinate.
"""
width, height = self.GetSize()
barSize = self._GetSashSize()
barSize: int = self._GetSashSize()

if x < 0:
x = 0
@@ -707,22 +716,21 @@ def MoveSplit(self, x, y):
self._splity = y

# Adjust layout
def AdjustLayout(self):
"""
Adjust layout of :class:`FourWaySplitter`.
def AdjustLayout(self) -> None:
"""Adjust layout of :class:`FourWaySplitter`.
Mainly used to recalculate the correct values for split fractions.
"""
width, height = self.GetSize()
barSize = self._GetSashSize()
barSize: int = self._GetSashSize()

self._fhor = (
self._fhor: int = (
width > barSize
and [(10000 * self._splitx + (width - barSize - 1)) // (width - barSize)]
or [0]
)[0]

self._fver = (
self._fver: int = (
height > barSize
and [(10000 * self._splity + (height - barSize - 1)) // (height - barSize)]
or [0]
@@ -731,44 +739,48 @@ def AdjustLayout(self):
self._SizeWindows()

# Button being pressed
def OnLeftDown(self, event):
"""
Handle the ``wx.EVT_LEFT_DOWN`` event for :class:`FourWaySplitter`.
def OnLeftDown(self, event: wx.MouseEvent) -> None:
"""Handle the ``wx.EVT_LEFT_DOWN`` event for :class:`FourWaySplitter`.
Args:
event: a :class:`MouseEvent` event to be processed.
event (wx.MouseEvent): a :class:`MouseEvent` event to be processed.
Returns:
None
"""
if not self.IsEnabled():
return

pt = event.GetPosition()
pt: wx.Point = event.GetPosition()
self.CaptureMouse()
self._mode = self.GetMode(pt)

if self._mode:
self._offx = pt.x - self._splitx
self._offy = pt.y - self._splity
self._offx: int = pt.x - self._splitx
self._offy: int = pt.y - self._splity
if not self.GetAGWWindowStyleFlag() & wx.SP_LIVE_UPDATE:
self.DrawSplitter(wx.ClientDC(self))
self.DrawTrackSplitter(self._splitx, self._splity)

self._flags |= FLAG_PRESSED

# Button being released
def OnLeftUp(self, event):
"""
Handle the ``wx.EVT_LEFT_UP`` event for :class:`FourWaySplitter`.
def OnLeftUp(self, event: wx.MouseEvent) -> None:
"""Handle the ``wx.EVT_LEFT_UP`` event for :class:`FourWaySplitter`.
Args:
event: a :class:`MouseEvent` event to be processed.
event (wx.MouseEvent): a :class:`MouseEvent` event to be processed.
Returns:
None
"""
if not self.IsEnabled():
return

if self.HasCapture():
self.ReleaseMouse()

flgs = self._flags
flgs: int = self._flags

self._flags &= ~FLAG_CHANGED
self._flags &= ~FLAG_PRESSED
@@ -781,68 +793,68 @@ def OnLeftUp(self, event):
self.AdjustLayout()

if flgs & FLAG_CHANGED:
event = FourWaySplitterEvent(
splitter_event = FourWaySplitterEvent(
wx.wxEVT_COMMAND_SPLITTER_SASH_POS_CHANGED, self
)
event.SetSashIdx(self._mode)
event.SetSashPosition(wx.Point(self._splitx, self._splity))
self.GetEventHandler().ProcessEvent(event)
splitter_event.SetSashIdx(self._mode)
splitter_event.SetSashPosition(wx.Point(self._splitx, self._splity))
self.GetEventHandler().ProcessEvent(splitter_event)

self._mode = NOWHERE

def OnLeaveWindow(self, event):
"""
Handle the ``wx.EVT_LEAVE_WINDOW`` event for :class:`FourWaySplitter`.
def OnLeaveWindow(self, event: wx.MouseEvent) -> None:
"""Handle the ``wx.EVT_LEAVE_WINDOW`` event for :class:`FourWaySplitter`.
Args:
event: a :class:`MouseEvent` event to be processed.
event (wx.MouseEvent): a :class:`MouseEvent` event to be processed.
"""
self.SetCursor(wx.STANDARD_CURSOR)
self._RedrawIfHotSensitive(False)

def OnEnterWindow(self, event):
"""
Handle the ``wx.EVT_ENTER_WINDOW`` event for :class:`FourWaySplitter`.
def OnEnterWindow(self, event: wx.MouseEvent) -> None:
"""Handle the ``wx.EVT_ENTER_WINDOW`` event for :class:`FourWaySplitter`.
Args:
event: a :class:`MouseEvent` event to be processed.
event (wx.MouseEvent): a :class:`MouseEvent` event to be processed.
"""
self._RedrawIfHotSensitive(True)

def _RedrawIfHotSensitive(self, isHot):
"""
Use internally.
def _RedrawIfHotSensitive(self, isHot: bool) -> None:
"""Use internally.
Redraw the splitter if we are using a hot-sensitive splitter.
Args:
isHot: ``True`` if the splitter is in a hot state, ``False`` otherwise.
isHot (bool): ``True`` if the splitter is in a hot state,
``False`` otherwise.
"""
if not self._IsVersionGreaterOrEqual(_RENDER_VER):
return

if wx.RendererNative.Get().GetSplitterParams(self).isHotSensitive:
self._isHot = isHot
self._isHot: bool = isHot
dc = wx.ClientDC(self)
self.DrawSplitter(dc)

def OnMotion(self, event):
"""
Handle the ``wx.EVT_MOTION`` event for :class:`FourWaySplitter`.
def OnMotion(self, event: wx.MouseEvent) -> None:
"""Handle the ``wx.EVT_MOTION`` event for :class:`FourWaySplitter`.
Args:
event: a :class:`MouseEvent` event to be processed.
event (wx.MouseEvent): a :class:`MouseEvent` event to be processed.
Returns:
None
"""
if self.HasFlag(wx.SP_NOSASH):
return

pt = event.GetPosition()
pt: wx.Point = event.GetPosition()

# Moving split
if self._flags & FLAG_PRESSED:

oldsplitx = self._splitx
oldsplity = self._splity
oldsplitx: int = self._splitx
oldsplity: int = self._splity

if self._mode == wx.BOTH:
self.MoveSplit(pt.x - self._offx, pt.y - self._offy)
@@ -869,7 +881,7 @@ def OnMotion(self, event):
self._flags |= FLAG_CHANGED

# Change cursor based on position
ff = self.GetMode(pt)
ff: int = self.GetMode(pt)

if ff == wx.BOTH:
self.SetCursor(self._sashCursorSIZING)
@@ -885,36 +897,36 @@ def OnMotion(self, event):

event.Skip()

def OnPaint(self, event):
"""
Handle the ``wx.EVT_PAINT`` event for :class:`FourWaySplitter`.
def OnPaint(self, event: wx.PaintEvent) -> None:
"""Handle the ``wx.EVT_PAINT`` event for :class:`FourWaySplitter`.
Args:
event: a :class:`PaintEvent` event to be processed.
event (wx.PaintEvent): a :class:`PaintEvent` event to be processed.
"""
dc = wx.PaintDC(self)
self.DrawSplitter(dc)

def OnSize(self, event):
"""
Handle the ``wx.EVT_SIZE`` event for :class:`FourWaySplitter`.
def OnSize(self, event: wx.SizeEvent) -> None:
"""Handle the ``wx.EVT_SIZE`` event for :class:`FourWaySplitter`.
Args:
event: a :class:``wx.SizeEvent` event to be processed.
event (wx.SizeEvent): a :class:`SizeEvent` event to be processed.
"""
parent = wx.GetTopLevelParent(self)
if parent.IsIconized():
parent: wx.Window = wx.GetTopLevelParent(self)
if isinstance(parent, wx.TopLevelWindow) and parent.IsIconized():
event.Skip()
return

self._SizeWindows()

def DoSendChangingEvent(self, pt):
"""
Send a ``EVT_SPLITTER_SASH_POS_CHANGING`` event.
def DoSendChangingEvent(self, pt: wx.Point) -> bool:
"""Send a ``EVT_SPLITTER_SASH_POS_CHANGING`` event.
Args:
pt: the point at which the splitter is being positioned.
pt (wx.Point): the point at which the splitter is being positioned.
Returns:
bool: ``True`` if the event is allowed, ``False`` otherwise.
"""
# send the event
event = FourWaySplitterEvent(wx.wxEVT_COMMAND_SPLITTER_SASH_POS_CHANGING, self)
@@ -928,8 +940,12 @@ def DoSendChangingEvent(self, pt):
# or it might have changed the value
return True

def _GetSashSize(self):
"""Use internally."""
def _GetSashSize(self) -> int:
"""Use internally.
Returns:
int: The size of the sash.
"""
if self.HasFlag(wx.SP_NOSASH):
return 0

@@ -938,22 +954,28 @@ def _GetSashSize(self):
else:
return 5

def _GetBorderSize(self):
"""Use internally."""
def _GetBorderSize(self) -> int:
"""Use internally.
Returns:
int: The size of the border.
"""
if self._IsVersionGreaterOrEqual(_RENDER_VER):
return wx.RendererNative.Get().GetSplitterParams(self).border
else:
return 0

# Draw the horizontal split
def DrawSplitter(self, dc):
"""
Actually draws the sashes.
def DrawSplitter(self, dc: wx.DC) -> None:
"""Actually draw the sashes.
Args:
dc: an instance of :class:`wx.DC`.
dc (wx.DC): an instance of :class:`wx.DC`.
Returns:
None
"""
backColour = self.GetBackgroundColour()
backColour: wx.Colour = self.GetBackgroundColour()
dc.SetBrush(wx.Brush(backColour))
dc.SetPen(wx.Pen(backColour))
dc.Clear()
@@ -964,7 +986,7 @@ def DrawSplitter(self, dc):
self, dc, self.GetClientRect()
)
else:
barSize = self._GetSashSize()
barSize: int = self._GetSashSize()

# Define barSize here to ensure it is always defined
barSize = self._GetSashSize()
@@ -975,7 +997,7 @@ def DrawSplitter(self, dc):

flag = 0
if self._isHot:
flag = wx.CONTROL_CURRENT
flag: int = wx.CONTROL_CURRENT

width, height = self.GetSize()

@@ -995,17 +1017,16 @@ def DrawSplitter(self, dc):
else:
dc.DrawRectangle(0, self._splity, width, barSize)

def DrawTrackSplitter(self, x, y):
"""
Draws a fake sash in case we don't have ``wx.SP_LIVE_UPDATE`` style.
def DrawTrackSplitter(self, x: int, y: int) -> None:
"""Draws a fake sash in case we don't have ``wx.SP_LIVE_UPDATE`` style.
Args:
x: the `x` position of the sash;
y: the `y` position of the sash.
x (int): the `x` position of the sash;
y (int): the `y` position of the sash.
Note:
This method relies on :class:`ScreenDC` which is currently
unavailable on wxMac.
This method relies on :class:`ScreenDC` which is currently unavailable on
wxMac.
"""
# Draw a line to represent the dragging sash, for when not doing live updates
w, h = self.GetClientSize()
@@ -1016,10 +1037,10 @@ def DrawTrackSplitter(self, x, y):
dc.SetBrush(wx.TRANSPARENT_BRUSH)

if self._mode == wx.VERTICAL:
x1 = x
x1: int = x
y1 = 2
x2 = x
y2 = h - 2
x2: int = x
y2: int = h - 2
if x1 > w:
x1 = w
x2 = w
@@ -1036,7 +1057,7 @@ def DrawTrackSplitter(self, x, y):
elif self._mode == wx.HORIZONTAL:

x1 = 2
y1 = y
y1: int = y
x2 = w - 2
y2 = y
if y1 > h:
@@ -1076,12 +1097,11 @@ def DrawTrackSplitter(self, x, y):
dc.SetLogicalFunction(wx.COPY)

# Change horizontal split [fraction*10000]
def SetHSplit(self, s):
"""
Change horizontal split fraction.
def SetHSplit(self, s: int) -> None:
"""Change horizontal split fraction.
Args:
s: the split fraction,
s (int): the split fraction,
which is an integer value between 0 and 10000 (inclusive),
indicating how much space to allocate to the leftmost panes.
For example, to split the panes at 35 percent, use::
@@ -1096,16 +1116,15 @@ def SetHSplit(self, s):
self._SizeWindows()

# Change vertical split [fraction*10000]
def SetVSplit(self, s):
"""
Change vertical split fraction.
def SetVSplit(self, s: int) -> None:
"""Change vertical split fraction.
Args:
s: the split fraction,
s (int): the split fraction,
which is an integer value between 0 and 10000 (inclusive),
indicating how much space to allocate to the topmost panes.
For example, to split the panes at 35 percent, use::
fourSplitter.SetVSplit(3500)
For example, to split the panes at 35 percent,
use::fourSplitter.SetVSplit(3500)
"""
if s < 0:
s = 0
@@ -1116,19 +1135,21 @@ def SetVSplit(self, s):
self._SizeWindows()

# Expand one or all of the four panes
def SetExpanded(self, expanded):
"""
Expand a window or revert to four.
def SetExpanded(self, expanded: int) -> None:
"""Expand a window or revert to four.
Args:
expanded: an integer >= 0 to expand a window to fill the whole client size,
or an integer < 0 to return to the four-window view.
expanded (int): an integer >= 0 to expand a window to fill the whole client
size, or an integer < 0 to return to the four-window view.
Raises:
Exception: If the `expanded` index is out of range (>= 4).
"""
if expanded >= 4:
raise Exception(f"ERROR: SetExpanded: index out of range: {expanded}")

if self._expanded != expanded:
self._expanded = expanded
self._expanded: int = expanded
self._SizeWindows()


@@ -1137,22 +1158,29 @@ def SetExpanded(self, expanded):
import wx

class MyFrame(wx.Frame):
"""
MyFrame is a custom wx.Frame that demonstrates the usage of the FourWaySplitter.
It initializes a frame with a FourWaySplitter containing four colored panels.
"""

def __init__(self, parent):
def __init__(self, parent: wx.Window | None) -> None:
"""Initialize the MyFrame with a FourWaySplitter and four colored panels.
Args:
parent (wx.Window | None): The parent window for this frame.
"""
wx.Frame.__init__(self, parent, -1, "FourWaySplitter Demo")

splitter = FourWaySplitter(self, -1, agwStyle=wx.SP_LIVE_UPDATE)

# Put in some coloured panels...
for colour in [wx.RED, wx.WHITE, wx.BLUE, wx.GREEN]:

panel = wx.Panel(splitter)
panel.SetBackgroundColour(colour)

splitter.AppendWindow(panel)

# our normal wxApp-derived class, as usual # noqa: SC100
# our normal wxApp-derived class, as usual

app = wx.App(False)

7 changes: 7 additions & 0 deletions whitelist.txt
Original file line number Diff line number Diff line change
@@ -1,10 +1,17 @@
5x5
Blit
FOURWAYSPLITTER
gavana
Gavana
gmail
GTK
maerskoil
Office2007
rect
Renderer
renderers
Splitter
unittest
WS
wx
xpm