예제 #1
0
파일: reporteditor.py 프로젝트: vertrex/DFF
class ReportEditor(QSplitter, EventHandler):
    def __init__(self, parent, outputpath=None):
        QSplitter.__init__(self)
        EventHandler.__init__(self)
        self.reportManager = ReportManager()
        self.reportManager.connection(self)
        self.parent = parent
        self.name = self.tr("Report Editor")

        self.reportView = ReportEditorView(self)
        self.reportTree = ReportEditorTree(self)

        self.connect(self.reportTree, SIGNAL("itemClicked"),
                     self.reportView.displayItem)

        treeWidget = QWidget()
        vbox = QVBoxLayout()
        vbox.addWidget(self.reportTree)

        buttonPreview = QPushButton(self.tr("&Generate preview"), treeWidget)
        self.connect(buttonPreview, SIGNAL("clicked()"),
                     self.reportView.showReportPreview)
        vbox.addWidget(buttonPreview)

        buttonExport = QPushButton(self.tr("&Export"), treeWidget)
        self.connect(buttonExport, SIGNAL("clicked()"), self.reportTree.export)
        vbox.addWidget(buttonExport)
        treeWidget.setLayout(vbox)
        self.addWidget(treeWidget)

        self.addWidget(self.reportView)
        self.setStretchFactor(1, 2)

    def Event(self, e):
        if e.type == ReportManager.EventNewCategory:
            self.emit(SIGNAL("newCategory"), e.value.value())

        if e.type == ReportManager.EventNewPage:
            self.parent.showReportEdit()
            self.emit(SIGNAL("newPage"), e.value.value())
예제 #2
0
파일: reportexport.py 프로젝트: vertrex/DFF
class ReportExportDialog(QDialog, EventHandler):
    def __init__(self):
        QDialog.__init__(self, None)
        EventHandler.__init__(self)
        self.reportManager = ReportManager()
        self.reportManager.connection(self)
        self.setModal(True)
        self.detail = False
        self.items = ReportExportProgressItems()
        self.__optionsDialog = None

        self.elements = ReportExportProgress(
            self.tr("of elements"), ReportPageFragment.EventWriteElements,
            ReportPageFragment.EventWriteElementStart,
            ReportPageFragment.EventWriteElementFinish)
        self.fragments = ReportExportProgress(
            self.tr("of fragments"), ReportPage.EventExportFragments,
            ReportPageFragment.EventWriteStart,
            ReportPageFragment.EventWriteFinish, self.elements)
        self.pages = ReportExportProgress(self.tr("of pages"),
                                          ReportManager.EventExportPages,
                                          ReportPage.EventExportStart,
                                          ReportPage.EventExportFinish,
                                          self.fragments)
        self.category = ReportExportProgress(
            self.tr("of category"), ReportManager.EventExportCategories,
            ReportManager.EventExportCategoryStart,
            ReportManager.EventExportCategoryFinish, self.pages)

        self.progresses = [
            self.category, self.pages, self.fragments, self.elements
        ]
        self.detailButton = QPushButton("<<< " + self.tr("Show details"))
        self.connect(self.detailButton, SIGNAL("clicked()"), self.showDetail)
        self.cancelButton = QPushButton("&" + self.tr("Cancel"))
        self.connect(self.cancelButton, SIGNAL("clicked()"), self.cancel)

        self.hboxLayout = QVBoxLayout(self)
        self.hboxLayout.addWidget(self.items.label)
        self.hboxLayout.addWidget(self.items.bar)
        for progress in self.progresses:
            self.hboxLayout.addWidget(progress.label)
            progress.label.hide()
            self.hboxLayout.addWidget(progress.bar)
            progress.bar.hide()
        self.hboxLayout.addWidget(self.detailButton)
        self.hboxLayout.addWidget(self.cancelButton)
        self.setLayout(self.hboxLayout)

    def showDetail(self):
        self.detail = not self.detail
        if self.detail:
            self.detailButton.setText(">>> " + self.tr("Hide details"))
            for progress in self.progresses:
                progress.bar.show()
                progress.label.show()
        else:
            self.detailButton.setText("<<< " + self.tr("Show details"))
            for progress in self.progresses:
                progress.bar.hide()
                progress.label.hide()
        if self.sizeHint().width() > self.size().width():
            self.resize(self.sizeHint().width(), self.sizeHint().height())
        else:
            self.resize(self.size().width(), self.sizeHint().height())

    def Event(self, event):
        self.items.event(event)
        for progress in self.progresses:
            progress.event(event)

    def checkExportFreeSpace(self, exportContent):
        exportPath = self.reportManager.exportPath()
        if os.name == "nt":
            exportPath = exportPath[:exportPath.rfind("\\")]
        else:
            exportPath = exportPath[:exportPath.rfind("/")]
        freeSpace = Extract.freeSpace(exportPath)
        exportSize = self.reportManager.exportSize(exportContent)
        if freeSpace < exportSize:
            msg = self.tr("Not enough free space to extract files.") + '\n'
            msg += str(freeSpace) + self.tr(" bytes of free space for ") + str(
                exportSize) + self.tr(" bytes of data to extract.") + '\n'
            msg += self.tr("Choose an other directory ?")
            return QMessageBox.warning(
                self, self.tr("Export"), msg,
                QMessageBox.Yes | QMessageBox.No | QMessageBox.Cancel)
        return QMessageBox.No

    def optionsDialog(self, exportContent=False):
        if self.__optionsDialog:
            return self.__optionsDialog
        else:
            self.__optionsDialog = ReportExportOptionsDialog(exportContent)
            return self.__optionsDialog

    def export(self,
               exportContent=True,
               askOptions=False,
               checkExportSize=True,
               displayInformations=True):
        if askOptions:
            self.optionsDialog(exportContent).exec_()
            exportContent = self.optionsDialog().exportContent()
        if checkExportSize:
            choice = self.checkExportFreeSpace(exportContent)
            if choice == QMessageBox.No:
                return self.__export(exportContent, displayInformations)
            elif choice == QMessageBox.Yes:
                self.export(exportContent,
                            askOptions=True,
                            checkExportSize=True,
                            displayInformations=True)
        else:
            return self.__export(exportContent, displayInformations)

    def __export(self, exportContent, displayInformations=True):
        self.show()
        try:
            self.reportManager.export(exportContent)
            status = True
            self.accept()
        except Exception as e:
            print 'Error : Export failed ', e
            self.reject()
            status = False
            self.reject()
        if displayInformations:
            ReportExportInformations(self, status).exec_()
        return status

    def cancel(self):
        self.reportManager.exportCancel()
        QDialog.reject(self)

    def __del__(self):
        self.reportManager.deconnection(self)