Esempio n. 1
0
    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
Esempio n. 2
0
    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)
Esempio n. 3
0
    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)
Esempio n. 4
0
 def _add_progress_text(self, progress_text, view):
     prog = NSTextField.createLabelWithText_(progress_text)
     prog.setFrameOrigin_(NSPoint(self.BOX_LEFT, self._window_y_offset))
     view.addSubview_(prog)
     prog.alignBottomInSuperview()
     offset = -2
     prog.setFrameOrigin_(NSPoint(prog.frame().origin.x, prog.frame().origin.y - offset))
     return prog
Esempio n. 5
0
 def _create_text_input(self, form_item, val, form_view):
     if form_item.secure:
         control = NSSecureTextField.createNormalSecureTextFieldWithFont_initialValue_placeholder_(self._system_font, val, form_item.placeholder)
     else:
         control = NSTextField.createNormalTextFieldWithFont_initialValue_placeholder_(self._system_font, val, form_item.placeholder)
     setattr(self.current_panel, form_item.attr, val)
     control.setDelegate_(self)
     control_label = NSTextField.createLabelWithText_font_(form_item.label, self._system_font)
     self._form_y_offset -= NSHeight(control.frame())
     control.setFrame_(NSMakeRect(self._center_point, self._form_y_offset, form_item.width, NSHeight(control.frame())))
     control_label.placeRelativeToControl_(control)
     if form_item.sublabel:
         sublabel = NSTextField.createLabelWithText_font_(form_item.sublabel, self._small_system_font)
         self._form_y_offset -= sublabel.frame().size.height
         sublabel.setFrameOrigin_(NSPoint(control.frame().origin.x - LABEL_PADDING - sublabel.frame().size.width, self._form_y_offset))
         form_view.addSubview_(sublabel)
     return (control, control_label)
Esempio n. 6
0
 def _create_choice(self, form_item, val, form_view):
     control_label = NSTextField.createLabelWithText_font_(form_item.label, self._system_font)
     control = NSPopUpButton.createNormalPopUpButtonWithChoices_default_(form_item.choices, val)
     control.setAction_(self.popupAction_)
     self._form_y_offset -= NSHeight(control.frame())
     control.setFrameOrigin_(NSPoint(self._center_point - 3, self._form_y_offset))
     if form_item.width != -1:
         f = control.frame()
         control.setFrameSize_((form_item.width, NSHeight(f)))
     control_label.placeRelativeToControl_(control)
     return (control, control_label)
Esempio n. 7
0
 def _create_date(self, form_item, val, form_view):
     gregorian = NSCalendar.alloc().initWithCalendarIdentifier_(NSGregorianCalendar)
     control_label = NSTextField.createLabelWithText_font_(form_item.label, self._system_font)
     control = NSDatePicker.alloc().initWithFrame_(NSZeroRect)
     control.setCalendar_(gregorian)
     control.setDatePickerElements_(NSYearMonthDatePickerElementFlag)
     control.setDrawsBackground_(YES)
     control.setDateValue_(NSDate.date())
     control.setMinDate_(NSDate.date())
     control.setMaxDate_(NSDate.dateWithString_('2029-12-31 23:59:59 +0600'))
     control.sizeToFit()
     control.setAction_(self.datePickerAction_)
     self._form_y_offset -= NSHeight(control.frame())
     control.setFrameOrigin_(NSPoint(self._center_point, self._form_y_offset))
     control_label.placeRelativeToControl_(control)
     return (control, control_label)
Esempio n. 8
0
    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)
Esempio n. 9
0
    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)
Esempio n. 10
0
 def initWithDropboxApp_initialIgnoreList_takeAction_callback_remote_(self, dropbox_app, initial_ignore_list, take_action, callback, remote):
     self = super(SelectiveSyncView, self).initWithFrame_(NSZeroRect)
     if self is None:
         return
     self._initial_ignore_list = initial_ignore_list
     self._callback = callback
     self._take_action = take_action
     self._remote = remote
     self.setAutoresizingMask_(NSViewWidthSizable | NSViewHeightSizable)
     self._dropbox_app = dropbox_app
     self.initBrowser(self._remote)
     self.initButtons()
     f = NSFont.systemFontOfSize_(NSFont.smallSystemFontSize())
     self.infoLabel = NSTextField.createLabelWithText_font_(selsync_strings.info, f)
     self.addSubview_(self.infoLabel)
     self.reloadInvalidState()
     self.layoutForWidth_(DEFAULT_ADVANCED_WIDTH if self.forest.advanced_view else DEFAULT_SIMPLE_WIDTH)
     return self
