diff options
-rw-r--r-- | lvc/widgets/osx/window.py | 110 |
1 files changed, 71 insertions, 39 deletions
diff --git a/lvc/widgets/osx/window.py b/lvc/widgets/osx/window.py index 53b1091..f2f2b56 100644 --- a/lvc/widgets/osx/window.py +++ b/lvc/widgets/osx/window.py @@ -52,6 +52,7 @@ from .utils import filename_to_unicode # object stay alive as long as the window is alive. alive_windows = set() + class MiroResponderInterceptor(NSResponder): """Intercepts cocoa events and gives our wrappers and chance to handle them first. @@ -69,7 +70,7 @@ class MiroResponderInterceptor(NSResponder): def keyDown_(self, event): if self.sendKeyDownToWrapper_(event): - return # signal handler returned True, stop processing + return # signal handler returned True, stop processing # If our responder is the last in the chain, we can stop intercepting if self.responder.nextResponder() is None: @@ -84,7 +85,7 @@ class MiroResponderInterceptor(NSResponder): # Make a new MiroResponderInterceptor whose responder is the next # responder down the chain. next_intercepter = MiroResponderInterceptor.alloc().initWithResponder_( - self.responder.nextResponder()) + self.responder.nextResponder()) # Install the interceptor self.responder.setNextResponder_(next_intercepter) # Send event along @@ -107,11 +108,12 @@ class MiroResponderInterceptor(NSResponder): return True return False + class MiroWindow(NSWindow): def initWithContentRect_styleMask_backing_defer_(self, rect, mask, - backing, defer): - self = NSWindow.initWithContentRect_styleMask_backing_defer_(self, - rect, mask, backing, defer) + backing, defer): + self = NSWindow.initWithContentRect_styleMask_backing_defer_( + self, rect, mask, backing, defer) self._last_focus_chain = None return self @@ -119,7 +121,7 @@ class MiroWindow(NSWindow): if self.handle_tab_navigation(event): return interceptor = MiroResponderInterceptor.alloc().initWithResponder_( - self.firstResponder()) + self.firstResponder()) interceptor.keyDown_(event) def handle_tab_navigation(self, event): @@ -186,12 +188,15 @@ class MiroWindow(NSWindow): wrapper = wrappermap.wrapper(self) return wrapper.performDragOperation_(info) or NO + class MainMiroWindow(MiroWindow): def isMovableByWindowBackground(self): return YES + class Window(signals.SignalEmitter): - """See https://develop.participatoryculture.org/index.php/WidgetAPI for a description of the API for this class.""" + """See https://develop.participatoryculture.org/index.php/WidgetAPI + for a description of the API for this class.""" def __init__(self, title, rect=None): signals.SignalEmitter.__init__(self) self.create_signal('active-change') @@ -208,10 +213,10 @@ class Window(signals.SignalEmitter): if rect is None: rect = Rect(0, 0, 470, 600) self.nswindow = MainMiroWindow.alloc().initWithContentRect_styleMask_backing_defer_( - rect.nsrect, - self.get_style_mask(), - NSBackingStoreBuffered, - NO) + rect.nsrect, + self.get_style_mask(), + NSBackingStoreBuffered, + NO) self.nswindow.setTitle_(title) self.nswindow.setMinSize_(NSSize(470, 600)) self.nswindow.setReleasedWhenClosed_(NO) @@ -220,12 +225,17 @@ class Window(signals.SignalEmitter): self.nswindow.setContentView_(self.content_view) self.content_widget = None self.view_notifications = NotificationForwarder.create(self.content_view) - self.view_notifications.connect(self.on_frame_change, 'NSViewFrameDidChangeNotification') + self.view_notifications.connect(self.on_frame_change, + 'NSViewFrameDidChangeNotification') self.window_notifications = NotificationForwarder.create(self.nswindow) - self.window_notifications.connect(self.on_activate, 'NSWindowDidBecomeMainNotification') - self.window_notifications.connect(self.on_deactivate, 'NSWindowDidResignMainNotification') - self.window_notifications.connect(self.on_did_move, 'NSWindowDidMoveNotification') - self.window_notifications.connect(self.on_will_close, 'NSWindowWillCloseNotification') + self.window_notifications.connect(self.on_activate, + 'NSWindowDidBecomeMainNotification') + self.window_notifications.connect(self.on_deactivate, + 'NSWindowDidResignMainNotification') + self.window_notifications.connect(self.on_did_move, + 'NSWindowDidMoveNotification') + self.window_notifications.connect(self.on_will_close, + 'NSWindowWillCloseNotification') wrappermap.add(self.nswindow, self) alive_windows.add(self) @@ -307,11 +317,11 @@ class Window(signals.SignalEmitter): def place_child(self): rect = self.nswindow.contentRectForFrameRect_(self.nswindow.frame()) self.content_widget.place(NSRect(NSPoint(0, 0), rect.size), - self.content_view) + self.content_view) def hookup_content_widget_signals(self): - self.size_req_handler = self.content_widget.connect('size-request-changed', - self.on_content_widget_size_request_change) + self.size_req_handler = self.content_widget.connect( + 'size-request-changed', self.on_content_widget_size_request_change) def unhook_content_widget_signals(self): self.content_widget.disconnect(self.size_req_handler) @@ -343,8 +353,8 @@ class Window(signals.SignalEmitter): rect = self.nswindow.contentRectForFrameRect_(self.nswindow.frame()) if rect.size.width < width or rect.size.height < height: logging.warn("Content widget too large for this window " - "size available: %dx%d widget size: %dx%d", - rect.size.width, rect.size.height, width, height) + "size available: %dx%d widget size: %dx%d", + rect.size.width, rect.size.height, width, height) def get_content_widget(self): return self.content_widget @@ -376,7 +386,7 @@ class Window(signals.SignalEmitter): type_ = available_types.pop() # DANCE! Everybody dance for portable Python code! values = [unicode( - NSURL.fileURLWithPath_(v).filePathURL()).encode('utf-8') + NSURL.fileURLWithPath_(v).filePathURL()).encode('utf-8') for v in list(pb.propertyListForType_(type_))] self.emit('file-drag-received', values) drag_ok = True @@ -396,6 +406,7 @@ class Window(signals.SignalEmitter): def center(self): self.nswindow.center() + class MainWindow(Window): def __init__(self, title, rect): Window.__init__(self, title, rect) @@ -404,16 +415,20 @@ class MainWindow(Window): def close(self): self.nswindow.orderOut_(nil) + class DialogBase(object): def __init__(self): self.sheet_parent = None + def set_transient_for(self, window): self.sheet_parent = window + class MiroPanel(NSPanel): def cancelOperation_(self, event): wrappermap.wrapper(self).end_with_code(-1) + class Dialog(DialogBase): def __init__(self, title, description=None): DialogBase.__init__(self) @@ -473,10 +488,10 @@ class Dialog(DialogBase): width = max(width, 400) window = MiroPanel.alloc() window.initWithContentRect_styleMask_backing_defer_( - NSMakeRect(400, 400, width, height), - NSTitledWindowMask, NSBackingStoreBuffered, NO) + NSMakeRect(400, 400, width, height), + NSTitledWindowMask, NSBackingStoreBuffered, NO) view = FlippedView.alloc().initWithFrame_(NSMakeRect(0, 0, width, - height)) + height)) window.setContentView_(view) window.setTitle_(self.title) self.content_widget.place(view.frame(), view) @@ -486,8 +501,8 @@ class Dialog(DialogBase): def hookup_content_widget_signals(self): self.size_req_handler = self.content_widget.connect( - 'size-request-changed', - self.on_content_widget_size_request_change) + 'size-request-changed', + self.on_content_widget_size_request_change) def unhook_content_widget_signals(self): self.content_widget.disconnect(self.size_req_handler) @@ -503,7 +518,7 @@ class Dialog(DialogBase): def change_content_size(self, width, height): content_rect = self.window.contentRectForFrameRect_( - self.window.frame()) + self.window.frame()) # Cocoa's coordinate system is funky, adjust y so that the top stays # in place content_rect.origin.y += (content_rect.size.height - height) @@ -560,11 +575,13 @@ class Dialog(DialogBase): def get_extra_widget(self): return self.extra_widget + class SheetDelegate(NSObject): @AppHelper.endSheetMethod def sheetDidEnd_returnCode_contextInfo_(self, sheet, return_code, info): NSApp().stopModalWithCode_(return_code) + class FileDialogBase(DialogBase): def __init__(self): DialogBase.__init__(self) @@ -594,6 +611,7 @@ class FileDialogBase(DialogBase): self._panel.orderOut_(nil) return response + class FileSaveDialog(FileDialogBase): def __init__(self, title): FileDialogBase.__init__(self) @@ -626,6 +644,7 @@ class FileSaveDialog(FileDialogBase): set_path = set_filename get_path = get_filename + class FileOpenDialog(FileDialogBase): def __init__(self, title): FileDialogBase.__init__(self) @@ -681,6 +700,7 @@ class FileOpenDialog(FileDialogBase): set_path = set_filename get_path = get_filename + class DirectorySelectDialog(FileDialogBase): def __init__(self, title): FileDialogBase.__init__(self) @@ -713,37 +733,45 @@ class DirectorySelectDialog(FileDialogBase): set_path = set_directory get_path = get_directory + class AboutDialog(DialogBase): def run(self): optionsDictionary = dict() - #revision = app.config.get(prefs.APP_REVISION_NUM) - #if revision: + # revision = app.config.get(prefs.APP_REVISION_NUM) + # if revision: # optionsDictionary['Version'] = revision if not optionsDictionary: optionsDictionary = nil NSApplication.sharedApplication().orderFrontStandardAboutPanelWithOptions_(optionsDictionary) + def destroy(self): pass + class AlertDialog(DialogBase): def __init__(self, title, message, alert_type): DialogBase.__init__(self) - self._nsalert = NSAlert.alloc().init(); + self._nsalert = NSAlert.alloc().init() self._nsalert.setMessageText_(title) self._nsalert.setInformativeText_(message) self._nsalert.setAlertStyle_(alert_type) + def add_button(self, text): self._nsalert.addButtonWithTitle_(text) + def run(self): self._nsalert.runModal() + def destroy(self): self._nsalert = nil + class PreferenceItem(NSToolbarItem): def setPanel_(self, panel): self.panel = panel + class PreferenceToolbarDelegate(NSObject): def initWithPanels_identifiers_window_(self, panels, identifiers, window): @@ -762,9 +790,8 @@ class PreferenceToolbarDelegate(NSObject): def toolbarSelectableItemIdentifiers_(self, toolbar): return self.identifiers - def toolbar_itemForItemIdentifier_willBeInsertedIntoToolbar_(self, toolbar, - itemIdentifier, - flag): + def toolbar_itemForItemIdentifier_willBeInsertedIntoToolbar_( + self, toolbar, itemIdentifier, flag): panel = self.panels[itemIdentifier] item = PreferenceItem.alloc().initWithItemIdentifier_(itemIdentifier) item.setLabel_(unicode(panel[1])) @@ -780,6 +807,7 @@ class PreferenceToolbarDelegate(NSObject): def switchPreferenceView_(self, sender): self.window.do_select_panel(sender.panel, YES) + class DialogWindow(Window): def __init__(self, title, rect, allow_miniaturize=False): self.allow_miniaturize = allow_miniaturize @@ -792,6 +820,7 @@ class DialogWindow(Window): mask |= NSMiniaturizableWindowMask return mask + class DonateWindow(Window): def __init__(self, title): Window.__init__(self, title, Rect(0, 0, 640, 440)) @@ -801,8 +830,8 @@ class DonateWindow(Window): self.nswindow.setShowsToolbarButton_(NO) self.nswindow.setReleasedWhenClosed_(NO) self.app_notifications = NotificationForwarder.create(NSApp()) - self.app_notifications.connect(self.on_app_quit, - 'NSApplicationWillTerminateNotification') + self.app_notifications.connect( + self.on_app_quit, 'NSApplicationWillTerminateNotification') def destroy(self): super(PreferencesWindow, self).destroy() @@ -821,6 +850,7 @@ class DonateWindow(Window): def on_app_quit(self, notification): self.close() + class PreferencesWindow(Window): def __init__(self, title): Window.__init__(self, title, Rect(0, 0, 640, 440)) @@ -830,8 +860,8 @@ class PreferencesWindow(Window): self.nswindow.setShowsToolbarButton_(NO) self.nswindow.setReleasedWhenClosed_(NO) self.app_notifications = NotificationForwarder.create(NSApp()) - self.app_notifications.connect(self.on_app_quit, - 'NSApplicationWillTerminateNotification') + self.app_notifications.connect( + self.on_app_quit, 'NSApplicationWillTerminateNotification') def destroy(self): super(PreferencesWindow, self).destroy() @@ -846,7 +876,8 @@ class PreferencesWindow(Window): self.identifiers.append(name) def finish_panels(self): - self.tbdelegate = PreferenceToolbarDelegate.alloc().initWithPanels_identifiers_window_(self.panels, self.identifiers, self) + self.tbdelegate = PreferenceToolbarDelegate.alloc().initWithPanels_identifiers_window_( + self.panels, self.identifiers, self) toolbar = NSToolbar.alloc().initWithIdentifier_(u"Preferences") toolbar.setAllowsUserCustomization_(NO) toolbar.setDelegate_(self.tbdelegate) @@ -882,6 +913,7 @@ class PreferencesWindow(Window): def on_app_quit(self, notification): self.close() + def get_first_time_dialog_coordinates(width, height): """Returns the coordinates for the first time dialog. """ |