Esempio n. 1
0
 def _openDeckFile(self, fname):
     """Open deck with givem file name."""
     fname = str(fname)
     problem = False
     # FIXME running setCardModelIndex to empty
     # to clean all other views
     # I must redesign the model/view thing
     self.setCardModelIndex(QModelIndex())
     self.cardModel().close()
     try:
         self.cardModel().open(fname)
         self.setCardModelIndex(self.cardModel().index(0, 0))
         config.add_most_recent_file(fname)
     except:
         config.remove_recent_file(fname)
         self.setCardModelIndex(QModelIndex())
         problem = True
     finally:
         self._refreshAppState()
         if problem:
             show_info('Problem opening deck file %s.' % fname)
Esempio n. 2
0
 def _newDeckFile(self, fname):
     """Creates a new deck with given file name."""
     fname = str(fname)
     problem = False
     # FIXME running setCardModelIndex with QModelIndex is  HACK to clean
     # all other views - it must be run before closing cardModel
     # I must redesign the model/view thing
     self.setCardModelIndex(QModelIndex())
     self.cardModel().close()
     try:
         # we want to overwrite
         if os.path.isfile(fname):
             os.remove(fname)
         self.cardModel().open(fname)
         self.setCardModelIndex(self.cardModel().index(0, 0))
         config.add_most_recent_file(fname)
     except:
         config.remove_most_recent_file(fname)
         self.setCardModelIndex(QModelIndex())
         problem = True
     finally:
         self._refreshAppState()
         if problem:
             show_info('Problem creating a new deck file %s.' % fname)