Esempio n. 11
0
 def initWithDropboxApp_takeAction_hideText_width_(self, dropbox_app, take_action, hide_text, width):
     self = super(SelectiveSyncLauncher, self).initWithFrame_(NSZeroRect)
     if self is None:
         return
     self._dropbox_app = dropbox_app
     self._action = None
     self._take_action = take_action
     self.current_ignore_list = None
     self._width = width
     self.listingProgress = None
     if not hide_text:
         self.info_label = NSTextField.createLabelWithText_(selsync_strings.prefs_launch_label)
         self.addSubview_(self.info_label)
     else:
         self.info_label = None
     self.launch_button = self.addNormalRoundButtonWithTitle_action_(selsync_strings.prefs_launch_button, self.launch_)
     self.setEnabled_(self._dropbox_app.ui_kit.post_link)
     self.sizeToFit()
     return self
Esempio n. 12
0
    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
Esempio n. 13
0
    def _create_flag_choice(self, form_item, val, form_view):
        control_label = NSTextField.createLabelWithText_font_(form_item.label, self._system_font)
        control = FlagPopUpButton(NSZeroRect, FLAG_WIDTH)
        control.sizeToFit()
        control.setAction_(self.popupAction_)
        self._form_y_offset -= NSHeight(control.frame())
        control.setFrameOrigin_(NSPoint(self._center_point - 3, self._form_y_offset))
        if form_item.width != -1:
            f = control.frame()
            control.setFrameSize_((form_item.width, NSHeight(f)))
        control_label.placeRelativeToControl_(control)
        menu = control.menu()
        for choice in form_item.choices:
            img, name, phonecode = choice
            title = u'%s %s' % (name, phonecode)
            item = NSMenuItem.alloc().initWithTitle_action_keyEquivalent_(title, None, '')
            if img:
                item.setImage_(img)
            menu.addItem_(item)

        control.selectItemAtIndex_(val)
        return (control, control_label)
Esempio n. 14
0
    def layout(self):
        view = self.contentView()
        buttons = []
        right_button = view.addNormalRoundButtonWithTitle_action_(self.right_button_text, self.handleRightButton_)
        right_button.setKeyEquivalent_(ENTER_KEY if not self.right_button_key else self.right_button_key)
        offset = (self.BOTTOM_BORDER - (NSHeight(right_button.frame()) + NSHeight(right_button.insetRect()))) / 2
        right_button.alignRightInSuperview()
        right_button.alignBottomInSuperview(offset)
        buttons.append(right_button)
        self.left_button = None
        if self.left_button_text:
            left_button = view.addNormalRoundButtonWithTitle_action_(self.left_button_text, self.handleLeftButton_)
            left_button.alignLeftInSuperview()
            left_button.alignBottomInSuperview(offset)
            if self.left_button_key:
                left_button.setKeyEquivalent_(self.left_button_key)
            self.left_button = left_button
            buttons.append(left_button)
        elif self.left_label:
            left_label = NSTextField.createLabelWithText_(self.left_label)
            view.addSubview_(left_label)
            left_label.alignLeftInSuperview()
            left_label.alignBottomInSuperview(offset)
        if self.lefter_right_button_text:
            lefter_right_button = view.addNormalRoundButtonWithTitle_action_(self.lefter_right_button_text, self.handleLefterRightButton_)
            if self.lefter_right_button_key:
                lefter_right_button.setKeyEquivalent_(self.lefter_right_button_key)
            lefter_right_button.placeLeftOfButton_(right_button)
            buttons.append(lefter_right_button)
        for button in buttons:
            button.setTarget_(self)

        bg_image = BackgroundImageView(NSRect((0, self.BOTTOM_BORDER), (NSWidth(self.frame()), NSHeight(self.frame()) - self.BOTTOM_BORDER)), self.background, bottom_align=True)
        if (self.background.size().width, self.background.size().height) != self.WINDOW_SIZE:
            bg_image.setImageSize_(NSSize(self.WINDOW_SIZE[0], self.WINDOW_SIZE[1]))
        view.addSubview_(bg_image)
        view.addSubview_(self.inner)
        self.inner.alignBottomInSuperview(self.BOTTOM_BORDER)
