def test_removeObserver(self):
     center = NotificationCenter()
     observable = _TestObservable(center, "Observable")
     observer = NotificationTestObserver()
     center.addObserver(observer, "notificationCallback", "A", observable)
     center.removeObserver(observer, "A", observable)
     self.assertFalse(center.hasObserver(observer, "A", observable))
 def test_removeObserver_no_notification_no_observable(self):
     center = NotificationCenter()
     _TestObservable(center, "Observable")
     observer = NotificationTestObserver()
     center.addObserver(observer, "notificationCallback", None, None)
     center.removeObserver(observer, None, None)
     self.assertFalse(center.hasObserver(observer, None, None))
 def test_removeObserver_no_notification_no_observable(self):
     center = NotificationCenter()
     _TestObservable(center, "Observable")
     observer = NotificationTestObserver()
     center.addObserver(observer, "notificationCallback", None, None)
     center.removeObserver(observer, None, None)
     self.assertFalse(center.hasObserver(observer, None, None))
 def test_removeObserver(self):
     center = NotificationCenter()
     observable = _TestObservable(center, "Observable")
     observer = NotificationTestObserver()
     center.addObserver(observer, "notificationCallback", "A", observable)
     center.removeObserver(observer, "A", observable)
     self.assertFalse(center.hasObserver(observer, "A", observable))
Exemple #5
0
 def test_removeObserver_identifier(self):
     center = NotificationCenter()
     observable = _TestObservable(center, "Observable")
     observer = NotificationTestObserver()
     center.addObserver(observer,
                        "notificationCallback",
                        "A",
                        observable,
                        identifier="identifier1")
     center.addObserver(observer,
                        "notificationCallback",
                        "B",
                        observable,
                        identifier="identifier2")
     center.removeObserver(observer, "A", observable)
     center.removeObserver(observer, "B", observable)
     expected = []
     self.assertEqual(center.findObservations(), expected)
Exemple #6
0
 def test_removeObserver_allNotifications(self):
     center = NotificationCenter()
     observable1 = _TestObservable(center, "Observable1")
     observable2 = _TestObservable(center, "Observable2")
     observer1 = NotificationTestObserver()
     observer2 = NotificationTestObserver()
     center.addObserver(observer1, "notificationCallback", "A", observable1)
     center.addObserver(observer1, "notificationCallback", "B", observable1)
     center.addObserver(observer2, "notificationCallback", "A", observable1)
     center.addObserver(observer2, "notificationCallback", "B", observable1)
     center.addObserver(observer1, "notificationCallback", "A", observable2)
     center.addObserver(observer1, "notificationCallback", "B", observable2)
     center.addObserver(observer2, "notificationCallback", "A", observable2)
     center.addObserver(observer2, "notificationCallback", "B", observable2)
     center.removeObserver(observer1, "all", observable1)
     self.assertFalse(center.hasObserver(observer1, "A", observable1))
     self.assertFalse(center.hasObserver(observer1, "B", observable1))
     self.assertTrue(center.hasObserver(observer1, "A", observable2))
     self.assertTrue(center.hasObserver(observer1, "B", observable2))
     self.assertTrue(center.hasObserver(observer2, "A", observable1))
     self.assertTrue(center.hasObserver(observer2, "B", observable1))
     self.assertTrue(center.hasObserver(observer2, "A", observable2))
     self.assertTrue(center.hasObserver(observer2, "B", observable2))
