def __init__(self, message='', title='', default_text='', ok=None, cancel=None, dimensions=(320, 160), secure=False): message = unicode(message) title = unicode(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) # informational style self._textfield = NSTextField.alloc().initWithFrame_( NSMakeRect(0, 0, *dimensions)) if not secure: self._textfield = NSTextField.alloc().initWithFrame_( NSMakeRect(0, 0, *dimensions)) else: self._textfield = NSSecureTextField.alloc().initWithFrame_( NSMakeRect(0, 0, *dimensions)) self._textfield.setSelectable_(True) self._alert.setAccessoryView_(self._textfield) self.default_text = default_text
def __init__(self): ''' initializes an alert with custom view containing username and password fields with a save to keychain checkbox''' # Create an dialog with ok and cancel buttons self.alert = NSAlert.alloc().init() self.alert.setMessageText_('Please enter your username and password!') self.alert.addButtonWithTitle_('Ok') self.alert.addButtonWithTitle_('Cancel') # create the view for username and password fields accessory_view = NSView.alloc().initWithFrame_( NSMakeRect(0, 114, 250, 110)) # setup username field and label self.username_field = NSTextField.alloc().initWithFrame_( NSMakeRect(0, 70, 250, 22)) username_label = NSTextField.alloc().initWithFrame_( NSMakeRect(0, 94, 250, 20)) username_label.setStringValue_('Username:'******'Password:'******'Save to Keychain') self.keychain_checkbox.cell().setBordered_(False) self.keychain_checkbox.cell().setEnabled_(True) self.keychain_checkbox.cell().setState_(True) # add various objects as subviews accessory_view.addSubview_(self.keychain_checkbox) accessory_view.addSubview_(username_label) accessory_view.addSubview_(self.username_field) accessory_view.addSubview_(password_label) accessory_view.addSubview_(self.password_field) # add custom view to alert dialog self.alert.setAccessoryView_(accessory_view)
def __init__(self): ''' initializes an alert with custom view containing username and password fields with a save to keychain checkbox''' # Create an dialog with ok and cancel buttons self.alert = NSAlert.alloc().init() self.alert.setMessageText_('Please enter your username and password!') self.alert.addButtonWithTitle_('Ok') self.alert.addButtonWithTitle_('Cancel') # create the view for username and password fields accessory_view = NSView.alloc().initWithFrame_(NSMakeRect(0, 114, 250, 110)) # setup username field and label self.username_field = NSTextField.alloc().initWithFrame_(NSMakeRect(0, 70, 250, 22)) username_label = NSTextField.alloc().initWithFrame_(NSMakeRect(0, 94, 250, 20)) username_label.setStringValue_('Username:'******'Password:'******'Save to Keychain') self.keychain_checkbox.cell().setBordered_(False) self.keychain_checkbox.cell().setEnabled_(True) self.keychain_checkbox.cell().setState_(True) # add various objects as subviews accessory_view.addSubview_(self.keychain_checkbox) accessory_view.addSubview_(username_label) accessory_view.addSubview_(self.username_field) accessory_view.addSubview_(password_label) accessory_view.addSubview_(self.password_field) # add custom view to alert dialog self.alert.setAccessoryView_(accessory_view)
def __init__(self, message, title='', default_text='', ok=None, cancel=False, dimensions=(320, 160)): message = str(message) title = str(title) self._default_text = default_text self._cancel = bool(cancel) self._icon = None self._alert = NSAlert.alertWithMessageText_defaultButton_alternateButton_otherButton_informativeTextWithFormat_( title, ok, 'Cancel' if cancel else None, None, message) self._alert.setAlertStyle_(0) # informational style self._textfield = NSTextField.alloc().initWithFrame_(NSMakeRect(0, 0, *dimensions)) self._textfield.setSelectable_(True) if default_text: self._textfield.setStringValue_(default_text) self._alert.setAccessoryView_(self._textfield)
def __init__(self, message='', title='', default_text='', ok=None, cancel=None, dimensions=(320, 160)): message = unicode(message) title = unicode(title) self._cancel = bool(cancel) self._icon = None _require_string_or_none(ok) if not isinstance(cancel, basestring): cancel = 'Cancel' if cancel else None self._alert = NSAlert.alertWithMessageText_defaultButton_alternateButton_otherButton_informativeTextWithFormat_( title, ok, cancel, None, message) self._alert.setAlertStyle_(0) # informational style self._textfield = NSTextField.alloc().initWithFrame_(NSMakeRect(0, 0, *dimensions)) self._textfield.setSelectable_(True) self._alert.setAccessoryView_(self._textfield) self.default_text = default_text
def __init__(self, title, message): AlertDialog.__init__(self, title, message) self.input = NSTextField.alloc().initWithFrame_(NSMakeRect(0, 0, 200, 24)) self.alert.setAccessoryView_(self.input)
def __init__(self, title, message): AlertDialog.__init__(self, title, message) self.input = NSTextField.alloc().initWithFrame_( NSMakeRect(0, 0, 200, 24)) self.alert.setAccessoryView_(self.input)
def _run_progress(comm_queue, message_txt, title_txt, use_bar): from AppKit import NSBundle, NSApplication, NSWindow, NSApp, NSScreen, NSMakeRect, NSMakePoint, NSProgressIndicator, NSWindow, \ NSTitledWindowMask, NSBackingStoreBuffered, NSProgressIndicatorPreferredAquaThickness, NSTextField, \ NSStatusWindowLevel, NSProgressIndicatorBarStyle, NSProgressIndicatorSpinningStyle, NSObject, \ NSApplicationDefined, NSEvent, NSTimer, NSSmallControlSize class MainController(NSObject): timer = None def kickRunLoop(self): event = NSEvent.otherEventWithType_location_modifierFlags_timestamp_windowNumber_context_subtype_data1_data2_(NSApplicationDefined, \ NSMakePoint(0,0), 0, 0.0, 0, None, 0, 0, 0) NSApp.postEvent_atStart_(event, True) def checkProcess_(self, timer): if not comm_queue.empty(): # We Get Signal, Take Off Every Zig - er, time to shut down this forked process # Clear the queue while not comm_queue.empty(): ignore = comm_queue.get_nowait() NSApp.stop_(None) # After you stop the runloop, the app has to receive another event to determine the runloop stopped ... self.kickRunLoop() 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() # Evil hack to make this process not show in the Dock bundle = NSBundle.mainBundle() info = bundle.localizedInfoDictionary() or bundle.infoDictionary() info['LSUIElement'] = '1' # Create our NSApplication instance app = NSApplication.sharedApplication() # Create a window, size doesn't matter now, we're going to resize it in the end window = NSWindow.alloc( ).initWithContentRect_styleMask_backing_defer_( NSMakeRect(0, 0, 500, 500), NSTitledWindowMask, NSBackingStoreBuffered, True) # Build the window from the bottom up # Create the progress indicator, placement doesn't matter, will be set later progress = NSProgressIndicator.alloc().init() if use_bar: progress.setStyle_(NSProgressIndicatorBarStyle) else: progress.setStyle_(NSProgressIndicatorSpinningStyle) progress.setUsesThreadedAnimation_(True) progress.setIndeterminate_(True) progress.startAnimation_(None) # Create the text, which will define the width of everything else - size doesn't matter at first... message = NSTextField.alloc().initWithFrame_( NSMakeRect(20, 50, 20, 20)) message.setStringValue_(message_txt) message.setBezeled_(False) message.setDrawsBackground_(False) message.setEditable_(False) message.setSelectable_(False) # Resize the field to fit the text message.sizeToFit() window.contentView().addSubview_(message) # Now we can calculate the width # Fix the window geometry # A default NSAlert is 420x150, let's aim for something with similar geometry! frame = NSMakeRect(0, 0, max(420, message.frame().size.width + 40), 110) screen = NSScreen.mainScreen() screenFrame = screen.frame() # Fix the progressbar geometry if use_bar: # Set the bar to stretch the width of the dialog progress.setFrame_( NSMakeRect(20, 20, frame.size.width - 40, NSProgressIndicatorPreferredAquaThickness)) else: # Center the spinning wheel at the bottom progress.setControlSize_(NSSmallControlSize) progress.setFrame_( NSMakeRect((frame.size.width / 2) - 8, 20, 16, 16)) window.contentView().addSubview_(progress) # Pleasant centering, 2/3rds of the way up, in the middle highCenterPoint = NSMakePoint( (screenFrame.size.width / 2) - (frame.size.width / 2), 1.3 * (screenFrame.size.height / 2) - (frame.size.height / 2)) window.setFrame_display_animate_(frame, True, False) window.setFrameOrigin_(highCenterPoint) window.makeKeyAndOrderFront_(None) window.setLevel_(NSStatusWindowLevel) window.setTitle_(title_txt) window.display() controller = MainController.alloc().init() controller.run()