Esempio n. 15
0
        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()
Esempio n. 16
0
    def layout(self):
        self._thumbnail = ThumbnailBoxView.alloc().initWithFrame_(NSZeroRect)
        self._thumbnail.setImage_(Images.Box64)
        self._thumbnail.setImageAlignment_(NSImageAlignCenter)
        self._thumbnail.setImageScaling_(NSScaleToFit)
        self._thumbnail.setFrameSize_(self.THUMBNAIL_SIZE)
        self._thumbnail.setFrameOrigin_(self.THUMBNAIL_ORIGIN)
        self._thumbnail.setShadowOffset_(self.SHADOW_OFFSET)
        self._thumbnail.setShadowBlurRadius_(self.SHADOW_BLUR)
        self._thumbnail.setShadowColor_(NSColor.blackColor().colorWithAlphaComponent_(0.3))
        self._label = NSTextField.createLabelWithText_font_('', NSFont.boldSystemFontOfSize_(13))
        self._label.setFrameOrigin_(self.LABEL_ORIGIN)
        self._progress_bar = NSProgressIndicator.alloc().initWithFrame_(NSRect(self.PROGRESS_ORIGIN, self.PROGRESS_SIZE))
        self._progress_bar.setStyle_(NSProgressIndicatorBarStyle)
        self._progress_bar.setIndeterminate_(YES)
        self._progress_bar.setFrameOrigin_(self.PROGRESS_ORIGIN)
        self._estimate = NSTextField.createLabelWithText_font_('', NSFont.systemFontOfSize_(NSFont.smallSystemFontSize()))
        self._estimate.setFrameOrigin_(self.ESTIMATE_ORIGIN)
        self._hide_button = self.addNormalRoundButtonWithTitle_action_(MiscStrings.hide_button, self.handleHideButton_)
        self._hide_button.setKeyEquivalent_(ENTER_KEY)
        self._hide_button.alignRightInSuperview()
        self._hide_button.alignBottomInSuperview()
        self._cancel_button = self.addNormalRoundButtonWithTitle_action_(MiscStrings.cancel_button, self.handleCancelButton_)
        self._cancel_button.placeLeftOfButton_(self._hide_button)
        self.addSubview_(self._thumbnail)
        self.addSubview_(self._label)
        self.addSubview_(self._progress_bar)
        self.addSubview_(self._estimate)

        @message_sender(AppHelper.callAfter)
        def handleMessage(message):
            self._label.setStringValue_(message)
            self._label.sizeToFit()

        @message_sender(AppHelper.callAfter)
        def handleTotalBytes(total_bytes):
            self._progress_bar.setIndeterminate_(YES if total_bytes == 0 else NO)
            self._progress_bar.setMinValue_(0.0)
            self._progress_bar.setMaxValue_(total_bytes)
            self._progress_bar.setDoubleValue_(self.ui.cur_bytes.get())

        @message_sender(AppHelper.callAfter)
        def handleCurBytes(cur_bytes):
            self._progress_bar.setDoubleValue_(cur_bytes)
            self._estimate.setStringValue_(self.ui.get_remaining_message())
            self._estimate.sizeToFit()

        @message_sender(AppHelper.callAfter)
        def handleLastPhoto(path):
            if path:
                if time.time() - self.last_photo_time > self.THUMBNAIL_TIMEOUT:
                    image = NSImage.alloc().initByReferencingFile_(unicode(path))
                    if image.isValid():
                        self._thumbnail.setBorder_(True)
                        self._thumbnail.setImage_(image)
                        self.last_photo_time = time.time()
            else:
                self._thumbnail.setBorder_(False)
                self._thumbnail.setImage_(Images.Box64)

        handleMessage(self.ui.message.get())
        handleTotalBytes(self.ui.total_bytes.get())
        handleCurBytes(self.ui.cur_bytes.get())
        handleLastPhoto(self.ui.last_photo.get())
        self.ui.message.register(handleMessage)
        self.ui.total_bytes.register(handleTotalBytes)
        self.ui.cur_bytes.register(handleCurBytes)
        self.ui.last_photo.register(handleLastPhoto)
