def onThemeChange(self, event): """Handles a theme change event (from a window with a themesMenu)""" win = event.EventObject.Window newTheme = win.themesMenu.FindItemById(event.GetId()).ItemLabel prefs.app['theme'] = newTheme prefs.saveUserPrefs() self.theme = newTheme
def theme(self, value): """The theme to be used through the application""" # Make sure we just have a name if isinstance(value, themes.Theme): value = value.code # Store new theme prefs.app['theme'] = value prefs.saveUserPrefs() # Reset icon cache icons.iconCache.clear() # Set theme at module level themes.theme.set(value) # Apply to frames for frameRef in self._allFrames: frame = frameRef() if isinstance(frame, handlers.ThemeMixin): frame.theme = themes.theme # On OSX 10.15 Catalina at least calling SetFaceName with 'AppleSystemUIFont' fails. # So this fix checks to see if changing the font name invalidates the font. # if so rollback to the font before attempted change. # Note that wx.Font uses referencing and copy-on-write so we need to force creation of a copy # with the wx.Font() call. Otherwise you just get reference to the font that gets borked by SetFaceName() # -Justin Ales beforesetface = wx.Font(self._codeFont) success = self._codeFont.SetFaceName("JetBrains Mono") if not (success): self._codeFont = beforesetface
def setupProxy(): """Set up the urllib proxy if possible. The function will use the following methods in order to try and determine proxies: #. standard urllib2.urlopen (which will use any statically-defined http-proxy settings) #. previous stored proxy address (in prefs) #. proxy.pac files if these have been added to system settings #. auto-detect proxy settings (WPAD technology) .. note: This can take time, as each failed attempt to set up a proxy involves trying to load a URL and timing out. Best to do in a separate thread. :Returns: True (success) or False (failure) """ global proxies #try doing nothing proxies=urllib2.ProxyHandler(urllib2.getproxies()) if testProxy(proxies) is True: logging.debug("Using standard urllib2 (static proxy or no proxy required)") urllib2.install_opener(urllib2.build_opener(proxies))#this will now be used globally for ALL urllib2 opening return 1 #try doing what we did last time if len(prefs.connections['proxy'])>0: proxies=urllib2.ProxyHandler({'http': prefs.connections['proxy']}) if testProxy(proxies) is True: logging.debug('Using %s (from prefs)' %(prefs.connections['proxy'])) urllib2.install_opener(urllib2.build_opener(proxies))#this will now be used globally for ALL urllib2 opening return 1 else: logging.debug("Found a previous proxy but it didn't work") #try finding/using a proxy.pac file pacURLs=getPacFiles() logging.debug("Found proxy PAC files: %s" %pacURLs) proxies=proxyFromPacFiles(pacURLs) # installs opener, if successful if proxies and hasattr(proxies, 'proxies') and len(proxies.proxies['http'])>0: #save that proxy for future prefs.connections['proxy']=proxies.proxies['http'] prefs.saveUserPrefs() logging.debug('Using %s (from proxy PAC file)' %(prefs.connections['proxy'])) return 1 #try finding/using 'auto-detect proxy' pacURLs=getWpadFiles() proxies=proxyFromPacFiles(pacURLs) # installs opener, if successful if proxies and hasattr(proxies, 'proxies') and len(proxies.proxies['http'])>0: #save that proxy for future prefs.connections['proxy']=proxies.proxies['http'] prefs.saveUserPrefs() logging.debug('Using %s (from proxy auto-detect)' %(prefs.connections['proxy'])) return 1 proxies=0 return 0
def setup(): """ Prepare psychopy environment and settings """ #pylint: disable=import-outside-toplevel from psychopy import prefs #pylint: enable=import-outside-toplevel prefs.hardware['audioLib'] = config.psy.PREFS.get('audioLib') prefs.general['winType'] = config.psy.PREFS.get('winType') prefs.hardware['highDPI'] = config.psy.PREFS.get('highDPI') prefs.saveUserPrefs() #pylint: disable=import-outside-toplevel import app.psy as psy #pylint: enable=import-outside-toplevel # Ensure data directory exists and is writeable if not os.path.exists(config.data.DATA_PATH): try: os.mkdir(config.data.DATA_PATH) except Exception as ex: raise SystemError('Cannot write to {}'.format( os.path.abspath(config.data.DATA_PATH))) from ex return psy.Psypy(config.psy.PREFS)
def setupProxy(log=True): """Set up the urllib proxy if possible. The function will use the following methods in order to try and determine proxies: #. standard urllib.request.urlopen (which will use any statically-defined http-proxy settings) #. previous stored proxy address (in prefs) #. proxy.pac files if these have been added to system settings #. auto-detect proxy settings (WPAD technology) .. note: This can take time, as each failed attempt to set up a proxy involves trying to load a URL and timing out. Best to do in a separate thread. :Returns: True (success) or False (failure) """ global proxies #try doing nothing proxies = urllib.request.ProxyHandler(urllib.request.getproxies()) if tryProxy(proxies) is True: if log: logging.debug( "Using standard urllib (static proxy or no proxy required)") urllib.request.install_opener(urllib.request.build_opener( proxies)) #this will now be used globally for ALL urllib opening return 1 #try doing what we did last time if len(prefs.connections['proxy']) > 0: proxies = urllib.request.ProxyHandler( {'http': prefs.connections['proxy']}) if tryProxy(proxies) is True: if log: logging.debug('Using %s (from prefs)' % (prefs.connections['proxy'])) urllib.request.install_opener( urllib.request.build_opener(proxies) ) #this will now be used globally for ALL urllib opening return 1 else: if log: logging.debug("Found a previous proxy but it didn't work") #try finding/using a proxy.pac file pacURLs = getPacFiles() if log: logging.debug("Found proxy PAC files: %s" % pacURLs) proxies = proxyFromPacFiles(pacURLs) # installs opener, if successful if proxies and hasattr(proxies, 'proxies') and len(proxies.proxies['http']) > 0: #save that proxy for future prefs.connections['proxy'] = proxies.proxies['http'] prefs.saveUserPrefs() if log: logging.debug('Using %s (from proxy PAC file)' % (prefs.connections['proxy'])) return 1 #try finding/using 'auto-detect proxy' pacURLs = getWpadFiles() proxies = proxyFromPacFiles(pacURLs) # installs opener, if successful if proxies and hasattr(proxies, 'proxies') and len(proxies.proxies['http']) > 0: #save that proxy for future prefs.connections['proxy'] = proxies.proxies['http'] prefs.saveUserPrefs() if log: logging.debug('Using %s (from proxy auto-detect)' % (prefs.connections['proxy'])) return 1 proxies = 0 return 0