-
-
Notifications
You must be signed in to change notification settings - Fork 695
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1930 from proneon267/patch-11
Added APIs for detecting multiple displays and setting windows on them.
- Loading branch information
Showing
54 changed files
with
1,076 additions
and
40 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
from android.graphics import ( | ||
Bitmap, | ||
Canvas as A_Canvas, | ||
) | ||
|
||
from toga.screens import Screen as ScreenInterface | ||
|
||
from .widgets.base import Scalable | ||
|
||
|
||
class Screen(Scalable): | ||
_instances = {} | ||
|
||
def __new__(cls, app, native): | ||
if native in cls._instances: | ||
return cls._instances[native] | ||
else: | ||
instance = super().__new__(cls) | ||
instance.interface = ScreenInterface(_impl=instance) | ||
instance.native = native | ||
cls._instances[native] = instance | ||
cls.app = app | ||
instance.init_scale(instance.app.native) | ||
return instance | ||
|
||
def get_name(self): | ||
return self.native.getName() | ||
|
||
def get_origin(self): | ||
return (0, 0) | ||
|
||
def get_size(self): | ||
return ( | ||
self.scale_out(self.native.getWidth()), | ||
self.scale_out(self.native.getHeight()), | ||
) | ||
|
||
def get_image_data(self): | ||
# Get the root view of the current activity | ||
root_view = self.app.native.getWindow().getDecorView().getRootView() | ||
bitmap = Bitmap.createBitmap( | ||
*map(self.scale_in, self.get_size()), | ||
Bitmap.Config.ARGB_8888, | ||
) | ||
canvas = A_Canvas(bitmap) | ||
root_view.draw(canvas) | ||
|
||
return bitmap |
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
from android.view import Display | ||
|
||
import toga | ||
from toga.images import Image as TogaImage | ||
from toga_android.widgets.base import Scalable | ||
|
||
from .probe import BaseProbe | ||
|
||
|
||
class ScreenProbe(BaseProbe, Scalable): | ||
def __init__(self, screen): | ||
app = toga.App.app | ||
super().__init__(app) | ||
self.screen = screen | ||
self._impl = screen._impl | ||
self.native = screen._impl.native | ||
self.init_scale(app._impl.native) | ||
assert isinstance(self.native, Display) | ||
|
||
def get_screenshot(self, format=TogaImage): | ||
return self.screen.as_image(format=format) |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Toga apps can now access details about the screens attached to the computer. Window position APIs have been extended to allow for placement on a specific screen, and positioning relative to a specific screen. |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
The macOS implementations of ``Window.as_image()`` and ``Canvas.as_image()`` APIs now return images in native device resolution, not CSS pixel resolution. This will result in images that are double the previous size on Retina displays. |
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
from rubicon.objc import CGSize | ||
|
||
from toga.screens import Screen as ScreenInterface | ||
from toga_cocoa.libs import ( | ||
NSImage, | ||
core_graphics, | ||
) | ||
|
||
|
||
class Screen: | ||
_instances = {} | ||
|
||
def __new__(cls, native): | ||
if native in cls._instances: | ||
return cls._instances[native] | ||
else: | ||
instance = super().__new__(cls) | ||
instance.interface = ScreenInterface(_impl=instance) | ||
instance.native = native | ||
cls._instances[native] = instance | ||
return instance | ||
|
||
def get_name(self): | ||
return str(self.native.localizedName) | ||
|
||
def get_origin(self): | ||
frame_native = self.native.frame | ||
return (int(frame_native.origin.x), int(frame_native.origin.y)) | ||
|
||
def get_size(self): | ||
frame_native = self.native.frame | ||
return (int(frame_native.size.width), int(frame_native.size.height)) | ||
|
||
def get_image_data(self): | ||
# Retrieve the device description dictionary for the NSScreen | ||
device_description = self.native.deviceDescription | ||
# Extract the CGDirectDisplayID from the device description | ||
cg_direct_display_id = device_description.objectForKey_( | ||
"NSScreenNumber" | ||
).unsignedIntValue | ||
|
||
cg_image = core_graphics.CGDisplayCreateImage( | ||
cg_direct_display_id, | ||
self.native.frame, | ||
) | ||
# Get the size of the CGImage | ||
target_size = CGSize( | ||
core_graphics.CGImageGetWidth(cg_image), | ||
core_graphics.CGImageGetHeight(cg_image), | ||
) | ||
# Create an NSImage from the CGImage | ||
ns_image = NSImage.alloc().initWithCGImage(cg_image, size=target_size) | ||
return ns_image |
This file contains 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
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
from toga.images import Image as TogaImage | ||
from toga_cocoa.libs import NSScreen | ||
|
||
from .probe import BaseProbe | ||
|
||
|
||
class ScreenProbe(BaseProbe): | ||
def __init__(self, screen): | ||
super().__init__() | ||
self.screen = screen | ||
self._impl = screen._impl | ||
self.native = screen._impl.native | ||
assert isinstance(self.native, NSScreen) | ||
|
||
def get_screenshot(self, format=TogaImage): | ||
return self.screen.as_image(format=format) |
Oops, something went wrong.