Package Camelot :: Package camelot :: Package view :: Module storage |
[frames] | no frames]

# Source Code for Module Camelot.camelot.view.storage

     1  from camelot.view.controls.exception import model_thread_exception_message_box
     2  from camelot.view.model_thread import post
     3  from camelot.core.utils import ugettext as _
     4
     5  from PyQt4 import QtGui, QtCore
     6
     7 -class OpenFileProgressDialog(QtGui.QProgressDialog):
     8
     9 -    def __init__(self):
    10          QtGui.QProgressDialog.__init__(self, _('Please wait'), QtCore.QString(), 0, 0)
    11          self.setWindowTitle(_('Open file'))
    12          self.setRange(0, 0)
    13
    14 -    def open_path(self, path):
    15          import os
    16          if not os.path.exists(path):
    17              QtGui.QMessageBox.critical (self, _('Could not open file'), _('%s does not exist')%path)
    18          #
    19          # support for windows shares
    20          #
    21          if not path.startswith(r'\\'):
    22              url = QtCore.QUrl.fromLocalFile(path)
    23          else:
    24              url = QtCore.QUrl(path, QtCore.QUrl.TolerantMode)
    25          QtGui.QDesktopServices.openUrl(url)
    26          self.close()
    27
    28 -class SaveFileProgressDialog(QtGui.QProgressDialog):
    29
    30 -    def __init__(self):
    31          QtGui.QProgressDialog.__init__(self, _('Please wait'), QtCore.QString(), 0, 0)
    32          self.setWindowTitle(_('Save file'))
    33          self.setRange(0, 0)
    34
    35 -    def finish(self, on_finish):
    36          on_finish()
    37          self.close()
    38
    39 -def open_stored_file(parent, stored_file):
    40      """Open the stored file with the default system editor for this file type"""
    41
    42      progress = OpenFileProgressDialog()
    43
    44      def get_path():
    45          return stored_file.storage.checkout(stored_file)
    46
    47      post(get_path, progress.open_path, model_thread_exception_message_box)
    48      progress.exec_()
    49
    50 -def create_stored_file(parent, storage, on_finish, filter="""All files (*)"""):
    51      """Popup a QFileDialog, put the selected file in the storage and return the
    52      call on_finish with the StoredFile when done"""
    53      filename = QtGui.QFileDialog.getOpenFileName(parent, 'Open file',
    54                                                   QtCore.QDir.currentPath(),
    55                                                   filter)
    56      if filename:
    57          progress = SaveFileProgressDialog()
    58
    59          def checkin():
    60              new_path = storage.checkin(str(filename))
    61              return lambda:on_finish(new_path)
    62
    63          post(checkin, progress.finish, model_thread_exception_message_box)
    64          progress.exec_()
    65