Exemplo n.º 1
0
    def printData(data, model, ids):
        if 'result' not in data:
            Notifier.notifyWarning(
                _('Report error'),
                _('There was an error trying to create the report.'))
            return

        if data.get('code', 'normal') == 'zlib':
            import zlib
            content = zlib.decompress(base64.decodestring(data['result']))
        else:
            content = base64.decodestring(data['result'])

        # We'll always try to open the file and won't limit ourselves to
        # doc, html and pdf. For example, one might get odt, ods, etc. Before
        # we stored the report in a file if it wasn't one of the first three
        # formats.
        if data['format'] == 'html' and os.name == 'nt':
            data['format'] = 'doc'

        fp, fileName = tempfile.mkstemp('.%s' % data['format'])
        fp = os.fdopen(fp, 'wb+')
        try:
            fp.write(content)
        finally:
            fp.close()
        # Add semantic information before printing file because otherwise
        # it raises an exception in some systems.
        Semantic.addInformationToFile(fileName, model, ids)
        Printer.printFile(fileName, data['format'])
Exemplo n.º 2
0
 def saveImage(self):
     name = QFileDialog.getSaveFileName(self, _('Save image as...'))[0]
     if name:
         try:
             with open(name, "wb") as fp:
                 fp.write(self.getImage())
         except:
             QMessageBox.warning(self, _('Error saving file'), _(
                 'Could not save the image with the given file name. Please check that you have permissions.'))
         Semantic.addInformationToFile(
             name, self.record.group.resource, self.record.id, self.name)
     else:
         return
Exemplo n.º 3
0
 def saveImage(self):
     name = QFileDialog.getSaveFileName(self, _('Save image as...'))
     if name.isNull():
         return
     try:
         fp = file(unicode(name), 'wb')
         fp.write(self.getImage())
         fp.close()
     except:
         QMessageBox.warning(
             self, _('Error saving file'),
             _('Could not save the image with the given file name. Please check that you have permissions.'
               ))
     Semantic.addInformationToFile(name, self.record.group.resource,
                                   self.record.id, self.name)
Exemplo n.º 4
0
    def save(self):
        directory = '%s/%s' % (self.baseDirectory, str(self.fileName()))
        filename = QFileDialog.getSaveFileName(self, _('Save as...'),
                                               directory, self.filters)[0]
        if not filename:
            return
        filename = str(filename)
        self.baseDirectory = os.path.dirname(filename)

        try:
            with open(filename, 'wb+') as fp:
                fp.write(self.record.value(self.name))
        except Exception as e:
            QMessageBox.information(
                self, _('Error'),
                _('Error writing the file:\n%s') % str(e.args))
            return
        Semantic.addInformationToFile(filename, self.record.group.resource,
                                      self.record.id, self.name)
Exemplo n.º 5
0
                                               directory, self.filters)
        if filename.isNull():
            return
        filename = unicode(filename)
        self.baseDirectory = os.path.dirname(filename)

        try:
            fp = file(filename, 'wb+')
            fp.write(self.record.value(self.name))
            fp.close()
        except Exception, e:
            QMessageBox.information(
                self, _('Error'),
                _('Error writing the file:\n%s') % unicode(e.args))
            return
        Semantic.addInformationToFile(filename, self.record.group.resource,
                                      self.record.id, self.name)

    def remove(self):
        self.record.setValue(self.name, False)
        self.clear()
        self.modified()
        if 'filename' in self.attrs:
            w = self.attrs['filename']
            self.record.setValue(w, False)
            if self.view:
                self.view.widgets[w].load(self.record)

    def showValue(self):
        if self.record.value(self.sizeName):
            self.setText(self.record.value(self.sizeName))
        else: