def focusSearchWindow_(self, sender): if self.search_window.isKeyWindow(): NSApp.hide_(None) else: NSApp.arrangeInFront_(None) self.search_window.makeKeyAndOrderFront_(None) NSApp.activateIgnoringOtherApps_(True) self.search_window.makeFirstResponder_(self.search_box)
def show(self, contact): NSApp.activateIgnoringOtherApps_(True) self.contact = contact self.window.setTitle_(u'Availability Information published by %s' % contact.name) self.name.setStringValue_(self.contact.name) self.addresses.setStringValue_(', '.join(uri.uri for uri in self.contact.uris)) self.window.orderFront_(None) self.icon.setImage_(self.contact.avatar.icon) self.render_pidf()
def show(self, contact): NSApp.activateIgnoringOtherApps_(True) self.contact = contact self.window.setTitle_(NSLocalizedString("Availability Information published by %s", "Window title") % contact.name) self.name.setStringValue_(self.contact.name) self.addresses.setStringValue_(', '.join(uri.uri for uri in self.contact.uris)) self.window.orderFront_(None) self.icon.setImage_(self.contact.avatar.icon) self.render_pidf()
def serverReady(self): print 'OttoDelegate#serverReady' closeSplash() #openWebBrowser() cookies = getSessionCookie() openSocketIO(cookies) NSApp.activateIgnoringOtherApps_(True) openMainWindow() # uses cookies directy from the shared cookie storage, Safari does too return
def displayAlert(message, info, buttons): alert = NSAlert.alloc().init() alert.setMessageText_(message) alert.setInformativeText_(info) alert.setAlertStyle_(NSInformationalAlertStyle) for button in buttons: alert.addButtonWithTitle_(button) NSApp.activateIgnoringOtherApps_(True) buttonPressed = alert.runModal() return buttonPressed
def decideForSessionRequest(self, action, session): sessionController = self.sessionControllersManager.sessionControllerForSession(session) if action == ACCEPT: NSApp.activateIgnoringOtherApps_(True) try: sessionController.log_info(u"Accepting session from %s" % format_identity_to_string(session.remote_identity)) self.acceptStreams(session) except Exception, exc: sessionController.log_info(u"Error accepting session: %s" % exc) self.removeSession(session)
def run(self): if self.hidden: psn = ProcessSerialNumber(0, kCurrentProcess) ApplicationServices.TransformProcessType(psn, kProcessTransformToUIElementAppication) else: psn = ProcessSerialNumber(0, kCurrentProcess) ApplicationServices.TransformProcessType(psn, kProcessTransformToForegroundApplication) self.win.makeKeyAndOrderFront_(None) self.win.display() NSApp.activateIgnoringOtherApps_(True) NSApp.run()
def display(self, sender): # Initiate the controller with a XIB self._controller = PreferencesController.alloc() \ .initWithWindowNibName_('preferences') # self._controller.loadWindow() # Show the window self._controller.showWindow_(sender) # Bring app to top NSApp.activateIgnoringOtherApps_(True)
def runAndStop_(self, timer): self.alert = NSAlert.alloc().init() self.alert.setAlertStyle_(NSInformationalAlertStyle) self.alert.setMessageText_(self.message) if self.buttons is None: self.alert.addButtonWithTitle_('OK') else: for x in self.buttons: self.alert.addButtonWithTitle_(x) NSApp.activateIgnoringOtherApps_(True) self.result_code = self.alert.runModal() NSApp.stop_(None)
def save_dialog(directory, filename): panel = NSSavePanel.savePanel() panel.setTitle_("Save PDF booklet") myUrl = NSURL.fileURLWithPath_isDirectory_(directory, True) panel.setDirectoryURL_(myUrl) panel.setNameFieldStringValue_(filename) NSApp.activateIgnoringOtherApps_(True) ret_value = panel.runModal() if ret_value: return panel.filename() else: return ''
def display_alert(title, message): """Display a warning alert with the given ``title`` and ``message``. :param str title: the big bold title :param str message: the body of the alert """ alert = NSAlert.alloc().init() alert.setAlertStyle_(NSWarningAlertStyle) alert.setMessageText_(title) alert.setInformativeText_(message) NSApp.activateIgnoringOtherApps_(True) alert.runModal()
def main(): session_id = 'mac-{:x}'.format(uuid.getnode()) session = Session(session_id) repository_path = os.path.join( os.environ['HOME'], 'Dropbox (Personal)', 'Earth Reader' ) # FIXME repository = FileSystemRepository(repository_path) # FIXME stage = Stage(session, repository) app = NSApplication.sharedApplication() viewController = MainController(stage) viewController.showWindow_(viewController) NSApp.activateIgnoringOtherApps_(True) return app
def __init__(self, message: str = '', title: str = '', ok: Optional[str] = None, cancel: Optional[str] = None): message = text_type(message) title = text_type(title) self._cancel = bool(cancel) self._icon = None _require_string_or_none(ok) if not isinstance(cancel, string_types): cancel = 'Cancel' if cancel else None self._alert = NSAlert.alertWithMessageText_defaultButton_alternateButton_otherButton_informativeTextWithFormat_( title, ok, cancel, None, message) self._alert.setAlertStyle_(0) NSApp.activateIgnoringOtherApps_(True)
def notify(title, message, bring_up=False): print title, message try: notification.notify(title, message) if system == 'Darwin': from AppKit import NSApp, NSApplication NSApplication.sharedApplication() app = NSApp() app.requestUserAttention_(0) # this should bounce the icon # the 0 should be replaced by the NSRequestUserAttentionType.NSCriticalRequest # imported from NSApplication? TODO # https://developer.apple.com/library/mac/documentation/Cocoa/Reference/ApplicationKit/Classes/NSApplication_Class/Reference/Reference.html#//apple_ref/doc/c_ref/NSRequestUserAttentionType if bring_up: app.activateIgnoringOtherApps_(True) # this should bring the app to the foreground except Exception as e: print e Logger.exception('Notification error:\n%s' % e)
def displayAlert(self): alert = NSAlert.alloc().init() alert.setMessageText_(self.messageText) alert.setInformativeText_(self.informativeText) alert.setAlertStyle_(NSInformationalAlertStyle) for button in self.buttons: alert.addButtonWithTitle_(button) if os.path.exists(alertIconPath): icon = NSImage.alloc().initWithContentsOfFile_(alertIconPath) alert.setIcon_(icon) # Don't show the Python rocketship in the dock NSApp.setActivationPolicy_(1) NSApp.activateIgnoringOtherApps_(True) alert.runModal()
def __init__(self, app, path): self.app = app self.path = path self.name = path.split("/")[-1] self.insecure = None self.menu_item = MenuItem( self.path, callback=self.clicked, key=self.path, icon=ICONS.GRAY, ) self.requirement_files = None self.ui_helper = UIHelper.alloc().initWithApp_(app) NSApp.activateIgnoringOtherApps_(True)
def notify(title, message, bring_up=False): try: kwargs = {'title': title, 'message': message} if system == "Windows" or system == "Linux": kwargs['app_icon'] = os.path.abspath(get_icon_path()) kwargs['timeout'] = 4 notification.notify(**kwargs) if system == 'Darwin': from AppKit import NSApp, NSApplication NSApplication.sharedApplication() app = NSApp() app.requestUserAttention_(0) # this should bounce the icon # the 0 should be replaced by the NSRequestUserAttentionType.NSCriticalRequest # imported from NSApplication? TODO # https://developer.apple.com/library/mac/documentation/Cocoa/Reference/ApplicationKit/Classes/NSApplication_Class/Reference/Reference.html#//apple_ref/doc/c_ref/NSRequestUserAttentionType if bring_up: app.activateIgnoringOtherApps_(True) # this should bring the app to the foreground except Exception as e: print e Logger.exception('Notification error:\n%s' % e)
def decideForAllSessionRequests(self, action): if self.attention is not None: NSApp.cancelUserAttentionRequest_(self.attention) self.attention = None self.panel.close() if action == ACCEPT: NSApp.activateIgnoringOtherApps_(True) for session in self.sessions.keys(): sessionController = self.sessionControllersManager.sessionControllerForSession(session) if sessionController is None: continue is_proposal = self.proposals.has_key(session) try: if is_proposal: sessionController.log_info(u"Accepting all proposed streams from %s" % format_identity_to_string(session.remote_identity)) self.acceptProposedStreams(session) else: sessionController.log_info(u"Accepting session from %s" % format_identity_to_string(session.remote_identity)) self.acceptStreams(session) except Exception, exc: sessionController.log_info(u"Error accepting session: %s" % exc) self.removeSession(session)
except Exception, exc: sessionController.log_info(u"Error rejecting proposal: %s" % exc) self.removeSession(session) def decideForSessionRequest(self, action, session): sessionController = self.sessionControllersManager.sessionControllerForSession(session) if action == ACCEPT: NSApp.activateIgnoringOtherApps_(True) try: sessionController.log_info(u"Accepting session from %s" % format_identity_to_string(session.remote_identity)) self.acceptStreams(session) except Exception, exc: sessionController.log_info(u"Error accepting session: %s" % exc) self.removeSession(session) elif action == ONLY_CHAT: NSApp.activateIgnoringOtherApps_(True) try: sessionController.log_info(u"Accepting chat from %s" % format_identity_to_string(session.remote_identity)) self.acceptChatStream(session) except Exception, exc: sessionController.log_info(u"Error accepting session: %s" % exc) self.removeSession(session) elif action == ONLY_AUDIO: NSApp.activateIgnoringOtherApps_(True) try: sessionController.log_info(u"Accepting audio from %s" % format_identity_to_string(session.remote_identity)) self.acceptChatStream(session) except Exception, exc: sessionController.log_info(u"Error accepting session: %s" % exc) self.removeSession(session) elif action == REJECT:
def enable_focus_workaround(): NSApp.activateIgnoringOtherApps_(True)
def disable_focus_workaround(): NSApp.activateIgnoringOtherApps_(False)
accessory = NSView.alloc().initWithFrame_(NSMakeRect(0, 0, 200, 34)) for i, name in enumerate(['Cancel', 'Copy']): button = NSButton.alloc().init() button.setBezelStyle_(NSRoundedBezelStyle) button.setTitle_(name) button.sizeToFit() x = (i + 0.5) / 2 * 200 - button.frame().size.width / 2 frame = NSMakeRect(x, (34 - button.frame().size.height) / 2, button.frame().size.width, button.frame().size.height) button.setFrame_(frame) button.setAutoresizingMask_(NSViewMaxXMargin | NSViewMinXMargin | NSViewMaxYMargin | NSViewMinYMargin) button.setTarget_(cb) button.setAction_({"Cancel": "close", "Copy": "copy"}[name]) accessory.addSubview_(button) NSApp.activateIgnoringOtherApps_(True) panel = NSColorPanel.sharedColorPanel() panel.setShowsAlpha_(True) panel.setAccessoryView_(accessory) panel.makeKeyAndOrderFront_(None) NSNotificationCenter.defaultCenter().addObserver_selector_name_object_( cb, "close", NSWindowDidResignKeyNotification, panel) from PyObjCTools import AppHelper AppHelper.runEventLoop() cb.copy()
def applicationDidFinishLaunching_(self, notification): makeMainMenu() closeSplash() NSApp.activateIgnoringOtherApps_(True)
def display_login_window(self): NSApp.arrangeInFront_(None) self.login_window.makeKeyAndOrderFront_(None) NSApp.activateIgnoringOtherApps_(True) self.login_window.makeFirstResponder_(self.username_box)
def run(self): # You could adjust the 1.0 here to how ever many seconds you wanted to wait between checks to terminate self.timer = NSTimer.scheduledTimerWithTimeInterval_target_selector_userInfo_repeats_( 1.0, self, self.checkProcess_, None, True) NSApp.activateIgnoringOtherApps_(True) NSApp.run()
def showWindow(self): self.window().makeKeyAndOrderFront_(self) self.window().setLevel_(NSStatusWindowLevel) # Give the window focus. NSApp.activateIgnoringOtherApps_(YES)
def enable_focus_workaround(*args): NSApp.activateIgnoringOtherApps_(True) client.timeout_add(OSX_FOCUS_WORKAROUND, disable_focus_workaround)