def __init__( self, log, filename, scheme, preferences_class ): self.log = log self.xml_prefs = XmlPreferences( scheme ) self.prefs_filename = filename self.preferences_class = preferences_class self.prefs = None
def __init__( self, app, prefs_filename, session_filename ): self.xml_prefs = XmlPreferences( bemacs_preferences_scheme ) self.xml_session = XmlPreferences( bemacs_session_scheme ) self.app = app self.prefs_filename = prefs_filename self.session_filename = session_filename assert isinstance( prefs_filename, pathlib.Path ) assert isinstance( session_filename, pathlib.Path ) try: self.session = self.xml_session.load( self.session_filename ) except IOError: self.session = Session() self.session.finaliseNode() try: self.prefs = self.xml_prefs.load( self.prefs_filename ) except IOError: self.prefs = Preferences() self.prefs.finaliseNode()
class BemacsPreferenceManager: def __init__( self, app, filename ): self.xml_prefs = XmlPreferences( bemacs_preferences_scheme ) self.app = app self.prefs_filename = filename assert isinstance( filename, pathlib.Path ) try: self.prefs = self.xml_prefs.load( self.prefs_filename ) except IOError: self.prefs = Preferences() self.prefs.finaliseNode() def getPrefs( self ): return self.prefs def writePreferences( self ): tmp_filename = self.prefs_filename.with_suffix( '.tmp' ) self.xml_prefs.saveAs( self.prefs, tmp_filename ) old_filename = self.prefs_filename.with_suffix( '.old.xml' ) if self.prefs_filename.exists(): if old_filename.exists(): old_filename.unlink() self.prefs_filename.rename( old_filename ) tmp_filename.rename( self.prefs_filename )
class BemacsPreferenceManager: def __init__(self, app, prefs_filename, session_filename): self.xml_prefs = XmlPreferences(bemacs_preferences_scheme) self.xml_session = XmlPreferences(bemacs_session_scheme) self.app = app self.prefs_filename = prefs_filename self.session_filename = session_filename assert isinstance(prefs_filename, pathlib.Path) assert isinstance(session_filename, pathlib.Path) try: self.session = self.xml_session.load(self.session_filename) except IOError: self.session = Session() self.session.finaliseNode() try: self.prefs = self.xml_prefs.load(self.prefs_filename) except IOError: self.prefs = Preferences() self.prefs.finaliseNode() def getPrefs(self): return self.prefs def writePreferences(self): self.prefs.window.geometry = None for filename, xml_scheme, data in ((self.prefs_filename, self.xml_prefs, self.prefs), (self.session_filename, self.xml_session, self.session)): tmp_filename = filename.with_suffix('.tmp') xml_scheme.saveAs(data, tmp_filename) old_filename = filename.with_suffix('.old.xml') if filename.exists(): if old_filename.exists(): old_filename.unlink() filename.rename(old_filename) tmp_filename.rename(filename) def getFrameGeometry(self): geometry = self.session.getFrameGeometry() if geometry is not None: return geometry return self.prefs.window.getFrameGeometry() def setFrameGeometry(self, geometry): self.session.setFrameGeometry(geometry)
class BemacsPreferenceManager: def __init__( self, app, prefs_filename, session_filename ): self.xml_prefs = XmlPreferences( bemacs_preferences_scheme ) self.xml_session = XmlPreferences( bemacs_session_scheme ) self.app = app self.prefs_filename = prefs_filename self.session_filename = session_filename assert isinstance( prefs_filename, pathlib.Path ) assert isinstance( session_filename, pathlib.Path ) try: self.session = self.xml_session.load( self.session_filename ) except IOError: self.session = Session() self.session.finaliseNode() try: self.prefs = self.xml_prefs.load( self.prefs_filename ) except IOError: self.prefs = Preferences() self.prefs.finaliseNode() def getPrefs( self ): return self.prefs def writePreferences( self ): self.prefs.window.geometry = None for filename, xml_scheme, data in ( (self.prefs_filename, self.xml_prefs, self.prefs), (self.session_filename, self.xml_session, self.session)): tmp_filename = filename.with_suffix( '.tmp' ) xml_scheme.saveAs( data, tmp_filename ) old_filename = filename.with_suffix( '.old.xml' ) if filename.exists(): if old_filename.exists(): old_filename.unlink() filename.rename( old_filename ) tmp_filename.rename( filename ) def getFrameGeometry( self ): geometry = self.session.getFrameGeometry() if geometry is not None: return geometry return self.prefs.window.getFrameGeometry() def setFrameGeometry( self, geometry ): self.session.setFrameGeometry( geometry )
def __init__( self, app, filename ): self.xml_prefs = XmlPreferences( bemacs_preferences_scheme ) self.app = app self.prefs_filename = filename assert isinstance( filename, pathlib.Path ) try: self.prefs = self.xml_prefs.load( self.prefs_filename ) except IOError: self.prefs = Preferences() self.prefs.finaliseNode()
class PreferencesManager: def __init__( self, log, filename, scheme, preferences_class ): self.log = log self.xml_prefs = XmlPreferences( scheme ) self.prefs_filename = filename self.preferences_class = preferences_class self.prefs = None def readPreferences( self ): try: self.prefs = self.xml_prefs.load( self.prefs_filename ) except IOError as e: self.log.info( 'No preferences found' ) # Assume its a missing file and default everything self.prefs = self.xml_prefs.default() except ParseError as e: self.log.error( 'Error parsing preferences: %s' % (str(e),) ) self.prefs = self.xml_prefs.default() #self.prefs.dumpNode( sys.stdout ) def getPreferences( self ): return self.prefs def writePreferences( self ): #self.prefs.dumpNode( sys.stdout ) tmp_filename = self.prefs_filename.with_suffix( '.tmp' ) self.xml_prefs.saveAs( self.prefs, tmp_filename ) old_filename = self.prefs_filename.with_suffix( '.old.xml' ) if self.prefs_filename.exists(): if old_filename.exists(): old_filename.unlink() self.prefs_filename.rename( old_filename ) tmp_filename.rename( self.prefs_filename )
class PreferencesManager: def __init__( self, log, filename, scheme, preferences_class ): self.log = log self.xml_prefs = XmlPreferences( scheme ) self.prefs_filename = filename self.preferences_class = preferences_class def readPreferences( self ): try: self.prefs = self.xml_prefs.load( self.prefs_filename ) except IOError as e: self.log.info( 'No preferences found' ) # Assume its a missing file and default everything self.prefs = self.xml_prefs.default() except ParseError as e: self.log.error( 'Error parsing preferences: %s' % (str(e),) ) self.prefs = self.xml_prefs.default() #self.prefs.dumpNode( sys.stdout ) def getPreferences( self ): return self.prefs def writePreferences( self ): #self.prefs.dumpNode( sys.stdout ) tmp_filename = self.prefs_filename.with_suffix( '.tmp' ) self.xml_prefs.saveAs( self.prefs, tmp_filename ) old_filename = self.prefs_filename.with_suffix( '.old.xml' ) if self.prefs_filename.exists(): if old_filename.exists(): old_filename.unlink() self.prefs_filename.rename( old_filename ) tmp_filename.rename( self.prefs_filename )
def __init__( self, log, filename, scheme, preferences_class ): self.log = log self.xml_prefs = XmlPreferences( scheme ) self.prefs_filename = filename self.preferences_class = preferences_class