示例#1
0
 def __init__(self, parent=None):
     super(OutTable, self).__init__(parent)
     self.setObjectName("Table")
     self.setWindowTitle("Table")
     self.dockWidgetContents = QWidget(self)
     self.verticalLayout = QVBoxLayout(self.dockWidgetContents)
     self.treeView = OfTreeView(self.dockWidgetContents)
     self.treeView.setAlternatingRowColors(True)
     self.treeView.setIndentation(10)
     selection_behavior = QAbstractItemView.SelectRows
     # we should enable contguous selection, but the copy method does not yet handle this.
     #        selection_mode = QAbstractItemView.ContiguousSelection
     selection_mode = QAbstractItemView.SingleSelection
     self.treeView.setSelectionBehavior(selection_behavior)
     self.treeView.setSelectionMode(selection_mode)
     self.verticalLayout.addWidget(self.treeView)
     self.setWidget(self.dockWidgetContents)
示例#2
0
    def __init__(self, parent = None):
        super(OutTable, self).__init__(parent)
        self.setObjectName("Table")
        self.setWindowTitle("Table")
        self.dockWidgetContents = QWidget(self)
        self.verticalLayout = QVBoxLayout(self.dockWidgetContents)
        self.treeView = OfTreeView(self.dockWidgetContents)
        self.treeView.setAlternatingRowColors(True)
        self.treeView.setIndentation(10)
        selection_behavior = QAbstractItemView.SelectRows
        # we should enable contguous selection, but the copy method does not yet handle this.
#        selection_mode = QAbstractItemView.ContiguousSelection
        selection_mode = QAbstractItemView.SingleSelection
        self.treeView.setSelectionBehavior(selection_behavior)
        self.treeView.setSelectionMode(selection_mode)
        self.verticalLayout.addWidget(self.treeView)
        self.setWidget(self.dockWidgetContents)
示例#3
0
class OutTable(QDockWidget):
    def __init__(self, parent = None):
        super(OutTable, self).__init__(parent)
        self.setObjectName("Table")
        self.setWindowTitle("Table")
        self.dockWidgetContents = QWidget(self)
        self.verticalLayout = QVBoxLayout(self.dockWidgetContents)
        self.treeView = OfTreeView(self.dockWidgetContents)
        self.treeView.setAlternatingRowColors(True)
        self.treeView.setIndentation(10)
        selection_behavior = QAbstractItemView.SelectRows
        # we should enable contguous selection, but the copy method does not yet handle this.
