Esempio n. 1
0
    def drawRect_(self, rect):
        VerticalBoxView.drawRect_(self, rect)

        if self.alternateRows:
            i = 0
            NSColor.colorWithCalibratedRed_green_blue_alpha_(237/256.0, 243/256.0, 254/256.0, 1.0).set()
            for v in self.subviews():
                if i % 2 == 1:
                    NSRectFill(v.frame())
                i += 1

        if self.selection != -1 and self.selection < self.subviews().count():
            if self.window().isKeyWindow():
                NSColor.alternateSelectedControlColor().set()
            else:
                NSColor.lightGrayColor().set()
            NSRectFill(self.subviews()[self.selection].frame())
Esempio n. 2
0
    def drawRect_(self, rect):
        VerticalBoxView.drawRect_(self, rect)

        if self.alternateRows:
            i = 0
            NSColor.colorWithCalibratedRed_green_blue_alpha_(
                237 / 256.0, 243 / 256.0, 254 / 256.0, 1.0).set()
            for v in self.subviews():
                if i % 2 == 1:
                    NSRectFill(v.frame())
                i += 1

        if self.selection != -1 and self.selection < self.subviews().count():
            if self.window().isKeyWindow():
                NSColor.alternateSelectedControlColor().set()
            else:
                NSColor.lightGrayColor().set()
            NSRectFill(self.subviews()[self.selection].frame())
Esempio n. 3
0
 def minimumHeight(self):
     return max(
         VerticalBoxView.minimumHeight(self),
         1)  #NSHeight(self.enclosingScrollView().documentVisibleRect()))
Esempio n. 4
0
 def dealloc(self):
     NSNotificationCenter.defaultCenter().removeObserver_(self)
     VerticalBoxView.dealloc(self)
Esempio n. 5
0
 def minimumHeight(self):
     return max(VerticalBoxView.minimumHeight(self), 1)#NSHeight(self.enclosingScrollView().documentVisibleRect()))
Esempio n. 6
0
 def dealloc(self):
     NSNotificationCenter.defaultCenter().removeObserver_(self)
     VerticalBoxView.dealloc(self)
    def createUIForSection(self,
                           object,
                           frame,
                           section_name,
                           section,
                           forAccount=False):
        section_object = getattr(object, section_name)

        section_view = NSScrollView.alloc().initWithFrame_(frame)
        section_view.setDrawsBackground_(False)
        section_view.setAutohidesScrollers_(True)
        # TODO: we will need a scrollbar if the number of settings cause the box to become to high -adi
        section_view.setHasVerticalScroller_(False)
        section_view.setAutoresizingMask_(NSViewWidthSizable
                                          | NSViewHeightSizable)

        settings_box_view = VerticalBoxView.alloc().initWithFrame_(frame)
        settings_box_view.setAutoresizingMask_(NSViewWidthSizable
                                               | NSViewHeightSizable)
        settings_box_view.setSpacing_(8)
        settings_box_view.setBorderWidth_(8)

        section_view.setDocumentView_(settings_box_view)

        unordered_options = [
            opt for opt in dir(section)
            if isinstance(getattr(section, opt, None), Setting)
        ]
        assert not [
            opt for opt in dir(section)
            if isinstance(getattr(section, opt, None), SettingsGroupMeta)
        ]
        try:
            options = AccountSettingsOrder[
                section_name] if forAccount else GeneralSettingsOrder[
                    section_name]
            remaining_options = [
                opt for opt in unordered_options if opt not in options
            ]
            options.extend(remaining_options)
        except KeyError:
            options = unordered_options

        if not ENABLE_PRESENCE and not ENABLE_DIALOG:
            PreferenceOptionTypes['sip.publish_interval'] = HiddenOption

        if NSApp.delegate().applicationName == 'Blink Lite':
            PreferenceOptionTypes['web_alert.alert_url'] = HiddenOption

        for option_name in options:
            if section_name == 'auth' and option_name == 'password':
                continue
            option = getattr(section, option_name, None)
            controlFactory = PreferenceOptionTypes.get(
                section_name + "." + option_name, None)
            if not controlFactory:
                if forAccount:
                    controlFactory = PreferenceOptionTypes.get(
                        option.type.__name__ + ":account", None)
                else:
                    controlFactory = None
            if not controlFactory:
                controlFactory = PreferenceOptionTypes.get(
                    option.type.__name__, None)
            if not controlFactory:
                print "Error: Option type %s is not supported (while reading %s)" % (
                    option.type, option_name)
                controlFactory = PreferenceOptionTypes[str.__name__]
            if controlFactory is HiddenOption:
                continue

            description_key = '%s.%s' % (section_name, option_name)

            try:
                description = SettingDescription[description_key]
            except KeyError:
                description = None

            control = controlFactory(section_object, option_name, option,
                                     description)

            try:
                tooltip = ToolTips[description_key]
                control.setTooltip(tooltip)
            except KeyError:
                pass

            try:
                placeholder = Placeholders[description_key]
                control.setPlaceHolder(placeholder)
            except KeyError:
                pass

            self.settingViews[section_name + "." + option_name] = control

            settings_box_view.addSubview_(control)

            control.delegate = self
            control.owner = object
            control.restore()

        return section_view
    def createUIForSection(self, object, frame, section_name, section, forAccount=False):
        section_object = getattr(object, section_name)

        section_view = NSScrollView.alloc().initWithFrame_(frame)
        section_view.setDrawsBackground_(False)
        section_view.setAutohidesScrollers_(True)
        # TODO: we will need a scrollbar if the number of settings cause the box to become to high -adi
        section_view.setHasVerticalScroller_(False)
        section_view.setAutoresizingMask_(NSViewWidthSizable|NSViewHeightSizable)

        settings_box_view = VerticalBoxView.alloc().initWithFrame_(frame)
        settings_box_view.setAutoresizingMask_(NSViewWidthSizable|NSViewHeightSizable)
        settings_box_view.setSpacing_(8)
        settings_box_view.setBorderWidth_(8)

        section_view.setDocumentView_(settings_box_view)

        unordered_options = [opt for opt in dir(section) if isinstance(getattr(section, opt, None), Setting)]
        assert not [opt for opt in dir(section) if isinstance(getattr(section, opt, None), SettingsGroupMeta)]
        try:
            options = AccountSettingsOrder[section_name] if forAccount else GeneralSettingsOrder[section_name]
            remaining_options = [opt for opt in unordered_options if opt not in options]
            options.extend(remaining_options)
        except KeyError:
            options = unordered_options

        if not ENABLE_PRESENCE and not ENABLE_DIALOG:
            PreferenceOptionTypes['sip.publish_interval'] = HiddenOption

        if NSApp.delegate().applicationName == 'Blink Lite':
            PreferenceOptionTypes['web_alert.alert_url'] = HiddenOption

        for option_name in options:
            if section_name == 'auth' and option_name == 'password':
                continue
            option = getattr(section, option_name, None)
            controlFactory = PreferenceOptionTypes.get(section_name+"."+option_name, None)
            if not controlFactory:
                if forAccount:
                    controlFactory = PreferenceOptionTypes.get(option.type.__name__+":account", None)
                else:
                    controlFactory = None
            if not controlFactory:
                controlFactory = PreferenceOptionTypes.get(option.type.__name__, None)
            if not controlFactory:
                print "Error: Option type %s is not supported (while reading %s)" % (option.type, option_name)
                controlFactory = PreferenceOptionTypes[str.__name__]
            if controlFactory is HiddenOption:
                continue

            description_key = '%s.%s' % (section_name, option_name)

            try:
                description = SettingDescription[description_key]
            except KeyError:
                description = None

            control = controlFactory(section_object, option_name, option, description)

            try:
                tooltip = ToolTips[description_key]
                control.setTooltip(tooltip)
            except KeyError:
                pass

            try:
                placeholder = Placeholders[description_key]
                control.setPlaceHolder(placeholder)
            except KeyError:
                pass

            self.settingViews[section_name+"."+option_name] = control

            settings_box_view.addSubview_(control)

            control.delegate = self
            control.owner = object
            control.restore()

        return section_view