Ejemplo n.º 1
0
 def __openFileForWriting(self,
                          filename,
                          openfile,
                          showerror,
                          mode='w',
                          encoding='utf-8'):
     try:
         return openfile(filename, mode, encoding)
     except IOError, reason:
         errorMessage = _('Cannot open %s\n%s') % (
             filename, ExceptionAsUnicode(reason))
         showerror(errorMessage, **self.__errorMessageOptions)
         return None
Ejemplo n.º 2
0
 def importTemplate(self, showerror=wx.MessageBox):
     filename = self.__askUserForFile(_('Import template'),
                                      fileDialogOpts={
                                          'default_extension':
                                          'tsktmpl',
                                          'wildcard':
                                          _('%s template files (*.tsktmpl)|'
                                            '*.tsktmpl') % meta.name
                                      })
     if filename:
         templates = persistence.TemplateList(
             self.__settings.pathToTemplatesDir())
         try:
             templates.copyTemplate(filename)
         except Exception, reason:  # pylint: disable=W0703
             errorMessage = _('Cannot import template %s\n%s') % (
                 filename, ExceptionAsUnicode(reason))
             showerror(errorMessage, **self.__errorMessageOptions)
Ejemplo n.º 3
0
 def __init__(self, load=True, iniFile=None, *args, **kwargs):
     # Sigh, ConfigParser.SafeConfigParser is an old-style class, so we 
     # have to call the superclass __init__ explicitly:
     CachingConfigParser.__init__(self, *args, **kwargs)
     self.initializeWithDefaults()
     self.__loadAndSave = load
     self.__iniFileSpecifiedOnCommandLine = iniFile
     self.migrateConfigurationFiles()
     if load:
         # First, try to load the settings file from the program directory,
         # if that fails, load the settings file from the settings directory
         try:
             if not self.read(self.filename(forceProgramDir=True)):
                 self.read(self.filename())
             errorMessage = ''
         except ConfigParser.ParsingError, errorMessage:
             # Ignore exceptions and simply use default values. 
             # Also record the failure in the settings:
             self.initializeWithDefaults()
         self.setLoadStatus(ExceptionAsUnicode(errorMessage))
Ejemplo n.º 4
0
 def _saveSave(self, taskFile, showerror, filename=None):
     ''' Save the file and show an error message if saving fails. '''
     try:
         if filename:
             taskFile.saveas(filename)
         else:
             filename = taskFile.filename()
             taskFile.save()
         self.__showSaveMessage(taskFile)
         self.__addRecentFile(filename)
         return True
     except lockfile.LockTimeout:
         errorMessage = _(
             'Cannot save %s\nIt is locked by another instance '
             'of %s.\n') % (filename, meta.name)
         showerror(errorMessage, **self.__errorMessageOptions)
         return False
     except (OSError, IOError, lockfile.LockFailed), reason:
         errorMessage = _('Cannot save %s\n%s') % (
             filename, ExceptionAsUnicode(reason))
         showerror(errorMessage, **self.__errorMessageOptions)
         return False