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

Protect accessible attributes from modification #16

Merged
merged 5 commits into from
Sep 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ build-backend = "hatchling.build"

[project]
name = "ScrollableContainers"
version = "2.1.0"
version = "2.1.1"
authors = [
{ name = "Vishal Pankaj Chandratreya" },
]
Expand Down
8 changes: 6 additions & 2 deletions src/ScrollableContainers/_qt5.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,11 @@ def __init__(self, *args, **kwargs):
container = QWidget()
self.setWidget(container)
vbox = QVBoxLayout(container)
self.area = QWidget()
vbox.addWidget(self.area, alignment=Qt.AlignHCenter)
self._area = QWidget()
vbox.addWidget(self._area, alignment=Qt.AlignHCenter)
vbox.addStretch()
self.setWidgetResizable(True)

@property
def area(self):
return self._area
8 changes: 6 additions & 2 deletions src/ScrollableContainers/_qt6.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,11 @@ def __init__(self, *args, **kwargs):
container = QWidget()
self.setWidget(container)
vbox = QVBoxLayout(container)
self.area = QWidget()
vbox.addWidget(self.area, alignment=Qt.AlignmentFlag.AlignHCenter)
self._area = QWidget()
vbox.addWidget(self._area, alignment=Qt.AlignmentFlag.AlignHCenter)
vbox.addStretch()
self.setWidgetResizable(True)

@property
def area(self):
return self._area
16 changes: 10 additions & 6 deletions src/ScrollableContainers/_tk.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,17 +42,21 @@ def __init__(self, *args, **kwargs):
self.grid_rowconfigure(0, weight=1)
self.grid_columnconfigure(0, weight=1)

self.frame = ttk.Frame(self._canvas)
self._window = self._canvas.create_window((0, 0), window=self.frame, anchor=tk.NW)
self.frame.bind("<Configure>", self._on_frame_configure)
self._on_frame_expose_id = self.frame.bind("<Expose>", self._on_frame_expose)
self._frame = ttk.Frame(self._canvas)
self._window = self._canvas.create_window((0, 0), window=self._frame, anchor=tk.NW)
self._frame.bind("<Configure>", self._on_frame_configure)
self._on_frame_expose_id = self._frame.bind("<Expose>", self._on_frame_expose)

# Initially, the vertical scrollbar is a hair below its topmost
# position. Move it to said position. No harm in doing the equivalent
# for the horizontal scrollbar.
self._canvas.xview_moveto(0.0)
self._canvas.yview_moveto(0.0)

@property
def frame(self):
return self._frame

def _show_scrollbars(self):
"""
Move the horizontal and vertical scrollbars above the scrollable
Expand Down Expand Up @@ -120,7 +124,7 @@ def _xview(self, *args, width: int | None = None):
# function with a negative argument. I don't know if this hack is
# supported (because the Tcl/Tk manual pages say that it must be a
# fraction between 0 and 1), but it works!
self._canvas.xview_moveto((1 - width / self.frame.winfo_width()) / 2)
self._canvas.xview_moveto((1 - width / self._frame.winfo_width()) / 2)

def _yview(self, *args):
"""
Expand Down Expand Up @@ -169,7 +173,7 @@ def _on_frame_expose(self, _event: tk.Event | None = None):
:param _event: Expose event.
"""
self._on_frame_configure()
self.frame.unbind("<Expose>", self._on_frame_expose_id)
self._frame.unbind("<Expose>", self._on_frame_expose_id)

def _on_canvas_enter(self, _event: tk.Event | None = None):
"""
Expand Down
8 changes: 6 additions & 2 deletions src/ScrollableContainers/_wx.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@ def __init__(self, *args, **kwargs):
# According to the documentation, a sizer is required to calculate the
# minimum virtual size of the panel.
vbox = wx.BoxSizer(wx.VERTICAL)
self.panel = wx.Panel(self)
vbox.Add(self.panel, flag=wx.ALIGN_CENTRE)
self._panel = wx.Panel(self)
vbox.Add(self._panel, flag=wx.ALIGN_CENTRE)
self.SetSizer(vbox)

@property
def panel(self):
return self._panel