#        selection_mode = QAbstractItemView.ContiguousSelection
        selection_mode = QAbstractItemView.SingleSelection
        self.treeView.setSelectionBehavior(selection_behavior)
        self.treeView.setSelectionMode(selection_mode)
        self.verticalLayout.addWidget(self.treeView)
        self.setWidget(self.dockWidgetContents)

    def clearModel(self):
        self.treeView.setModel(None)

    def updateTable(self, data, reforme, mode, dataDefault):
        '''
        Updates table
        '''

        if dataDefault is None:
            dataDefault = data

        x_axis = CONF.get('simulation', 'x_axis')
        for axe in model.x_axes.itervalues():
            if axe.name == x_axis:
                x_axis_typ_tot = axe.typ_tot_default
                break

        headers = dataDefault[x_axis_typ_tot]
        n = len(headers.vals)
        self.data = data
        self.outputModel = OutputModel(data, headers, n , self)
        self.treeView.setModel(self.outputModel)
        self.treeView.expandAll()
        self.treeView.setColumnWidth(0, 200)
        if mode == 'bareme':
            for i in range(n):
                self.treeView.resizeColumnToContents(i+1)
        else:
            self.treeView.setColumnWidth(1,100)


    def create_dataframe(self):
        '''
        Formats data into a dataframe
        '''
        data_dict = dict()
        index = []
        for row in self.data:
            if not row.desc in ('root'):
                index.append(row.desc)
                data_dict[row.desc] = row.vals

        df = DataFrame(data_dict).T
        df = df.reindex(index)
        return df

    def create_description(self):
        '''
        Creates a description dataframe
        '''
        now = datetime.now()
        descr =  [u'OpenFisca',
                         u'Calculé le %s à %s' % (now.strftime('%d-%m-%Y'), now.strftime('%H:%M')),
                         u'Système socio-fiscal au %s' % CONF.get('simulation', 'datesim')]
        return DataFrame(descr)

    def saveCsv(self):
        self.save_table( table_format = "csv")

    def save_table(self, table_format = None):

        if table_format is None:
            table_format = CONF.get('paths', 'table')

        output_dir = CONF.get('paths', 'output_dir')
        filename = 'sans-titre.' + table_format
        user_path = os.path.join(output_dir, filename)

        extension = table_format.upper() + "   (*." + table_format + ")"
        fname = QFileDialog.getSaveFileName(self,
                                               u"Exporter la table", user_path, extension)

        if fname:
            CONF.set('paths', 'output_dir', os.path.dirname(str(fname)))
            try:
                if table_format == "xls":
                    writer = ExcelWriter(str(fname))
                    df = self.create_dataframe()
                    descr = self.create_description()
                    df.to_excel(writer, "table", index=True, header= False)
                    descr.to_excel(writer, "description", index = False, header=False)
                    writer.save()
                elif table_format =="csv":
                    # TODO: use DataFrame's ?
                    now = datetime.now()
                    csvfile = open(fname, 'wb')
                    writer = UnicodeWriter(csvfile, dialect= csv.excel, delimiter=';')

                    for row in self.data:
                        if not row.desc in ('root'):
                            outlist = [row.desc]
                            for val in row.vals:
                                outlist.append(locale.str(val))
                            writer.writerow(outlist)

                    writer.writerow([u'OpenFisca'])
                    writer.writerow([u'Calculé le %s à %s' % (now.strftime('%d-%m-%Y'), now.strftime('%H:%M'))])
                    writer.writerow([u'Système socio-fiscal au %s' % CONF.get('simulation', 'datesim')])
                    writer.writerow([])

                    csvfile.close()

            except Exception, e:
                QMessageBox.critical(
                    self, "Error saving file", str(e),
                    QMessageBox.Ok, QMessageBox.NoButton)
示例#4
0
class OutTable(QDockWidget):
    def __init__(self, parent=None):
        super(OutTable, self).__init__(parent)
        self.setObjectName("Table")
        self.setWindowTitle("Table")
        self.dockWidgetContents = QWidget(self)
        self.verticalLayout = QVBoxLayout(self.dockWidgetContents)
        self.treeView = OfTreeView(self.dockWidgetContents)
        self.treeView.setAlternatingRowColors(True)
        self.treeView.setIndentation(10)
        selection_behavior = QAbstractItemView.SelectRows
        # we should enable contguous selection, but the copy method does not yet handle this.
        #        selection_mode = QAbstractItemView.ContiguousSelection
        selection_mode = QAbstractItemView.SingleSelection
        self.treeView.setSelectionBehavior(selection_behavior)
        self.treeView.setSelectionMode(selection_mode)
        self.verticalLayout.addWidget(self.treeView)
        self.setWidget(self.dockWidgetContents)

    def clearModel(self):
        self.treeView.setModel(None)

    def updateTable(self, data, reforme, mode, dataDefault):
        xaxis = CONF.get('simulation', 'xaxis')
        if dataDefault is None:
            dataDefault = data
        headers = dataDefault[xaxis]
        n = len(headers.vals)
        self.data = data
        self.outputModel = OutputModel(data, headers, n, self)
        self.treeView.setModel(self.outputModel)
        self.treeView.expandAll()
        self.treeView.setColumnWidth(0, 200)
        if mode == 'bareme':
            for i in range(n):
                self.treeView.resizeColumnToContents(i + 1)
        else:
            self.treeView.setColumnWidth(1, 100)

    def saveCsv(self):
        output_dir = CONF.get('paths', 'output_dir')
        user_path = os.path.join(output_dir, 'sans-titre.csv')

        fname = QFileDialog.getSaveFileName(
            self, u"Exporter la table", user_path,
            u"CSV (séparateur: point virgule) (*.csv)")

        if fname:
            CONF.set('paths', 'output_dir', os.path.dirname(str(fname)))
            try:
                now = datetime.now()
                csvfile = open(fname, 'wb')
                writer = UnicodeWriter(csvfile,
                                       dialect=csv.excel,
                                       delimiter=';')
                writer.writerow([u'OpenFisca'])
                writer.writerow([
                    u'Calculé le %s à %s' %
                    (now.strftime('%d-%m-%Y'), now.strftime('%H:%M'))
                ])
                writer.writerow([
                    u'Système socio-fiscal au %s' %
                    CONF.get('simulation', 'datesim')
                ])
                writer.writerow([])

                for row in self.data:
                    if not row.desc in ('root'):
                        outlist = [row.desc]
                        for val in row.vals:
                            outlist.append(locale.str(val))
                        writer.writerow(outlist)
                csvfile.close()
            except Exception, e:
                QMessageBox.critical(self, "Error saving file", str(e),
                                     QMessageBox.Ok, QMessageBox.NoButton)
