Skip to content

Commit

Permalink
Cascade multiple windows properly
Browse files Browse the repository at this point in the history
Also make the newly opened window the keyWindow so that it automatically
receives focus.
  • Loading branch information
shivaprsd authored and Roman Sirokov committed May 15, 2017
1 parent fe3634b commit 3b80973
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions webview/cocoa.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
class BrowserView:
instances = []
active_instances = 0
cascade_loc = Foundation.NSMakePoint(140.0, 0.0)
app = AppKit.NSApplication.sharedApplication()

class AppDelegate(AppKit.NSObject):
Expand Down Expand Up @@ -205,7 +206,7 @@ def __init__(self, title, url, width, height, resizable, fullscreen, min_size, w
self.webview_ready = webview_ready
self.is_fullscreen = False

rect = AppKit.NSMakeRect(100.0, 350.0, width, height)
rect = AppKit.NSMakeRect(0.0, 0.0, width, height)
window_mask = AppKit.NSTitledWindowMask | AppKit.NSClosableWindowMask | AppKit.NSMiniaturizableWindowMask

if resizable:
Expand All @@ -215,6 +216,7 @@ def __init__(self, title, url, width, height, resizable, fullscreen, min_size, w
initWithContentRect_styleMask_backing_defer_(rect, window_mask, AppKit.NSBackingStoreBuffered, False)
self.window.setTitle_(title)
self.window.setMinSize_(AppKit.NSSize(min_size[0], min_size[1]))
BrowserView.cascade_loc = self.window.cascadeTopLeftFromPoint_(BrowserView.cascade_loc)

self.webkit = BrowserView.WebKitHost.alloc().initWithFrame_(rect)
self.window.setContentView_(self.webkit)
Expand Down Expand Up @@ -245,7 +247,7 @@ def __init__(self, title, url, width, height, resizable, fullscreen, min_size, w

def show(self):
self.window.display()
self.window.orderFrontRegardless()
self.window.makeKeyAndOrderFront_(self.window)
if not BrowserView.app.isRunning():
BrowserView.app.activateIgnoringOtherApps_(Foundation.YES)
BrowserView.app.run()
Expand Down

0 comments on commit 3b80973

Please sign in to comment.