Exemple #7
0
class PyREPLSettings(object):

    def __init__(self):
        self._dispatcher = NotificationCenter()

    def __repr__(self):
        return "<Editor Settings Manager. Type \"settings.help\" for documentation.>"

    def _get_help(self):
        # LOL. This is probably very illegal.
        print settingsManagerDoc

    help = property(_get_help)

    # Notifications

    def addObserver(self, obj, methodName, notification="PyREPL.SettingsChanged"):
        self._dispatcher.addObserver(obj, methodName, notification=notification, observable=self)

    def removeObserver(self, obj, notification="PyREPL.SettingsChanged"):
        self._dispatcher.removeObserver(obj, notification, self)

    def postNotification(self, notification="PyREPL.SettingsChanged", data=None):
        self._dispatcher.postNotification(notification, self, data)

    # Properties

    windowWidth = settingsProperty("windowWidth", settingsWindowSizeValidator)
    windowHeight = settingsProperty("windowHeight", settingsWindowSizeValidator)
    fontName = settingsProperty("fontName", settingsStringValidator)
    fontSize = settingsProperty("fontSize", settingsPositiveNumberValidator)
    colorCode = settingsProperty("colorCode", settingsColorValidator)
    colorStdout = settingsProperty("colorStdout", settingsColorValidator)
    colorStderr = settingsProperty("colorStderr", settingsColorValidator)
    colorBackground = settingsProperty("colorBackground", settingsColorValidator)
    bannerGreeting = settingsProperty("bannerGreeting", settingsStringValidator)
    startupCode = settingsProperty("startupCode", settingsStringValidator)
    tabString = settingsProperty("tabString", settingsStringValidator)
    showInvisibleCharacters = settingsProperty("showInvisibleCharacters", settingsBoolValidator)

    def editorItems(self):
        d = dict(
            fontName=self.fontName,
            fontSize=self.fontSize,
            colorCode=self.colorCode,
            colorStdout=self.colorStdout,
            colorStderr=self.colorStderr,
            colorBackground=self.colorBackground,
            tabString=self.tabString,
            showInvisibleCharacters=self.showInvisibleCharacters
        )
        return d.items()

    # Fonts

    def _get_availableFonts(self):
        manager = NSFontManager.sharedFontManager()
        for name in manager.availableFonts():
            font = NSFont.fontWithName_size_(name, 10)
            if font.isFixedPitch():
                print name

    availableFonts = property(_get_availableFonts)

    # Startup Code

    def editStartupCode(self):
        self.postNotification(notification="PyREPL.ShowStartupCodeEditor")

    # Themes

    def loadTheme(self, name):
        userThemes = getDefaultValue("userThemes")
        if name in userThemes:
            theme = userThemes[name]
        elif name in defaultThemes:
            theme = defaultThemes[name]
        else:
            raise PyREPLSettingsError("No theme named %r." % name)
        self.colorCode = theme["colorCode"]
        self.colorStdout = theme["colorStdout"]
        self.colorStderr = theme["colorStderr"]
        self.colorBackground = theme["colorBackground"]

    def saveTheme(self, name):
        if not settingsStringValidator(name):
            raise PyREPLSettingsError("Theme names must be strings.")
        theme = dict(
            colorCode=self.colorCode,
            colorStderr=self.colorStderr,
            colorStdout=self.colorStdout,
            colorBackground=self.colorBackground
        )
        userThemes = getDefaultValue("userThemes")
        userThemes[name] = theme
        setDefaultValue("userThemes", userThemes)
Exemple #8
0
class PyREPLSettings(object):
    def __init__(self):
        self._dispatcher = NotificationCenter()

    def __repr__(self):
        return "<Editor Settings Manager. Type \"settings.help\" for documentation.>"

    def _get_help(self):
        # LOL. This is probably very illegal.
        print(settingsManagerDoc)

    help = property(_get_help)

    # Notifications

    def addObserver(self,
                    obj,
                    methodName,
                    notification="PyREPL.SettingsChanged"):
        self._dispatcher.addObserver(obj,
                                     methodName,
                                     notification=notification,
                                     observable=self)

    def removeObserver(self, obj, notification="PyREPL.SettingsChanged"):
        self._dispatcher.removeObserver(obj, notification, self)

    def postNotification(self,
                         notification="PyREPL.SettingsChanged",
                         data=None):
        self._dispatcher.postNotification(notification, self, data)

    # Properties

    windowWidth = settingsProperty("windowWidth", settingsWindowSizeValidator)
    windowHeight = settingsProperty("windowHeight",
                                    settingsWindowSizeValidator)
    fontName = settingsProperty("fontName", settingsStringValidator)
    fontSize = settingsProperty("fontSize", settingsPositiveNumberValidator)
    colorCode = settingsProperty("colorCode", settingsColorValidator)
    colorStdout = settingsProperty("colorStdout", settingsColorValidator)
    colorStderr = settingsProperty("colorStderr", settingsColorValidator)
    colorBackground = settingsProperty("colorBackground",
                                       settingsColorValidator)
    bannerGreeting = settingsProperty("bannerGreeting",
                                      settingsStringValidator)
    startupCode = settingsProperty("startupCode", settingsStringValidator)
    tabString = settingsProperty("tabString", settingsStringValidator)
    showInvisibleCharacters = settingsProperty("showInvisibleCharacters",
                                               settingsBoolValidator)

    def editorItems(self):
        d = dict(fontName=self.fontName,
                 fontSize=self.fontSize,
                 colorCode=self.colorCode,
                 colorStdout=self.colorStdout,
                 colorStderr=self.colorStderr,
                 colorBackground=self.colorBackground,
                 tabString=self.tabString,
                 showInvisibleCharacters=self.showInvisibleCharacters)
        return d.items()

    # Fonts

    def _get_availableFonts(self):
        manager = NSFontManager.sharedFontManager()
        for name in manager.availableFonts():
            font = NSFont.fontWithName_size_(name, 10)
            if font.isFixedPitch():
                print(name)

    availableFonts = property(_get_availableFonts)

    # Startup Code

    def editStartupCode(self):
        self.postNotification(notification="PyREPL.ShowStartupCodeEditor")

    # Themes

    def loadTheme(self, name):
        userThemes = getDefaultValue("userThemes")
        if name in userThemes:
            theme = userThemes[name]
        elif name in defaultThemes:
            theme = defaultThemes[name]
        else:
            raise PyREPLSettingsError("No theme named %r." % name)
        self.colorCode = theme["colorCode"]
        self.colorStdout = theme["colorStdout"]
        self.colorStderr = theme["colorStderr"]
        self.colorBackground = theme["colorBackground"]

    def saveTheme(self, name):
        if not settingsStringValidator(name):
            raise PyREPLSettingsError("Theme names must be strings.")
        theme = dict(colorCode=self.colorCode,
                     colorStderr=self.colorStderr,
                     colorStdout=self.colorStdout,
                     colorBackground=self.colorBackground)
        userThemes = getDefaultValue("userThemes")
        userThemes[name] = theme
        setDefaultValue("userThemes", userThemes)

    def exportSettings(self):
        exportPath = vanilla.dialogs.putFile(
            messageText="Export RoboREPL Settings",
            fileName="Settings.roboREPLSettings")

        if exportPath:
            d = dict(windowWidth=int(self.windowWidth),
                     windowHeight=int(self.windowHeight),
                     fontName=str(self.fontName),
                     fontSize=int(self.fontSize),
                     colorCode=tuple(self.colorCode),
                     colorStdout=tuple(self.colorStdout),
                     colorStderr=tuple(self.colorStderr),
                     colorBackground=tuple(self.colorBackground),
                     bannerGreeting=str(self.bannerGreeting),
                     startupCode=str(self.startupCode),
                     tabString=str(self.tabString),
                     showInvisibleCharacters=bool(
                         self.showInvisibleCharacters),
                     userThemes=dict(getDefaultValue("userThemes")))

            with open(exportPath, 'wb') as f:
                plistlib.dump(d, f)

    def importSettings(self):
        importPath = (vanilla.dialogs.getFile(
            messageText="Import RoboREPL Settings",
            fileTypes=["roboREPLSettings"]))[0]

        if importPath:
            with open(importPath, 'rb') as f:
                try:
                    d = plistlib.load(f)
                except:
                    raise PyREPLSettingsError(
                        "There was an error when loading settings file: %s." %
                        importPath)

            if "windowWidth" in d.keys():
                self.windowWidth = int(d["windowWidth"])
            if "windowHeight" in d.keys():
                self.windowHeight = int(d["windowHeight"])
            if "fontName" in d.keys():
                self.fontName = str(d["fontName"])
            if "fontSize" in d.keys():
                self.fontSize = int(d["fontSize"])
            if "colorCode" in d.keys():
                self.colorCode = tuple(d["colorCode"])
            if "colorStdout" in d.keys():
                self.colorStdout = tuple(d["colorStdout"])
            if "colorStderr" in d.keys():
                self.colorStderr = tuple(d["colorStderr"])
            if "colorBackground" in d.keys():
                self.colorBackground = tuple(d["colorBackground"])
            if "bannerGreeting" in d.keys():
                self.bannerGreeting = str(d["bannerGreeting"])
            if "startupCode" in d.keys():
                self.startupCode = str(d["startupCode"])
            if "tabString" in d.keys():
                self.tabString = str(d["tabString"])
            if "showInvisibleCharacters" in d.keys():
                self.showInvisibleCharacters = bool(
                    d["showInvisibleCharacters"])
            if "userThemes" in d.keys():
                setDefaultValue("userThemes", dict(d["userThemes"]))
Exemple #9
0
class PyREPLSettings(object):
    def __init__(self):
        self._dispatcher = NotificationCenter()

    def __repr__(self):
        return "<Editor Settings Manager. Type \"settings.help\" for documentation.>"

    def _get_help(self):
        # LOL. This is probably very illegal.
        print(settingsManagerDoc)

    help = property(_get_help)

    # Notifications

    def addObserver(self,
                    obj,
                    methodName,
                    notification="PyREPL.SettingsChanged"):
        self._dispatcher.addObserver(obj,
                                     methodName,
                                     notification=notification,
                                     observable=self)

    def removeObserver(self, obj, notification="PyREPL.SettingsChanged"):
        self._dispatcher.removeObserver(obj, notification, self)

    def postNotification(self,
                         notification="PyREPL.SettingsChanged",
                         data=None):
        self._dispatcher.postNotification(notification, self, data)

    # Properties

    windowWidth = settingsProperty("windowWidth", settingsWindowSizeValidator)
    windowHeight = settingsProperty("windowHeight",
                                    settingsWindowSizeValidator)
    fontName = settingsProperty("fontName", settingsStringValidator)
    fontSize = settingsProperty("fontSize", settingsPositiveNumberValidator)
    colorCode = settingsProperty("colorCode", settingsColorValidator)
    colorStdout = settingsProperty("colorStdout", settingsColorValidator)
    colorStderr = settingsProperty("colorStderr", settingsColorValidator)
    colorBackground = settingsProperty("colorBackground",
                                       settingsColorValidator)
    bannerGreeting = settingsProperty("bannerGreeting",
                                      settingsStringValidator)
    startupCode = settingsProperty("startupCode", settingsStringValidator)
    tabString = settingsProperty("tabString", settingsStringValidator)
    showInvisibleCharacters = settingsProperty("showInvisibleCharacters",
                                               settingsBoolValidator)

    def editorItems(self):
        d = dict(fontName=self.fontName,
                 fontSize=self.fontSize,
                 colorCode=self.colorCode,
                 colorStdout=self.colorStdout,
                 colorStderr=self.colorStderr,
                 colorBackground=self.colorBackground,
                 tabString=self.tabString,
                 showInvisibleCharacters=self.showInvisibleCharacters)
        return d.items()

    # Fonts

    def _get_availableFonts(self):
        manager = NSFontManager.sharedFontManager()
        for name in manager.availableFonts():
            font = NSFont.fontWithName_size_(name, 10)
            if font.isFixedPitch():
                print(name)

    availableFonts = property(_get_availableFonts)

    # Startup Code

    def editStartupCode(self):
        self.postNotification(notification="PyREPL.ShowStartupCodeEditor")

    # Themes

    def loadTheme(self, name):
        userThemes = getDefaultValue("userThemes")
        if name in userThemes:
            theme = userThemes[name]
        elif name in defaultThemes:
            theme = defaultThemes[name]
        else:
            raise PyREPLSettingsError("No theme named %r." % name)
        self.colorCode = theme["colorCode"]
        self.colorStdout = theme["colorStdout"]
        self.colorStderr = theme["colorStderr"]
        self.colorBackground = theme["colorBackground"]

    def saveTheme(self, name):
        if not settingsStringValidator(name):
            raise PyREPLSettingsError("Theme names must be strings.")
        theme = dict(colorCode=self.colorCode,
                     colorStderr=self.colorStderr,
                     colorStdout=self.colorStdout,
                     colorBackground=self.colorBackground)
        userThemes = getDefaultValue("userThemes")
        userThemes[name] = theme
        setDefaultValue("userThemes", userThemes)