示例#5
0
class OutTable(QDockWidget):
    def __init__(self, parent = None):
        super(OutTable, self).__init__(parent)
        self.setObjectName("Table")
        self.setWindowTitle("Table")
        self.dockWidgetContents = QWidget(self)
        self.verticalLayout = QVBoxLayout(self.dockWidgetContents)
        self.treeView = OfTreeView(self.dockWidgetContents)
        self.treeView.setAlternatingRowColors(True)
        self.treeView.setIndentation(10)
        selection_behavior = QAbstractItemView.SelectRows
        # we should enable contguous selection, but the copy method does not yet handle this.
#        selection_mode = QAbstractItemView.ContiguousSelection
        selection_mode = QAbstractItemView.SingleSelection       
        self.treeView.setSelectionBehavior(selection_behavior)
        self.treeView.setSelectionMode(selection_mode)
        self.verticalLayout.addWidget(self.treeView)
        self.setWidget(self.dockWidgetContents)

    def clearModel(self):
        self.treeView.setModel(None)

    def updateTable(self, data, reforme, mode, dataDefault):
        xaxis = CONF.get('simulation', 'xaxis')
        if dataDefault is None:
            dataDefault = data
        headers = dataDefault[xaxis]
        n = len(headers.vals)
        self.data = data
        self.outputModel = OutputModel(data, headers, n , self)
        self.treeView.setModel(self.outputModel)
        self.treeView.expandAll()
        self.treeView.setColumnWidth(0, 200)
        if mode == 'bareme':
            for i in range(n):
                self.treeView.resizeColumnToContents(i+1)
        else:
            self.treeView.setColumnWidth(1,100)

    def saveCsv(self):
        output_dir = CONF.get('paths', 'output_dir')
        user_path = os.path.join(output_dir, 'sans-titre.csv')

        fname = QFileDialog.getSaveFileName(self,
                                               u"Exporter la table", user_path, u"CSV (séparateur: point virgule) (*.csv)")
        
        if fname:
            CONF.set('paths', 'output_dir', os.path.dirname(str(fname)))
            try:
                now = datetime.now()
                csvfile = open(fname, 'wb')
                writer = UnicodeWriter(csvfile, dialect= csv.excel, delimiter=';')
                writer.writerow([u'OpenFisca'])
                writer.writerow([u'Calculé le %s à %s' % (now.strftime('%d-%m-%Y'), now.strftime('%H:%M'))])
                writer.writerow([u'Système socio-fiscal au %s' % CONF.get('simulation', 'datesim')])
                writer.writerow([])
                
                for row in self.data:
                    if not row.desc in ('root'):
                        outlist = [row.desc]
                        for val in row.vals:
                            outlist.append(locale.str(val))
                        writer.writerow(outlist)
                csvfile.close()                
            except Exception, e:
                QMessageBox.critical(
                    self, "Error saving file", str(e),
                    QMessageBox.Ok, QMessageBox.NoButton)