Esempio n. 17
0
 def layout(self):
     height = self.BORDER + self.IMAGE_PADDING
     width = self.VIEW_SIZE[0] - self.BORDER * 2
     image = NonBlurryImageView.alloc().initWithFrame_(NSZeroRect)
     image.setImage_(self.image)
     image.setFrameSize_(self.image.size())
     self.addSubview_(image)
     image.setFrameOrigin_((0, height))
     image.centerHorizontallyInSuperview()
     height += NSHeight(image.frame()) + self.HEADER_PADDING
     label1 = NSTextField.createLabelWithText_font_maxWidth_origin_(self.header, NSFont.boldSystemFontOfSize_(self.HEADER_SIZE) if self.BOLD_HEADER else NSFont.systemFontOfSize_(self.HEADER_SIZE), width, NSPoint(0, height))
     self.addSubview_(label1)
     label1.centerHorizontallyInSuperview()
     label1.setTextColor_(self.HEADER_COLOR)
     height += NSHeight(label1.frame()) + self.SUBHEADER_PADDING
     label2 = NSTextField.createLabelWithText_font_maxWidth_origin_(NSAttributedString.boldify(self.subheader, font=NSFont.systemFontOfSize_(self.SUBHEADER_SIZE), bold_font=NSFont.boldSystemFontOfSize_(self.SUBHEADER_SIZE), center=True, line_height=self.SUBHEADER_LINE_HEIGHT), NSFont.systemFontOfSize_(self.SUBHEADER_SIZE), width, NSPoint(0, height))
     self.addSubview_(label2)
     label2.setAlignment_(NSCenterTextAlignment)
     label2.setTextColor_(self.SUBHEADER_COLOR)
     label2.balancedWrapToWidth_(width)
     label2.centerHorizontallyInSuperview()
     if self.checkbox_text:
         checkbox = NSButton.alloc().initWithFrame_(NSZeroRect)
         self.addSubview_(checkbox)
         checkbox.setButtonType_(NSSwitchButton)
         checkbox.setAttributedTitle_(NSAttributedString.boldify(self.checkbox_text, font=NSFont.systemFontOfSize_(self.CHECKBOX_SIZE), bold_font=NSFont.boldSystemFontOfSize_(self.CHECKBOX_SIZE)))
         checkbox.setTextColor_(Colors.camera_font)
         checkbox.sizeToFit()
         if NSWidth(checkbox.frame()) > width:
             checkbox.setAttributedTitle_(CameraStrings.splash_always_import_no_name)
             checkbox.setTextColor_(Colors.camera_font)
             checkbox.sizeToFit()
         checkbox.setState_(True)
         checkbox.centerHorizontallyInSuperview()
         checkbox.alignBottomInSuperview(self.BORDER - checkbox.flippedBaselineOffset())
         self.checkbox = checkbox
     else:
         self.checkbox = None
     height += NSHeight(label2.frame()) + self.FINE_PRINT_PADDING
     if self.fine_print:
         fine_print = NSTextField.createLabelWithText_font_maxWidth_origin_(self.fine_print, NSFont.systemFontOfSize_(self.FINE_PRINT_SIZE), width, NSPoint(0, height))
         self.addSubview_(fine_print)
         fine_print.setAlignment_(NSCenterTextAlignment)
         fine_print.setTextColor_(Colors.fine_print)
         fine_print.balancedWrapToWidth_(width)
         fine_print.centerHorizontallyInSuperview()
         self.fine_print_label = fine_print
     else:
         self.fine_print_label = None
     self.combo = None
     if self.choice_selector:
         subview = NSView.alloc().initWithFrame_(NSZeroRect)
         combo_descriptor = NSTextField.createLabelWithText_(NSAttributedString.boldify(self.choice_selector.text, font=NSFont.systemFontOfSize_(NSRegularControlSize), bold_font=NSFont.boldSystemFontOfSize_(NSRegularControlSize)))
         combo_descriptor.setTextColor_(self.SUBHEADER_COLOR)
         subview.addSubview_(combo_descriptor)
         combo = NSPopUpButton.createNormalPopUpButtonWithChoices_default_(self.choice_selector.selections, self.choice_selector.default_index)
         combo.sizeToFit()
         subview.addSubview_(combo)
         descriptor_frame = combo_descriptor.frame()
         half = combo.frame().size.height / 2.0
         descriptor_half = descriptor_frame.size.height / 2.0
         combo_descriptor.setFrameOrigin_(NSPoint(descriptor_frame.origin.x, half - descriptor_half + 2.0))
         combo.setFrameOrigin_(NSPoint(descriptor_frame.origin.x + descriptor_frame.size.width, 0))
         subview.setFrameSize_((combo.frame().size.width + descriptor_frame.size.width, combo.frame().size.height))
         self.addSubview_(subview)
         subview.centerHorizontallyInSuperview()
         subview.alignBottomInSuperview(CONTENT_BORDER + self.CHOICE_SELECTOR_PADDING)
         self.combo = combo
