def __init__(self, parent):
        wx.Panel.__init__(self, parent, -1, style=wx.TAB_TRAVERSAL)

        ##        self.listviewAvecFooter = OL_Suivi_budget.ListviewAvecFooter(self)
        ##        self.ctrl = self.listviewAvecFooter.GetListview()
        self.ctrl = OL_Suivi_budget.ListView(
            self,
            id=-1,
            style=wx.LC_REPORT | wx.SUNKEN_BORDER | wx.LC_SINGLE_SEL
            | wx.LC_HRULES | wx.LC_VRULES)

        self.ctrl.MAJ()

        # Boutons
        self.bouton_apercu = wx.BitmapButton(
            self, -1,
            wx.Bitmap(Chemins.GetStaticPath(u"Images/16x16/Apercu.png"),
                      wx.BITMAP_TYPE_ANY))
        self.bouton_imprimer = wx.BitmapButton(
            self, -1,
            wx.Bitmap(Chemins.GetStaticPath(u"Images/16x16/Imprimante.png"),
                      wx.BITMAP_TYPE_ANY))
        self.bouton_excel = wx.BitmapButton(
            self, -1,
            wx.Bitmap(Chemins.GetStaticPath(u"Images/16x16/Excel.png"),
                      wx.BITMAP_TYPE_ANY))
        self.bouton_texte = wx.BitmapButton(
            self, -1,
            wx.Bitmap(Chemins.GetStaticPath(u"Images/16x16/Texte2.png"),
                      wx.BITMAP_TYPE_ANY))

        # Binds
        self.Bind(wx.EVT_BUTTON, self.ctrl.Apercu, self.bouton_apercu)
        self.Bind(wx.EVT_BUTTON, self.ctrl.Imprimer, self.bouton_imprimer)
        self.Bind(wx.EVT_BUTTON, self.ctrl.ExportExcel, self.bouton_excel)
        self.Bind(wx.EVT_BUTTON, self.ctrl.ExportTexte, self.bouton_texte)

        # Properties
        self.bouton_apercu.SetToolTipString(
            _(u"Cliquez ici pour afficher un aperçu avant impression des données"
              ))
        self.bouton_imprimer.SetToolTipString(
            _(u"Cliquez ici pour imprimer les données"))
        self.bouton_excel.SetToolTipString(
            _(u"Cliquez ici pour exporter au format Excel les données"))
        self.bouton_texte.SetToolTipString(
            _(u"Cliquez ici pour exporter au format texte les données"))

        # Layout
        grid_sizer_base = wx.FlexGridSizer(1, 2, 5, 5)

        ##        grid_sizer_base.Add(self.listviewAvecFooter, 1, wx.EXPAND | wx.TOP | wx.LEFT | wx.BOTTOM, 10)
        grid_sizer_base.Add(self.ctrl, 1,
                            wx.EXPAND | wx.TOP | wx.LEFT | wx.BOTTOM, 10)

        grid_sizer_boutons = wx.FlexGridSizer(5, 1, 5, 5)
        grid_sizer_boutons.Add(self.bouton_apercu, 0, 0, 0)
        grid_sizer_boutons.Add(self.bouton_imprimer, 0, 0, 0)
        grid_sizer_boutons.Add((5, 5), 0, 0, 0)
        grid_sizer_boutons.Add(self.bouton_excel, 0, 0, 0)
        grid_sizer_boutons.Add(self.bouton_texte, 0, 0, 0)
        grid_sizer_base.Add(grid_sizer_boutons, 1,
                            wx.EXPAND | wx.TOP | wx.BOTTOM | wx.RIGHT, 10)

        grid_sizer_base.AddGrowableCol(0)
        grid_sizer_base.AddGrowableRow(0)

        self.SetSizer(grid_sizer_base)
        self.Layout()
    def MAJ(self):
        self.figure.clear()
        if self.dictBudget == None:
            wx.CallAfter(self.SendSizeEvent)
            return

        # Récupération des données
        from Ol import OL_Suivi_budget
        analyse = OL_Suivi_budget.Analyse(self.dictBudget)
        listeCategories = analyse.GetValeurs()

        listeRealise = []
        listeBudgete = []
        listeLabels = []

        for dictCategorie in listeCategories:
            listeRealise.append(dictCategorie["realise"])
            listeBudgete.append(dictCategorie["plafond"])
            listeLabels.append(dictCategorie["nomCategorie"])

##            if dictCategorie["typeCategorie"] == "debit" :
##                solde = plafond - realise
##            else :
##                solde = realise - plafond

##        # TEST
##        listeIndex = np.arange(len(listeLabels))
##        bar_width = 0.2
##        opacity = 0.4
##
##        ax = self.figure.add_subplot(111)
##        barres = ax.bar(listeIndex, listeRealise, width=bar_width, alpha=opacity, color="g", label=_(u"Réel"))
##        barres = ax.bar(listeIndex + bar_width, listeBudgete, width=bar_width, alpha=opacity, color="b", label=_(u"Budgété"))
##
##        # Formatage des montants sur y
##        majorFormatter = FormatStrFormatter(SYMBOLE + u" %d")
##        ax.yaxis.set_major_formatter(majorFormatter)
##
##        # Affichage des labels x
##        ax.set_xticks(listeIndex + bar_width)
##        ax.set_xticklabels(listeLabels)
##
##        labels = ax.get_xticklabels()
##        setp(labels, rotation=45)
##
##        # Légende
##        props = matplotlib.font_manager.FontProperties(size=10)
##        leg = ax.legend(loc='best', shadow=False, fancybox=True, prop=props)
##        leg.get_frame().set_alpha(0.5)
##
##        # Espaces autour du graph
##        self.figure.subplots_adjust(left=0.12, bottom=0.40, right=None, wspace=None, hspace=None)

# TEST
        listeIndex = np.arange(len(listeLabels))
        bar_height = 0.2
        opacity = 0.4

        ax = self.figure.add_subplot(111)
        barresRealise = ax.barh(listeIndex,
                                listeRealise,
                                height=bar_height,
                                alpha=opacity,
                                color="g",
                                label=_(u"Réel"))
        barresBudgete = ax.barh(listeIndex + bar_height,
                                listeBudgete,
                                height=bar_height,
                                alpha=opacity,
                                color="b",
                                label=_(u"Budgété"))

        # Formatage des montants sur x
        majorFormatter = FormatStrFormatter(u"%d " + SYMBOLE)
        ax.xaxis.set_major_formatter(majorFormatter)

        # Affichage des labels x
        ax.set_yticks(listeIndex + bar_height)
        ax.set_yticklabels(listeLabels)

        def autolabel(rects):
            # attach some text labels
            for rect in rects:
                width = rect.get_width()
                ax.text(width + 20,
                        rect.get_y() + rect.get_height() / 2.,
                        u"%.2f %s" % (int(width), SYMBOLE),
                        ha='left',
                        va='center',
                        fontsize=8,
                        color="grey")

        if self.afficher_valeurs == True:
            autolabel(barresRealise)
            autolabel(barresBudgete)

        # Recherche la largeur de texte max
        largeurMax = 0
        for label in listeLabels:
            if len(label) > largeurMax:
                largeurMax = len(label)

        # Espaces autour du graph
        margeGauche = 0.1 + largeurMax * 0.008
        self.figure.subplots_adjust(left=margeGauche,
                                    right=None,
                                    wspace=None,
                                    hspace=None)

        # Légende
        props = matplotlib.font_manager.FontProperties(size=10)
        leg = ax.legend(loc='best', shadow=False, fancybox=True, prop=props)
        leg.get_frame().set_alpha(0.5)

        # Finalisation
        ax.autoscale_view('tight')
        ##        ax.grid(True)
        ax.figure.canvas.draw()
        wx.CallAfter(self.SendSizeEvent)
        return
Beispiel #3
0
    def Graphe_tiers(self, typeCategorie=""):
        # Récupération des données
        conditions = []
        if self.dictParametres["date_debut"] != None:
            conditions.append("date_budget>='%s'" %
                              self.dictParametres["date_debut"])
            conditions.append("date_budget<='%s'" %
                              self.dictParametres["date_fin"])
        if self.dictParametres["IDanalytique"] != None:
            conditions.append("IDanalytique=%d" %
                              self.dictParametres["IDanalytique"])
        if len(conditions) > 0:
            ConditionsStr = "AND " + " AND ".join(conditions)
        else:
            ConditionsStr = ""

        DB = GestionDB.DB()
        req = """SELECT compta_tiers.IDtiers, compta_tiers.nom, SUM(compta_ventilation.montant)
        FROM compta_tiers
        LEFT JOIN compta_operations ON compta_operations.IDtiers = compta_tiers.IDtiers
        LEFT JOIN compta_ventilation ON compta_ventilation.IDoperation = compta_operations.IDoperation
        WHERE type='%s' %s
        GROUP BY compta_tiers.IDtiers
        ;""" % (typeCategorie, ConditionsStr)
        DB.ExecuterReq(req)
        listeDonnees = DB.ResultatReq()
        DB.Close()
        if len(listeDonnees) == 0:
            return

        listeValeurs = []
        listeLabels = []
        listeCouleurs = []

        for IDtiers, nom, montant in listeDonnees:
            listeValeurs.append(montant)
            listeLabels.append(nom)

        listeIndex = np.arange(len(listeLabels))
        bar_height = 0.2
        opacity = 0.4

        ax = self.figure.add_subplot(111)
        barres = ax.barh(listeIndex,
                         listeValeurs,
                         height=bar_height,
                         align='center',
                         alpha=opacity)

        # Formatage des montants sur x
        majorFormatter = FormatStrFormatter(u"%d " + SYMBOLE)
        ax.xaxis.set_major_formatter(majorFormatter)

        # Affichage des labels x
        ax.set_yticks(listeIndex)
        ax.set_yticklabels(listeLabels)

        def autolabel(rects):
            # attach some text labels
            for rect in rects:
                width = rect.get_width()
                ax.text(width + 10,
                        rect.get_y() + rect.get_height() / 2.,
                        u"%.2f %s" % (int(width), SYMBOLE),
                        ha='left',
                        va='center',
                        fontsize=8,
                        color="grey")

        if self.afficher_valeurs == True:
            autolabel(barres)

        # Recherche la largeur de texte max
        largeurMax = 0
        for label in listeLabels:
            if len(label) > largeurMax:
                largeurMax = len(label)

        # Espaces autour du graph
        margeGauche = 0.1 + largeurMax * 0.008
        self.figure.subplots_adjust(left=margeGauche,
                                    right=None,
                                    wspace=None,
                                    hspace=None)

        # Finalisation
        ax.autoscale_view('tight')
        ##        ax.grid(True)
        ax.figure.canvas.draw()
        wx.CallAfter(self.SendSizeEvent)
        return

        # Récupération des données
        from Ol import OL_Suivi_budget
        analyse = OL_Suivi_budget.Analyse(self.dictBudget)
        listeCategories = analyse.GetValeurs()

        listeRealise = []
        listeBudgete = []
        listeLabels = []

        for dictCategorie in listeCategories:
            listeRealise.append(dictCategorie["realise"])
            listeBudgete.append(dictCategorie["plafond"])
            listeLabels.append(dictCategorie["nomCategorie"])

##            if dictCategorie["typeCategorie"] == "debit" :
##                solde = plafond - realise
##            else :
##                solde = realise - plafond

##        # TEST
##        listeIndex = np.arange(len(listeLabels))
##        bar_width = 0.2
##        opacity = 0.4
##
##        ax = self.figure.add_subplot(111)
##        barres = ax.bar(listeIndex, listeRealise, width=bar_width, alpha=opacity, color="g", label=_(u"Réel"))
##        barres = ax.bar(listeIndex + bar_width, listeBudgete, width=bar_width, alpha=opacity, color="b", label=_(u"Budgété"))
##
##        # Formatage des montants sur y
##        majorFormatter = FormatStrFormatter(SYMBOLE + u" %d")
##        ax.yaxis.set_major_formatter(majorFormatter)
##
##        # Affichage des labels x
##        ax.set_xticks(listeIndex + bar_width)
##        ax.set_xticklabels(listeLabels)
##
##        labels = ax.get_xticklabels()
##        setp(labels, rotation=45)
##
##        # Légende
##        props = matplotlib.font_manager.FontProperties(size=10)
##        leg = ax.legend(loc='best', shadow=False, fancybox=True, prop=props)
##        leg.get_frame().set_alpha(0.5)
##
##        # Espaces autour du graph
##        self.figure.subplots_adjust(left=0.12, bottom=0.40, right=None, wspace=None, hspace=None)

# TEST
        listeIndex = np.arange(len(listeLabels))
        bar_height = 0.2
        opacity = 0.4

        ax = self.figure.add_subplot(111)
        barresRealise = ax.barh(listeIndex,
                                listeRealise,
                                height=bar_height,
                                alpha=opacity,
                                color="g",
                                label=_(u"Réel"))
        barresBudgete = ax.barh(listeIndex + bar_height,
                                listeBudgete,
                                height=bar_height,
                                alpha=opacity,
                                color="b",
                                label=_(u"Budgété"))

        # Formatage des montants sur x
        majorFormatter = FormatStrFormatter(u"%d " + SYMBOLE)
        ax.xaxis.set_major_formatter(majorFormatter)

        # Affichage des labels x
        ax.set_yticks(listeIndex + bar_height)
        ax.set_yticklabels(listeLabels)

        def autolabel(rects):
            # attach some text labels
            for rect in rects:
                width = rect.get_width()
                ax.text(width + 20,
                        rect.get_y() + rect.get_height() / 2.,
                        u"%.2f %s" % (int(width), SYMBOLE),
                        ha='left',
                        va='center',
                        fontsize=8,
                        color="grey")

        if self.afficher_valeurs == True:
            autolabel(barresRealise)
            autolabel(barresBudgete)

        # Recherche la largeur de texte max
        largeurMax = 0
        for label in listeLabels:
            if len(label) > largeurMax:
                largeurMax = len(label)

        # Espaces autour du graph
        margeGauche = 0.1 + largeurMax * 0.008
        self.figure.subplots_adjust(left=margeGauche,
                                    right=None,
                                    wspace=None,
                                    hspace=None)

        # Légende
        props = matplotlib.font_manager.FontProperties(size=10)
        leg = ax.legend(loc='best', shadow=False, fancybox=True, prop=props)
        leg.get_frame().set_alpha(0.5)

        # Finalisation
        ax.autoscale_view('tight')
        ax.grid(True)
        ax.figure.canvas.draw()
        wx.CallAfter(self.SendSizeEvent)
        return