Created
October 29, 2025 13:47
-
-
Save adbac/007aa6c2ac7679b33301127616a1d0b3 to your computer and use it in GitHub Desktop.
Change cursor inside ScrollingMerzView
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| """ | |
| Set a cursor (custom or native) for a ScrollingMerzView | |
| using the underlying NSScrollView | |
| """ | |
| import AppKit | |
| import ezui | |
| import merz | |
| class Demo(ezui.WindowController): | |
| def build(self): | |
| self.viewBaseSize = (400, 400) | |
| content = """ | |
| * ScrollingMerzView @merzView | |
| """ | |
| descriptionData = dict( | |
| merzView=dict( | |
| delegate=self, | |
| width=self.viewBaseSize[0], | |
| height=self.viewBaseSize[1] | |
| ) | |
| ) | |
| self.w = ezui.EZWindow( | |
| content=content, | |
| descriptionData=descriptionData, | |
| controller=self | |
| ) | |
| self.merzView = self.w.getItem("merzView") | |
| self.merzView.setMerzViewSize(self.viewBaseSize) | |
| # Set cursor | |
| self.nsScrollView = self.merzView.getNSScrollView() | |
| self.nsScrollView.setDocumentCursor_( | |
| AppKit.NSCursor.crosshairCursor() | |
| ) | |
| container = self.merzView.getMerzContainer() | |
| container.appendOvalSublayer( | |
| position=(50, 50), | |
| size=(150, 150), | |
| fillColor=(1, 0, 0, 1) | |
| ) | |
| container.appendBaseSublayer( | |
| position=(50, 200), | |
| size=(150, 150), | |
| backgroundColor=(0, 1, 0, 1) | |
| ) | |
| container.appendBaseSublayer( | |
| position=(200, 50), | |
| size=(150, 150), | |
| backgroundColor=(0, 0, 1, 1) | |
| ) | |
| container.appendOvalSublayer( | |
| position=(200, 200), | |
| size=(150, 150), | |
| fillColor=(1, 1, 0, 1) | |
| ) | |
| def started(self): | |
| self.w.open() | |
| # MerzView Delegate | |
| def acceptsFirstResponder(self, sender): | |
| return True | |
| Demo() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment