def test_postNotification_notification_observable(self): # notification, observable center = NotificationCenter() observable1 = _TestObservable(center, "Observable1") observable2 = _TestObservable(center, "Observable2") observer = NotificationTestObserver() center.addObserver(observer, "notificationCallback", "A", observable1) center.postNotification("A", observable1) self.assertEqual(observer.stack[-1], ("A", "Observable1")) center.postNotification("A", observable2) self.assertEqual(observer.stack[-1], ("A", "Observable1")) center.postNotification("B", observable1) self.assertEqual(observer.stack[-1], ("A", "Observable1")) center.postNotification("B", observable2) self.assertEqual(observer.stack[-1], ("A", "Observable1"))
def test_postNotification_notification_observable(self): # notification, observable center = NotificationCenter() observable1 = _TestObservable(center, "Observable1") observable2 = _TestObservable(center, "Observable2") observer = NotificationTestObserver() center.addObserver(observer, "notificationCallback", "A", observable1) center.postNotification("A", observable1) self.assertEqual(observer.stack[-1], ("A", "Observable1")) center.postNotification("A", observable2) self.assertEqual(observer.stack[-1], ("A", "Observable1")) center.postNotification("B", observable1) self.assertEqual(observer.stack[-1], ("A", "Observable1")) center.postNotification("B", observable2) self.assertEqual(observer.stack[-1], ("A", "Observable1"))
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)
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"]))
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)