示例#6
0
class OutTable(QDockWidget):
    def __init__(self, parent=None):
        super(OutTable, self).__init__(parent)
        self.setObjectName("Table")
        self.setWindowTitle("Table")
        self.dockWidgetContents = QWidget(self)
        self.verticalLayout = QVBoxLayout(self.dockWidgetContents)
        self.treeView = OfTreeView(self.dockWidgetContents)
        self.treeView.setAlternatingRowColors(True)
        self.treeView.setIndentation(10)
        selection_behavior = QAbstractItemView.SelectRows
        # we should enable contguous selection, but the copy method does not yet handle this.
        #        selection_mode = QAbstractItemView.ContiguousSelection
        selection_mode = QAbstractItemView.SingleSelection
        self.treeView.setSelectionBehavior(selection_behavior)
        self.treeView.setSelectionMode(selection_mode)
        self.verticalLayout.addWidget(self.treeView)
        self.setWidget(self.dockWidgetContents)

    def clearModel(self):
        self.treeView.setModel(None)

    def updateTable(self, data, reforme, mode, dataDefault):
        '''
        Updates table
        '''

        if dataDefault is None:
            dataDefault = data

        x_axis = CONF.get('simulation', 'x_axis')
        for axe in model.x_axes.itervalues():
            if axe.name == x_axis:
                x_axis_typ_tot = axe.typ_tot_default
                break

        headers = dataDefault[x_axis_typ_tot]
        n = len(headers.vals)
        self.data = data
        self.outputModel = OutputModel(data, headers, n, self)
        self.treeView.setModel(self.outputModel)
        self.treeView.expandAll()
        self.treeView.setColumnWidth(0, 200)
        if mode == 'bareme':
            for i in range(n):
                self.treeView.resizeColumnToContents(i + 1)
        else:
            self.treeView.setColumnWidth(1, 100)

    def create_dataframe(self):
        '''
        Formats data into a dataframe
        '''
        data_dict = dict()
        index = []
        for row in self.data:
            if not row.desc in ('root'):
                index.append(row.desc)
                data_dict[row.desc] = row.vals

        df = DataFrame(data_dict).T
        df = df.reindex(index)
        return df

    def create_description(self):
        '''
        Creates a description dataframe
        '''
        now = datetime.now()
        descr = [
            u'OpenFisca',
            u'Calculé le %s à %s' %
            (now.strftime('%d-%m-%Y'), now.strftime('%H:%M')),
            u'Système socio-fiscal au %s' % CONF.get('simulation', 'datesim')
        ]
        return DataFrame(descr)

    def saveCsv(self):
        self.save_table(table_format="csv")

    def save_table(self, table_format=None):

        if table_format is None:
            table_format = CONF.get('paths', 'table')

        output_dir = CONF.get('paths', 'output_dir')
        filename = 'sans-titre.' + table_format
        user_path = os.path.join(output_dir, filename)

        extension = table_format.upper() + "   (*." + table_format + ")"
        fname = QFileDialog.getSaveFileName(self, u"Exporter la table",
                                            user_path, extension)

        if fname:
            CONF.set('paths', 'output_dir', os.path.dirname(str(fname)))
            try:
                if table_format == "xls":
                    writer = ExcelWriter(str(fname))
                    df = self.create_dataframe()
                    descr = self.create_description()
                    df.to_excel(writer, "table", index=True, header=False)
                    descr.to_excel(writer,
                                   "description",
                                   index=False,
                                   header=False)
                    writer.save()
                elif table_format == "csv":
                    # TODO: use DataFrame's ?
                    now = datetime.now()
                    csvfile = open(fname, 'wb')
                    writer = UnicodeWriter(csvfile,
                                           dialect=csv.excel,
                                           delimiter=';')

                    for row in self.data:
                        if not row.desc in ('root'):
                            outlist = [row.desc]
                            for val in row.vals:
                                outlist.append(locale.str(val))
                            writer.writerow(outlist)

                    writer.writerow([u'OpenFisca'])
                    writer.writerow([
                        u'Calculé le %s à %s' %
                        (now.strftime('%d-%m-%Y'), now.strftime('%H:%M'))
                    ])
                    writer.writerow([
                        u'Système socio-fiscal au %s' %
                        CONF.get('simulation', 'datesim')
                    ])
                    writer.writerow([])

                    csvfile.close()

            except Exception, e:
                QMessageBox.critical(self, "Error saving file", str(e),
                                     QMessageBox.Ok, QMessageBox.NoButton)