Esempio n. 18
0
 def textDidChange_(self, arg):
     #print("PyGUI_NSTextField.textDidChange_")
     NSTextField.textDidChange_(self, arg)
     self.pygui_component.do_text_changed_action()
Esempio n. 19
0
 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)
Esempio n. 20
0
 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)
Esempio n. 21
0
    def _setupContentView(self):
        # ------------------------------------------ #
        #                   Table View               #
        # ------------------------------------------ #
        rect = NSMakeRect(0, 0, self.WIDTH, self.HEIGHT)
        containerView = NSView.alloc().initWithFrame_(rect)

        # Startup btn
        height = 20
        margin = 20
        width = self.WIDTH - 2 * margin
        self.startupBtn = NSButton.buttonWithTitle_target_action_(
            "Run safetyapp on startup", self, "startupDidChanged:")
        self.startupBtn.setButtonType_(NSButtonTypeSwitch)
        self.startupBtn.setFrame_(
            NSMakeRect(margin, self.HEIGHT - 2 * height, width, height))
        self.startupBtn.setState_(self.data["startup"])
        containerView.addSubview_(self.startupBtn)

        # API Key settings
        titleLabel = NSTextField.labelWithString_("API Key")
        titleLabel.setTextColor_(NSColor.blackColor())
        rect = NSMakeRect(
            self.startupBtn.frame().origin.x,
            self.startupBtn.frame().origin.y -
            self.startupBtn.frame().size.height - height, width, height)
        titleLabel.setFrame_(rect)
        titleLabel.setFont_(NSFont.boldSystemFontOfSize_(14))
        containerView.addSubview_(titleLabel)

        # API Key Sub-label
        titleSubLabel = NSTextField.labelWithString_(
            "Lorem lpsum dolor sit amet")
        titleSubLabel.setTextColor_(NSColor.blackColor())
        rect = NSMakeRect(
            titleLabel.frame().origin.x,
            titleLabel.frame().origin.y - titleLabel.frame().size.height -
            height / 2, width, height)
        titleSubLabel.setFrame_(rect)
        titleSubLabel.setFont_(NSFont.systemFontOfSize_(14))
        containerView.addSubview_(titleSubLabel)

        # API Key text field
        self.apiTextField = NSTextField.textFieldWithString_("")
        rect = NSMakeRect(
            titleSubLabel.frame().origin.x,
            titleSubLabel.frame().origin.y -
            titleSubLabel.frame().size.height - height / 2, width,
            1.2 * height)
        self.apiTextField.setFrame_(rect)
        self.apiTextField.setFocusRingType_(NSFocusRingTypeNone)
        self.apiTextField.setTitleWithMnemonic_(self.data["api_key"])
        self.apiTextField.setEditable_(True)
        containerView.addSubview_(self.apiTextField)
        self.window().makeFirstResponder_(self.apiTextField)

        # Table title
        tableTitleLabel = NSTextField.labelWithString_("Directories")
        tableTitleLabel.setTextColor_(NSColor.blackColor())
        rect = NSMakeRect(
            self.apiTextField.frame().origin.x,
            self.apiTextField.frame().origin.y -
            self.apiTextField.frame().size.height - height, width, height)
        tableTitleLabel.setFrame_(rect)
        tableTitleLabel.setFont_(NSFont.boldSystemFontOfSize_(14))
        containerView.addSubview_(tableTitleLabel)

        # Table sub-title
        tableSubTitleLabel = NSTextField.labelWithString_(
            "Lorem lpsum dolor sit amet")
        tableSubTitleLabel.setTextColor_(NSColor.blackColor())
        rect = NSMakeRect(
            tableTitleLabel.frame().origin.x,
            tableTitleLabel.frame().origin.y -
            tableTitleLabel.frame().size.height - height / 2, width, height)
        tableSubTitleLabel.setFrame_(rect)
        tableSubTitleLabel.setFont_(NSFont.systemFontOfSize_(14))
        containerView.addSubview_(tableSubTitleLabel)

        # ------------------------------------------ #
        #               Toolbar button               #
        # ------------------------------------------ #
        rect = NSMakeRect(20, 20, 67, 21)
        segControl = NSSegmentedControl.alloc().initWithFrame_(rect)
        segControl.setSegmentCount_(2)
        segControl.setSegmentStyle_(NSSegmentStyleSmallSquare)
        segControl.setWidth_forSegment_(32, 0)
        segControl.setWidth_forSegment_(32, 1)
        segControl.setImage_forSegment_(
            NSImage.imageNamed_(NSImageNameAddTemplate), 0)
        segControl.setImage_forSegment_(
            NSImage.imageNamed_(NSImageNameRemoveTemplate), 1)
        segControl.setTarget_(self)
        segControl.setAction_("segControlDidClicked:")
        containerView.addSubview_(segControl)

        rect = NSMakeRect(86, 21,
                          self.WIDTH - 2 * margin - rect.size.width + 1, 21)
        toolbar = NSButton.alloc().initWithFrame_(rect)
        toolbar.setTitle_("")
        toolbar.setRefusesFirstResponder_(True)
        toolbar.setBezelStyle_(NSBezelStyleSmallSquare)
        containerView.addSubview_(toolbar)

        height = tableSubTitleLabel.frame().origin.y - segControl.frame(
        ).origin.y - margin - segControl.frame(
        ).size.height + 1 + tableSubTitleLabel.frame().size.height / 2
        rect = NSMakeRect(
            tableSubTitleLabel.frame().origin.x,
            tableSubTitleLabel.frame().origin.y -
            tableSubTitleLabel.frame().size.height / 2 - height, width, height)
        scrollView = NSScrollView.alloc().initWithFrame_(rect)
        scrollView.setBorderType_(NSBezelBorder)

        self.tableView = NSTableView.alloc().initWithFrame_(
            scrollView.bounds())
        self.tableView.setDataSource_(self)
        self.tableView.setDelegate_(self)
        self.tableView.setFocusRingType_(NSFocusRingTypeNone)

        # Path column
        pathCol = NSTableColumn.alloc().initWithIdentifier_(
            self.PATH_COL_IDENTIFIER)
        pathCol.setTitle_("Directory")  # <-- Table view directory column title
        pathCol.setWidth_(self.WIDTH * 0.8)
        textCell = NSTextFieldCell.alloc().init()
        textCell.setEditable_(True)
        textCell.setTarget_(self)
        pathCol.setDataCell_(textCell)

        # Enable column
        enableCol = NSTableColumn.alloc().initWithIdentifier_(
            self.ENALBE_COL_IDENTIFIER)
        enableCol.setTitle_("Enable?")  # <-- Enable column title
        enableCol.setWidth_(self.WIDTH * 0.2)
        cell = NSButtonCell.alloc().init()
        cell.setButtonType_(NSButtonTypeSwitch)
        cell.setTitle_("")
        cell.setTarget_(self)
        enableCol.setDataCell_(cell)

        self.tableView.addTableColumn_(pathCol)
        self.tableView.addTableColumn_(enableCol)

        scrollView.setDocumentView_(self.tableView)
        scrollView.setHasVerticalScroller_(True)
        containerView.addSubview_(scrollView)
        self.window().setContentView_(containerView)